diff --git a/DDRec/include/DDRec/SurfaceManager.h b/DDRec/include/DDRec/SurfaceManager.h index f3f08a063..a44518e45 100644 --- a/DDRec/include/DDRec/SurfaceManager.h +++ b/DDRec/include/DDRec/SurfaceManager.h @@ -41,17 +41,13 @@ namespace dd4hep { SurfaceManager(const Detector& theDetector); /// No default constructor -#if defined(G__ROOT) - SurfaceManager() = default ; -#else SurfaceManager() = delete ; -#endif ~SurfaceManager() = default; SurfaceManager(const SurfaceManager&) = delete; SurfaceManager& operator=(const SurfaceManager&) = delete; - SurfaceManager(SurfaceManager&&) = default; - SurfaceManager& operator=(SurfaceManager&&) = default; + SurfaceManager(SurfaceManager&&) = delete; + SurfaceManager& operator=(SurfaceManager&&) = delete; /** Get the maps of all surfaces associated to the given detector or @@ -68,9 +64,11 @@ namespace dd4hep { /// initialize all known surface maps - void initialize(const Detector& theDetector) ; + void initialize(const Detector& theDetector) const; - SurfaceMapsMap _map ; + mutable SurfaceMapsMap _map{} ; + const Detector& _theDetector ; + mutable std::once_flag _initializedFlag{} ; }; } /* namespace rec */ diff --git a/DDRec/src/SurfaceManager.cpp b/DDRec/src/SurfaceManager.cpp index 513d201a9..16734b837 100644 --- a/DDRec/src/SurfaceManager.cpp +++ b/DDRec/src/SurfaceManager.cpp @@ -15,25 +15,27 @@ #include "DDRec/SurfaceHelper.h" #include "DD4hep/VolumeManager.h" #include "DD4hep/Detector.h" +#include "DD4hep/Printout.h" #include namespace dd4hep { namespace rec { - SurfaceManager::SurfaceManager(const Detector& theDetector){ + SurfaceManager::SurfaceManager(const Detector& theDetector) : _theDetector(theDetector) { // have to make sure the volume manager is populated once in order to have // the volumeIDs attached to the DetElements VolumeManager::getVolumeManager(theDetector); - initialize(theDetector) ; } const SurfaceMap* SurfaceManager::map( const std::string& name ) const { + std::call_once( _initializedFlag, &SurfaceManager::initialize, this, _theDetector ) ; + SurfaceMapsMap::const_iterator it = _map.find( name ) ; if( it != _map.end() ){ @@ -44,7 +46,7 @@ namespace dd4hep { return nullptr ; } - void SurfaceManager::initialize(const Detector& description) { + void SurfaceManager::initialize(const Detector& description) const { for(const auto& type : description.detectorTypes()) { @@ -75,6 +77,8 @@ namespace dd4hep { } } + printout(INFO,"SurfaceManager","%s" , description.extension()->toString().c_str() ); + } std::string SurfaceManager::toString() const { diff --git a/DDRec/src/plugins/createSurfaceManager.cpp b/DDRec/src/plugins/createSurfaceManager.cpp index 4ebc8d5b3..10afd8957 100644 --- a/DDRec/src/plugins/createSurfaceManager.cpp +++ b/DDRec/src/plugins/createSurfaceManager.cpp @@ -40,10 +40,10 @@ namespace dd4hep{ static long createSurfaceManager(Detector& description, int /*argc*/, char** /*argv*/) { printout(INFO,"InstallSurfaceManager","**** running plugin InstallSurfaceManager ! " ); + printout(INFO,"InstallSurfaceManager","**** the map of surfaces will be created on first access ! " ); description.addExtension( new SurfaceManager(description) ) ; - printout(INFO,"InstallSurfaceManager","%s" , description.extension()->toString().c_str() ); return 1; }