Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StdHepReader.cc
Go to the documentation of this file.
1 
2 #include "marlin/StdHepReader.h"
3 
4 #include "marlin/ProcessorMgr.h"
5 
6 #include "IMPL/LCEventImpl.h"
7 #include "IMPL/LCRunHeaderImpl.h"
8 
9 #include "UTIL/LCStdHepRdr.h"
10 #include "UTIL/LCTOOLS.h"
11 
12 
13 namespace marlin{
14 
15 
16 
18 
19 
20  StdHepReader::StdHepReader() : DataSourceProcessor("StdHepReader"),_fileName("") {
21 
22  _description = "Reads StdHep files as input and creates LCIO events with MCParticle collections."
23  " Make sure to not specify any LCIOInputFiles in the steering in order to read StdHep files." ;
24 
25  registerProcessorParameter( "StdHepFileName" ,
26  "input file" ,
27  _fileName ,
28  std::string("input.stdhep") ) ;
29 
30  }
31 
33  return new StdHepReader ;
34  }
35 
37  printParameters() ;
38  }
39 
40 
41  void StdHepReader::readDataSource( int numEvents ) {
42 
43  LCStdHepRdr* rdr = new LCStdHepRdr( _fileName.c_str() ) ;
44 
45  LCCollection* col ;
46  LCEventImpl* evt ;
47 
48  int evtNum = 0 ;
49  int runNum = 0 ;
50 
51  while( ( col = rdr->readEvent() ) != 0 ) {
52 
53  if ( numEvents > 0 && evtNum+1 > numEvents )
54  {
55  delete col;
56  break;
57  }
58 
59  if( isFirstEvent() ) { // create run header
60 
61  LCRunHeaderImpl* rHdr = new LCRunHeaderImpl ;
62 
63  rHdr->setDescription( " Events read from stdhep input file: " + _fileName ) ;
64  rHdr->setRunNumber( runNum ) ;
65 
67  _isFirstEvent = false ;
68  }
69 
70  evt = new LCEventImpl ;
71  evt->setRunNumber( runNum ) ;
72  evt->setEventNumber( evtNum++ ) ;
73 
74 
75  evt->addCollection( col, "MCParticle" ) ;
76 
78 
79  delete evt ;
80  }
81 
82  delete rdr ;
83  }
84 
85 
86 
88 
89  }
90 
91 
92 }
void registerProcessorParameter(const std::string &parameterName, const std::string &parameterDescription, T &parameter, const T &defaultVal, int setSize=0)
Register a steering variable for this processor - call in constructor of processor.
Definition: Processor.h:254
static ProcessorMgr * instance()
Return the instance of this manager.
Definition: ProcessorMgr.cc:60
Base class for data source handlers that can read arbitrary non-LCIO input files and create LCIO even...
virtual void end()
Called after data processing for clean up in the inverse order of the init() method so that resources...
Definition: StdHepReader.cc:87
virtual void processEvent(LCEvent *)
virtual StdHepReader * newProcessor()
Return a new instance of the processor.
Definition: StdHepReader.cc:32
STL class.
void printParameters()
Print the parameters and their values depending on the given verbosity level.
Definition: Processor.h:156
std::string _fileName
Definition: StdHepReader.h:49
bool isFirstEvent()
True if first event in processEvent(evt) - use this e.g.
Definition: Processor.h:198
virtual void processRunHeader(LCRunHeader *)
T c_str(T...args)
StdHepReader aStdHepReader
Definition: StdHepReader.cc:17
virtual void readDataSource(int numEvents)
Creates events with MCParticle collections from the StdHep input file and calls all active processors...
Definition: StdHepReader.cc:41
std::string _description
Describes what the processor does.
Definition: Processor.h:452
virtual void init()
Called at the begin of the job before anything is read.
Definition: StdHepReader.cc:36
Reads binary StdHep files.
Definition: StdHepReader.h:28