From 3af6531c6926e70009829a2c189fb7acaf4fb330 Mon Sep 17 00:00:00 2001
From: Frank Gaede <frank.gaede@desy.de>
Date: Fri, 5 Feb 2016 10:30:21 +0000
Subject: [PATCH]  - added utility class for setting detector type properties
 in    a flag wordL DetType  - added test_DetType.cc

---
 DDCore/include/DD4hep/DetType.h  | 113 +++++++++++++++++++++++++++++++
 DDTest/CMakeLists.txt            |   4 +-
 DDTest/src/test_DetType.cc       |  66 ++++++++++++++++++
 UtilityApps/src/teve_display.cpp |   2 +-
 4 files changed, 182 insertions(+), 3 deletions(-)
 create mode 100644 DDCore/include/DD4hep/DetType.h
 create mode 100644 DDTest/src/test_DetType.cc

diff --git a/DDCore/include/DD4hep/DetType.h b/DDCore/include/DD4hep/DetType.h
new file mode 100644
index 000000000..26db8d95a
--- /dev/null
+++ b/DDCore/include/DD4hep/DetType.h
@@ -0,0 +1,113 @@
+// $Id: $
+//==========================================================================
+//  AIDA Detector description implementation for LCD
+//--------------------------------------------------------------------------
+// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
+// All rights reserved.
+//
+// For the licensing terms see $DD4hepINSTALL/LICENSE.
+// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
+//
+// Author     : F.Gaede
+//
+//==========================================================================
+
+#ifndef DD4HEP_DetType_H
+#define DD4HEP_DetType_H
+
+/// Namespace for the AIDA detector description toolkit
+namespace DD4hep {
+
+  /** Helper class for encoding sub detector types in a flag word.
+   *  Example:<br>
+   *  DetType type( DetType::TRACKER | DetType::STRIP | DetType::BARREL ) ; <br>
+   *  type.is( DetType::EMCALO  ) ; // false <br>
+   *  type.isNot( DetType::CALORIMETER  ) ; // true <br>
+   *  type.is( DetType::STRIP | DetType::BARREL ) ; // true <br>
+   *
+   * @author F.gaede, DESY
+   * @date 05.02.2016
+   * @version $Id: $
+   */
+  class DetType {
+
+    friend std::ostream& operator<<(std::ostream& os , const DetType& t   ) ;
+
+  public:
+
+    enum {
+      TRACKER      = 1 <<  0, 
+      CALORIMETER  = 1 <<  1, 
+      CHERENKOV    = 1 <<  2, 
+      ENDCAP	   = 1 <<  3, 
+      BARREL	   = 1 <<  4, 
+      FORWARD	   = 1 <<  5, 
+      VERTEX	   = 1 <<  6, 
+      STRIP	   = 1 <<  7, 
+      PIXEL	   = 1 <<  8, 
+      GASEOUS	   = 1 <<  9, 
+      WIRE	   = 1 << 10, 
+      EMCALO	   = 1 << 11, 
+      HADCALO	   = 1 << 12, 
+      MUON	   = 1 << 13, 
+      SUPPORT      = 1 << 14
+    } ;
+    
+
+    /// default c'tor
+    DetType( ) : _type(0) {}
+
+    /** initialize with a ulong containing all properties, e.g.
+     *  DetType type( DetType::TRACKER | DetType::STRIP | DetType::BARREL ) ;
+     */
+    DetType( unsigned long types ) : _type( types ){}
+    
+    /// set additional properties
+    inline void set(  unsigned long prop ) {
+      _type |= prop ;
+    }
+    
+    /// unset the given properties
+    inline void unset(  unsigned long prop ) {
+      _type &= ~prop ;
+    }
+    
+    /// true if detector has all properties
+    inline bool is( unsigned long prop ) const {
+      return ( _type & prop ) == prop ;
+    }
+
+    /// true if detector has none of the given properties
+    inline bool isNot( unsigned long prop ) const {
+      return ( _type & prop ) == 0 ;
+    }
+
+  private:
+    unsigned long _type ;
+  } ;
+  
+  inline std::ostream& operator<<( std::ostream& os , const DetType& t  ){
+    
+    os << "DetType( " << std::hex << "0x" << t._type << ") : " << std::dec ;
+    if( t.is( DetType::TRACKER      ) ) os << "TRACKER, " ;
+    if( t.is( DetType::CALORIMETER  ) ) os << "CALORIMETER, " ;
+    if( t.is( DetType::CHERENKOV    ) ) os << "CHERENKOV, " ;
+    if( t.is( DetType::ENDCAP	    ) ) os << "ENDCAP, " ;
+    if( t.is( DetType::BARREL	    ) ) os << "BARREL, " ;
+    if( t.is( DetType::FORWARD	    ) ) os << "FORWARD, " ;
+    if( t.is( DetType::VERTEX	    ) ) os << "VERTEX, " ;
+    if( t.is( DetType::STRIP	    ) ) os << "STRIP, " ;
+    if( t.is( DetType::PIXEL	    ) ) os << "PIXEL, " ;
+    if( t.is( DetType::GASEOUS	    ) ) os << "GASEOUS, " ;
+    if( t.is( DetType::WIRE	    ) ) os << "WIRE, " ;
+    if( t.is( DetType::EMCALO	    ) ) os << "EMCALO, " ;
+    if( t.is( DetType::HADCALO	    ) ) os << "HADCALO, " ;
+    if( t.is( DetType::MUON	    ) ) os << "MUON, " ;
+    if( t.is( DetType::SUPPORT      ) ) os << "SUPPORT, " ;
+    return os ;
+  }
+
+  
+} /* End namespace DD4hep        */
+
+#endif    /* DD4HEP_DETECTOR_H      */
diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt
index 26c77350b..ed7e136df 100644
--- a/DDTest/CMakeLists.txt
+++ b/DDTest/CMakeLists.txt
@@ -21,9 +21,9 @@ dd4hep_add_test_reg ( test_units               BUILD_EXEC REGEX_FAIL "TEST_FAILE
   EXEC_ARGS file:${CMAKE_CURRENT_SOURCE_DIR}/units.xml )
 dd4hep_add_test_reg ( test_surface             BUILD_EXEC REGEX_FAIL "TEST_FAILED" 
   EXEC_ARGS file:${CMAKE_CURRENT_SOURCE_DIR}/units.xml )
-dd4hep_add_test_reg ( test_bitfield64          BUILD_EXEC REGEX_FAIL "TEST_FAILED"
-  EXEC_ARGS file:${CMAKE_CURRENT_SOURCE_DIR}/units.xml )
 
+dd4hep_add_test_reg ( test_bitfield64          BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
+dd4hep_add_test_reg ( test_DetType            BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
 dd4hep_add_test_reg ( test_PolarGridRPhi2      BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
 dd4hep_add_test_reg ( test_cellDimensions      BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
 dd4hep_add_test_reg ( test_cellDimensionsRPhi2 BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
diff --git a/DDTest/src/test_DetType.cc b/DDTest/src/test_DetType.cc
new file mode 100644
index 000000000..61e10be35
--- /dev/null
+++ b/DDTest/src/test_DetType.cc
@@ -0,0 +1,66 @@
+#include "DD4hep/DDTest.h"
+#include <exception>
+#include <iostream>
+#include <assert.h>
+#include <cmath>
+
+#include "DD4hep/DetType.h"
+
+
+using namespace std ;
+using namespace DD4hep ;
+
+// this should be the first line in your test
+DDTest test = DDTest( "bitfield64" ) ; 
+
+//=============================================================================
+
+int main(int /* argc */, char** /* argv */ ){
+    
+  try{
+    
+    // ----- write your tests in here -------------------------------------
+
+    test.log( "test DetType" );
+    
+    DetType type( DetType::TRACKER | DetType::STRIP | DetType::BARREL ) ;
+
+    std::cout << type << std::endl ;
+
+    test(  type.is( DetType::TRACKER ) ,  true , " is DetType::TRACKER " ) ; 
+
+    test(  type.is( DetType::STRIP | DetType::BARREL ) ,  true , 
+	   " is DetType::STRIP | DetType::BARREL" ) ; 
+
+    test(  type.is( DetType::CALORIMETER ) ,  false , " DetType::CALORIMETER is false " ) ; 
+
+    test(  type.isNot( DetType::SUPPORT | DetType::CHERENKOV ) ,  true , 
+	   " is not DetType::SUPPORT | DetType::CHERENKOV " ) ;
+
+
+    type.unset( DetType::STRIP | DetType::BARREL  )  ;
+    
+    std::cout << type << std::endl ;
+    
+    type.set( DetType::PIXEL | DetType::ENDCAP | DetType::VERTEX  )  ;
+    
+    std::cout << type << std::endl ;
+   
+    test(  type.isNot( DetType::STRIP | DetType::BARREL ) ,  true , 
+	   " is not DetType::STRIP | DetType::BARREL " ) ;
+    
+
+    // --------------------------------------------------------------------
+
+
+  } catch( exception &e ){
+    //} catch( ... ){
+
+    test.log( e.what() );
+    test.error( "exception occurred" );
+  }
+
+  return 0;
+}
+
+//=============================================================================
diff --git a/UtilityApps/src/teve_display.cpp b/UtilityApps/src/teve_display.cpp
index 49fcfd3a5..d754b9368 100644
--- a/UtilityApps/src/teve_display.cpp
+++ b/UtilityApps/src/teve_display.cpp
@@ -133,7 +133,7 @@ static long teve_display(LCDD& lcdd, int /* argc */, char** /* argv */) {
   v->RefreshPadEditor(v);
   //  v->CurrentCamera().RotateRad(-1.2, 0.5);
 
-  gEve->GetGlobalScene()->GetGLScene()->SetSelectable(kFALSE);
+  gEve->GetGlobalScene()->GetGLScene()->SetSelectable(kFALSE) ; //change for debugging (kTRUE);
 
 
   MultiView::instance()->ImportGeomRPhi( surfaces );
-- 
GitLab