LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dumpevent.cc
Go to the documentation of this file.
1 #include "lcio.h"
2 #include <stdio.h>
3 
4 #include "IO/LCReader.h"
5 #include "IMPL/LCTOOLS.h"
6 #include "EVENT/LCRunHeader.h"
7 
9 #include "EVENT/CalorimeterHit.h"
10 #include "EVENT/RawCalorimeterHit.h"
11 // #include "EVENT/SimTrackerHit.h"
12 
13 #include "UTIL/CellIDDecoder.h"
14 
15 #include <cstdlib>
16 
17 using namespace std ;
18 using namespace lcio ;
19 
23 int main(int argc, char** argv ){
24 
25 
26  char* FILEN ;
27  int runNumber=0 ;
28  int evtNumber=0 ;
29  int nthEvent=1 ;
30 
31  // read file name from command line (only argument)
32  if( argc < 3 ) {
33 
34  cout << " usage: dumpevent filename runNum evtNum " << endl ;
35  cout << " or: dumpevent filename n " << endl ;
36  cout << " where the first dumps the event with the specified run and event number" << endl ;
37  cout << " and the second simply dumps the n-th event in the file" << endl << endl ;
38  cout << " set the environment variable LCIO_READ_COL_NAMES to a space separated list" << endl ;
39  cout << " of collection names that you would like to dump (all are dumped if not set)" << endl ;
40 
41  exit(1) ;
42  }
43 
44  FILEN = argv[1] ;
45 
46  bool dumpNthEvent( argc == 3 ) ;
47 
48 
49  if( dumpNthEvent ) {
50 
51  nthEvent = atoi( argv[2] ) ;
52 
53  if( nthEvent < 1 ) {
54 
55  cout << " usage: dumpevent filename n - whith n > 0 ! " << endl ;
56 
57  exit(1) ;
58  }
59 
60  }else{
61 
62  runNumber = atoi( argv[2] ) ;
63  evtNumber = atoi( argv[3] ) ;
64  }
65 
66 
67  // set the default encoding for cellid's according to the old Mokka convention
68  // CellIDDecoder<SimCalorimeterHit>::setDefaultEncoding("M:3,S-1:3,I:9,J:9,K-1:6") ;
69  // CellIDDecoder<CalorimeterHit>::setDefaultEncoding("M:3,S-1:3,I:9,J:9,K-1:6") ;
70  // CellIDDecoder<RawCalorimeterHit>::setDefaultEncoding("M:3,S-1:3,I:9,J:9,K-1:6") ;
71 
72  LCReader* lcReader ;
73  if( dumpNthEvent )
74  lcReader = LCFactory::getInstance()->createLCReader() ;
75  else
76  lcReader = LCFactory::getInstance()->createLCReader(LCReader::directAccess) ;
77 
78 
79  // ------ check if LCIO_READ_COL_NAMES is set -------------
80 
81  char* rColChar = getenv ("LCIO_READ_COL_NAMES");
82 
83  if ( rColChar != 0 ) {
84 
85  std::vector< std::string > colSubset ;
86  std::stringstream sts( rColChar ) ;
87  std::string colName;
88 
89  while( sts >> colName) {
90 
91  colSubset.push_back( colName ) ;
92  }
93 
94  lcReader->setReadCollectionNames( colSubset ) ;
95  }
96  //-----------------------------------------------------------
97 
98 
99 
100  LCEvent* evt(0) ;
101 
102  try{
103 
104  lcReader->open( FILEN ) ;
105 
106  if( dumpNthEvent ) {
107 
108  if( nthEvent > 0 )
109  lcReader->skipNEvents( nthEvent - 1 ) ;
110 
111  evt = lcReader->readNextEvent() ;
112 
113  }else{
114 
115  evt = lcReader->readEvent(runNumber, evtNumber) ;
116  }
117 
118 
119  // } catch( EndOfDataException& e) {
120  // cout << " couldn't find event " << evtNumber << " - run " << runNumber
121  // << " in file " << FILEN << endl ;
122  // exit(1) ;
123 
124  if( !evt ){
125 
126  if(dumpNthEvent){
127 
128  cout << " less than " << nthEvent << " events in file " << FILEN << endl ;
129 
130  }else{
131 
132  cout << " couldn't find event " << evtNumber << " - run " << runNumber
133  << " in file " << FILEN << endl ;
134  }
135 
136  exit(1) ;
137  }
138 
139  LCTOOLS::dumpEventDetailed( evt ) ;
140 
141 
142  lcReader->close() ;
143 
144  }
145  catch( IOException& e) {
146  cout << e.what() << endl ;
147  exit(1) ;
148  }
149 
150 // catch( Exception& e) {
151 // cout << e.what() << endl ;
152 // exit(1) ;
153 // }
154  return 0 ;
155 }
156 
T atoi(T...args)
T endl(T...args)
STL class.
T getenv(T...args)
T push_back(T...args)
T exit(T...args)
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
LCReader * lcReader
Definition: lsh.cc:78
static std::vector< std::string > FILEN