CMS 3D CMS Logo

EcalDBCopy.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/EcalDBCopy.h"
00012 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
00013 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
00014 #include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h"
00015 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
00016 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00017 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00018 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00019 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00020 #include "CondFormats/EcalObjects/interface/EcalIntercalibErrors.h"
00021 #include "CondFormats/DataRecord/interface/EcalIntercalibErrorsRcd.h"
00022 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
00023 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
00024 #include "CondFormats/EcalObjects/interface/EcalWeightXtalGroups.h"
00025 #include "CondFormats/DataRecord/interface/EcalWeightXtalGroupsRcd.h"
00026 #include "CondFormats/EcalObjects/interface/EcalTBWeights.h"
00027 #include "CondFormats/DataRecord/interface/EcalTBWeightsRcd.h"
00028 #include "CondFormats/EcalObjects/interface/EcalLaserAlphas.h"
00029 #include "CondFormats/DataRecord/interface/EcalLaserAlphasRcd.h"
00030 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatios.h"
00031 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRcd.h"
00032 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatiosRef.h"
00033 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRefRcd.h"
00034 
00035 
00036 #include <vector>
00037 
00038 
00039 
00040 EcalDBCopy::EcalDBCopy(const edm::ParameterSet& iConfig) :
00041   m_timetype(iConfig.getParameter<std::string>("timetype")),
00042   m_cacheIDs(),
00043   m_records()
00044 {
00045 
00046   std::string container;
00047   std::string tag;
00048   std::string record;
00049   typedef std::vector< edm::ParameterSet > Parameters;
00050   Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
00051   for(Parameters::iterator i = toCopy.begin(); i != toCopy.end(); ++i) {
00052     container = i->getParameter<std::string>("container");
00053     record = i->getParameter<std::string>("record");
00054     m_cacheIDs.insert( std::make_pair(container, 0) );
00055     m_records.insert( std::make_pair(container, record) );
00056   }
00057   
00058 }
00059 
00060 
00061 EcalDBCopy::~EcalDBCopy()
00062 {
00063   
00064 }
00065 
00066 void EcalDBCopy::analyze( const edm::Event& evt, const edm::EventSetup& evtSetup)
00067 {
00068 
00069   std::string container;
00070   std::string record;
00071   typedef std::map<std::string, std::string>::const_iterator recordIter;
00072   for (recordIter i = m_records.begin(); i != m_records.end(); ++i) {
00073     container = (*i).first;
00074     record = (*i).second;
00075     if ( shouldCopy(evtSetup, container) ) {
00076       copyToDB(evtSetup, container);
00077     }
00078   }
00079   
00080 }
00081 
00082 
00083 
00084 bool EcalDBCopy::shouldCopy(const edm::EventSetup& evtSetup, std::string container)
00085 {
00086 
00087   unsigned long long cacheID = 0;
00088   if (container == "EcalPedestals") {
00089     cacheID = evtSetup.get<EcalPedestalsRcd>().cacheIdentifier();
00090   } else if (container == "EcalADCToGeVConstant") {
00091     cacheID = evtSetup.get<EcalADCToGeVConstantRcd>().cacheIdentifier();
00092   } else if (container == "EcalIntercalibConstants") {
00093     cacheID = evtSetup.get<EcalIntercalibConstantsRcd>().cacheIdentifier();
00094   } else if (container == "EcalIntercalibErrors") {
00095     cacheID = evtSetup.get<EcalIntercalibErrorsRcd>().cacheIdentifier();
00096   } else if (container == "EcalGainRatios") {
00097     cacheID = evtSetup.get<EcalGainRatiosRcd>().cacheIdentifier();
00098   } else if (container == "EcalWeightXtalGroups") {
00099     cacheID = evtSetup.get<EcalWeightXtalGroupsRcd>().cacheIdentifier();
00100   } else if (container == "EcalTBWeights") {
00101     cacheID = evtSetup.get<EcalTBWeightsRcd>().cacheIdentifier();
00102   } else if (container == "EcalLaserAPDPNRatios") {
00103     cacheID = evtSetup.get<EcalLaserAPDPNRatiosRcd>().cacheIdentifier();
00104   } else if (container == "EcalLaserAPDPNRatiosRef") {
00105     cacheID = evtSetup.get<EcalTBWeightsRcd>().cacheIdentifier();
00106   } else if (container == "EcalLaserAlphas") {
00107     cacheID = evtSetup.get<EcalTBWeightsRcd>().cacheIdentifier();
00108   } else if (container == "EcalChannelStatus") {
00109     cacheID = evtSetup.get<EcalChannelStatusRcd>().cacheIdentifier();
00110   } 
00111 
00112   else {
00113     throw cms::Exception("Unknown container");
00114   }
00115   
00116   if (m_cacheIDs[container] == cacheID) {
00117     return 0;
00118   } else {
00119     m_cacheIDs[container] = cacheID;
00120     return 1;
00121   }
00122 
00123 }
00124 
00125 
00126 
00127 void EcalDBCopy::copyToDB(const edm::EventSetup& evtSetup, std::string container)
00128 {
00129   edm::Service<cond::service::PoolDBOutputService> dbOutput;
00130   if ( !dbOutput.isAvailable() ) {
00131     throw cms::Exception("PoolDBOutputService is not available");
00132   }
00133 
00134   std::string recordName = m_records[container];
00135 
00136   if (container == "EcalPedestals") {
00137     edm::ESHandle<EcalPedestals> handle;
00138     evtSetup.get<EcalPedestalsRcd>().get(handle);
00139     const EcalPedestals* obj = handle.product();
00140     cout << "ped pointer is: "<< obj<< endl;
00141     dbOutput->createNewIOV<const EcalPedestals>( new EcalPedestals(*obj), dbOutput->beginOfTime(),dbOutput->endOfTime(),recordName);
00142 
00143   }  else if (container == "EcalADCToGeVConstant") {
00144     edm::ESHandle<EcalADCToGeVConstant> handle;
00145     evtSetup.get<EcalADCToGeVConstantRcd>().get(handle);
00146     const EcalADCToGeVConstant* obj = handle.product();
00147     cout << "adc pointer is: "<< obj<< endl;
00148 
00149    dbOutput->createNewIOV<const EcalADCToGeVConstant>( new EcalADCToGeVConstant(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00150 
00151 
00152   }  else if (container == "EcalChannelStatus") {
00153     edm::ESHandle<EcalChannelStatus> handle;
00154     evtSetup.get<EcalChannelStatusRcd>().get(handle);
00155     const EcalChannelStatus* obj = handle.product();
00156     cout << "channel status pointer is: "<< obj<< endl;
00157 
00158    dbOutput->createNewIOV<const EcalChannelStatus>( new EcalChannelStatus(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00159 
00160 
00161   }
00162 else if (container == "EcalIntercalibConstants") {
00163     edm::ESHandle<EcalIntercalibConstants> handle;
00164     evtSetup.get<EcalIntercalibConstantsRcd>().get(handle);
00165     const EcalIntercalibConstants* obj = handle.product();
00166     cout << "inter pointer is: "<< obj<< endl;
00167    dbOutput->createNewIOV<const EcalIntercalibConstants>( new EcalIntercalibConstants(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00168 
00169   } else if (container == "EcalIntercalibErrors") {
00170     edm::ESHandle<EcalIntercalibErrors> handle;
00171     evtSetup.get<EcalIntercalibErrorsRcd>().get(handle);
00172     const EcalIntercalibErrors* obj = handle.product();
00173     cout << "inter pointer is: "<< obj<< endl;
00174    dbOutput->createNewIOV<const EcalIntercalibErrors>( new EcalIntercalibErrors(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00175 
00176   } else if (container == "EcalGainRatios") {
00177     edm::ESHandle<EcalGainRatios> handle;
00178     evtSetup.get<EcalGainRatiosRcd>().get(handle);
00179     const EcalGainRatios* obj = handle.product();
00180     cout << "gain pointer is: "<< obj<< endl;
00181    dbOutput->createNewIOV<const EcalGainRatios>( new EcalGainRatios(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00182 
00183   } else if (container == "EcalWeightXtalGroups") {
00184     edm::ESHandle<EcalWeightXtalGroups> handle;
00185     evtSetup.get<EcalWeightXtalGroupsRcd>().get(handle);
00186     const EcalWeightXtalGroups* obj = handle.product();
00187     cout << "weight pointer is: "<< obj<< endl;
00188    dbOutput->createNewIOV<const EcalWeightXtalGroups>( new EcalWeightXtalGroups(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00189 
00190   } else if (container == "EcalTBWeights") {
00191     edm::ESHandle<EcalTBWeights> handle;
00192     evtSetup.get<EcalTBWeightsRcd>().get(handle);
00193     const EcalTBWeights* obj = handle.product();
00194     cout << "tbweight pointer is: "<< obj<< endl;
00195    dbOutput->createNewIOV<const EcalTBWeights>( new EcalTBWeights(*obj), dbOutput->beginOfTime(),dbOutput->endOfTime(),recordName);
00196 
00197   } else if (container == "EcalLaserAlphas") {
00198     edm::ESHandle<EcalLaserAlphas> handle;
00199     evtSetup.get<EcalLaserAlphasRcd>().get(handle);
00200     const EcalLaserAlphas* obj = handle.product();
00201     cout << "ecalLaserAlpha pointer is: "<< obj<< endl;
00202    dbOutput->createNewIOV<const EcalLaserAlphas>( new EcalLaserAlphas(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00203 
00204   } else if (container == "EcalLaserAPDPNRatios") {
00205     edm::ESHandle<EcalLaserAPDPNRatios> handle;
00206     evtSetup.get<EcalLaserAPDPNRatiosRcd>().get(handle);
00207     const EcalLaserAPDPNRatios* obj = handle.product();
00208     cout << "tbweight pointer is: "<< obj<< endl;
00209    dbOutput->createNewIOV<const EcalLaserAPDPNRatios>( new EcalLaserAPDPNRatios(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00210 
00211   } else if (container == "EcalLaserAPDPNRatiosRef") {
00212     edm::ESHandle<EcalLaserAPDPNRatiosRef> handle;
00213     evtSetup.get<EcalLaserAPDPNRatiosRefRcd>().get(handle);
00214     const EcalLaserAPDPNRatiosRef* obj = handle.product();
00215     cout << "tbweight pointer is: "<< obj<< endl;
00216    dbOutput->createNewIOV<const EcalLaserAPDPNRatiosRef>( new EcalLaserAPDPNRatiosRef(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00217 
00218   } else {
00219     throw cms::Exception("Unknown container");
00220   }
00221 
00222   cout<< "EcalDBCopy wrote " << recordName << endl;
00223 }

Generated on Tue Jun 9 17:26:52 2009 for CMSSW by  doxygen 1.5.4