From bd0730c022bf7998c327aa8a9c1bb15f03d825b5 Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Mon, 1 Apr 2019 17:02:00 +0200 Subject: [PATCH] Improve const-ness of detector object in DDG4 --- DDCore/include/DD4hep/Detector.h | 2 +- DDCore/include/DD4hep/VolumeManager.h | 4 ++-- DDCore/src/DetectorImp.cpp | 2 +- DDCore/src/DetectorImp.h | 2 +- DDCore/src/VolumeManager.cpp | 16 ++++++++-------- DDG4/include/DDG4/Geant4Converter.h | 4 ++-- DDG4/include/DDG4/Geant4Mapping.h | 6 +++--- DDG4/include/DDG4/Geant4VolumeManager.h | 2 +- DDG4/src/Geant4Converter.cpp | 4 ++-- DDG4/src/Geant4Mapping.cpp | 4 ++-- DDG4/src/Geant4VolumeManager.cpp | 6 +++--- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/DDCore/include/DD4hep/Detector.h b/DDCore/include/DD4hep/Detector.h index 95a57da98..ee6094646 100644 --- a/DDCore/include/DD4hep/Detector.h +++ b/DDCore/include/DD4hep/Detector.h @@ -286,7 +286,7 @@ namespace dd4hep { /// Stupid legacy method virtual void dump() const = 0; /// Manipulate geometry using factory converter - virtual long apply(const char* factory, int argc, char** argv) = 0; + virtual long apply(const char* factory, int argc, char** argv) const = 0; /// Add an extension object to the detector element (low level member function) virtual void* addUserExtension(unsigned long long int key, ExtensionEntry* entry) = 0; diff --git a/DDCore/include/DD4hep/VolumeManager.h b/DDCore/include/DD4hep/VolumeManager.h index 0e6c0fd10..3cb72178f 100644 --- a/DDCore/include/DD4hep/VolumeManager.h +++ b/DDCore/include/DD4hep/VolumeManager.h @@ -146,7 +146,7 @@ namespace dd4hep { * Please see enum PopulateFlags for further info. * No action whatsoever is performed here, if the detector element is not valid. */ - VolumeManager(Detector& description, + VolumeManager(const Detector& description, const std::string& name, DetElement world = DetElement(), Readout ro = Readout(), @@ -155,7 +155,7 @@ namespace dd4hep { VolumeManager(DetElement subdetector, Readout ro); /// static accessor calling DD4hepVolumeManagerPlugin if necessary - static VolumeManager getVolumeManager(Detector& description); + static VolumeManager getVolumeManager(const Detector& description); /// Assignment operator VolumeManager& operator=(const VolumeManager& m) = default; diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp index 2a43619e2..1192a8f56 100644 --- a/DDCore/src/DetectorImp.cpp +++ b/DDCore/src/DetectorImp.cpp @@ -698,7 +698,7 @@ void DetectorImp::dump() const { } /// Manipulate geometry using facroy converter -long DetectorImp::apply(const char* factory_type, int argc, char** argv) { +long DetectorImp::apply(const char* factory_type, int argc, char** argv) const { string fac = factory_type; try { long result = PluginService::Create<long>(fac, (Detector*) this, argc, argv); diff --git a/DDCore/src/DetectorImp.h b/DDCore/src/DetectorImp.h index be947b8dd..441f30a60 100644 --- a/DDCore/src/DetectorImp.h +++ b/DDCore/src/DetectorImp.h @@ -112,7 +112,7 @@ namespace dd4hep { virtual void dump() const override; /// Manipulate geometry using facroy converter - virtual long apply(const char* factory, int argc, char** argv) override; + virtual long apply(const char* factory, int argc, char** argv) const override; /// Open the geometry at startup. virtual void init() override; diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index dc06b84cb..162be4e01 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -63,19 +63,19 @@ namespace dd4hep { typedef PlacedVolume::VolIDs VolIDs; typedef pair<VolumeID, VolumeID> Encoding; /// Reference to the Detector instance - Detector& m_detDesc; + const Detector& m_detDesc; /// Reference to the volume manager to be populated - VolumeManager m_volManager; + VolumeManager m_volManager; /// Set of already added entries - set<VolumeID> m_entries; + set<VolumeID> m_entries; /// Debug flag - bool m_debug = false; + bool m_debug = false; /// Node counter - size_t m_numNodes = 0; + size_t m_numNodes = 0; public: /// Default constructor - VolumeManager_Populator(Detector& description, VolumeManager vm) + VolumeManager_Populator(const Detector& description, VolumeManager vm) : m_detDesc(description), m_volManager(vm) { m_debug = (0 != ::getenv("DD4HEP_VOLMGR_DEBUG")); @@ -343,7 +343,7 @@ const TGeoHMatrix& VolumeManagerContext::toElement() const { } /// Initializing constructor to create a new object -VolumeManager::VolumeManager(Detector& description, const string& nam, DetElement elt, Readout ro, int flags) { +VolumeManager::VolumeManager(const Detector& description, const string& nam, DetElement elt, Readout ro, int flags) { printout(INFO, "VolumeManager", " - populating volume ids - be patient ..." ); size_t node_count = 0; Object* obj_ptr = new Object(); @@ -368,7 +368,7 @@ VolumeManager::VolumeManager(DetElement sub_detector, Readout ro) { assign(obj_ptr, sub_detector.name(), "VolumeManager"); } -VolumeManager VolumeManager::getVolumeManager(Detector& description) { +VolumeManager VolumeManager::getVolumeManager(const Detector& description) { if( not description.volumeManager().isValid() ) { description.apply("DD4hepVolumeManager", 0, 0); } diff --git a/DDG4/include/DDG4/Geant4Converter.h b/DDG4/include/DDG4/Geant4Converter.h index b3c190f65..7b46df952 100644 --- a/DDG4/include/DDG4/Geant4Converter.h +++ b/DDG4/include/DDG4/Geant4Converter.h @@ -57,10 +57,10 @@ namespace dd4hep { PrintLevel outputLevel; /// Initializing Constructor - Geant4Converter(Detector& description); + Geant4Converter(const Detector& description); /// Initializing Constructor - Geant4Converter(Detector& description, PrintLevel level); + Geant4Converter(const Detector& description, PrintLevel level); /// Standard destructor virtual ~Geant4Converter(); diff --git a/DDG4/include/DDG4/Geant4Mapping.h b/DDG4/include/DDG4/Geant4Mapping.h index 4d5eed2e8..10956e8c3 100644 --- a/DDG4/include/DDG4/Geant4Mapping.h +++ b/DDG4/include/DDG4/Geant4Mapping.h @@ -34,14 +34,14 @@ namespace dd4hep { */ class Geant4Mapping: public detail::GeoHandlerTypes { protected: - Detector& m_detDesc; + const Detector& m_detDesc; Geant4GeometryInfo* m_dataPtr; /// When resolving pointers, we must check for the validity of the data block void checkValidity() const; public: /// Initializing Constructor - Geant4Mapping(Detector& description); + Geant4Mapping(const Detector& description); /// Standard destructor virtual ~Geant4Mapping(); @@ -50,7 +50,7 @@ namespace dd4hep { static Geant4Mapping& instance(); /// Accesor to the Detector instance - Detector& detectorDescription() const { + const Detector& detectorDescription() const { return m_detDesc; } diff --git a/DDG4/include/DDG4/Geant4VolumeManager.h b/DDG4/include/DDG4/Geant4VolumeManager.h index b3c9a0fea..a7f9991d8 100644 --- a/DDG4/include/DDG4/Geant4VolumeManager.h +++ b/DDG4/include/DDG4/Geant4VolumeManager.h @@ -53,7 +53,7 @@ namespace dd4hep { static const VolumeID NonExisting = 0ULL; /// Initializing constructor. The tree will automatically be built if possible - Geant4VolumeManager(Detector& description, Geant4GeometryInfo* info); + Geant4VolumeManager(const Detector& description, Geant4GeometryInfo* info); /// Default constructor Geant4VolumeManager() = default; /// Constructor to be used when reading the already parsed object diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 727e476f7..fcfba4fbb 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -269,7 +269,7 @@ namespace { } /// Initializing Constructor -Geant4Converter::Geant4Converter(Detector& description_ref) +Geant4Converter::Geant4Converter(const Detector& description_ref) : Geant4Mapping(description_ref), checkOverlaps(true) { this->Geant4Mapping::init(); m_propagateRegions = true; @@ -277,7 +277,7 @@ Geant4Converter::Geant4Converter(Detector& description_ref) } /// Initializing Constructor -Geant4Converter::Geant4Converter(Detector& description_ref, PrintLevel level) +Geant4Converter::Geant4Converter(const Detector& description_ref, PrintLevel level) : Geant4Mapping(description_ref), checkOverlaps(true) { this->Geant4Mapping::init(); m_propagateRegions = true; diff --git a/DDG4/src/Geant4Mapping.cpp b/DDG4/src/Geant4Mapping.cpp index 9bc8efcf8..0521bdccc 100644 --- a/DDG4/src/Geant4Mapping.cpp +++ b/DDG4/src/Geant4Mapping.cpp @@ -24,7 +24,7 @@ using namespace dd4hep; using namespace std; /// Initializing Constructor -Geant4Mapping::Geant4Mapping(Detector& description_ref) +Geant4Mapping::Geant4Mapping(const Detector& description_ref) : m_detDesc(description_ref), m_dataPtr(0) { } @@ -73,7 +73,7 @@ void Geant4Mapping::attach(Geant4GeometryInfo* data_ptr) { Geant4VolumeManager Geant4Mapping::volumeManager() const { if ( m_dataPtr ) { if ( m_dataPtr->g4Paths.empty() ) { - VolumeManager::getVolumeManager(m_detDesc); + //VolumeManager::getVolumeManager(m_detDesc); return Geant4VolumeManager(m_detDesc, m_dataPtr); } return Geant4VolumeManager(Handle < Geant4GeometryInfo > (m_dataPtr)); diff --git a/DDG4/src/Geant4VolumeManager.cpp b/DDG4/src/Geant4VolumeManager.cpp index c7d395d18..b3ac6ca8a 100644 --- a/DDG4/src/Geant4VolumeManager.cpp +++ b/DDG4/src/Geant4VolumeManager.cpp @@ -44,14 +44,14 @@ namespace { typedef vector<const TGeoNode*> Chain; typedef map<VolumeID,Geant4GeometryInfo::Geant4PlacementPath> Registries; /// Reference to the Detector instance - Detector& m_detDesc; + const Detector& m_detDesc; /// Set of already added entries Registries m_entries; /// Reference to Geant4 translation information Geant4GeometryInfo& m_geo; /// Default constructor - Populator(Detector& description, Geant4GeometryInfo& g) + Populator(const Detector& description, Geant4GeometryInfo& g) : m_detDesc(description), m_geo(g) { } @@ -185,7 +185,7 @@ namespace { } /// Initializing constructor. The tree will automatically be built if possible -Geant4VolumeManager::Geant4VolumeManager(Detector& description, Geant4GeometryInfo* info) +Geant4VolumeManager::Geant4VolumeManager(const Detector& description, Geant4GeometryInfo* info) : Handle<Geant4GeometryInfo>(info), m_isValid(false) { if (info && info->valid && info->g4Paths.empty()) { Populator p(description, *info); -- GitLab