00001
00002
00003
00004
00005 #include "tutil.h"
00006 #include "lcio.h"
00007
00008 #include "EVENT/LCIO.h"
00009 #include "IO/LCReader.h"
00010 #include "IO/LCWriter.h"
00011 #include "IMPL/LCEventImpl.h"
00012 #include "IMPL/LCCollectionVec.h"
00013 #include "IMPL/TrackerPulseImpl.h"
00014 #include "IMPL/LCFlagImpl.h"
00015
00016
00017
00018 using namespace std ;
00019 using namespace lcio ;
00020
00021
00022 static const int NEVENT = 10 ;
00023 static const int NPULSES = 1000 ;
00024
00025 static string FILEN = "trackerpulses.slcio" ;
00026
00027
00028 const static string testname="test_trackerpulse";
00029
00030
00031
00032 int main(int argc, char** argv ){
00033
00034
00035 TEST MYTEST=TEST( testname, std::cout );
00036
00037 try{
00038
00039
00040 MYTEST.LOG( " writing TrackerPulses " );
00041
00042
00043 LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ;
00044
00045 lcWrt->open( FILEN , LCIO::WRITE_NEW ) ;
00046
00047
00048 for(int i=0;i<NEVENT;i++){
00049
00050
00051 LCEventImpl* evt = new LCEventImpl() ;
00052
00053
00054 evt->setRunNumber( 4711 ) ;
00055 evt->setEventNumber( i ) ;
00056
00057 LCCollectionVec* trkPulses = new LCCollectionVec( LCIO::TRACKERPULSE ) ;
00058 LCCollectionVec* trkPulsesCov = new LCCollectionVec( LCIO::TRACKERPULSE ) ;
00059
00060 LCFlagImpl flag( trkPulsesCov->getFlag() ) ;
00061 flag.setBit( LCIO::TRAWBIT_CM ) ;
00062 trkPulsesCov->setFlag( flag.getFlag() ) ;
00063
00064
00065 for(int j=0;j<NPULSES;j++){
00066 TrackerPulseImpl* trkPulse = new TrackerPulseImpl ;
00067 trkPulse->setTime( 3.1415 + 0.1 * i ) ;
00068
00069 trkPulse->setCharge( 3.1415 + 0.1 * j ) ;
00070
00071
00072 trkPulses->addElement( trkPulse ) ;
00073 }
00074 for(int j=0;j<NPULSES;j++){
00075 TrackerPulseImpl* trkPulse = new TrackerPulseImpl ;
00076 trkPulse->setTime( 3.1415 + 0.1 * i ) ;
00077
00078 trkPulse->setCharge( 3.1415 + 0.1 * j ) ;
00079
00080
00081 float cov[3] = { i, j, i*j } ;
00082 trkPulse->setCovMatrix( cov );
00083
00084 trkPulsesCov->addElement( trkPulse ) ;
00085 }
00086
00087 evt->addCollection( trkPulses , "TrackerPulses") ;
00088 evt->addCollection( trkPulsesCov , "TrackerPulsesWithCovMatrix") ;
00089
00090 lcWrt->writeEvent(evt) ;
00091
00092 delete evt ;
00093 }
00094
00095
00096 lcWrt->close() ;
00097
00098 MYTEST.LOG(" reading back TrackerPulses from file " ) ;
00099
00100
00101 LCReader* lcRdr = LCFactory::getInstance()->createLCReader() ;
00102
00103 lcRdr->open( FILEN ) ;
00104
00105 for(int i=0;i<NEVENT;i++){
00106
00107
00108
00109 LCEvent* evt = lcRdr->readNextEvent() ;
00110
00111 MYTEST( evt->getRunNumber() , 4711 , " run number " ) ;
00112
00113 MYTEST( evt->getEventNumber() , i , " event number " ) ;
00114
00115 LCCollection* trkPulses = evt->getCollection( "TrackerPulses") ;
00116
00117
00118
00119 for(int j=0;j<NPULSES;j++) {
00120
00121
00122
00123 TrackerPulse* trkPulse = dynamic_cast<TrackerPulse*>(trkPulses->getElementAt(j)) ;
00124
00125 MYTEST( trkPulse->getTime(), float( 3.1415 + 0.1 * i ), "time" ) ;
00126
00127 MYTEST( trkPulse->getCharge(), float( 3.1415 + 0.1 * j ), "charge" ) ;
00128
00129
00130
00131 const FloatVec& cov = trkPulse->getCovMatrix() ;
00132
00133
00134 MYTEST( cov[0] , 0 , " cov[0] " ) ;
00135 MYTEST( cov[1] , 0 , " cov[1] " ) ;
00136 MYTEST( cov[2] , 0 , " cov[2] " ) ;
00137
00138 }
00139
00140 LCCollection* trkPulsesCov = evt->getCollection( "TrackerPulsesWithCovMatrix") ;
00141
00142
00143
00144 for(int j=0;j<NPULSES;j++) {
00145
00146
00147
00148 TrackerPulse* trkPulse = dynamic_cast<TrackerPulse*>(trkPulsesCov->getElementAt(j)) ;
00149
00150 MYTEST( trkPulse->getTime(), float( 3.1415 + 0.1 * i ), "time" ) ;
00151
00152 MYTEST( trkPulse->getCharge(), float( 3.1415 + 0.1 * j ), "charge" ) ;
00153
00154 const FloatVec& cov = trkPulse->getCovMatrix() ;
00155
00156 MYTEST( cov[0] , i , " cov[0] " ) ;
00157 MYTEST( cov[1] , j , " cov[1] " ) ;
00158 MYTEST( cov[2] , i*j , " cov[2] " ) ;
00159 }
00160
00161 }
00162 lcRdr->close() ;
00163
00164
00165 } catch( Exception &e ){
00166 MYTEST.FAILED( e.what() );
00167 }
00168
00169 return 0;
00170 }
00171
00172
00173