From 3baf47793fa637aa1dd8fc1bc58378e69090c2cf Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Tue, 28 Apr 2015 13:47:11 +0000 Subject: [PATCH] - renamed SurfaceManager to SurfaceHelper - in a next step the SurfaceManager will be re-written to be a singleton that caches surface lists and maps ... --- DDRec/include/DDRec/SurfaceHelper.h | 42 +++++++++++ DDRec/include/DDRec/SurfaceManager.h | 12 +-- DDRec/src/SurfaceHelper.cpp | 94 ++++++++++++++++++++++++ DDRec/src/SurfaceManager.cpp | 106 +++++++++++++-------------- UtilityApps/src/dumpdetector.cpp | 20 ++++- UtilityApps/src/test_surfaces.cpp | 4 +- UtilityApps/src/teve_display.cpp | 6 +- 7 files changed, 217 insertions(+), 67 deletions(-) create mode 100644 DDRec/include/DDRec/SurfaceHelper.h create mode 100644 DDRec/src/SurfaceHelper.cpp diff --git a/DDRec/include/DDRec/SurfaceHelper.h b/DDRec/include/DDRec/SurfaceHelper.h new file mode 100644 index 000000000..ac9df5727 --- /dev/null +++ b/DDRec/include/DDRec/SurfaceHelper.h @@ -0,0 +1,42 @@ +#ifndef DDRec_SurfaceHelper_H_ +#define DDRec_SurfaceHelper_H_ + +#include "DDRec/Surface.h" + +namespace DD4hep { + namespace DDRec { + + /** Surface helper class that allows to access all surfaces + * assigned to a DetElement and all its daughters. + * (originally this was called SurfaceManager). + * + * @author F.Gaede, DESY + * @date Apr, 11 2014 + * @version $Id: $ + */ + class SurfaceHelper { + + public: + + SurfaceHelper(const Geometry::DetElement& e); + + ~SurfaceHelper(); + + /** Get the list of all surfaces added to this DetElement and all its daughters - + * instantiate SurfaceHelper with lcdd.world() to get all surfaces. + */ + const SurfaceList& surfaceList() { return _sL ; } + + protected : + SurfaceList _sL ; + const Geometry::DetElement& _det ; + + /// initializes surfaces from VolSurfaces assigned to this DetElement in detector construction + void initialize() ; + + }; + + } /* namespace DDRec */ +} /* namespace DD4hep */ + +#endif // DDRec_SurfaceHelper_H_ diff --git a/DDRec/include/DDRec/SurfaceManager.h b/DDRec/include/DDRec/SurfaceManager.h index c69d7d598..7a7150d56 100644 --- a/DDRec/include/DDRec/SurfaceManager.h +++ b/DDRec/include/DDRec/SurfaceManager.h @@ -17,21 +17,21 @@ namespace DD4hep { public: - SurfaceManager(const Geometry::DetElement& e); + SurfaceManager(); ~SurfaceManager(); /** Get the list of all surfaces added to this DetElement and all its daughters - * instantiate SurfaceManager with lcdd.world() to get all surfaces. */ - const SurfaceList& surfaceList() { return _sL ; } + // const SurfaceList& surfaceList() { return _sL ; } protected : - SurfaceList _sL ; - const Geometry::DetElement& _det ; + // SurfaceList _sL ; + // const Geometry::DetElement& _det ; - /// initializes surfaces from VolSurfaces assigned to this DetElement in detector construction - void initialize() ; + // /// initializes surfaces from VolSurfaces assigned to this DetElement in detector construction + // void initialize() ; }; diff --git a/DDRec/src/SurfaceHelper.cpp b/DDRec/src/SurfaceHelper.cpp new file mode 100644 index 000000000..728f0b308 --- /dev/null +++ b/DDRec/src/SurfaceHelper.cpp @@ -0,0 +1,94 @@ +#include "DDRec/SurfaceHelper.h" + +#include "DDRec/DetectorSurfaces.h" +#include "DD4hep/Detector.h" +#include "DD4hep/LCDD.h" +#include "DD4hep/VolumeManager.h" + +namespace DD4hep { + + using namespace Geometry ; + + namespace DDRec { + + + SurfaceHelper::SurfaceHelper(DD4hep::Geometry::DetElement const& e) : _det(e) { + + initialize() ; + } + + SurfaceHelper::~SurfaceHelper(){ + // nothing to do + } + + + void SurfaceHelper::initialize() { + + // have to populate the volume manager once in order to have + // the volumeIDs attached to the DetElements + LCDD& lcdd = LCDD::getInstance(); + static VolumeManager volMgr( lcdd , "volMan" , lcdd.world() ) ; + + + //------------------ breadth first tree traversal --------- + std::list< DetElement > dets ; + std::list< DetElement > daugs ; + std::list< DetElement > gdaugs ; + + daugs.push_back( _det ) ; + + while( ! daugs.empty() ) { + + for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){ + DetElement dau = *li ; + DetElement::Children chMap = dau.children() ; + for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){ + DetElement de = (*it).second ; + gdaugs.push_back( de ) ; + } + } + dets.splice( dets.end() , daugs ) ; + daugs.splice( daugs.end() , gdaugs ) ; + } + //------------------ end tree traversal --------- + + // std::cout << " **** SurfaceHelper::initialize() : # DetElements found " << dets.size() << std::endl ; + + for( std::list< DetElement >::iterator li=dets.begin() ; li != dets.end() ; ++li ) { + + DetElement det = (*li) ; + + + + // create surfaces + DetectorSurfaces ds( det ) ; + + const SurfaceList& detSL = ds.surfaceList() ; + + + // // ---------------------- debug printout + // std::cout << " ---- DetElement id: " << det.volumeID() << " name : " << det.name() << " #surfaces : " << detSL.size() << std::endl ; + // PlacedVolume pv = det.placement() ; + // if( pv.isValid() ) { + // try{ // needed as above is also true for world whcih has invalid placment ... + // PlacedVolume::VolIDs volIDs = pv.volIDs() ; + // for(unsigned i=0,n=volIDs.size(); i<n ; ++i){ + // std::cout << " " << volIDs[i].first << " : " << volIDs[i].second << std::endl ; + // } + // }catch(...){} + // }else{ + // std::cout << " invalid placement for DetElement ??? !! " << std::endl ; + // } + // // ------------------------- end debug printout + + + // and add copy them to this list + _sL.insert( _sL.end(), detSL.begin(), detSL.end() ); + } + + } + + + + } // namespace +}// namespace diff --git a/DDRec/src/SurfaceManager.cpp b/DDRec/src/SurfaceManager.cpp index 2677aad9a..2d8470380 100644 --- a/DDRec/src/SurfaceManager.cpp +++ b/DDRec/src/SurfaceManager.cpp @@ -12,81 +12,81 @@ namespace DD4hep { namespace DDRec { - SurfaceManager::SurfaceManager(DD4hep::Geometry::DetElement const& e) : _det(e) { + // SurfaceManager::SurfaceManager(DD4hep::Geometry::DetElement const& e) : _det(e) { - initialize() ; - } + // initialize() ; + // } - SurfaceManager::~SurfaceManager(){ - // nothing to do - } + // SurfaceManager::~SurfaceManager(){ + // // nothing to do + // } - void SurfaceManager::initialize() { + // void SurfaceManager::initialize() { - // have to populate the volume manager once in order to have - // the volumeIDs attached to the DetElements - LCDD& lcdd = LCDD::getInstance(); - static VolumeManager volMgr( lcdd , "volMan" , lcdd.world() ) ; + // // have to populate the volume manager once in order to have + // // the volumeIDs attached to the DetElements + // LCDD& lcdd = LCDD::getInstance(); + // static VolumeManager volMgr( lcdd , "volMan" , lcdd.world() ) ; - //------------------ breadth first tree traversal --------- - std::list< DetElement > dets ; - std::list< DetElement > daugs ; - std::list< DetElement > gdaugs ; + // //------------------ breadth first tree traversal --------- + // std::list< DetElement > dets ; + // std::list< DetElement > daugs ; + // std::list< DetElement > gdaugs ; - daugs.push_back( _det ) ; + // daugs.push_back( _det ) ; - while( ! daugs.empty() ) { + // while( ! daugs.empty() ) { - for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){ - DetElement dau = *li ; - DetElement::Children chMap = dau.children() ; - for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){ - DetElement de = (*it).second ; - gdaugs.push_back( de ) ; - } - } - dets.splice( dets.end() , daugs ) ; - daugs.splice( daugs.end() , gdaugs ) ; - } - //------------------ end tree traversal --------- + // for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){ + // DetElement dau = *li ; + // DetElement::Children chMap = dau.children() ; + // for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){ + // DetElement de = (*it).second ; + // gdaugs.push_back( de ) ; + // } + // } + // dets.splice( dets.end() , daugs ) ; + // daugs.splice( daugs.end() , gdaugs ) ; + // } + // //------------------ end tree traversal --------- - // std::cout << " **** SurfaceManager::initialize() : # DetElements found " << dets.size() << std::endl ; + // // std::cout << " **** SurfaceManager::initialize() : # DetElements found " << dets.size() << std::endl ; - for( std::list< DetElement >::iterator li=dets.begin() ; li != dets.end() ; ++li ) { + // for( std::list< DetElement >::iterator li=dets.begin() ; li != dets.end() ; ++li ) { - DetElement det = (*li) ; + // DetElement det = (*li) ; - // create surfaces - DetectorSurfaces ds( det ) ; + // // create surfaces + // DetectorSurfaces ds( det ) ; - const SurfaceList& detSL = ds.surfaceList() ; + // const SurfaceList& detSL = ds.surfaceList() ; - // // ---------------------- debug printout - // std::cout << " ---- DetElement id: " << det.volumeID() << " name : " << det.name() << " #surfaces : " << detSL.size() << std::endl ; - // PlacedVolume pv = det.placement() ; - // if( pv.isValid() ) { - // try{ // needed as above is also true for world whcih has invalid placment ... - // PlacedVolume::VolIDs volIDs = pv.volIDs() ; - // for(unsigned i=0,n=volIDs.size(); i<n ; ++i){ - // std::cout << " " << volIDs[i].first << " : " << volIDs[i].second << std::endl ; - // } - // }catch(...){} - // }else{ - // std::cout << " invalid placement for DetElement ??? !! " << std::endl ; - // } - // // ------------------------- end debug printout + // // // ---------------------- debug printout + // // std::cout << " ---- DetElement id: " << det.volumeID() << " name : " << det.name() << " #surfaces : " << detSL.size() << std::endl ; + // // PlacedVolume pv = det.placement() ; + // // if( pv.isValid() ) { + // // try{ // needed as above is also true for world whcih has invalid placment ... + // // PlacedVolume::VolIDs volIDs = pv.volIDs() ; + // // for(unsigned i=0,n=volIDs.size(); i<n ; ++i){ + // // std::cout << " " << volIDs[i].first << " : " << volIDs[i].second << std::endl ; + // // } + // // }catch(...){} + // // }else{ + // // std::cout << " invalid placement for DetElement ??? !! " << std::endl ; + // // } + // // // ------------------------- end debug printout - // and add copy them to this list - _sL.insert( _sL.end(), detSL.begin(), detSL.end() ); - } + // // and add copy them to this list + // _sL.insert( _sL.end(), detSL.begin(), detSL.end() ); + // } - } + // } diff --git a/UtilityApps/src/dumpdetector.cpp b/UtilityApps/src/dumpdetector.cpp index d0c9ce42d..ed188d13a 100644 --- a/UtilityApps/src/dumpdetector.cpp +++ b/UtilityApps/src/dumpdetector.cpp @@ -13,7 +13,7 @@ #include "DDRec/Surface.h" #include "DDRec/DetectorSurfaces.h" -#include "DDRec/SurfaceManager.h" +#include "DDRec/SurfaceHelper.h" #include <list> @@ -42,6 +42,20 @@ int main(int argc, char** argv ){ DetElement world = lcdd.world() ; + + DD4hep::Geometry::LCDD::HandleMap sensDet = lcdd.sensitiveDetectors() ; + + + std::cout << "############################################################################### " << std::endl + << " sensitive detectors: " << std::endl ; + + for( DD4hep::Geometry::LCDD::HandleMap::const_iterator it = sensDet.begin() ; it != sensDet.end() ; ++it ){ + + SensitiveDetector sDet = it->second ; + std::cout << " " << it->first << " : type = " << sDet.type() << std::endl ; + } + + std::cout << "############################################################################### " << std::endl << std::endl ; @@ -76,7 +90,7 @@ int main(int argc, char** argv ){ ++parentCount ; } - SurfaceManager surfMan( de ) ; + SurfaceHelper surfMan( de ) ; const SurfaceList& sL = surfMan.surfaceList() ; @@ -84,7 +98,7 @@ int main(int argc, char** argv ){ for(unsigned i=0 ; i < parentCount ; ++i ) std::cout << "\t" ; - std::cout << de.name() << "[ path: "<< de.placementPath () << "] \t surfaces : " << ( sL.empty() ? 0 : sL.size() ) << std::endl ; + std::cout << de.name() << "[ path: "<< de.placementPath () << "] (id: " << de.id() << ") - sens type : " << lcdd.sensitiveDetector( de.name() ).type() << "\t surfaces : " << ( sL.empty() ? 0 : sL.size() ) << std::endl ; // for( SurfaceList::const_iterator it = sL.begin() ; it != sL.end() ; ++it ){ // Surface* surf = *it ; diff --git a/UtilityApps/src/test_surfaces.cpp b/UtilityApps/src/test_surfaces.cpp index c8b515b63..d7f0c23f7 100644 --- a/UtilityApps/src/test_surfaces.cpp +++ b/UtilityApps/src/test_surfaces.cpp @@ -2,7 +2,7 @@ #include "DDRec/Surface.h" #include "DDRec/DetectorSurfaces.h" -#include "DDRec/SurfaceManager.h" +#include "DDRec/SurfaceHelper.h" #include "DD4hep/DDTest.h" #include "DD4hep/DD4hepUnits.h" @@ -47,7 +47,7 @@ int main(int argc, char** argv ){ // create a list of all surfaces in the detector: - SurfaceManager surfMan( world ) ; + SurfaceHelper surfMan( world ) ; const SurfaceList& sL = surfMan.surfaceList() ; diff --git a/UtilityApps/src/teve_display.cpp b/UtilityApps/src/teve_display.cpp index 4356550ce..4fc52e021 100644 --- a/UtilityApps/src/teve_display.cpp +++ b/UtilityApps/src/teve_display.cpp @@ -10,7 +10,7 @@ //==================================================================== #include "DD4hep/Factories.h" #include "DD4hep/LCDD.h" -#include "DDRec/SurfaceManager.h" +#include "DDRec/SurfaceHelper.h" #include "EvNavHandler.h" #include "MultiView.h" @@ -150,7 +150,7 @@ TEveStraightLineSet* getSurfaceVectors() { DetElement world = lcdd.world() ; // create a list of all surfaces in the detector: - SurfaceManager surfMan( world ) ; + SurfaceHelper surfMan( world ) ; const SurfaceList& sL = surfMan.surfaceList() ; @@ -191,7 +191,7 @@ TEveStraightLineSet* getSurfaces(int col, const SurfaceType& type) { DetElement world = lcdd.world() ; // create a list of all surfaces in the detector: - SurfaceManager surfMan( world ) ; + SurfaceHelper surfMan( world ) ; const SurfaceList& sL = surfMan.surfaceList() ; -- GitLab