Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-12 08:24:45

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : F.Gaede
0011 //
0012 //==========================================================================
0013 #include "DDRec/SurfaceManager.h"
0014 
0015 #include "DDRec/SurfaceHelper.h"
0016 #include "DD4hep/VolumeManager.h"
0017 #include "DD4hep/Detector.h"
0018 #include "DD4hep/Printout.h"
0019 
0020 #include <sstream>
0021 
0022 namespace dd4hep {
0023   namespace rec {
0024 
0025     SurfaceManager::SurfaceManager(const Detector& theDetector) : _theDetector(theDetector) {
0026 
0027       // have to make sure the volume manager is populated once in order to have
0028       // the volumeIDs attached to the DetElements
0029 
0030       VolumeManager::getVolumeManager(theDetector);
0031 
0032     }
0033     
0034     
0035     const SurfaceMap* SurfaceManager::map( const std::string& name ) const {
0036 
0037       std::call_once( _initializedFlag, &SurfaceManager::initialize, this, _theDetector ) ;
0038 
0039       SurfaceMapsMap::const_iterator it = _map.find( name ) ;
0040 
0041       if( it != _map.end() ){
0042 
0043         return & it->second ;
0044       }
0045 
0046       return nullptr ;
0047     }
0048 
0049     void SurfaceManager::initialize(const Detector& description) const {
0050       
0051       for(const auto& type : description.detectorTypes()) {
0052 
0053         const std::vector<DetElement>& dets = description.detectors( type ) ;
0054 
0055         for(const auto& det : dets) {
0056 
0057           const std::string& name = det.name() ;
0058 
0059           SurfaceHelper surfH( det ) ;
0060       
0061           const SurfaceList& detSL = surfH.surfaceList() ;
0062   
0063           // add an empty map for this detector in case there are no surfaces attached 
0064           _map.emplace(name , SurfaceMap());
0065 
0066           for( auto* surf : detSL ) {
0067             // enter surface into map for this detector
0068             _map[ name ].emplace(surf->id(), surf );
0069 
0070             // enter surface into map for detector type
0071             _map[ type ].emplace(surf->id(), surf );
0072 
0073             // enter surface into world map 
0074             _map[ "world" ].emplace(surf->id(), surf );
0075 
0076           }
0077         }
0078       }
0079 
0080       printout(INFO,"SurfaceManager","%s" , description.extension<SurfaceManager>()->toString().c_str() );
0081 
0082     }
0083 
0084     std::string SurfaceManager::toString() const {
0085       
0086       std::stringstream sstr ;
0087        
0088       sstr << "--------  SurfaceManager contains the following maps : --------- " << std::endl ;
0089  
0090       for( SurfaceMapsMap::const_iterator mi = _map.begin() ; mi != _map.end() ; ++mi ) {
0091     
0092         sstr << "  key: " <<  mi->first << " \t number of surfaces : " << mi->second.size() << std::endl ; 
0093       }
0094       sstr << "---------------------------------------------------------------- " << std::endl ;
0095 
0096       return sstr.str() ;
0097     }
0098 
0099 
0100   } // namespace
0101 }// namespace