From 846f219492d1247c6cd824ed033819a821914c1b Mon Sep 17 00:00:00 2001
From: Frank Gaede <frank.gaede@desy.de>
Date: Fri, 5 Feb 2016 15:05:59 +0000
Subject: [PATCH]  - changed method signature: LCDD::detectors(unsigned int
 includeFlag,  unsigned int excludeFlag=0 )    - allows to select sets of
 detectors with some properties and explicitely excluding others    - see
 dumpdetector for example usage

---
 DDCore/include/DD4hep/DetType.h  |  1 +
 DDCore/include/DD4hep/LCDD.h     |  7 ++++---
 DDCore/src/LCDDImp.cpp           |  7 +++----
 DDCore/src/LCDDImp.h             |  7 +++++--
 UtilityApps/src/dumpdetector.cpp | 16 ++++++++++++----
 5 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/DDCore/include/DD4hep/DetType.h b/DDCore/include/DD4hep/DetType.h
index fe881a348..f96120303 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 adfa62832..49e0c2b87 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 c29136112..e9fceac0a 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 bb35c2ebf..a04f2743d 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 bfd01b217..4a1ecc4c0 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 ){
 
-- 
GitLab