DD4hep  1.30.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 
19 #include <sstream>
20 
21 namespace dd4hep {
22 
23  using namespace detail ;
24 
25  namespace rec {
26 
27 
28  SurfaceManager::SurfaceManager(const Detector& theDetector){
29 
30  // have to make sure the volume manager is populated once in order to have
31  // the volumeIDs attached to the DetElements
32 
34 
35  initialize(theDetector) ;
36  }
37 
38  SurfaceManager::~SurfaceManager(){
39  // nothing to do
40  }
41 
42 
43  const SurfaceMap* SurfaceManager::map( const std::string name ) const {
44 
45  SurfaceMapsMap::const_iterator it = _map.find( name ) ;
46 
47  if( it != _map.end() ){
48 
49  return & it->second ;
50  }
51 
52  return 0 ;
53  }
54 
55  void SurfaceManager::initialize(const Detector& description) {
56 
57  const std::vector<std::string>& types = description.detectorTypes() ;
58 
59  for(unsigned i=0,N=types.size();i<N;++i){
60 
61  const std::vector<DetElement>& dets = description.detectors( types[i] ) ;
62 
63  for(unsigned j=0,M=dets.size();j<M;++j){
64 
65  std::string name = dets[j].name() ;
66 
67  SurfaceHelper surfH( dets[j] ) ;
68 
69  const SurfaceList& detSL = surfH.surfaceList() ;
70 
71  // add an empty map for this detector in case there are no surfaces attached
72  _map.emplace(name , SurfaceMap());
73 
74  for( SurfaceList::const_iterator it = detSL.begin() ; it != detSL.end() ; ++it ){
75  ISurface* surf = *it ;
76 
77  // enter surface into map for this detector
78  _map[ name ].emplace(surf->id(), surf );
79 
80  // enter surface into map for detector type
81  _map[ types[i] ].emplace(surf->id(), surf );
82 
83  // enter surface into world map
84  _map[ "world" ].emplace(surf->id(), surf );
85 
86  }
87  }
88  }
89 
90  }
91 
92  std::string SurfaceManager::toString() const {
93 
94  std::stringstream sstr ;
95 
96  sstr << "-------- SurfaceManager contains the following maps : --------- " << std::endl ;
97 
98  for( SurfaceMapsMap::const_iterator mi = _map.begin() ; mi != _map.end() ; ++mi ) {
99 
100  sstr << " key: " << mi->first << " \t number of surfaces : " << mi->second.size() << std::endl ;
101  }
102  sstr << "---------------------------------------------------------------- " << std::endl ;
103 
104  return sstr.str() ;
105  }
106 
107 
108  } // namespace
109 }// namespace
SurfaceManager.h
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::SurfaceMap
std::multimap< unsigned long, ISurface * > SurfaceMap
typedef for surface maps, keyed by the cellID
Definition: SurfaceManager.h:25
SurfaceHelper.h
VolumeManager.h
dd4hep::rec::SurfaceList
Definition: Surface.h:681
dd4hep::rec::ISurface::id
virtual long64 id() const =0
The id of this surface - corresponds to DetElement id ( or'ed with the placement ids )
dd4hep::rec::SurfaceHelper::surfaceList
const SurfaceList & surfaceList()
Definition: SurfaceHelper.h:40
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 availible detector types.
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::detail::tools::toString
std::string toString(const PlacedVolume::VolIDs &ids)
Convert VolumeID to string.
Definition: DetectorTools.cpp:378
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::rec::SurfaceHelper
Definition: SurfaceHelper.h:29