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