8 #include "EVENT/LCIO.h"
19 using namespace lcio ;
25 static string FILEN =
"cluster.slcio" ;
40 MYTEST.
LOG(
" writing Clusters " );
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* clusters =
new LCCollectionVec( LCIO::CLUSTER ) ;
58 LCCollectionVec* clustersErr =
new LCCollectionVec( LCIO::CLUSTER ) ;
60 for(
int j=0;j<
NHITS;j++){
61 ClusterImpl* clu =
new ClusterImpl ;
62 clu->setEnergy( i*j*117. ) ;
63 float pos[3] = { float(i) , float(j) ,float(i*j) } ;
64 clu->setPosition( pos ) ;
65 clusters->addElement( clu ) ;
67 for(
int j=0;j<
NHITS;j++){
68 ClusterImpl* clu =
new ClusterImpl ;
69 clu->setEnergy( i*j*117. ) ;
70 clu->setEnergyError( i*j*0.117 ) ;
71 float pos[3] = { float(i) , float(j) ,float(i*j) } ;
72 clu->setPosition( pos ) ;
73 clustersErr->addElement( clu ) ;
75 evt->addCollection( clusters ,
"Clusters") ;
76 evt->addCollection( clustersErr ,
"ClustersWithEnergyError") ;
78 lcWrt->writeEvent(evt) ;
86 MYTEST.
LOG(
" reading back Clusters from file " ) ;
89 LCReader* lcRdr = LCFactory::getInstance()->createLCReader() ;
91 lcRdr->open(
FILEN ) ;
97 LCEvent* evt = lcRdr->readNextEvent() ;
99 MYTEST( evt->getRunNumber() , 4711 ,
" run number " ) ;
101 MYTEST( evt->getEventNumber() , i ,
" event number " ) ;
103 LCCollection* clusters = evt->getCollection(
"Clusters") ;
104 LCCollection* clustersErr = evt->getCollection(
"ClustersWithEnergyError") ;
106 for(
int j=0;j<
NHITS;j++) {
110 Cluster* clu =
dynamic_cast<Cluster*
>(clusters->getElementAt(j)) ;
112 MYTEST( clu->getEnergy() , i*j*117. ,
"energy" ) ;
114 const float* pos = clu->getPosition() ;
116 MYTEST( pos[0] , i ,
" pos[0] " ) ;
117 MYTEST( pos[1] , j ,
" pos[1] " ) ;
118 MYTEST( pos[2] , i*j ,
" pos[2] " ) ;
121 for(
int j=0;j<
NHITS;j++) {
125 Cluster* clu =
dynamic_cast<Cluster*
>(clustersErr->getElementAt(j)) ;
127 MYTEST( clu->getEnergy() , i*j*117. ,
"energy" ) ;
128 MYTEST( clu->getEnergyError() , float(i*j*0.117) ,
"energy error" ) ;
130 const float* pos = clu->getPosition() ;
132 MYTEST( pos[0] , i ,
" pos[0] " ) ;
133 MYTEST( pos[1] , j ,
" pos[1] " ) ;
134 MYTEST( pos[2] , i*j ,
" pos[2] " ) ;
141 }
catch( Exception &e ){
142 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