CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
RPCTwinMuxRawToDigi Class Reference

#include <RPCTwinMuxRawToDigi.h>

Inheritance diagram for RPCTwinMuxRawToDigi:
edm::stream::EDProducer<>

Public Member Functions

void beginRun (edm::Run const &run, edm::EventSetup const &setup) override
 
void produce (edm::Event &event, edm::EventSetup const &setup) override
 
 RPCTwinMuxRawToDigi (edm::ParameterSet const &config)
 
 ~RPCTwinMuxRawToDigi () 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 compute_crc_64bit (std::uint16_t &crc, std::uint64_t const &word)
 
static void fillDescriptions (edm::ConfigurationDescriptions &descs)
 

Protected Member Functions

bool processBlock (int fed, std::uint64_t const *&word, std::uint64_t const *word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters, std::set< std::pair< RPCDetId, RPCDigi > > &digis) const
 
bool processCDFHeaders (int fed, std::uint64_t const *&word, std::uint64_t const *&word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters) const
 
bool processCDFTrailers (int fed, unsigned int nwords, std::uint64_t const *&word, std::uint64_t const *&word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters) const
 
void processRPCRecord (int fed, unsigned int amc_number, unsigned int bx_counter, rpctwinmux::RPCRecord const &record, RPCAMCLinkCounters &counters, std::set< std::pair< RPCDetId, RPCDigi > > &digis, int bx_min, int bx_max, unsigned int link, unsigned int link_max) const
 
bool processTwinMux (int fed, unsigned int amc_number, unsigned int size, std::uint64_t const *&word, std::uint64_t const *word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters, std::set< std::pair< RPCDetId, RPCDigi > > &digis) const
 
void putCounters (edm::Event &event, std::unique_ptr< RPCAMCLinkCounters > counters)
 
void putRPCDigis (edm::Event &event, std::set< std::pair< RPCDetId, RPCDigi > > const &digis)
 

Protected Attributes

int bx_max_
 
int bx_min_
 
bool calculate_crc_
 
edm::ESHandle< RPCLBLinkMapes_lb_link_map_
 
edm::ESHandle< RPCAMCLinkMapes_tm_link_map_
 
edm::ESWatcher< RPCTwinMuxLinkMapRcdes_tm_link_map_watcher_
 
std::vector< int > feds_
 
bool fill_counters_
 
edm::EDGetTokenT< FEDRawDataCollectionraw_token_
 

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 30 of file RPCTwinMuxRawToDigi.h.

Constructor & Destructor Documentation

RPCTwinMuxRawToDigi::RPCTwinMuxRawToDigi ( edm::ParameterSet const &  config)

Definition at line 24 of file RPCTwinMuxRawToDigi.cc.

References fill_counters_, edm::ParameterSet::getParameter(), and raw_token_.

25  : calculate_crc_(config.getParameter<bool>("calculateCRC"))
26  , fill_counters_(config.getParameter<bool>("fillCounters"))
27  , bx_min_(config.getParameter<int>("bxMin"))
28  , bx_max_(config.getParameter<int>("bxMax"))
29 {
30  produces<RPCDigiCollection>();
31  if (fill_counters_) {
32  produces<RPCAMCLinkCounters>();
33  }
34  raw_token_ = consumes<FEDRawDataCollection>(config.getParameter<edm::InputTag>("inputTag"));
35 }
Definition: config.py:1
edm::EDGetTokenT< FEDRawDataCollection > raw_token_
RPCTwinMuxRawToDigi::~RPCTwinMuxRawToDigi ( )
override

Definition at line 37 of file RPCTwinMuxRawToDigi.cc.

38 {}

Member Function Documentation

void RPCTwinMuxRawToDigi::beginRun ( edm::Run const &  run,
edm::EventSetup const &  setup 
)
override

Definition at line 60 of file RPCTwinMuxRawToDigi.cc.

References edm::ESWatcher< T >::check(), es_tm_link_map_, es_tm_link_map_watcher_, feds_, edm::EventSetup::get(), and RPCAMCLinkMap::getMap().

61 {
64  std::set<int> feds;
65  for (auto const & tm_link : es_tm_link_map_->getMap()) {
66  feds.insert(tm_link.first.getFED());
67  }
68  feds_.assign(feds.begin(), feds.end());
69  }
70 }
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
map_type & getMap()
Definition: RPCAMCLinkMap.h:28
edm::ESWatcher< RPCTwinMuxLinkMapRcd > es_tm_link_map_watcher_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::vector< int > feds_
edm::ESHandle< RPCAMCLinkMap > es_tm_link_map_
void RPCTwinMuxRawToDigi::compute_crc_64bit ( std::uint16_t &  crc,
std::uint64_t const &  word 
)
static

Definition at line 40 of file RPCTwinMuxRawToDigi.cc.

References evf::compute_crc_8bit().

Referenced by processBlock(), processCDFHeaders(), processTwinMux(), and produce().

41 { // overcome constness problem evf::compute_crc_64bit
42  unsigned char const * uchars(reinterpret_cast<unsigned char const *>(&word));
43  for (unsigned char const * uchar = uchars + 7
44  ; uchar >= uchars ; --uchar) {
45  crc = evf::compute_crc_8bit(crc, *uchar);
46  }
47 }
unsigned short compute_crc_8bit(unsigned short crc, unsigned char data)
Definition: CRC16.h:79
void RPCTwinMuxRawToDigi::fillDescriptions ( edm::ConfigurationDescriptions descs)
static

Definition at line 49 of file RPCTwinMuxRawToDigi.cc.

References edm::ConfigurationDescriptions::add(), and edm::ParameterSetDescription::add().

50 {
52  desc.add<edm::InputTag>("inputTag", edm::InputTag("rawDataCollector", ""));
53  desc.add<bool>("calculateCRC", true);
54  desc.add<bool>("fillCounters", true);
55  desc.add<int>("bxMin", -2);
56  desc.add<int>("bxMax", 2);
57  descs.add("rpcTwinMuxRawToDigi", desc);
58 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool RPCTwinMuxRawToDigi::processBlock ( int  fed,
std::uint64_t const *&  word,
std::uint64_t const *  word_end,
std::uint16_t &  crc,
RPCAMCLinkCounters counters,
std::set< std::pair< RPCDetId, RPCDigi > > &  digis 
) const
protected

Definition at line 227 of file RPCTwinMuxRawToDigi.cc.

References RPCAMCLinkCounters::add(), amc, RPCAMCLinkEvents::amc_amc13_evc_bc_invalid_, calculate_crc_, compute_crc_64bit(), RPCAMCLinkEvents::fed_amc13_block_incomplete_, fill_counters_, rpctwinmux::BlockAMCContent::getAMCNumber(), rpctwinmux::BlockHeader::getNAMC(), rpctwinmux::BlockAMCContent::getSize(), rpctwinmux::BlockAMCContent::isValid(), LogDebug, processTwinMux(), and RPCAMCLink::wildcard_.

Referenced by produce().

232 {
233  // Block Header and Content
234  rpctwinmux::BlockHeader block_header(*word);
235  if (calculate_crc_) {
236  compute_crc_64bit(crc, *word);
237  }
238  ++word;
239 
240  unsigned int n_amc(block_header.getNAMC());
241  if (word + n_amc + 1 >= word_end) {
242  if (fill_counters_) {
244  }
245  edm::LogWarning("RPCTwinMuxRawToDigi") << "Block can not be complete for FED " << fed;
246  word = word_end;
247  return false;
248  }
249 
250  std::vector<std::pair<unsigned int, unsigned int> > amc_size_map;
251  for (unsigned int amc = 0 ; amc < n_amc ; ++amc) {
252  LogDebug("RPCTwinMuxRawToDigi") << "Block AMC " << amc;
253  rpctwinmux::BlockAMCContent amc_content(*word);
254  if (calculate_crc_) {
255  compute_crc_64bit(crc, *word);
256  }
257  ++word;
258 
259  amc_size_map.push_back(std::make_pair(amc_content.getAMCNumber(), amc_content.getSize()));
260  if (!amc_content.isValid()) {
261  if (fill_counters_) {
262  counters.add(RPCAMCLinkEvents::amc_amc13_evc_bc_invalid_, RPCAMCLink(fed, amc_content.getAMCNumber()));
263  }
264  edm::LogWarning("RPCTwinMuxRawToDigi") << "BlockAMCContent is reporting an invalid "
265  << "Event Counter or Bunch Counter for FED " << fed
266  << ", AMC " << amc_content.getAMCNumber();
267  }
268  }
269 
270  for (std::pair<unsigned int, unsigned int> const & amc_size : amc_size_map) {
271  processTwinMux(fed, amc_size.first, amc_size.second
272  , word, word_end
273  , crc, counters
274  , digis);
275  }
276 
277  if (word < word_end) {
278  rpctwinmux::BlockTrailer block_trailer(*word);
279  if (calculate_crc_) {
280  compute_crc_64bit(crc, *word);
281  }
282  ++word;
283  return true;
284  } else {
285  return false;
286  }
287 }
#define LogDebug(id)
static unsigned int const amc_amc13_evc_bc_invalid_
bool processTwinMux(int fed, unsigned int amc_number, unsigned int size, std::uint64_t const *&word, std::uint64_t const *word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters, std::set< std::pair< RPCDetId, RPCDigi > > &digis) const
double amc
Definition: hdecay.h:20
static unsigned int const fed_amc13_block_incomplete_
void add(unsigned int event, RPCAMCLink const &link, unsigned int count=1)
static void compute_crc_64bit(std::uint16_t &crc, std::uint64_t const &word)
Definition: AMCSpec.h:8
bool RPCTwinMuxRawToDigi::processCDFHeaders ( int  fed,
std::uint64_t const *&  word,
std::uint64_t const *&  word_end,
std::uint16_t &  crc,
RPCAMCLinkCounters counters 
) const
protected

Definition at line 150 of file RPCTwinMuxRawToDigi.cc.

References RPCAMCLinkCounters::add(), calculate_crc_, FEDHeader::check(), compute_crc_64bit(), TauDecayModes::dec, RPCAMCLinkEvents::fed_header_check_fail_, RPCAMCLinkEvents::fed_header_id_mismatch_, fill_counters_, RecoTauValidation_cfi::header, LogDebug, FEDHeader::sourceID(), and RPCAMCLink::wildcard_.

Referenced by produce().

154 {
155  bool more_headers(true);
156  for ( ; word < word_end && more_headers ; ++word) {
157  if (calculate_crc_) {
158  compute_crc_64bit(crc, *word);
159  }
160 
161  LogDebug("RPCTwinMuxRawToDigi") << "CDF Header " << std::hex << *word << std::dec;
162  FEDHeader header(reinterpret_cast<unsigned char const *>(word));
163  if (!header.check()) {
164  if (fill_counters_) {
166  }
167  edm::LogWarning("RPCTwinMuxRawToDigi") << "FED Header check failed for FED id " << fed;
168  ++word;
169  break;
170  }
171  if (header.sourceID() != fed) {
172  if (fill_counters_) {
174  }
175  edm::LogWarning("RPCTwinMuxRawToDigi") << "FED Header Source ID " << header.sourceID()
176  << " does not match requested FED id " << fed;
177  break;
178  }
179 
180  // moreHeaders() not used
181  // more_headers = header.moreHeaders();
182  more_headers = false;
183  }
184 
185  return !more_headers;
186 }
#define LogDebug(id)
static unsigned int const fed_header_check_fail_
static unsigned int const fed_header_id_mismatch_
void add(unsigned int event, RPCAMCLink const &link, unsigned int count=1)
static void compute_crc_64bit(std::uint16_t &crc, std::uint64_t const &word)
bool RPCTwinMuxRawToDigi::processCDFTrailers ( int  fed,
unsigned int  nwords,
std::uint64_t const *&  word,
std::uint64_t const *&  word_end,
std::uint16_t &  crc,
RPCAMCLinkCounters counters 
) const
protected

Definition at line 188 of file RPCTwinMuxRawToDigi.cc.

References RPCAMCLinkCounters::add(), FEDTrailer::check(), TauDecayModes::dec, RPCAMCLinkEvents::fed_trailer_check_fail_, RPCAMCLinkEvents::fed_trailer_length_mismatch_, fill_counters_, FEDTrailer::fragmentLength(), LogDebug, and RPCAMCLink::wildcard_.

Referenced by produce().

192 {
193  bool more_trailers(true);
194  for (--word_end ; word_end > word && more_trailers ; --word_end) {
195  FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
196  LogDebug("RPCTwinMuxRawToDigi") << "CDF Trailer " << std::hex << *word_end << std::dec
197  << ", length " << trailer.fragmentLength();
198  if (!trailer.check()) {
199  if (fill_counters_) {
201  }
202  edm::LogWarning("RPCTwinMuxRawToDigi") << "FED Trailer check failed for FED id " << fed;
203  --word_end;
204  break;
205  }
206  if (trailer.fragmentLength() != nwords) {
207  if (fill_counters_) {
209  }
210  edm::LogWarning("RPCTwinMuxRawToDigi") << "FED Trailer length " << trailer.fragmentLength()
211  << " does not match actual data size " << nwords
212  << " for FED id " << fed;
213  --word_end;
214  break;
215  }
216 
217  // moreTrailers() not used
218  // more_trailers = trailer.moreTrailers();
219  more_trailers = false;
220  }
221 
222  ++word_end;
223 
224  return !more_trailers;
225 }
#define LogDebug(id)
static unsigned int const fed_trailer_length_mismatch_
void add(unsigned int event, RPCAMCLink const &link, unsigned int count=1)
static unsigned int const fed_trailer_check_fail_
void RPCTwinMuxRawToDigi::processRPCRecord ( int  fed,
unsigned int  amc_number,
unsigned int  bx_counter,
rpctwinmux::RPCRecord const &  record,
RPCAMCLinkCounters counters,
std::set< std::pair< RPCDetId, RPCDigi > > &  digis,
int  bx_min,
int  bx_max,
unsigned int  link,
unsigned int  link_max 
) const
protected

Definition at line 400 of file RPCTwinMuxRawToDigi.cc.

References RPCAMCLinkCounters::add(), RPCAMCLinkEvents::amc_event_, RPCAMCLinkEvents::amc_link_invalid_, data, TauDecayModes::dec, es_lb_link_map_, es_tm_link_map_, fill_counters_, rpctwinmux::RPCRecord::getBXOffset(), RPCLBLinkMap::getMap(), RPCAMCLinkMap::getMap(), rpctwinmux::RPCRecord::getRecord(), RPCFebConnector::getRPCDetId(), rpctwinmux::RPCRecord::getRPCLinkRecord(), RPCFebConnector::getStrip(), RPCAMCLinkEvents::input_connector_invalid_, RPCAMCLinkEvents::input_connector_not_used_, RPCAMCLinkEvents::input_eod_, RPCAMCLinkEvents::input_event_, RPCAMCLinkEvents::input_lb_invalid_, RPCAMCLinkEvents::input_link_ack_fail_, RPCAMCLinkEvents::input_link_error_, createfilelist::int, LogDebug, RPCLBLink::max_connector_, RPCLBLink::max_linkboard_, RPCLBLink::setConnector(), RPCLBLink::setLinkBoard(), digitizers_cfi::strip, and globals_cff::x1.

Referenced by processTwinMux().

407 {
408  LogDebug("RPCTwinMuxRawToDigi") << "RPCRecord " << std::hex << record.getRecord()[0]
409  << ", " << record.getRecord()[1] << std::dec << std::endl;
410  int bx_offset(record.getBXOffset());
411  RPCAMCLink tm_link(fed, amc_number);
412  for ( ; link <= link_max ; ++link) {
413  tm_link.setAMCInput(link);
414  rpctwinmux::RPCLinkRecord link_record(record.getRPCLinkRecord(link));
415 
416  if (link_record.isError()) {
417  if (fill_counters_ && bx_offset == 0) {
418  counters.add(RPCAMCLinkEvents::input_link_error_, tm_link);
419  }
420  LogDebug("RPCTwinMuxRawToDigi") << "Link in error for " << tm_link;
421  continue;
422  } else if (!link_record.isAcknowledge()) {
423  if (fill_counters_ && bx_offset == 0) {
424  counters.add(RPCAMCLinkEvents::input_link_ack_fail_, tm_link);
425  }
426  LogDebug("RPCTwinMuxRawToDigi") << "Link without acknowledge for " << tm_link;
427  continue;
428  }
429 
430  if (!link_record.getPartitionData()) {
431  continue;
432  }
433 
434  int bx(bx_offset - (int)(link_record.getDelay()));
435  LogDebug("RPCTwinMuxRawToDigi") << "RPC BX " << bx << " for offset " << bx_offset;
436 
437  if (fill_counters_ && bx == 0 && link_record.isEOD()) { // EOD comes at the last delay
438  counters.add(RPCAMCLinkEvents::input_eod_, tm_link);
439  }
440 
441  RPCAMCLinkMap::map_type::const_iterator tm_link_it = es_tm_link_map_->getMap().find(tm_link);
442  if (tm_link_it == es_tm_link_map_->getMap().end()) {
443  if (fill_counters_ && bx_offset == 0) {
444  counters.add(RPCAMCLinkEvents::amc_link_invalid_, RPCAMCLink(fed, amc_number));
445  }
446  LogDebug("RPCTwinMuxRawToDigi") << "Skipping unknown TwinMuxLink " << tm_link;
447  continue;
448  }
449 
450  RPCLBLink lb_link = tm_link_it->second;
451 
452  if (link_record.getLinkBoard() > (unsigned int)RPCLBLink::max_linkboard_) {
453  if (fill_counters_ && bx_offset == 0) {
454  counters.add(RPCAMCLinkEvents::input_lb_invalid_, tm_link);
455  }
456  LogDebug("RPCTwinMuxRawToDigi") << "Skipping invalid LinkBoard " << link_record.getLinkBoard()
457  << " for record " << link << " (" << std::hex << link_record.getRecord()
458  << " in " << record.getRecord()[0] << ':' << record.getRecord()[1] << std::dec
459  << " from " << tm_link;
460  continue;
461  }
462 
463  if (link_record.getConnector() > (unsigned int)RPCLBLink::max_connector_) {
464  if (fill_counters_ && bx_offset == 0) {
466  }
467  LogDebug("RPCTwinMuxRawToDigi") << "Skipping invalid Connector " << link_record.getConnector()
468  << " for record " << link << " (" << std::hex << link_record.getRecord()
469  << " in " << record.getRecord()[0] << ':' << record.getRecord()[1] << std::dec
470  << ") from " << tm_link;
471  continue;
472  }
473 
474  lb_link.setLinkBoard(link_record.getLinkBoard());
475  lb_link.setConnector(link_record.getConnector());
476 
477  RPCLBLinkMap::map_type::const_iterator lb_link_it = es_lb_link_map_->getMap().find(lb_link);
478  if (lb_link_it == es_lb_link_map_->getMap().end()) {
479  if (fill_counters_ && bx_offset == 0) {
481  }
482  LogDebug("RPCTwinMuxRawToDigi") << "Could not find " << lb_link
483  << " for record " << link << " (" << std::hex << link_record.getRecord()
484  << " in " << record.getRecord()[0] << ':' << record.getRecord()[1] << std::dec
485  << ") from " << tm_link;
486  continue;
487  }
488 
489  if (bx < bx_min || bx > bx_max) {
490  continue;
491  }
492 
493  if (fill_counters_ && bx == 0) {
494  counters.add(RPCAMCLinkEvents::amc_event_, RPCAMCLink(fed, amc_number));
495  counters.add(RPCAMCLinkEvents::input_event_, tm_link);
496  }
497 
498  RPCFebConnector const & feb_connector(lb_link_it->second);
499  RPCDetId det_id(feb_connector.getRPCDetId());
500  unsigned int channel_offset(link_record.getPartition() ? 9 : 1); // 1-16
501  std::uint8_t data(link_record.getPartitionData());
502 
503  for (unsigned int channel = 0 ; channel < 8 ; ++channel) {
504  if (data & (0x1 << channel)) {
505  unsigned int strip(feb_connector.getStrip(channel + channel_offset));
506  if (strip) {
507  digis.insert(std::pair<RPCDetId, RPCDigi>(det_id, RPCDigi(strip, bx)));
508  LogDebug("RPCTwinMuxRawToDigi") << "RPCDigi " << det_id.rawId()
509  << ", " << strip << ", " << bx;
510  }
511  }
512  }
513 
514  // rpctwinmux::RPCBXRecord checks postponed: not implemented in firmware as planned and tbd if design or firmware should change
515 
516  }
517 }
#define LogDebug(id)
static unsigned int const input_connector_not_used_
static unsigned int const amc_event_
JetCorrectorParameters::Record record
Definition: classes.h:7
static unsigned int const input_link_error_
static unsigned int const input_lb_invalid_
static unsigned int const amc_link_invalid_
map_type & getMap()
Definition: RPCAMCLinkMap.h:28
map_type & getMap()
Definition: RPCLBLinkMap.h:28
static unsigned int const input_event_
void add(unsigned int event, RPCAMCLink const &link, unsigned int count=1)
static unsigned int const input_link_ack_fail_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
edm::ESHandle< RPCLBLinkMap > es_lb_link_map_
edm::ESHandle< RPCAMCLinkMap > es_tm_link_map_
static unsigned int const input_eod_
static unsigned int const input_connector_invalid_
bool RPCTwinMuxRawToDigi::processTwinMux ( int  fed,
unsigned int  amc_number,
unsigned int  size,
std::uint64_t const *&  word,
std::uint64_t const *  word_end,
std::uint16_t &  crc,
RPCAMCLinkCounters counters,
std::set< std::pair< RPCDetId, RPCDigi > > &  digis 
) const
protected

Definition at line 289 of file RPCTwinMuxRawToDigi.cc.

References RPCAMCLinkCounters::add(), RPCAMCLinkEvents::amc_number_mismatch_, RPCAMCLinkEvents::amc_payload_incomplete_, bx_max_, bx_min_, calculate_crc_, compute_crc_64bit(), TauDecayModes::dec, RPCAMCLinkEvents::fed_amc13_amc_number_invalid_, fill_counters_, rpctwinmux::TwinMuxHeader::getAMCNumber(), rpctwinmux::TwinMuxHeader::getBXCounter(), rpctwinmux::TwinMuxHeader::getRPCBXMax(), rpctwinmux::TwinMuxHeader::getRPCBXMin(), rpctwinmux::TwinMuxRecord::getType(), rpctwinmux::TwinMuxHeader::hasRPCBXWindow(), RecoTauValidation_cfi::header, LogDebug, SiStripPI::max, RPCAMCLink::max_amcnumber_, min(), processRPCRecord(), rpctwinmux::RPCRecord::reset(), rpctwinmux::TwinMuxRecord::rpc_first_type_, rpctwinmux::TwinMuxRecord::rpc_second_type_, rpctwinmux::RPCRecord::set(), findQualityFiles::size, and RPCAMCLink::wildcard_.

Referenced by processBlock().

294 {
295  LogDebug("RPCTwinMuxRawToDigi") << "TwinMux AMC#" << amc_number << ", size " << size;
296  if (!size) {
297  return true;
298  }
299  if (amc_number > (unsigned int)RPCAMCLink::max_amcnumber_) {
300  if (fill_counters_) {
302  }
303  edm::LogWarning("RPCTwinMuxRawToDigi") << "Invalid AMC Number " << amc_number
304  << " for FED " << fed;
305  if (calculate_crc_) {
306  for ( ; size > 0 ; --size, ++word) {
307  compute_crc_64bit(crc, *word);
308  }
309  } else {
310  word += size;
311  }
312  return false;
313  }
314  if (word + size >= word_end || size < 3) {
315  if (fill_counters_) {
316  counters.add(RPCAMCLinkEvents::amc_payload_incomplete_, RPCAMCLink(fed, amc_number));
317  }
318  edm::LogWarning("RPCTwinMuxRawToDigi") << "TwinMux Data can not be complete for FED " << fed << " AMC #" << amc_number;
319  if (calculate_crc_) {
320  for ( ; size > 0 ; --size, ++word) {
321  compute_crc_64bit(crc, *word);
322  }
323  } else {
324  word += size;
325  }
326  return false;
327  }
328 
330  unsigned int bx_counter(header.getBXCounter());
331  if (calculate_crc_) {
332  compute_crc_64bit(crc, *word); ++word;
333  compute_crc_64bit(crc, *word); ++word;
334  } else {
335  word += 2;
336  }
337  size -= 2;
338 
339  if (amc_number != header.getAMCNumber()) {
340  if (fill_counters_) {
341  counters.add(RPCAMCLinkEvents::amc_number_mismatch_, RPCAMCLink(fed, amc_number));
342  }
343  edm::LogWarning("RPCTwinMuxRawToDigi") << "AMC Number inconsistent in TwinMuxHeader vs BlockAMCContent: " << header.getAMCNumber()
344  << " vs " << amc_number;
345  if (calculate_crc_) {
346  for ( ; size > 0 ; --size, ++word) {
347  compute_crc_64bit(crc, *word);
348  }
349  } else {
350  word += size;
351  }
352  return false;
353  }
354 
355  int bx_min(bx_min_), bx_max(bx_max_);
356  if (header.hasRPCBXWindow()) {
357  bx_min = std::max(bx_min, header.getRPCBXMin());
358  bx_max = std::min(bx_max, header.getRPCBXMax());
359  LogDebug("RPCTwinMuxRawToDigi") << "BX range set to " << bx_min << ", " << bx_max;
360  }
361 
362  bool has_first_rpc_word(false);
363  rpctwinmux::RPCRecord rpc_record;
364  for ( ; size > 1 ; --size, ++word) {
365  if (calculate_crc_) {
366  compute_crc_64bit(crc, *word);
367  }
368  unsigned int type(rpctwinmux::TwinMuxRecord::getType(*word));
369  LogDebug("RPCTwinMuxRawToDigi") << "TwinMux data type " << std::hex << type << std::dec;
371  if (has_first_rpc_word) {
372  processRPCRecord(fed, amc_number, bx_counter, rpc_record, counters, digis, bx_min, bx_max, 0, 1);
373  }
374  rpc_record.reset();
375  rpc_record.set(0, *word);
376  has_first_rpc_word = true;
378  if (!has_first_rpc_word) {
379  edm::LogWarning("RPCTwinMuxRawToDigi") << "Received second RPC word without first";
380  } else {
381  rpc_record.set(1, *word);
382  processRPCRecord(fed, amc_number, bx_counter, rpc_record, counters, digis, bx_min, bx_max, 0, 4);
383  has_first_rpc_word = false;
384  }
385  }
386  }
387  if (has_first_rpc_word) {
388  processRPCRecord(fed, amc_number, bx_counter, rpc_record, counters, digis, bx_min, bx_max, 0, 1);
389  }
390 
391  rpctwinmux::TwinMuxTrailer trailer(*word);
392  LogDebug("RPCTwinMuxRawToDigi") << "TwinMux Trailer " << std::hex << *word << std::dec;
393  if (calculate_crc_) {
394  compute_crc_64bit(crc, *word);
395  }
396  ++word;
397  return true;
398 }
#define LogDebug(id)
size
Write out results.
type
Definition: HCALResponse.h:21
static unsigned int const fed_amc13_amc_number_invalid_
static unsigned int const amc_payload_incomplete_
void processRPCRecord(int fed, unsigned int amc_number, unsigned int bx_counter, rpctwinmux::RPCRecord const &record, RPCAMCLinkCounters &counters, std::set< std::pair< RPCDetId, RPCDigi > > &digis, int bx_min, int bx_max, unsigned int link, unsigned int link_max) const
void set(unsigned int word, std::uint64_t const record)
unsigned int getType() const
T min(T a, T b)
Definition: MathUtil.h:58
static unsigned int const rpc_first_type_
static unsigned int const amc_number_mismatch_
void add(unsigned int event, RPCAMCLink const &link, unsigned int count=1)
static unsigned int const rpc_second_type_
static void compute_crc_64bit(std::uint16_t &crc, std::uint64_t const &word)
void RPCTwinMuxRawToDigi::produce ( edm::Event event,
edm::EventSetup const &  setup 
)
override

Definition at line 72 of file RPCTwinMuxRawToDigi.cc.

References calculate_crc_, compute_crc_64bit(), FEDTrailer::crc(), FEDRawData::data(), es_lb_link_map_, es_tm_link_map_, RPCAMCLinkEvents::fed_event_, RPCAMCLinkEvents::fed_trailer_crc_mismatch_, FEDRawDataCollection::FEDData(), feds_, fill_counters_, edm::EventSetup::get(), LogDebug, eostools::move(), processBlock(), processCDFHeaders(), processCDFTrailers(), putCounters(), putRPCDigis(), raw_token_, FEDRawData::size(), and RPCAMCLink::wildcard_.

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

73 {
74  // Get EventSetup Electronics Maps
77 
78  // Get RAW Data
79  edm::Handle<FEDRawDataCollection> raw_data_collection;
80  event.getByToken(raw_token_, raw_data_collection);
81 
82  std::set<std::pair<RPCDetId, RPCDigi> > rpc_digis;
83  std::unique_ptr<RPCAMCLinkCounters> counters(new RPCAMCLinkCounters());
84 
85  // Loop over the FEDs
86  for (int fed : feds_) {
87 
88  if (fill_counters_) {
90  }
91 
92  std::uint16_t crc(0xffff);
93 
94  FEDRawData const & raw_data = raw_data_collection->FEDData(fed);
95  unsigned int nwords(raw_data.size() / sizeof(std::uint64_t));
96  if (!nwords) {
97  continue;
98  }
99 
100  std::uint64_t const * word(reinterpret_cast<std::uint64_t const *>(raw_data.data()));
101  std::uint64_t const * word_end = word + nwords;
102 
103  LogDebug("RPCTwinMuxRawToDigi") << "Handling FED " << fed << " with length " << nwords;
104 
105  // Handle the CDF Headers
106  if (!processCDFHeaders(fed
107  , word, word_end
108  , crc, *counters)) {
109  continue;
110  }
111 
112  // Handle the CDF Trailers
113  if (!processCDFTrailers(fed, nwords
114  , word, word_end
115  , crc, *counters)) {
116  continue;
117  }
118 
119  // Loop over the Blocks
120  while (word < word_end) {
121  processBlock(fed
122  , word, word_end
123  , crc, *counters, rpc_digis);
124  }
125 
126  // Complete CRC check with trailer
127  if (calculate_crc_) {
128  word = word_end;
129  word_end = reinterpret_cast<std::uint64_t const *>(raw_data.data()) + nwords - 1;
130  for ( ; word < word_end ; ++word) {
131  compute_crc_64bit(crc, *word);
132  }
133  compute_crc_64bit(crc, (*word & 0xffffffff0000ffff)); // trailer excluding crc
134  FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
135  if ((unsigned int)(trailer.crc()) != crc) {
136  if (fill_counters_) {
138  }
139  edm::LogWarning("RPCTwinMuxRawToDigi") << "FED Trailer CRC doesn't match for FED id " << fed;
140  }
141  }
142  }
143 
144  putRPCDigis(event, rpc_digis);
145  if (fill_counters_) {
146  putCounters(event, std::move(counters));
147  }
148 }
#define LogDebug(id)
static unsigned int const fed_trailer_crc_mismatch_
bool processCDFHeaders(int fed, std::uint64_t const *&word, std::uint64_t const *&word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters) const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
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
edm::EDGetTokenT< FEDRawDataCollection > raw_token_
bool processBlock(int fed, std::uint64_t const *&word, std::uint64_t const *word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters, std::set< std::pair< RPCDetId, RPCDigi > > &digis) const
bool processCDFTrailers(int fed, unsigned int nwords, std::uint64_t const *&word, std::uint64_t const *&word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters) const
static unsigned int const fed_event_
unsigned long long uint64_t
Definition: Time.h:15
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::vector< int > feds_
void putCounters(edm::Event &event, std::unique_ptr< RPCAMCLinkCounters > counters)
static void compute_crc_64bit(std::uint16_t &crc, std::uint64_t const &word)
edm::ESHandle< RPCLBLinkMap > es_lb_link_map_
edm::ESHandle< RPCAMCLinkMap > es_tm_link_map_
def move(src, dest)
Definition: eostools.py:511
void putRPCDigis(edm::Event &event, std::set< std::pair< RPCDetId, RPCDigi > > const &digis)
void RPCTwinMuxRawToDigi::putCounters ( edm::Event event,
std::unique_ptr< RPCAMCLinkCounters counters 
)
protected

Definition at line 544 of file RPCTwinMuxRawToDigi.cc.

References DEFINE_FWK_MODULE, and eostools::move().

Referenced by produce().

546 {
547  event.put(std::move(counters));
548 }
def move(src, dest)
Definition: eostools.py:511
void RPCTwinMuxRawToDigi::putRPCDigis ( edm::Event event,
std::set< std::pair< RPCDetId, RPCDigi > > const &  digis 
)
protected

Definition at line 519 of file RPCTwinMuxRawToDigi.cc.

References LogDebug, and eostools::move().

Referenced by produce().

521 {
522  std::unique_ptr<RPCDigiCollection> rpc_digi_collection(new RPCDigiCollection());
523  RPCDetId rpc_det_id;
524  std::vector<RPCDigi> local_digis;
525  for (std::pair<RPCDetId, RPCDigi> const & rpc_digi : digis) {
526  LogDebug("RPCTwinMuxRawToDigi") << "RPCDigi " << rpc_digi.first.rawId()
527  << ", " << rpc_digi.second.strip() << ", " << rpc_digi.second.bx();
528  if (rpc_digi.first != rpc_det_id) {
529  if (!local_digis.empty()) {
530  rpc_digi_collection->put(RPCDigiCollection::Range(local_digis.begin(), local_digis.end()), rpc_det_id);
531  local_digis.clear();
532  }
533  rpc_det_id = rpc_digi.first;
534  }
535  local_digis.push_back(rpc_digi.second);
536  }
537  if (!local_digis.empty()) {
538  rpc_digi_collection->put(RPCDigiCollection::Range(local_digis.begin(), local_digis.end()), rpc_det_id);
539  }
540 
541  event.put(std::move(rpc_digi_collection));
542 }
#define LogDebug(id)
MuonDigiCollection< RPCDetId, RPCDigi > RPCDigiCollection
std::pair< const_iterator, const_iterator > Range
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

int RPCTwinMuxRawToDigi::bx_max_
protected

Definition at line 79 of file RPCTwinMuxRawToDigi.h.

Referenced by processTwinMux().

int RPCTwinMuxRawToDigi::bx_min_
protected

Definition at line 79 of file RPCTwinMuxRawToDigi.h.

Referenced by processTwinMux().

bool RPCTwinMuxRawToDigi::calculate_crc_
protected

Definition at line 78 of file RPCTwinMuxRawToDigi.h.

Referenced by processBlock(), processCDFHeaders(), processTwinMux(), and produce().

edm::ESHandle<RPCLBLinkMap> RPCTwinMuxRawToDigi::es_lb_link_map_
protected

Definition at line 84 of file RPCTwinMuxRawToDigi.h.

Referenced by processRPCRecord(), and produce().

edm::ESHandle<RPCAMCLinkMap> RPCTwinMuxRawToDigi::es_tm_link_map_
protected

Definition at line 83 of file RPCTwinMuxRawToDigi.h.

Referenced by beginRun(), processRPCRecord(), and produce().

edm::ESWatcher<RPCTwinMuxLinkMapRcd> RPCTwinMuxRawToDigi::es_tm_link_map_watcher_
protected

Definition at line 81 of file RPCTwinMuxRawToDigi.h.

Referenced by beginRun().

std::vector<int> RPCTwinMuxRawToDigi::feds_
protected

Definition at line 82 of file RPCTwinMuxRawToDigi.h.

Referenced by beginRun(), and produce().

bool RPCTwinMuxRawToDigi::fill_counters_
protected
edm::EDGetTokenT<FEDRawDataCollection> RPCTwinMuxRawToDigi::raw_token_
protected

Definition at line 76 of file RPCTwinMuxRawToDigi.h.

Referenced by produce(), and RPCTwinMuxRawToDigi().