DD4hep  01.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
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(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 
33  VolumeManager::getVolumeManager(theDetector);
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(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
const SurfaceList & surfaceList()
Get the list of all surfaces added to this DetElement and all its daughters - instantiate SurfaceHelp...
Definition: SurfaceHelper.h:40
Interface for tracking surfaces.
Definition: ISurface.h:39
Surface helper class that allows to access all surfaces assigned to a DetElement and all its daughter...
Definition: SurfaceHelper.h:29
T endl(T...args)
T end(T...args)
std::multimap< unsigned long, ISurface * > SurfaceMap
typedef for surface maps, keyed by the cellID
std::list of Surfaces that optionally takes ownership.
Definition: Surface.h:681
STL class.
T str(T...args)
virtual long64 id() const =0
The id of this surface - corresponds to DetElement id ( or&#39;ed with the placement ids ) ...
STL class.
T find(T...args)
T size(T...args)
STL class.
T begin(T...args)
T emplace(T...args)