8 #include "EVENT/LCIO.h"
19 using namespace lcio ;
25 static string FILEN =
"calohit.slcio" ;
40 MYTEST.
LOG(
" writing CalorimeterHits " );
43 LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ;
45 lcWrt->open(
FILEN , LCIO::WRITE_NEW ) ;
51 LCEventImpl* evt =
new LCEventImpl() ;
54 evt->setRunNumber( 4711 ) ;
55 evt->setEventNumber( i ) ;
57 LCCollectionVec* calHits =
new LCCollectionVec( LCIO::CALORIMETERHIT ) ;
58 LCCollectionVec* calHitsErr =
new LCCollectionVec( LCIO::CALORIMETERHIT ) ;
59 LCFlagImpl calFlag( calHits->getFlag() ) ;
60 calFlag.setBit( LCIO::RCHBIT_LONG ) ;
61 calHits->setFlag( calFlag.getFlag() ) ;
63 calFlag.setBit( LCIO::RCHBIT_ENERGY_ERROR ) ;
64 calHitsErr->setFlag( calFlag.getFlag() ) ;
66 for(
int j=0;j<
NHITS;j++){
67 CalorimeterHitImpl* calHit =
new CalorimeterHitImpl ;
68 calHit->setEnergy( i*j*117. ) ;
69 calHit->setCellID0( i+100000 + j ) ;
70 float pos[3] = { float(i) , float(j) ,float(i*j) } ;
71 calHit->setPosition( pos ) ;
72 calHits->addElement( calHit ) ;
74 for(
int j=0;j<
NHITS;j++){
75 CalorimeterHitImpl* calHit =
new CalorimeterHitImpl ;
76 calHit->setEnergy( i*j*117. ) ;
77 calHit->setEnergyError( i*j*0.117 ) ;
78 calHit->setCellID0( i+100000 + j ) ;
79 float pos[3] = { float(i) , float(j) ,float(i*j) } ;
80 calHit->setPosition( pos ) ;
81 calHitsErr->addElement( calHit ) ;
83 evt->addCollection( calHits ,
"CalorimeterHits") ;
84 evt->addCollection( calHitsErr ,
"CalorimeterHitsWithEnergyError") ;
86 lcWrt->writeEvent(evt) ;
94 MYTEST.
LOG(
" reading back CalorimeterHits from file " ) ;
97 LCReader* lcRdr = LCFactory::getInstance()->createLCReader() ;
99 lcRdr->open(
FILEN ) ;
101 for(
int i=0;i<
NEVENT;i++){
105 LCEvent* evt = lcRdr->readNextEvent() ;
107 MYTEST( evt->getRunNumber() , 4711 ,
" run number " ) ;
109 MYTEST( evt->getEventNumber() , i ,
" event number " ) ;
111 LCCollection* calHits = evt->getCollection(
"CalorimeterHits") ;
112 LCCollection* calHitsErr = evt->getCollection(
"CalorimeterHitsWithEnergyError") ;
114 for(
int j=0;j<
NHITS;j++) {
118 CalorimeterHit* calHit =
dynamic_cast<CalorimeterHit*
>(calHits->getElementAt(j)) ;
120 MYTEST( calHit->getEnergy() , i*j*117. ,
"energy" ) ;
121 MYTEST( calHit->getCellID0() , i+100000 + j ,
" cellid0 " ) ;
123 const float* pos = calHit->getPosition() ;
125 MYTEST( pos[0] , i ,
" pos[0] " ) ;
126 MYTEST( pos[1] , j ,
" pos[1] " ) ;
127 MYTEST( pos[2] , i*j ,
" pos[2] " ) ;
130 for(
int j=0;j<
NHITS;j++) {
134 CalorimeterHit* calHit =
dynamic_cast<CalorimeterHit*
>(calHitsErr->getElementAt(j)) ;
136 MYTEST( calHit->getEnergy() , i*j*117. ,
"energy" ) ;
137 MYTEST( calHit->getEnergyError() , float(i*j*0.117) ,
"energy error" ) ;
138 MYTEST( calHit->getCellID0() , i+100000 + j ,
" cellid0 " ) ;
140 const float* pos = calHit->getPosition() ;
142 MYTEST( pos[0] , i ,
" pos[0] " ) ;
143 MYTEST( pos[1] , j ,
" pos[1] " ) ;
144 MYTEST( pos[2] , i*j ,
" pos[2] " ) ;
151 }
catch( Exception &e ){
152 MYTEST.
FAILED( e.what() );
void FAILED(const std::string &msg)
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
void LOG(const std::string &msg)
static const string testname