Warning, file /DD4hep/DDCore/src/Readout.cpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 #include <DD4hep/Readout.h>
0016 #include <DD4hep/detail/SegmentationsInterna.h>
0017 #include <DD4hep/detail/ObjectsInterna.h>
0018 #include <DD4hep/detail/Handle.inl>
0019 #include <DD4hep/InstanceCount.h>
0020 #include <DD4hep/DD4hepUnits.h>
0021 #include <DD4hep/Detector.h>
0022 #include <DD4hep/Printout.h>
0023 
0024 using namespace dd4hep;
0025 
0026 
0027 HitCollection::HitCollection(const HitCollection& c)
0028   : name(c.name), key(c.key), key_min(c.key_min), key_max(c.key_max)
0029 {
0030 }
0031 
0032 
0033 HitCollection::HitCollection(const std::string& n, const std::string& k, long k_min, long k_max)  
0034   : name(n), key(k), key_min(k_min), key_max(k_max)
0035 {
0036 }
0037 
0038 
0039 HitCollection& HitCollection::operator=(const HitCollection& c)   {
0040   if ( this != &c )   {
0041     name = c.name;
0042     key = c.key;
0043     key_min = c.key_min;
0044     key_max = c.key_max;
0045   }
0046   return *this;
0047 }
0048 
0049 
0050 Readout::Readout(const std::string& nam) {
0051   assign(new ReadoutObject(), nam, "readout");
0052 }
0053 
0054 
0055 size_t Readout::numCollections() const   {
0056   if ( isValid() ) {
0057     Object& ro = object<Object>();
0058     return ro.hits.size();
0059   }
0060   except("dd4hep::Readout","numCollections: Cannot access object data [Invalid Handle]");
0061   throw std::runtime_error("dd4hep: Readout");
0062 }
0063 
0064 
0065 std::vector<std::string> Readout::collectionNames()  const   {
0066   std::vector<std::string> colls;
0067   if ( isValid() ) {
0068     Object& ro = object<Object>();
0069     if ( !ro.hits.empty() )  {
0070       for(const auto& hit : ro.hits )
0071         colls.emplace_back(hit.name);
0072     }
0073     return colls;
0074   }
0075   except("dd4hep::Readout", "collectionsNames: Cannot access object data [Invalid Handle]");
0076   throw std::runtime_error("dd4hep: Readout");
0077 }
0078 
0079 
0080 std::vector<const HitCollection*> Readout::collections()  const   {
0081   std::vector<const HitCollection*> colls;
0082   if ( isValid() ) {
0083     Object& ro = object<Object>();
0084     if ( !ro.hits.empty() )  {
0085       for(const auto& hit : ro.hits )
0086         colls.emplace_back(&hit);
0087     }
0088     return colls;
0089   }
0090   except("dd4hep::Readout", "collections: Cannot access object data [Invalid Handle]");
0091   throw std::runtime_error("dd4hep: Readout");
0092 }
0093 
0094 
0095 void Readout::setIDDescriptor(const Ref_t& new_descriptor) const {
0096   if ( isValid() ) {                  
0097     if (new_descriptor.isValid()) {   
0098       data<Object>()->id = new_descriptor;
0099       Segmentation seg = data<Object>()->segmentation;
0100       IDDescriptor id  = new_descriptor;
0101       if ( seg.isValid() ) {
0102         seg.setDecoder(id.decoder());
0103       }
0104       return;
0105     }
0106   }
0107   except("dd4hep::Readout", "setIDDescriptor: Cannot assign ID descriptor [Invalid Handle]");
0108   throw std::runtime_error("dd4hep: Readout");
0109 }
0110 
0111 
0112 IDDescriptor Readout::idSpec() const {
0113   return object<Object>().id;
0114 }
0115 
0116 
0117 void Readout::setSegmentation(const Segmentation& seg) const {
0118   if ( isValid() ) {
0119     Object& ro = object<Object>();
0120     Segmentation::Object* e = ro.segmentation.ptr();
0121     if ( e && e != seg.ptr() ) {      
0122       delete e;                       
0123     }                                 
0124     if ( seg.isValid() ) {
0125       ro.segmentation = seg;
0126       return;
0127     }
0128   }
0129   except("dd4hep::Readout", "setSegmentation: Cannot assign segmentation [Invalid Handle]");
0130   throw std::runtime_error("dd4hep: Readout");
0131 }
0132 
0133 
0134 Segmentation Readout::segmentation() const {
0135   return object<Object>().segmentation;
0136 }
0137