CMS 3D CMS Logo

L1TRawToDigi.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventFilter/L1TRawToDigi
4 // Class: L1TRawToDigi
5 //
13 //
14 // Original Author: Matthias Wolf
15 // Created: Mon, 10 Feb 2014 14:29:40 GMT
16 //
17 //
18 
19 // system include files
20 #include <iostream>
21 #include <iomanip>
22 #include <memory>
23 
24 // user include files
31 
36 
39 
40 #include "PackingSetupFactory.h"
41 
43 
44 namespace l1t {
46  public:
47  explicit L1TRawToDigi(const edm::ParameterSet&);
48  ~L1TRawToDigi() override;
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52  private:
53  void produce(edm::Event&, const edm::EventSetup&) override;
54 
55  void beginRun(edm::Run const&, edm::EventSetup const&) override{};
56  void endRun(edm::Run const&, edm::EventSetup const&) override{};
58  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override{};
59 
60  // ----------member data ---------------------------
62  std::vector<int> fedIds_;
63  unsigned int minFeds_;
64  unsigned int fwId_;
65  unsigned int dmxFwId_;
67 
68  std::unique_ptr<PackingSetup> prov_;
69 
70  // header and trailer sizes in chars
77 
78  bool tmtCheck_;
79 
80  bool ctp7_mode_;
81  bool mtf7_mode_;
82  bool debug_;
83  int warnsa_;
84  int warnsb_;
85  };
86 } // namespace l1t
87 
88 std::ostream& operator<<(std::ostream& o, const l1t::BlockHeader& h) {
89  o << "L1T Block Header " << h.getID() << " with size " << h.getSize();
90  return o;
91 };
92 
93 namespace l1t {
95  : fedIds_(config.getParameter<std::vector<int>>("FedIds")),
96  minFeds_(config.getParameter<unsigned int>("MinFeds")),
97  fwId_(config.getParameter<unsigned int>("FWId")),
98  dmxFwId_(config.getParameter<unsigned int>("DmxFWId")),
99  fwOverride_(config.getParameter<bool>("FWOverride")),
100  tmtCheck_(config.getParameter<bool>("TMTCheck")),
101  ctp7_mode_(config.getUntrackedParameter<bool>("CTP7")),
102  mtf7_mode_(config.getUntrackedParameter<bool>("MTF7")) {
103  fedData_ = consumes<FEDRawDataCollection>(config.getParameter<edm::InputTag>("InputLabel"));
104 
105  if (ctp7_mode_ and mtf7_mode_) {
106  throw cms::Exception("L1TRawToDigi") << "Can only use one unpacking mode concurrently!";
107  }
108 
109  prov_ = PackingSetupFactory::get()->make(config.getParameter<std::string>("Setup"));
110  prov_->registerProducts(producesCollector());
111 
112  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader");
113  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer");
114  amcHeaderSize_ = config.getUntrackedParameter<int>("lenAMCHeader");
115  amcTrailerSize_ = config.getUntrackedParameter<int>("lenAMCTrailer");
116  amc13HeaderSize_ = config.getUntrackedParameter<int>("lenAMC13Header");
117  amc13TrailerSize_ = config.getUntrackedParameter<int>("lenAMC13Trailer");
118 
119  debug_ = config.getUntrackedParameter<bool>("debug");
120  warnsa_ = 0;
121  warnsb_ = 0;
122  }
123 
125 
126  //
127  // member functions
128  //
129 
130  // ------------ method called to produce the data ------------
132  using namespace edm;
133 
134  std::unique_ptr<UnpackerCollections> coll = prov_->getCollections(event);
135 
137  event.getByToken(fedData_, feds);
138 
139  if (!feds.isValid()) {
140  LogError("L1T") << "Cannot unpack: no FEDRawDataCollection found";
141  return;
142  }
143 
144  unsigned valid_count = 0;
145  for (const auto& fedId : fedIds_) {
146  const FEDRawData& l1tRcd = feds->FEDData(fedId);
147 
148  LogDebug("L1T") << "Found FEDRawDataCollection with ID " << fedId << " and size " << l1tRcd.size();
149 
152  if (l1tRcd.size() > 0) {
153  LogError("L1T") << "Cannot unpack: invalid L1T raw data (size = " << l1tRcd.size() << ") for ID " << fedId
154  << ". Returning empty collections!";
155  } else if (warnsa_ < 5) {
156  warnsa_++;
157  LogInfo("L1T") << "During unpacking, encountered empty L1T raw data (size = " << l1tRcd.size()
158  << ") for FED ID " << fedId << ".";
159  }
160  continue;
161  } else {
162  valid_count++;
163  }
164 
165  const unsigned char* data = l1tRcd.data();
167 
168  if (header.check()) {
169  LogDebug("L1T") << "Found SLink header:"
170  << " Trigger type " << header.triggerType() << " L1 event ID " << header.lvl1ID()
171  << " BX Number " << header.bxID() << " FED source " << header.sourceID() << " FED version "
172  << header.version();
173  } else {
174  LogWarning("L1T") << "Did not find a SLink header!";
175  }
176 
177  FEDTrailer trailer(data + (l1tRcd.size() - slinkTrailerSize_));
178 
179  if (trailer.check()) {
180  LogDebug("L1T") << "Found SLink trailer:"
181  << " Length " << trailer.fragmentLength() << " CRC " << trailer.crc() << " Status "
182  << trailer.evtStatus() << " Throttling bits " << trailer.ttsBits();
183  } else {
184  LogWarning("L1T") << "Did not find a SLink trailer!";
185  }
186 
187  // FIXME Hard-coded firmware version for first 74x MC campaigns.
188  // Will account for differences in the AMC payload, MP7 payload,
189  // and unpacker setup.
190  bool legacy_mc = fwOverride_ && ((fwId_ >> 24) == 0xff);
191 
192  amc13::Packet packet;
193  if (!packet.parse((const uint64_t*)data,
194  (const uint64_t*)(data + slinkHeaderSize_),
195  (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8,
196  header.lvl1ID(),
197  header.bxID(),
198  legacy_mc,
199  mtf7_mode_)) {
200  LogError("L1T") << "Could not extract AMC13 Packet.";
201  return;
202  }
203 
204  for (auto& amc : packet.payload()) {
205  if (amc.size() == 0)
206  continue;
207 
208  auto payload64 = amc.data();
209  const uint32_t* start = (const uint32_t*)payload64.get();
210  // Want to have payload size in 32 bit words, but AMC measures
211  // it in 64 bit words → factor 2.
212  const uint32_t* end = start + (amc.size() * 2);
213 
214  std::unique_ptr<Payload> payload;
215  if (ctp7_mode_) {
216  LogDebug("L1T") << "Using CTP7 mode";
217  // CTP7 uses userData in AMC header
218  payload = std::make_unique<CTP7Payload>(start, end, amc.header());
219  } else if (mtf7_mode_) {
220  LogDebug("L1T") << "Using MTF7 mode";
221  payload = std::make_unique<MTF7Payload>(start, end);
222  } else {
223  LogDebug("L1T") << "Using MP7 mode";
224  payload = std::make_unique<MP7Payload>(start, end, legacy_mc);
225  }
226  unsigned fw = payload->getAlgorithmFWVersion();
227  unsigned board = amc.blockHeader().getBoardID();
228  unsigned amc_no = amc.blockHeader().getAMCNumber();
229 
230  // Let parameterset value override FW version
231  if (fwOverride_) {
232  if (fedId == 1360)
233  fw = fwId_;
234  else if (fedId == 1366)
235  fw = dmxFwId_;
236  }
237 
238  auto unpackers = prov_->getUnpackers(fedId, board, amc_no, fw);
239 
240  // getBlock() returns a non-null unique_ptr on success
241  std::unique_ptr<Block> block;
242  while ((block = payload->getBlock()).get()) {
243  // only unpack the Calo Layer 2 MP TMT node if it has processed this BX
244  unsigned tmtId = board - l1t::stage2::layer2::mp::offsetBoardId + 1;
245  unsigned bxId = header.bxID();
246  unsigned unpackTMT = (!tmtCheck_ || ((tmtId - 1) == ((bxId - 1 + 3) % 9)));
247  unsigned isCaloL2TMT =
249 
250  if (!isCaloL2TMT || unpackTMT) {
251  if (debug_) {
252  std::cout << ">>> block to unpack <<<" << std::endl
253  << "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw()
254  << std::dec << " (ID " << block->header().getID() << ", size " << block->header().getSize()
255  << ", CapID 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getCapID()
256  << ")" << std::dec << std::endl;
257  for (const auto& word : block->payload()) {
258  if (debug_)
259  std::cout << "data: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec
260  << std::endl;
261  }
262  }
263 
264  auto unpacker = unpackers.find(block->header().getID());
265 
266  block->amc(amc.header());
267 
268  if (unpacker == unpackers.end()) {
269  LogDebug("L1T") << "Cannot find an unpacker for"
270  << "\n\tblock: ID " << block->header().getID() << ", size " << block->header().getSize()
271  << "\n\tAMC: # " << amc_no << ", board ID 0x" << std::hex << board << std::dec
272  << "\n\tFED ID " << fedId << ", and FW ID " << fw;
273  // TODO Handle error
274  } else if (!unpacker->second->unpack(*block, coll.get())) {
275  LogDebug("L1T") << "Error unpacking data for block ID " << block->header().getID() << ", AMC # " << amc_no
276  << ", board ID " << board << ", FED ID " << fedId << ", and FW ID " << fw << "!";
277  // TODO Handle error
278  }
279  }
280  }
281  }
282  }
283  if (valid_count < minFeds_) {
284  if (warnsb_ < 5) {
285  warnsb_++;
286  LogWarning("L1T") << "Unpacked " << valid_count << " non-empty FED IDs but minimum is set to " << minFeds_
287  << "\n";
288  }
289  }
290  }
291 
292  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
295  // These parameters are part of the L1T/HLT interface, avoid changing if possible:
296  desc.add<std::vector<int>>("FedIds", {})->setComment("required parameter: default value is invalid");
297  desc.add<std::string>("Setup", "")->setComment("required parameter: default value is invalid");
298  // These parameters have well defined default values and are not currently
299  // part of the L1T/HLT interface. They can be cleaned up or updated at will:
300  desc.add<unsigned int>("FWId", 0)->setComment(
301  "Ignored unless FWOverride is true. Calo Stage1: 32 bits: if the first eight bits are 0xff, will read the "
302  "74x MC format.\n");
303  desc.add<unsigned int>("DmxFWId", 0)
304  ->setComment(
305  "Ignored unless FWOverride is true. Calo Stage1: 32 bits: if the first eight bits are 0xff, will read "
306  "the 74x MC format.\n");
307  desc.add<bool>("FWOverride", false)->setComment("Firmware version should be taken as FWId parameters");
308  desc.add<bool>("TMTCheck", true)->setComment("Flag for turning on/off Calo Layer 2 TMT node check");
309  desc.addUntracked<bool>("CTP7", false);
310  desc.addUntracked<bool>("MTF7", false);
311  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
312  desc.addUntracked<int>("lenSlinkHeader", 8);
313  desc.addUntracked<int>("lenSlinkTrailer", 8);
314  desc.addUntracked<int>("lenAMCHeader", 8);
315  desc.addUntracked<int>("lenAMCTrailer", 0);
316  desc.addUntracked<int>("lenAMC13Header", 8);
317  desc.addUntracked<int>("lenAMC13Trailer", 8);
318  desc.addUntracked<bool>("debug", false)->setComment("turn on verbose output");
319  desc.add<unsigned int>("MinFeds", 0)
320  ->setComment("optional parameter: warn if less than MinFeds non-empty FED ids unpacked.");
321  descriptions.add("l1tRawToDigi", desc);
322  }
323 } // namespace l1t
324 
325 using namespace l1t;
326 //define this as a plug-in
Block.h
FEDNumbering.h
l1tstage2emulator_dqm_sourceclient-live_cfg.feds
feds
Definition: l1tstage2emulator_dqm_sourceclient-live_cfg.py:152
electrons_cff.bool
bool
Definition: electrons_cff.py:393
start
Definition: start.py:1
amc13::Packet::parse
bool parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
Definition: AMC13Spec.cc:60
l1t::L1TRawToDigi::fwOverride_
bool fwOverride_
Definition: L1TRawToDigi.cc:66
l1t::L1TRawToDigi::warnsb_
int warnsb_
Definition: L1TRawToDigi.cc:84
l1t::L1TRawToDigi::debug_
bool debug_
Definition: L1TRawToDigi.cc:82
L1TStage2Layer2Constants.h
l1t::L1TRawToDigi::tmtCheck_
bool tmtCheck_
Definition: L1TRawToDigi.cc:78
l1t::L1TRawToDigi::mtf7_mode_
bool mtf7_mode_
Definition: L1TRawToDigi.cc:81
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< FEDRawDataCollection >
l1t::L1TRawToDigi::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:56
l1t::L1TRawToDigi::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:57
edm
HLT enums.
Definition: AlignableModifier.h:19
l1t::stage2::layer2::demux::amcSlotNum
const unsigned int amcSlotNum
Definition: L1TStage2Layer2Constants.cc:16
PackingSetupFactory.h
l1t::L1TRawToDigi::slinkHeaderSize_
int slinkHeaderSize_
Definition: L1TRawToDigi.cc:71
FEDTrailer::crc
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
Definition: FEDTrailer.cc:15
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
l1t::L1TRawToDigi::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: L1TRawToDigi.cc:131
EDProducer.h
FEDTrailer::evtStatus
uint8_t evtStatus() const
Event fragment status information.
Definition: FEDTrailer.cc:17
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
amc13::Packet::payload
std::vector< amc::Packet > payload() const
Definition: AMC13Spec.h:92
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
FEDRawData
Definition: FEDRawData.h:19
AMC13Spec.h
FEDTrailer::check
bool check() const
Check that the trailer is OK.
Definition: FEDTrailer.cc:45
l1t::L1TRawToDigi::ctp7_mode_
bool ctp7_mode_
Definition: L1TRawToDigi.cc:80
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
config
Definition: config.py:1
MakerMacros.h
l1t::L1TRawToDigi::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:58
l1t::L1TRawToDigi::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TRawToDigi.cc:293
h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
amc13::Packet
Definition: AMC13Spec.h:69
mps_fire.end
end
Definition: mps_fire.py:242
l1t::L1TRawToDigi::L1TRawToDigi
L1TRawToDigi(const edm::ParameterSet &)
Definition: L1TRawToDigi.cc:94
jets_cff.payload
payload
Definition: jets_cff.py:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1t::L1TRawToDigi::minFeds_
unsigned int minFeds_
Definition: L1TRawToDigi.cc:63
l1t::L1TRawToDigi::dmxFwId_
unsigned int dmxFwId_
Definition: L1TRawToDigi.cc:65
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
FEDTrailer
Definition: FEDTrailer.h:14
Event.h
l1t
delete x;
Definition: CaloConfig.h:22
l1t::L1TRawToDigi::amcTrailerSize_
int amcTrailerSize_
Definition: L1TRawToDigi.cc:74
fw
Definition: estimate_field.h:12
l1t::BlockHeader
Definition: Block.h:29
createfilelist.int
int
Definition: createfilelist.py:10
FEDRawDataCollection.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:38
operator<<
std::ostream & operator<<(std::ostream &o, const l1t::BlockHeader &h)
Definition: L1TRawToDigi.cc:88
l1t::L1TRawToDigi
Definition: L1TRawToDigi.cc:45
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
edm::EventSetup
Definition: EventSetup.h:57
l1t::L1TRawToDigi::amcHeaderSize_
int amcHeaderSize_
Definition: L1TRawToDigi.cc:73
l1t::stage2::layer2::fedId
const signed int fedId
Definition: L1TStage2Layer2Constants.cc:4
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
l1t::L1TRawToDigi::amc13TrailerSize_
int amc13TrailerSize_
Definition: L1TRawToDigi.cc:76
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
InputTag.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
l1t::L1TRawToDigi::fedIds_
std::vector< int > fedIds_
Definition: L1TRawToDigi.cc:62
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
l1t::L1TRawToDigi::fwId_
unsigned int fwId_
Definition: L1TRawToDigi.cc:64
l1t::L1TRawToDigi::prov_
std::unique_ptr< PackingSetup > prov_
Definition: L1TRawToDigi.cc:68
l1t::PackingSetupFactory::make
std::unique_ptr< PackingSetup > make(const std::string &) const
Definition: PackingSetupFactory.cc:8
amc
Definition: AMCSpec.h:8
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
l1t::L1TRawToDigi::warnsa_
int warnsa_
Definition: L1TRawToDigi.cc:83
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
l1t::L1TRawToDigi::fedData_
edm::EDGetTokenT< FEDRawDataCollection > fedData_
Definition: L1TRawToDigi.cc:58
l1t::PackingSetupFactory::get
static const PackingSetupFactory * get()
Definition: PackingSetupFactory.h:14
l1t::stage2::layer2::mp::offsetBoardId
const unsigned int offsetBoardId
Definition: L1TStage2Layer2Constants.cc:6
ParameterSet.h
l1t::L1TRawToDigi::slinkTrailerSize_
int slinkTrailerSize_
Definition: L1TRawToDigi.cc:72
FEDTrailer::ttsBits
uint8_t ttsBits() const
Current value of the Trigger Throttling System bits.
Definition: FEDTrailer.cc:19
event
Definition: event.py:1
dt_dqm_sourceclient_common_cff.unpackers
unpackers
Definition: dt_dqm_sourceclient_common_cff.py:108
FEDHeader
Definition: FEDHeader.h:14
edm::Event
Definition: Event.h:73
FEDHeader.h
l1t::L1TRawToDigi::~L1TRawToDigi
~L1TRawToDigi() override
Definition: L1TRawToDigi.cc:124
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::InputTag
Definition: InputTag.h:15
l1t::L1TRawToDigi::amc13HeaderSize_
int amc13HeaderSize_
Definition: L1TRawToDigi.cc:75
FEDTrailer::fragmentLength
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:13
l1t::L1TRawToDigi::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1TRawToDigi.cc:55
FEDTrailer.h