Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:02

0001 #include "FWCore/ServiceRegistry/interface/Service.h"
0002 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 
0008 #include "CondTools/Ecal/interface/ESDBCopy.h"
0009 #include <vector>
0010 
0011 ESDBCopy::ESDBCopy(const edm::ParameterSet& iConfig)
0012     : m_timetype(iConfig.getParameter<std::string>("timetype")),
0013       m_cacheIDs(),
0014       m_records(),
0015       esPedestalsToken_(esConsumes()),
0016       esADCToGeVConstantToken_(esConsumes()),
0017       esChannelStatusToken_(esConsumes()),
0018       esIntercalibConstantsToken_(esConsumes()),
0019       esWeightStripGroupsToken_(esConsumes()),
0020       esTBWeightsToken_(esConsumes()) {
0021   std::string container;
0022   std::string record;
0023   typedef std::vector<edm::ParameterSet> Parameters;
0024   Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
0025   for (const auto& iparam : toCopy) {
0026     container = iparam.getParameter<std::string>("container");
0027     record = iparam.getParameter<std::string>("record");
0028     m_cacheIDs.emplace(container, 0);
0029     m_records.emplace(container, record);
0030   }
0031 }
0032 
0033 ESDBCopy::~ESDBCopy() {}
0034 
0035 void ESDBCopy::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0036   for (const auto& irec : m_records) {
0037     if (shouldCopy(evtSetup, irec.first)) {
0038       copyToDB(evtSetup, irec.first);
0039     }
0040   }
0041 }
0042 
0043 bool ESDBCopy::shouldCopy(const edm::EventSetup& evtSetup, const std::string& container) {
0044   unsigned long long cacheID = 0;
0045   if (container == "ESPedestals") {
0046     cacheID = evtSetup.get<ESPedestalsRcd>().cacheIdentifier();
0047   } else if (container == "ESADCToGeVConstant") {
0048     cacheID = evtSetup.get<ESADCToGeVConstantRcd>().cacheIdentifier();
0049   } else if (container == "ESIntercalibConstants") {
0050     cacheID = evtSetup.get<ESIntercalibConstantsRcd>().cacheIdentifier();
0051   } else if (container == "ESWeightStripGroups") {
0052     cacheID = evtSetup.get<ESWeightStripGroupsRcd>().cacheIdentifier();
0053   } else if (container == "ESTBWeights") {
0054     cacheID = evtSetup.get<ESTBWeightsRcd>().cacheIdentifier();
0055   } else if (container == "ESChannelStatus") {
0056     cacheID = evtSetup.get<ESChannelStatusRcd>().cacheIdentifier();
0057   } else {
0058     throw cms::Exception("Unknown container");
0059   }
0060 
0061   if (m_cacheIDs[container] == cacheID) {
0062     return false;
0063   } else {
0064     m_cacheIDs[container] = cacheID;
0065     return true;
0066   }
0067 }
0068 
0069 void ESDBCopy::copyToDB(const edm::EventSetup& evtSetup, const std::string& container) {
0070   edm::Service<cond::service::PoolDBOutputService> dbOutput;
0071   if (!dbOutput.isAvailable()) {
0072     throw cms::Exception("PoolDBOutputService is not available");
0073   }
0074 
0075   std::string recordName = m_records[container];
0076 
0077   if (container == "ESPedestals") {
0078     const auto& obj = evtSetup.getData(esPedestalsToken_);
0079     edm::LogInfo("ESDBCopy") << "ped pointer is: " << &obj;
0080     dbOutput->createOneIOV<const ESPedestals>(obj, dbOutput->beginOfTime(), recordName);
0081 
0082   } else if (container == "ESADCToGeVConstant") {
0083     const auto& obj = evtSetup.getData(esADCToGeVConstantToken_);
0084     edm::LogInfo("ESDBCopy") << "adc pointer is: " << &obj;
0085     dbOutput->createOneIOV<const ESADCToGeVConstant>(obj, dbOutput->beginOfTime(), recordName);
0086 
0087   } else if (container == "ESChannelStatus") {
0088     const auto& obj = evtSetup.getData(esChannelStatusToken_);
0089     edm::LogInfo("ESDBCopy") << "channel status pointer is: " << &obj;
0090     dbOutput->createOneIOV<const ESChannelStatus>(obj, dbOutput->beginOfTime(), recordName);
0091 
0092   } else if (container == "ESIntercalibConstants") {
0093     const auto& obj = evtSetup.getData(esIntercalibConstantsToken_);
0094     edm::LogInfo("ESDBCopy") << "inter pointer is: " << &obj;
0095     dbOutput->createOneIOV<const ESIntercalibConstants>(obj, dbOutput->beginOfTime(), recordName);
0096 
0097   } else if (container == "ESWeightStripGroups") {
0098     const auto& obj = evtSetup.getData(esWeightStripGroupsToken_);
0099     edm::LogInfo("ESDBCopy") << "weight pointer is: " << &obj;
0100     dbOutput->createOneIOV<const ESWeightStripGroups>(obj, dbOutput->beginOfTime(), recordName);
0101 
0102   } else if (container == "ESTBWeights") {
0103     const auto& obj = evtSetup.getData(esTBWeightsToken_);
0104     edm::LogInfo("ESDBCopy") << "tbweight pointer is: " << &obj;
0105     dbOutput->createOneIOV<const ESTBWeights>(obj, dbOutput->beginOfTime(), recordName);
0106 
0107   } else {
0108     throw cms::Exception("Unknown container");
0109   }
0110 
0111   edm::LogInfo("ESDBCopy") << "ESDBCopy wrote " << recordName;
0112 }