CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

ConditionDBWriter< T > Class Template Reference

#include <ConditionDBWriter.h>

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

List of all members.

Public Member Functions

 ConditionDBWriter (const edm::ParameterSet &iConfig)
virtual ~ConditionDBWriter ()

Protected Member Functions

void setDoStore (const bool doStore)
 When set to false the payload will not be written to the db.
void storeOnDbNow ()
cond::Time_t timeOfLastIOV ()

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_
std::string Record_
bool RunMode_
bool setSinceTime_
bool SinceAppendMode_
cond::Time_t Time_
bool timeFromEndRun_

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 158 of file ConditionDBWriter.h.


Constructor & Destructor Documentation

template<class T>
ConditionDBWriter< T >::ConditionDBWriter ( const edm::ParameterSet iConfig) [inline, explicit]

Definition at line 162 of file ConditionDBWriter.h.

                                                             : LumiBlockMode_(false), RunMode_(false), JobMode_(false), AlgoDrivenMode_(false), Time_(0), setSinceTime_(false), firstRun_(true)
  {
    edm::LogInfo("ConditionDBWriter::ConditionDBWriter()") << std::endl;
    SinceAppendMode_=iConfig.getParameter<bool>("SinceAppendMode");
    std::string IOVMode=iConfig.getParameter<std::string>("IOVMode");
    if (IOVMode==std::string("Job")) JobMode_=true;
    else if (IOVMode==std::string("Run")) RunMode_=true;
    else if (IOVMode==std::string("LumiBlock")) LumiBlockMode_=true;
    else if (IOVMode==std::string("AlgoDriven")) AlgoDrivenMode_=true;
    else  edm::LogError("ConditionDBWriter::ConditionDBWriter(): ERROR - unknown IOV interval write mode...will not store anything on the DB") << std::endl;
    Record_=iConfig.getParameter<std::string>("Record");
    doStore_=iConfig.getParameter<bool>("doStoreOnDB");
    timeFromEndRun_=iConfig.getUntrackedParameter<bool>("TimeFromEndRun", false);
    
    if(! SinceAppendMode_ ) 
      edm::LogError("ConditionDBWriter::endJob(): ERROR - only SinceAppendMode support!!!!");
  }
template<class T>
virtual ConditionDBWriter< T >::~ConditionDBWriter ( ) [inline, virtual]

Definition at line 180 of file ConditionDBWriter.h.

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

Member Function Documentation

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

Definition at line 203 of file ConditionDBWriter.h.

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

{};
template<class T>
void ConditionDBWriter< T >::analyze ( const edm::Event event,
const edm::EventSetup iSetup 
) [inline, private, virtual]

Implements edm::EDAnalyzer.

Definition at line 229 of file ConditionDBWriter.h.

  {
    if(setSinceTime_ ){
      setTime(); //set new since time for possible next upload to DB  
      setSinceTime_=false;
    }
    algoAnalyze(event, iSetup);
  }
template<class T>
void ConditionDBWriter< T >::beginJob ( void  ) [inline, private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 207 of file ConditionDBWriter.h.

{}
template<class T>
void ConditionDBWriter< T >::beginLuminosityBlock ( const edm::LuminosityBlock lumiBlock,
const edm::EventSetup iSetup 
) [inline, private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 222 of file ConditionDBWriter.h.

  {
    edm::LogInfo("ConditionDBWriter::beginLuminosityBlock") << std::endl;
    if(LumiBlockMode_ && SinceAppendMode_) setSinceTime_=true;
    algoBeginLuminosityBlock(lumiBlock, iSetup);
  }
template<class T>
void ConditionDBWriter< T >::beginRun ( const edm::Run run,
const edm::EventSetup es 
) [inline, private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 209 of file ConditionDBWriter.h.

  {
    if( firstRun_ ) {
      edm::LogInfo("ConditionDBWriter::beginJob") << std::endl;
      if( (JobMode_ || AlgoDrivenMode_) && SinceAppendMode_) setSinceTime_=true;
      algoBeginJob(es);
      firstRun_ = false;
    }
    edm::LogInfo("ConditionDBWriter::beginRun") << std::endl;
    if(RunMode_ && SinceAppendMode_) setSinceTime_=true;
    algoBeginRun(run,es);
  }
template<class T>
void ConditionDBWriter< T >::endJob ( void  ) [inline, private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 278 of file ConditionDBWriter.h.

  {
    edm::LogInfo("ConditionDBWriter::endJob") << std::endl;
    
    algoEndJob();
    
    if(JobMode_){
      
      T * objPointer = getNewObject();
      
      if( objPointer ){
        storeOnDb(objPointer);
      }
      
      else {
        
        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;
      }
    }
  }
template<class T>
void ConditionDBWriter< T >::endLuminosityBlock ( const edm::LuminosityBlock lumiBlock,
const edm::EventSetup es 
) [inline, private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 238 of file ConditionDBWriter.h.

  {
    edm::LogInfo("ConditionDBWriter::endLuminosityBlock") << std::endl;
    algoEndLuminosityBlock(lumiBlock, es);
    
    if(LumiBlockMode_){
      
      T * objPointer = getNewObject();
      
      if(objPointer ){
        storeOnDb(objPointer);
      }
      else {
        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;
      }
    }
  }
template<class T>
void ConditionDBWriter< T >::endRun ( const edm::Run run,
const edm::EventSetup es 
) [inline, private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 258 of file ConditionDBWriter.h.

  {
    edm::LogInfo("ConditionDBWriter::endRun") << std::endl;
    
    algoEndRun(run, es);
    
    if(RunMode_){
      
      T * objPointer = getNewObject();
      
      if(objPointer ){
        if( timeFromEndRun_ ) Time_ = run.id().run();
        storeOnDb(objPointer);
      }
      else {
        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;
      }
    }
  }
template<class T>
virtual T* ConditionDBWriter< T >::getNewObject ( ) [private, pure virtual]
template<class T>
void ConditionDBWriter< T >::setDoStore ( const bool  doStore) [inline, protected]

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

Definition at line 372 of file ConditionDBWriter.h.

{doStore_ = doStore;}
template<class T>
void ConditionDBWriter< T >::setTime ( ) [inline, private]

Definition at line 326 of file ConditionDBWriter.h.

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

  {
    edm::Service<cond::service::PoolDBOutputService> mydbservice;
    
    if( mydbservice.isAvailable() ){
      Time_ = mydbservice->currentTime();
      edm::LogInfo("ConditionDBWriter::setTime: time set to ") << Time_ << std::endl;
    }
    else{
      edm::LogError("ConditionDBWriter::setTime(): PoolDBOutputService is not available...cannot set current time") << std::endl;
    }
  }
template<class T>
void ConditionDBWriter< T >::storeOnDb ( T objPointer) [inline, private]

Definition at line 299 of file ConditionDBWriter.h.

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

  {
    edm::LogInfo("ConditionDBWriter::storeOnDb ")  << std::endl;
    
    setSinceTime_=true;
    
    if(! objPointer) {
      edm::LogError("ConditionDBWriter: Pointer to object has not been set...storing no data on DB") ;
      return;
    }
    
    //And now write  data in DB
    if( !doStore_ ) return;
    edm::Service<cond::service::PoolDBOutputService> mydbservice;
    if (!  mydbservice.isAvailable() ) {
      edm::LogError("ConditionDBWriter")<<"PoolDBOutputService is unavailable"<<std::endl;
      return;
    }
    
    cond::Time_t since = 
      ( mydbservice->isNewTagRequest(Record_) && !timeFromEndRun_ ) ? mydbservice->beginOfTime() : Time_;

    edm::LogInfo("ConditionDBWriter") << "appending a new object to tag " 
                                      <<Record_ <<" in since mode " << std::endl;
    mydbservice->writeOne<T>(objPointer, since, Record_);
  }
template<class T>
void ConditionDBWriter< T >::storeOnDbNow ( ) [inline, protected]

Definition at line 343 of file ConditionDBWriter.h.

  {
    T * objPointer = 0;
    
    if(AlgoDrivenMode_){
      
      setSinceTime_=true;
      
      objPointer = getNewObject();
      
      if (!objPointer ) {
        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;
        return;
      }
      else {storeOnDb(objPointer);}
      
    }
    else {
      
      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;
      return;
    }
  }
template<class T>
cond::Time_t ConditionDBWriter< T >::timeOfLastIOV ( ) [inline, protected]

Definition at line 369 of file ConditionDBWriter.h.

{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 389 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>
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]