Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CellIDDecoder.h

Go to the documentation of this file.
00001 #ifndef CellIDDecoder_h
00002 #define CellIDDecoder_h 1
00003 
00004 //#include <vector>
00005 //#include "EVENT/LCObject.h"
00006 #include "EVENT/LCCollection.h"
00007 #include "EVENT/SimTrackerHit.h"
00008 #include "UTIL/BitField64.h"
00009 #include "lcio.h"
00010 #include <string>
00011 
00012 // fixes problem in gcc 4.0.3
00013 #include "EVENT/LCParameters.h"
00014 
00015 //#include <sstream>
00016 //#include <typeinfo>
00017 
00018 using namespace lcio ;
00019 
00020 namespace UTIL{
00021 
00022 
00023   /** Convenient class for decoding cellIDs from collection parameter LCIO::CellIDEncoding.
00024    *  See UTIL::BitField64 for a description of the encoding string. 
00025    * 
00026    *  @see BitField64
00027    *  @version $Id: CellIDDecoder.h,v 1.9 2006/12/08 10:18:59 gaede Exp $
00028    */
00029   template <class T> 
00030   class CellIDDecoder {
00031     
00032   public:  
00033     
00034     /** Constructor reads encoding string from collection parameter LCIO::CellIDEncoding.
00035      */
00036     CellIDDecoder( const LCCollection* col ) : _oldHit(0) {
00037       
00038       std::string initString("") ; 
00039 
00040       if( col !=0 ) 
00041         initString = col->getParameters().getStringVal(  LCIO::CellIDEncoding ) ;
00042       
00043       if( initString.size() == 0 ) {
00044         
00045         initString = *_defaultEncoding ;
00046 
00047         std::cout << "    ----------------------------------------- " << std::endl  
00048                   << "       WARNING: CellIDDecoder - no CellIDEncoding parameter in collection ! " 
00049                   << std::endl 
00050                   << "         -> using default : \"" << initString << "\"" 
00051                   << std::endl 
00052                   << "    ------------------------------------------ "  
00053                   << std::endl ;
00054       }
00055       
00056       _b = new BitField64(  initString ) ; 
00057     }
00058     
00059     ~CellIDDecoder(){ 
00060       
00061       delete _b ;
00062     } 
00063     
00064     
00065     /** Provides access to the bit fields, e.g. <br>
00066      *   int layer =  myCellIDEncoding( hit )[ "layer" ] ;
00067      * 
00068      */
00069     inline const BitField64 & operator()( T* hit ){  
00070       
00071       if( hit != _oldHit && hit ) {
00072         
00073 
00074         long64 val = long64( hit->getCellID0() & 0xffffffff ) 
00075           |        ( long64( hit->getCellID1() ) << 32      ) ;
00076         
00077         _b->setValue( val ) ;
00078 
00079         _oldHit = hit ;
00080       }
00081       
00082       return  *_b ;
00083     }
00084     
00085 
00086     /** This can be used to set the default encoding that is used if no
00087      *  CellIDEncoding parameter is set in the collection, e.g. in older lcio files.
00088      */ 
00089     static void setDefaultEncoding(const std::string& defaultEncoding ) {
00090       
00091       delete _defaultEncoding ;
00092       
00093       _defaultEncoding = new std::string( defaultEncoding ) ;
00094     }
00095     
00096   protected:
00097     BitField64* _b ;
00098     T* _oldHit ;
00099     
00100     static std::string*  _defaultEncoding ;
00101   } ; 
00102   
00103   template <class T>
00104   std::string* CellIDDecoder<T>::_defaultEncoding 
00105   = new std::string("byte0:8,byte1:8,byte2:8,byte3:8,byte4:8,byte5:8,byte6:8,byte7:8") ;
00106 
00107   
00108 
00109   /** Provides access to the bit fields, e.g. <br>
00110    *   int layer =  myCellIDEncoding( hit )[ "layer" ] ;
00111    * Specialization for SimTrackerHits that have only one cellID.
00112    */
00113   template<>
00114   inline const BitField64 & CellIDDecoder<SimTrackerHit>::operator()( SimTrackerHit* hit ){  
00115     
00116     if( hit != _oldHit && hit ) {
00117       
00118       long64 val = long64( hit->getCellID() & 0xffffffff )  ;
00119       
00120       _b->setValue( val ) ;
00121       
00122       _oldHit = hit ;
00123     }
00124     
00125     return  *_b ;
00126   }
00127   
00128   
00129   template <>
00130   std::string* CellIDDecoder<SimTrackerHit>::_defaultEncoding  ;
00131 
00132 } // namespace
00133 #endif
00134 
00135 

Generated on Sun Jun 3 06:32:01 2007 for A TPC Tracking Environment by  doxygen 1.3.9.1