CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
l1t::L1TRawToDigi Class Reference
Inheritance diagram for l1t::L1TRawToDigi:
edm::stream::EDProducer<>

Public Member Functions

 L1TRawToDigi (const edm::ParameterSet &)
 
 ~L1TRawToDigi () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

int amc13HeaderSize_
 
int amc13TrailerSize_
 
int amcHeaderSize_
 
int amcTrailerSize_
 
bool ctp7_mode_
 
bool debug_
 
unsigned int dmxFwId_
 
edm::EDGetTokenT< FEDRawDataCollectionfedData_
 
std::vector< int > fedIds_
 
unsigned int fwId_
 
bool fwOverride_
 
unsigned int minFeds_
 
bool mtf7_mode_
 
std::unique_ptr< PackingSetupprov_
 
int slinkHeaderSize_
 
int slinkTrailerSize_
 
bool tmtCheck_
 
int warnsa_
 
int warnsb_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 45 of file L1TRawToDigi.cc.

Constructor & Destructor Documentation

◆ L1TRawToDigi()

L1TRawToDigi::L1TRawToDigi ( const edm::ParameterSet config)
explicit

Definition at line 89 of file L1TRawToDigi.cc.

References amc13HeaderSize_, amc13TrailerSize_, amcHeaderSize_, amcTrailerSize_, ctp7_mode_, debug_, Exception, fedData_, l1t::PackingSetupFactory::get(), l1t::PackingSetupFactory::make(), mtf7_mode_, prov_, slinkHeaderSize_, slinkTrailerSize_, AlCaHLTBitMon_QueryRunRegistry::string, warnsa_, and warnsb_.

90  : fedIds_(config.getParameter<std::vector<int>>("FedIds")),
91  minFeds_(config.getParameter<unsigned int>("MinFeds")),
92  fwId_(config.getParameter<unsigned int>("FWId")),
93  dmxFwId_(config.getParameter<unsigned int>("DmxFWId")),
94  fwOverride_(config.getParameter<bool>("FWOverride")),
95  tmtCheck_(config.getParameter<bool>("TMTCheck")),
96  ctp7_mode_(config.getUntrackedParameter<bool>("CTP7")),
97  mtf7_mode_(config.getUntrackedParameter<bool>("MTF7")) {
98  fedData_ = consumes<FEDRawDataCollection>(config.getParameter<edm::InputTag>("InputLabel"));
99 
100  if (ctp7_mode_ and mtf7_mode_) {
101  throw cms::Exception("L1TRawToDigi") << "Can only use one unpacking mode concurrently!";
102  }
103 
104  prov_ = PackingSetupFactory::get()->make(config.getParameter<std::string>("Setup"));
105  prov_->registerProducts(producesCollector());
106 
107  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader");
108  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer");
109  amcHeaderSize_ = config.getUntrackedParameter<int>("lenAMCHeader");
110  amcTrailerSize_ = config.getUntrackedParameter<int>("lenAMCTrailer");
111  amc13HeaderSize_ = config.getUntrackedParameter<int>("lenAMC13Header");
112  amc13TrailerSize_ = config.getUntrackedParameter<int>("lenAMC13Trailer");
113 
114  debug_ = config.getUntrackedParameter<bool>("debug");
115  warnsa_ = 0;
116  warnsb_ = 0;
117  }
unsigned int dmxFwId_
Definition: L1TRawToDigi.cc:60
Definition: config.py:1
std::unique_ptr< PackingSetup > make(const std::string &) const
std::vector< int > fedIds_
Definition: L1TRawToDigi.cc:57
unsigned int fwId_
Definition: L1TRawToDigi.cc:59
static const PackingSetupFactory * get()
unsigned int minFeds_
Definition: L1TRawToDigi.cc:58
std::unique_ptr< PackingSetup > prov_
Definition: L1TRawToDigi.cc:63
edm::EDGetTokenT< FEDRawDataCollection > fedData_
Definition: L1TRawToDigi.cc:56

◆ ~L1TRawToDigi()

L1TRawToDigi::~L1TRawToDigi ( )
override

Definition at line 119 of file L1TRawToDigi.cc.

119 {}

Member Function Documentation

◆ fillDescriptions()

void L1TRawToDigi::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 288 of file L1TRawToDigi.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, ProducerED_cfi::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

288  {
290  // These parameters are part of the L1T/HLT interface, avoid changing if possible:
291  desc.add<std::vector<int>>("FedIds", {})->setComment("required parameter: default value is invalid");
292  desc.add<std::string>("Setup", "")->setComment("required parameter: default value is invalid");
293  // These parameters have well defined default values and are not currently
294  // part of the L1T/HLT interface. They can be cleaned up or updated at will:
295  desc.add<unsigned int>("FWId", 0)->setComment(
296  "Ignored unless FWOverride is true. Calo Stage1: 32 bits: if the first eight bits are 0xff, will read the "
297  "74x MC format.\n");
298  desc.add<unsigned int>("DmxFWId", 0)
299  ->setComment(
300  "Ignored unless FWOverride is true. Calo Stage1: 32 bits: if the first eight bits are 0xff, will read "
301  "the 74x MC format.\n");
302  desc.add<bool>("FWOverride", false)->setComment("Firmware version should be taken as FWId parameters");
303  desc.add<bool>("TMTCheck", true)->setComment("Flag for turning on/off Calo Layer 2 TMT node check");
304  desc.addUntracked<bool>("CTP7", false);
305  desc.addUntracked<bool>("MTF7", false);
306  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
307  desc.addUntracked<int>("lenSlinkHeader", 8);
308  desc.addUntracked<int>("lenSlinkTrailer", 8);
309  desc.addUntracked<int>("lenAMCHeader", 8);
310  desc.addUntracked<int>("lenAMCTrailer", 0);
311  desc.addUntracked<int>("lenAMC13Header", 8);
312  desc.addUntracked<int>("lenAMC13Trailer", 8);
313  desc.addUntracked<bool>("debug", false)->setComment("turn on verbose output");
314  desc.add<unsigned int>("MinFeds", 0)
315  ->setComment("optional parameter: warn if less than MinFeds non-empty FED ids unpacked.");
316  descriptions.add("l1tRawToDigi", desc);
317  }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

void L1TRawToDigi::produce ( edm::Event event,
const edm::EventSetup setup 
)
overrideprivate

Definition at line 126 of file L1TRawToDigi.cc.

References amc13HeaderSize_, amc13TrailerSize_, amcHeaderSize_, l1t::stage2::layer2::demux::amcSlotNum, amcTrailerSize_, groupFilesInBlocks::block, FEDTrailer::check(), gather_cfg::cout, FEDTrailer::crc(), ctp7_mode_, FEDRawData::data(), data, debug_, TauDecayModes::dec, dmxFwId_, FEDTrailer::evtStatus(), fedData_, l1t::stage2::layer2::fedId, l1tstage2_dqm_sourceclient-live_cfg::fedId, fedIds_, l1tstage2emulator_dqm_sourceclient-live_cfg::feds, FEDTrailer::fragmentLength(), fwId_, fwOverride_, RecoTauValidation_cfi::header, LogDebug, minFeds_, mtf7_mode_, l1t::stage2::layer2::mp::offsetBoardId, amc13::Packet::parse(), jetsAK4_Puppi_cff::payload, amc13::Packet::payload(), prov_, FEDRawData::size(), slinkHeaderSize_, slinkTrailerSize_, command_line::start, tmtCheck_, FEDTrailer::ttsBits(), dt_dqm_sourceclient_common_cff::unpackers, warnsa_, and warnsb_.

126  {
127  using namespace edm;
128 
129  std::unique_ptr<UnpackerCollections> coll = prov_->getCollections(event);
130 
132  event.getByToken(fedData_, feds);
133 
134  if (!feds.isValid()) {
135  LogError("L1T") << "Cannot unpack: no FEDRawDataCollection found";
136  return;
137  }
138 
139  unsigned valid_count = 0;
140  for (const auto& fedId : fedIds_) {
141  const FEDRawData& l1tRcd = feds->FEDData(fedId);
142 
143  LogDebug("L1T") << "Found FEDRawDataCollection with ID " << fedId << " and size " << l1tRcd.size();
144 
147  if (l1tRcd.size() > 0) {
148  LogError("L1T") << "Cannot unpack: invalid L1T raw data (size = " << l1tRcd.size() << ") for ID " << fedId
149  << ". Returning empty collections!";
150  } else if (warnsa_ < 5) {
151  warnsa_++;
152  LogInfo("L1T") << "During unpacking, encountered empty L1T raw data (size = " << l1tRcd.size()
153  << ") for FED ID " << fedId << ".";
154  }
155  continue;
156  } else {
157  valid_count++;
158  }
159 
160  const unsigned char* data = l1tRcd.data();
162 
163  if (header.check()) {
164  LogDebug("L1T") << "Found SLink header:"
165  << " Trigger type " << header.triggerType() << " L1 event ID " << header.lvl1ID()
166  << " BX Number " << header.bxID() << " FED source " << header.sourceID() << " FED version "
167  << header.version();
168  } else {
169  LogWarning("L1T") << "Did not find a SLink header!";
170  }
171 
172  FEDTrailer trailer(data + (l1tRcd.size() - slinkTrailerSize_));
173 
174  if (trailer.check()) {
175  LogDebug("L1T") << "Found SLink trailer:"
176  << " Length " << trailer.fragmentLength() << " CRC " << trailer.crc() << " Status "
177  << trailer.evtStatus() << " Throttling bits " << trailer.ttsBits();
178  } else {
179  LogWarning("L1T") << "Did not find a SLink trailer!";
180  }
181 
182  // FIXME Hard-coded firmware version for first 74x MC campaigns.
183  // Will account for differences in the AMC payload, MP7 payload,
184  // and unpacker setup.
185  bool legacy_mc = fwOverride_ && ((fwId_ >> 24) == 0xff);
186 
187  amc13::Packet packet;
188  if (!packet.parse((const uint64_t*)data,
189  (const uint64_t*)(data + slinkHeaderSize_),
190  (l1tRcd.size() - slinkHeaderSize_ - slinkTrailerSize_) / 8,
191  header.lvl1ID(),
192  header.bxID(),
193  legacy_mc,
194  mtf7_mode_)) {
195  LogError("L1T") << "Could not extract AMC13 Packet.";
196  return;
197  }
198 
199  for (auto& amc : packet.payload()) {
200  if (amc.size() == 0)
201  continue;
202 
203  auto payload64 = amc.data();
204  const uint32_t* start = (const uint32_t*)payload64.get();
205  // Want to have payload size in 32 bit words, but AMC measures
206  // it in 64 bit words → factor 2.
207  const uint32_t* end = start + (amc.size() * 2);
208 
209  std::unique_ptr<Payload> payload;
210  if (ctp7_mode_) {
211  LogDebug("L1T") << "Using CTP7 mode";
212  // CTP7 uses userData in AMC header
213  payload = std::make_unique<CTP7Payload>(start, end, amc.header());
214  } else if (mtf7_mode_) {
215  LogDebug("L1T") << "Using MTF7 mode";
216  payload = std::make_unique<MTF7Payload>(start, end);
217  } else {
218  LogDebug("L1T") << "Using MP7 mode";
219  payload = std::make_unique<MP7Payload>(start, end, legacy_mc);
220  }
221  unsigned fw = payload->getAlgorithmFWVersion();
222  unsigned board = amc.blockHeader().getBoardID();
223  unsigned amc_no = amc.blockHeader().getAMCNumber();
224 
225  // Let parameterset value override FW version
226  if (fwOverride_) {
227  if (fedId == 1360)
228  fw = fwId_;
229  else if (fedId == 1366)
230  fw = dmxFwId_;
231  }
232 
233  auto unpackers = prov_->getUnpackers(fedId, board, amc_no, fw);
234 
235  // getBlock() returns a non-null unique_ptr on success
236  std::unique_ptr<Block> block;
237  while ((block = payload->getBlock()).get()) {
238  // only unpack the Calo Layer 2 MP TMT node if it has processed this BX
239  unsigned tmtId = board - l1t::stage2::layer2::mp::offsetBoardId + 1;
240  unsigned bxId = header.bxID();
241  unsigned unpackTMT = (!tmtCheck_ || ((tmtId - 1) == ((bxId - 1 + 3) % 9)));
242  unsigned isCaloL2TMT =
244 
245  if (!isCaloL2TMT || unpackTMT) {
246  if (debug_) {
247  std::cout << ">>> block to unpack <<<" << std::endl
248  << "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw()
249  << std::dec << " (ID " << block->header().getID() << ", size " << block->header().getSize()
250  << ", CapID 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getCapID()
251  << ")" << std::dec << std::endl;
252  for (const auto& word : block->payload()) {
253  if (debug_)
254  std::cout << "data: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec
255  << std::endl;
256  }
257  }
258 
259  auto unpacker = unpackers.find(block->header().getID());
260 
261  block->amc(amc.header());
262 
263  if (unpacker == unpackers.end()) {
264  LogDebug("L1T") << "Cannot find an unpacker for"
265  << "\n\tblock: ID " << block->header().getID() << ", size " << block->header().getSize()
266  << "\n\tAMC: # " << amc_no << ", board ID 0x" << std::hex << board << std::dec
267  << "\n\tFED ID " << fedId << ", and FW ID " << fw;
268  // TODO Handle error
269  } else if (!unpacker->second->unpack(*block, coll.get())) {
270  LogDebug("L1T") << "Error unpacking data for block ID " << block->header().getID() << ", AMC # " << amc_no
271  << ", board ID " << board << ", FED ID " << fedId << ", and FW ID " << fw << "!";
272  // TODO Handle error
273  }
274  }
275  }
276  }
277  }
278  if (valid_count < minFeds_) {
279  if (warnsb_ < 5) {
280  warnsb_++;
281  LogWarning("L1T") << "Unpacked " << valid_count << " non-empty FED IDs but minimum is set to " << minFeds_
282  << "\n";
283  }
284  }
285  }
Definition: start.py:1
unsigned int dmxFwId_
Definition: L1TRawToDigi.cc:60
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
Log< level::Error, false > LogError
uint64_t word
std::vector< int > fedIds_
Definition: L1TRawToDigi.cc:57
Log< level::Info, false > LogInfo
unsigned long long uint64_t
Definition: Time.h:13
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
unsigned int fwId_
Definition: L1TRawToDigi.cc:59
unsigned int minFeds_
Definition: L1TRawToDigi.cc:58
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
std::unique_ptr< PackingSetup > prov_
Definition: L1TRawToDigi.cc:63
std::vector< amc::Packet > payload() const
Definition: AMC13Spec.h:92
edm::EDGetTokenT< FEDRawDataCollection > fedData_
Definition: L1TRawToDigi.cc:56
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
Log< level::Warning, false > LogWarning
Definition: AMCSpec.h:8
Definition: event.py:1
#define LogDebug(id)

Member Data Documentation

◆ amc13HeaderSize_

int l1t::L1TRawToDigi::amc13HeaderSize_
private

Definition at line 70 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ amc13TrailerSize_

int l1t::L1TRawToDigi::amc13TrailerSize_
private

Definition at line 71 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ amcHeaderSize_

int l1t::L1TRawToDigi::amcHeaderSize_
private

Definition at line 68 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ amcTrailerSize_

int l1t::L1TRawToDigi::amcTrailerSize_
private

Definition at line 69 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ ctp7_mode_

bool l1t::L1TRawToDigi::ctp7_mode_
private

Definition at line 75 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ debug_

bool l1t::L1TRawToDigi::debug_
private

Definition at line 77 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ dmxFwId_

unsigned int l1t::L1TRawToDigi::dmxFwId_
private

Definition at line 60 of file L1TRawToDigi.cc.

Referenced by produce().

◆ fedData_

edm::EDGetTokenT<FEDRawDataCollection> l1t::L1TRawToDigi::fedData_
private

Definition at line 56 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ fedIds_

std::vector<int> l1t::L1TRawToDigi::fedIds_
private

Definition at line 57 of file L1TRawToDigi.cc.

Referenced by produce().

◆ fwId_

unsigned int l1t::L1TRawToDigi::fwId_
private

Definition at line 59 of file L1TRawToDigi.cc.

Referenced by produce().

◆ fwOverride_

bool l1t::L1TRawToDigi::fwOverride_
private

Definition at line 61 of file L1TRawToDigi.cc.

Referenced by produce().

◆ minFeds_

unsigned int l1t::L1TRawToDigi::minFeds_
private

Definition at line 58 of file L1TRawToDigi.cc.

Referenced by produce().

◆ mtf7_mode_

bool l1t::L1TRawToDigi::mtf7_mode_
private

Definition at line 76 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ prov_

std::unique_ptr<PackingSetup> l1t::L1TRawToDigi::prov_
private

Definition at line 63 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ slinkHeaderSize_

int l1t::L1TRawToDigi::slinkHeaderSize_
private

Definition at line 66 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ slinkTrailerSize_

int l1t::L1TRawToDigi::slinkTrailerSize_
private

Definition at line 67 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ tmtCheck_

bool l1t::L1TRawToDigi::tmtCheck_
private

Definition at line 73 of file L1TRawToDigi.cc.

Referenced by produce().

◆ warnsa_

int l1t::L1TRawToDigi::warnsa_
private

Definition at line 78 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

◆ warnsb_

int l1t::L1TRawToDigi::warnsb_
private

Definition at line 79 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().