Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:34

0001 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0002 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0003 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include <iostream>
0007 
0008 #include "EventFilter/CastorRawToDigi/interface/CastorCollections.h"
0009 #include "EventFilter/CastorRawToDigi/plugins/CastorDigiToRaw.h"
0010 
0011 using namespace std;
0012 
0013 CastorDigiToRaw::CastorDigiToRaw(edm::ParameterSet const& conf)
0014     : castorTag_(conf.getParameter<edm::InputTag>("CASTOR")),
0015       usingctdc_(conf.getParameter<bool>("CastorCtdc")),
0016       tok_input_(consumes<CastorDigiCollection>(castorTag_)),
0017       tok_put_(produces<FEDRawDataCollection>()),
0018       tok_pSetup_(esConsumes<CastorDbService, CastorDbRecord>()) {}
0019 
0020 // Functions that gets called by framework every event
0021 void CastorDigiToRaw::produce(edm::StreamID, edm::Event& e, const edm::EventSetup& es) const {
0022   CastorCollections colls;
0023 
0024   // Step A: Get Inputs
0025   edm::Handle<CastorDigiCollection> castor;
0026   if (!castorTag_.label().empty()) {
0027     e.getByToken(tok_input_, castor);
0028     colls.castorCont = castor.product();
0029   }
0030   // get the mapping
0031   edm::ESHandle<CastorDbService> pSetup = es.getHandle(tok_pSetup_);
0032   const CastorElectronicsMap* readoutMap = pSetup->getCastorMapping();
0033   // Step B: Create empty output
0034   FEDRawDataCollection raw;
0035 
0036   constexpr int ifed_first = FEDNumbering::MINCASTORFEDID;  //690
0037   constexpr int ifed_last = FEDNumbering::MAXCASTORFEDID;   //693
0038 
0039   int orbitN = e.id().event();
0040   int bcnN = 2000;
0041 
0042   // Step C: pack all requested FEDs
0043   for (int ifed = ifed_first; ifed <= ifed_last; ++ifed) {
0044     FEDRawData& fed = raw.FEDData(ifed);
0045     try {
0046       if (usingctdc_) {
0047         CastorCtdcPacker::pack(ifed, ifed - ifed_first, e.id().event(), orbitN, bcnN, colls, *readoutMap, fed);
0048       } else {
0049         CastorPacker::pack(ifed, ifed - ifed_first, e.id().event(), orbitN, bcnN, colls, *readoutMap, fed);
0050       }
0051     } catch (cms::Exception& e) {
0052       edm::LogWarning("Unpacking error") << e.what();
0053     } catch (...) {
0054       edm::LogWarning("Unpacking exception");
0055     }
0056   }
0057 
0058   e.emplace(tok_put_, std::move(raw));
0059 }