DD4hep  1.34.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/Printout.h"
19 
20 #include <sstream>
21 
22 namespace dd4hep {
23  namespace rec {
24 
25  SurfaceManager::SurfaceManager(const Detector& theDetector) : _theDetector(theDetector) {
26 
27  // have to make sure the volume manager is populated once in order to have
28  // the volumeIDs attached to the DetElements
29 
31 
32  }
33 
34 
35  const SurfaceMap* SurfaceManager::map( const std::string& name ) const {
36 
37  std::call_once( _initializedFlag, &SurfaceManager::initialize, this, _theDetector ) ;
38 
39  SurfaceMapsMap::const_iterator it = _map.find( name ) ;
40 
41  if( it != _map.end() ){
42 
43  return & it->second ;
44  }
45 
46  return nullptr ;
47  }
48 
49  void SurfaceManager::initialize(const Detector& description) const {
50 
51  for(const auto& type : description.detectorTypes()) {
52 
53  const std::vector<DetElement>& dets = description.detectors( type ) ;
54 
55  for(const auto& det : dets) {
56 
57  const std::string& name = det.name() ;
58 
59  SurfaceHelper surfH( det ) ;
60 
61  const SurfaceList& detSL = surfH.surfaceList() ;
62 
63  // add an empty map for this detector in case there are no surfaces attached
64  _map.emplace(name , SurfaceMap());
65 
66  for( auto* surf : detSL ) {
67  // enter surface into map for this detector
68  _map[ name ].emplace(surf->id(), surf );
69 
70  // enter surface into map for detector type
71  _map[ type ].emplace(surf->id(), surf );
72 
73  // enter surface into world map
74  _map[ "world" ].emplace(surf->id(), surf );
75 
76  }
77  }
78  }
79 
80  printout(INFO,"SurfaceManager","%s" , description.extension<SurfaceManager>()->toString().c_str() );
81 
82  }
83 
84  std::string SurfaceManager::toString() const {
85 
86  std::stringstream sstr ;
87 
88  sstr << "-------- SurfaceManager contains the following maps : --------- " << std::endl ;
89 
90  for( SurfaceMapsMap::const_iterator mi = _map.begin() ; mi != _map.end() ; ++mi ) {
91 
92  sstr << " key: " << mi->first << " \t number of surfaces : " << mi->second.size() << std::endl ;
93  }
94  sstr << "---------------------------------------------------------------- " << std::endl ;
95 
96  return sstr.str() ;
97  }
98 
99 
100  } // namespace
101 }// namespace
SurfaceManager.h
dd4hep::rec::SurfaceManager::map
const SurfaceMap * map(const std::string &name) const
Definition: SurfaceManager.cpp:35
Detector.h
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:49
dd4hep::rec::SurfaceManager::toString
std::string toString() const
create a string with all available maps and their size (number of surfaces)
Definition: SurfaceManager.cpp:84
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:420
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::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:344
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:90
Printout.h
dd4hep::rec::SurfaceHelper
Definition: SurfaceHelper.h:29