Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:42

0001 #include "DD4hep/DDTest.h"
0002 #include <exception>
0003 #include <iostream>
0004 #include <assert.h>
0005 #include <cmath>
0006 
0007 #include "DDSegmentation/BitField64.h"
0008 
0009 using namespace std;
0010 using namespace dd4hep;
0011 using namespace DDSegmentation;
0012 
0013 //=============================================================================
0014 int main(int /* argc */, char** /* argv */ ){
0015     
0016   DDTest test( "bitfield64" ) ; 
0017 
0018   try{
0019     // ----- write your tests in here -------------------------------------
0020     test.log( "test bitfield64" );
0021 
0022     // initialize with a string that uses all 64 bits :
0023     BitField64 bf("system:5,side:-2,layer:9,module:8,sensor:8,x:32:-16,y:-16" ) ;
0024 
0025     BitField64 bf2( bf.fieldDescription() ) ;
0026     BitField64 bf3( bf.fieldDescription() ) ;
0027 
0028 
0029     test(  bf.getValue() , CellID(0x0) , " initialized with 0 " ); 
0030 
0031     //    std::cout  << " bf value : " << bf << std::endl ;
0032     
0033     bf.setValue( 0xbebafecacafebabe ) ;
0034 
0035     //    std::cout  << " bf value : " << bf << std::endl ;
0036 
0037     test(  bf.getValue() , 0xbebafecacafebabeULL, 
0038        " initialized with 0xbebafecacafebabeUL - compare as signed " ); 
0039 
0040     test( bf.getValue()   , 0xbebafecacafebabeULL  , 
0041        " initialized with 0xbebafecacafebabeUL - compare as unsigned " ); 
0042 
0043 
0044     // set some 'random' values to bf2 
0045 
0046     bf2["layer"]   = 373 ;
0047     bf2["module"]  = 254 ;
0048     bf2["sensor"]  = 202 ;
0049     bf2["side"]    = 1 ;
0050     bf2["system"]  = 30 ;
0051     bf2["x"]       = -310 ;
0052     bf2["y"]       = -16710 ;
0053 
0054 
0055     test(  bf.getValue() , bf2.getValue()  , " same value 0xbebafecacafebabeUL from individual initialization " ); 
0056 
0057     // check for setting high and low words indiviually :
0058 
0059     bf3.setValue(  bf.lowWord() , bf.highWord() ) ; 
0060 
0061     test(  bf3.getValue() , bf2.getValue()  , " same value 0xbebafecacafebabeUL from setting low and high word " ); 
0062 
0063 
0064     test(  bf3["layer"] , 373  , " get value for \"layer\": 373  " );
0065 
0066     unsigned xIndex = bf2.index( "x" ) ;
0067 
0068     test(  bf3[xIndex] , -310  , " get value for xIndex : -310  " );
0069 
0070     // --------------------------------------------------------------------
0071 
0072 
0073   } catch( exception &e ){
0074     //} catch( ... ){
0075 
0076     test.log( e.what() );
0077     test.error( "exception occurred" );
0078   }
0079 
0080   return 0;
0081 }
0082 
0083 //=============================================================================