Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AIDAProcessor.cc
Go to the documentation of this file.
1 #include "marlin/MarlinConfig.h" // defines MARLIN_CLHEP / MARLIN_AIDA
2 
3 #ifdef MARLIN_AIDA
4 
5 #include "marlin/AIDAProcessor.h"
6 
7 #include <iostream>
8 #include <assert.h>
9 #include <time.h>
10 
11 #include <AIDA/IAnalysisFactory.h>
12 #include <AIDA/ITreeFactory.h>
13 #include <AIDA/ITree.h>
14 #include <AIDA/IHistogramFactory.h>
15 #include <AIDA/ITupleFactory.h>
16 #include <AIDA/IDataPointSetFactory.h>
17 
18 #include <AIDA/ICloud1D.h>
19 
20 
21 namespace marlin {
22 
23  AIDAProcessor aAIDAProcessor ;
24 
25 
26  AIDAProcessor::AIDAProcessor() : Processor("AIDAProcessor"),
27  _analysisFactory(NULL),
28  _treeFactory(NULL),
29  _tree(NULL),
30  _histoFactory(NULL),
31  _tupleFactory(NULL),
32  _dataPointSetFactory(NULL),
33  _fileType(""),
34  _fileName(""),
35  _compress(1) {
36 
37  _description = "Processor that handles AIDA files. Creates on directory per processor. "
38  " Processors only need to create and fill the histograms, clouds and tuples. Needs to be the first ActiveProcessor" ;
39 
40  registerProcessorParameter( "FileType" ,
41  " type of output file root (default) or xml )" ,
42  _fileType ,
43  std::string("root") ) ;
44 
45  registerProcessorParameter( "FileName" ,
46  " filename without extension" ,
47  _fileName ,
48  std::string("aida_file") ) ;
49 
50  registerProcessorParameter( "Compress" ,
51  " compression of output file 0: false >0: true (default) " ,
52  _compress ,
53  1 ) ;
54 
55  }
56 
57  AIDAProcessor* AIDAProcessor::_me ;
58 
61  Processor* AIDAProcessor::newProcessor() {
62  if( ! _me )
63  _me = new AIDAProcessor ;
64  return _me ;
65  }
66 
67  void AIDAProcessor::init() {
68 
69 
70  printParameters() ;
71 
72  //--- steering parameters ---------
73 
74  bool compress = false ;
75  if( _compress != 0 )
76  compress = true ;
77 
78  //-------------------------------------------------
79 
80  _analysisFactory = AIDA_createAnalysisFactory() ;
81 
82  assert( _analysisFactory != 0 ) ;
83 
84  _treeFactory = _analysisFactory->createTreeFactory();
85 
86  assert( _treeFactory != 0 ) ;
87 
88 
89  std::string sexport("root") ; // root or Lab - only meaningful for _fileType==root
90 
91  std::string option("") ;
92 
93  option += compress ? "compress=yes" : "compress=no";
94 
95  if( _fileType == "root" ) {
96 
97  _fileName += ".root" ;
98  option += std::string(";export=") + sexport;
99 
100  } else if( _fileType == "xml" ) {
101 
102  _fileName += ".aida";
103  }
104 
105  _tree = _treeFactory->create( _fileName, _fileType, false, true , option );
106 
107  assert( _tree != 0 ) ;
108 
109 
110  _histoFactory = _analysisFactory->createHistogramFactory( *_tree ) ;
111 
112  assert( _histoFactory != 0 ) ;
113 
114  _tupleFactory = _analysisFactory->createTupleFactory( *_tree ) ;
115 
116  assert( _tupleFactory != 0 ) ;
117 
118  _dataPointSetFactory = _analysisFactory->createDataPointSetFactory( *_tree ) ;
119 
120  assert( _dataPointSetFactory != 0 ) ;
121 
122  }
123 
124 
125  void AIDAProcessor::processRunHeader( LCRunHeader* ) {
126  }
127 
128 
129  void AIDAProcessor::processEvent( LCEvent* ) {
130  // no processing
131  }
132 
133  void AIDAProcessor::check( LCEvent* ) {
134 
135  static AIDA::ICloud1D* hEvtTime ;
136  static clock_t eventTime = clock () ;
137 
138 
139  // create directory for this processor
140  if( isFirstEvent() ) {
141  _tree->cd( "/" ) ;
142  assert( _tree->mkdir( name() ) ) ;
143 
144  _tree->cd( "/" + name() ) ;
145 
146  hEvtTime = _histoFactory->createCloud1D( "hEvtProcessingTime", "event processing time [s] ", 100 ) ;
147 
148  _tree->cd("..") ;
149 
150 
151  } else {
152 
153  clock_t now = clock () ;
154 
155  hEvtTime->fill( double(now - eventTime) / double(CLOCKS_PER_SEC) ) ;
156  eventTime = now ;
157 
158  }
159  }
160 
161  void AIDAProcessor::end(){
162 
163 
164  _tree->commit() ;
165 
166  delete _treeFactory ;
167  delete _analysisFactory ;
168  delete _histoFactory ;
169  delete _tupleFactory ;
170  delete _dataPointSetFactory ;
171 
172  delete _tree;
173 
174  }
175  AIDA::IAnalysisFactory* AIDAProcessor::GetIAnalysisFactory( const Processor* proc )
176  {
177  tree( proc );
178  return _me->_analysisFactory;
179 
180  }
181 
182  AIDA::IHistogramFactory* AIDAProcessor::histogramFactory( const Processor* proc ){
183  tree( proc );
184 // if( !_me->_tree->cd( "/" + proc->name() ) ) {
185 // _me->_tree->cd("/") ;
186 // _me->_tree->mkdir( proc->name() ) ;
187 // _me->_tree->cd( "/" + proc->name() ) ;
188 // }
189  return _me->_histoFactory ;
190  }
191 
192  AIDA::ITupleFactory* AIDAProcessor::tupleFactory( const Processor* proc ) {
193  tree( proc );
194  return _me->_tupleFactory ;
195  }
196 
197  AIDA::IDataPointSetFactory* AIDAProcessor::dataPointSetFactory( const Processor* proc ) {
198  tree( proc );
199  return _me->_dataPointSetFactory ;
200  }
201 
202  AIDA::ITree* AIDAProcessor::tree( const Processor* proc ) {
203 
204  if( !_me ) {
205  throw Exception(" AIDA is not properly initialized - you need to have the AIDAProcessor as"
206  " first processor in your execute section !" ) ;
207  }
208 
209  if( !_me->_tree->cd( "/" + proc->name() ) ) {
210  _me->_tree->mkdir( "/" + proc->name() ) ;
211  _me->_tree->cd( "/" + proc->name() ) ;
212  }
213  return _me->_tree ;
214  }
215 
216 } // namespace
217 
218 #endif // MARLIN_AIDA
219 
T clock(T...args)
STL class.
std::string _fileName
Definition: XMLParser.h:208