File indexing completed on 2024-04-06 12:10:20
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
0021 void CastorDigiToRaw::produce(edm::StreamID, edm::Event& e, const edm::EventSetup& es) const {
0022 CastorCollections colls;
0023
0024
0025 edm::Handle<CastorDigiCollection> castor;
0026 if (!castorTag_.label().empty()) {
0027 e.getByToken(tok_input_, castor);
0028 colls.castorCont = castor.product();
0029 }
0030
0031 edm::ESHandle<CastorDbService> pSetup = es.getHandle(tok_pSetup_);
0032 const CastorElectronicsMap* readoutMap = pSetup->getCastorMapping();
0033
0034 FEDRawDataCollection raw;
0035
0036 constexpr int ifed_first = FEDNumbering::MINCASTORFEDID;
0037 constexpr int ifed_last = FEDNumbering::MAXCASTORFEDID;
0038
0039 int orbitN = e.id().event();
0040 int bcnN = 2000;
0041
0042
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 }