Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-18 02:24:40

0001 #include <map>
0002 #include <memory>
0003 #include <iostream>
0004 #include <fstream>
0005 #include <string>
0006 
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 #include "FWCore/Framework/interface/ESProducer.h"
0009 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0010 #include "FWCore/ParameterSet/interface/FileInPath.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 #include "FWCore/Framework/interface/ValidityInterval.h"
0014 
0015 #include "CalibCalorimetry/CastorCalib/interface/CastorDbASCIIIO.h"
0016 
0017 #include "CondFormats/CastorObjects/interface/CastorPedestals.h"
0018 #include "CondFormats/CastorObjects/interface/CastorPedestalWidths.h"
0019 #include "CondFormats/CastorObjects/interface/CastorGains.h"
0020 #include "CondFormats/CastorObjects/interface/CastorGainWidths.h"
0021 #include "CondFormats/CastorObjects/interface/CastorElectronicsMap.h"
0022 #include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
0023 #include "CondFormats/CastorObjects/interface/CastorQIEData.h"
0024 
0025 #include "CondFormats/DataRecord/interface/CastorPedestalsRcd.h"
0026 #include "CondFormats/DataRecord/interface/CastorPedestalWidthsRcd.h"
0027 #include "CondFormats/DataRecord/interface/CastorGainsRcd.h"
0028 #include "CondFormats/DataRecord/interface/CastorGainWidthsRcd.h"
0029 #include "CondFormats/DataRecord/interface/CastorElectronicsMapRcd.h"
0030 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
0031 #include "CondFormats/DataRecord/interface/CastorQIEDataRcd.h"
0032 #include "CondFormats/DataRecord/interface/CastorRecoParamsRcd.h"
0033 #include "CondFormats/DataRecord/interface/CastorSaturationCorrsRcd.h"
0034 
0035 class CastorTextCalibrations : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0036 public:
0037   CastorTextCalibrations(const edm::ParameterSet&);
0038   ~CastorTextCalibrations() override;
0039 
0040   void produce(){};
0041 
0042 protected:
0043   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0044                       const edm::IOVSyncValue&,
0045                       edm::ValidityInterval&) override;
0046 
0047   std::unique_ptr<CastorPedestals> producePedestals(const CastorPedestalsRcd& rcd);
0048   std::unique_ptr<CastorPedestalWidths> producePedestalWidths(const CastorPedestalWidthsRcd& rcd);
0049   std::unique_ptr<CastorGains> produceGains(const CastorGainsRcd& rcd);
0050   std::unique_ptr<CastorGainWidths> produceGainWidths(const CastorGainWidthsRcd& rcd);
0051   std::unique_ptr<CastorQIEData> produceQIEData(const CastorQIEDataRcd& rcd);
0052   std::unique_ptr<CastorChannelQuality> produceChannelQuality(const CastorChannelQualityRcd& rcd);
0053   std::unique_ptr<CastorElectronicsMap> produceElectronicsMap(const CastorElectronicsMapRcd& rcd);
0054   std::unique_ptr<CastorRecoParams> produceRecoParams(const CastorRecoParamsRcd& rcd);
0055   std::unique_ptr<CastorSaturationCorrs> produceSaturationCorrs(const CastorSaturationCorrsRcd& rcd);
0056 
0057 private:
0058   std::map<std::string, std::string> mInputs;
0059 };
0060 //
0061 // class decleration
0062 //
0063 
0064 using namespace cms;
0065 
0066 CastorTextCalibrations::CastorTextCalibrations(const edm::ParameterSet& iConfig)
0067 
0068 {
0069   //parsing parameters
0070   std::vector<edm::ParameterSet> data = iConfig.getParameter<std::vector<edm::ParameterSet> >("input");
0071   std::vector<edm::ParameterSet>::iterator request = data.begin();
0072   for (; request != data.end(); ++request) {
0073     std::string objectName = request->getParameter<std::string>("object");
0074     edm::FileInPath fp = request->getParameter<edm::FileInPath>("file");
0075     mInputs[objectName] = fp.fullPath();
0076     if (objectName == "Pedestals") {
0077       setWhatProduced(this, &CastorTextCalibrations::producePedestals);
0078       findingRecord<CastorPedestalsRcd>();
0079     } else if (objectName == "PedestalWidths") {
0080       setWhatProduced(this, &CastorTextCalibrations::producePedestalWidths);
0081       findingRecord<CastorPedestalWidthsRcd>();
0082     } else if (objectName == "Gains") {
0083       setWhatProduced(this, &CastorTextCalibrations::produceGains);
0084       findingRecord<CastorGainsRcd>();
0085     } else if (objectName == "GainWidths") {
0086       setWhatProduced(this, &CastorTextCalibrations::produceGainWidths);
0087       findingRecord<CastorGainWidthsRcd>();
0088     } else if (objectName == "QIEData") {
0089       setWhatProduced(this, &CastorTextCalibrations::produceQIEData);
0090       findingRecord<CastorQIEDataRcd>();
0091     } else if (objectName == "ChannelQuality") {
0092       setWhatProduced(this, &CastorTextCalibrations::produceChannelQuality);
0093       findingRecord<CastorChannelQualityRcd>();
0094     } else if (objectName == "ElectronicsMap") {
0095       setWhatProduced(this, &CastorTextCalibrations::produceElectronicsMap);
0096       findingRecord<CastorElectronicsMapRcd>();
0097     } else if (objectName == "RecoParams") {
0098       setWhatProduced(this, &CastorTextCalibrations::produceRecoParams);
0099       findingRecord<CastorRecoParamsRcd>();
0100     } else if (objectName == "SaturationCorrs") {
0101       setWhatProduced(this, &CastorTextCalibrations::produceSaturationCorrs);
0102       findingRecord<CastorSaturationCorrsRcd>();
0103     } else {
0104       std::cerr << "CastorTextCalibrations-> Unknown object name '" << objectName << "', known names are: "
0105                 << "Pedestals PedestalWidths Gains GainWidths QIEData ChannelQuality ElectronicsMap RecoParams "
0106                    "SaturationCorrs"
0107                 << std::endl;
0108     }
0109   }
0110   //  setWhatProduced(this);
0111 }
0112 
0113 CastorTextCalibrations::~CastorTextCalibrations() {}
0114 
0115 //
0116 // member functions
0117 //
0118 void CastorTextCalibrations::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& iKey,
0119                                             const edm::IOVSyncValue& iTime,
0120                                             edm::ValidityInterval& oInterval) {
0121   std::string record = iKey.name();
0122   oInterval = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());  //infinite
0123 }
0124 
0125 template <class T>
0126 std::unique_ptr<T> produce_impl(const std::string& fFile) {
0127   std::unique_ptr<T> result(new T());
0128   std::ifstream inStream(fFile.c_str());
0129   if (!inStream.good()) {
0130     std::cerr << "CastorTextCalibrations-> Unable to open file '" << fFile << "'" << std::endl;
0131     throw cms::Exception("FileNotFound") << "Unable to open '" << fFile << "'" << std::endl;
0132   }
0133   if (!CastorDbASCIIIO::getObject(inStream, *result)) {
0134     std::cerr << "CastorTextCalibrations-> Can not read object from file '" << fFile << "'" << std::endl;
0135     throw cms::Exception("ReadError") << "Can not read object from file '" << fFile << "'" << std::endl;
0136   }
0137   return result;
0138 }
0139 
0140 std::unique_ptr<CastorPedestals> CastorTextCalibrations::producePedestals(const CastorPedestalsRcd&) {
0141   return produce_impl<CastorPedestals>(mInputs["Pedestals"]);
0142 }
0143 
0144 std::unique_ptr<CastorPedestalWidths> CastorTextCalibrations::producePedestalWidths(const CastorPedestalWidthsRcd&) {
0145   return produce_impl<CastorPedestalWidths>(mInputs["PedestalWidths"]);
0146 }
0147 
0148 std::unique_ptr<CastorGains> CastorTextCalibrations::produceGains(const CastorGainsRcd&) {
0149   return produce_impl<CastorGains>(mInputs["Gains"]);
0150 }
0151 
0152 std::unique_ptr<CastorGainWidths> CastorTextCalibrations::produceGainWidths(const CastorGainWidthsRcd&) {
0153   return produce_impl<CastorGainWidths>(mInputs["GainWidths"]);
0154 }
0155 
0156 std::unique_ptr<CastorQIEData> CastorTextCalibrations::produceQIEData(const CastorQIEDataRcd& rcd) {
0157   return produce_impl<CastorQIEData>(mInputs["QIEData"]);
0158 }
0159 
0160 std::unique_ptr<CastorChannelQuality> CastorTextCalibrations::produceChannelQuality(const CastorChannelQualityRcd& rcd) {
0161   return produce_impl<CastorChannelQuality>(mInputs["ChannelQuality"]);
0162 }
0163 
0164 std::unique_ptr<CastorElectronicsMap> CastorTextCalibrations::produceElectronicsMap(const CastorElectronicsMapRcd& rcd) {
0165   return produce_impl<CastorElectronicsMap>(mInputs["ElectronicsMap"]);
0166 }
0167 
0168 std::unique_ptr<CastorRecoParams> CastorTextCalibrations::produceRecoParams(const CastorRecoParamsRcd& rcd) {
0169   return produce_impl<CastorRecoParams>(mInputs["RecoParams"]);
0170 }
0171 
0172 std::unique_ptr<CastorSaturationCorrs> CastorTextCalibrations::produceSaturationCorrs(
0173     const CastorSaturationCorrsRcd& rcd) {
0174   return produce_impl<CastorSaturationCorrs>(mInputs["SaturationCorrs"]);
0175 }
0176 
0177 #include "FWCore/PluginManager/interface/ModuleDef.h"
0178 #include "FWCore/Framework/interface/SourceFactory.h"
0179 
0180 DEFINE_FWK_EVENTSETUP_SOURCE(CastorTextCalibrations);