Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:15:04

0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include <iostream>
0013 #include <unordered_set>
0014 #include <string>
0015 
0016 //helper
0017 namespace raw_impl {
0018   template <class T>
0019   void get(edm::EDGetTokenT<T> tok, edm::Event& e, const std::string& productName = "") {
0020     edm::Handle<T> h_coll;
0021     e.getByToken(tok, h_coll);
0022     auto o_coll = std::make_unique<T>();
0023     if (h_coll.isValid()) {
0024       //copy constructor
0025       o_coll = std::make_unique<T>(*(h_coll.product()));
0026     }
0027     if (!productName.empty())
0028       e.put(std::move(o_coll), productName);
0029     else
0030       e.put(std::move(o_coll));
0031   }
0032 }  // namespace raw_impl
0033 
0034 class HcalRawToDigiFake : public edm::global::EDProducer<> {
0035 public:
0036   explicit HcalRawToDigiFake(const edm::ParameterSet& ps);
0037   ~HcalRawToDigiFake() override;
0038   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0039   void produce(edm::StreamID id, edm::Event& e, const edm::EventSetup& c) const override;
0040 
0041 private:
0042   //members
0043   edm::EDGetTokenT<QIE10DigiCollection> tok_QIE10DigiCollection_;
0044   edm::EDGetTokenT<QIE11DigiCollection> tok_QIE11DigiCollection_;
0045   edm::EDGetTokenT<HBHEDigiCollection> tok_HBHEDigiCollection_;
0046   edm::EDGetTokenT<HFDigiCollection> tok_HFDigiCollection_;
0047   edm::EDGetTokenT<HODigiCollection> tok_HODigiCollection_;
0048   edm::EDGetTokenT<HcalTrigPrimDigiCollection> tok_TPDigiCollection_;
0049   edm::EDGetTokenT<HOTrigPrimDigiCollection> tok_HOTPDigiCollection_;
0050   edm::EDGetTokenT<HcalCalibDigiCollection> tok_CalibDigiCollection_;
0051   edm::EDGetTokenT<ZDCDigiCollection> tok_ZDCDigiCollection_;
0052   edm::EDGetTokenT<QIE10DigiCollection> tok_ZDCQIE10DigiCollection_;
0053   edm::EDGetTokenT<HcalTTPDigiCollection> tok_TTPDigiCollection_;
0054   const bool unpackCalib_, unpackZDC_, unpackTTP_;
0055 };
0056 
0057 HcalRawToDigiFake::HcalRawToDigiFake(edm::ParameterSet const& conf)
0058     : tok_QIE10DigiCollection_(consumes<QIE10DigiCollection>(conf.getParameter<edm::InputTag>("QIE10"))),
0059       tok_QIE11DigiCollection_(consumes<QIE11DigiCollection>(conf.getParameter<edm::InputTag>("QIE11"))),
0060       tok_HBHEDigiCollection_(consumes<HBHEDigiCollection>(conf.getParameter<edm::InputTag>("HBHE"))),
0061       tok_HFDigiCollection_(consumes<HFDigiCollection>(conf.getParameter<edm::InputTag>("HF"))),
0062       tok_HODigiCollection_(consumes<HODigiCollection>(conf.getParameter<edm::InputTag>("HO"))),
0063       tok_TPDigiCollection_(consumes<HcalTrigPrimDigiCollection>(conf.getParameter<edm::InputTag>("TRIG"))),
0064       tok_HOTPDigiCollection_(consumes<HOTrigPrimDigiCollection>(conf.getParameter<edm::InputTag>("HOTP"))),
0065       tok_CalibDigiCollection_(consumes<HcalCalibDigiCollection>(conf.getParameter<edm::InputTag>("CALIB"))),
0066       tok_ZDCDigiCollection_(consumes<ZDCDigiCollection>(conf.getParameter<edm::InputTag>("ZDC"))),
0067       tok_ZDCQIE10DigiCollection_(consumes<QIE10DigiCollection>(conf.getParameter<edm::InputTag>("ZDCQIE10"))),
0068       tok_TTPDigiCollection_(consumes<HcalTTPDigiCollection>(conf.getParameter<edm::InputTag>("TTP"))),
0069       unpackCalib_(conf.getParameter<bool>("UnpackCalib")),
0070       unpackZDC_(conf.getParameter<bool>("UnpackZDC")),
0071       unpackTTP_(conf.getParameter<bool>("UnpackTTP")) {
0072   // products produced...
0073   produces<QIE10DigiCollection>();
0074   produces<QIE11DigiCollection>();
0075   produces<HBHEDigiCollection>();
0076   produces<HFDigiCollection>();
0077   produces<HODigiCollection>();
0078   produces<HcalTrigPrimDigiCollection>();
0079   produces<HOTrigPrimDigiCollection>();
0080   if (unpackCalib_)
0081     produces<HcalCalibDigiCollection>();
0082   if (unpackZDC_)
0083     produces<ZDCDigiCollection>();
0084   if (unpackTTP_)
0085     produces<HcalTTPDigiCollection>();
0086   produces<QIE10DigiCollection>("ZDC");
0087 }
0088 
0089 // Virtual destructor needed.
0090 HcalRawToDigiFake::~HcalRawToDigiFake() {}
0091 
0092 void HcalRawToDigiFake::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0093   edm::ParameterSetDescription desc;
0094   desc.add<bool>("UnpackZDC", true);
0095   desc.add<bool>("UnpackCalib", true);
0096   desc.add<bool>("UnpackTTP", true);
0097   //empty tag = not usually produced by simulation
0098   desc.add<edm::InputTag>("QIE10", edm::InputTag("simHcalDigis", "HFQIE10DigiCollection"));
0099   desc.add<edm::InputTag>("QIE11", edm::InputTag("simHcalDigis", "HBHEQIE11DigiCollection"));
0100   desc.add<edm::InputTag>("HBHE", edm::InputTag("simHcalDigis"));
0101   desc.add<edm::InputTag>("HF", edm::InputTag("simHcalDigis"));
0102   desc.add<edm::InputTag>("HO", edm::InputTag("simHcalDigis"));
0103   desc.add<edm::InputTag>("TRIG", edm::InputTag("simHcalTriggerPrimitiveDigis"));
0104   desc.add<edm::InputTag>("HOTP", edm::InputTag(""));
0105   desc.add<edm::InputTag>("CALIB", edm::InputTag(""));
0106   desc.add<edm::InputTag>("ZDC", edm::InputTag("simHcalUnsuppressedDigis"));
0107   desc.add<edm::InputTag>("ZDCQIE10", edm::InputTag(""));
0108   desc.add<edm::InputTag>("TTP", edm::InputTag(""));
0109   //not used, just for compatibility
0110   desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
0111   desc.add<int>("firstSample", 0);
0112   desc.add<int>("lastSample", 0);
0113   descriptions.add("HcalRawToDigiFake", desc);
0114 }
0115 
0116 // Functions that gets called by framework every event
0117 void HcalRawToDigiFake::produce(edm::StreamID id, edm::Event& e, const edm::EventSetup& es) const {
0118   //handle each collection
0119   raw_impl::get(tok_QIE10DigiCollection_, e);
0120   raw_impl::get(tok_QIE11DigiCollection_, e);
0121   raw_impl::get(tok_HBHEDigiCollection_, e);
0122   raw_impl::get(tok_HFDigiCollection_, e);
0123   raw_impl::get(tok_HODigiCollection_, e);
0124   raw_impl::get(tok_TPDigiCollection_, e);
0125   raw_impl::get(tok_HOTPDigiCollection_, e);
0126   if (unpackCalib_)
0127     raw_impl::get(tok_CalibDigiCollection_, e);
0128   if (unpackZDC_)
0129     raw_impl::get(tok_ZDCDigiCollection_, e);
0130   raw_impl::get(tok_ZDCQIE10DigiCollection_, e, "ZDC");
0131   if (unpackTTP_)
0132     raw_impl::get(tok_TTPDigiCollection_, e);
0133 }
0134 
0135 DEFINE_FWK_MODULE(HcalRawToDigiFake);