Skip to content

Commit 4f3f727

Browse files
committed
Delay the construction of Surfaces and the surface maps until they are needed
and are obtained with `map()`. Delete the move constructor since std::once_flag is not movable. initialize() now can be const, but this is only called within DD4hep. Interface for users doesn't change, except now the message with the number of elements in each surface map appears later, when they are built.
1 parent f2fa261 commit 4f3f727

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

DDRec/include/DDRec/SurfaceManager.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,13 @@ namespace dd4hep {
4141
SurfaceManager(const Detector& theDetector);
4242

4343
/// No default constructor
44-
#if defined(G__ROOT)
45-
SurfaceManager() = default ;
46-
#else
4744
SurfaceManager() = delete ;
48-
#endif
4945

5046
~SurfaceManager() = default;
5147
SurfaceManager(const SurfaceManager&) = delete;
5248
SurfaceManager& operator=(const SurfaceManager&) = delete;
53-
SurfaceManager(SurfaceManager&&) = default;
54-
SurfaceManager& operator=(SurfaceManager&&) = default;
49+
SurfaceManager(SurfaceManager&&) = delete;
50+
SurfaceManager& operator=(SurfaceManager&&) = delete;
5551

5652

5753
/** Get the maps of all surfaces associated to the given detector or
@@ -68,9 +64,11 @@ namespace dd4hep {
6864

6965

7066
/// initialize all known surface maps
71-
void initialize(const Detector& theDetector) ;
67+
void initialize(const Detector& theDetector) const;
7268

73-
SurfaceMapsMap _map ;
69+
mutable SurfaceMapsMap _map{} ;
70+
const Detector& _theDetector ;
71+
mutable std::once_flag _initializedFlag{} ;
7472
};
7573

7674
} /* namespace rec */

DDRec/src/SurfaceManager.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,27 @@
1515
#include "DDRec/SurfaceHelper.h"
1616
#include "DD4hep/VolumeManager.h"
1717
#include "DD4hep/Detector.h"
18+
#include "DD4hep/Printout.h"
1819

1920
#include <sstream>
2021

2122
namespace dd4hep {
2223
namespace rec {
2324

24-
SurfaceManager::SurfaceManager(const Detector& theDetector){
25+
SurfaceManager::SurfaceManager(const Detector& theDetector) : _theDetector(theDetector) {
2526

2627
// have to make sure the volume manager is populated once in order to have
2728
// the volumeIDs attached to the DetElements
2829

2930
VolumeManager::getVolumeManager(theDetector);
3031

31-
initialize(theDetector) ;
3232
}
3333

3434

3535
const SurfaceMap* SurfaceManager::map( const std::string& name ) const {
3636

37+
std::call_once( _initializedFlag, &SurfaceManager::initialize, this, _theDetector ) ;
38+
3739
SurfaceMapsMap::const_iterator it = _map.find( name ) ;
3840

3941
if( it != _map.end() ){
@@ -44,7 +46,7 @@ namespace dd4hep {
4446
return nullptr ;
4547
}
4648

47-
void SurfaceManager::initialize(const Detector& description) {
49+
void SurfaceManager::initialize(const Detector& description) const {
4850

4951
for(const auto& type : description.detectorTypes()) {
5052

@@ -75,6 +77,8 @@ namespace dd4hep {
7577
}
7678
}
7779

80+
printout(INFO,"SurfaceManager","%s" , description.extension<SurfaceManager>()->toString().c_str() );
81+
7882
}
7983

8084
std::string SurfaceManager::toString() const {

DDRec/src/plugins/createSurfaceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ namespace dd4hep{
4040
static long createSurfaceManager(Detector& description, int /*argc*/, char** /*argv*/) {
4141

4242
printout(INFO,"InstallSurfaceManager","**** running plugin InstallSurfaceManager ! " );
43+
printout(INFO,"InstallSurfaceManager","**** the map of surfaces will be created on first access ! " );
4344

4445
description.addExtension<SurfaceManager>( new SurfaceManager(description) ) ;
4546

46-
printout(INFO,"InstallSurfaceManager","%s" , description.extension<SurfaceManager>()->toString().c_str() );
4747

4848
return 1;
4949
}

0 commit comments

Comments
 (0)