File indexing completed on 2024-09-07 04:34:44
0001
0002
0003
0004
0005
0006
0007
0008 #include <iostream>
0009 #include <memory>
0010 #include <map>
0011 #include <string>
0012
0013 #include "FWCore/Framework/interface/ValidityInterval.h"
0014 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
0015 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0016 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0017 #include "CalibCalorimetry/CastorCalib/interface/CastorDbHardcode.h"
0018
0019 #include "CondFormats/DataRecord/interface/CastorPedestalsRcd.h"
0020 #include "CondFormats/DataRecord/interface/CastorPedestalWidthsRcd.h"
0021 #include "CondFormats/DataRecord/interface/CastorGainsRcd.h"
0022 #include "CondFormats/DataRecord/interface/CastorGainWidthsRcd.h"
0023 #include "CondFormats/DataRecord/interface/CastorElectronicsMapRcd.h"
0024 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
0025 #include "CondFormats/DataRecord/interface/CastorQIEDataRcd.h"
0026 #include "CondFormats/DataRecord/interface/CastorRecoParamsRcd.h"
0027 #include "CondFormats/DataRecord/interface/CastorSaturationCorrsRcd.h"
0028
0029 #include "Geometry/ForwardGeometry/interface/CastorTopology.h"
0030 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032
0033 #include "FWCore/Framework/interface/ESProducer.h"
0034 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0035 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0036
0037 #include "CondFormats/CastorObjects/interface/AllObjects.h"
0038
0039 class CastorHardcodeCalibrations : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0040 public:
0041 CastorHardcodeCalibrations(const edm::ParameterSet&);
0042 ~CastorHardcodeCalibrations() override;
0043
0044 void produce() {}
0045
0046 protected:
0047 void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0048 const edm::IOVSyncValue&,
0049 edm::ValidityInterval&) override;
0050
0051 std::unique_ptr<CastorPedestals> producePedestals(const CastorPedestalsRcd& rcd);
0052 std::unique_ptr<CastorPedestalWidths> producePedestalWidths(const CastorPedestalWidthsRcd& rcd);
0053 std::unique_ptr<CastorGains> produceGains(const CastorGainsRcd& rcd);
0054 std::unique_ptr<CastorGainWidths> produceGainWidths(const CastorGainWidthsRcd& rcd);
0055 std::unique_ptr<CastorQIEData> produceQIEData(const CastorQIEDataRcd& rcd);
0056 std::unique_ptr<CastorChannelQuality> produceChannelQuality(const CastorChannelQualityRcd& rcd);
0057 std::unique_ptr<CastorElectronicsMap> produceElectronicsMap(const CastorElectronicsMapRcd& rcd);
0058 std::unique_ptr<CastorRecoParams> produceRecoParams(const CastorRecoParamsRcd& rcd);
0059 std::unique_ptr<CastorSaturationCorrs> produceSaturationCorrs(const CastorSaturationCorrsRcd& rcd);
0060 bool h2mode_;
0061 };
0062
0063
0064
0065
0066 using namespace cms;
0067
0068 namespace {
0069
0070 std::vector<HcalGenericDetId> allCells(bool h2_mode) {
0071 static std::vector<HcalGenericDetId> result;
0072 if (result.empty()) {
0073 CastorTopology castortopology;
0074 HcalCastorDetId cell;
0075 HcalCastorDetId::Section section = HcalCastorDetId::EM;
0076
0077 for (int sector = 1; sector < 17; sector++) {
0078 for (int module = 1; module < 3; module++) {
0079 cell = HcalCastorDetId(section, true, sector, module);
0080 if (castortopology.valid(cell))
0081 result.push_back(cell);
0082 cell = HcalCastorDetId(section, false, sector, module);
0083 if (castortopology.valid(cell))
0084 result.push_back(cell);
0085 }
0086 }
0087
0088 section = HcalCastorDetId::HAD;
0089 for (int sector = 1; sector < 17; sector++) {
0090 for (int module = 3; module < 15; module++) {
0091 cell = HcalCastorDetId(section, true, sector, module);
0092 if (castortopology.valid(cell))
0093 result.push_back(cell);
0094 cell = HcalCastorDetId(section, false, sector, module);
0095 if (castortopology.valid(cell))
0096 result.push_back(cell);
0097 }
0098 }
0099 }
0100 return result;
0101 }
0102 }
0103
0104 CastorHardcodeCalibrations::CastorHardcodeCalibrations(const edm::ParameterSet& iConfig)
0105
0106 {
0107 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::CastorHardcodeCalibrations->...";
0108
0109 h2mode_ = iConfig.getUntrackedParameter<bool>("H2Mode", false);
0110 std::vector<std::string> toGet = iConfig.getUntrackedParameter<std::vector<std::string> >("toGet");
0111 for (std::vector<std::string>::iterator objectName = toGet.begin(); objectName != toGet.end(); ++objectName) {
0112 bool all = *objectName == "all";
0113 if ((*objectName == "Pedestals") || all) {
0114 setWhatProduced(this, &CastorHardcodeCalibrations::producePedestals);
0115 findingRecord<CastorPedestalsRcd>();
0116 }
0117 if ((*objectName == "PedestalWidths") || all) {
0118 setWhatProduced(this, &CastorHardcodeCalibrations::producePedestalWidths);
0119 findingRecord<CastorPedestalWidthsRcd>();
0120 }
0121 if ((*objectName == "Gains") || all) {
0122 setWhatProduced(this, &CastorHardcodeCalibrations::produceGains);
0123 findingRecord<CastorGainsRcd>();
0124 }
0125 if ((*objectName == "GainWidths") || all) {
0126 setWhatProduced(this, &CastorHardcodeCalibrations::produceGainWidths);
0127 findingRecord<CastorGainWidthsRcd>();
0128 }
0129 if ((*objectName == "QIEData") || all) {
0130 setWhatProduced(this, &CastorHardcodeCalibrations::produceQIEData);
0131 findingRecord<CastorQIEDataRcd>();
0132 }
0133 if ((*objectName == "ChannelQuality") || (*objectName == "channelQuality") || all) {
0134 setWhatProduced(this, &CastorHardcodeCalibrations::produceChannelQuality);
0135 findingRecord<CastorChannelQualityRcd>();
0136 }
0137 if ((*objectName == "ElectronicsMap") || (*objectName == "electronicsMap") || all) {
0138 setWhatProduced(this, &CastorHardcodeCalibrations::produceElectronicsMap);
0139 findingRecord<CastorElectronicsMapRcd>();
0140 }
0141 if ((*objectName == "RecoParams") || all) {
0142 setWhatProduced(this, &CastorHardcodeCalibrations::produceRecoParams);
0143 findingRecord<CastorRecoParamsRcd>();
0144 }
0145 if ((*objectName == "SaturationCorrs") || all) {
0146 setWhatProduced(this, &CastorHardcodeCalibrations::produceSaturationCorrs);
0147 findingRecord<CastorSaturationCorrsRcd>();
0148 }
0149 }
0150 }
0151
0152 CastorHardcodeCalibrations::~CastorHardcodeCalibrations() {}
0153
0154
0155
0156
0157 void CastorHardcodeCalibrations::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& iKey,
0158 const edm::IOVSyncValue& iTime,
0159 edm::ValidityInterval& oInterval) {
0160 std::string record = iKey.name();
0161 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::setIntervalFor-> key: " << record << " time: " << iTime.eventID()
0162 << '/' << iTime.time().value();
0163 oInterval = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0164 }
0165
0166 std::unique_ptr<CastorPedestals> CastorHardcodeCalibrations::producePedestals(const CastorPedestalsRcd&) {
0167 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::producePedestals-> ...";
0168 auto result = std::make_unique<CastorPedestals>(false);
0169 std::vector<HcalGenericDetId> cells = allCells(h2mode_);
0170 for (std::vector<HcalGenericDetId>::const_iterator cell = cells.begin(); cell != cells.end(); ++cell) {
0171 CastorPedestal item = CastorDbHardcode::makePedestal(*cell);
0172 result->addValues(item);
0173 }
0174 return result;
0175 }
0176
0177 std::unique_ptr<CastorPedestalWidths> CastorHardcodeCalibrations::producePedestalWidths(const CastorPedestalWidthsRcd&) {
0178 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::producePedestalWidths-> ...";
0179 auto result = std::make_unique<CastorPedestalWidths>(false);
0180 std::vector<HcalGenericDetId> cells = allCells(h2mode_);
0181 for (std::vector<HcalGenericDetId>::const_iterator cell = cells.begin(); cell != cells.end(); ++cell) {
0182 CastorPedestalWidth item = CastorDbHardcode::makePedestalWidth(*cell);
0183 result->addValues(item);
0184 }
0185 return result;
0186 }
0187
0188 std::unique_ptr<CastorGains> CastorHardcodeCalibrations::produceGains(const CastorGainsRcd&) {
0189 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceGains-> ...";
0190 auto result = std::make_unique<CastorGains>();
0191 std::vector<HcalGenericDetId> cells = allCells(h2mode_);
0192 for (std::vector<HcalGenericDetId>::const_iterator cell = cells.begin(); cell != cells.end(); ++cell) {
0193 CastorGain item = CastorDbHardcode::makeGain(*cell);
0194 result->addValues(item);
0195 }
0196 return result;
0197 }
0198
0199 std::unique_ptr<CastorGainWidths> CastorHardcodeCalibrations::produceGainWidths(const CastorGainWidthsRcd&) {
0200 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceGainWidths-> ...";
0201 auto result = std::make_unique<CastorGainWidths>();
0202 std::vector<HcalGenericDetId> cells = allCells(h2mode_);
0203 for (std::vector<HcalGenericDetId>::const_iterator cell = cells.begin(); cell != cells.end(); ++cell) {
0204 CastorGainWidth item = CastorDbHardcode::makeGainWidth(*cell);
0205 result->addValues(item);
0206 }
0207 return result;
0208 }
0209
0210 std::unique_ptr<CastorQIEData> CastorHardcodeCalibrations::produceQIEData(const CastorQIEDataRcd& rcd) {
0211 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceQIEData-> ...";
0212 auto result = std::make_unique<CastorQIEData>();
0213 std::vector<HcalGenericDetId> cells = allCells(h2mode_);
0214 for (std::vector<HcalGenericDetId>::const_iterator cell = cells.begin(); cell != cells.end(); ++cell) {
0215 CastorQIECoder coder = CastorDbHardcode::makeQIECoder(*cell);
0216 result->addCoder(coder);
0217 }
0218 return result;
0219 }
0220
0221 std::unique_ptr<CastorChannelQuality> CastorHardcodeCalibrations::produceChannelQuality(
0222 const CastorChannelQualityRcd& rcd) {
0223 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceChannelQuality-> ...";
0224 auto result = std::make_unique<CastorChannelQuality>();
0225 std::vector<HcalGenericDetId> cells = allCells(h2mode_);
0226 for (std::vector<HcalGenericDetId>::const_iterator cell = cells.begin(); cell != cells.end(); ++cell) {
0227 CastorChannelStatus item(cell->rawId(), CastorChannelStatus::GOOD);
0228 result->addValues(item);
0229 }
0230 return result;
0231 }
0232
0233 std::unique_ptr<CastorElectronicsMap> CastorHardcodeCalibrations::produceElectronicsMap(
0234 const CastorElectronicsMapRcd& rcd) {
0235 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceElectronicsMap-> ...";
0236
0237 auto result = std::make_unique<CastorElectronicsMap>();
0238 CastorDbHardcode::makeHardcodeMap(*result);
0239 return result;
0240 }
0241
0242 std::unique_ptr<CastorRecoParams> CastorHardcodeCalibrations::produceRecoParams(const CastorRecoParamsRcd& rcd) {
0243 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceRecoParams-> ...";
0244 auto result = std::make_unique<CastorRecoParams>();
0245 std::vector<HcalGenericDetId> cells = allCells(h2mode_);
0246 for (std::vector<HcalGenericDetId>::const_iterator cell = cells.begin(); cell != cells.end(); ++cell) {
0247 CastorRecoParam item = CastorDbHardcode::makeRecoParam(*cell);
0248 result->addValues(item);
0249 }
0250 return result;
0251 }
0252
0253 std::unique_ptr<CastorSaturationCorrs> CastorHardcodeCalibrations::produceSaturationCorrs(
0254 const CastorSaturationCorrsRcd& rcd) {
0255 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceSaturationCorrs-> ...";
0256 auto result = std::make_unique<CastorSaturationCorrs>();
0257 std::vector<HcalGenericDetId> cells = allCells(h2mode_);
0258 for (std::vector<HcalGenericDetId>::const_iterator cell = cells.begin(); cell != cells.end(); ++cell) {
0259 CastorSaturationCorr item = CastorDbHardcode::makeSaturationCorr(*cell);
0260 result->addValues(item);
0261 }
0262 return result;
0263 }
0264
0265 #include "FWCore/PluginManager/interface/ModuleDef.h"
0266 #include "FWCore/Framework/interface/SourceFactory.h"
0267
0268 DEFINE_FWK_EVENTSETUP_SOURCE(CastorHardcodeCalibrations);