test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConditionDBWriter.h
Go to the documentation of this file.
1 #ifndef CommonTools_ConditionDBWriter_ConditionDBWriter_h
2 #define CommonTools_ConditionDBWriter_ConditionDBWriter_h
3 // -*- C++ -*-
4 //
5 // Package: ConditionDBWriter
6 // Class: ConditionDBWriter
7 //
8 // \class ConditionDBWriter
9 //
10 // Description:
11 
122 //
123 
124 
125 //
126 // Original Author: Giacomo Bruno
127 // Created: May 23 10:04:31 CET 2007
128 //
129 //
130 
131 
132 // system include files
133 #include <memory>
134 #include <string>
135 #include <cstdlib>
136 
137 
138 // user include files
145 
148 
150 //#include "FWCore/Framework/interface/EventSetup.h"
151 
154 
155 
156 template< class T >
158 
159 public:
160 
162  {
163  edm::LogInfo("ConditionDBWriter::ConditionDBWriter()") << std::endl;
164  SinceAppendMode_=iConfig.getParameter<bool>("SinceAppendMode");
165  std::string IOVMode=iConfig.getParameter<std::string>("IOVMode");
166  if (IOVMode==std::string("Job")) JobMode_=true;
167  else if (IOVMode==std::string("Run")) RunMode_=true;
168  else if (IOVMode==std::string("LumiBlock")) LumiBlockMode_=true;
169  else if (IOVMode==std::string("AlgoDriven")) AlgoDrivenMode_=true;
170  else edm::LogError("ConditionDBWriter::ConditionDBWriter(): ERROR - unknown IOV interval write mode...will not store anything on the DB") << std::endl;
171  Record_=iConfig.getParameter<std::string>("Record");
172  doStore_=iConfig.getParameter<bool>("doStoreOnDB");
173  timeFromEndRun_=iConfig.getUntrackedParameter<bool>("TimeFromEndRun", false);
174 
175  if(! SinceAppendMode_ )
176  edm::LogError("ConditionDBWriter::endJob(): ERROR - only SinceAppendMode support!!!!");
177  }
178 
180  {
181  edm::LogInfo("ConditionDBWriter::~ConditionDBWriter()") << std::endl;
182  }
183 
184 private:
185 
186  // method to be implemented by derived class. Must return a pointer to the DB object to be stored, which must have been created with "new". The derived class looses control on it (must not "delete" it at any time in its code!)
187 
188  virtual T * getNewObject()=0;
189 
190 
191  // Optional methods that may be implemented (technically "overridden") in the derived classes if needed
192 
193  //Will be called at the beginning of the job
194  virtual void algoBeginJob(const edm::EventSetup&){};
195  //Will be called at the beginning of each run in the job
196  virtual void algoBeginRun(const edm::Run &, const edm::EventSetup &){};
197  //Will be called at the beginning of each luminosity block in the run
199  //Will be called at every event
200  virtual void algoAnalyze(const edm::Event&, const edm::EventSetup&){};
201  //Will be called at the end of each run in the job
202  virtual void algoEndRun(const edm::Run &, const edm::EventSetup &){};
203  //Will be called at the end of the job
204  virtual void algoEndJob(){};
205 
206  void beginJob() {}
207 
208  void beginRun(const edm::Run & run, const edm::EventSetup & es)
209  {
210  if( firstRun_ ) {
211  edm::LogInfo("ConditionDBWriter::beginJob") << std::endl;
213  algoBeginJob(es);
214  firstRun_ = false;
215  }
216  edm::LogInfo("ConditionDBWriter::beginRun") << std::endl;
218  algoBeginRun(run,es);
219  }
220 
221  void beginLuminosityBlock(const edm::LuminosityBlock & lumiBlock, const edm::EventSetup & iSetup)
222  {
223  edm::LogInfo("ConditionDBWriter::beginLuminosityBlock") << std::endl;
225  algoBeginLuminosityBlock(lumiBlock, iSetup);
226  }
227 
228  void analyze(const edm::Event& event, const edm::EventSetup& iSetup)
229  {
230  if(setSinceTime_ ){
231  setTime(); //set new since time for possible next upload to DB
232  setSinceTime_=false;
233  }
234  algoAnalyze(event, iSetup);
235  }
236 
237  void endLuminosityBlock(const edm::LuminosityBlock & lumiBlock, const edm::EventSetup & es)
238  {
239  edm::LogInfo("ConditionDBWriter::endLuminosityBlock") << std::endl;
240  algoEndLuminosityBlock(lumiBlock, es);
241 
242  if(LumiBlockMode_){
243 
244  T * objPointer = getNewObject();
245 
246  if(objPointer ){
247  storeOnDb(objPointer);
248  }
249  else {
250  edm::LogError("ConditionDBWriter::endLuminosityblock(): ERROR - requested to store on DB on a Lumi Block based interval, but received null pointer...will not store anything on the DB") << std::endl;
251  }
252  }
253  }
254 
256 
257  void endRun(const edm::Run & run, const edm::EventSetup & es)
258  {
259  edm::LogInfo("ConditionDBWriter::endRun") << std::endl;
260 
261  algoEndRun(run, es);
262 
263  if(RunMode_){
264 
265  T * objPointer = getNewObject();
266 
267  if(objPointer ){
268  if( timeFromEndRun_ ) Time_ = run.id().run();
269  storeOnDb(objPointer);
270  }
271  else {
272  edm::LogError("ConditionDBWriter::endRun(): ERROR - requested to store on DB on a Run based interval, but received null pointer...will not store anything on the DB") << std::endl;
273  }
274  }
275  }
276 
277  void endJob()
278  {
279  edm::LogInfo("ConditionDBWriter::endJob") << std::endl;
280 
281  algoEndJob();
282 
283  if(JobMode_){
284 
285  T * objPointer = getNewObject();
286 
287  if( objPointer ){
288  storeOnDb(objPointer);
289  }
290 
291  else {
292 
293  edm::LogError("ConditionDBWriter::endJob(): ERROR - requested to store on DB on a Job based interval, but received null pointer...will not store anything on the DB") << std::endl;
294  }
295  }
296  }
297 
298  void storeOnDb(T * objPointer)
299  {
300  edm::LogInfo("ConditionDBWriter::storeOnDb ") << std::endl;
301 
302  setSinceTime_=true;
303 
304  if(! objPointer) {
305  edm::LogError("ConditionDBWriter: Pointer to object has not been set...storing no data on DB") ;
306  return;
307  }
308 
309  //And now write data in DB
310  if( !doStore_ ) return;
312  if (! mydbservice.isAvailable() ) {
313  edm::LogError("ConditionDBWriter")<<"PoolDBOutputService is unavailable"<<std::endl;
314  return;
315  }
316 
317  cond::Time_t since =
318  ( mydbservice->isNewTagRequest(Record_) && !timeFromEndRun_ ) ? mydbservice->beginOfTime() : Time_;
319 
320  edm::LogInfo("ConditionDBWriter") << "appending a new object to tag "
321  <<Record_ <<" in since mode " << std::endl;
322  mydbservice->writeOne<T>(objPointer, since, Record_);
323  }
324 
325  void setTime()
326  {
328 
329  if( mydbservice.isAvailable() ){
330  Time_ = mydbservice->currentTime();
331  edm::LogInfo("ConditionDBWriter::setTime: time set to ") << Time_ << std::endl;
332  }
333  else{
334  edm::LogError("ConditionDBWriter::setTime(): PoolDBOutputService is not available...cannot set current time") << std::endl;
335  }
336  }
337 
338 protected:
339 
340  // This method should be called by the derived class only if it support the algodriven mode; this method will trigger a call of the getNewObject method, but only if algoDrivenMode is chosen
341 
343  {
344  T * objPointer = 0;
345 
346  if(AlgoDrivenMode_){
347 
348  setSinceTime_=true;
349 
350  objPointer = getNewObject();
351 
352  if (!objPointer ) {
353  edm::LogError("ConditionDBWriter::storeOnDbNow: ERROR - requested to store on DB a new object (module configuration is algo driven based IOV), but received NULL pointer...will not store anything on the DB") << std::endl;
354  return;
355  }
356  else {storeOnDb(objPointer);}
357 
358  }
359  else {
360 
361  edm::LogError("ConditionDBWriter::storeOnDbNow(): ERROR - received a direct request from concrete algorithm to store on DB a new object, but module configuration is not to store on DB on an algo driven based interval...will not store anything on the DB") << std::endl;
362  return;
363  }
364  }
365 
366  // utility method: it returns the lastly set IOV time (till or since according to what was chosen in the configuration)
367 
369 
371  void setDoStore(const bool doStore) {doStore_ = doStore;}
372 
373 private:
374 
375  bool SinceAppendMode_; // till or since append mode
376 
377  bool LumiBlockMode_; //LumiBlock since/till time
378  bool RunMode_; //
379  bool JobMode_;
381  bool doStore_;
382 
384  cond::Time_t Time_; //time until which the DB object is valid. It is taken from the time of the first event analyzed. The end of the validity is infinity. However as soon as a new DB object with a later start time is inserted, the end time of this one becomes the start time of the new one.
385 
387 
388  bool firstRun_;
389 
391 };
392 
393 #endif
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
RunID const & id() const
Definition: RunBase.h:39
RunNumber_t run() const
Definition: RunID.h:39
void storeOnDb(T *objPointer)
virtual T * getNewObject()=0
virtual void algoBeginJob(const edm::EventSetup &)
virtual void algoBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
void endLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &es)
cond::Time_t timeOfLastIOV()
unsigned long long Time_t
Definition: Time.h:16
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:46
void beginLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup)
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
virtual void algoEndJob()
virtual void algoBeginRun(const edm::Run &, const edm::EventSetup &)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void beginRun(const edm::Run &run, const edm::EventSetup &es)
void analyze(const edm::Event &event, const edm::EventSetup &iSetup)
ConditionDBWriter(const edm::ParameterSet &iConfig)
void setDoStore(const bool doStore)
When set to false the payload will not be written to the db.
virtual void algoEndRun(const edm::Run &, const edm::EventSetup &)
void endRun(const edm::Run &run, const edm::EventSetup &es)
volatile std::atomic< bool > shutdown_flag false
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &)
long double T
virtual void algoEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
Definition: Run.h:43
virtual ~ConditionDBWriter()