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"))
30 produces<RPCDigiCollection>();
32 produces<RPCAMCLinkCounters>();
42 unsigned char const * uchars(reinterpret_cast<unsigned char const *>(&word));
43 for (
unsigned char const * uchar = uchars + 7
44 ; uchar >= uchars ; --uchar) {
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);
66 feds.insert(tm_link.first.getFED());
68 feds_.assign(feds.begin(), feds.end());
80 event.getByToken(
raw_token_, raw_data_collection);
82 std::set<std::pair<RPCDetId, RPCDigi> > rpc_digis;
86 for (
int fed :
feds_) {
92 std::uint16_t crc(0xffff);
100 std::uint64_t const * word(reinterpret_cast<std::uint64_t const *>(raw_data.
data()));
103 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Handling FED " << fed <<
" with length " << nwords;
120 while (word < word_end) {
123 , crc, *counters, rpc_digis);
129 word_end =
reinterpret_cast<std::uint64_t const *
>(raw_data.
data()) + nwords - 1;
130 for ( ; word < word_end ; ++word) {
134 FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
135 if ((
unsigned int)(trailer.
crc()) != crc) {
139 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Trailer CRC doesn't match for FED id " << fed;
152 , std::uint16_t & crc
155 bool more_headers(
true);
156 for ( ; word < word_end && more_headers ; ++word) {
161 LogDebug(
"RPCTwinMuxRawToDigi") <<
"CDF Header " << std::hex << *word <<
std::dec;
163 if (!header.
check()) {
167 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Header check failed for FED id " << fed;
176 <<
" does not match requested FED id " << fed;
182 more_headers =
false;
185 return !more_headers;
190 , std::uint16_t & crc
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 198 if (!trailer.
check()) {
202 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Trailer check failed for FED id " << fed;
211 <<
" does not match actual data size " << nwords
212 <<
" for FED id " << fed;
219 more_trailers =
false;
224 return !more_trailers;
229 , std::uint16_t & crc
231 , std::set<std::pair<RPCDetId, RPCDigi> > & digis)
const 240 unsigned int n_amc(block_header.
getNAMC());
241 if (word + n_amc + 1 >= word_end) {
245 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"Block can not be complete for FED " << fed;
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;
264 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"BlockAMCContent is reporting an invalid " 265 <<
"Event Counter or Bunch Counter for FED " << fed
270 for (std::pair<unsigned int, unsigned int>
const & amc_size : amc_size_map) {
277 if (word < word_end) {
291 , std::uint16_t & crc
293 , std::set<std::pair<RPCDetId, RPCDigi> > & digis)
const 295 LogDebug(
"RPCTwinMuxRawToDigi") <<
"TwinMux AMC#" << amc_number <<
", size " <<
size;
303 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"Invalid AMC Number " << amc_number
304 <<
" for FED " << fed;
306 for ( ; size > 0 ; --
size, ++word) {
314 if (word + size >= word_end || size < 3) {
318 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"TwinMux Data can not be complete for FED " << fed <<
" AMC #" << amc_number;
320 for ( ; size > 0 ; --
size, ++word) {
344 <<
" vs " << amc_number;
346 for ( ; size > 0 ; --
size, ++word) {
359 LogDebug(
"RPCTwinMuxRawToDigi") <<
"BX range set to " << bx_min <<
", " << bx_max;
362 bool has_first_rpc_word(
false);
364 for ( ; size > 1 ; --
size, ++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);
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";
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;
387 if (has_first_rpc_word) {
388 processRPCRecord(fed, amc_number, bx_counter, rpc_record, counters, digis, bx_min, bx_max, 0, 1);
392 LogDebug(
"RPCTwinMuxRawToDigi") <<
"TwinMux Trailer " << std::hex << *word <<
std::dec;
401 ,
unsigned int bx_counter
404 , std::set<std::pair<RPCDetId, RPCDigi> > & digis
405 ,
int bx_min,
int bx_max
406 ,
unsigned int link,
unsigned int link_max)
const 408 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPCRecord " << std::hex << record.
getRecord()[0]
412 for ( ; link <= link_max ; ++link) {
413 tm_link.setAMCInput(link);
416 if (link_record.isError()) {
420 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Link in error for " << tm_link;
422 }
else if (!link_record.isAcknowledge()) {
426 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Link without acknowledge for " << tm_link;
430 if (!link_record.getPartitionData()) {
434 int bx(bx_offset - (
int)(link_record.getDelay()));
435 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPC BX " << bx <<
" for offset " << bx_offset;
446 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping unknown TwinMuxLink " << tm_link;
456 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping invalid LinkBoard " << link_record.getLinkBoard()
457 <<
" for record " << link <<
" (" << std::hex << link_record.getRecord()
459 <<
" from " << tm_link;
467 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping invalid Connector " << link_record.getConnector()
468 <<
" for record " << link <<
" (" << std::hex << link_record.getRecord()
470 <<
") from " << tm_link;
482 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Could not find " << lb_link
483 <<
" for record " << link <<
" (" << std::hex << link_record.getRecord()
485 <<
") from " << tm_link;
489 if (bx < bx_min || bx > bx_max) {
500 unsigned int channel_offset(link_record.getPartition() ? 9 : 1);
501 std::uint8_t
data(link_record.getPartitionData());
503 for (
unsigned int channel = 0 ; channel < 8 ; ++channel) {
504 if (
data & (0
x1 << channel)) {
505 unsigned int strip(feb_connector.
getStrip(channel + channel_offset));
507 digis.insert(std::pair<RPCDetId, RPCDigi>(det_id,
RPCDigi(
strip, bx)));
508 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPCDigi " << det_id.rawId()
509 <<
", " <<
strip <<
", " << bx;
520 , std::set<std::pair<RPCDetId, RPCDigi> >
const & digis)
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()) {
533 rpc_det_id = rpc_digi.first;
535 local_digis.push_back(rpc_digi.second);
537 if (!local_digis.empty()) {
541 event.put(
std::move(rpc_digi_collection));
545 , std::unique_ptr<RPCAMCLinkCounters>counters)
static unsigned int const fed_amc13_amc_number_invalid_
T getParameter(std::string const &) const
unsigned int getStrip(unsigned int channel) const
static unsigned int const fed_trailer_crc_mismatch_
static unsigned int const input_connector_not_used_
RPCLinkRecord getRPCLinkRecord(unsigned int link) const
static unsigned int const amc_payload_incomplete_
static unsigned int const amc_event_
std::uint64_t const * getRecord() const
static unsigned int const fed_header_check_fail_
bool processCDFHeaders(int fed, std::uint64_t const *&word, std::uint64_t const *&word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters) const
void beginRun(edm::Run const &run, edm::EventSetup const &setup) override
static int const max_connector_
static unsigned int const input_link_error_
#define DEFINE_FWK_MODULE(type)
static unsigned int const input_lb_invalid_
RPCLBLink & setConnector(int connector=wildcard_)
def setup(process, global_tag, zero_tesla=False)
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
bool check() const
Check that the trailer is OK.
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
static unsigned int const fed_trailer_length_mismatch_
size_t size() const
Lenght of the data buffer in bytes.
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
~RPCTwinMuxRawToDigi() override
static int const max_amcnumber_
RPCTwinMuxRawToDigi(edm::ParameterSet const &config)
static unsigned int const amc_link_invalid_
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)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
unsigned int getType() const
unsigned int getAMCNumber() const
edm::EDGetTokenT< FEDRawDataCollection > raw_token_
MuonDigiCollection< RPCDetId, RPCDigi > RPCDigiCollection
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
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static unsigned int const rpc_first_type_
static unsigned int const fed_header_id_mismatch_
static unsigned int const amc_number_mismatch_
static unsigned int const fed_amc13_block_incomplete_
static unsigned int const input_event_
void add(unsigned int event, RPCAMCLink const &link, unsigned int count=1)
static unsigned int const fed_event_
edm::ESWatcher< RPCTwinMuxLinkMapRcd > es_tm_link_map_watcher_
static unsigned int const rpc_second_type_
static unsigned int const input_link_ack_fail_
unsigned long long uint64_t
void add(std::string const &label, ParameterSetDescription const &psetDescription)
unsigned short compute_crc_8bit(unsigned short crc, unsigned char data)
bool check(const edm::EventSetup &iSetup)
unsigned int getSize() const
char data[epos_bytes_allocation]
static void fillDescriptions(edm::ConfigurationDescriptions &descs)
void produce(edm::Event &event, edm::EventSetup const &setup) override
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
std::pair< const_iterator, const_iterator > Range
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_
RPCLBLink & setLinkBoard(int linkboard=wildcard_)
static int const wildcard_
edm::ESHandle< RPCAMCLinkMap > es_tm_link_map_
static unsigned int const fed_trailer_check_fail_
RPCDetId getRPCDetId() const
void putRPCDigis(edm::Event &event, std::set< std::pair< RPCDetId, RPCDigi > > const &digis)
static int const max_linkboard_
static unsigned int const input_eod_
static unsigned int const input_connector_invalid_