Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-13 03:30:39

0001 #include "FWCore/ServiceRegistry/interface/Service.h"
0002 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0003 
0004 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 
0009 #include "EcalTPGDBCopy.h"
0010 
0011 #include <vector>
0012 
0013 EcalTPGDBCopy::EcalTPGDBCopy(const edm::ParameterSet& iConfig)
0014     : m_timetype(iConfig.getParameter<std::string>("timetype")), m_cacheIDs(), m_records() {
0015   auto cc = consumesCollector();
0016   std::string container;
0017   std::string tag;
0018   std::string record;
0019   typedef std::vector<edm::ParameterSet> Parameters;
0020   Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
0021   for (Parameters::iterator i = toCopy.begin(); i != toCopy.end(); ++i) {
0022     container = i->getParameter<std::string>("container");
0023     record = i->getParameter<std::string>("record");
0024     m_cacheIDs.insert(std::make_pair(container, 0));
0025     m_records.insert(std::make_pair(container, record));
0026     setConsumes(cc, container);
0027   }
0028 }
0029 
0030 EcalTPGDBCopy::~EcalTPGDBCopy() {}
0031 
0032 void EcalTPGDBCopy::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0033   std::string container;
0034   std::string record;
0035   typedef std::map<std::string, std::string>::const_iterator recordIter;
0036   for (recordIter i = m_records.begin(); i != m_records.end(); ++i) {
0037     container = (*i).first;
0038     record = (*i).second;
0039     if (shouldCopy(evtSetup, container)) {
0040       copyToDB(evtSetup, container);
0041     }
0042   }
0043 }
0044 
0045 void EcalTPGDBCopy::setConsumes(edm::ConsumesCollector& cc, const std::string& container) {
0046   if (container == "EcalTPGPedestals") {
0047     pedestalsToken_ = cc.esConsumes();
0048   } else if (container == "EcalTPGLinearizationConst") {
0049     linearizationConstToken_ = cc.esConsumes();
0050   } else if (container == "EcalTPGSlidingWindow") {
0051     slidingWindowToken_ = cc.esConsumes();
0052   } else if (container == "EcalTPGFineGrainEBIdMap") {
0053     fineGrainEBIdMapToken_ = cc.esConsumes();
0054   } else if (container == "EcalTPGFineGrainStripEE") {
0055     fineGrainStripEEToken_ = cc.esConsumes();
0056   } else if (container == "EcalTPGFineGrainTowerEE") {
0057     fineGrainTowerEEToken_ = cc.esConsumes();
0058   } else if (container == "EcalTPGLutIdMap") {
0059     lutIdMapToken_ = cc.esConsumes();
0060   } else if (container == "EcalTPGWeightIdMap") {
0061     weightIdMapToken_ = cc.esConsumes();
0062   } else if (container == "EcalTPGWeightGroup") {
0063     weightGroupToken_ = cc.esConsumes();
0064   } else if (container == "EcalTPGOddWeightIdMap") {
0065     oddWeightIdMapToken_ = cc.esConsumes();
0066   } else if (container == "EcalTPGOddWeightGroup") {
0067     oddWeightGroupToken_ = cc.esConsumes();
0068   } else if (container == "EcalTPGTPMode") {
0069     tpModeToken_ = cc.esConsumes();
0070   } else if (container == "EcalTPGLutGroup") {
0071     lutGroupToken_ = cc.esConsumes();
0072   } else if (container == "EcalTPGFineGrainEBGroup") {
0073     fineGrainEBGroupToken_ = cc.esConsumes();
0074   } else if (container == "EcalTPGPhysicsConst") {
0075     physicsConstToken_ = cc.esConsumes();
0076   } else if (container == "EcalTPGCrystalStatus") {
0077     crystalStatusToken_ = cc.esConsumes();
0078   } else if (container == "EcalTPGTowerStatus") {
0079     towerStatusToken_ = cc.esConsumes();
0080   } else if (container == "EcalTPGSpike") {
0081     spikeToken_ = cc.esConsumes();
0082   } else if (container == "EcalTPGStripStatus") {
0083     stripStatusToken_ = cc.esConsumes();
0084   } else {
0085     throw cms::Exception("Unknown container");
0086   }
0087 }
0088 
0089 bool EcalTPGDBCopy::shouldCopy(const edm::EventSetup& evtSetup, const std::string& container) {
0090   unsigned long long cacheID = 0;
0091 
0092   if (container == "EcalTPGPedestals") {
0093     cacheID = evtSetup.get<EcalTPGPedestalsRcd>().cacheIdentifier();
0094   } else if (container == "EcalTPGLinearizationConst") {
0095     cacheID = evtSetup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
0096   } else if (container == "EcalTPGSlidingWindow") {
0097     cacheID = evtSetup.get<EcalTPGSlidingWindowRcd>().cacheIdentifier();
0098   } else if (container == "EcalTPGFineGrainEBIdMap") {
0099     cacheID = evtSetup.get<EcalTPGFineGrainEBIdMapRcd>().cacheIdentifier();
0100   } else if (container == "EcalTPGFineGrainStripEE") {
0101     cacheID = evtSetup.get<EcalTPGFineGrainStripEERcd>().cacheIdentifier();
0102   } else if (container == "EcalTPGFineGrainTowerEE") {
0103     cacheID = evtSetup.get<EcalTPGFineGrainTowerEERcd>().cacheIdentifier();
0104   } else if (container == "EcalTPGLutIdMap") {
0105     cacheID = evtSetup.get<EcalTPGLutIdMapRcd>().cacheIdentifier();
0106   } else if (container == "EcalTPGWeightIdMap") {
0107     cacheID = evtSetup.get<EcalTPGWeightIdMapRcd>().cacheIdentifier();
0108   } else if (container == "EcalTPGWeightGroup") {
0109     cacheID = evtSetup.get<EcalTPGWeightGroupRcd>().cacheIdentifier();
0110   } else if (container == "EcalTPGOddWeightIdMap") {
0111     cacheID = evtSetup.get<EcalTPGOddWeightIdMapRcd>().cacheIdentifier();
0112   } else if (container == "EcalTPGOddWeightGroup") {
0113     cacheID = evtSetup.get<EcalTPGOddWeightGroupRcd>().cacheIdentifier();
0114   } else if (container == "EcalTPGTPMode") {
0115     cacheID = evtSetup.get<EcalTPGTPModeRcd>().cacheIdentifier();
0116   } else if (container == "EcalTPGLutGroup") {
0117     cacheID = evtSetup.get<EcalTPGLutGroupRcd>().cacheIdentifier();
0118   } else if (container == "EcalTPGFineGrainEBGroup") {
0119     cacheID = evtSetup.get<EcalTPGFineGrainEBGroupRcd>().cacheIdentifier();
0120   } else if (container == "EcalTPGPhysicsConst") {
0121     cacheID = evtSetup.get<EcalTPGPhysicsConstRcd>().cacheIdentifier();
0122   } else if (container == "EcalTPGCrystalStatus") {
0123     cacheID = evtSetup.get<EcalTPGCrystalStatusRcd>().cacheIdentifier();
0124   } else if (container == "EcalTPGTowerStatus") {
0125     cacheID = evtSetup.get<EcalTPGTowerStatusRcd>().cacheIdentifier();
0126   } else if (container == "EcalTPGSpike") {
0127     cacheID = evtSetup.get<EcalTPGSpikeRcd>().cacheIdentifier();
0128   } else if (container == "EcalTPGStripStatus") {
0129     cacheID = evtSetup.get<EcalTPGStripStatusRcd>().cacheIdentifier();
0130   } else {
0131     throw cms::Exception("Unknown container");
0132   }
0133 
0134   if (m_cacheIDs[container] == cacheID) {
0135     return false;
0136   } else {
0137     m_cacheIDs[container] = cacheID;
0138     return true;
0139   }
0140 }
0141 
0142 void EcalTPGDBCopy::copyToDB(const edm::EventSetup& evtSetup, const std::string& container) {
0143   edm::Service<cond::service::PoolDBOutputService> dbOutput;
0144   if (!dbOutput.isAvailable()) {
0145     throw cms::Exception("PoolDBOutputService is not available");
0146   }
0147 
0148   std::string recordName = m_records[container];
0149 
0150   if (container == "EcalTPGPedestals") {
0151     const auto& obj = evtSetup.getData(pedestalsToken_);
0152     dbOutput->createOneIOV<const EcalTPGPedestals>(obj, dbOutput->beginOfTime(), recordName);
0153 
0154   } else if (container == "EcalTPGLinearizationConst") {
0155     const auto& obj = evtSetup.getData(linearizationConstToken_);
0156     dbOutput->createOneIOV<const EcalTPGLinearizationConst>(obj, dbOutput->beginOfTime(), recordName);
0157 
0158   } else if (container == "EcalTPGSlidingWindow") {
0159     const auto& obj = evtSetup.getData(slidingWindowToken_);
0160     dbOutput->createOneIOV<const EcalTPGSlidingWindow>(obj, dbOutput->beginOfTime(), recordName);
0161 
0162   } else if (container == "EcalTPGFineGrainEBIdMap") {
0163     const auto& obj = evtSetup.getData(fineGrainEBIdMapToken_);
0164     dbOutput->createOneIOV<const EcalTPGFineGrainEBIdMap>(obj, dbOutput->beginOfTime(), recordName);
0165 
0166   } else if (container == "EcalTPGFineGrainStripEE") {
0167     const auto& obj = evtSetup.getData(fineGrainStripEEToken_);
0168     dbOutput->createOneIOV<const EcalTPGFineGrainStripEE>(obj, dbOutput->beginOfTime(), recordName);
0169 
0170   } else if (container == "EcalTPGFineGrainTowerEE") {
0171     const auto& obj = evtSetup.getData(fineGrainTowerEEToken_);
0172     dbOutput->createOneIOV<const EcalTPGFineGrainTowerEE>(obj, dbOutput->beginOfTime(), recordName);
0173 
0174   } else if (container == "EcalTPGLutIdMap") {
0175     const auto& obj = evtSetup.getData(lutIdMapToken_);
0176     dbOutput->createOneIOV<const EcalTPGLutIdMap>(obj, dbOutput->beginOfTime(), recordName);
0177 
0178   } else if (container == "EcalTPGWeightIdMap") {
0179     const auto& obj = evtSetup.getData(weightIdMapToken_);
0180     dbOutput->createOneIOV<const EcalTPGWeightIdMap>(obj, dbOutput->beginOfTime(), recordName);
0181 
0182   } else if (container == "EcalTPGWeightGroup") {
0183     const auto& obj = evtSetup.getData(weightGroupToken_);
0184     dbOutput->createOneIOV<const EcalTPGWeightGroup>(obj, dbOutput->beginOfTime(), recordName);
0185 
0186   } else if (container == "EcalTPGOddWeightIdMap") {
0187     const auto& obj = evtSetup.getData(oddWeightIdMapToken_);
0188     dbOutput->createOneIOV<const EcalTPGOddWeightIdMap>(obj, dbOutput->beginOfTime(), recordName);
0189 
0190   } else if (container == "EcalTPGOddWeightGroup") {
0191     const auto& obj = evtSetup.getData(oddWeightGroupToken_);
0192     dbOutput->createOneIOV<const EcalTPGOddWeightGroup>(obj, dbOutput->beginOfTime(), recordName);
0193 
0194   } else if (container == "EcalTPGTPMode") {
0195     const auto& obj = evtSetup.getData(tpModeToken_);
0196     dbOutput->createOneIOV<const EcalTPGTPMode>(obj, dbOutput->beginOfTime(), recordName);
0197 
0198   } else if (container == "EcalTPGLutGroup") {
0199     const auto& obj = evtSetup.getData(lutGroupToken_);
0200     dbOutput->createOneIOV<const EcalTPGLutGroup>(obj, dbOutput->beginOfTime(), recordName);
0201 
0202   } else if (container == "EcalTPGFineGrainEBGroup") {
0203     const auto& obj = evtSetup.getData(fineGrainEBGroupToken_);
0204     dbOutput->createOneIOV<const EcalTPGFineGrainEBGroup>(obj, dbOutput->beginOfTime(), recordName);
0205 
0206   } else if (container == "EcalTPGPhysicsConst") {
0207     const auto& obj = evtSetup.getData(physicsConstToken_);
0208     dbOutput->createOneIOV<const EcalTPGPhysicsConst>(obj, dbOutput->beginOfTime(), recordName);
0209 
0210   } else if (container == "EcalTPGCrystalStatus") {
0211     const auto& obj = evtSetup.getData(crystalStatusToken_);
0212     dbOutput->createOneIOV<const EcalTPGCrystalStatus>(obj, dbOutput->beginOfTime(), recordName);
0213 
0214   } else if (container == "EcalTPGTowerStatus") {
0215     const auto& obj = evtSetup.getData(towerStatusToken_);
0216     dbOutput->createOneIOV<const EcalTPGTowerStatus>(obj, dbOutput->beginOfTime(), recordName);
0217 
0218   } else if (container == "EcalTPGSpike") {
0219     const auto& obj = evtSetup.getData(spikeToken_);
0220     dbOutput->createOneIOV<const EcalTPGSpike>(obj, dbOutput->beginOfTime(), recordName);
0221 
0222   } else if (container == "EcalTPGStripStatus") {
0223     const auto& obj = evtSetup.getData(stripStatusToken_);
0224     dbOutput->createOneIOV<const EcalTPGStripStatus>(obj, dbOutput->beginOfTime(), recordName);
0225 
0226   } else {
0227     throw cms::Exception("Unknown container");
0228   }
0229 
0230   edm::LogInfo("EcalTPGDBCopy") << "EcalTPGDBCopy wrote " << recordName;
0231 }