Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-27 03:17:26

0001 // -*- C++ -*-
0002 //
0003 // Package:    HcalTPGCoderULUT
0004 // Class:      HcalTPGCoderULUT
0005 //
0006 /**\class HcalTPGCoderULUT HcalTPGCoderULUT.h src/HcalTPGCoderULUT/interface/HcalTPGCoderULUT.h
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jeremiah Mans
0015 //         Created:  Fri Sep 15 11:49:44 CDT 2006
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <string>
0022 
0023 // user include files
0024 
0025 #include "FWCore/Framework/interface/ModuleFactory.h"
0026 #include "FWCore/Framework/interface/ESProducer.h"
0027 #include "FWCore/Framework/interface/ESProductHost.h"
0028 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0029 
0030 #include "CalibCalorimetry/HcalTPGAlgos/interface/HcaluLUTTPGCoder.h"
0031 #include "CalibFormats/HcalObjects/interface/HcalTPGRecord.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0034 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0035 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
0036 
0037 //
0038 // class decleration
0039 //
0040 
0041 class HcalTPGCoderULUT : public edm::ESProducer {
0042 public:
0043   HcalTPGCoderULUT(const edm::ParameterSet&);
0044   ~HcalTPGCoderULUT() override;
0045 
0046   typedef std::shared_ptr<HcalTPGCoder> ReturnType;
0047 
0048   ReturnType produce(const HcalTPGRecord&);
0049 
0050 private:
0051   using HostType = edm::ESProductHost<HcaluLUTTPGCoder, HcalDbRecord>;
0052 
0053   void buildCoder(const HcalTopology*, const HcalElectronicsMap*, const HcalTimeSlew*, HcaluLUTTPGCoder*);
0054 
0055   // ----------member data ---------------------------
0056   edm::ReusableObjectHolder<HostType> holder_;
0057   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> topoToken_;
0058   edm::ESGetToken<HcalTimeSlew, HcalTimeSlewRecord> delayToken_;
0059   edm::ESGetToken<HcalDbService, HcalDbRecord> serviceToken_;
0060   bool read_FGLut_, read_Ascii_, read_XML_, LUTGenerationMode_, linearLUTs_;
0061   bool contain1TSHB_, contain1TSHE_;
0062   double containPhaseNSHB_, containPhaseNSHE_;
0063   bool applyFixPCC_;
0064   bool overrideDBweightsAndFilterHB_, overrideDBweightsAndFilterHE_;
0065   double linearLSB_QIE8_, linearLSB_QIE11Overlap_, linearLSB_QIE11_;
0066   int maskBit_;
0067   std::vector<uint32_t> FG_HF_thresholds_;
0068   edm::FileInPath fgfile_, ifilename_;
0069 };
0070 
0071 //
0072 // constants, enums and typedefs
0073 //
0074 
0075 //
0076 // static data member definitions
0077 //
0078 
0079 //
0080 // constructors and destructor
0081 //
0082 HcalTPGCoderULUT::HcalTPGCoderULUT(const edm::ParameterSet& iConfig) {
0083   read_Ascii_ = iConfig.getParameter<bool>("read_Ascii_LUTs");
0084   read_XML_ = iConfig.getParameter<bool>("read_XML_LUTs");
0085   read_FGLut_ = iConfig.getParameter<bool>("read_FG_LUTs");
0086   fgfile_ = iConfig.getParameter<edm::FileInPath>("FGLUTs");
0087   contain1TSHB_ = iConfig.getParameter<bool>("contain1TSHB");
0088   contain1TSHE_ = iConfig.getParameter<bool>("contain1TSHE");
0089   containPhaseNSHB_ = iConfig.getParameter<double>("containPhaseNSHB");
0090   containPhaseNSHE_ = iConfig.getParameter<double>("containPhaseNSHE");
0091   overrideDBweightsAndFilterHB_ = iConfig.getParameter<bool>("overrideDBweightsAndFilterHB");
0092   overrideDBweightsAndFilterHE_ = iConfig.getParameter<bool>("overrideDBweightsAndFilterHE");
0093   applyFixPCC_ = iConfig.getParameter<bool>("applyFixPCC");
0094 
0095   //the following line is needed to tell the framework what
0096   // data is being produced
0097   auto cc = setWhatProduced(this);
0098   topoToken_ = cc.consumes();
0099   delayToken_ = cc.consumes(edm::ESInputTag{"", "HBHE"});
0100   serviceToken_ = cc.consumes();
0101 
0102   if (!(read_Ascii_ || read_XML_)) {
0103     LUTGenerationMode_ = iConfig.getParameter<bool>("LUTGenerationMode");
0104     linearLUTs_ = iConfig.getParameter<bool>("linearLUTs");
0105     auto scales = iConfig.getParameter<edm::ParameterSet>("tpScales").getParameter<edm::ParameterSet>("HBHE");
0106     linearLSB_QIE8_ = scales.getParameter<double>("LSBQIE8");
0107     linearLSB_QIE11_ = scales.getParameter<double>("LSBQIE11");
0108     linearLSB_QIE11Overlap_ = scales.getParameter<double>("LSBQIE11Overlap");
0109     maskBit_ = iConfig.getParameter<int>("MaskBit");
0110     FG_HF_thresholds_ = iConfig.getParameter<std::vector<uint32_t> >("FG_HF_thresholds");
0111   } else {
0112     ifilename_ = iConfig.getParameter<edm::FileInPath>("inputLUTs");
0113   }
0114 }
0115 
0116 void HcalTPGCoderULUT::buildCoder(const HcalTopology* topo,
0117                                   const HcalElectronicsMap* emap,
0118                                   const HcalTimeSlew* delay,
0119                                   HcaluLUTTPGCoder* theCoder) {
0120   using namespace edm::es;
0121   theCoder->init(topo, emap, delay);
0122 
0123   theCoder->setOverrideDBweightsAndFilterHB(overrideDBweightsAndFilterHB_);
0124   theCoder->setOverrideDBweightsAndFilterHE(overrideDBweightsAndFilterHE_);
0125 
0126   theCoder->set1TSContainHB(contain1TSHB_);
0127   theCoder->set1TSContainHE(contain1TSHE_);
0128 
0129   theCoder->setContainPhaseHB(containPhaseNSHB_);
0130   theCoder->setContainPhaseHE(containPhaseNSHE_);
0131 
0132   theCoder->setApplyFixPCC(applyFixPCC_);
0133 
0134   if (read_Ascii_ || read_XML_) {
0135     edm::LogInfo("HCAL") << "Using ASCII/XML LUTs" << ifilename_.fullPath() << " for HcalTPGCoderULUT initialization";
0136     if (read_Ascii_) {
0137       theCoder->update(ifilename_.fullPath().c_str());
0138     } else if (read_XML_) {
0139       theCoder->updateXML(ifilename_.fullPath().c_str());
0140     }
0141     // Read FG LUT and append to most significant bit 11
0142     if (read_FGLut_) {
0143       theCoder->update(fgfile_.fullPath().c_str(), true);
0144     }
0145   } else {
0146     theCoder->setAllLinear(linearLUTs_, linearLSB_QIE8_, linearLSB_QIE11_, linearLSB_QIE11Overlap_);
0147     theCoder->setLUTGenerationMode(LUTGenerationMode_);
0148     theCoder->setMaskBit(maskBit_);
0149     theCoder->setFGHFthresholds(FG_HF_thresholds_);
0150   }
0151 }
0152 
0153 HcalTPGCoderULUT::~HcalTPGCoderULUT() {
0154   // do anything here that needs to be done at desctruction time
0155   // (e.g. close files, deallocate resources etc.)
0156 }
0157 
0158 //
0159 // member functions
0160 //
0161 
0162 // ------------ method called to produce the data  ------------
0163 HcalTPGCoderULUT::ReturnType HcalTPGCoderULUT::produce(const HcalTPGRecord& iRecord) {
0164   auto host = holder_.makeOrGet([]() { return new HostType; });
0165 
0166   const auto& topo = iRecord.get(topoToken_);
0167   const auto& delayRcd = iRecord.getRecord<HcalDbRecord>();
0168   const auto& dbServ = iRecord.get(serviceToken_);
0169   const auto* emap = dbServ.getHcalMapping();
0170   const auto& delay = delayRcd.get(delayToken_);
0171   if (read_Ascii_ || read_XML_) {
0172     buildCoder(&topo, emap, &delay, host.get());
0173   } else {
0174     host->ifRecordChanges<HcalDbRecord>(iRecord, [this, &topo, emap, &delay, h = host.get()](auto const& rec) {
0175       buildCoder(&topo, emap, &delay, h);
0176       h->update(rec.get(serviceToken_));
0177       // Temporary update for FG Lut
0178       // Will be moved to DB
0179       if (read_FGLut_)
0180         h->update(fgfile_.fullPath().c_str(), true);
0181     });
0182   }
0183   return host;
0184 }
0185 
0186 //define this as a plug-in
0187 DEFINE_FWK_EVENTSETUP_MODULE(HcalTPGCoderULUT);