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
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void beginLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) override
 
void beginRun (edm::Run const &, edm::EventSetup const &) override
 
void endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) override
 
void endRun (edm::Run const &, edm::EventSetup const &) override
 
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<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 45 of file L1TRawToDigi.cc.

Constructor & Destructor Documentation

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

Definition at line 94 of file L1TRawToDigi.cc.

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

94  :
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  {
104  fedData_ = consumes<FEDRawDataCollection>(config.getParameter<edm::InputTag>("InputLabel"));
105 
106  if (ctp7_mode_ and mtf7_mode_) {
107  throw cms::Exception("L1TRawToDigi") << "Can only use one unpacking mode concurrently!";
108  }
109 
111  prov_->registerProducts(*this);
112 
113  slinkHeaderSize_ = config.getUntrackedParameter<int>("lenSlinkHeader");
114  slinkTrailerSize_ = config.getUntrackedParameter<int>("lenSlinkTrailer");
115  amcHeaderSize_ = config.getUntrackedParameter<int>("lenAMCHeader");
116  amcTrailerSize_ = config.getUntrackedParameter<int>("lenAMCTrailer");
117  amc13HeaderSize_ = config.getUntrackedParameter<int>("lenAMC13Header");
118  amc13TrailerSize_ = config.getUntrackedParameter<int>("lenAMC13Trailer");
119 
120  debug_ = config.getUntrackedParameter<bool>("debug");
121  warnsa_ = 0;
122  warnsb_ = 0;
123  }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
unsigned int dmxFwId_
Definition: L1TRawToDigi.cc:65
std::vector< int > fedIds_
Definition: L1TRawToDigi.cc:62
std::unique_ptr< PackingSetup > make(const std::string &) const
unsigned int fwId_
Definition: L1TRawToDigi.cc:64
static const PackingSetupFactory * get()
unsigned int minFeds_
Definition: L1TRawToDigi.cc:63
std::unique_ptr< PackingSetup > prov_
Definition: L1TRawToDigi.cc:68
edm::EDGetTokenT< FEDRawDataCollection > fedData_
Definition: L1TRawToDigi.cc:58
L1TRawToDigi::~L1TRawToDigi ( )
override

Definition at line 126 of file L1TRawToDigi.cc.

127  {
128  }

Member Function Documentation

void l1t::L1TRawToDigi::beginLuminosityBlock ( edm::LuminosityBlock const &  ,
edm::EventSetup const &   
)
inlineoverrideprivate

Definition at line 57 of file L1TRawToDigi.cc.

57 {};
void l1t::L1TRawToDigi::beginRun ( edm::Run const &  ,
edm::EventSetup const &   
)
inlineoverrideprivate

Definition at line 55 of file L1TRawToDigi.cc.

55 {};
void l1t::L1TRawToDigi::endLuminosityBlock ( edm::LuminosityBlock const &  ,
edm::EventSetup const &   
)
inlineoverrideprivate

Definition at line 58 of file L1TRawToDigi.cc.

58 {};
void l1t::L1TRawToDigi::endRun ( edm::Run const &  ,
edm::EventSetup const &   
)
inlineoverrideprivate

Definition at line 56 of file L1TRawToDigi.cc.

56 {};
void L1TRawToDigi::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 306 of file L1TRawToDigi.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addUntracked(), DEFINE_FWK_MODULE, and AlCaHLTBitMon_QueryRunRegistry::string.

306  {
308  // These parameters are part of the L1T/HLT interface, avoid changing if possible:
309  desc.add<std::vector<int>>("FedIds", {})->setComment("required parameter: default value is invalid");
310  desc.add<std::string>("Setup", "")->setComment("required parameter: default value is invalid");
311  // These parameters have well defined default values and are not currently
312  // part of the L1T/HLT interface. They can be cleaned up or updated at will:
313  desc.add<unsigned int>("FWId",0)->setComment("Ignored unless FWOverride is true. Calo Stage1: 32 bits: if the first eight bits are 0xff, will read the 74x MC format.\n");
314  desc.add<unsigned int>("DmxFWId",0)->setComment("Ignored unless FWOverride is true. Calo Stage1: 32 bits: if the first eight bits are 0xff, will read the 74x MC format.\n");
315  desc.add<bool>("FWOverride", false)->setComment("Firmware version should be taken as FWId parameters");
316  desc.add<bool>("TMTCheck", true)->setComment("Flag for turning on/off Calo Layer 2 TMT node check");
317  desc.addUntracked<bool>("CTP7", false);
318  desc.addUntracked<bool>("MTF7", false);
319  desc.add<edm::InputTag>("InputLabel",edm::InputTag("rawDataCollector"));
320  desc.addUntracked<int>("lenSlinkHeader", 8);
321  desc.addUntracked<int>("lenSlinkTrailer", 8);
322  desc.addUntracked<int>("lenAMCHeader", 8);
323  desc.addUntracked<int>("lenAMCTrailer", 0);
324  desc.addUntracked<int>("lenAMC13Header", 8);
325  desc.addUntracked<int>("lenAMC13Trailer", 8);
326  desc.addUntracked<bool>("debug", false)->setComment("turn on verbose output");
327  desc.add<unsigned int>("MinFeds", 0)->setComment("optional parameter: warn if less than MinFeds non-empty FED ids unpacked.");
328  descriptions.add("l1tRawToDigi", desc);
329  }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void L1TRawToDigi::produce ( edm::Event event,
const edm::EventSetup setup 
)
overrideprivate

Definition at line 137 of file L1TRawToDigi.cc.

References amc13HeaderSize_, amc13TrailerSize_, amcHeaderSize_, l1t::stage2::layer2::demux::amcSlotNum, amcTrailerSize_, groupFilesInBlocks::block, FEDHeader::bxID(), FEDHeader::check(), FEDTrailer::check(), coll, gather_cfg::cout, FEDTrailer::crc(), ctp7_mode_, FEDRawData::data(), data, debug_, TauDecayModes::dec, dmxFwId_, end, FEDTrailer::evtStatus(), FEDRawDataCollection::FEDData(), fedData_, l1t::stage2::layer2::fedId, fedIds_, FEDTrailer::fragmentLength(), fwId_, fwOverride_, RecoTauValidation_cfi::header, edm::HandleBase::isValid(), LogDebug, FEDHeader::lvl1ID(), minFeds_, mtf7_mode_, l1t::stage2::layer2::mp::offsetBoardId, amc13::Packet::parse(), jets_cff::payload, amc13::Packet::payload(), prov_, FEDRawData::size(), slinkHeaderSize_, slinkTrailerSize_, FEDHeader::sourceID(), tmtCheck_, FEDHeader::triggerType(), FEDTrailer::ttsBits(), FEDHeader::version(), warnsa_, and warnsb_.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

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

Member Data Documentation

int l1t::L1TRawToDigi::amc13HeaderSize_
private

Definition at line 75 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

int l1t::L1TRawToDigi::amc13TrailerSize_
private

Definition at line 76 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

int l1t::L1TRawToDigi::amcHeaderSize_
private

Definition at line 73 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

int l1t::L1TRawToDigi::amcTrailerSize_
private

Definition at line 74 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

bool l1t::L1TRawToDigi::ctp7_mode_
private

Definition at line 80 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

bool l1t::L1TRawToDigi::debug_
private

Definition at line 82 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

unsigned int l1t::L1TRawToDigi::dmxFwId_
private

Definition at line 65 of file L1TRawToDigi.cc.

Referenced by produce().

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

Definition at line 58 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

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

Definition at line 62 of file L1TRawToDigi.cc.

Referenced by produce().

unsigned int l1t::L1TRawToDigi::fwId_
private

Definition at line 64 of file L1TRawToDigi.cc.

Referenced by produce().

bool l1t::L1TRawToDigi::fwOverride_
private

Definition at line 66 of file L1TRawToDigi.cc.

Referenced by produce().

unsigned int l1t::L1TRawToDigi::minFeds_
private

Definition at line 63 of file L1TRawToDigi.cc.

Referenced by produce().

bool l1t::L1TRawToDigi::mtf7_mode_
private

Definition at line 81 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

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

Definition at line 68 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

int l1t::L1TRawToDigi::slinkHeaderSize_
private

Definition at line 71 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

int l1t::L1TRawToDigi::slinkTrailerSize_
private

Definition at line 72 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

bool l1t::L1TRawToDigi::tmtCheck_
private

Definition at line 78 of file L1TRawToDigi.cc.

Referenced by produce().

int l1t::L1TRawToDigi::warnsa_
private

Definition at line 83 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().

int l1t::L1TRawToDigi::warnsb_
private

Definition at line 84 of file L1TRawToDigi.cc.

Referenced by L1TRawToDigi(), and produce().