Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:20:10

0001 /**
0002  *  @file   PandoraSDK/include/Pandora/PandoraInternal.h
0003  * 
0004  *  @brief  Header file defining relevant internal typedefs, sort and string conversion functions
0005  * 
0006  *  $Log: $
0007  */
0008 #ifndef PANDORA_INTERNAL_H
0009 #define PANDORA_INTERNAL_H 1
0010 
0011 #include <algorithm>
0012 #include <cstdint>
0013 #include <iostream>
0014 #include <iomanip>
0015 #include <list>
0016 #include <map>
0017 #include <set>
0018 #include <sstream>
0019 #include <string>
0020 #include <unordered_map>
0021 #include <unordered_set>
0022 #include <vector>
0023 
0024 namespace pandora
0025 {
0026 
0027 class Algorithm;
0028 class AlgorithmTool;
0029 class BFieldPlugin;
0030 class BoxGap;
0031 class CaloHit;
0032 class CartesianVector;
0033 class Cluster;
0034 class ConcentricGap;
0035 class DetectorGap;
0036 class EnergyCorrectionPlugin;
0037 class ExternalParameters;
0038 class Helix;
0039 class Histogram;
0040 class LArTPC;
0041 class LArTransformationPlugin;
0042 class LineGap;
0043 class MCParticle;
0044 class OrderedCaloHitList;
0045 class ParticleFlowObject;
0046 class ParticleIdPlugin;
0047 class PandoraSettings;
0048 class PseudoLayerPlugin;
0049 class ShowerProfilePlugin;
0050 class SubDetector;
0051 class Track;
0052 class TrackState;
0053 class TwoDHistogram;
0054 class Vertex;
0055 
0056 //------------------------------------------------------------------------------------------------------------------------------------------
0057 
0058 // Macros for registering lists of algorithms, energy corrections functions, particle id functions or settings functions
0059 #define PANDORA_REGISTER_ALGORITHM(a, b)                                                                    \
0060 {                                                                                                           \
0061     const pandora::StatusCode statusCode(PandoraApi::RegisterAlgorithmFactory(pandora, a, new b));          \
0062     if (pandora::STATUS_CODE_SUCCESS != statusCode)                                                         \
0063         return statusCode;                                                                                  \
0064 }
0065 
0066 #define PANDORA_REGISTER_ALGORITHM_TOOL(a, b)                                                               \
0067 {                                                                                                           \
0068     const pandora::StatusCode statusCode(PandoraApi::RegisterAlgorithmToolFactory(pandora, a, new b));      \
0069     if (pandora::STATUS_CODE_SUCCESS != statusCode)                                                         \
0070         return statusCode;                                                                                  \
0071 }
0072 
0073 #define PANDORA_REGISTER_ENERGY_CORRECTION(a, b, c)                                                         \
0074 {                                                                                                           \
0075     const pandora::StatusCode statusCode(PandoraApi::RegisterEnergyCorrectionPlugin(pandora, a, b, new c)); \
0076     if (pandora::STATUS_CODE_SUCCESS != statusCode)                                                         \
0077         return statusCode;                                                                                  \
0078 }
0079 
0080 #define PANDORA_REGISTER_PARTICLE_ID(a, b)                                                                  \
0081 {                                                                                                           \
0082     const pandora::StatusCode statusCode(PandoraApi::RegisterParticleIdPlugin(pandora, a, new b));          \
0083     if (pandora::STATUS_CODE_SUCCESS != statusCode)                                                         \
0084         return statusCode;                                                                                  \
0085 }
0086 
0087 //------------------------------------------------------------------------------------------------------------------------------------------
0088 //------------------------------------------------------------------------------------------------------------------------------------------
0089 
0090 template <class T>
0091 inline bool StringToType(const std::string &s, T &t)
0092 {
0093     std::istringstream iss(s);
0094     return !(iss >> t).fail();
0095 }
0096 
0097 template <>
0098 inline bool StringToType(const std::string &s, const void *&t)
0099 {
0100     uintptr_t address;
0101     std::istringstream iss(s);
0102     iss >> std::hex >> address;
0103     t = reinterpret_cast<const void*>(address);
0104     return true;
0105 }
0106 
0107 //------------------------------------------------------------------------------------------------------------------------------------------
0108 //------------------------------------------------------------------------------------------------------------------------------------------
0109 
0110 template <class T>
0111 inline std::string TypeToString(const T &t)
0112 {
0113     std::ostringstream oss;
0114 
0115     if ((oss << t).fail())
0116         throw;
0117 
0118     return oss.str();
0119 }
0120 
0121 template <>
0122 inline std::string TypeToString(const void *const &t)
0123 {
0124     const uintptr_t address(reinterpret_cast<uintptr_t>(t));
0125     return TypeToString(address);
0126 }
0127 
0128 //------------------------------------------------------------------------------------------------------------------------------------------
0129 //------------------------------------------------------------------------------------------------------------------------------------------
0130 
0131 template <class T>
0132 inline std::string TypeToStringPrecision(const T &t, const unsigned int precision = 12)
0133 {
0134     const std::streamsize ss(std::cout.precision());
0135     std::ostringstream oss;
0136 
0137     if ((oss << std::setprecision(precision) << t << std::setprecision(ss)).fail())
0138         throw;
0139 
0140     return oss.str();
0141 }
0142 
0143 template <>
0144 inline std::string TypeToStringPrecision(const void *const &t, const unsigned int precision)
0145 {
0146     const uintptr_t address(reinterpret_cast<uintptr_t>(t));
0147     return TypeToStringPrecision(address, precision);
0148 }
0149 
0150 //------------------------------------------------------------------------------------------------------------------------------------------
0151 //------------------------------------------------------------------------------------------------------------------------------------------
0152 
0153 /**
0154  *  @brief  Enable ordering of pointers based on properties of target objects
0155  */
0156 template <typename T>
0157 class PointerLessThan
0158 {
0159 public:
0160     bool operator()(const T *lhs, const T *rhs) const;
0161 };
0162 
0163 //------------------------------------------------------------------------------------------------------------------------------------------
0164 
0165 template <typename T>
0166 inline bool PointerLessThan<T>::operator()(const T *lhs, const T *rhs) const
0167 {
0168     return (*lhs < *rhs);
0169 }
0170 
0171 //------------------------------------------------------------------------------------------------------------------------------------------
0172 //------------------------------------------------------------------------------------------------------------------------------------------
0173 
0174 /**
0175  *  @brief  Wrapper around std::list
0176  */
0177 template <typename T>
0178 class MyList
0179 {
0180 public:
0181     typedef typename std::list<T> TheList;
0182     typedef typename TheList::const_iterator const_iterator;
0183     typedef typename TheList::const_iterator iterator;
0184     typedef typename TheList::value_type value_type;
0185 
0186     /**
0187      *  @brief  Default constructor
0188      */
0189     MyList();
0190 
0191     /**
0192      *  @brief  Copy constructor
0193      * 
0194      *  @param  rhs
0195      */
0196     MyList(const MyList &rhs);
0197 
0198     /**
0199      *  @brief  Constructor
0200      * 
0201      *  @param  n
0202      *  @param  val
0203      */
0204     MyList(size_t n, const value_type &val = value_type());
0205 
0206     /**
0207      *  @brief  Constructor
0208      * 
0209      *  @param  first
0210      *  @param  last
0211      */
0212     template <class InputIterator>
0213     MyList(InputIterator first, InputIterator last);
0214 
0215     /**
0216      *  @brief  Destructor
0217      */
0218     ~MyList();
0219 
0220     /**
0221      *  @brief  operator=
0222      * 
0223      *  @param  rhs
0224      */
0225     void operator= (const MyList &rhs);
0226 
0227     /**
0228      *  @brief  begin
0229      */
0230     const_iterator begin() const;
0231 
0232     /**
0233      *  @brief  end
0234      */
0235     const_iterator end() const;
0236 
0237     /**
0238      *  @brief  push_back
0239      * 
0240      *  @param  val
0241      */
0242     void push_back(const value_type &val);
0243 
0244     /**
0245      *  @brief  erase
0246      * 
0247      *  @param  position
0248      */
0249     iterator erase(const_iterator position);
0250 
0251     /**
0252      *  @brief  insert
0253      * 
0254      *  @param  position
0255      *  @param  first
0256      *  @param  last
0257      */
0258     template <class InputIterator>
0259     void insert(const_iterator position, InputIterator first, InputIterator last);
0260 
0261     /**
0262      *  @brief  sort
0263      * 
0264      *  @param  comp
0265      */
0266     template <class Compare>
0267     void sort (Compare comp);
0268 
0269     /**
0270      *  @brief  size
0271      * 
0272      *  @return size
0273      */
0274     unsigned int size() const;
0275 
0276     /**
0277      *  @brief  empty
0278      * 
0279      *  @return boolean
0280      */
0281     bool empty() const;
0282 
0283     /**
0284      *  @brief  clear
0285      */
0286     void clear();
0287 
0288 private:
0289     TheList     m_theList;      ///< The list
0290 };
0291 
0292 //------------------------------------------------------------------------------------------------------------------------------------------
0293 
0294 template <typename T>
0295 inline MyList<T>::MyList()
0296 {
0297 }
0298 
0299 //------------------------------------------------------------------------------------------------------------------------------------------
0300 
0301 template <typename T>
0302 inline MyList<T>::MyList(const MyList &rhs) :
0303     m_theList(rhs.m_theList)
0304 {
0305 }
0306 
0307 //------------------------------------------------------------------------------------------------------------------------------------------
0308 
0309 template <typename T>
0310 inline MyList<T>::MyList(size_t n, const value_type &val) :
0311     m_theList(n, val)
0312 {
0313 }
0314 
0315 //------------------------------------------------------------------------------------------------------------------------------------------
0316 
0317 template <typename T>
0318 template <class InputIterator>
0319 inline MyList<T>::MyList(InputIterator first, InputIterator last) :
0320     m_theList(first, last)
0321 {
0322 }
0323 
0324 //------------------------------------------------------------------------------------------------------------------------------------------
0325 
0326 template <typename T>
0327 inline MyList<T>::~MyList()
0328 {
0329 }
0330 
0331 //------------------------------------------------------------------------------------------------------------------------------------------
0332 
0333 template <typename T>
0334 inline void MyList<T>::operator= (const MyList &rhs)
0335 {
0336     m_theList = rhs.m_theList;
0337 }
0338 
0339 //------------------------------------------------------------------------------------------------------------------------------------------
0340 
0341 template <typename T>
0342 inline typename MyList<T>::const_iterator MyList<T>::begin() const
0343 {
0344     return m_theList.begin();
0345 }
0346 
0347 //------------------------------------------------------------------------------------------------------------------------------------------
0348 
0349 template <typename T>
0350 inline typename MyList<T>::const_iterator MyList<T>::end() const
0351 {
0352     return m_theList.end();
0353 }
0354 
0355 //------------------------------------------------------------------------------------------------------------------------------------------
0356 
0357 template <typename T>
0358 inline void MyList<T>::push_back(const value_type &val)
0359 {
0360     if (m_theList.end() != std::find(m_theList.begin(), m_theList.end(), val))
0361     {
0362         std::cout << "push_back duplicate, in file:     " << __FILE__ << " line#: " << __LINE__ << std::endl;
0363         throw;
0364     }
0365 
0366     m_theList.push_back(val);
0367 }
0368 
0369 //------------------------------------------------------------------------------------------------------------------------------------------
0370 
0371 template <typename T>
0372 inline typename MyList<T>::iterator MyList<T>::erase(const_iterator position)
0373 {
0374     return m_theList.erase(position);
0375 }
0376 
0377 //------------------------------------------------------------------------------------------------------------------------------------------
0378 
0379 template <typename T>
0380 template <class InputIterator>
0381 inline void MyList<T>::insert(const_iterator position, InputIterator first, InputIterator last)
0382 {
0383     for (InputIterator iter = first; iter != last; ++iter)
0384     {
0385         if (m_theList.end() != std::find(m_theList.begin(), m_theList.end(), *iter))
0386         {
0387             std::cout << "insert duplicate, in file:     " << __FILE__ << " line#: " << __LINE__ << std::endl;
0388             throw;
0389         }
0390     }
0391 
0392     m_theList.insert(position, first, last);
0393 }
0394 
0395 //------------------------------------------------------------------------------------------------------------------------------------------
0396 
0397 template <typename T>
0398 template <class Compare>
0399 inline void MyList<T>::sort(Compare comp)
0400 {
0401     m_theList.sort(comp);
0402 }
0403 
0404 //------------------------------------------------------------------------------------------------------------------------------------------
0405 
0406 template <typename T>
0407 inline unsigned int MyList<T>::size() const
0408 {
0409     return m_theList.size();
0410 }
0411 
0412 //------------------------------------------------------------------------------------------------------------------------------------------
0413 
0414 template <typename T>
0415 inline bool MyList<T>::empty() const
0416 {
0417     return m_theList.empty();
0418 }
0419 
0420 //------------------------------------------------------------------------------------------------------------------------------------------
0421 
0422 template <typename T>
0423 inline void MyList<T>::clear()
0424 {
0425     m_theList.clear();
0426 }
0427 
0428 //------------------------------------------------------------------------------------------------------------------------------------------
0429 //------------------------------------------------------------------------------------------------------------------------------------------
0430 
0431 #define MANAGED_CONTAINER std::list
0432 
0433 typedef MANAGED_CONTAINER<const CaloHit *> CaloHitList;
0434 typedef MANAGED_CONTAINER<const Cluster *> ClusterList;
0435 typedef MANAGED_CONTAINER<const DetectorGap *> DetectorGapList;
0436 typedef MANAGED_CONTAINER<const LArTPC *> LArTPCList;
0437 typedef MANAGED_CONTAINER<const MCParticle *> MCParticleList;
0438 typedef MANAGED_CONTAINER<const ParticleFlowObject *> ParticleFlowObjectList;
0439 typedef MANAGED_CONTAINER<const ParticleFlowObject *> PfoList;
0440 typedef MANAGED_CONTAINER<const SubDetector *> SubDetectorList;
0441 typedef MANAGED_CONTAINER<const Track *> TrackList;
0442 typedef MANAGED_CONTAINER<const Vertex *> VertexList;
0443 
0444 typedef std::vector<const CaloHit *> CaloHitVector;
0445 typedef std::vector<const Cluster *> ClusterVector;
0446 typedef std::vector<const DetectorGap *> DetectorGapVector;
0447 typedef std::vector<const LArTPC *> LArTPCVector;
0448 typedef std::vector<const MCParticle *> MCParticleVector;
0449 typedef std::vector<const ParticleFlowObject *> ParticleFlowObjectVector;
0450 typedef std::vector<const ParticleFlowObject *> PfoVector;
0451 typedef std::vector<const SubDetector *> SubDetectorVector;
0452 typedef std::vector<const Track *> TrackVector;
0453 typedef std::vector<const Vertex *> VertexVector;
0454 
0455 typedef std::unordered_set<const CaloHit *> CaloHitSet;
0456 typedef std::unordered_set<const Cluster *> ClusterSet;
0457 typedef std::unordered_set<const DetectorGap *> DetectorGapSet;
0458 typedef std::unordered_set<const LArTPC *> LArTPCSet;
0459 typedef std::unordered_set<const MCParticle *> MCParticleSet;
0460 typedef std::unordered_set<const ParticleFlowObject *> ParticleFlowObjectSet;
0461 typedef std::unordered_set<const ParticleFlowObject *> PfoSet;
0462 typedef std::unordered_set<const SubDetector *> SubDetectorSet;
0463 typedef std::unordered_set<const Track *> TrackSet;
0464 typedef std::unordered_set<const Vertex *> VertexSet;
0465 
0466 typedef std::vector<int> IntVector;
0467 typedef std::vector<float> FloatVector;
0468 typedef std::vector<std::string> StringVector;
0469 typedef std::vector<CartesianVector> CartesianPointVector;
0470 typedef std::vector<TrackState> TrackStateVector;
0471 typedef std::vector<AlgorithmTool *> AlgorithmToolVector;
0472 
0473 typedef const void * Uid;
0474 typedef std::unordered_map<Uid, const MCParticle *> UidToMCParticleMap;
0475 typedef std::unordered_map<const MCParticle *, float> MCParticleWeightMap;
0476 typedef std::unordered_map<Uid, MCParticleWeightMap> UidToMCParticleWeightMap;
0477 typedef std::unordered_map<const Cluster *, const Track * > ClusterToTrackMap;
0478 typedef std::unordered_map<const Track *, const Cluster * > TrackToClusterMap;
0479 
0480 typedef std::set<std::string> StringSet;
0481 typedef std::map<std::string, float> PropertiesMap;
0482 typedef std::map<std::string, const SubDetector *> SubDetectorMap;
0483 typedef std::map<unsigned int, const LArTPC *> LArTPCMap;
0484 
0485 } // namespace pandora
0486 
0487 #endif // #ifndef PANDORA_INTERNAL_H