Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-31 23:51:03

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 R.Ofierzynski - 2.Oct. 2007
0005    modified to dump all pedestals on screen, see 
0006    testHcalDBFake.cfg
0007    testHcalDBFrontier.cfg
0008 
0009 July 29, 2009       Added HcalValidationCorrs - Gena Kukartsev
0010 September 21, 2009  Added HcalLutMetadata - Gena Kukartsev
0011    
0012 ----------------------------------------------------------------------*/
0013 
0014 #include <stdexcept>
0015 #include <string>
0016 #include <iostream>
0017 #include <fstream>
0018 #include <sstream>
0019 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 
0026 #include "CondFormats/DataRecord/interface/HcalAllRcds.h"
0027 
0028 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
0029 
0030 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0031 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0032 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0033 
0034 #include "FWCore/Framework/interface/IOVSyncValue.h"
0035 #include "CondFormats/HcalObjects/interface/AllObjects.h"
0036 
0037 namespace edmtest {
0038   class HcalDumpConditions : public edm::one::EDAnalyzer<> {
0039   public:
0040     explicit HcalDumpConditions(edm::ParameterSet const& p) {
0041       front = p.getUntrackedParameter<std::string>("outFilePrefix", "Dump");
0042       mDumpRequest = p.getUntrackedParameter<std::vector<std::string> >("dump", std::vector<std::string>());
0043       m_toktopo = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0044       m_tokdb = esConsumes<HcalDbService, HcalDbRecord>();
0045 
0046       tok_ElectronicsMap = esConsumes<HcalElectronicsMap, HcalElectronicsMapRcd>();
0047       tok_FrontEndMap = esConsumes<HcalFrontEndMap, HcalFrontEndMapRcd>();
0048       tok_QIEData = esConsumes<HcalQIEData, HcalQIEDataRcd>();
0049       tok_QIETypes = esConsumes<HcalQIETypes, HcalQIETypesRcd>();
0050       tok_Pedestals = esConsumes<HcalPedestals, HcalPedestalsRcd>();
0051       tok_PedestalWidths = esConsumes<HcalPedestalWidths, HcalPedestalWidthsRcd>();
0052       tok_Pedestals_effective = esConsumes<HcalPedestals, HcalPedestalsRcd>(edm::ESInputTag("", "effective"));
0053       tok_PedestalWidths_effective =
0054           esConsumes<HcalPedestalWidths, HcalPedestalWidthsRcd>(edm::ESInputTag("", "effective"));
0055       tok_Gains = esConsumes<HcalGains, HcalGainsRcd>();
0056       tok_GainWidths = esConsumes<HcalGainWidths, HcalGainWidthsRcd>();
0057       tok_ChannelQuality = esConsumes<HcalChannelQuality, HcalChannelQualityRcd>();
0058       tok_RespCorrs = esConsumes<HcalRespCorrs, HcalRespCorrsRcd>();
0059       tok_ZSThresholds = esConsumes<HcalZSThresholds, HcalZSThresholdsRcd>();
0060       tok_L1TriggerObjects = esConsumes<HcalL1TriggerObjects, HcalL1TriggerObjectsRcd>();
0061       tok_TimeCorrs = esConsumes<HcalTimeCorrs, HcalTimeCorrsRcd>();
0062       tok_LUTCorrs = esConsumes<HcalLUTCorrs, HcalLUTCorrsRcd>();
0063       tok_PFCorrs = esConsumes<HcalPFCorrs, HcalPFCorrsRcd>();
0064       tok_ValidationCorrs = esConsumes<HcalValidationCorrs, HcalValidationCorrsRcd>();
0065       tok_LutMetadata = esConsumes<HcalLutMetadata, HcalLutMetadataRcd>();
0066       tok_DcsValues = esConsumes<HcalDcsValues, HcalDcsRcd>();
0067       tok_DcsMap = esConsumes<HcalDcsMap, HcalDcsMapRcd>();
0068       tok_RecoParams = esConsumes<HcalRecoParams, HcalRecoParamsRcd>();
0069       tok_TimingParams = esConsumes<HcalTimingParams, HcalTimingParamsRcd>();
0070       tok_LongRecoParams = esConsumes<HcalLongRecoParams, HcalLongRecoParamsRcd>();
0071       tok_ZDCLowGainFractions = esConsumes<HcalZDCLowGainFractions, HcalZDCLowGainFractionsRcd>();
0072       tok_MCParams = esConsumes<HcalMCParams, HcalMCParamsRcd>();
0073       tok_FlagHFDigiTimeParams = esConsumes<HcalFlagHFDigiTimeParams, HcalFlagHFDigiTimeParamsRcd>();
0074       tok_SiPMParameters = esConsumes<HcalSiPMParameters, HcalSiPMParametersRcd>();
0075       tok_SiPMCharacteristics = esConsumes<HcalSiPMCharacteristics, HcalSiPMCharacteristicsRcd>();
0076       tok_TPChannelParameters = esConsumes<HcalTPChannelParameters, HcalTPChannelParametersRcd>();
0077       tok_TPParameters = esConsumes<HcalTPParameters, HcalTPParametersRcd>();
0078     }
0079 
0080     explicit HcalDumpConditions(int i) {}
0081     ~HcalDumpConditions() override {}
0082     void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0083 
0084     template <class S, class SRcd>
0085     void dumpIt(const std::vector<std::string>& mDumpRequest,
0086                 const edm::Event& e,
0087                 const edm::EventSetup& context,
0088                 const std::string name,
0089                 const edm::ESGetToken<S, SRcd> tok);
0090     template <class S, class SRcd>
0091     void dumpIt(const std::vector<std::string>& mDumpRequest,
0092                 const edm::Event& e,
0093                 const edm::EventSetup& context,
0094                 const std::string name,
0095                 const HcalTopology* topo,
0096                 const edm::ESGetToken<S, SRcd> tok);
0097     template <class S>
0098     void writeToFile(const S& myS, const edm::Event& e, const std::string name);
0099 
0100   private:
0101     std::string front;
0102     std::vector<std::string> mDumpRequest;
0103     edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> m_toktopo;
0104     edm::ESGetToken<HcalDbService, HcalDbRecord> m_tokdb;
0105     edm::ESGetToken<HcalElectronicsMap, HcalElectronicsMapRcd> tok_ElectronicsMap;
0106     edm::ESGetToken<HcalFrontEndMap, HcalFrontEndMapRcd> tok_FrontEndMap;
0107     edm::ESGetToken<HcalQIEData, HcalQIEDataRcd> tok_QIEData;
0108     edm::ESGetToken<HcalQIETypes, HcalQIETypesRcd> tok_QIETypes;
0109     edm::ESGetToken<HcalPedestals, HcalPedestalsRcd> tok_Pedestals;
0110     edm::ESGetToken<HcalPedestalWidths, HcalPedestalWidthsRcd> tok_PedestalWidths;
0111     edm::ESGetToken<HcalPedestals, HcalPedestalsRcd> tok_Pedestals_effective;
0112     edm::ESGetToken<HcalPedestalWidths, HcalPedestalWidthsRcd> tok_PedestalWidths_effective;
0113     edm::ESGetToken<HcalGains, HcalGainsRcd> tok_Gains;
0114     edm::ESGetToken<HcalGainWidths, HcalGainWidthsRcd> tok_GainWidths;
0115     edm::ESGetToken<HcalChannelQuality, HcalChannelQualityRcd> tok_ChannelQuality;
0116     edm::ESGetToken<HcalRespCorrs, HcalRespCorrsRcd> tok_RespCorrs;
0117     edm::ESGetToken<HcalZSThresholds, HcalZSThresholdsRcd> tok_ZSThresholds;
0118     edm::ESGetToken<HcalL1TriggerObjects, HcalL1TriggerObjectsRcd> tok_L1TriggerObjects;
0119     edm::ESGetToken<HcalTimeCorrs, HcalTimeCorrsRcd> tok_TimeCorrs;
0120     edm::ESGetToken<HcalLUTCorrs, HcalLUTCorrsRcd> tok_LUTCorrs;
0121     edm::ESGetToken<HcalPFCorrs, HcalPFCorrsRcd> tok_PFCorrs;
0122     edm::ESGetToken<HcalValidationCorrs, HcalValidationCorrsRcd> tok_ValidationCorrs;
0123     edm::ESGetToken<HcalLutMetadata, HcalLutMetadataRcd> tok_LutMetadata;
0124     edm::ESGetToken<HcalDcsValues, HcalDcsRcd> tok_DcsValues;
0125     edm::ESGetToken<HcalDcsMap, HcalDcsMapRcd> tok_DcsMap;
0126     edm::ESGetToken<HcalRecoParams, HcalRecoParamsRcd> tok_RecoParams;
0127     edm::ESGetToken<HcalTimingParams, HcalTimingParamsRcd> tok_TimingParams;
0128     edm::ESGetToken<HcalLongRecoParams, HcalLongRecoParamsRcd> tok_LongRecoParams;
0129     edm::ESGetToken<HcalZDCLowGainFractions, HcalZDCLowGainFractionsRcd> tok_ZDCLowGainFractions;
0130     edm::ESGetToken<HcalMCParams, HcalMCParamsRcd> tok_MCParams;
0131     edm::ESGetToken<HcalFlagHFDigiTimeParams, HcalFlagHFDigiTimeParamsRcd> tok_FlagHFDigiTimeParams;
0132     edm::ESGetToken<HcalSiPMParameters, HcalSiPMParametersRcd> tok_SiPMParameters;
0133     edm::ESGetToken<HcalSiPMCharacteristics, HcalSiPMCharacteristicsRcd> tok_SiPMCharacteristics;
0134     edm::ESGetToken<HcalTPChannelParameters, HcalTPChannelParametersRcd> tok_TPChannelParameters;
0135     edm::ESGetToken<HcalTPParameters, HcalTPParametersRcd> tok_TPParameters;
0136   };
0137 
0138   template <class S, class SRcd>
0139   void HcalDumpConditions::dumpIt(const std::vector<std::string>& mDumpRequest,
0140                                   const edm::Event& e,
0141                                   const edm::EventSetup& context,
0142                                   const std::string name,
0143                                   const edm::ESGetToken<S, SRcd> tok) {
0144     if (std::find(mDumpRequest.begin(), mDumpRequest.end(), name) != mDumpRequest.end()) {
0145       const S& myobject = context.getData(tok);
0146 
0147       writeToFile(myobject, e, name);
0148 
0149       if (context.get<SRcd>().validityInterval().first() == edm::IOVSyncValue::invalidIOVSyncValue())
0150         std::cout << "error: invalid IOV sync value !" << std::endl;
0151     }
0152   }
0153 
0154   template <class S, class SRcd>
0155   void HcalDumpConditions::dumpIt(const std::vector<std::string>& mDumpRequest,
0156                                   const edm::Event& e,
0157                                   const edm::EventSetup& context,
0158                                   const std::string name,
0159                                   const HcalTopology* topo,
0160                                   const edm::ESGetToken<S, SRcd> tok) {
0161     if (std::find(mDumpRequest.begin(), mDumpRequest.end(), name) != mDumpRequest.end()) {
0162       S myobject = context.getData(tok);
0163       if (topo)
0164         myobject.setTopo(topo);
0165 
0166       writeToFile(myobject, e, name);
0167 
0168       if (context.get<SRcd>().validityInterval().first() == edm::IOVSyncValue::invalidIOVSyncValue())
0169         std::cout << "error: invalid IOV sync value !" << std::endl;
0170     }
0171   }
0172 
0173   template <class S>
0174   void HcalDumpConditions::writeToFile(const S& myS, const edm::Event& e, const std::string name) {
0175     int myrun = e.id().run();
0176     std::ostringstream file;
0177     file << front << name.c_str() << "_Run" << myrun << ".txt";
0178     std::ofstream outStream(file.str().c_str());
0179     std::cout << "HcalDumpConditions: ---- Dumping " << name << " ----" << std::endl;
0180     HcalDbASCIIIO::dumpObject(outStream, myS);
0181   }
0182 
0183   void HcalDumpConditions::analyze(const edm::Event& e, const edm::EventSetup& context) {
0184     const HcalTopology* topo = &context.getData(m_toktopo);
0185 
0186     using namespace edm::eventsetup;
0187     std::cout << "HcalDumpConditions::analyze-> I AM IN RUN NUMBER " << e.id().run() << std::endl;
0188 
0189     if (mDumpRequest.empty())
0190       return;
0191 
0192     // dumpIt called for all possible ValueMaps. The function checks if the dump is actually requested.
0193 
0194     dumpIt<HcalElectronicsMap, HcalElectronicsMapRcd>(mDumpRequest, e, context, "ElectronicsMap", tok_ElectronicsMap);
0195     dumpIt<HcalFrontEndMap, HcalFrontEndMapRcd>(mDumpRequest, e, context, "FrontEndMap", tok_FrontEndMap);
0196     dumpIt<HcalQIEData, HcalQIEDataRcd>(mDumpRequest, e, context, "QIEData", topo, tok_QIEData);
0197     dumpIt<HcalQIETypes, HcalQIETypesRcd>(mDumpRequest, e, context, "QIETypes", topo, tok_QIETypes);
0198     dumpIt<HcalPedestals, HcalPedestalsRcd>(mDumpRequest, e, context, "Pedestals", topo, tok_Pedestals);
0199     dumpIt<HcalPedestalWidths, HcalPedestalWidthsRcd>(
0200         mDumpRequest, e, context, "PedestalWidths", topo, tok_PedestalWidths);
0201     dumpIt<HcalPedestals, HcalPedestalsRcd>(
0202         mDumpRequest, e, context, "EffectivePedestals", topo, tok_Pedestals_effective);
0203     dumpIt<HcalPedestalWidths, HcalPedestalWidthsRcd>(
0204         mDumpRequest, e, context, "EffectivePedestalWidths", topo, tok_PedestalWidths_effective);
0205     dumpIt<HcalGains, HcalGainsRcd>(mDumpRequest, e, context, "Gains", topo, tok_Gains);
0206     dumpIt<HcalGainWidths, HcalGainWidthsRcd>(mDumpRequest, e, context, "GainWidths", topo, tok_GainWidths);
0207     dumpIt<HcalChannelQuality, HcalChannelQualityRcd>(
0208         mDumpRequest, e, context, "ChannelQuality", topo, tok_ChannelQuality);
0209     dumpIt<HcalRespCorrs, HcalRespCorrsRcd>(mDumpRequest, e, context, "RespCorrs", topo, tok_RespCorrs);
0210     dumpIt<HcalZSThresholds, HcalZSThresholdsRcd>(mDumpRequest, e, context, "ZSThresholds", topo, tok_ZSThresholds);
0211     dumpIt<HcalL1TriggerObjects, HcalL1TriggerObjectsRcd>(
0212         mDumpRequest, e, context, "L1TriggerObjects", topo, tok_L1TriggerObjects);
0213     dumpIt<HcalTimeCorrs, HcalTimeCorrsRcd>(mDumpRequest, e, context, "TimeCorrs", topo, tok_TimeCorrs);
0214     dumpIt<HcalLUTCorrs, HcalLUTCorrsRcd>(mDumpRequest, e, context, "LUTCorrs", topo, tok_LUTCorrs);
0215     dumpIt<HcalPFCorrs, HcalPFCorrsRcd>(mDumpRequest, e, context, "PFCorrs", topo, tok_PFCorrs);
0216     dumpIt<HcalValidationCorrs, HcalValidationCorrsRcd>(
0217         mDumpRequest, e, context, "ValidationCorrs", topo, tok_ValidationCorrs);
0218     dumpIt<HcalLutMetadata, HcalLutMetadataRcd>(mDumpRequest, e, context, "LutMetadata", topo, tok_LutMetadata);
0219     dumpIt<HcalDcsValues, HcalDcsRcd>(mDumpRequest, e, context, "DcsValues", tok_DcsValues);
0220     dumpIt<HcalDcsMap, HcalDcsMapRcd>(mDumpRequest, e, context, "DcsMap", tok_DcsMap);
0221     dumpIt<HcalRecoParams, HcalRecoParamsRcd>(mDumpRequest, e, context, "RecoParams", topo, tok_RecoParams);
0222     dumpIt<HcalTimingParams, HcalTimingParamsRcd>(mDumpRequest, e, context, "TimingParams", topo, tok_TimingParams);
0223     dumpIt<HcalLongRecoParams, HcalLongRecoParamsRcd>(
0224         mDumpRequest, e, context, "LongRecoParams", topo, tok_LongRecoParams);
0225     dumpIt<HcalZDCLowGainFractions, HcalZDCLowGainFractionsRcd>(
0226         mDumpRequest, e, context, "ZDCLowGainFractions", topo, tok_ZDCLowGainFractions);
0227     dumpIt<HcalMCParams, HcalMCParamsRcd>(mDumpRequest, e, context, "MCParams", topo, tok_MCParams);
0228     dumpIt<HcalFlagHFDigiTimeParams, HcalFlagHFDigiTimeParamsRcd>(
0229         mDumpRequest, e, context, "FlagHFDigiTimeParams", topo, tok_FlagHFDigiTimeParams);
0230     dumpIt<HcalSiPMParameters, HcalSiPMParametersRcd>(
0231         mDumpRequest, e, context, "SiPMParameters", topo, tok_SiPMParameters);
0232     dumpIt<HcalSiPMCharacteristics, HcalSiPMCharacteristicsRcd>(
0233         mDumpRequest, e, context, "SiPMCharacteristics", tok_SiPMCharacteristics);
0234     dumpIt<HcalTPChannelParameters, HcalTPChannelParametersRcd>(
0235         mDumpRequest, e, context, "TPChannelParameters", topo, tok_TPChannelParameters);
0236     dumpIt<HcalTPParameters, HcalTPParametersRcd>(mDumpRequest, e, context, "TPParameters", tok_TPParameters);
0237   }
0238   DEFINE_FWK_MODULE(HcalDumpConditions);
0239 }  // namespace edmtest