CMS 3D CMS Logo

HGCalRawToDigi.cc
Go to the documentation of this file.
1 #include <memory>
2 
9 
11 
15 
17 public:
18  explicit HGCalRawToDigi(const edm::ParameterSet&);
19 
21 
22 private:
23  void produce(edm::Event&, const edm::EventSetup&) override;
24 
28 
29  const std::vector<unsigned int> fedIds_;
30  const unsigned int badECONDMax_;
31  const unsigned int numERxsInECOND_;
32  const std::unique_ptr<HGCalUnpacker<HGCalElectronicsId> > unpacker_;
33 };
34 
36  : fedRawToken_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("src"))),
37  digisToken_(produces<HGCalDigiCollection>()),
38  elecDigisToken_(produces<HGCalElecDigiCollection>()),
39  fedIds_(iConfig.getParameter<std::vector<unsigned int> >("fedIds")),
40  badECONDMax_(iConfig.getParameter<unsigned int>("badECONDMax")),
41  numERxsInECOND_(iConfig.getParameter<unsigned int>("numERxsInECOND")),
42  unpacker_(new HGCalUnpacker<HGCalElectronicsId>(
43  HGCalUnpackerConfig{.sLinkBOE = iConfig.getParameter<unsigned int>("slinkBOE"),
44  .captureBlockReserved = iConfig.getParameter<unsigned int>("captureBlockReserved"),
45  .econdHeaderMarker = iConfig.getParameter<unsigned int>("econdHeaderMarker"),
46  .sLinkCaptureBlockMax = iConfig.getParameter<unsigned int>("maxCaptureBlock"),
47  .captureBlockECONDMax = iConfig.getParameter<unsigned int>("captureBlockECONDMax"),
48  .econdERXMax = iConfig.getParameter<unsigned int>("econdERXMax"),
49  .erxChannelMax = iConfig.getParameter<unsigned int>("erxChannelMax"),
50  .payloadLengthMax = iConfig.getParameter<unsigned int>("payloadLengthMax"),
51  .channelMax = iConfig.getParameter<unsigned int>("channelMax"),
52  .commonModeMax = iConfig.getParameter<unsigned int>("commonModeMax")})) {}
53 
55  // retrieve the FED raw data
56  const auto& raw_data = iEvent.get(fedRawToken_);
57  // prepare the output
58  HGCalDigiCollection digis;
59  HGCalElecDigiCollection elec_digis;
60  for (const auto& fed_id : fedIds_) {
61  const auto& fed_data = raw_data.FEDData(fed_id);
62  if (fed_data.size() == 0)
63  continue;
64 
65  std::vector<uint32_t> data_32bit;
66  auto* ptr = fed_data.data();
67  size_t fed_size = fed_data.size();
68  for (size_t i = 0; i < fed_size; i += 4)
69  data_32bit.emplace_back(((*(ptr + i) & 0xff) << 0) + (((i + 1) < fed_size) ? ((*(ptr + i + 1) & 0xff) << 8) : 0) +
70  (((i + 2) < fed_size) ? ((*(ptr + i + 2) & 0xff) << 16) : 0) +
71  (((i + 3) < fed_size) ? ((*(ptr + i + 3) & 0xff) << 24) : 0));
72 
73  unpacker_->parseSLink(
74  data_32bit,
75  [this](uint16_t /*sLink*/, uint8_t /*captureBlock*/, uint8_t /*econd*/) { return (1 << numERxsInECOND_) - 1; },
77  const auto elecid_to_detid = [](const HGCalElectronicsId& id) -> HGCalDetId {
78  return HGCalDetId(id.raw());
79  }; //TODO: implement something more relevant
80 
81  auto channeldata = unpacker_->channelData();
82  auto cms = unpacker_->commonModeIndex();
83  for (unsigned int i = 0; i < channeldata.size(); i++) {
84  auto data = channeldata.at(i);
85  auto cm = cms.at(i);
86  const auto& id = data.id();
87  auto idraw = id.raw();
88  auto raw = data.raw();
89  LogDebug("HGCalRawToDigi:produce") << "id=" << idraw << ", raw=" << raw << ", common mode index=" << cm << ".";
90  digis.push_back(HGCROCChannelDataFrameSpec(elecid_to_detid(id), data.raw()));
91  elec_digis.push_back(data);
92  }
93  if (const auto& bad_econds = unpacker_->badECOND(); !bad_econds.empty()) {
94  if (bad_econds.size() > badECONDMax_)
95  throw cms::Exception("HGCalRawToDigi:produce")
96  << "Too many bad ECON-Ds: " << bad_econds.size() << " > " << badECONDMax_ << ".";
97  edm::LogWarning("HGCalRawToDigi:produce").log([&bad_econds](auto& log) {
98  log << "Bad ECON-D: " << std::dec;
100  for (const auto& badECOND : bad_econds)
101  log << prefix << badECOND, prefix = ", ";
102  log << ".";
103  });
104  }
105  }
106  iEvent.emplace(digisToken_, std::move(digis));
107  iEvent.emplace(elecDigisToken_, std::move(elec_digis));
108 }
109 
112  desc.add<edm::InputTag>("src", edm::InputTag("rawDataCollector"));
113  desc.add<unsigned int>("maxCaptureBlock", 1)->setComment("maximum number of capture blocks in one S-Link");
114  desc.add<unsigned int>("captureBlockReserved", 0)->setComment("capture block reserved pattern");
115  desc.add<unsigned int>("econdHeaderMarker", 0x154)->setComment("ECON-D header Marker pattern");
116  desc.add<unsigned int>("slinkBOE", 0x2a)->setComment("SLink BOE pattern");
117  desc.add<unsigned int>("captureBlockECONDMax", 12)->setComment("maximum number of ECON-D's in one capture block");
118  desc.add<unsigned int>("econdERXMax", 12)->setComment("maximum number of eRx's in one ECON-D");
119  desc.add<unsigned int>("erxChannelMax", 37)->setComment("maximum number of channels in one eRx");
120  desc.add<unsigned int>("payloadLengthMax", 469)->setComment("maximum length of payload length");
121  desc.add<unsigned int>("channelMax", 7000000)->setComment("maximum number of channels unpacked");
122  desc.add<unsigned int>("commonModeMax", 4000000)->setComment("maximum number of common modes unpacked");
123  desc.add<unsigned int>("badECONDMax", 200)->setComment("maximum number of bad ECON-D's");
124  desc.add<std::vector<unsigned int> >("fedIds", {});
125  desc.add<unsigned int>("numERxsInECOND", 12)->setComment("number of eRxs in each ECON-D payload");
126  descriptions.add("hgcalDigis", desc);
127 }
128 
129 // define this as a plug-in
const edm::EDPutTokenT< HGCalDigiCollection > digisToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
size_type size() const
void push_back(T const &t)
HGCROCChannelDataFrame< HGCalDetId > HGCROCChannelDataFrameSpec
const std::vector< unsigned int > fedIds_
This class is designed to unpack raw data from HGCal, formatted as S-Links, capture blocks...
Definition: HGCalUnpacker.h:36
int iEvent
Definition: GenABIO.cc:224
void produce(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
wrapper for a 32b data word identifying a readout channel in the raw data The format is the following...
HGCalRawToDigi(const edm::ParameterSet &)
const unsigned int badECONDMax_
Namespace of DDCMS conversion namespace.
const edm::EDPutTokenT< HGCalElecDigiCollection > elecDigisToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
uint32_t sLinkBOE
S-Link BOE pattern.
Definition: HGCalUnpacker.h:22
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static const int elecID
Definition: TopGenEvent.h:18
const std::unique_ptr< HGCalUnpacker< HGCalElectronicsId > > unpacker_
static void fillDescriptions(edm::ConfigurationDescriptions &)
Log< level::Warning, false > LogWarning
const unsigned int numERxsInECOND_
def move(src, dest)
Definition: eostools.py:511
const edm::EDGetTokenT< FEDRawDataCollection > fedRawToken_
#define LogDebug(id)