DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceManager.cpp
Go to the documentation of this file.
1 #include "DDRec/SurfaceManager.h"
2 
3 #include "DDRec/SurfaceHelper.h"
4 #include "DD4hep/LCDD.h"
5 
6 #include <sstream>
7 
8 namespace DD4hep {
9 
10  using namespace Geometry ;
11  using namespace DDSurfaces ;
12 
13  namespace DDRec {
14 
15 
16  SurfaceManager::SurfaceManager(){
17 
18  initialize() ;
19  }
20 
21  SurfaceManager::~SurfaceManager(){
22  // nothing to do
23  }
24 
25 
26  const SurfaceMap* SurfaceManager::map( const std::string name ) const {
27 
28  SurfaceMapsMap::const_iterator it = _map.find( name ) ;
29 
30  if( it != _map.end() ){
31 
32  return & it->second ;
33  }
34 
35  return 0 ;
36  }
37 
38  void SurfaceManager::initialize() {
39 
40  LCDD& lcdd = LCDD::getInstance();
41 
42  const std::vector<std::string>& types = lcdd.detectorTypes() ;
43 
44  for(unsigned i=0,N=types.size();i<N;++i){
45 
46  const std::vector<DetElement>& dets = lcdd.detectors( types[i] ) ;
47 
48  for(unsigned j=0,M=dets.size();j<M;++j){
49 
50  std::string name = dets[j].name() ;
51 
52  SurfaceHelper surfH( dets[j] ) ;
53 
54  const SurfaceList& detSL = surfH.surfaceList() ;
55 
56  // add an empty map for this detector in case there are no surfaces attached
57  _map.insert( std::make_pair( name , SurfaceMap() ) ) ;
58 
59  for( SurfaceList::const_iterator it = detSL.begin() ; it != detSL.end() ; ++it ){
60  ISurface* surf = *it ;
61 
62  // enter surface into map for this detector
63  _map[ name ].insert( std::make_pair( surf->id(), surf ) ) ;
64 
65  // enter surface into map for detector type
66  _map[ types[i] ].insert( std::make_pair( surf->id(), surf ) ) ;
67 
68  // enter surface into world map
69  _map[ "world" ].insert( std::make_pair( surf->id(), surf ) ) ;
70 
71  }
72  }
73  }
74 
75  }
76 
77  std::string SurfaceManager::toString() const {
78 
79  std::stringstream sstr ;
80 
81  sstr << "-------- SurfaceManager contains the following maps : --------- " << std::endl ;
82 
83  for( SurfaceMapsMap::const_iterator mi = _map.begin() ; mi != _map.end() ; ++mi ) {
84 
85  sstr << " key: " << mi->first << " \t number of surfaces : " << mi->second.size() << std::endl ;
86  }
87  sstr << "---------------------------------------------------------------- " << std::endl ;
88 
89  return sstr.str() ;
90  }
91 
92 
93  } // namespace
94 }// namespace
virtual const HandleMap & detectors() const =0
Accessor to the map of sub-detectors.
static LCDD & getInstance(void)
—Factory method----—
Definition: LCDDImp.cpp:87
virtual std::vector< std::string > detectorTypes() const =0
Access the availible detector types.
std::multimap< unsigned long, DDSurfaces::ISurface * > SurfaceMap
typedef for surface maps, keyed by the cellID
virtual long64 id() const =0
The id of this surface - corresponds to DetElement id ( or'ed with the placement ids ) ...
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
const SurfaceList & surfaceList()
Definition: SurfaceHelper.h:28
std::string toString(const PlacedVolume::VolIDs &ids)
Convert VolumeID to string.