diff --git a/DDCore/include/DD4hep/DetType.h b/DDCore/include/DD4hep/DetType.h index fe881a34882a6638cac1f623d956b614f7e535a7..f96120303bd84d5dac07295c8de60898d8da0696 100644 --- a/DDCore/include/DD4hep/DetType.h +++ b/DDCore/include/DD4hep/DetType.h @@ -36,6 +36,7 @@ namespace DD4hep { public: enum { + IGNORE = 0 , TRACKER = 1 << 0, CALORIMETER = 1 << 1, CHERENKOV = 1 << 2, diff --git a/DDCore/include/DD4hep/LCDD.h b/DDCore/include/DD4hep/LCDD.h index adfa628328a0cd62f210802b31f3734209494c52..49e0c2b87586126bd4ef7cbab50bfa67acb51967 100644 --- a/DDCore/include/DD4hep/LCDD.h +++ b/DDCore/include/DD4hep/LCDD.h @@ -179,10 +179,11 @@ namespace DD4hep { virtual std::vector<std::string> detectorTypes() const = 0; - /** return a vector with all detectors that have all the given type properties set - * or not set depending on bitsSet. + /** return a vector with all detectors that have all the type properties in + * includeFlag set but none of the properties given in excludeFlag */ - virtual std::vector<DetElement> detectors(unsigned int typeFlag, bool bitsSet=true ) const = 0 ; + virtual std::vector<DetElement> detectors(unsigned int includeFlag, + unsigned int excludeFlag=0 ) const = 0 ; #endif /** Miscaneleous accessors to the detexctor description */ diff --git a/DDCore/src/LCDDImp.cpp b/DDCore/src/LCDDImp.cpp index c2913611209697617fd1c28e56e11ab7d2199d9b..e9fceac0ae58bd682cce510a33664f4a652c7133 100644 --- a/DDCore/src/LCDDImp.cpp +++ b/DDCore/src/LCDDImp.cpp @@ -343,15 +343,13 @@ const vector<DetElement>& LCDDImp::detectors(const string& type) { throw runtime_error("detectors("+type+"): Detectors can only selected by type once the geometry is closed!"); } -vector<DetElement> LCDDImp::detectors(unsigned int typeFlag, bool bitsSet) const { +vector<DetElement> LCDDImp::detectors(unsigned int includeFlag, unsigned int excludeFlag ) const { if( ! m_manager->IsClosed() ) { throw runtime_error("detectors(typeFlag): Detectors can only selected by typeFlag once the geometry is closed!"); } vector<DetElement> dets ; dets.reserve( m_detectors.size() ) ; - unsigned int compFlag = ( bitsSet ? typeFlag : 0 ) ; - for(HandleMap::const_iterator i=m_detectors.begin(); i!=m_detectors.end(); ++i) { DetElement det((*i).second); if ( det.parent().isValid() ) { // Exclude 'world' @@ -359,7 +357,8 @@ vector<DetElement> LCDDImp::detectors(unsigned int typeFlag, bool bitsSet) const //fixme: what to do with compounds - add their daughters ? // ... - if( ( det.typeFlag() & typeFlag ) == compFlag ) + if( ( det.typeFlag() & includeFlag ) == includeFlag && + ( det.typeFlag() & excludeFlag ) == 0 ) dets.push_back( det ) ; } } diff --git a/DDCore/src/LCDDImp.h b/DDCore/src/LCDDImp.h index bb35c2ebf830ed2fe9a1e010b9710fc471d88517..a04f2743d41867d802f5d4d3a719fad454925636 100644 --- a/DDCore/src/LCDDImp.h +++ b/DDCore/src/LCDDImp.h @@ -271,8 +271,11 @@ namespace DD4hep { /// Access the availible detector types virtual std::vector<std::string> detectorTypes() const; - /// return a vector with all detectors that have all the given type properties set/ not set. - virtual std::vector<DetElement> detectors(unsigned int typeFlag, bool bitsSet=true ) const ; + /** return a vector with all detectors that have all the type properties in + * includeFlag set but none of the properties given in excludeFlag + */ + virtual std::vector<DetElement> detectors(unsigned int includeFlag, + unsigned int excludeFlag=0 ) const ; #define __R return *this diff --git a/UtilityApps/src/dumpdetector.cpp b/UtilityApps/src/dumpdetector.cpp index bfd01b21772d9054c19d0b4df7ab8314f35273b3..4a1ecc4c000f2acab8ba8f1a40f2c0ba1243f6f3 100644 --- a/UtilityApps/src/dumpdetector.cpp +++ b/UtilityApps/src/dumpdetector.cpp @@ -63,10 +63,10 @@ void printDetectorData( DetElement det ){ } -void printDetectorSets( std::string name, unsigned int typeFlag ){ +void printDetectorSets( std::string name, unsigned int includeFlag, unsigned int excludeFlag=DetType::IGNORE ){ LCDD& lcdd = LCDD::getInstance(); - const std::vector<DetElement>& dets = lcdd.detectors( typeFlag ) ; + const std::vector<DetElement>& dets = lcdd.detectors( includeFlag, excludeFlag ) ; std::cout << " " << name ; for(int i=0,N=dets.size();i<N;++i) std::cout << dets[i].name() << ", " ; @@ -112,12 +112,20 @@ int main(int argc, char** argv ){ << " status : " << h.status() << std::endl ; - printDetectorSets( " barrel trackers : " , ( DetType::TRACKER | DetType::BARREL ) ) ; - printDetectorSets( " endcap trackers : " , ( DetType::TRACKER | DetType::ENDCAP ) ) ; + // print a few sets of detectors (mainly to demonstrate the usage of the detector types ) + + printDetectorSets( " barrel trackers : " , ( DetType::TRACKER | DetType::BARREL ) , ( DetType::VERTEX) ) ; + printDetectorSets( " endcap trackers : " , ( DetType::TRACKER | DetType::ENDCAP ) , ( DetType::VERTEX) ) ; + + printDetectorSets( " vertex barrel trackers : " , ( DetType::TRACKER | DetType::BARREL | DetType::VERTEX) ) ; + printDetectorSets( " vertex endcap trackers : " , ( DetType::TRACKER | DetType::ENDCAP | DetType::VERTEX) ) ; printDetectorSets( " barrel calorimeters : " , ( DetType::CALORIMETER | DetType::BARREL ) ) ; printDetectorSets( " endcap calorimeters : " , ( DetType::CALORIMETER | DetType::ENDCAP ) ) ; + // everything that is not TRACKER or CALORIMETER + printDetectorSets( " other detecors : " , ( DetType::IGNORE ) , ( DetType::CALORIMETER | DetType::TRACKER ) ) ; + if( printDetData ){