Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:02

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
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 /// Copy constructor
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 /// Initializing constructor
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 /// Assignment operator
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 /// Initializing constructor to create a new object
0050 Readout::Readout(const std::string& nam) {
0051   assign(new ReadoutObject(), nam, "readout");
0052 }
0053 
0054 /// Access number of hit collections
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 /// Access names of hit collections
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 /// Access hit collectionsy
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 /// Assign IDDescription to readout structure
0095 void Readout::setIDDescriptor(const Ref_t& new_descriptor) const {
0096   if ( isValid() ) {                  // The ID descriptor is NOT owned by the readout!
0097     if (new_descriptor.isValid()) {   // Do NOT delete!
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 /// Access IDDescription structure
0112 IDDescriptor Readout::idSpec() const {
0113   return object<Object>().id;
0114 }
0115 
0116 /// Assign segmentation structure to readout
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() ) {      // Remember:
0122       delete e;                       // The segmentation is owned by the readout!
0123     }                                 // Need to delete the segmentation object
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 /// Access segmentation structure
0134 Segmentation Readout::segmentation() const {
0135   return object<Object>().segmentation;
0136 }
0137