CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
ConditionDBWriter< T > Class Template Referenceabstract

#include <ConditionDBWriter.h>

Inheritance diagram for ConditionDBWriter< T >:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 ConditionDBWriter (const edm::ParameterSet &iConfig)
 
virtual ~ConditionDBWriter ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Protected Member Functions

void setDoStore (const bool doStore)
 When set to false the payload will not be written to the db. More...
 
void storeOnDbNow ()
 
cond::Time_t timeOfLastIOV ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Private Member Functions

virtual void algoAnalyze (const edm::Event &, const edm::EventSetup &)
 
virtual void algoBeginJob (const edm::EventSetup &)
 
virtual void algoBeginLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &)
 
virtual void algoBeginRun (const edm::Run &, const edm::EventSetup &)
 
virtual void algoEndJob ()
 
virtual void algoEndLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &)
 
virtual void algoEndRun (const edm::Run &, const edm::EventSetup &)
 
void analyze (const edm::Event &event, const edm::EventSetup &iSetup)
 
void beginJob ()
 
void beginLuminosityBlock (const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup)
 
void beginRun (const edm::Run &run, const edm::EventSetup &es)
 
void endJob ()
 
void endLuminosityBlock (const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &es)
 
void endRun (const edm::Run &run, const edm::EventSetup &es)
 
virtual TgetNewObject ()=0
 
void setTime ()
 
void storeOnDb (T *objPointer)
 

Private Attributes

bool AlgoDrivenMode_
 
bool doStore_
 
bool firstRun_
 
bool JobMode_
 
bool LumiBlockMode_
 
unsigned int maxRunRange_
 
unsigned int minRunRange_
 
std::string Record_
 
bool RunMode_
 
bool setSinceTime_
 
bool SinceAppendMode_
 
cond::Time_t Time_
 
bool timeFromEndRun_
 
bool timeFromStartOfRunRange_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 

Detailed Description

template<class T>
class ConditionDBWriter< T >

Implementation:

This class can be very useful whenever a CMSSW application needs to store data to the offline DB. Typically such applications require access to event data and/or need to be notified about the start of Run, Lumi section in order to set a correct Interval Of Validity (IOV) for the data they have to store. Therefore the FWK EDAnalyzer is an excellent candidate for the implementation of such applications; this is the reason why this class inherits from the EDAnalyzer class.

The user class should inherit from this class. The templated type must be the type of the object that has to be written on the DB (e.g. MyCalibration). Examples of use of this class can be found in package CalibTracker/SiStripChannelGain. Have a look also at the test/ directory for examples of full cfg files.

The user must implement in his derived class the abstract method below

virtual MyCalibration * getNewObject()=0;

in this method, the user must create a new instance of the DB object and return a pointer to it. The object must be created with "new" and never be deleted by the user: it will be the FWK that takes control over it.

The user can optionally implement the following methods

//Will be called at the beginning of the job virtual void algoBeginJob(const edm::EventSetup&){}; //Will be called at the beginning of each run in the job virtual void algoBeginRun(const edm::Run &, const edm::EventSetup &){}; //Will be called at the beginning of each luminosity block in the run virtual void algoBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &){}; //Will be called at every event virtual void algoAnalyze(const edm::Event&, const edm::EventSetup&){}; //Will be called at the end of each run in the job virtual void algoEndRun(const edm::Run &, const edm::EventSetup &){}; //Will be called at the end of the job virtual void algoEndJob(){};

where he can access information needed to build his object. For instance, if he is computing a calibration that is computed as the mean of a certain quantity that varies from event to event, he will implement the algoAnalyze method.

The important part is the IOV setting. The advantage of using this class is that this setting is performed almost automatically: the only thing that the user has to do is to pass prescriptions about the IOV setting in the configuration of his module. A typical configuration is as follows:

   module prod =  SiStripGainRandomCalculator {

   #parameters of the derived class
    double MinPositiveGain = 0.1
    double MeanGain    = 1
    double SigmaGain   = 0
             untracked bool   printDebug = true

   #parameters of the base class
    string IOVMode       = "Run"
    bool SinceAppendMode = true
    string Record        = "SiStripApvGainRcd"

            }

Two subsets of parameters can be found. The first subset contains the specific parameters of the user class, which is called in this case SiStripGainRandomCalculator. The second subset contains the parameters of the base class. These are the following:

1) string IOVMode

4 possible values can be given: "Job", "Run", "LumiBlock" and "AlgoDriven" This card determines the length of the IOV. In other words, together with the number of Lumysections/runs the user has decided to run his application, this card determines the number of objects that will be stored on the DB (the getNewObject method will be called as many times). For example if the user is running on the events of one Run, which has 10 luminosity sections and chooses the "LumiBlock" mode, then 10 objects with corresponding IOV will be written. If the "Job" mode is chosen, only one object will be stored irrespective of the dataset on which the user is running. The "AlgoDriven" option is special. If this choice is made, then it is up to the user to tell in the code when the getNewObject method must be called. This can be done by calling the method below void storeOnDbNow() must be invoked whenever a certain condition that justifies the start/end of an IOV is met.

2) bool SinceAppendMode

obsolete option now ONLY Since append mode is supported

 WARNING: due to the policy of the framework, objects SHALL be stored
 in IOV chronological order. If you have 10 runs, then execute your application starting from run 1 and not for example in two steps: first from Run 6 to Run 10 and then from Run 1 to Run 6.

3)string Record

this is the eventsetup record of your object.

Note that the setDoStore method changes the doStore parameter read from configuration file. This is sometimes needed e.g. to avoid filling bad payloads to the database.

Definition at line 157 of file ConditionDBWriter.h.

Constructor & Destructor Documentation

template<class T>
ConditionDBWriter< T >::ConditionDBWriter ( const edm::ParameterSet iConfig)
inlineexplicit

Definition at line 161 of file ConditionDBWriter.h.

161  : minRunRange_(1<<31), maxRunRange_(0), LumiBlockMode_(false), RunMode_(false), JobMode_(false), AlgoDrivenMode_(false), Time_(0), setSinceTime_(false), firstRun_(true)
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  timeFromStartOfRunRange_=iConfig.getUntrackedParameter<bool>("TimeFromStartOfRunRange", false);
175 
176  if(! SinceAppendMode_ )
177  edm::LogError("ConditionDBWriter::endJob(): ERROR - only SinceAppendMode support!!!!");
178  }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
unsigned int maxRunRange_
unsigned int minRunRange_
template<class T>
virtual ConditionDBWriter< T >::~ConditionDBWriter ( )
inlinevirtual

Definition at line 180 of file ConditionDBWriter.h.

181  {
182  edm::LogInfo("ConditionDBWriter::~ConditionDBWriter()") << std::endl;
183  }

Member Function Documentation

template<class T>
virtual void ConditionDBWriter< T >::algoAnalyze ( const edm::Event ,
const edm::EventSetup  
)
inlineprivatevirtual
template<class T>
virtual void ConditionDBWriter< T >::algoBeginJob ( const edm::EventSetup )
inlineprivatevirtual
template<class T>
virtual void ConditionDBWriter< T >::algoBeginLuminosityBlock ( const edm::LuminosityBlock ,
const edm::EventSetup  
)
inlineprivatevirtual
template<class T>
virtual void ConditionDBWriter< T >::algoBeginRun ( const edm::Run ,
const edm::EventSetup  
)
inlineprivatevirtual
template<class T>
virtual void ConditionDBWriter< T >::algoEndJob ( )
inlineprivatevirtual
template<class T>
virtual void ConditionDBWriter< T >::algoEndLuminosityBlock ( const edm::LuminosityBlock ,
const edm::EventSetup  
)
inlineprivatevirtual

Definition at line 260 of file ConditionDBWriter.h.

Referenced by ConditionDBWriter< SiStripApvGain >::endLuminosityBlock().

260 {};
template<class T>
virtual void ConditionDBWriter< T >::algoEndRun ( const edm::Run ,
const edm::EventSetup  
)
inlineprivatevirtual

Reimplemented in SiStripGainFromCalibTree.

Definition at line 203 of file ConditionDBWriter.h.

Referenced by ConditionDBWriter< SiStripApvGain >::endRun().

203 {};
template<class T>
void ConditionDBWriter< T >::analyze ( const edm::Event event,
const edm::EventSetup iSetup 
)
inlineprivate

Definition at line 233 of file ConditionDBWriter.h.

234  {
235  if(setSinceTime_ ){
236  setTime(); //set new since time for possible next upload to DB
237  setSinceTime_=false;
238  }
239  algoAnalyze(event, iSetup);
240  }
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &)
template<class T>
void ConditionDBWriter< T >::beginJob ( void  )
inlineprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 207 of file ConditionDBWriter.h.

207 {}
template<class T>
void ConditionDBWriter< T >::beginLuminosityBlock ( const edm::LuminosityBlock lumiBlock,
const edm::EventSetup iSetup 
)
inlineprivate

Definition at line 226 of file ConditionDBWriter.h.

227  {
228  edm::LogInfo("ConditionDBWriter::beginLuminosityBlock") << std::endl;
230  algoBeginLuminosityBlock(lumiBlock, iSetup);
231  }
virtual void algoBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
template<class T>
void ConditionDBWriter< T >::beginRun ( const edm::Run run,
const edm::EventSetup es 
)
inlineprivate

Definition at line 209 of file ConditionDBWriter.h.

210  {
211  if( firstRun_ ) {
212  edm::LogInfo("ConditionDBWriter::beginJob") << std::endl;
214  algoBeginJob(es);
215  firstRun_ = false;
216  }
217 
218  if( run.id().run() < minRunRange_ ) minRunRange_=run.id().run();
219  if( run.id().run() > maxRunRange_ ) maxRunRange_=run.id().run();
220 
221  edm::LogInfo("ConditionDBWriter::beginRun") << std::endl;
223  algoBeginRun(run,es);
224  }
RunID const & id() const
Definition: RunBase.h:39
RunNumber_t run() const
Definition: RunID.h:39
virtual void algoBeginJob(const edm::EventSetup &)
unsigned int maxRunRange_
virtual void algoBeginRun(const edm::Run &, const edm::EventSetup &)
unsigned int minRunRange_
template<class T>
void ConditionDBWriter< T >::endJob ( void  )
inlineprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 282 of file ConditionDBWriter.h.

Referenced by o2olib.O2ORunMgr::executeJob().

283  {
284  edm::LogInfo("ConditionDBWriter::endJob") << std::endl;
285 
286  algoEndJob();
287 
288  if(JobMode_){
289 
290  T * objPointer = getNewObject();
291 
292  if( objPointer ){
293  storeOnDb(objPointer);
294  }
295 
296  else {
297 
298  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;
299  }
300  }
301  }
void storeOnDb(T *objPointer)
virtual T * getNewObject()=0
virtual void algoEndJob()
long double T
template<class T>
void ConditionDBWriter< T >::endLuminosityBlock ( const edm::LuminosityBlock lumiBlock,
const edm::EventSetup es 
)
inlineprivate

Definition at line 242 of file ConditionDBWriter.h.

243  {
244  edm::LogInfo("ConditionDBWriter::endLuminosityBlock") << std::endl;
245  algoEndLuminosityBlock(lumiBlock, es);
246 
247  if(LumiBlockMode_){
248 
249  T * objPointer = getNewObject();
250 
251  if(objPointer ){
252  storeOnDb(objPointer);
253  }
254  else {
255  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;
256  }
257  }
258  }
void storeOnDb(T *objPointer)
virtual T * getNewObject()=0
long double T
virtual void algoEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
template<class T>
void ConditionDBWriter< T >::endRun ( const edm::Run run,
const edm::EventSetup es 
)
inlineprivate

Definition at line 262 of file ConditionDBWriter.h.

263  {
264  edm::LogInfo("ConditionDBWriter::endRun") << std::endl;
265 
266  algoEndRun(run, es);
267 
268  if(RunMode_){
269 
270  T * objPointer = getNewObject();
271 
272  if(objPointer ){
273  if( timeFromEndRun_ ) Time_ = run.id().run();
274  storeOnDb(objPointer);
275  }
276  else {
277  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;
278  }
279  }
280  }
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 algoEndRun(const edm::Run &, const edm::EventSetup &)
long double T
template<class T>
virtual T* ConditionDBWriter< T >::getNewObject ( )
privatepure virtual
template<class T>
void ConditionDBWriter< T >::setDoStore ( const bool  doStore)
inlineprotected

When set to false the payload will not be written to the db.

Definition at line 379 of file ConditionDBWriter.h.

379 {doStore_ = doStore;}
template<class T>
void ConditionDBWriter< T >::setTime ( )
inlineprivate

Definition at line 333 of file ConditionDBWriter.h.

Referenced by ConditionDBWriter< SiStripApvGain >::analyze().

334  {
336 
337  if( mydbservice.isAvailable() ){
338  Time_ = mydbservice->currentTime();
339  edm::LogInfo("ConditionDBWriter::setTime: time set to ") << Time_ << std::endl;
340  }
341  else{
342  edm::LogError("ConditionDBWriter::setTime(): PoolDBOutputService is not available...cannot set current time") << std::endl;
343  }
344  }
bool isAvailable() const
Definition: Service.h:46
template<class T>
void ConditionDBWriter< T >::storeOnDb ( T objPointer)
inlineprivate

Definition at line 303 of file ConditionDBWriter.h.

Referenced by ConditionDBWriter< SiStripApvGain >::endJob(), ConditionDBWriter< SiStripApvGain >::endLuminosityBlock(), ConditionDBWriter< SiStripApvGain >::endRun(), and ConditionDBWriter< SiStripApvGain >::storeOnDbNow().

304  {
305  edm::LogInfo("ConditionDBWriter::storeOnDb ") << std::endl;
306 
307  setSinceTime_=true;
308 
309  if(! objPointer) {
310  edm::LogError("ConditionDBWriter: Pointer to object has not been set...storing no data on DB") ;
311  return;
312  }
313 
314  //And now write data in DB
315  if( !doStore_ ) return;
317  if (! mydbservice.isAvailable() ) {
318  edm::LogError("ConditionDBWriter")<<"PoolDBOutputService is unavailable"<<std::endl;
319  return;
320  }
321 
323  ( mydbservice->isNewTagRequest(Record_) && !timeFromEndRun_ ) ? mydbservice->beginOfTime() : Time_;
324 
325  //overwrite tim in the case we have the flag TimeFromStartOfRunRange set to on
326  if (timeFromStartOfRunRange_ ) since = minRunRange_;
327 
328  edm::LogInfo("ConditionDBWriter") << "appending a new object to tag "
329  <<Record_ <<" in since mode " << std::endl;
330  mydbservice->writeOne<T>(objPointer, since, Record_);
331  }
unsigned long long Time_t
Definition: Time.h:16
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
long double T
unsigned int minRunRange_
template<class T>
void ConditionDBWriter< T >::storeOnDbNow ( )
inlineprotected

Definition at line 350 of file ConditionDBWriter.h.

351  {
352  T * objPointer = 0;
353 
354  if(AlgoDrivenMode_){
355 
356  setSinceTime_=true;
357 
358  objPointer = getNewObject();
359 
360  if (!objPointer ) {
361  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;
362  return;
363  }
364  else {storeOnDb(objPointer);}
365 
366  }
367  else {
368 
369  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;
370  return;
371  }
372  }
void storeOnDb(T *objPointer)
virtual T * getNewObject()=0
long double T
template<class T>
cond::Time_t ConditionDBWriter< T >::timeOfLastIOV ( )
inlineprotected

Definition at line 376 of file ConditionDBWriter.h.

376 {return Time_;}

Member Data Documentation

template<class T>
bool ConditionDBWriter< T >::AlgoDrivenMode_
private
template<class T>
bool ConditionDBWriter< T >::doStore_
private
template<class T>
bool ConditionDBWriter< T >::firstRun_
private

Definition at line 399 of file ConditionDBWriter.h.

Referenced by ConditionDBWriter< SiStripApvGain >::beginRun().

template<class T>
bool ConditionDBWriter< T >::JobMode_
private
template<class T>
bool ConditionDBWriter< T >::LumiBlockMode_
private
template<class T>
unsigned int ConditionDBWriter< T >::maxRunRange_
private

Definition at line 384 of file ConditionDBWriter.h.

Referenced by ConditionDBWriter< SiStripApvGain >::beginRun().

template<class T>
unsigned int ConditionDBWriter< T >::minRunRange_
private
template<class T>
std::string ConditionDBWriter< T >::Record_
private
template<class T>
bool ConditionDBWriter< T >::RunMode_
private
template<class T>
bool ConditionDBWriter< T >::setSinceTime_
private
template<class T>
bool ConditionDBWriter< T >::SinceAppendMode_
private
template<class T>
cond::Time_t ConditionDBWriter< T >::Time_
private
template<class T>
bool ConditionDBWriter< T >::timeFromEndRun_
private
template<class T>
bool ConditionDBWriter< T >::timeFromStartOfRunRange_
private