DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Readout.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Readout.h>
18 #include <DD4hep/detail/Handle.inl>
19 #include <DD4hep/InstanceCount.h>
20 #include <DD4hep/DD4hepUnits.h>
21 #include <DD4hep/Detector.h>
22 #include <DD4hep/Printout.h>
23 
24 using namespace dd4hep;
25 
28  : name(c.name), key(c.key), key_min(c.key_min), key_max(c.key_max)
29 {
30 }
31 
33 HitCollection::HitCollection(const std::string& n, const std::string& k, long k_min, long k_max)
34  : name(n), key(k), key_min(k_min), key_max(k_max)
35 {
36 }
37 
40  if ( this != &c ) {
41  name = c.name;
42  key = c.key;
43  key_min = c.key_min;
44  key_max = c.key_max;
45  }
46  return *this;
47 }
48 
50 Readout::Readout(const std::string& nam) {
51  assign(new ReadoutObject(), nam, "readout");
52 }
53 
55 size_t Readout::numCollections() const {
56  if ( isValid() ) {
57  Object& ro = object<Object>();
58  return ro.hits.size();
59  }
60  except("dd4hep::Readout","numCollections: Cannot access object data [Invalid Handle]");
61  throw std::runtime_error("dd4hep: Readout");
62 }
63 
65 std::vector<std::string> Readout::collectionNames() const {
66  std::vector<std::string> colls;
67  if ( isValid() ) {
68  Object& ro = object<Object>();
69  if ( !ro.hits.empty() ) {
70  for(const auto& hit : ro.hits )
71  colls.emplace_back(hit.name);
72  }
73  return colls;
74  }
75  except("dd4hep::Readout", "collectionsNames: Cannot access object data [Invalid Handle]");
76  throw std::runtime_error("dd4hep: Readout");
77 }
78 
80 std::vector<const HitCollection*> Readout::collections() const {
81  std::vector<const HitCollection*> colls;
82  if ( isValid() ) {
83  Object& ro = object<Object>();
84  if ( !ro.hits.empty() ) {
85  for(const auto& hit : ro.hits )
86  colls.emplace_back(&hit);
87  }
88  return colls;
89  }
90  except("dd4hep::Readout", "collections: Cannot access object data [Invalid Handle]");
91  throw std::runtime_error("dd4hep: Readout");
92 }
93 
95 void Readout::setIDDescriptor(const Ref_t& new_descriptor) const {
96  if ( isValid() ) { // The ID descriptor is NOT owned by the readout!
97  if (new_descriptor.isValid()) { // Do NOT delete!
98  data<Object>()->id = new_descriptor;
99  Segmentation seg = data<Object>()->segmentation;
100  IDDescriptor id = new_descriptor;
101  if ( seg.isValid() ) {
102  seg.setDecoder(id.decoder());
103  }
104  return;
105  }
106  }
107  except("dd4hep::Readout", "setIDDescriptor: Cannot assign ID descriptor [Invalid Handle]");
108  throw std::runtime_error("dd4hep: Readout");
109 }
110 
113  return object<Object>().id;
114 }
115 
117 void Readout::setSegmentation(const Segmentation& seg) const {
118  if ( isValid() ) {
119  Object& ro = object<Object>();
121  if ( e && e != seg.ptr() ) { // Remember:
122  delete e; // The segmentation is owned by the readout!
123  } // Need to delete the segmentation object
124  if ( seg.isValid() ) {
125  ro.segmentation = seg;
126  return;
127  }
128  }
129  except("dd4hep::Readout", "setSegmentation: Cannot assign segmentation [Invalid Handle]");
130  throw std::runtime_error("dd4hep: Readout");
131 }
132 
135  return object<Object>().segmentation;
136 }
137 
dd4hep::HitCollection::name
std::string name
Hit collection name.
Definition: ObjectsInterna.h:160
dd4hep::HitCollection::key_min
long key_min
Range values of the key is not empty.
Definition: ObjectsInterna.h:164
dd4hep::ReadoutObject::segmentation
Segmentation segmentation
Handle to the readout segmentation.
Definition: ObjectsInterna.h:185
Detector.h
dd4hep::HitCollection
Definition of the HitCollection parameters used by the Readout.
Definition: ObjectsInterna.h:157
dd4hep::ReadoutObject
Concrete object implementation of the Readout Handle.
Definition: ObjectsInterna.h:182
dd4hep::Readout::setSegmentation
void setSegmentation(const Segmentation &segment) const
Assign segmentation structure to readout.
Definition: Readout.cpp:117
dd4hep::HitCollection::key
std::string key
Discriminator key name from the <id> string.
Definition: ObjectsInterna.h:162
dd4hep::IDDescriptor
Class implementing the ID encoding of the detector response.
Definition: IDDescriptor.h:37
dd4hep::Handle< ReadoutObject >::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::Handle< NamedObject >
dd4hep::SegmentationObject
Implementation class supporting generic Segmentation of sensitive detectors.
Definition: SegmentationsInterna.h:46
dd4hep::Readout::collections
std::vector< const HitCollection * > collections() const
Access hit collections if present.
Definition: Readout.cpp:80
dd4hep::Readout::collectionNames
std::vector< std::string > collectionNames() const
Access explicit names of hit collections if present.
Definition: Readout.cpp:65
dd4hep::HitCollection::HitCollection
HitCollection()
Default constructor.
Definition: ObjectsInterna.h:166
dd4hep::HitCollection::key_max
long key_max
Definition: ObjectsInterna.h:164
dd4hep::Segmentation::setDecoder
void setDecoder(const BitFieldCoder *decoder) const
Set the underlying decoder.
Definition: Segmentations.cpp:109
dd4hep::Handle< ReadoutObject >::assign
void assign(Object *n, const std::string &nam, const std::string &title)
Assign a new named object. Note: object references must be managed by the user.
Readout.h
dd4hep::Readout::segmentation
Segmentation segmentation() const
Access segmentation structure.
Definition: Readout.cpp:134
dd4hep::Readout::setIDDescriptor
void setIDDescriptor(const Ref_t &spec) const
Assign IDDescription to readout structure.
Definition: Readout.cpp:95
SegmentationsInterna.h
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::Segmentation::segmentation
DDSegmentation::Segmentation * segmentation() const
Access to the base DDSegmentation object. WARNING: Deprecated call!
Definition: Segmentations.cpp:99
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
ObjectsInterna.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::HitCollection::operator=
HitCollection & operator=(const HitCollection &c)
Assignment operator.
Definition: Readout.cpp:39
dd4hep::Readout::numCollections
size_t numCollections() const
Access number of hit collections.
Definition: Readout.cpp:55
dd4hep::Segmentation
Handle class supporting generic Segmentations of sensitive detectors.
Definition: Segmentations.h:41
dd4hep::Readout::idSpec
IDDescriptor idSpec() const
Access IDDescription structure.
Definition: Readout.cpp:112
InstanceCount.h
dd4hep::Readout::Readout
Readout()=default
Default constructor.
DD4hepUnits.h
dd4hep::ReadoutObject::hits
std::vector< HitCollection > hits
Hit collection container (if defined)
Definition: ObjectsInterna.h:191
Printout.h