Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-30 23:16:42

0001 // -*- C++ -*-
0002 // Original Author:  Fedor Ratnikov
0003 //
0004 //
0005 
0006 #include <memory>
0007 #include <iostream>
0008 #include <fstream>
0009 
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 #include "FWCore/ParameterSet/interface/FileInPath.h"
0012 
0013 #include "FWCore/Framework/interface/ValidityInterval.h"
0014 
0015 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0016 
0017 #include "CondFormats/DataRecord/interface/HcalAllRcds.h"
0018 
0019 #include "HcalTextCalibrations.h"
0020 //
0021 // class declaration
0022 //
0023 
0024 using namespace cms;
0025 
0026 HcalTextCalibrations::HcalTextCalibrations(const edm::ParameterSet& iConfig)
0027 
0028 {
0029   //parsing parameters
0030   std::vector<edm::ParameterSet> data = iConfig.getParameter<std::vector<edm::ParameterSet> >("input");
0031   std::vector<edm::ParameterSet>::iterator request = data.begin();
0032   for (; request != data.end(); ++request) {
0033     std::string objectName = request->getParameter<std::string>("object");
0034     edm::FileInPath fp = request->getParameter<edm::FileInPath>("file");
0035     mInputs[objectName] = fp.fullPath();
0036     //   std::cout << objectName << " with file " << fp.fullPath() << std::endl;
0037     if (objectName == "Pedestals") {
0038       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::producePedestals).consumes();
0039       findingRecord<HcalPedestalsRcd>();
0040     } else if (objectName == "PedestalWidths") {
0041       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::producePedestalWidths).consumes();
0042       findingRecord<HcalPedestalWidthsRcd>();
0043     } else if (objectName == "EffectivePedestals") {
0044       mTokens[objectName] =
0045           setWhatProduced(this, &HcalTextCalibrations::produceEffectivePedestals, edm::es::Label("effective"))
0046               .consumes();
0047       findingRecord<HcalPedestalsRcd>();
0048     } else if (objectName == "EffectivePedestalWidths") {
0049       mTokens[objectName] =
0050           setWhatProduced(this, &HcalTextCalibrations::produceEffectivePedestalWidths, edm::es::Label("effective"))
0051               .consumes();
0052       findingRecord<HcalPedestalWidthsRcd>();
0053     } else if (objectName == "Gains") {
0054       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceGains).consumes();
0055       findingRecord<HcalGainsRcd>();
0056     } else if (objectName == "GainWidths") {
0057       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceGainWidths).consumes();
0058       findingRecord<HcalGainWidthsRcd>();
0059     } else if (objectName == "QIEData") {
0060       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceQIEData).consumes();
0061       findingRecord<HcalQIEDataRcd>();
0062     } else if (objectName == "QIETypes") {
0063       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceQIETypes).consumes();
0064       findingRecord<HcalQIETypesRcd>();
0065     } else if (objectName == "ChannelQuality") {
0066       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceChannelQuality).consumes();
0067       findingRecord<HcalChannelQualityRcd>();
0068     } else if (objectName == "ZSThresholds") {
0069       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceZSThresholds).consumes();
0070       findingRecord<HcalZSThresholdsRcd>();
0071     } else if (objectName == "RespCorrs") {
0072       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceRespCorrs).consumes();
0073       findingRecord<HcalRespCorrsRcd>();
0074     } else if (objectName == "LUTCorrs") {
0075       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceLUTCorrs).consumes();
0076       findingRecord<HcalLUTCorrsRcd>();
0077     } else if (objectName == "PFCorrs") {
0078       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::producePFCorrs).consumes();
0079       findingRecord<HcalPFCorrsRcd>();
0080     } else if (objectName == "TimeCorrs") {
0081       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceTimeCorrs).consumes();
0082       findingRecord<HcalTimeCorrsRcd>();
0083     } else if (objectName == "L1TriggerObjects") {
0084       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceL1TriggerObjects).consumes();
0085       findingRecord<HcalL1TriggerObjectsRcd>();
0086     } else if (objectName == "ElectronicsMap") {
0087       setWhatProduced(this, &HcalTextCalibrations::produceElectronicsMap);
0088       findingRecord<HcalElectronicsMapRcd>();
0089     } else if (objectName == "FrontEndMap") {
0090       setWhatProduced(this, &HcalTextCalibrations::produceFrontEndMap);
0091       findingRecord<HcalFrontEndMapRcd>();
0092     } else if (objectName == "ValidationCorrs") {
0093       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceValidationCorrs).consumes();
0094       findingRecord<HcalValidationCorrsRcd>();
0095     } else if (objectName == "LutMetadata") {
0096       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceLutMetadata).consumes();
0097       findingRecord<HcalLutMetadataRcd>();
0098     } else if (objectName == "DcsValues") {
0099       setWhatProduced(this, &HcalTextCalibrations::produceDcsValues);
0100       findingRecord<HcalDcsRcd>();
0101     } else if (objectName == "DcsMap") {
0102       setWhatProduced(this, &HcalTextCalibrations::produceDcsMap);
0103       findingRecord<HcalDcsMapRcd>();
0104     } else if (objectName == "RecoParams") {
0105       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceRecoParams).consumes();
0106       findingRecord<HcalRecoParamsRcd>();
0107     } else if (objectName == "TimingParams") {
0108       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceTimingParams).consumes();
0109       findingRecord<HcalTimingParamsRcd>();
0110     } else if (objectName == "LongRecoParams") {
0111       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceLongRecoParams).consumes();
0112       findingRecord<HcalLongRecoParamsRcd>();
0113     } else if (objectName == "ZDCLowGainFractions") {
0114       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceZDCLowGainFractions).consumes();
0115       findingRecord<HcalZDCLowGainFractionsRcd>();
0116     } else if (objectName == "MCParams") {
0117       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceMCParams).consumes();
0118       findingRecord<HcalMCParamsRcd>();
0119     } else if (objectName == "FlagHFDigiTimeParams") {
0120       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceFlagHFDigiTimeParams).consumes();
0121       findingRecord<HcalFlagHFDigiTimeParamsRcd>();
0122     } else if (objectName == "SiPMParameters") {
0123       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceSiPMParameters).consumes();
0124       findingRecord<HcalSiPMParametersRcd>();
0125     } else if (objectName == "SiPMCharacteristics") {
0126       setWhatProduced(this, &HcalTextCalibrations::produceSiPMCharacteristics);
0127       findingRecord<HcalSiPMCharacteristicsRcd>();
0128     } else if (objectName == "TPChannelParameters") {
0129       mTokens[objectName] = setWhatProduced(this, &HcalTextCalibrations::produceTPChannelParameters).consumes();
0130       findingRecord<HcalTPChannelParametersRcd>();
0131     } else if (objectName == "TPParameters") {
0132       setWhatProduced(this, &HcalTextCalibrations::produceTPParameters);
0133       findingRecord<HcalTPParametersRcd>();
0134     } else {
0135       std::cerr << "HcalTextCalibrations-> Unknown object name '" << objectName << "', known names are: "
0136                 << "Pedestals PedestalWidths Gains GainWidths QIEData QIETypes ChannelQuality ElectronicsMap "
0137                 << "FrontEndMap ZSThresholds RespCorrs LUTCorrs PFCorrs TimeCorrs L1TriggerObjects "
0138                 << "ValidationCorrs LutMetadata DcsValues DcsMap "
0139                 << "RecoParams LongRecoParams ZDCLowGainFraction FlagHFDigiTimeParams MCParams "
0140                 << "SiPMParameters SiPMCharacteristics TPChannelParameters TPParameters" << std::endl;
0141     }
0142   }
0143   //  setWhatProduced(this);
0144 }
0145 
0146 HcalTextCalibrations::~HcalTextCalibrations() {}
0147 
0148 //
0149 // member functions
0150 //
0151 void HcalTextCalibrations::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& iKey,
0152                                           const edm::IOVSyncValue& iTime,
0153                                           edm::ValidityInterval& oInterval) {
0154   std::string record = iKey.name();
0155   oInterval = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());  //infinite
0156 }
0157 namespace {
0158   template <class T, template <class> class F>
0159   std::unique_ptr<T> produce_impl(const std::string& fFile, const HcalTopology* topo = nullptr) {
0160     std::ifstream inStream(fFile.c_str());
0161     if (!inStream.good()) {
0162       std::cerr << "HcalTextCalibrations-> Unable to open file '" << fFile << "'" << std::endl;
0163       throw cms::Exception("FileNotFound") << "Unable to open '" << fFile << "'" << std::endl;
0164     }
0165     auto result = F<T>(topo)(inStream);
0166     if (!result) {
0167       std::cerr << "HcalTextCalibrations-> Can not read object from file '" << fFile << "'" << std::endl;
0168       throw cms::Exception("ReadError") << "Can not read object from file '" << fFile << "'" << std::endl;
0169     }
0170     return result;
0171   }
0172   template <class T>
0173   std::unique_ptr<T> get_impl(const std::string& fFile) {
0174     return produce_impl<T, HcalTextCalibrations::CheckGetObject>(fFile);
0175   }
0176   template <class T>
0177   std::unique_ptr<T> get_impl_topo(const std::string& fFile, const HcalTopology* topo) {
0178     return produce_impl<T, HcalTextCalibrations::CheckGetObjectTopo>(fFile, topo);
0179   }
0180   template <class T>
0181   std::unique_ptr<T> create_impl(const std::string& fFile) {
0182     return produce_impl<T, HcalTextCalibrations::CheckCreateObject>(fFile);
0183   }
0184 }  // namespace
0185 
0186 std::unique_ptr<HcalPedestals> HcalTextCalibrations::producePedestals(const HcalPedestalsRcd& rcd) {
0187   std::string const n = "Pedestals";
0188   return get_impl_topo<HcalPedestals>(mInputs[n], &rcd.get(mTokens[n]));
0189 }
0190 
0191 std::unique_ptr<HcalPedestalWidths> HcalTextCalibrations::producePedestalWidths(const HcalPedestalWidthsRcd& rcd) {
0192   std::string const n = "PedestalWidths";
0193   return get_impl_topo<HcalPedestalWidths>(mInputs[n], &rcd.get(mTokens[n]));
0194 }
0195 
0196 std::unique_ptr<HcalPedestals> HcalTextCalibrations::produceEffectivePedestals(const HcalPedestalsRcd& rcd) {
0197   std::string const n = "EffectivePedestals";
0198   return get_impl_topo<HcalPedestals>(mInputs[n], &rcd.get(mTokens[n]));
0199 }
0200 
0201 std::unique_ptr<HcalPedestalWidths> HcalTextCalibrations::produceEffectivePedestalWidths(
0202     const HcalPedestalWidthsRcd& rcd) {
0203   std::string const n = "EffectivePedestalWidths";
0204   return get_impl_topo<HcalPedestalWidths>(mInputs[n], &rcd.get(mTokens[n]));
0205 }
0206 
0207 std::unique_ptr<HcalGains> HcalTextCalibrations::produceGains(const HcalGainsRcd& rcd) {
0208   std::string const n = "Gains";
0209   return get_impl_topo<HcalGains>(mInputs[n], &rcd.get(mTokens[n]));
0210 }
0211 
0212 std::unique_ptr<HcalGainWidths> HcalTextCalibrations::produceGainWidths(const HcalGainWidthsRcd& rcd) {
0213   std::string const n = "GainWidths";
0214   return get_impl_topo<HcalGainWidths>(mInputs[n], &rcd.get(mTokens[n]));
0215 }
0216 
0217 std::unique_ptr<HcalQIEData> HcalTextCalibrations::produceQIEData(const HcalQIEDataRcd& rcd) {
0218   std::string const n = "QIEData";
0219   return get_impl_topo<HcalQIEData>(mInputs[n], &rcd.get(mTokens[n]));
0220 }
0221 
0222 std::unique_ptr<HcalQIETypes> HcalTextCalibrations::produceQIETypes(const HcalQIETypesRcd& rcd) {
0223   std::string const n = "QIETypes";
0224   return get_impl_topo<HcalQIETypes>(mInputs[n], &rcd.get(mTokens[n]));
0225 }
0226 
0227 std::unique_ptr<HcalChannelQuality> HcalTextCalibrations::produceChannelQuality(const HcalChannelQualityRcd& rcd) {
0228   std::string const n = "ChannelQuality";
0229   return get_impl_topo<HcalChannelQuality>(mInputs[n], &rcd.get(mTokens[n]));
0230 }
0231 
0232 std::unique_ptr<HcalZSThresholds> HcalTextCalibrations::produceZSThresholds(const HcalZSThresholdsRcd& rcd) {
0233   std::string const n = "ZSThresholds";
0234   return get_impl_topo<HcalZSThresholds>(mInputs[n], &rcd.get(mTokens[n]));
0235 }
0236 
0237 std::unique_ptr<HcalRespCorrs> HcalTextCalibrations::produceRespCorrs(const HcalRespCorrsRcd& rcd) {
0238   std::string const n = "RespCorrs";
0239   return get_impl_topo<HcalRespCorrs>(mInputs[n], &rcd.get(mTokens[n]));
0240 }
0241 
0242 std::unique_ptr<HcalLUTCorrs> HcalTextCalibrations::produceLUTCorrs(const HcalLUTCorrsRcd& rcd) {
0243   std::string const n = "LUTCorrs";
0244   return get_impl_topo<HcalLUTCorrs>(mInputs[n], &rcd.get(mTokens[n]));
0245 }
0246 
0247 std::unique_ptr<HcalPFCorrs> HcalTextCalibrations::producePFCorrs(const HcalPFCorrsRcd& rcd) {
0248   std::string const n = "PFCorrs";
0249   return get_impl_topo<HcalPFCorrs>(mInputs[n], &rcd.get(mTokens[n]));
0250 }
0251 
0252 std::unique_ptr<HcalTimeCorrs> HcalTextCalibrations::produceTimeCorrs(const HcalTimeCorrsRcd& rcd) {
0253   std::string const n = "TimeCorrs";
0254   return get_impl_topo<HcalTimeCorrs>(mInputs[n], &rcd.get(mTokens[n]));
0255 }
0256 
0257 std::unique_ptr<HcalL1TriggerObjects> HcalTextCalibrations::produceL1TriggerObjects(const HcalL1TriggerObjectsRcd& rcd) {
0258   std::string const n = "L1TriggerObjects";
0259   return get_impl_topo<HcalL1TriggerObjects>(mInputs[n], &rcd.get(mTokens[n]));
0260 }
0261 
0262 std::unique_ptr<HcalElectronicsMap> HcalTextCalibrations::produceElectronicsMap(const HcalElectronicsMapRcd& rcd) {
0263   return create_impl<HcalElectronicsMap>(mInputs["ElectronicsMap"]);
0264 }
0265 
0266 std::unique_ptr<HcalFrontEndMap> HcalTextCalibrations::produceFrontEndMap(const HcalFrontEndMapRcd& rcd) {
0267   return create_impl<HcalFrontEndMap>(mInputs["FrontEndMap"]);
0268 }
0269 
0270 std::unique_ptr<HcalValidationCorrs> HcalTextCalibrations::produceValidationCorrs(const HcalValidationCorrsRcd& rcd) {
0271   std::string const n = "ValidationCorrs";
0272   return get_impl_topo<HcalValidationCorrs>(mInputs[n], &rcd.get(mTokens[n]));
0273 }
0274 
0275 std::unique_ptr<HcalLutMetadata> HcalTextCalibrations::produceLutMetadata(const HcalLutMetadataRcd& rcd) {
0276   std::string const n = "LutMetadata";
0277   return get_impl_topo<HcalLutMetadata>(mInputs[n], &rcd.get(mTokens[n]));
0278 }
0279 
0280 std::unique_ptr<HcalDcsValues> HcalTextCalibrations::produceDcsValues(HcalDcsRcd const& rcd) {
0281   return get_impl<HcalDcsValues>(mInputs["DcsValues"]);
0282 }
0283 
0284 std::unique_ptr<HcalDcsMap> HcalTextCalibrations::produceDcsMap(const HcalDcsMapRcd& rcd) {
0285   return create_impl<HcalDcsMap>(mInputs["DcsMap"]);
0286 }
0287 
0288 std::unique_ptr<HcalRecoParams> HcalTextCalibrations::produceRecoParams(const HcalRecoParamsRcd& rcd) {
0289   std::string const n = "RecoParams";
0290   return get_impl_topo<HcalRecoParams>(mInputs[n], &rcd.get(mTokens[n]));
0291 }
0292 
0293 std::unique_ptr<HcalLongRecoParams> HcalTextCalibrations::produceLongRecoParams(const HcalLongRecoParamsRcd& rcd) {
0294   std::string const n = "LongRecoParams";
0295   return get_impl_topo<HcalLongRecoParams>(mInputs[n], &rcd.get(mTokens[n]));
0296 }
0297 
0298 std::unique_ptr<HcalZDCLowGainFractions> HcalTextCalibrations::produceZDCLowGainFractions(
0299     const HcalZDCLowGainFractionsRcd& rcd) {
0300   std::string const n = "ZDCLowGainFractions";
0301   return get_impl_topo<HcalZDCLowGainFractions>(mInputs[n], &rcd.get(mTokens[n]));
0302 }
0303 
0304 std::unique_ptr<HcalTimingParams> HcalTextCalibrations::produceTimingParams(const HcalTimingParamsRcd& rcd) {
0305   std::string const n = "TimingParams";
0306   return get_impl_topo<HcalTimingParams>(mInputs[n], &rcd.get(mTokens[n]));
0307 }
0308 std::unique_ptr<HcalMCParams> HcalTextCalibrations::produceMCParams(const HcalMCParamsRcd& rcd) {
0309   std::string const n = "MCParams";
0310   return get_impl_topo<HcalMCParams>(mInputs[n], &rcd.get(mTokens[n]));
0311 }
0312 
0313 std::unique_ptr<HcalFlagHFDigiTimeParams> HcalTextCalibrations::produceFlagHFDigiTimeParams(
0314     const HcalFlagHFDigiTimeParamsRcd& rcd) {
0315   std::string const n = "FlagHFDigiTimeParams";
0316   return get_impl_topo<HcalFlagHFDigiTimeParams>(mInputs[n], &rcd.get(mTokens[n]));
0317 }
0318 
0319 std::unique_ptr<HcalSiPMParameters> HcalTextCalibrations::produceSiPMParameters(const HcalSiPMParametersRcd& rcd) {
0320   std::string const n = "SiPMParameters";
0321   return get_impl_topo<HcalSiPMParameters>(mInputs[n], &rcd.get(mTokens[n]));
0322 }
0323 
0324 std::unique_ptr<HcalSiPMCharacteristics> HcalTextCalibrations::produceSiPMCharacteristics(
0325     const HcalSiPMCharacteristicsRcd& rcd) {
0326   return create_impl<HcalSiPMCharacteristics>(mInputs["SiPMCharacteristics"]);
0327 }
0328 
0329 std::unique_ptr<HcalTPChannelParameters> HcalTextCalibrations::produceTPChannelParameters(
0330     const HcalTPChannelParametersRcd& rcd) {
0331   std::string const n = "TPChannelParameters";
0332   return get_impl_topo<HcalTPChannelParameters>(mInputs[n], &rcd.get(mTokens[n]));
0333 }
0334 
0335 std::unique_ptr<HcalTPParameters> HcalTextCalibrations::produceTPParameters(const HcalTPParametersRcd& rcd) {
0336   return get_impl<HcalTPParameters>(mInputs["TPParameters"]);
0337 }