Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
PandoraInternal.h
Go to the documentation of this file.
1
8#ifndef PANDORA_INTERNAL_H
9#define PANDORA_INTERNAL_H 1
10
11#include <algorithm>
12#include <cstdint>
13#include <iostream>
14#include <iomanip>
15#include <list>
16#include <map>
17#include <set>
18#include <sstream>
19#include <string>
20#include <unordered_map>
21#include <unordered_set>
22#include <vector>
23
24namespace pandora
25{
26
27class Algorithm;
28class AlgorithmTool;
29class BFieldPlugin;
30class BoxGap;
31class CaloHit;
32class CartesianVector;
33class Cluster;
34class ConcentricGap;
35class DetectorGap;
36class EnergyCorrectionPlugin;
37class ExternalParameters;
38class Helix;
39class Histogram;
40class LArTPC;
41class LArTransformationPlugin;
42class LineGap;
43class MCParticle;
44class OrderedCaloHitList;
46class ParticleIdPlugin;
47class PandoraSettings;
48class PseudoLayerPlugin;
49class ShowerProfilePlugin;
50class SubDetector;
51class Track;
52class TrackState;
53class TwoDHistogram;
54class Vertex;
55
56//------------------------------------------------------------------------------------------------------------------------------------------
57
58// Macros for registering lists of algorithms, energy corrections functions, particle id functions or settings functions
59#define PANDORA_REGISTER_ALGORITHM(a, b) \
60{ \
61 const pandora::StatusCode statusCode(PandoraApi::RegisterAlgorithmFactory(pandora, a, new b)); \
62 if (pandora::STATUS_CODE_SUCCESS != statusCode) \
63 return statusCode; \
64}
65
66#define PANDORA_REGISTER_ALGORITHM_TOOL(a, b) \
67{ \
68 const pandora::StatusCode statusCode(PandoraApi::RegisterAlgorithmToolFactory(pandora, a, new b)); \
69 if (pandora::STATUS_CODE_SUCCESS != statusCode) \
70 return statusCode; \
71}
72
73#define PANDORA_REGISTER_ENERGY_CORRECTION(a, b, c) \
74{ \
75 const pandora::StatusCode statusCode(PandoraApi::RegisterEnergyCorrectionPlugin(pandora, a, b, new c)); \
76 if (pandora::STATUS_CODE_SUCCESS != statusCode) \
77 return statusCode; \
78}
79
80#define PANDORA_REGISTER_PARTICLE_ID(a, b) \
81{ \
82 const pandora::StatusCode statusCode(PandoraApi::RegisterParticleIdPlugin(pandora, a, new b)); \
83 if (pandora::STATUS_CODE_SUCCESS != statusCode) \
84 return statusCode; \
85}
86
87//------------------------------------------------------------------------------------------------------------------------------------------
88//------------------------------------------------------------------------------------------------------------------------------------------
89
90template <class T>
91inline bool StringToType(const std::string &s, T &t)
92{
93 std::istringstream iss(s);
94 return !(iss >> t).fail();
95}
96
97template <>
98inline bool StringToType(const std::string &s, const void *&t)
99{
100 uintptr_t address;
101 std::istringstream iss(s);
102 iss >> std::hex >> address;
103 t = reinterpret_cast<const void*>(address);
104 return true;
105}
106
107//------------------------------------------------------------------------------------------------------------------------------------------
108//------------------------------------------------------------------------------------------------------------------------------------------
109
110template <class T>
111inline std::string TypeToString(const T &t)
112{
113 std::ostringstream oss;
114
115 if ((oss << t).fail())
116 throw;
117
118 return oss.str();
119}
120
121template <>
122inline std::string TypeToString(const void *const &t)
123{
124 const uintptr_t address(reinterpret_cast<uintptr_t>(t));
125 return TypeToString(address);
126}
127
128//------------------------------------------------------------------------------------------------------------------------------------------
129//------------------------------------------------------------------------------------------------------------------------------------------
130
131template <class T>
132inline std::string TypeToStringPrecision(const T &t, const unsigned int precision = 12)
133{
134 const std::streamsize ss(std::cout.precision());
135 std::ostringstream oss;
136
137 if ((oss << std::setprecision(precision) << t << std::setprecision(ss)).fail())
138 throw;
139
140 return oss.str();
141}
142
143template <>
144inline std::string TypeToStringPrecision(const void *const &t, const unsigned int precision)
145{
146 const uintptr_t address(reinterpret_cast<uintptr_t>(t));
147 return TypeToStringPrecision(address, precision);
148}
149
150//------------------------------------------------------------------------------------------------------------------------------------------
151//------------------------------------------------------------------------------------------------------------------------------------------
152
156template <typename T>
158{
159public:
160 bool operator()(const T *lhs, const T *rhs) const;
161};
162
163//------------------------------------------------------------------------------------------------------------------------------------------
164
165template <typename T>
166inline bool PointerLessThan<T>::operator()(const T *lhs, const T *rhs) const
167{
168 return (*lhs < *rhs);
169}
170
171//------------------------------------------------------------------------------------------------------------------------------------------
172//------------------------------------------------------------------------------------------------------------------------------------------
173
177template <typename T>
179{
180public:
181 typedef typename std::list<T> TheList;
182 typedef typename TheList::const_iterator const_iterator;
183 typedef typename TheList::const_iterator iterator;
184 typedef typename TheList::value_type value_type;
185
189 MyList();
190
196 MyList(const MyList &rhs);
197
204 MyList(size_t n, const value_type &val = value_type());
205
212 template <class InputIterator>
213 MyList(InputIterator first, InputIterator last);
214
218 ~MyList();
219
225 void operator= (const MyList &rhs);
226
230 const_iterator begin() const;
231
235 const_iterator end() const;
236
242 void push_back(const value_type &val);
243
249 iterator erase(const_iterator position);
250
258 template <class InputIterator>
259 void insert(const_iterator position, InputIterator first, InputIterator last);
260
266 template <class Compare>
267 void sort (Compare comp);
268
274 unsigned int size() const;
275
281 bool empty() const;
282
286 void clear();
287
288private:
290};
291
292//------------------------------------------------------------------------------------------------------------------------------------------
293
294template <typename T>
296{
297}
298
299//------------------------------------------------------------------------------------------------------------------------------------------
300
301template <typename T>
302inline MyList<T>::MyList(const MyList &rhs) :
303 m_theList(rhs.m_theList)
304{
305}
306
307//------------------------------------------------------------------------------------------------------------------------------------------
308
309template <typename T>
310inline MyList<T>::MyList(size_t n, const value_type &val) :
311 m_theList(n, val)
312{
313}
314
315//------------------------------------------------------------------------------------------------------------------------------------------
316
317template <typename T>
318template <class InputIterator>
319inline MyList<T>::MyList(InputIterator first, InputIterator last) :
320 m_theList(first, last)
321{
322}
323
324//------------------------------------------------------------------------------------------------------------------------------------------
325
326template <typename T>
328{
329}
330
331//------------------------------------------------------------------------------------------------------------------------------------------
332
333template <typename T>
334inline void MyList<T>::operator= (const MyList &rhs)
335{
336 m_theList = rhs.m_theList;
337}
338
339//------------------------------------------------------------------------------------------------------------------------------------------
340
341template <typename T>
343{
344 return m_theList.begin();
345}
346
347//------------------------------------------------------------------------------------------------------------------------------------------
348
349template <typename T>
351{
352 return m_theList.end();
353}
354
355//------------------------------------------------------------------------------------------------------------------------------------------
356
357template <typename T>
358inline void MyList<T>::push_back(const value_type &val)
359{
360 if (m_theList.end() != std::find(m_theList.begin(), m_theList.end(), val))
361 {
362 std::cout << "push_back duplicate, in file: " << __FILE__ << " line#: " << __LINE__ << std::endl;
363 throw;
364 }
365
366 m_theList.push_back(val);
367}
368
369//------------------------------------------------------------------------------------------------------------------------------------------
370
371template <typename T>
373{
374 return m_theList.erase(position);
375}
376
377//------------------------------------------------------------------------------------------------------------------------------------------
378
379template <typename T>
380template <class InputIterator>
381inline void MyList<T>::insert(const_iterator position, InputIterator first, InputIterator last)
382{
383 for (InputIterator iter = first; iter != last; ++iter)
384 {
385 if (m_theList.end() != std::find(m_theList.begin(), m_theList.end(), *iter))
386 {
387 std::cout << "insert duplicate, in file: " << __FILE__ << " line#: " << __LINE__ << std::endl;
388 throw;
389 }
390 }
391
392 m_theList.insert(position, first, last);
393}
394
395//------------------------------------------------------------------------------------------------------------------------------------------
396
397template <typename T>
398template <class Compare>
399inline void MyList<T>::sort(Compare comp)
400{
401 m_theList.sort(comp);
402}
403
404//------------------------------------------------------------------------------------------------------------------------------------------
405
406template <typename T>
407inline unsigned int MyList<T>::size() const
408{
409 return m_theList.size();
410}
411
412//------------------------------------------------------------------------------------------------------------------------------------------
413
414template <typename T>
415inline bool MyList<T>::empty() const
416{
417 return m_theList.empty();
418}
419
420//------------------------------------------------------------------------------------------------------------------------------------------
421
422template <typename T>
423inline void MyList<T>::clear()
424{
425 m_theList.clear();
426}
427
428//------------------------------------------------------------------------------------------------------------------------------------------
429//------------------------------------------------------------------------------------------------------------------------------------------
430
431#define MANAGED_CONTAINER std::list
432
433typedef MANAGED_CONTAINER<const CaloHit *> CaloHitList;
434typedef MANAGED_CONTAINER<const Cluster *> ClusterList;
435typedef MANAGED_CONTAINER<const DetectorGap *> DetectorGapList;
436typedef MANAGED_CONTAINER<const LArTPC *> LArTPCList;
437typedef MANAGED_CONTAINER<const MCParticle *> MCParticleList;
438typedef MANAGED_CONTAINER<const ParticleFlowObject *> ParticleFlowObjectList;
439typedef MANAGED_CONTAINER<const ParticleFlowObject *> PfoList;
440typedef MANAGED_CONTAINER<const SubDetector *> SubDetectorList;
441typedef MANAGED_CONTAINER<const Track *> TrackList;
442typedef MANAGED_CONTAINER<const Vertex *> VertexList;
443
444typedef std::vector<const CaloHit *> CaloHitVector;
445typedef std::vector<const Cluster *> ClusterVector;
446typedef std::vector<const DetectorGap *> DetectorGapVector;
447typedef std::vector<const LArTPC *> LArTPCVector;
448typedef std::vector<const MCParticle *> MCParticleVector;
449typedef std::vector<const ParticleFlowObject *> ParticleFlowObjectVector;
450typedef std::vector<const ParticleFlowObject *> PfoVector;
451typedef std::vector<const SubDetector *> SubDetectorVector;
452typedef std::vector<const Track *> TrackVector;
453typedef std::vector<const Vertex *> VertexVector;
454
455typedef std::unordered_set<const CaloHit *> CaloHitSet;
456typedef std::unordered_set<const Cluster *> ClusterSet;
457typedef std::unordered_set<const DetectorGap *> DetectorGapSet;
458typedef std::unordered_set<const LArTPC *> LArTPCSet;
459typedef std::unordered_set<const MCParticle *> MCParticleSet;
460typedef std::unordered_set<const ParticleFlowObject *> ParticleFlowObjectSet;
461typedef std::unordered_set<const ParticleFlowObject *> PfoSet;
462typedef std::unordered_set<const SubDetector *> SubDetectorSet;
463typedef std::unordered_set<const Track *> TrackSet;
464typedef std::unordered_set<const Vertex *> VertexSet;
465
466typedef std::vector<int> IntVector;
467typedef std::vector<float> FloatVector;
468typedef std::vector<std::string> StringVector;
469typedef std::vector<CartesianVector> CartesianPointVector;
470typedef std::vector<TrackState> TrackStateVector;
471typedef std::vector<AlgorithmTool *> AlgorithmToolVector;
472
473typedef const void * Uid;
474typedef std::unordered_map<Uid, const MCParticle *> UidToMCParticleMap;
475typedef std::unordered_map<const MCParticle *, float> MCParticleWeightMap;
476typedef std::unordered_map<Uid, MCParticleWeightMap> UidToMCParticleWeightMap;
477typedef std::unordered_map<const Cluster *, const Track * > ClusterToTrackMap;
478typedef std::unordered_map<const Track *, const Cluster * > TrackToClusterMap;
479
480typedef std::set<std::string> StringSet;
481typedef std::map<std::string, float> PropertiesMap;
482typedef std::map<std::string, const SubDetector *> SubDetectorMap;
483typedef std::map<unsigned int, const LArTPC *> LArTPCMap;
484
485} // namespace pandora
486
487#endif // #ifndef PANDORA_INTERNAL_H
Wrapper around std::list.
TheList::const_iterator iterator
~MyList()
Destructor.
iterator erase(const_iterator position)
erase
const_iterator begin() const
begin
unsigned int size() const
size
std::list< T > TheList
bool empty() const
empty
void sort(Compare comp)
sort
void operator=(const MyList &rhs)
operator=
TheList m_theList
The list.
const_iterator end() const
end
MyList()
Default constructor.
void push_back(const value_type &val)
push_back
void insert(const_iterator position, InputIterator first, InputIterator last)
insert
TheList::const_iterator const_iterator
TheList::value_type value_type
Enable ordering of pointers based on properties of target objects.
bool operator()(const T *lhs, const T *rhs) const
ObjectCreationHelper< CaloHitParameters, CaloHitMetadata, pandora::CaloHit > CaloHit
ObjectCreationHelper< ClusterParameters, ClusterMetadata, pandora::Cluster > Cluster
ObjectCreationHelper< ParticleFlowObjectCreation, ParticleFlowObjectMetadata, pandora::ParticleFlowObject > ParticleFlowObject
ObjectCreationHelper< MCParticleParameters, ObjectMetadata, pandora::MCParticle > MCParticle
ObjectCreationHelper< TrackParameters, ObjectMetadata, pandora::Track > Track
ObjectCreationHelper< VertexParameters, VertexMetadata, pandora::Vertex > Vertex
std::unordered_set< const MCParticle * > MCParticleSet
std::vector< const LArTPC * > LArTPCVector
MANAGED_CONTAINER< const LArTPC * > LArTPCList
std::vector< const SubDetector * > SubDetectorVector
MANAGED_CONTAINER< const MCParticle * > MCParticleList
std::vector< const CaloHit * > CaloHitVector
std::unordered_set< const LArTPC * > LArTPCSet
std::unordered_set< const SubDetector * > SubDetectorSet
std::vector< const DetectorGap * > DetectorGapVector
MANAGED_CONTAINER< const ParticleFlowObject * > ParticleFlowObjectList
std::vector< const Cluster * > ClusterVector
bool StringToType(const std::string &s, T &t)
std::unordered_set< const ParticleFlowObject * > PfoSet
std::unordered_map< const MCParticle *, float > MCParticleWeightMap
std::unordered_set< const Track * > TrackSet
MANAGED_CONTAINER< const Cluster * > ClusterList
std::vector< const ParticleFlowObject * > PfoVector
std::vector< std::string > StringVector
std::vector< int > IntVector
std::vector< CartesianVector > CartesianPointVector
MANAGED_CONTAINER< const SubDetector * > SubDetectorList
std::vector< const ParticleFlowObject * > ParticleFlowObjectVector
std::vector< AlgorithmTool * > AlgorithmToolVector
std::unordered_set< const CaloHit * > CaloHitSet
std::unordered_map< Uid, const MCParticle * > UidToMCParticleMap
std::map< unsigned int, const LArTPC * > LArTPCMap
std::set< std::string > StringSet
std::unordered_set< const Vertex * > VertexSet
std::string TypeToStringPrecision(const T &t, const unsigned int precision=12)
std::vector< const Track * > TrackVector
std::unordered_map< const Cluster *, const Track * > ClusterToTrackMap
std::unordered_set< const Cluster * > ClusterSet
const void * Uid
std::map< std::string, const SubDetector * > SubDetectorMap
MANAGED_CONTAINER< const DetectorGap * > DetectorGapList
std::unordered_set< const DetectorGap * > DetectorGapSet
MANAGED_CONTAINER< const CaloHit * > CaloHitList
std::vector< TrackState > TrackStateVector
MANAGED_CONTAINER< const Track * > TrackList
std::vector< float > FloatVector
std::string TypeToString(const T &t)
std::vector< const MCParticle * > MCParticleVector
std::unordered_map< const Track *, const Cluster * > TrackToClusterMap
MANAGED_CONTAINER< const Vertex * > VertexList
std::map< std::string, float > PropertiesMap
MANAGED_CONTAINER< const ParticleFlowObject * > PfoList
std::unordered_map< Uid, MCParticleWeightMap > UidToMCParticleWeightMap
std::vector< const Vertex * > VertexVector
std::unordered_set< const ParticleFlowObject * > ParticleFlowObjectSet