LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
readcalibration.cc
Go to the documentation of this file.
1 #include "lcio.h"
2 
3 #include "IO/LCReader.h"
4 #include "UTIL/LCTOOLS.h"
5 #include "EVENT/LCRunHeader.h"
6 #include "EVENT/LCCollection.h"
7 
8 #include "CalibrationConstant.h"
9 
10 // needed for gcc 4.4
11 #include <cstdlib>
12 
13 static const char* FILEN ;
14 
15 //using namespace std ;
16 using namespace lcio ;
17 
21 int main(int argc, char** argv ){
22 
23  // read file names from command line (only argument)
24  if( argc != 2) {
25  std::cout << " usage: readcalibration input-file1" << std::endl ;
26  exit(1) ;
27  }
28 
29  FILEN = argv[1] ;
30 
31  LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
32 
33  lcReader->open( FILEN ) ;
34 
35  LCEvent* evt ;
36  int nEvents = 0 ;
37 
38  //----------- the event loop -----------
39  while( (evt = lcReader->readNextEvent()) != 0 ) {
40 
41  // loop over collections and check if we have objects of user defined
42  // type "CalibrationConstant"
43  // NB: this is only needed if you don't know the name of the collection
44  // that holds the calibration constants
45 
46  const StringVec* colNames = evt->getCollectionNames() ;
47 
48  for(unsigned int i=0 ; i < colNames->size() ; i++ ){
49 
50  LCCollection* col = evt->getCollection( (*colNames)[i] ) ;
51 
52  if( col->getParameters().getStringVal("TypeName") == "CalibrationConstant" ) {
53 
54 
55  // now print the calibration constants
56  for(int j=0;j<col->getNumberOfElements();j++){
57 
58  CalibrationConstant cal( col->getElementAt( j ) ) ;
59 
60  std::cout << " calibration for cellid: " << cal.getCellID()
61  << " offset: " << cal.getOffset()
62  << " gain: " << cal.getGain()
63  << std::endl ;
64 
65  }
66 
67  }
68  }
69 
70  nEvents ++ ;
71  }
72  // -------- end of event loop -----------
73 
74  std::cout << std::endl << " " << nEvents << " events read from file: "
75  << FILEN << std::endl ;
76 
77 
78  lcReader->close() ;
79  delete lcReader ;
80  return 0 ;
81 }
82 
83 
std::vector< std::string > StringVec
Vector of strings.
Definition: LCIOSTLTypes.h:16
static const char * FILEN
T endl(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...
Example for a simple calibration class based on the LCFixedObject template.
LCReader * lcReader
Definition: lsh.cc:78