24 : calculate_crc_(config.getParameter<bool>(
"calculateCRC"))
25 , fill_counters_(config.getParameter<bool>(
"fillCounters"))
26 , bx_min_(config.getParameter<
int>(
"bxMin"))
27 , bx_max_(config.getParameter<
int>(
"bxMax"))
29 produces<RPCDigiCollection>();
31 produces<RPCAMCLinkCounters>();
41 unsigned char const * uchars(reinterpret_cast<unsigned char const *>(&word));
42 for (
unsigned char const * uchar = uchars + 7
43 ; uchar >= uchars ; --uchar) {
52 desc.
add<
bool>(
"calculateCRC",
true);
53 desc.
add<
bool>(
"fillCounters",
true);
54 desc.
add<
int>(
"bxMin", -2);
55 desc.
add<
int>(
"bxMax", 2);
56 descs.
add(
"RPCTwinMuxRawToDigi", desc);
65 feds.insert(tm_link.first.getFED());
67 feds_.assign(feds.begin(), feds.end());
79 event.getByToken(
raw_token_, raw_data_collection);
81 std::set<std::pair<RPCDetId, RPCDigi> > rpc_digis;
85 for (
int fed :
feds_) {
91 std::uint16_t crc(0xffff);
99 std::uint64_t const * word(reinterpret_cast<std::uint64_t const *>(raw_data.
data()));
102 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Handling FED " << fed <<
" with length " << nwords;
119 while (word < word_end) {
122 , crc, *counters, rpc_digis);
128 word_end =
reinterpret_cast<std::uint64_t const *
>(raw_data.
data()) + nwords - 1;
129 for ( ; word < word_end ; ++word) {
133 FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
134 if ((
unsigned int)(trailer.
crc()) != crc) {
138 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Trailer CRC doesn't match for FED id " << fed;
151 , std::uint16_t & crc
154 bool more_headers(
true);
155 for ( ; word < word_end && more_headers ; ++word) {
160 LogDebug(
"RPCTwinMuxRawToDigi") <<
"CDF Header " << std::hex << *word <<
std::dec;
162 if (!header.
check()) {
166 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Header check failed for FED id " << fed;
175 <<
" does not match requested FED id " << fed;
181 more_headers =
false;
184 return !more_headers;
189 , std::uint16_t & crc
192 bool more_trailers(
true);
193 for (--word_end ; word_end > word && more_trailers ; --word_end) {
194 FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
195 LogDebug(
"RPCTwinMuxRawToDigi") <<
"CDF Trailer " << std::hex << *word_end <<
std::dec 196 <<
", length " << trailer.
lenght();
197 if (!trailer.
check()) {
201 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Trailer check failed for FED id " << fed;
210 <<
" does not match actual data size " << nwords
211 <<
" for FED id " << fed;
218 more_trailers =
false;
223 return !more_trailers;
228 , std::uint16_t & crc
230 , std::set<std::pair<RPCDetId, RPCDigi> > & digis)
const 239 unsigned int n_amc(block_header.
getNAMC());
240 if (word + n_amc + 1 >= word_end) {
244 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"Block can not be complete for FED " << fed;
249 std::vector<std::pair<unsigned int, unsigned int> > amc_size_map;
250 for (
unsigned int amc = 0 ;
amc < n_amc ; ++
amc) {
251 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Block AMC " <<
amc;
263 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"BlockAMCContent is reporting an invalid " 264 <<
"Event Counter or Bunch Counter for FED " << fed
269 for (std::pair<unsigned int, unsigned int>
const & amc_size : amc_size_map) {
276 if (word < word_end) {
290 , std::uint16_t & crc
292 , std::set<std::pair<RPCDetId, RPCDigi> > & digis)
const 294 LogDebug(
"RPCTwinMuxRawToDigi") <<
"TwinMux AMC#" << amc_number <<
", size " <<
size;
302 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"Invalid AMC Number " << amc_number
303 <<
" for FED " << fed;
305 for ( ; size > 0 ; --
size, ++word) {
313 if (word + size >= word_end || size < 3) {
317 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"TwinMux Data can not be complete for FED " << fed <<
" AMC #" << amc_number;
319 for ( ; size > 0 ; --
size, ++word) {
343 <<
" vs " << amc_number;
345 for ( ; size > 0 ; --
size, ++word) {
358 LogDebug(
"RPCTwinMuxRawToDigi") <<
"BX range set to " << bx_min <<
", " << bx_max;
361 bool has_first_rpc_word(
false);
363 for ( ; size > 1 ; --
size, ++word) {
368 LogDebug(
"RPCTwinMuxRawToDigi") <<
"TwinMux data type " << std::hex << type <<
std::dec;
370 if (has_first_rpc_word) {
371 processRPCRecord(fed, amc_number, bx_counter, rpc_record, counters, digis, bx_min, bx_max, 0, 1);
374 rpc_record.
set(0, *word);
375 has_first_rpc_word =
true;
377 if (!has_first_rpc_word) {
378 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"Received second RPC word without first";
380 rpc_record.
set(1, *word);
381 processRPCRecord(fed, amc_number, bx_counter, rpc_record, counters, digis, bx_min, bx_max, 0, 4);
382 has_first_rpc_word =
false;
386 if (has_first_rpc_word) {
387 processRPCRecord(fed, amc_number, bx_counter, rpc_record, counters, digis, bx_min, bx_max, 0, 1);
391 LogDebug(
"RPCTwinMuxRawToDigi") <<
"TwinMux Trailer " << std::hex << *word <<
std::dec;
400 ,
unsigned int bx_counter
403 , std::set<std::pair<RPCDetId, RPCDigi> > & digis
404 ,
int bx_min,
int bx_max
405 ,
unsigned int link,
unsigned int link_max)
const 407 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPCRecord " << std::hex << record.
getRecord()[0]
411 for ( ; link <= link_max ; ++link) {
412 tm_link.setAMCInput(link);
415 if (link_record.isError()) {
419 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Link in error for " << tm_link;
421 }
else if (!link_record.isAcknowledge()) {
425 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Link without acknowledge for " << tm_link;
429 if (!link_record.getPartitionData()) {
433 int bx(bx_offset - (
int)(link_record.getDelay()));
434 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPC BX " << bx <<
" for offset " << bx_offset;
445 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping unknown TwinMuxLink " << tm_link;
455 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping invalid LinkBoard " << link_record.getLinkBoard()
456 <<
" for record " << link <<
" (" << std::hex << link_record.getRecord()
458 <<
" from " << tm_link;
466 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping invalid Connector " << link_record.getConnector()
467 <<
" for record " << link <<
" (" << std::hex << link_record.getRecord()
469 <<
") from " << tm_link;
481 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Could not find " << lb_link
482 <<
" for record " << link <<
" (" << std::hex << link_record.getRecord()
484 <<
") from " << tm_link;
488 if (bx < bx_min || bx > bx_max) {
499 unsigned int channel_offset(link_record.getPartition() ? 9 : 1);
500 std::uint8_t
data(link_record.getPartitionData());
502 for (
unsigned int channel = 0 ; channel < 8 ; ++channel) {
503 if (
data & (0x1 << channel)) {
504 unsigned int strip(feb_connector.
getStrip(channel + channel_offset));
506 digis.insert(std::pair<RPCDetId, RPCDigi>(det_id,
RPCDigi(
strip, bx)));
507 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPCDigi " << det_id.rawId()
508 <<
", " <<
strip <<
", " << bx;
519 , std::set<std::pair<RPCDetId, RPCDigi> >
const & digis)
523 std::vector<RPCDigi> local_digis;
524 for (std::pair<RPCDetId, RPCDigi>
const & rpc_digi : digis) {
525 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPCDigi " << rpc_digi.first.rawId()
526 <<
", " << rpc_digi.second.strip() <<
", " << rpc_digi.second.bx();
527 if (rpc_digi.first != rpc_det_id) {
528 if (!local_digis.empty()) {
532 rpc_det_id = rpc_digi.first;
534 local_digis.push_back(rpc_digi.second);
536 if (!local_digis.empty()) {
540 event.put(
std::move(rpc_digi_collection));
544 , std::unique_ptr<RPCAMCLinkCounters>counters)
T getParameter(std::string const &) const
unsigned int getStrip(unsigned int channel) const
RPCLinkRecord getRPCLinkRecord(unsigned int link) const
static unsigned int const amc_link_invalid_
static unsigned int const fed_header_check_fail_
static unsigned int const fed_event_
std::uint64_t const * getRecord() const
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_
#define DEFINE_FWK_MODULE(type)
static unsigned int const input_link_ack_fail_
RPCLBLink & setConnector(int connector=wildcard_)
def setup(process, global_tag, zero_tesla=False)
static unsigned int const input_connector_invalid_
static unsigned int const fed_trailer_length_mismatch_
static unsigned int const input_data_
static unsigned int const input_link_error_
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
size_t size() const
Lenght of the data buffer in bytes.
static unsigned int const fed_trailer_crc_mismatch_
static int const max_amcnumber_
RPCTwinMuxRawToDigi(edm::ParameterSet const &config)
static unsigned int const amc_evc_bc_invalid_
static unsigned int const fed_block_amc_number_invalid_
static unsigned int const fed_header_id_mismatch_
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
static unsigned int const amc_payload_length_invalid_
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
static unsigned int const fed_block_length_invalid_
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_trailer_check_fail_
edm::ESWatcher< RPCTwinMuxLinkMapRcd > es_tm_link_map_watcher_
static unsigned int const rpc_second_type_
unsigned long long uint64_t
static unsigned int const input_eod_
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
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
static unsigned int const amc_data_
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.
int crc()
Cyclic Redundancy Code of the event fragment including header and trailer.
std::pair< const_iterator, const_iterator > Range
static unsigned int const amc_number_mismatch_
void putCounters(edm::Event &event, std::unique_ptr< RPCAMCLinkCounters > counters)
static void compute_crc_64bit(std::uint16_t &crc, std::uint64_t const &word)
void add(unsigned int type, RPCAMCLink const &link, unsigned int count=1)
edm::ESHandle< RPCLBLinkMap > es_lb_link_map_
RPCLBLink & setLinkBoard(int linkboard=wildcard_)
static int const wildcard_
static unsigned int const input_connector_not_used_
edm::ESHandle< RPCAMCLinkMap > es_tm_link_map_
static unsigned int const input_lb_invalid_
RPCDetId getRPCDetId() const
void putRPCDigis(edm::Event &event, std::set< std::pair< RPCDetId, RPCDigi > > const &digis)
static int const max_linkboard_