Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0002 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <iostream>
0006 
0007 #include "EventFilter/HcalRawToDigi/plugins/HcalDigiToRaw.h"
0008 
0009 using namespace std;
0010 
0011 HcalDigiToRaw::HcalDigiToRaw(edm::ParameterSet const& conf)
0012     : hbheTag_(conf.getUntrackedParameter("HBHE", edm::InputTag())),
0013       hoTag_(conf.getUntrackedParameter("HO", edm::InputTag())),
0014       hfTag_(conf.getUntrackedParameter("HF", edm::InputTag())),
0015       zdcTag_(conf.getUntrackedParameter("ZDC", edm::InputTag())),
0016       calibTag_(conf.getUntrackedParameter("CALIB", edm::InputTag())),
0017       trigTag_(conf.getUntrackedParameter("TRIG", edm::InputTag())),
0018       // register for data access
0019       tok_hbhe_(consumes<HBHEDigiCollection>(hbheTag_)),
0020       tok_ho_(consumes<HODigiCollection>(hoTag_)),
0021       tok_hf_(consumes<HFDigiCollection>(hfTag_)),
0022       tok_calib_(consumes<HcalCalibDigiCollection>(calibTag_)),
0023       tok_zdc_(consumes<ZDCDigiCollection>(zdcTag_)),
0024       tok_htp_(consumes<HcalTrigPrimDigiCollection>(trigTag_)),
0025       tok_dbService_(esConsumes<HcalDbService, HcalDbRecord>()) {
0026   produces<FEDRawDataCollection>();
0027 }
0028 
0029 // Virtual destructor needed.
0030 HcalDigiToRaw::~HcalDigiToRaw() {}
0031 
0032 // Functions that gets called by framework every event
0033 void HcalDigiToRaw::produce(edm::StreamID id, edm::Event& e, const edm::EventSetup& es) const {
0034   HcalPacker::Collections colls;
0035 
0036   // Step A: Get Inputs
0037   edm::Handle<HBHEDigiCollection> hbhe;
0038   if (!hbheTag_.label().empty()) {
0039     e.getByToken(tok_hbhe_, hbhe);
0040     colls.hbhe = hbhe.product();
0041   }
0042   edm::Handle<HODigiCollection> ho;
0043   if (!hoTag_.label().empty()) {
0044     e.getByToken(tok_ho_, ho);
0045     colls.hoCont = ho.product();
0046   }
0047   edm::Handle<HFDigiCollection> hf;
0048   if (!hfTag_.label().empty()) {
0049     e.getByToken(tok_hf_, hf);
0050     colls.hfCont = hf.product();
0051   }
0052   edm::Handle<HcalCalibDigiCollection> Calib;
0053   if (!calibTag_.label().empty()) {
0054     e.getByToken(tok_calib_, Calib);
0055     colls.calibCont = Calib.product();
0056   }
0057   edm::Handle<ZDCDigiCollection> zdc;
0058   if (!zdcTag_.label().empty()) {
0059     e.getByToken(tok_zdc_, zdc);
0060     colls.zdcCont = zdc.product();
0061   }
0062   edm::Handle<HcalTrigPrimDigiCollection> htp;
0063   if (!trigTag_.label().empty()) {
0064     e.getByToken(tok_htp_, htp);
0065     if (htp.isValid())
0066       colls.tpCont = htp.product();
0067   }
0068   // get the mapping
0069   edm::ESHandle<HcalDbService> pSetup = es.getHandle(tok_dbService_);
0070   const HcalElectronicsMap* readoutMap = pSetup->getHcalMapping();
0071   // Step B: Create empty output
0072   auto raw = std::make_unique<FEDRawDataCollection>();
0073 
0074   const int ifed_first = FEDNumbering::MINHCALFEDID;
0075   const int ifed_last = FEDNumbering::MAXHCALFEDID;
0076 
0077   int orbitN = e.id().event();
0078   int bcnN = 2000;
0079 
0080   // Step C: pack all requested FEDs
0081   for (int ifed = ifed_first; ifed <= ifed_last; ++ifed) {
0082     FEDRawData& fed = raw->FEDData(ifed);
0083     try {
0084       packer_.pack(ifed, ifed - ifed_first, e.id().event(), orbitN, bcnN, colls, *readoutMap, fed);
0085     } catch (cms::Exception& e) {
0086       edm::LogWarning("Unpacking error") << e.what();
0087     } catch (...) {
0088       edm::LogWarning("Unpacking exception");
0089     }
0090   }
0091 
0092   e.put(std::move(raw));
0093 }