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/PandoraInputTypes.h
0003  * 
0004  *  @brief  Header file for pandora input types and associated external typedefs exposed via the PandoraApi
0005  * 
0006  *  $Log: $
0007  */
0008 #ifndef PANDORA_INPUT_TYPES_H
0009 #define PANDORA_INPUT_TYPES_H 1
0010 
0011 #include "Objects/CartesianVector.h"
0012 #include "Objects/TrackState.h"
0013 
0014 #include "Pandora/PandoraInternal.h"
0015 #include "Pandora/PandoraEnumeratedTypes.h"
0016 #include "Pandora/StatusCodes.h"
0017 
0018 #include <cmath>
0019 #include <string>
0020 #include <vector>
0021 
0022 namespace pandora
0023 {
0024 
0025 /**
0026  *  @brief  PandoraInputType template class
0027  */
0028 template <typename T>
0029 class PandoraInputType
0030 {
0031 public:
0032     /**
0033      *  @brief  Default constructor
0034      */
0035     PandoraInputType();
0036 
0037     /**
0038      *  @brief  Destructor
0039      */
0040     ~PandoraInputType();
0041 
0042     /**
0043      *  @brief  Constructor
0044      *
0045      *  @param  t the initial value
0046      */
0047     PandoraInputType(const T &t);
0048 
0049     /**
0050      *  @brief  Copy constructor (EXPENSIVE WITH LARGE OBJECTS)
0051      * 
0052      *  @param  rhs the initial pandora type
0053      */
0054     PandoraInputType(const PandoraInputType<T> &rhs);
0055 
0056     /**
0057      *  @brief  Set the value held by the pandora type
0058      *
0059      *  @param  t the value
0060      */
0061     void Set(const T &t);
0062 
0063     /**
0064      *  @brief  Get the value held by the pandora type
0065      *
0066      *  @return the value
0067      */
0068     const T &Get() const;
0069 
0070     /**
0071      *  @brief  Reset the pandora type
0072      */   
0073     void Reset();
0074 
0075     /**
0076      *  @brief  Whether the pandora type is initialized
0077      *
0078      *  @return boolean
0079      */
0080     bool IsInitialized() const;
0081 
0082     /**
0083      *  @brief  Assignment operator for the pandora type
0084      * 
0085      *  @return whether assignment succeeded
0086      */
0087     bool operator= (const T &rhs); 
0088 
0089     /**
0090      *  @brief  Assignment operator for parent pandora type (EXPENSIVE WITH LARGE OBJECTS)
0091      * 
0092      *  @throw  status code exception
0093      */   
0094     bool operator= (const PandoraInputType<T> &rhs);
0095 
0096 private:
0097     /**
0098      *  @brief  Whether pandora type is valid (not inf or nan)
0099      * 
0100      *  @return boolean
0101      */
0102     bool IsValid(const T &t) const;
0103 
0104     T      *m_pValue;           ///< Address of the actual value being held by the pandora type
0105     bool    m_isInitialized;    ///< Whether the pandora type is initialized
0106 };
0107 
0108 //------------------------------------------------------------------------------------------------------------------------------------------
0109 
0110 typedef PandoraInputType<unsigned int> InputUInt;
0111 typedef PandoraInputType<int> InputInt;
0112 typedef PandoraInputType<float> InputFloat;
0113 typedef PandoraInputType<const void *> InputAddress;
0114 typedef PandoraInputType<bool> InputBool;
0115 typedef PandoraInputType<std::string> InputString;
0116 
0117 typedef PandoraInputType<CellGeometry> InputCellGeometry;
0118 typedef PandoraInputType<HitRegion> InputHitRegion;
0119 typedef PandoraInputType<HitType> InputHitType;
0120 typedef PandoraInputType<LineGapType> InputLineGapType;
0121 typedef PandoraInputType<MCParticleType> InputMCParticleType;
0122 typedef PandoraInputType<SubDetectorType> InputSubDetectorType;
0123 typedef PandoraInputType<VertexLabel> InputVertexLabel;
0124 typedef PandoraInputType<VertexType> InputVertexType;
0125 
0126 typedef PandoraInputType<CartesianVector> InputCartesianVector;
0127 typedef PandoraInputType<TrackState> InputTrackState;
0128 typedef PandoraInputType<const Track *> InputTrackAddress;
0129 
0130 typedef std::vector<const void *> CaloHitAddressList, TrackAddressList;
0131 typedef std::vector<CaloHitAddressList> ClusterAddressList;
0132 
0133 //------------------------------------------------------------------------------------------------------------------------------------------
0134 //------------------------------------------------------------------------------------------------------------------------------------------
0135 
0136 template <typename T>
0137 inline PandoraInputType<T>::PandoraInputType() :
0138     m_pValue(nullptr),
0139     m_isInitialized(false)
0140 {
0141 }
0142 
0143 //------------------------------------------------------------------------------------------------------------------------------------------
0144 
0145 template <typename T>
0146 inline PandoraInputType<T>::~PandoraInputType()
0147 {
0148     if (nullptr != m_pValue)
0149         delete m_pValue;
0150 }
0151 
0152 //------------------------------------------------------------------------------------------------------------------------------------------
0153 
0154 template <typename T>
0155 inline PandoraInputType<T>::PandoraInputType(const T &t) :
0156     m_pValue(new T(t)),
0157     m_isInitialized(true)
0158 {
0159 }
0160 
0161 //------------------------------------------------------------------------------------------------------------------------------------------
0162 
0163 template <typename T>
0164 inline PandoraInputType<T>::PandoraInputType(const PandoraInputType<T> &rhs) :
0165     m_pValue(nullptr),
0166     m_isInitialized(rhs.m_isInitialized)
0167 {
0168     if (rhs.m_isInitialized)
0169         m_pValue = new T(*rhs.m_pValue);
0170 }
0171 
0172 //------------------------------------------------------------------------------------------------------------------------------------------
0173 
0174 template <typename T>
0175 inline void PandoraInputType<T>::Set(const T &t)
0176 {
0177     if (m_isInitialized)
0178         delete m_pValue;
0179 
0180     if (!this->IsValid(t))
0181         throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
0182 
0183     m_pValue = new T(t);
0184     m_isInitialized = true;
0185 }
0186 
0187 //------------------------------------------------------------------------------------------------------------------------------------------
0188 
0189 template <typename T>
0190 inline const T &PandoraInputType<T>::Get() const
0191 {
0192     if (!m_isInitialized)
0193         throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
0194 
0195     return *m_pValue;
0196 }
0197 
0198 //------------------------------------------------------------------------------------------------------------------------------------------
0199 
0200 template <typename T>
0201 inline void PandoraInputType<T>::Reset()
0202 {
0203     if (nullptr != m_pValue)
0204         delete m_pValue;
0205 
0206     m_isInitialized = false;
0207     m_pValue = nullptr;
0208 }
0209 
0210 //------------------------------------------------------------------------------------------------------------------------------------------
0211 
0212 template <typename T>
0213 inline bool PandoraInputType<T>::IsInitialized() const
0214 {
0215     return m_isInitialized;
0216 }
0217 
0218 //------------------------------------------------------------------------------------------------------------------------------------------
0219 
0220 template <typename T>
0221 inline bool PandoraInputType<T>::operator= (const T &rhs)
0222 {
0223     this->Set(rhs);
0224     return m_isInitialized;
0225 }
0226 
0227 //------------------------------------------------------------------------------------------------------------------------------------------
0228 
0229 template <typename T>
0230 inline bool PandoraInputType<T>::operator= (const PandoraInputType<T> &rhs)
0231 {
0232     if (this == &rhs)
0233         return m_isInitialized;
0234 
0235     if (rhs.m_isInitialized)
0236     {
0237         this->Set(*rhs.m_pValue);
0238     }
0239     else
0240     {
0241         this->Reset();
0242     }
0243 
0244     return m_isInitialized;
0245 }
0246 
0247 //------------------------------------------------------------------------------------------------------------------------------------------
0248 
0249 template <typename T>
0250 inline bool PandoraInputType<T>::IsValid(const T &t) const
0251 {
0252     return !(std::isnan(t) || std::isinf(t));
0253 }
0254 
0255 template <>
0256 inline bool PandoraInputType<const void *>::IsValid(const void *const &) const
0257 {
0258     return true;
0259 }
0260 
0261 template <>
0262 inline bool PandoraInputType<const CaloHit *>::IsValid(const CaloHit *const &) const
0263 {
0264     return true;
0265 }
0266 
0267 template <>
0268 inline bool PandoraInputType<const Track *>::IsValid(const Track *const &) const
0269 {
0270     return true;
0271 }
0272 
0273 template <>
0274 inline bool PandoraInputType<CellGeometry>::IsValid(const CellGeometry &t) const
0275 {
0276     return !(std::isnan(static_cast<unsigned int>(t)) || std::isinf(static_cast<unsigned int>(t)));
0277 }
0278 
0279 template <>
0280 inline bool PandoraInputType<HitRegion>::IsValid(const HitRegion &t) const
0281 {
0282     return !(std::isnan(static_cast<unsigned int>(t)) || std::isinf(static_cast<unsigned int>(t)));
0283 }
0284 
0285 template <>
0286 inline bool PandoraInputType<HitType>::IsValid(const HitType &t) const
0287 {
0288     return !(std::isnan(static_cast<unsigned int>(t)) || std::isinf(static_cast<unsigned int>(t)));
0289 }
0290 
0291 template <>
0292 inline bool PandoraInputType<LineGapType>::IsValid(const LineGapType &t) const
0293 {
0294     return !(std::isnan(static_cast<unsigned int>(t)) || std::isinf(static_cast<unsigned int>(t)));
0295 }
0296 
0297 template <>
0298 inline bool PandoraInputType<MCParticleType>::IsValid(const MCParticleType &t) const
0299 {
0300     return !(std::isnan(static_cast<unsigned int>(t)) || std::isinf(static_cast<unsigned int>(t)));
0301 }
0302 
0303 template <>
0304 inline bool PandoraInputType<SubDetectorType>::IsValid(const SubDetectorType &t) const
0305 {
0306     return !(std::isnan(static_cast<unsigned int>(t)) || std::isinf(static_cast<unsigned int>(t)));
0307 }
0308 
0309 template <>
0310 inline bool PandoraInputType<VertexLabel>::IsValid(const VertexLabel &t) const
0311 {
0312     return !(std::isnan(static_cast<unsigned int>(t)) || std::isinf(static_cast<unsigned int>(t)));
0313 }
0314 
0315 template <>
0316 inline bool PandoraInputType<VertexType>::IsValid(const VertexType &t) const
0317 {
0318     return !(std::isnan(static_cast<unsigned int>(t)) || std::isinf(static_cast<unsigned int>(t)));
0319 }
0320 
0321 template <>
0322 inline bool PandoraInputType<std::string>::IsValid(const std::string &t) const
0323 {
0324     return !t.empty();
0325 }
0326 
0327 template <>
0328 inline bool PandoraInputType<CartesianVector>::IsValid(const CartesianVector &t) const
0329 {
0330     return !(std::isnan(t.GetX()) || std::isnan(t.GetY()) || std::isnan(t.GetZ()) ||
0331         std::isinf(t.GetX()) || std::isinf(t.GetY()) || std::isinf(t.GetZ()));
0332 }
0333 
0334 template <>
0335 inline bool PandoraInputType<TrackState>::IsValid(const TrackState &t) const
0336 {
0337     const CartesianVector &p(t.GetPosition());
0338     const CartesianVector &m(t.GetMomentum());
0339 
0340     return !(std::isnan(p.GetX()) || std::isnan(p.GetY()) || std::isnan(p.GetZ()) ||
0341         std::isinf(p.GetX()) || std::isinf(p.GetY()) || std::isinf(p.GetZ()) ||
0342         std::isnan(m.GetX()) || std::isnan(m.GetY()) || std::isnan(m.GetZ()) ||
0343         std::isinf(m.GetX()) || std::isinf(m.GetY()) || std::isinf(m.GetZ()));
0344 }
0345 
0346 } // namespace pandora
0347 
0348 #endif // #ifndef PANDORA_INPUT_TYPES_H