File indexing completed on 2025-01-18 09:14:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef DETECTOR_DETECTORELEMENT_H
0016 #define DETECTOR_DETECTORELEMENT_H 1
0017
0018
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
0028
0029
0030 namespace dd4hep { namespace DDDB { class DDDBCatalog; }}
0031
0032
0033
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
0102 namespace detail {
0103
0104
0105 typedef dd4hep::detail::ConditionObject ConditionObject;
0106
0107
0108
0109
0110
0111
0112
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
0123 DE_CTORS_DEFAULT(DeObject);
0124 };
0125 }
0126
0127
0128 struct Keys {
0129 typedef dd4hep::Condition::key_type key_type;
0130 typedef dd4hep::Condition::itemkey_type itemkey_type;
0131
0132
0133 static const std::string staticKeyName;
0134
0135 static const itemkey_type staticKey;
0136
0137
0138 static const std::string deKeyName;
0139
0140 static const itemkey_type deKey;
0141
0142
0143 static const std::string alignmentsComputedKeyName;
0144
0145 static const key_type alignmentsComputedKey;
0146 };
0147 }
0148
0149
0150
0151 #include "Detector/DeStatic.h"
0152
0153
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
0165 const static_t& static_data() const;
0166
0167 base_t& base() { return *this; }
0168
0169 public:
0170
0171 DetectorStaticElement() = default;
0172
0173 DetectorStaticElement(const DetectorStaticElement&) = default;
0174
0175 DetectorStaticElement& operator=(const DetectorStaticElement&) = default;
0176
0177 DetectorStaticElement(const typename base_t::Object* p) : base_t(p) {}
0178
0179 template <typename Q> DetectorStaticElement(Q* p) : base_t(dd4hep::Handle<Q>(p)) {}
0180
0181
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
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
0195 static int classID() { return static_t::classID; }
0196
0197
0198 void print(int indent, int flg) const;
0199
0200
0201
0202 const ParameterMap::Parameters& params() const
0203 { return static_data().params(); }
0204
0205
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
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
0214 DeStaticElement child(DetElement de) const
0215 { return static_data().child(de); }
0216 };
0217
0218
0219
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
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
0231 typedef DetectorStaticElement<DeStaticElement> DeStatic;
0232 }
0233
0234
0235 #include "Detector/DeIOV.h"
0236
0237
0238 namespace gaudi {
0239
0240
0241
0242
0243
0244
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
0258 const static_t& static_data() const;
0259
0260 const iov_t& iovData() const;
0261
0262 base_t& base() { return *this; }
0263
0264 public:
0265
0266 DetectorElement() = default;
0267
0268 DetectorElement(const DetectorElement&) = default;
0269
0270 DetectorElement& operator=(const DetectorElement&) = default;
0271
0272 DetectorElement(const typename base_t::Object* p) : base_t(p) {}
0273
0274 template <typename Q> DetectorElement(Q* p) : base_t(dd4hep::Handle<Q>(p)) {}
0275
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
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
0288 static int classID() { return static_t::classID; }
0289
0290 void print(int indent, int flg) const;
0291
0292 static itemkey_type key(const std::string& value)
0293 { return dd4hep::ConditionKey::itemCode(value); }
0294
0295 static itemkey_type key(const char* value)
0296 { return dd4hep::ConditionKey::itemCode(value); }
0297
0298
0299
0300 int clsID() const
0301 { return static_data().clsID; }
0302
0303 DetElement detector() const
0304 { return static_data().detector; }
0305
0306 PlacedVolume geometry() const
0307 { return static_data().geometry; }
0308
0309 const ParameterMap& params() const
0310 { return static_data().parameters; }
0311
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
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
0318 DetElement parent() const
0319 { return static_data().detector.parent(); }
0320
0321 children_t children() const
0322 { return static_data().detector.children(); }
0323
0324
0325
0326 bool hasCondition(const std::string& nam) const
0327 { return iovData().condition(nam).isValid(); }
0328
0329 const Conditions& conditions() const
0330 { return iovData().conditions; }
0331
0332 Condition condition(const std::string& nam) const
0333 { return iovData().condition(nam, true); }
0334
0335 Condition condition(const std::string& nam, bool throw_if) const
0336 { return iovData().condition(nam, throw_if); }
0337
0338 Alignment detectorAlignment() const
0339 { return iovData().detectorAlignment; }
0340
0341 const VolumeAlignments& volumeAlignments() const
0342 { return iovData().volumeAlignments; }
0343
0344
0345 bool isInside(const XYZPoint& globalPoint) const
0346 { return iovData().isInside(static_data(), globalPoint); }
0347
0348
0349
0350 bool hasLVolume() const
0351 { return geometry().volume().isValid(); }
0352
0353 bool hasSupport() const
0354 { return detector().parent().isValid(); }
0355
0356
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
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
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
0382 template <typename TYPE> inline
0383 const typename DetectorElement<TYPE>::iov_t&
0384 DetectorElement<TYPE>::iovData() const
0385 { return *(this->TYPE::access()); }
0386
0387
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
0393 typedef DetectorElement<DeIOVElement> DeIOV;
0394 }
0395
0396 #endif