Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 ----------------------------------------------------------------------*/
0010 
0011 #include <stdexcept>
0012 #include <string>
0013 #include <iostream>
0014 #include <fstream>
0015 #include <sstream>
0016 #include <map>
0017 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 
0024 #include "CondFormats/DataRecord/interface/HcalPedestalsRcd.h"
0025 #include "CondFormats/DataRecord/interface/HcalQIEDataRcd.h"
0026 #include "CondFormats/DataRecord/interface/HcalQIETypesRcd.h"
0027 #include "CondFormats/DataRecord/interface/HcalPedestalWidthsRcd.h"
0028 #include "CondFormats/DataRecord/interface/HcalGainsRcd.h"
0029 #include "CondFormats/DataRecord/interface/HcalElectronicsMapRcd.h"
0030 #include "CondFormats/DataRecord/interface/HcalGainWidthsRcd.h"
0031 #include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h"
0032 #include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
0033 #include "CondFormats/DataRecord/interface/HcalZSThresholdsRcd.h"
0034 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
0035 
0036 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0037 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0038 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0039 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0040 
0041 #include "FWCore/Framework/interface/IOVSyncValue.h"
0042 
0043 namespace edmtest {
0044   class HcalConditionsTest : public edm::one::EDAnalyzer<> {
0045   public:
0046     explicit HcalConditionsTest(edm::ParameterSet const& p) {
0047       front = p.getUntrackedParameter<std::string>("outFilePrefix", "Dump");
0048       tok_ = esConsumes<HcalDbService, HcalDbRecord>();
0049       tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0050     }
0051 
0052     explicit HcalConditionsTest(int i) {
0053       tok_ = esConsumes<HcalDbService, HcalDbRecord>();
0054       tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0055     }
0056     virtual ~HcalConditionsTest() {}
0057     virtual void analyze(const edm::Event& e, const edm::EventSetup& c);
0058 
0059     template <class S, class SRcd>
0060     void dumpIt(S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name);
0061 
0062   private:
0063     std::string front;
0064     edm::ESGetToken<HcalDbService, HcalDbRecord> tok_;
0065     edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0066   };
0067 
0068   template <class S, class SRcd>
0069   void HcalConditionsTest::dumpIt(
0070       S* myS, SRcd* mySRcd, const edm::Event& e, const edm::EventSetup& context, std::string name) {
0071     edm::ESGetToken<S, SRcd> tok = esConsumes<S, SRcd>();
0072     int myrun = e.id().run();
0073     const S* myobject = &context.getData(tok);
0074 
0075     std::ostringstream file;
0076     file << front << name.c_str() << "_Run" << myrun << ".txt";
0077     std::ofstream outStream(file.str().c_str());
0078     std::cout << "HcalConditionsTest: ---- Dumping " << name.c_str() << " ----" << std::endl;
0079     HcalDbASCIIIO::dumpObject(outStream, (*myobject));
0080 
0081     if (context.get<HcalPedestalsRcd>().validityInterval().first() == edm::IOVSyncValue::invalidIOVSyncValue())
0082       std::cout << "error: invalid IOV sync value !" << std::endl;
0083   }
0084 
0085   void HcalConditionsTest::analyze(const edm::Event& e, const edm::EventSetup& context) {
0086     using namespace edm::eventsetup;
0087     std::cout << "HcalConditionsTest::analyze-> I AM IN RUN NUMBER " << e.id().run() << std::endl;
0088     const HcalTopology* topo = &context.getData(tok_htopo_);
0089 
0090     dumpIt(new HcalElectronicsMap, new HcalElectronicsMapRcd, e, context, "ElectronicsMap");
0091     dumpIt(new HcalQIEData, new HcalQIEDataRcd, e, context, "QIEData");
0092     dumpIt(new HcalQIETypes, new HcalQIETypesRcd, e, context, "QIETypes");
0093     dumpIt(new HcalPedestals(topo, false), new HcalPedestalsRcd, e, context, "Pedestals");
0094     dumpIt(new HcalPedestalWidths(topo, false), new HcalPedestalWidthsRcd, e, context, "PedestalWidths");
0095     dumpIt(new HcalGains, new HcalGainsRcd, e, context, "Gains");
0096     dumpIt(new HcalGainWidths, new HcalGainWidthsRcd, e, context, "GainWidths");
0097     dumpIt(new HcalRespCorrs, new HcalRespCorrsRcd, e, context, "RespCorrs");
0098     dumpIt(new HcalChannelQuality, new HcalChannelQualityRcd, e, context, "ChannelQuality");
0099     dumpIt(new HcalZSThresholds, new HcalZSThresholdsRcd, e, context, "ZSThresholds");
0100 
0101     // get conditions
0102     const auto& conditions = &context.getData(tok_);
0103     int cell = HcalDetId(HcalBarrel, -1, 4, 1).rawId();
0104     const HcalCalibrations& calibrations = conditions->getHcalCalibrations(cell);
0105     std::cout << HcalDetId(cell) << " RespCorr " << calibrations.respcorr() << " TimeCorr " << calibrations.timecorr()
0106               << std::endl;
0107   }
0108 
0109   DEFINE_FWK_MODULE(HcalConditionsTest);
0110 }  // namespace edmtest