File indexing completed on 2025-01-18 09:13:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_DETELEMENT_H
0014 #define DD4HEP_DETELEMENT_H
0015
0016
0017 #include <DD4hep/Handle.h>
0018 #include <DD4hep/Callback.h>
0019 #include <DD4hep/Objects.h>
0020 #include <DD4hep/Volumes.h>
0021 #include <DD4hep/Readout.h>
0022 #include <DD4hep/Alignments.h>
0023 #include <DD4hep/Segmentations.h>
0024 #include <DD4hep/ObjectExtensions.h>
0025
0026
0027 #include <map>
0028 #include <typeinfo>
0029
0030
0031 namespace dd4hep {
0032
0033
0034 class Detector;
0035 class DetElementObject;
0036 class SensitiveDetectorObject;
0037
0038
0039
0040
0041
0042
0043
0044 class SensitiveDetector: public Handle<SensitiveDetectorObject> {
0045 public:
0046
0047
0048 SensitiveDetector() : Handle<SensitiveDetectorObject>() { }
0049
0050
0051 SensitiveDetector(Object* obj_pointer)
0052 : Handle<SensitiveDetectorObject>(obj_pointer) { }
0053
0054
0055 SensitiveDetector(Handle<SensitiveDetectorObject>&& sd)
0056 : Handle<SensitiveDetectorObject>(sd) { }
0057
0058
0059 SensitiveDetector(const Handle<SensitiveDetectorObject>& sd)
0060 : Handle<SensitiveDetectorObject>(sd) { }
0061
0062
0063 SensitiveDetector(SensitiveDetector&& sd) = default;
0064
0065
0066 SensitiveDetector(const SensitiveDetector& sd) = default;
0067
0068
0069 template <typename Q> SensitiveDetector(const Handle<Q>& e)
0070 : Handle<SensitiveDetectorObject>(e) { }
0071
0072
0073 SensitiveDetector(const std::string& name, const std::string& type = "sensitive");
0074
0075
0076 SensitiveDetector& operator=(SensitiveDetector&& sd) = default;
0077
0078
0079 SensitiveDetector& operator=(const SensitiveDetector& sd) = default;
0080
0081
0082 template <typename T> bool operator ==(const Handle<T>& e) const {
0083 return ptr() == e.ptr();
0084 }
0085
0086 template <typename T> bool operator !=(const Handle<T>& e) const {
0087 return ptr() != e.ptr();
0088 }
0089
0090
0091 std::string type() const;
0092
0093
0094 SensitiveDetector& setType(const std::string& typ);
0095
0096
0097 SensitiveDetector& setVerbose(bool value);
0098
0099
0100 bool verbose() const;
0101
0102
0103 SensitiveDetector& setCombineHits(bool value);
0104
0105
0106 bool combineHits() const;
0107
0108
0109 SensitiveDetector& setHitsCollection(const std::string& spec);
0110
0111
0112 const std::string& hitsCollection() const;
0113
0114
0115 SensitiveDetector& setReadout(Readout readout);
0116
0117
0118 Readout readout() const;
0119
0120
0121 IDDescriptor idSpec() const;
0122
0123
0124 SensitiveDetector& setEnergyCutoff(double value);
0125
0126
0127 double energyCutoff() const;
0128
0129
0130 SensitiveDetector& setRegion(Region reg);
0131
0132
0133 Region region() const;
0134
0135
0136 SensitiveDetector& setLimitSet(LimitSet limits);
0137
0138
0139 LimitSet limits() const;
0140
0141
0142 void* addExtension(unsigned long long int key, ExtensionEntry* entry) const;
0143
0144
0145 void* extension(unsigned long long int key) const;
0146
0147
0148 void* extension(unsigned long long int key, bool alert) const;
0149
0150
0151 template <typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) const {
0152 return (IFACE*) this->addExtension(detail::typeHash64<IFACE>(),
0153 new detail::DeleteExtension<IFACE,CONCRETE>(c));
0154 }
0155
0156
0157 template <typename IFACE> IFACE* extension() const {
0158 return (IFACE*) this->extension(detail::typeHash64<IFACE>());
0159 }
0160 };
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 class DetElement: public Handle<DetElementObject> {
0189 public:
0190
0191
0192
0193
0194
0195
0196 class Processor {
0197 public:
0198
0199 Processor();
0200
0201 virtual ~Processor();
0202
0203 virtual int processElement(DetElement detector) = 0;
0204 };
0205
0206 typedef std::map<std::string, DetElement> Children;
0207
0208 enum CopyParameters {
0209 COPY_NONE = 0,
0210 COPY_PLACEMENT = 1 << 0,
0211 COPY_PARENT = 1 << 1,
0212 COPY_ALIGNMENT = 1 << 2,
0213 PROPAGATE_PARENT_ID = 1 << 3,
0214 LAST
0215 };
0216
0217 enum UpdateParam {
0218 CONDITIONS_CHANGED = 1<<0,
0219 PLACEMENT_CHANGED = 1<<1,
0220 SOMETHING_CHANGED = 1<<2,
0221 PLACEMENT_ELEMENT = 1<<20,
0222 PLACEMENT_HIGHEST = 1<<21,
0223 PLACEMENT_DETECTOR = 1<<22,
0224 PLACEMENT_NONE
0225 };
0226
0227
0228 void check(bool condition, const std::string& msg) const;
0229
0230 protected:
0231
0232
0233
0234
0235
0236
0237
0238
0239 template <typename Q, typename T> class DetElementExtension : public ExtensionEntry {
0240 protected:
0241 T* ptr = 0;
0242 mutable Q* iface = 0;
0243 public:
0244
0245 DetElementExtension() = delete;
0246
0247 DetElementExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
0248
0249 DetElementExtension(const DetElementExtension& copy) = default;
0250
0251 DetElementExtension& operator=(const DetElementExtension& copy) = default;
0252
0253 virtual ~DetElementExtension() = default;
0254
0255 T* copy(DetElement de) const { return new T(*ptr,de); }
0256
0257 virtual void destruct() const override { delete ptr; }
0258
0259 virtual void* object() const override
0260 { return iface ? iface : (iface=dynamic_cast<Q*>(ptr)); }
0261
0262 virtual void* copy(void* det) const override
0263 { return copy(DetElement((Object*)det)); }
0264
0265 virtual ExtensionEntry* clone(void* det) const override
0266 { return new DetElementExtension<Q,T>((T*)this->copy(det)); }
0267
0268 virtual unsigned long long int hash64() const override
0269 { return detail::typeHash64<Q>(); }
0270 };
0271
0272
0273 void i_addUpdateCall(unsigned int callback_type, const Callback& callback) const;
0274
0275 public:
0276
0277
0278 DetElement() = default;
0279
0280
0281 DetElement(DetElement&& e) = default;
0282
0283
0284 DetElement(const DetElement& e) = default;
0285
0286
0287 DetElement(Object* obj) : Handle<DetElementObject>(obj) { }
0288
0289
0290 DetElement(Object* obj, const std::string& name, const std::string& type);
0291
0292
0293 template <typename Q> DetElement(const Handle<Q>& e) : Handle<DetElementObject>(e) {}
0294
0295
0296 DetElement(NamedObject* obj) : Handle<DetElementObject>(obj) { }
0297
0298 #ifdef __MAKECINT__
0299
0300 DetElement(const Ref_t& e) : Handle<DetElementObject>(e) { }
0301 #endif
0302
0303 DetElement(const std::string& name, const std::string& type, int id);
0304
0305
0306 DetElement(const std::string& name, int id);
0307
0308
0309 DetElement(DetElement parent, const std::string& name, int id);
0310
0311
0312 DetElement& operator=(DetElement&& sd) = default;
0313
0314 DetElement& operator=(const DetElement& e) = default;
0315
0316
0317 Object& _data() const {
0318 return object<Object>();
0319 }
0320
0321
0322 bool operator <(const DetElement e) const {
0323 return ptr() < e.ptr();
0324 }
0325
0326 template <typename T> bool operator ==(const Handle<T>& e) const {
0327 return ptr() == e.ptr();
0328 }
0329
0330 template <typename T> bool operator !=(const Handle<T>& e) const {
0331 return ptr() != e.ptr();
0332 }
0333
0334
0335 DetElement clone(int flag) const;
0336
0337
0338 DetElement clone(const std::string& new_name) const;
0339
0340
0341 DetElement clone(const std::string& new_name, int new_id) const;
0342
0343
0344 std::pair<DetElement,Volume> reflect(const std::string& new_name) const;
0345
0346
0347 std::pair<DetElement,Volume> reflect(const std::string& new_name, int new_id) const;
0348
0349 std::pair<DetElement,Volume> reflect(const std::string& new_name, int new_id, SensitiveDetector sd) const;
0350
0351
0352 void* addExtension(ExtensionEntry* entry) const;
0353
0354
0355 void* extension(unsigned long long int key, bool alert) const;
0356
0357
0358 template <typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) const {
0359 CallbackSequence::checkTypes(typeid(IFACE), typeid(CONCRETE), dynamic_cast<IFACE*>(c));
0360 return (IFACE*) this->addExtension(new DetElementExtension<IFACE,CONCRETE>(c));
0361 }
0362
0363 template <typename IFACE> IFACE* extension() const {
0364 return (IFACE*) this->extension(detail::typeHash64<IFACE>(),true);
0365 }
0366
0367 template <typename IFACE> IFACE* extension(bool alert) const {
0368 return (IFACE*) this->extension(detail::typeHash64<IFACE>(),alert);
0369 }
0370
0371 template <typename Q, typename T>
0372 void callAtUpdate(unsigned int typ, Q* pointer,
0373 void (T::*pmf)(unsigned long typ, DetElement& det, void* opt_par)) const
0374 {
0375 CallbackSequence::checkTypes(typeid(T), typeid(Q), dynamic_cast<T*>(pointer));
0376 i_addUpdateCall(typ, Callback(pointer).make(pmf));
0377 }
0378
0379 void removeAtUpdate(unsigned int type, void* pointer) const;
0380
0381
0382 int id() const;
0383
0384 DetElement& setCombineHits(bool value, SensitiveDetector& sens);
0385
0386 bool combineHits() const;
0387
0388
0389
0390
0391 std::string type() const;
0392
0393 DetElement& setType(const std::string& typ);
0394
0395
0396 unsigned int typeFlag() const;
0397
0398
0399 DetElement& setTypeFlag(unsigned int types);
0400
0401
0402 unsigned int key() const;
0403
0404 int level() const;
0405
0406 const std::string& path() const;
0407
0408 const std::string& placementPath() const;
0409
0410
0411 DetElement& setAttributes(const Detector& description,
0412 const Volume& volume,
0413 const std::string& region,
0414 const std::string& limits,
0415 const std::string& vis);
0416
0417
0418 DetElement& setVisAttributes(const Detector& description, const std::string& name, const Volume& volume);
0419
0420 DetElement& setRegion(const Detector& description, const std::string& name, const Volume& volume);
0421
0422 DetElement& setLimitSet(const Detector& description, const std::string& name, const Volume& volume);
0423
0424
0425 Volume volume() const;
0426
0427 Solid solid() const;
0428
0429
0430
0431
0432
0433
0434 PlacedVolume placement() const;
0435
0436
0437
0438
0439
0440 PlacedVolume idealPlacement() const;
0441
0442 DetElement& setPlacement(const PlacedVolume& volume);
0443
0444 VolumeID volumeID() const;
0445
0446
0447 DetElement& add(DetElement sub_element);
0448
0449 const Children& children() const;
0450
0451 DetElement child(const std::string& name) const;
0452
0453 DetElement child(const std::string& child_name, bool throw_if_not_found) const;
0454
0455 DetElement parent() const;
0456
0457 DetElement world() const;
0458
0459
0460 Alignment nominal() const;
0461
0462 Alignment survey() const;
0463 };
0464 }
0465
0466 #include <DD4hep/AlignmentData.h>
0467
0468 #endif