CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CondTools/Ecal/src/ESDBCopy.cc

Go to the documentation of this file.
00001 #include "FWCore/ServiceRegistry/interface/Service.h"
00002 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00003 
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 
00006 
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 
00010 
00011 #include "CondTools/Ecal/interface/ESDBCopy.h"
00012 #include "CondFormats/ESObjects/interface/ESPedestals.h"
00013 #include "CondFormats/DataRecord/interface/ESPedestalsRcd.h"
00014 #include "CondFormats/ESObjects/interface/ESADCToGeVConstant.h"
00015 #include "CondFormats/DataRecord/interface/ESADCToGeVConstantRcd.h"
00016 #include "CondFormats/ESObjects/interface/ESChannelStatus.h"
00017 #include "CondFormats/DataRecord/interface/ESChannelStatusRcd.h"
00018 #include "CondFormats/ESObjects/interface/ESIntercalibConstants.h"
00019 #include "CondFormats/DataRecord/interface/ESIntercalibConstantsRcd.h"
00020 #include "CondFormats/ESObjects/interface/ESWeightStripGroups.h"
00021 #include "CondFormats/DataRecord/interface/ESWeightStripGroupsRcd.h"
00022 #include "CondFormats/ESObjects/interface/ESTBWeights.h"
00023 #include "CondFormats/DataRecord/interface/ESTBWeightsRcd.h"
00024 
00025 
00026 
00027 #include <vector>
00028 
00029 ESDBCopy::ESDBCopy(const edm::ParameterSet& iConfig) :
00030   m_timetype(iConfig.getParameter<std::string>("timetype")),
00031   m_cacheIDs(),
00032   m_records()
00033 {
00034 
00035   std::string container;
00036   std::string tag;
00037   std::string record;
00038   typedef std::vector< edm::ParameterSet > Parameters;
00039   Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
00040   for(Parameters::iterator i = toCopy.begin(); i != toCopy.end(); ++i) {
00041     container = i->getParameter<std::string>("container");
00042     record = i->getParameter<std::string>("record");
00043     m_cacheIDs.insert( std::make_pair(container, 0) );
00044     m_records.insert( std::make_pair(container, record) );
00045   }
00046   
00047 }
00048 
00049 
00050 ESDBCopy::~ESDBCopy()
00051 {
00052   
00053 }
00054 
00055 void ESDBCopy::analyze( const edm::Event& evt, const edm::EventSetup& evtSetup)
00056 {
00057 
00058   std::string container;
00059   std::string record;
00060   typedef std::map<std::string, std::string>::const_iterator recordIter;
00061   for (recordIter i = m_records.begin(); i != m_records.end(); ++i) {
00062     container = (*i).first;
00063     record = (*i).second;
00064     if ( shouldCopy(evtSetup, container) ) {
00065       copyToDB(evtSetup, container);
00066     }
00067   }
00068   
00069 }
00070 
00071 
00072 
00073 bool ESDBCopy::shouldCopy(const edm::EventSetup& evtSetup, std::string container)
00074 {
00075 
00076   unsigned long long cacheID = 0;
00077   if (container == "ESPedestals") {
00078     cacheID = evtSetup.get<ESPedestalsRcd>().cacheIdentifier();
00079   } else if (container == "ESADCToGeVConstant") {
00080     cacheID = evtSetup.get<ESADCToGeVConstantRcd>().cacheIdentifier();
00081   } else if (container == "ESIntercalibConstants") {
00082     cacheID = evtSetup.get<ESIntercalibConstantsRcd>().cacheIdentifier();
00083   } else if (container == "ESWeightStripGroups") {
00084     cacheID = evtSetup.get<ESWeightStripGroupsRcd>().cacheIdentifier();
00085   } else if (container == "ESTBWeights") {
00086     cacheID = evtSetup.get<ESTBWeightsRcd>().cacheIdentifier();
00087   } else if (container == "ESChannelStatus") {
00088     cacheID = evtSetup.get<ESChannelStatusRcd>().cacheIdentifier();
00089   } 
00090 
00091   else {
00092     throw cms::Exception("Unknown container");
00093   }
00094   
00095   if (m_cacheIDs[container] == cacheID) {
00096     return 0;
00097   } else {
00098     m_cacheIDs[container] = cacheID;
00099     return 1;
00100   }
00101 
00102 }
00103 
00104 
00105 
00106 void ESDBCopy::copyToDB(const edm::EventSetup& evtSetup, std::string container)
00107 {
00108   edm::Service<cond::service::PoolDBOutputService> dbOutput;
00109   if ( !dbOutput.isAvailable() ) {
00110     throw cms::Exception("PoolDBOutputService is not available");
00111   }
00112 
00113   std::string recordName = m_records[container];
00114 
00115   if (container == "ESPedestals") {
00116     edm::ESHandle<ESPedestals> handle;
00117     evtSetup.get<ESPedestalsRcd>().get(handle);
00118     const ESPedestals* obj = handle.product();
00119     std::cout << "ped pointer is: "<< obj<< std::endl;
00120     dbOutput->createNewIOV<const ESPedestals>( new ESPedestals(*obj), dbOutput->beginOfTime(),dbOutput->endOfTime(),recordName);
00121 
00122   }  else if (container == "ESADCToGeVConstant") {
00123     edm::ESHandle<ESADCToGeVConstant> handle;
00124     evtSetup.get<ESADCToGeVConstantRcd>().get(handle);
00125     const ESADCToGeVConstant* obj = handle.product();
00126     std::cout << "adc pointer is: "<< obj<< std::endl;
00127 
00128    dbOutput->createNewIOV<const ESADCToGeVConstant>( new ESADCToGeVConstant(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00129 
00130 
00131   }  else if (container == "ESChannelStatus") {
00132     edm::ESHandle<ESChannelStatus> handle;
00133     evtSetup.get<ESChannelStatusRcd>().get(handle);
00134     const ESChannelStatus* obj = handle.product();
00135     std::cout << "channel status pointer is: "<< obj<< std::endl;
00136 
00137    dbOutput->createNewIOV<const ESChannelStatus>( new ESChannelStatus(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00138 
00139 
00140   }
00141 else if (container == "ESIntercalibConstants") {
00142     edm::ESHandle<ESIntercalibConstants> handle;
00143     evtSetup.get<ESIntercalibConstantsRcd>().get(handle);
00144     const ESIntercalibConstants* obj = handle.product();
00145     std::cout << "inter pointer is: "<< obj<< std::endl;
00146    dbOutput->createNewIOV<const ESIntercalibConstants>( new ESIntercalibConstants(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00147 
00148 
00149   } else if (container == "ESWeightStripGroups") {
00150     edm::ESHandle<ESWeightStripGroups> handle;
00151     evtSetup.get<ESWeightStripGroupsRcd>().get(handle);
00152     const ESWeightStripGroups* obj = handle.product();
00153     std::cout << "weight pointer is: "<< obj<< std::endl;
00154    dbOutput->createNewIOV<const ESWeightStripGroups>( new ESWeightStripGroups(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00155 
00156   } else if (container == "ESTBWeights") {
00157     edm::ESHandle<ESTBWeights> handle;
00158     evtSetup.get<ESTBWeightsRcd>().get(handle);
00159     const ESTBWeights* obj = handle.product();
00160     std::cout << "tbweight pointer is: "<< obj<< std::endl;
00161    dbOutput->createNewIOV<const ESTBWeights>( new ESTBWeights(*obj), dbOutput->beginOfTime(),dbOutput->endOfTime(),recordName);
00162 
00163 
00164   } else {
00165     throw cms::Exception("Unknown container");
00166   }
00167 
00168   std::cout<< "ESDBCopy wrote " << recordName << std::endl;
00169 }