CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CalibCalorimetry/EcalTPGTools/plugins/EcalTPGDBCopy.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 "CondFormats/EcalObjects/interface/EcalTPGPedestals.h" 
00012 #include "CondFormats/EcalObjects/interface/EcalTPGLinearizationConst.h" 
00013 #include "CondFormats/EcalObjects/interface/EcalTPGSlidingWindow.h" 
00014 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBIdMap.h" 
00015 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainStripEE.h" 
00016 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainTowerEE.h" 
00017 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h" 
00018 #include "CondFormats/EcalObjects/interface/EcalTPGWeightIdMap.h" 
00019 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h" 
00020 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h" 
00021 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBGroup.h" 
00022 #include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h" 
00023 #include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h" 
00024 #include "CondFormats/EcalObjects/interface/EcalTPGSpike.h" 
00025 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h" 
00026 #include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h" 
00027 
00028 #include "CondFormats/DataRecord/interface/EcalTPGPedestalsRcd.h" 
00029 #include "CondFormats/DataRecord/interface/EcalTPGLinearizationConstRcd.h" 
00030 #include "CondFormats/DataRecord/interface/EcalTPGSlidingWindowRcd.h" 
00031 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBIdMapRcd.h" 
00032 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainStripEERcd.h" 
00033 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainTowerEERcd.h" 
00034 #include "CondFormats/DataRecord/interface/EcalTPGLutIdMapRcd.h" 
00035 #include "CondFormats/DataRecord/interface/EcalTPGWeightIdMapRcd.h" 
00036 #include "CondFormats/DataRecord/interface/EcalTPGWeightGroupRcd.h" 
00037 #include "CondFormats/DataRecord/interface/EcalTPGLutGroupRcd.h" 
00038 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBGroupRcd.h" 
00039 #include "CondFormats/DataRecord/interface/EcalTPGPhysicsConstRcd.h" 
00040 #include "CondFormats/DataRecord/interface/EcalTPGCrystalStatusRcd.h" 
00041 #include "CondFormats/DataRecord/interface/EcalTPGTowerStatusRcd.h" 
00042 #include "CondFormats/DataRecord/interface/EcalTPGSpikeRcd.h" 
00043 #include "CondFormats/DataRecord/interface/EcalTPGStripStatusRcd.h" 
00044 
00045 #include "EcalTPGDBCopy.h"
00046 
00047 #include <vector>
00048 
00049 
00050 
00051 EcalTPGDBCopy::EcalTPGDBCopy(const edm::ParameterSet& iConfig) :
00052   m_timetype(iConfig.getParameter<std::string>("timetype")),
00053   m_cacheIDs(),
00054   m_records()
00055 {
00056 
00057   std::string container;
00058   std::string tag;
00059   std::string record;
00060   typedef std::vector< edm::ParameterSet > Parameters;
00061   Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
00062   for(Parameters::iterator i = toCopy.begin(); i != toCopy.end(); ++i) {
00063     container = i->getParameter<std::string>("container");
00064     record = i->getParameter<std::string>("record");
00065     m_cacheIDs.insert( std::make_pair(container, 0) );
00066     m_records.insert( std::make_pair(container, record) );
00067   }
00068   
00069 }
00070 
00071 
00072 EcalTPGDBCopy::~EcalTPGDBCopy()
00073 {
00074   
00075 }
00076 
00077 void EcalTPGDBCopy::analyze( const edm::Event& evt, const edm::EventSetup& evtSetup)
00078 {
00079   std::string container;
00080   std::string record;
00081   typedef std::map<std::string, std::string>::const_iterator recordIter;
00082   for (recordIter i = m_records.begin(); i != m_records.end(); ++i) {
00083     container = (*i).first;
00084     record = (*i).second;
00085     if ( shouldCopy(evtSetup, container) ) {
00086       copyToDB(evtSetup, container);
00087     }
00088   }
00089   
00090 }
00091 
00092 
00093 
00094 bool EcalTPGDBCopy::shouldCopy(const edm::EventSetup& evtSetup, std::string container)
00095 {
00096 
00097   unsigned long long cacheID = 0;
00098 
00099   if (container == "EcalTPGPedestals") {
00100     cacheID = evtSetup.get<EcalTPGPedestalsRcd>().cacheIdentifier();
00101   } else if (container == "EcalTPGLinearizationConst") {
00102     cacheID = evtSetup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
00103   } else if (container == "EcalTPGSlidingWindow") {
00104     cacheID = evtSetup.get<EcalTPGSlidingWindowRcd>().cacheIdentifier();
00105   } else if (container == "EcalTPGFineGrainEBIdMap") {
00106     cacheID = evtSetup.get<EcalTPGFineGrainEBIdMapRcd>().cacheIdentifier();
00107   } else if (container == "EcalTPGFineGrainStripEE") {
00108     cacheID = evtSetup.get<EcalTPGFineGrainStripEERcd>().cacheIdentifier();
00109   } else if (container == "EcalTPGFineGrainTowerEE") {
00110     cacheID = evtSetup.get<EcalTPGFineGrainTowerEERcd>().cacheIdentifier();
00111   } else if (container == "EcalTPGLutIdMap") {
00112     cacheID = evtSetup.get<EcalTPGLutIdMapRcd>().cacheIdentifier();
00113   } else if (container == "EcalTPGWeightIdMap") {
00114     cacheID = evtSetup.get<EcalTPGWeightIdMapRcd>().cacheIdentifier();
00115   } else if (container == "EcalTPGWeightGroup") {
00116     cacheID = evtSetup.get<EcalTPGWeightGroupRcd>().cacheIdentifier();
00117   } else if (container == "EcalTPGLutGroup") {
00118     cacheID = evtSetup.get<EcalTPGLutGroupRcd>().cacheIdentifier();
00119   } else if (container == "EcalTPGFineGrainEBGroup") {
00120     cacheID = evtSetup.get<EcalTPGFineGrainEBGroupRcd>().cacheIdentifier();
00121   } else if (container == "EcalTPGPhysicsConst") {
00122     cacheID = evtSetup.get<EcalTPGPhysicsConstRcd>().cacheIdentifier();
00123   } else if (container == "EcalTPGCrystalStatus") {
00124     cacheID = evtSetup.get<EcalTPGCrystalStatusRcd>().cacheIdentifier();
00125   } else if (container == "EcalTPGTowerStatus") {
00126     cacheID = evtSetup.get<EcalTPGTowerStatusRcd>().cacheIdentifier();
00127   } else if (container == "EcalTPGSpike") {
00128     cacheID = evtSetup.get<EcalTPGSpikeRcd>().cacheIdentifier();
00129   } else if (container == "EcalTPGStripStatus") {
00130     cacheID = evtSetup.get<EcalTPGStripStatusRcd>().cacheIdentifier();
00131   }
00132   else {
00133     throw cms::Exception("Unknown container");
00134   }
00135   
00136   if (m_cacheIDs[container] == cacheID) {
00137     return 0;
00138   } else {
00139     m_cacheIDs[container] = cacheID;
00140     return 1;
00141   }
00142 
00143 }
00144 
00145 
00146 
00147 void EcalTPGDBCopy::copyToDB(const edm::EventSetup& evtSetup, std::string container)
00148 { 
00149 
00150   edm::Service<cond::service::PoolDBOutputService> dbOutput;
00151   if ( !dbOutput.isAvailable() ) {
00152     throw cms::Exception("PoolDBOutputService is not available");
00153   }
00154   
00155   
00156   std::string recordName = m_records[container];
00157   
00158 
00159   if (container == "EcalTPGPedestals") {
00160     edm::ESHandle<EcalTPGPedestals> handle;
00161     evtSetup.get<EcalTPGPedestalsRcd>().get(handle);
00162     const EcalTPGPedestals* obj = handle.product();
00163     dbOutput->createNewIOV<const EcalTPGPedestals>( new EcalTPGPedestals(*obj), dbOutput->beginOfTime(),dbOutput->endOfTime(),recordName);
00164     
00165   } else if (container == "EcalTPGLinearizationConst") {
00166     edm::ESHandle<EcalTPGLinearizationConst> handle;
00167     evtSetup.get<EcalTPGLinearizationConstRcd>().get(handle);
00168     const EcalTPGLinearizationConst* obj = handle.product();
00169 
00170     dbOutput->createNewIOV<const EcalTPGLinearizationConst>( new EcalTPGLinearizationConst(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00171 
00172   } else if (container == "EcalTPGSlidingWindow") {
00173     edm::ESHandle<EcalTPGSlidingWindow> handle;
00174     evtSetup.get<EcalTPGSlidingWindowRcd>().get(handle);
00175     const EcalTPGSlidingWindow* obj = handle.product();
00176 
00177     dbOutput->createNewIOV<const EcalTPGSlidingWindow>( new EcalTPGSlidingWindow(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00178 
00179   } else if (container == "EcalTPGFineGrainEBIdMap") {
00180     edm::ESHandle<EcalTPGFineGrainEBIdMap> handle;
00181     evtSetup.get<EcalTPGFineGrainEBIdMapRcd>().get(handle);
00182     const EcalTPGFineGrainEBIdMap* obj = handle.product();
00183     dbOutput->createNewIOV<const EcalTPGFineGrainEBIdMap>( new EcalTPGFineGrainEBIdMap(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00184 
00185   } else if (container == "EcalTPGFineGrainStripEE") {
00186     edm::ESHandle<EcalTPGFineGrainStripEE> handle;
00187     evtSetup.get<EcalTPGFineGrainStripEERcd>().get(handle);
00188     const EcalTPGFineGrainStripEE* obj = handle.product();
00189     dbOutput->createNewIOV<const EcalTPGFineGrainStripEE>( new EcalTPGFineGrainStripEE(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00190     
00191   } else if (container == "EcalTPGFineGrainTowerEE") {
00192     edm::ESHandle<EcalTPGFineGrainTowerEE> handle;
00193     evtSetup.get<EcalTPGFineGrainTowerEERcd>().get(handle);
00194     const EcalTPGFineGrainTowerEE* obj = handle.product();
00195     dbOutput->createNewIOV<const EcalTPGFineGrainTowerEE>( new EcalTPGFineGrainTowerEE(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00196 
00197   } else if (container == "EcalTPGLutIdMap") {
00198     edm::ESHandle<EcalTPGLutIdMap> handle;
00199     evtSetup.get<EcalTPGLutIdMapRcd>().get(handle);
00200     const EcalTPGLutIdMap* obj = handle.product();
00201     dbOutput->createNewIOV<const EcalTPGLutIdMap>( new EcalTPGLutIdMap(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00202 
00203   } else if (container == "EcalTPGWeightIdMap") {
00204     edm::ESHandle<EcalTPGWeightIdMap> handle;
00205     evtSetup.get<EcalTPGWeightIdMapRcd>().get(handle);
00206     const EcalTPGWeightIdMap* obj = handle.product();
00207     dbOutput->createNewIOV<const EcalTPGWeightIdMap>( new EcalTPGWeightIdMap(*obj), dbOutput->beginOfTime(),dbOutput->endOfTime(),recordName);
00208 
00209   } else if (container == "EcalTPGWeightGroup") {
00210     edm::ESHandle<EcalTPGWeightGroup> handle;
00211     evtSetup.get<EcalTPGWeightGroupRcd>().get(handle);
00212     const EcalTPGWeightGroup* obj = handle.product();
00213     dbOutput->createNewIOV<const EcalTPGWeightGroup>( new EcalTPGWeightGroup(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00214 
00215   } else if (container == "EcalTPGLutGroup") {
00216     edm::ESHandle<EcalTPGLutGroup> handle;
00217     evtSetup.get<EcalTPGLutGroupRcd>().get(handle);
00218     const EcalTPGLutGroup* obj = handle.product();
00219     dbOutput->createNewIOV<const EcalTPGLutGroup>( new EcalTPGLutGroup(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00220 
00221   } else if (container == "EcalTPGFineGrainEBGroup") {
00222   
00223     edm::ESHandle<EcalTPGFineGrainEBGroup> handle;
00224     evtSetup.get<EcalTPGFineGrainEBGroupRcd>().get(handle);
00225     
00226     const EcalTPGFineGrainEBGroup* obj = handle.product();
00227     
00228     dbOutput->createNewIOV<const EcalTPGFineGrainEBGroup>( new EcalTPGFineGrainEBGroup(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00229     
00230   } else if (container == "EcalTPGPhysicsConst") {
00231     edm::ESHandle<EcalTPGPhysicsConst> handle;
00232     evtSetup.get<EcalTPGPhysicsConstRcd>().get(handle);
00233     const EcalTPGPhysicsConst* obj = handle.product();
00234     dbOutput->createNewIOV<const EcalTPGPhysicsConst>( new EcalTPGPhysicsConst(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00235     
00236   } else if (container == "EcalTPGCrystalStatus") {
00237     edm::ESHandle<EcalTPGCrystalStatus> handle;
00238     evtSetup.get<EcalTPGCrystalStatusRcd>().get(handle);
00239     const EcalTPGCrystalStatus* obj = handle.product();
00240     dbOutput->createNewIOV<const EcalTPGCrystalStatus>( new EcalTPGCrystalStatus(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00241 
00242   } else if (container == "EcalTPGTowerStatus") {
00243     edm::ESHandle<EcalTPGTowerStatus> handle;
00244     evtSetup.get<EcalTPGTowerStatusRcd>().get(handle);
00245     const EcalTPGTowerStatus* obj = handle.product();
00246     dbOutput->createNewIOV<const EcalTPGTowerStatus>( new EcalTPGTowerStatus(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00247 
00248   } else if (container == "EcalTPGSpike") {
00249 
00250     edm::ESHandle<EcalTPGSpike> handle;
00251     evtSetup.get<EcalTPGSpikeRcd>().get(handle);
00252     const EcalTPGSpike* obj = handle.product();
00253     
00254     dbOutput->createNewIOV<const EcalTPGSpike>( new EcalTPGSpike(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00255     
00256   } else if (container == "EcalTPGStripStatus") {
00257      
00258     edm::ESHandle<EcalTPGStripStatus> handle;
00259     evtSetup.get<EcalTPGStripStatusRcd>().get(handle);
00260     const EcalTPGStripStatus* obj = handle.product();
00261     dbOutput->createNewIOV<const EcalTPGStripStatus>( new EcalTPGStripStatus(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
00262     
00263   } 
00264   
00265   else {
00266     throw cms::Exception("Unknown container");
00267   }
00268 
00269   std::cout<< "EcalTPGDBCopy wrote " << recordName << std::endl;
00270 }