diff --git a/DDCore/include/DD4hep/Segmentations.h b/DDCore/include/DD4hep/Segmentations.h index 89b5e486bfd8eae03c659e05bfb46f29bed64978..4f75e77743456536ab72baee7ccab8c9e6211ac2 100644 --- a/DDCore/include/DD4hep/Segmentations.h +++ b/DDCore/include/DD4hep/Segmentations.h @@ -41,18 +41,12 @@ namespace DD4hep { * \version 1.0 * \ingroup DD4HEP_GEOMETRY */ - class SegmentationObject : public DDSegmentation::Segmentation { + class SegmentationObject /* : public DDSegmentation::Segmentation */ { public: typedef DDSegmentation::Segmentation BaseSegmentation; typedef DDSegmentation::Parameters Parameters; typedef DDSegmentation::Parameter Parameter; public: - /// determine the local position based on the cell ID - DDSegmentation::Vector3D position(const long64& cellID) const; - /// determine the cell ID based on the local position - long64 cellID(const DDSegmentation::Vector3D& localPosition, - const DDSegmentation::Vector3D& globalPosition, - const long64& volumeID) const; /// Standard constructor SegmentationObject(BaseSegmentation* s = 0); /// Default destructor @@ -78,6 +72,18 @@ namespace DD4hep { /// Set all parameters from an existing set of parameters void setParameters(const Parameters& parameters); + /** Segmentation interface */ + /// Determine the local position based on the cell ID + Position position(const CellID& cellID) const; + /// Determine the cell ID based on the position + CellID cellID(const Position& localPosition, + const Position& globalPosition, + const VolumeID& volumeID) const; + /// Determine the volume ID from the full cell ID by removing all local fields + VolumeID volumeID(const CellID& cellID) const; + /// Calculates the neighbours of the given cell ID and adds them to the list of neighbours + void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const; + /// Magic word to check object integrity unsigned long magic; /// Flag to use segmentation for hit positioning diff --git a/DDCore/src/Segmentations.cpp b/DDCore/src/Segmentations.cpp index 2398c75e69cb7378d936c8558bfa1b3eb0849988..2a4d53a10d9deca156024c2c5efaeb91196278c2 100644 --- a/DDCore/src/Segmentations.cpp +++ b/DDCore/src/Segmentations.cpp @@ -36,6 +36,8 @@ SegmentationObject::SegmentationObject(BaseSegmentation* s) : magic(magic_word()), useForHitPosition(0), detector(0), sensitive(0), segmentation(s) { + //s->backLink = this; + //this->backLink = this; InstanceCount::increment(this); } @@ -47,22 +49,11 @@ SegmentationObject::~SegmentationObject() { } } -/// determine the local position based on the cell ID -DDSegmentation::Vector3D SegmentationObject::position(const long64& cell) const { - return segmentation->position(cell); -} - -/// determine the cell ID based on the local position -long64 SegmentationObject::cellID(const DDSegmentation::Vector3D& localPosition, - const DDSegmentation::Vector3D& globalPosition, - const long64& volID) const { - return segmentation->cellID(localPosition, globalPosition, volID); -} - /// Access the encoding string string SegmentationObject::fieldDescription() const { return segmentation->fieldDescription(); } + /// Access the segmentation name const string& SegmentationObject::name() const { return segmentation->name(); @@ -107,6 +98,28 @@ void SegmentationObject::setParameters(const Parameters& params) { segmentation->setParameters(params); } +/// Determine the local position based on the cell ID +Position SegmentationObject::position(const CellID& cell) const { + return Position(segmentation->position(cell)); +} + +/// Determine the cell ID based on the position +CellID SegmentationObject::cellID(const Position& local, + const Position& global, + const VolumeID& volID) const { + return segmentation->cellID(local, global, volID); +} + +/// Determine the volume ID from the full cell ID by removing all local fields +VolumeID SegmentationObject::volumeID(const CellID& cell) const { + return segmentation->volumeID(cell); +} + +/// Calculates the neighbours of the given cell ID and adds them to the list of neighbours +void SegmentationObject::neighbours(const CellID& cell, std::set<CellID>& nb) const { + segmentation->neighbours(cell, nb); +} + /// Constructor to used when creating a new object Segmentation::Segmentation(const string& typ, const string& nam) : Handle<Implementation>() { diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 5299d7f21171ecf16e92e50dacf44320bfa2aa82..96ba65161d312fe93dbea67ecf7ab039d6a75686 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -626,10 +626,18 @@ template <> void Converter<Segmentation>::operator()(xml_h seg) const { */ template <> void Converter<Readout>::operator()(xml_h e) const { xml_h seg = e.child(_U(segmentation), false); + xml_h id = e.child(_U(id)); string name = e.attr<string>(_U(name)); Readout ro(name); printout(DEBUG, "Compact", "++ Converting readout structure: %s.",ro.name()); + if (id) { + // <id>system:6,barrel:3,module:4,layer:8,slice:5,x:32:-16,y:-16</id> + Ref_t idSpec = IDDescriptor(id.text()); + idSpec->SetName(ro.name()); + ro.setIDDescriptor(idSpec); + lcdd.addIDSpecification(idSpec); + } if (seg) { // Segmentation is not mandatory! SegmentationObject* object = 0; Converter<Segmentation> converter(lcdd,param,&object); @@ -640,14 +648,6 @@ template <> void Converter<Readout>::operator()(xml_h e) const { ro.setSegmentation(segment); } } - xml_h id = e.child(_U(id)); - if (id) { - // <id>system:6,barrel:3,module:4,layer:8,slice:5,x:32:-16,y:-16</id> - Ref_t idSpec = IDDescriptor(id.text()); - idSpec->SetName(ro.name()); - ro.setIDDescriptor(idSpec); - lcdd.addIDSpecification(idSpec); - } for(xml_coll_t colls(e,_U(hits_collections)); colls; ++colls) { string hits_key; if ( colls.hasAttr(_U(key)) ) hits_key = colls.attr<string>(_U(key)); diff --git a/DDSegmentation/include/DDSegmentation/Segmentation.h b/DDSegmentation/include/DDSegmentation/Segmentation.h index 1db44adca61eb6d19c78946b2fbd2a33e2e35a16..db21677e75aa9dccd31a089e14a6ed234ba33994 100644 --- a/DDSegmentation/include/DDSegmentation/Segmentation.h +++ b/DDSegmentation/include/DDSegmentation/Segmentation.h @@ -161,7 +161,9 @@ protected: mutable BitField64* _decoder; /// Keeps track of the decoder ownership bool _ownsDecoder; - +public: + /// DD4hep usage ONLY. Backlink to DD4hep segmentation + Segmentation* backLink; private: /// No copy constructor allowed Segmentation(const Segmentation&); diff --git a/DDSegmentation/src/Segmentation.cpp b/DDSegmentation/src/Segmentation.cpp index e9b037f8e8d95b04f42425e0a54301e3b9ce375a..ad97ea88f40bb71cee95655af460e719f75613b5 100644 --- a/DDSegmentation/src/Segmentation.cpp +++ b/DDSegmentation/src/Segmentation.cpp @@ -26,13 +26,13 @@ namespace DD4hep { /// Default constructor used by derived classes passing the encoding string Segmentation::Segmentation(const std::string& cellEncoding) : - _name("Segmentation"), _type("Segmentation"), _decoder(new BitField64(cellEncoding)), _ownsDecoder(true) { + _name("Segmentation"), _type("Segmentation"), _decoder(new BitField64(cellEncoding)), _ownsDecoder(true), backLink(0) { } /// Default constructor used by derived classes passing an existing decoder Segmentation::Segmentation(BitField64* newDecoder) : - _name("Segmentation"), _type("Segmentation"), _decoder(newDecoder), _ownsDecoder(false) { + _name("Segmentation"), _type("Segmentation"), _decoder(newDecoder), _ownsDecoder(false), backLink(0) { } /// Destructor