DD4hep  1.38.0
Detector Description Toolkit for High Energy Physics
SurfaceManager.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : F.Gaede
11 //
12 //==========================================================================
13 #include "DDRec/SurfaceManager.h"
14 
15 #include "DDRec/SurfaceHelper.h"
16 #include "DD4hep/VolumeManager.h"
17 #include "DD4hep/Detector.h"
18 #include "DD4hep/DetectorTools.h"
19 #include "DD4hep/Printout.h"
20 
21 #include <sstream>
22 #include <unordered_set>
23 
24 namespace dd4hep {
25  namespace rec {
26 
27  SurfaceManager::SurfaceManager(const Detector& theDetector) : _theDetector(theDetector) {
28 
29  // have to make sure the volume manager is populated once in order to have
30  // the volumeIDs attached to the DetElements
31 
33 
34  }
35 
36 
37  const SurfaceMap* SurfaceManager::map( const std::string& name ) const {
38 
39  std::call_once( _initializedFlag, &SurfaceManager::initialize, this, _theDetector ) ;
40 
41  SurfaceMapsMap::const_iterator it = _map.find( name ) ;
42 
43  if( it != _map.end() ){
44 
45  return & it->second ;
46  }
47 
48  return nullptr ;
49  }
50 
51  void SurfaceManager::initialize(const Detector& description) const {
52 
53  // A surface can reach the same map more than once: a nested detector is also part of the
54  // detector that contains it, and a detector can have the same name as a detector type.
55  // Enter each surface only once into each map (the first entry is kept).
56  std::map<std::string, std::unordered_set<const ISurface*>> entered;
57  auto enter = [&]( const std::string& key, ISurface* surf ) {
58  if( entered[ key ].insert( surf ).second )
59  _map[ key ].emplace( surf->id(), surf );
60  };
61 
62  detail::tools::PlacementPathCache cache; // every surface calls DetElement::nominal()
63  for(const auto& type : description.detectorTypes()) {
64 
65  const std::vector<DetElement>& dets = description.detectors( type ) ;
66 
67  for(const auto& det : dets) {
68 
69  const std::string& name = det.name() ;
70 
71  SurfaceHelper surfH( det ) ;
72 
73  const SurfaceList& detSL = surfH.surfaceList() ;
74 
75  // add an empty map for this detector in case there are no surfaces attached
76  _map.emplace(name , SurfaceMap());
77 
78  for( auto* surf : detSL ) {
79  // enter surface into map for this detector
80  enter( name, surf );
81 
82  // enter surface into map for detector type
83  if(name != type)
84  enter( type, surf );
85 
86  // enter surface into world map
87  enter( "world", surf );
88 
89  }
90  }
91  }
92 
93  printout(INFO,"SurfaceManager","%s" , description.extension<SurfaceManager>()->toString().c_str() );
94 
95  }
96 
97  std::string SurfaceManager::toString() const {
98 
99  std::stringstream sstr ;
100 
101  sstr << "-------- SurfaceManager contains the following maps : --------- " << std::endl ;
102 
103  for( SurfaceMapsMap::const_iterator mi = _map.begin() ; mi != _map.end() ; ++mi ) {
104 
105  sstr << " key: " << mi->first << " \t number of surfaces : " << mi->second.size() << std::endl ;
106  }
107  sstr << "---------------------------------------------------------------- " << std::endl ;
108 
109  return sstr.str() ;
110  }
111 
112 
113  } // namespace
114 }// namespace
SurfaceManager.h
dd4hep::rec::SurfaceManager::map
const SurfaceMap * map(const std::string &name) const
Definition: SurfaceManager.cpp:37
Detector.h
dd4hep::rec::ISurface
Definition: ISurface.h:39
dd4hep::Detector::detectors
virtual const HandleMap & detectors() const =0
Accessor to the map of sub-detectors.
dd4hep::rec::SurfaceManager::initialize
void initialize(const Detector &theDetector) const
initialize all known surface maps
Definition: SurfaceManager.cpp:51
dd4hep::rec::SurfaceManager::toString
std::string toString() const
create a string with all available maps and their size (number of surfaces)
Definition: SurfaceManager.cpp:97
dd4hep::rec::SurfaceMap
std::multimap< unsigned long, ISurface * > SurfaceMap
typedef for surface maps, keyed by the cellID
Definition: SurfaceManager.h:25
SurfaceHelper.h
SurfaceManager
Plugin that creates a SurfaceManager object and attaches it to description as a user extension object...
VolumeManager.h
dd4hep::rec::SurfaceManager::_theDetector
const Detector & _theDetector
Definition: SurfaceManager.h:70
dd4hep::rec::SurfaceList
Definition: Surface.h:679
dd4hep::rec::SurfaceManager::_initializedFlag
std::once_flag _initializedFlag
Definition: SurfaceManager.h:71
dd4hep::rec::SurfaceHelper::surfaceList
const SurfaceList & surfaceList()
Definition: SurfaceHelper.h:44
dd4hep::VolumeManager::getVolumeManager
static VolumeManager getVolumeManager(const Detector &description)
static accessor calling DD4hepVolumeManagerPlugin if necessary
Definition: VolumeManager.cpp:440
DetectorTools.h
dd4hep::Detector::detectorTypes
virtual std::vector< std::string > detectorTypes() const =0
Access the available detector types.
dd4hep::rec::SurfaceManager::_map
SurfaceMapsMap _map
Definition: SurfaceManager.h:69
dd4hep::detail::tools::PlacementPathCache
Definition: DetectorTools.h:72
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::rec::SurfaceManager::SurfaceManager
SurfaceManager()=delete
No default constructor.
dd4hep::Detector::extension
IFACE * extension(bool alert=true) const
Access extension element by the type.
Definition: Detector.h:343
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:89
Printout.h
dd4hep::rec::SurfaceHelper
Definition: SurfaceHelper.h:29