DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Readout.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
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/InstanceCount.h"
19 #include "DD4hep/DD4hepUnits.h"
20 #include "DD4hep/LCDD.h"
21 #include "DD4hep/Handle.inl"
22 
23 using namespace std;
24 using namespace DD4hep;
25 using namespace DD4hep::Geometry;
26 
28 HitCollection::HitCollection(const HitCollection& c)
29  : name(c.name), key(c.key), key_min(c.key_min), key_max(c.key_max)
30 {
31 }
32 
34 HitCollection::HitCollection(const string& n, const string& k, long k_min, long k_max)
35  : name(n), key(k), key_min(k_min), key_max(k_max)
36 {
37 }
38 
41  if ( this != &c ) {
42  name = c.name;
43  key = c.key;
44  key_min = c.key_min;
45  key_max = c.key_max;
46  }
47  return *this;
48 }
49 
51 Readout::Readout(const string& nam) {
52  assign(new ReadoutObject(), nam, "readout");
53 }
54 
56 size_t Readout::numCollections() const {
57  if ( isValid() ) {
58  Object& ro = object<Object>();
59  return ro.hits.size();
60  }
61  throw runtime_error("DD4hep: Readout::numCollections: Cannot access object data [Invalid Handle]");
62 }
63 
65 vector<string> Readout::collectionNames() const {
66  vector<string> colls;
67  if ( isValid() ) {
68  Object& ro = object<Object>();
69  if ( !ro.hits.empty() ) {
70  for(Object::Collections::const_iterator i=ro.hits.begin(); i!=ro.hits.end(); ++i)
71  colls.push_back((*i).name);
72  }
73  return colls;
74  }
75  throw runtime_error("DD4hep: Readout::collectionsNames: Cannot access object data [Invalid Handle]");
76 }
77 
79 vector<const HitCollection*> Readout::collections() const {
80  vector<const HitCollection*> colls;
81  if ( isValid() ) {
82  Object& ro = object<Object>();
83  if ( !ro.hits.empty() ) {
84  for(Object::Collections::const_iterator i=ro.hits.begin(); i!=ro.hits.end(); ++i)
85  colls.push_back(&(*i));
86  }
87  return colls;
88  }
89  throw runtime_error("DD4hep: Readout::collections: Cannot access object data [Invalid Handle]");
90 }
91 
93 void Readout::setIDDescriptor(const Ref_t& new_descriptor) const {
94  if ( isValid() ) { // The ID descriptor is NOT owned by the readout!
95  if (new_descriptor.isValid()) { // Do NOT delete!
96  data<Object>()->id = new_descriptor;
97  Segmentation seg = data<Object>()->segmentation;
98  IDDescriptor id = new_descriptor;
99  if ( seg.isValid() ) {
100  seg.setDecoder(id.decoder());
101  }
102  return;
103  }
104  }
105  throw runtime_error("DD4hep: Readout::setIDDescriptor: Cannot assign ID descriptor [Invalid Handle]");
106 }
107 
110  return object<Object>().id;
111 }
112 
114 void Readout::setSegmentation(const Segmentation& seg) const {
115  if ( isValid() ) {
116  Object& ro = object<Object>();
118  if ( e && e != seg.ptr() ) { // Remember:
119  delete e; // The segmentation is owned by the readout!
120  } // Need to delete the segmentation object
121  if ( seg.isValid() ) {
122  ro.segmentation = seg;
123  return;
124  }
125  }
126  throw runtime_error("DD4hep: Readout::setSegmentation: Cannot assign segmentation [Invalid Handle]");
127 }
128 
131  return object<Object>().segmentation;
132 }
133 
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
HitCollection()
Default constructor.
std::string key
Discriminator key name from the <id> string.
size_t numCollections() const
Access number of hit collections.
Definition: Readout.cpp:56
Readout()=default
Default constructor.
std::vector< const Collection * > collections() const
Access hit collections if present.
Definition: Readout.cpp:79
return e
Definition: Volumes.cpp:297
T * ptr() const
Access to the held object.
Definition: Handle.h:149
Collections hits
Hit collection container (if defined)
Segmentation segmentation
Handle to the readout segmentation.
void assign(Implementation *n, const std::string &nam, const std::string &title)
Assign a new named object. Note: object references must be managed by the user.
Definition: Handle.inl:27
IDDescriptor idSpec() const
Access IDDescription structure.
Definition: Readout.cpp:109
Handle class supporting generic Segmentation of sensitive detectors.
Definition: Segmentations.h:43
void setIDDescriptor(const Ref_t &spec) const
Assign IDDescription to readout structure.
Definition: Readout.cpp:93
Segmentation segmentation() const
Access segmentation structure.
Definition: Readout.cpp:130
std::vector< std::string > collectionNames() const
Access explicit names of hit collections if present.
Definition: Readout.cpp:65
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
Definition: Handle.h:176
long key_min
Range values of the key is not empty.
HitCollection & operator=(const HitCollection &c)
Assignment operator.
Definition: Readout.cpp:40
Definition of the HitCollection parameters used by the Readout.
Concrete object implementation of the Readout Handle.
std::string name
Hit collection name.
void setSegmentation(const Segmentation &segment) const
Assign segmentation structure to readout.
Definition: Readout.cpp:114
Class implementing the ID encoding of detector response.
Definition: IDDescriptor.h:40