Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConditionsProcessor.cc
Go to the documentation of this file.
1 #include "marlin/MarlinConfig.h" // defines MARLIN_LCCD
2 
3 #ifdef MARLIN_LCCD
4 
6 #include "lccd/IConditionsChangeListener.hh"
7 
8 //--- LCIO headers
9 //#include <UTIL/LCTOOLS.h> // debug
10 //#include <IMPL/LCEventImpl.h> // debug
11 
12 //--- LCCD headers
13 #include "lccd.h"
14 #include "lccd/SimpleFileHandler.hh"
15 #include "lccd/DBCondHandler.hh"
16 #include "lccd/DBFileHandler.hh"
17 #include "lccd/DataFileHandler.hh"
18 
19 #include "lccd/LCConditionsMgr.hh"
20 
21 //#include <iostream>
22 
23 using namespace lcio ;
24 
25 
26 namespace marlin{
27 
28 
29  ConditionsProcessor aConditionsProcessor ;
30 
31 
32  bool ConditionsProcessor::registerChangeListener( lccd::IConditionsChangeListener* cl, const std::string& name) {
33 
34  try{
35  lccd::LCConditionsMgr::instance()->registerChangeListener( cl , name ) ;
36  return true ;
37  }
38  catch(Exception){}
39 
40  return false ;
41  }
42 
43 
44  ConditionsProcessor::ConditionsProcessor() : Processor("ConditionsProcessor") {
45 
46  // modify processor description
47  _description = "ConditionsProcessor provides access to conditions data "
48  " transparently from LCIO files or a databases, using LCCD" ;
49 
50 
51  // register steering parameters: name, description, class-variable, default value
52 
53  registerProcessorParameter( "DBInit" ,
54  "Initialization string for conditions database" ,
55  _dbInit ,
56  std::string("localhost:lccd_test:calvin:hobbes")) ;
57 
58 
59  StringVec dbcondExample ;
60  dbcondExample.push_back("conditionsName");
61  dbcondExample.push_back("/lccd/myfolder");
62  dbcondExample.push_back("HEAD");
63 
64 
65  registerOptionalParameter( "DBCondHandler" ,
66  "Initialization of a conditions database handler" ,
67  _dbcondHandlerInit ,
68  dbcondExample ,
69  dbcondExample.size() ) ;
70 
71 
72  StringVec simpleExample ;
73  simpleExample.push_back("conditionsName");
74  simpleExample.push_back("conditions.slcio");
75  simpleExample.push_back("collectionName");
76 
77  registerOptionalParameter( "SimpleFileHandler" ,
78  "Initialization of a simple conditions file handler" ,
79  _simpleHandlerInit ,
80  simpleExample ,
81  simpleExample.size() ) ;
82 
83  StringVec dbfileExample ;
84  dbfileExample.push_back("conditionsName");
85  dbfileExample.push_back("conditions.slcio");
86  dbfileExample.push_back("collectionName");
87 
88 
89  registerOptionalParameter( "DBFileHandler" ,
90  "Initialization of a conditions db file handler" ,
91  _dbfileHandlerInit ,
92  dbfileExample ,
93  dbfileExample.size() ) ;
94 
95 
96  StringVec datafileExample ;
97  datafileExample.push_back("conditionsName");
98 
99  registerOptionalParameter( "DataFileHandler" ,
100  "Initialization of a data file handler" ,
101  _datafileHandlerInit ,
102  datafileExample ,
103  datafileExample.size() ) ;
104 
105  _nRun = -1;
106  _nEvt = -1;
107 
108  }
109 
110 
111  void ConditionsProcessor::init() {
112 
113  // usually a good idea to
114  printParameters() ;
115 
116  _nRun = 0 ;
117  _nEvt = 0 ;
118 
119  // initialize the requested conditions handler
120 
121  if( parameterSet( "SimpleFileHandler" ) ) {
122 
123  unsigned index = 0 ;
124  while( index < _simpleHandlerInit.size() ){
125 
126  std::string condName( _simpleHandlerInit[ index++ ] ) ;
127  std::string fileName( _simpleHandlerInit[ index++ ] ) ;
128  std::string colName ( _simpleHandlerInit[ index++ ] ) ;
129 
130  lccd::LCConditionsMgr::instance()->
131  registerHandler( condName , new lccd::SimpleFileHandler( fileName, condName, colName ) ) ;
132 
133  _condHandlerNames.push_back( condName ) ;
134  }
135  }
136 
137 
138  if( parameterSet( "DBCondHandler" ) ) {
139 
140  unsigned index = 0 ;
141  while( index < _dbcondHandlerInit.size() ){
142 
143  std::string condName( _dbcondHandlerInit[ index++ ] ) ;
144  std::string folder ( _dbcondHandlerInit[ index++ ] ) ;
145  std::string tag ( _dbcondHandlerInit[ index++ ] ) ;
146 
147  // HEAD corresponds to no tag in database
148  if( tag == "HEAD" ) tag = "" ;
149 
150  lccd::LCConditionsMgr::instance()->
151  registerHandler( condName, new lccd::DBCondHandler( _dbInit , folder , condName, tag ) ) ;
152 
153  _condHandlerNames.push_back( condName ) ;
154  }
155  }
156 
157 
158  if( parameterSet( "DBFileHandler" ) ) {
159 
160  unsigned index = 0 ;
161  while( index < _dbfileHandlerInit.size() ){
162 
163  std::string condName( _dbfileHandlerInit[ index++ ] ) ;
164  std::string fileName( _dbfileHandlerInit[ index++ ] ) ;
165  std::string colName ( _dbfileHandlerInit[ index++ ] ) ;
166 
167  lccd::LCConditionsMgr::instance()->
168  registerHandler( condName , new lccd::DBFileHandler( fileName, condName, colName ) ) ;
169 
170  _condHandlerNames.push_back( condName ) ;
171  }
172  }
173 
174 
175  if( parameterSet( "DataFileHandler" ) ) {
176 
177  unsigned index = 0 ;
178  while( index < _datafileHandlerInit.size() ){
179 
180  std::string condName ( _datafileHandlerInit[ index++ ] ) ;
181 
182  lccd::LCConditionsMgr::instance()->
183  registerHandler( condName , new lccd::DataFileHandler( condName ) ) ;
184 
185  _condHandlerNames.push_back( condName ) ;
186  }
187  }
188 
189  }
190 
191 
192 // void ConditionsProcessor::processRunHeader( LCRunHeader* run) {
193 // _nRun++ ;
194 // }
195 
196  void ConditionsProcessor::processEvent( LCEvent * evt ) {
197 
198  static int lastEvent = -1 ;
199  static int lastRun = -1 ;
200 
201  // update all condition handlers - if not yet done by previous conditions processor
202 
203  if( evt->getEventNumber() != lastEvent || evt->getRunNumber() != lastRun ){
204 
205  lccd::LCConditionsMgr::instance()->updateEvent( evt ) ;
206 
207  lastEvent = evt->getEventNumber() ;
208  lastRun = evt->getRunNumber() ;
209  }
210  }
211 
212  // void ConditionsProcessor::check( LCEvent * evt ) {
213  // // nothing to check here - could be used to fill checkplots in reconstruction processor
214  // }
215 
216 
217  void ConditionsProcessor::end(){
218 
219  // delete all handlers
220  for(unsigned int i=0; i< _condHandlerNames.size() ; ++i){
221 
222  lccd::LCConditionsMgr::instance()->removeHandler( _condHandlerNames[i] );
223  }
224  }
225 
226 }
227 
228 #endif // #ifdef MARLIN_LCCD
STL class.
T push_back(T...args)
T size(T...args)