00001 #include "lcio.h"
00002
00003 #include "IO/LCWriter.h"
00004 #include "EVENT/LCIO.h"
00005 #include <EVENT/RawCalorimeterHit.h>
00006 #include "DATA/LCFloatVec.h"
00007 #include "DATA/LCIntVec.h"
00008
00009 #include "IMPL/LCEventImpl.h"
00010 #include "IMPL/LCRunHeaderImpl.h"
00011 #include "IMPL/LCCollectionVec.h"
00012 #include "IMPL/RawCalorimeterHitImpl.h"
00013 #include "IMPL/SimTrackerHitImpl.h"
00014 #include "IMPL/MCParticleImpl.h"
00015 #include "IMPL/LCFlagImpl.h"
00016 #include "IMPL/LCTOOLS.h"
00017
00018 #include "IMPL/TrackerRawDataImpl.h"
00019 #include "IMPL/TrackerDataImpl.h"
00020 #include "IMPL/TrackerPulseImpl.h"
00021
00022 #include "UTIL/LCRelationNavigator.h"
00023 #include "UTIL/LCTime.h"
00024
00025 #include "UTIL/CellIDEncoder.h"
00026 #include "UTIL/CellIDDecoder.h"
00027 #include <UTIL/BitField64.h>
00028 #include "UTIL/LCTypedVector.h"
00029
00030 #include "UTIL/LCSplitWriter.h"
00031
00032 #include "mTypes.h"
00033 #include "geometry/Detector.hh"
00034 #include "event/Run.hh"
00035 #include "geometry/Dif.hh"
00036 #include "geometry/Chip.hh"
00037 #include "geometry/Channel.hh"
00038 #include "tools/SteerDesc.hh"
00039 #include "xml/XMLTool.hh"
00040
00041
00042
00043 #include <cstdlib>
00044 #include <iostream>
00045 #include <sstream>
00046
00047
00048 using namespace std ;
00049 using namespace lcio ;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 int main(int argc, char** argv )
00061 {
00062 if( argc !=2 && argc !=3 )
00063 {
00064 cout << endl <<"usage lcioTest slcioFile [xmlFile]" <<endl;
00065 exit(-1);
00066 }
00067
00068 bool geometrySet = false;
00069
00070
00071 static string lcioFile = argv[1] ;
00072
00073 Detector detector;
00074 if ( argc == 3 )
00075 {
00076 geometrySet = true;
00077 string steerName;
00078 steerName.assign(argv[2]);
00079
00080
00081 FILE *file = fopen(steerName.c_str(), "r");
00082 if(file == NULL){
00083 cout << "Steer file ["<< steerName.c_str() << "] does not exist" << endl;
00084 fclose(file);
00085 exit(0);
00086 }
00087
00088
00089 Run run(detector);
00090 SteerDesc steerDesc;
00091 XMLTool xml;
00092 xml.parse(steerDesc, steerName);
00093
00094 if ( ! steerDesc.setRun(run))
00095 {
00096 exit(1);
00097 }
00098 fclose(file);
00099 detector.build(steerDesc);
00100 }
00101
00102
00103
00104 IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
00105 lcReader->open( lcioFile ) ;
00106
00107
00108 LCEvent* evt = NULL;
00109
00110 while( (evt = lcReader->readNextEvent()) != 0 )
00111 {
00112
00113 cout << endl << endl << endl << " NEW EVENT " << endl;
00114 UTIL::LCTOOLS::dumpEvent( evt ) ;
00115 EVENT::long64 timestamp = evt->getTimeStamp();
00116
00117 LCTime time(timestamp);
00118 cout << time.getDateString() << endl;
00119
00120 cout << "Dif synchro: " << evt->getParameters().getIntVal("Dif_syncro" ) << endl ;
00121 cout << "Temperature:" << evt->parameters().getFloatVal("Temperature" ) << endl ;
00122 cout << "Pressure:" << evt->parameters().getFloatVal("Pressure") << endl;
00123 cout << "globalTriggerCounter:" << evt->parameters().getIntVal("Global trigger counter") << endl;
00124 cout << "difTriggerCounter:" << evt->parameters().getIntVal("Dif trigger counter" ) << endl;
00125
00126 const vector<string>* collNames = evt->getCollectionNames ();
00127
00128 vector<string>::const_iterator it;
00129
00130 for ( it = collNames->begin(); it!=collNames->end(); ++it)
00131 {
00132 cout << *it << endl;
00133 LCCollection* collec = evt->getCollection(*it);
00134 cout << " collection type:" << collec->getTypeName() << endl;
00135 for ( int i = 0; i < collec->getNumberOfElements(); i++)
00136 {
00137 try
00138 {
00139 RawCalorimeterHit* rawHit = dynamic_cast<RawCalorimeterHit*>(collec->getElementAt(i));
00140
00141
00142 if ( rawHit != NULL )
00143 {
00144 CellIDDecoder<RawCalorimeterHit> idDecoder( collec ) ;
00145 const BitField64& bitField = idDecoder( rawHit );
00146
00147 cout << idDecoder( rawHit ).valueString() << endl;
00148 lcio::long64 chamberId = bitField["CHAMBER"] ;
00149 lcio::long64 difId = bitField["DIF"] ;
00150 lcio::long64 chipId = bitField["CHIP"] ;
00151 lcio::long64 channelId = bitField["CHANNEL"] ;
00152 cout << "Chamber[" << chamberId<< "] " ;
00153 cout << "Dif[" <<difId << "] " ;
00154 cout << "Chip[" <<chipId << "] " ;
00155 cout << "Channel[" << channelId << "]" << endl;
00156
00157 if ( geometrySet )
00158 {
00159 Channel &channel = detector.getDifById(difId).getChipById(chipId).getChannelById(channelId);
00160 cout << " Position[X,Y,Z] = [" << channel.getX() << "," << channel.getY() << "," << channel.getZ() << "]" << endl;
00161 }
00162
00163
00164 }
00165 else { cout << " rawHit == NULL "<< endl; }
00166 } catch( Exception& ex)
00167 {
00168 cout << " an excpetion occured when trying dynamic_cast<RawCalorimeterHit*>: " << endl ;
00169 cout << " " << ex.what() << endl ;
00170 }
00171 }
00172 }
00173 const LCParameters& params = evt->getParameters();
00174 }
00175
00176 lcReader->close() ;
00177
00178 delete lcReader ;
00179
00180
00181 }
00182