Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:49

0001 //==============================================================================
0002 //  AIDA Detector description implementation for LHCb
0003 //------------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 //  \author   Markus Frank
0011 //  \date     2018-03-08
0012 //  \version  1.0
0013 //
0014 //==============================================================================
0015 #ifndef DETECTOR_DETECTORELEMENT_H 
0016 #define DETECTOR_DETECTORELEMENT_H 1
0017 
0018 // Framework include files
0019 #include "DD4hep/Objects.h"
0020 #include "DD4hep/Printout.h"
0021 #include "DD4hep/DetElement.h"
0022 #include "DD4hep/detail/ConditionsInterna.h"
0023 #include "Math/Vector3D.h"
0024 #include "Math/Point3D.h"
0025 #include "Detector/ParameterMap.h"
0026 
0027 // C/C++ include files
0028 
0029 
0030 namespace dd4hep { namespace DDDB { class DDDBCatalog; }}
0031 
0032 
0033 /// Gaudi namespace declaration
0034 namespace gaudi   {
0035 
0036   typedef ROOT::Math::XYZPoint      XYZPoint;
0037   typedef ROOT::Math::XYZVector     XYZVector;
0038   typedef ROOT::Math::Translation3D Translation3D;
0039 
0040 #define DE_CONDITIONS_TYPEDEFS                              \
0041   public:                                                   \
0042   typedef dd4hep::DDDB::DDDBCatalog        Catalog;         \
0043   typedef ParameterMap::Parameter          Parameter;       \
0044   typedef dd4hep::DetElement               DetElement;      \
0045   typedef dd4hep::Condition                Condition;       \
0046   typedef dd4hep::ConditionsMap            ConditionsMap;   \
0047   typedef dd4hep::PlacedVolume             PlacedVolume;    \
0048   typedef dd4hep::Alignment                Alignment;       \
0049   typedef Condition::itemkey_type          itemkey_type;    \
0050   typedef std::map<itemkey_type,Condition> Conditions;      \
0051   typedef std::map<PlacedVolume,Alignment> VolumeAlignments
0052 
0053   using dd4hep::yes_no;
0054   using dd4hep::except;
0055   using dd4hep::printout;
0056   using dd4hep::DEBUG;
0057   using dd4hep::INFO;
0058   using dd4hep::ERROR;
0059   
0060 #define DE_CTORS_DEFAULT(X)                     \
0061   X() = default;                                \
0062   X(const X& c) = delete;                       \
0063   virtual ~X() = default;                       \
0064   X& operator=(const X& c) = delete
0065 
0066 #define DE_CTORS_HANDLE(X,B)                                    \
0067   X() = default;                                                \
0068   X(const X& c) = default;                                      \
0069   explicit X(Object* p) : B(p) {}                               \
0070   template <typename Q> X(const dd4hep::Handle<Q>& e) : B(e) {} \
0071   X& operator=(const X& c) = default;                           \
0072   X& operator=(Object* p)  { return (*this = X(p));  }          \
0073   ~X() = default
0074   
0075   namespace DE  {
0076     std::string indent(int level);
0077   }
0078   namespace DePrint {
0079     enum PrintFlags { BASICS     = 1<<1,
0080                       PARAMS     = 1<<2,
0081                       DETAIL     = 1<<4,
0082                       SPECIFIC   = 1<<5,
0083                       STATIC     = 1<<6,
0084                       ALIGNMENTS = 1<<7,
0085                       CHILDREN   = 1<<8,
0086                       ALL        = BASICS|PARAMS|DETAIL|SPECIFIC|STATIC|CHILDREN
0087     };
0088   }
0089   namespace DeInit {
0090     enum InitFlags  { FILLCACHE = 1,
0091                       INITIALIZED = 1<<15
0092     };
0093   }
0094   struct DeHelpers {
0095     DE_CONDITIONS_TYPEDEFS;
0096     enum { ALL = 1<<31 };
0097     template<typename T> static std::map<DetElement, T*>
0098     getChildConditions(ConditionsMap& m, DetElement de, itemkey_type key, int flags);
0099   };
0100   
0101   /// Gaudi::detail namespace declaration
0102   namespace detail   {
0103 
0104     /// We want to have the base in the local namespace
0105     typedef dd4hep::detail::ConditionObject ConditionObject;
0106     
0107     /// Generic Detector element data object combining static and iov data
0108     /**
0109      *
0110      *  \author  Markus Frank
0111      *  \date    2018-03-08
0112      *  \version  1.0
0113      */
0114     template <typename STATIC, typename IOV>
0115     class DeObject : public ConditionObject    {
0116       DE_CONDITIONS_TYPEDEFS;
0117       typedef STATIC   static_t;
0118       typedef IOV      iov_t;
0119       static_t         de_static;
0120       iov_t            de_iov;
0121     public:
0122       /// Standard constructors and assignment
0123       DE_CTORS_DEFAULT(DeObject);
0124     };
0125   }
0126 
0127   /// Static identifiers computed once. Use the hash code whenever possible!
0128   struct Keys  {
0129     typedef dd4hep::Condition::key_type     key_type;
0130     typedef dd4hep::Condition::itemkey_type itemkey_type;
0131     
0132     /// Static key name: "DetElement-Info-Static"
0133     static const std::string  staticKeyName;
0134     /// Static key: 32 bit hash of "DetElement-Info-Static". Must be unique for one DetElement
0135     static const itemkey_type staticKey;
0136 
0137     /// Static key name: "DetElement-Info-IOV"
0138     static const std::string  deKeyName;
0139     /// Static key: 32 bit hash of "DetElement-Info-IOV". Must be unique for one DetElement
0140     static const itemkey_type deKey;
0141 
0142     /// Static key name: "Alignments-Computed"
0143     static const std::string alignmentsComputedKeyName;
0144     /// Static key: 32 bit hash of "Alignments-Computed". Must be unique for the world
0145     static const key_type alignmentsComputedKey;
0146   };
0147 }      // End namespace gaudi
0148 
0149 
0150 /// ------------------- Generic handle layer for STATIC objects -----------------
0151 #include "Detector/DeStatic.h"
0152 
0153 /// Gaudi::detail namespace declaration
0154 namespace gaudi    {
0155 
0156   template<typename TYPE>
0157   class DetectorStaticElement : public TYPE {
0158     DE_CONDITIONS_TYPEDEFS;
0159     typedef DetectorStaticElement<TYPE>      self_t;
0160     typedef TYPE                             base_t;
0161     typedef typename TYPE::static_t          static_t;
0162     typedef typename DetElement::Children    children_t;
0163   protected:
0164     /// Static detelement accessor. Used internally - may be specialized for optimization
0165     const static_t& static_data()  const;
0166     /// Access to the base implementation
0167     base_t& base()  { return *this; }
0168 
0169   public:
0170     /// Standard constructor
0171     DetectorStaticElement() = default;
0172     /// Copy constructoe
0173     DetectorStaticElement(const DetectorStaticElement&) = default;
0174     /// Copy assignment
0175     DetectorStaticElement& operator=(const DetectorStaticElement&) = default;
0176     /// Constructor from base class pointer
0177     DetectorStaticElement(const typename base_t::Object* p) : base_t(p) {}
0178     /// Constructor from other polymorph pointers
0179     template <typename Q> DetectorStaticElement(Q* p) : base_t(dd4hep::Handle<Q>(p)) {}
0180 
0181     /// Constructor from other polymorph handle
0182     template <typename Q> DetectorStaticElement(const dd4hep::Handle<Q>& p) : base_t() {
0183       base() = p;
0184       if ( p.ptr() && !this->ptr() ) { this->bad_assignment(typeid(p),typeid(self_t)); }
0185     }
0186 
0187     /// Copy assignment from polymorph handle
0188     template <typename Q> DetectorStaticElement& operator=(const dd4hep::Handle<Q>& p) {
0189       base() = p;
0190       if ( p.ptr() && !this->ptr() ) { this->bad_assignment(typeid(p),typeid(self_t)); }
0191       return *this;
0192     }
0193 
0194     /// Access to the classID
0195     static int classID()                    { return static_t::classID;         }  
0196 
0197     /// Print the detector element's information to stdout. No-inline, allow specialization
0198     void print(int indent, int flg)  const;
0199 
0200     /** Simplification accessors. Do not check validity here   */
0201     /// Access parameters directory
0202     const ParameterMap::Parameters& params()  const
0203     {  return static_data().params();                                           }
0204 
0205     /// Access single parameter
0206     const ParameterMap::Parameter& parameter(const std::string& nam, bool throw_if_not_present=true)   const
0207     {  return static_data().parameter(nam, throw_if_not_present);               }
0208 
0209     /// Type dependent accessor to a named parameter
0210     template <typename T> T param(const std::string& nam, bool throw_if_not_present=true)   const
0211     {  return static_data().template parameter<T>(nam,throw_if_not_present);    }
0212 
0213     /// Access daughter elements: Static part
0214     DeStaticElement child(DetElement de)  const
0215     {  return static_data().child(de);                                          }
0216   };
0217   
0218   
0219   /// Static detelement accessor. Used internally - may be specialized for optimization
0220   template <typename TYPE> inline
0221   const typename DetectorStaticElement<TYPE>::static_t&
0222   DetectorStaticElement<TYPE>::static_data()  const
0223   {  return this->TYPE::staticData();                                           }
0224 
0225   /// Print the detector element's information to stdout. Allow specialization
0226   template <typename TYPE> inline
0227   void DetectorStaticElement<TYPE>::print(int indent, int flg)  const
0228   {  this->base_t::access()->print(indent, flg);                                }
0229 
0230   /// For the fully enabled object, we have to combine it with the generic stuff
0231   typedef  DetectorStaticElement<DeStaticElement>  DeStatic;
0232 }      // End namespace gaudi
0233 
0234 /// ------------------- Generic handle layer for IOV objects -------------------
0235 #include "Detector/DeIOV.h"
0236 
0237 /// Gaudi::detail namespace declaration
0238 namespace gaudi    {
0239   
0240   /// Main detector element class
0241   /**
0242    *  \author  Markus Frank
0243    *  \date    2018-03-08
0244    *  \version  1.0
0245    *
0246    */
0247   template<typename TYPE>
0248   class DetectorElement : public TYPE {
0249     DE_CONDITIONS_TYPEDEFS;
0250     typedef DetectorElement<TYPE>            self_t;
0251     typedef TYPE                             base_t;
0252     typedef typename TYPE::Object            iov_t;
0253     typedef typename TYPE::static_t          static_t;
0254     typedef typename DetElement::Children    children_t;
0255 
0256   private:
0257     /// Static detelement accessor. Used internally - may be specialized for optimization
0258     const static_t& static_data()  const;
0259     /// Access the time dependent data block. Used internally - may be specialized for optimization
0260     const iov_t& iovData()  const;
0261     /// Access to the base implementation
0262     base_t& base()  { return *this; }
0263 
0264   public: 
0265     /// Standard constructor
0266     DetectorElement() = default;
0267     /// Copy constructoe
0268     DetectorElement(const DetectorElement&) = default;
0269     /// Copy assignment
0270     DetectorElement& operator=(const DetectorElement&) = default;
0271     /// Constructor from base class pointer
0272     DetectorElement(const typename base_t::Object* p) : base_t(p) {}
0273     /// Constructor from other polymorph pointers
0274     template <typename Q> DetectorElement(Q* p) : base_t(dd4hep::Handle<Q>(p)) {}
0275     /// Constructor from other polymorph handle
0276     template <typename Q> DetectorElement(const dd4hep::Handle<Q>& p) : base_t() {
0277       base() = p;
0278       if ( p.ptr() && !this->ptr() ) { this->bad_assignment(typeid(p),typeid(self_t)); }
0279     }
0280     /// Copy assignment from polymorph handle
0281     template <typename Q> DetectorElement& operator=(const dd4hep::Handle<Q>& p) {
0282       base() = p;
0283       if ( p.ptr() && !this->ptr() ) { this->bad_assignment(typeid(p),typeid(self_t)); }
0284       return *this;
0285     }
0286 
0287     /// Access to the classID
0288     static int classID()                    { return static_t::classID;         }  
0289     /// Print the detector element's information to stdout
0290     void print(int indent, int flg)  const;
0291     /// Compute key value for caching
0292     static itemkey_type key(const std::string& value)
0293     {  return dd4hep::ConditionKey::itemCode(value);                            }
0294     /// Compute key value for caching
0295     static itemkey_type key(const char* value)
0296     {  return dd4hep::ConditionKey::itemCode(value);                            }
0297 
0298     /** Access to static detector element data                                */
0299     /// Detector element Class ID (real one from XML, not the enum!)
0300     int clsID()  const
0301     {  return static_data().clsID;                                              }
0302     /// Accessor to detector structure
0303     DetElement   detector() const
0304     {  return static_data().detector;                                           }
0305     /// Accessor to the geometry structure of this detector element
0306     PlacedVolume geometry() const
0307     {  return static_data().geometry;                                           }
0308     /// Accessor to the parameter map
0309     const ParameterMap& params()   const
0310     {  return static_data().parameters;                                         }
0311     /// Access single parameter
0312     const Parameter& parameter(const std::string& nam, bool throw_if_not_present=true)   const
0313     {   return params().parameter(nam, throw_if_not_present);                   }
0314     /// Type dependent accessor to a named parameter
0315     template <typename T> T param(const std::string& nam, bool throw_if_not_present=true)   const
0316     {   return parameter(nam, throw_if_not_present).template get<T>();          }
0317     /// Access the parent detector element
0318     DetElement parent()  const
0319     {   return static_data().detector.parent();                                 }
0320     /// Access the children detector elements
0321     children_t children()  const
0322     {   return static_data().detector.children();                               }
0323 
0324     /** Access to IOV dependent data                                           */
0325     /// Check if the condition called 'name' is in the list of conditionrefs.
0326     bool hasCondition(const std::string& nam) const
0327     {   return iovData().condition(nam).isValid();                              }
0328     /// Access all conditions which belong to this detector element
0329     const Conditions& conditions()  const
0330     {  return iovData().conditions;                                             }
0331     /// Return the SmartRef for the condition called 'name'. Throw exception on failure
0332     Condition condition(const std::string& nam) const
0333     {  return iovData().condition(nam, true);                                   }
0334     /// Return the SmartRef for the condition called 'name'. Throw exception if requested.
0335     Condition condition(const std::string& nam, bool throw_if) const
0336     {  return iovData().condition(nam, throw_if);                               }
0337     /// Access to the alignmant object to transformideal coordinates 
0338     Alignment detectorAlignment()   const
0339     {  return iovData().detectorAlignment;                                      }
0340     /// Access the volume alignments
0341     const VolumeAlignments& volumeAlignments()  const
0342     {  return iovData().volumeAlignments;                                       }
0343 
0344     /// helper member using IGeometryInfo::isInside
0345     bool isInside(const XYZPoint& globalPoint) const
0346     {  return iovData().isInside(static_data(), globalPoint);                   } 
0347 
0348     /** Access to more sophisticated geometry information                      */
0349     /// Check if the geometry is connected to a logical volume
0350     bool hasLVolume() const
0351     {  return geometry().volume().isValid();                                    }
0352     /// Check if the geometry is connected to a supporting parent detector element
0353     bool hasSupport() const
0354     {  return detector().parent().isValid();                                    }
0355 
0356     /// Access to transformation matrices
0357     const TGeoHMatrix& toLocalMatrix() const
0358     {  return iovData().toLocalMatrix;                                          }
0359     const TGeoHMatrix& toGlobalMatrix() const 
0360     {  return iovData().toGlobalMatrix();                                         }
0361     const TGeoHMatrix& toLocalMatrixNominal() const
0362     {  return iovData().toLocalMatrixNominal;                                   }
0363 
0364     /// Local -> Global and Global -> Local transformations
0365     XYZPoint toLocal( const XYZPoint& global ) const
0366     {  return iovData().toLocal(global);                                        }
0367     XYZPoint toGlobal( const XYZPoint& local ) const
0368     {  return iovData().toGlobal(local);                                        }
0369     XYZVector toLocal( const XYZVector& globalDirection ) const
0370     {  return iovData().toLocal(globalDirection);                               }
0371     XYZVector toGlobal( const XYZVector& localDirection  ) const
0372     {  return iovData().toGlobal(localDirection);                               }
0373   };
0374 
0375   /// Static detelement accessor. Used internally - may be specialized for optimization
0376   template <typename TYPE> inline
0377   const typename DetectorElement<TYPE>::static_t&
0378   DetectorElement<TYPE>::static_data()  const
0379   {  return this->TYPE::staticData();                                           }
0380 
0381   /// Access the time dependent data block. Used internally - may be specialized for optimization
0382   template <typename TYPE> inline
0383   const typename DetectorElement<TYPE>::iov_t&
0384   DetectorElement<TYPE>::iovData()  const
0385   {  return *(this->TYPE::access());                                            }
0386 
0387   /// Print the detector element's information to stdout. Allow specialization
0388   template <typename TYPE> inline
0389   void DetectorElement<TYPE>::print(int indent, int flg)  const
0390   {  this->base_t::access()->print(indent, flg);                                }
0391   
0392   /// For the fully enabled object, we have to combine it with the generic stuff
0393   typedef  DetectorElement<DeIOVElement>  DeIOV;
0394 }      // End namespace gaudi
0395 
0396 #endif