CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CalibTracker/SiStripESProducers/plugins/DBWriter/DummyCondDBWriter.h

Go to the documentation of this file.
00001 #ifndef CalibTracker_SiStripESProducer_DummyCondDBWriter_h
00002 #define CalibTracker_SiStripESProducer_DummyCondDBWriter_h
00003 
00004 // user include files
00005 #include "FWCore/Framework/interface/EDAnalyzer.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "FWCore/Framework/interface/Run.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00012 #include "CondCore/DBCommon/interface/Time.h"
00013 
00014 #include "FWCore/Utilities/interface/Exception.h"
00015 
00016 #include <string>
00017 
00018 
00019 
00020 template< typename TObject , typename TObjectO , typename TRecord>
00021 class DummyCondDBWriter : public edm::EDAnalyzer {
00022 
00023 public:
00024 
00025   explicit DummyCondDBWriter(const edm::ParameterSet& iConfig);
00026   ~DummyCondDBWriter();
00027   void analyze(const edm::Event& e, const edm::EventSetup&es){};
00028 
00029   void endRun(const edm::Run & run, const edm::EventSetup & es);
00030 
00031  private:
00032   edm::ParameterSet iConfig_;
00033   unsigned long long cacheID;
00034 };
00035 
00036 template< typename TObject , typename TObjectO ,typename TRecord>
00037 DummyCondDBWriter<TObject,TObjectO,TRecord>::DummyCondDBWriter(const edm::ParameterSet& iConfig):iConfig_(iConfig),cacheID(0){
00038   edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter constructor for typename " << typeid(TObject).name() << " and record " << typeid(TRecord).name() << std::endl;
00039 }
00040 
00041 
00042 template< typename TObject , typename TObjectO ,typename TRecord >
00043 DummyCondDBWriter<TObject,TObjectO,TRecord>::~DummyCondDBWriter(){
00044  edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter::~DummyCondDBWriter()" << std::endl;
00045 }
00046 
00047 template< typename TObject , typename TObjectO ,typename TRecord >
00048 void DummyCondDBWriter<TObject,TObjectO,TRecord>::endRun(const edm::Run & run, const edm::EventSetup & es){
00049 
00050   std::string rcdName=iConfig_.getParameter<std::string>("record");
00051 
00052   if( cacheID == es.get<TRecord>().cacheIdentifier()){
00053       edm::LogInfo("DummyCondDBWriter") << "not needed to store objects with Record "<< rcdName << " at run " << run.run() << std::endl;    return;
00054   }
00055   cacheID = es.get<TRecord>().cacheIdentifier();
00056 
00057   edm::ESHandle<TObject> esobj;
00058   es.get<TRecord>().get( esobj );
00059   TObjectO *obj= new TObjectO(*(esobj.product()));
00060   cond::Time_t Time_;  
00061   
00062   //And now write  data in DB
00063   edm::Service<cond::service::PoolDBOutputService> dbservice;
00064   if( dbservice.isAvailable() ){
00065 
00066     std::string openIovAt=iConfig_.getUntrackedParameter<std::string>("OpenIovAt","beginOfTime");
00067     if(openIovAt=="beginOfTime")
00068       Time_=dbservice->beginOfTime();
00069     else if (openIovAt=="currentTime")
00070       Time_=dbservice->currentTime();
00071     else
00072       Time_=iConfig_.getUntrackedParameter<uint32_t>("OpenIovAtTime",1);
00073     
00074     dbservice->writeOne(obj, Time_, rcdName);
00075   } else{
00076     edm::LogError("SiStripFedCablingBuilder")<<"Service is unavailable"<<std::endl;
00077   }
00078 }
00079 
00080 #endif