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")),
31 produces<RPCDigiCollection>();
33 produces<RPCAMCLinkCounters>();
42 unsigned char const *uchars(reinterpret_cast<unsigned char const *>(&
word));
43 for (
unsigned char const *uchar = uchars + 7; uchar >= uchars; --uchar) {
51 desc.add<
bool>(
"calculateCRC",
true);
52 desc.add<
bool>(
"fillCounters",
true);
53 desc.add<
int>(
"bxMin", -2);
54 desc.add<
int>(
"bxMax", 2);
55 descs.
add(
"rpcTwinMuxRawToDigi",
desc);
62 for (
auto const &tm_link : link_map->getMap()) {
63 feds.insert(tm_link.first.getFED());
76 event.getByToken(
raw_token_, raw_data_collection);
78 std::set<std::pair<RPCDetId, RPCDigi> > rpc_digis;
82 for (
int fed :
feds_) {
87 std::uint16_t crc(0xffff);
98 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Handling FED " << fed <<
" with length " << nwords;
111 while (
word < word_end) {
118 word_end =
reinterpret_cast<std::uint64_t const *
>(raw_data.
data()) + nwords - 1;
123 FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
124 if ((
unsigned int)(trailer.
crc()) != crc) {
128 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Trailer CRC doesn't match for FED id " << fed;
144 bool more_headers(
true);
145 for (;
word < word_end && more_headers; ++
word) {
156 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Header check failed for FED id " << fed;
160 if (
header.sourceID() != fed) {
165 <<
"FED Header Source ID " <<
header.sourceID() <<
" does not match requested FED id " << fed;
171 more_headers =
false;
174 return !more_headers;
183 bool more_trailers(
true);
184 for (--word_end; word_end >
word && more_trailers; --word_end) {
185 FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
186 LogDebug(
"RPCTwinMuxRawToDigi") <<
"CDF Trailer " << std::hex << *word_end <<
std::dec <<
", length " 188 if (!trailer.
check()) {
192 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"FED Trailer check failed for FED id " << fed;
201 <<
" does not match actual data size " << nwords <<
" for FED id " << fed;
208 more_trailers =
false;
213 return !more_trailers;
221 std::set<std::pair<RPCDetId, RPCDigi> > &digis)
const {
229 unsigned int n_amc(block_header.
getNAMC());
230 if (
word + n_amc + 1 >= word_end) {
234 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"Block can not be complete for FED " << fed;
239 std::vector<std::pair<unsigned int, unsigned int> > amc_size_map;
240 for (
unsigned int amc = 0;
amc < n_amc; ++
amc) {
241 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Block AMC " <<
amc;
254 <<
"BlockAMCContent is reporting an invalid " 255 <<
"Event Counter or Bunch Counter for FED " << fed <<
", AMC " << amc_content.
getAMCNumber();
259 for (std::pair<unsigned int, unsigned int>
const &amc_size : amc_size_map) {
263 if (
word < word_end) {
276 unsigned int amc_number,
282 std::set<std::pair<RPCDetId, RPCDigi> > &digis)
const {
283 LogDebug(
"RPCTwinMuxRawToDigi") <<
"TwinMux AMC#" << amc_number <<
", size " <<
size;
291 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"Invalid AMC Number " << amc_number <<
" for FED " << fed;
306 <<
"TwinMux Data can not be complete for FED " << fed <<
" AMC #" << amc_number;
318 unsigned int bx_counter(
header.getBXCounter());
329 if (amc_number !=
header.getAMCNumber()) {
334 <<
"AMC Number inconsistent in TwinMuxHeader vs BlockAMCContent: " <<
header.getAMCNumber() <<
" vs " 347 if (
header.hasRPCBXWindow()) {
350 LogDebug(
"RPCTwinMuxRawToDigi") <<
"BX range set to " << bx_min <<
", " << bx_max;
353 bool has_first_rpc_word(
false);
362 if (has_first_rpc_word) {
367 has_first_rpc_word =
true;
369 if (!has_first_rpc_word) {
370 edm::LogWarning(
"RPCTwinMuxRawToDigi") <<
"Received second RPC word without first";
374 has_first_rpc_word =
false;
378 if (has_first_rpc_word) {
392 unsigned int amc_number,
393 unsigned int bx_counter,
396 std::set<std::pair<RPCDetId, RPCDigi> > &digis,
400 unsigned int link_max)
const {
401 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPCRecord " << std::hex <<
record.getRecord()[0] <<
", " <<
record.getRecord()[1]
403 int bx_offset(
record.getBXOffset());
406 tm_link.setAMCInput(
link);
409 if (link_record.isError()) {
413 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Link in error for " << tm_link;
415 }
else if (!link_record.isAcknowledge()) {
419 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Link without acknowledge for " << tm_link;
423 if (!link_record.getPartitionData()) {
427 int bx(bx_offset - (
int)(link_record.getDelay()));
428 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPC BX " <<
bx <<
" for offset " << bx_offset;
439 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping unknown TwinMuxLink " << tm_link;
449 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping invalid LinkBoard " << link_record.getLinkBoard() <<
" for record " 450 <<
link <<
" (" << std::hex << link_record.getRecord() <<
" in " 460 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Skipping invalid Connector " << link_record.getConnector() <<
" for record " 461 <<
link <<
" (" << std::hex << link_record.getRecord() <<
" in " 475 LogDebug(
"RPCTwinMuxRawToDigi") <<
"Could not find " << lb_link <<
" for record " <<
link <<
" (" << std::hex
476 << link_record.getRecord() <<
" in " <<
record.getRecord()[0] <<
':' 481 if (bx < bx_min || bx > bx_max) {
492 unsigned int channel_offset(link_record.getPartition() ? 9 : 1);
493 std::uint8_t
data(link_record.getPartitionData());
495 for (
unsigned int channel = 0; channel < 8; ++channel) {
496 if (
data & (0
x1 << channel)) {
497 unsigned int strip(feb_connector.
getStrip(channel + channel_offset));
499 digis.insert(std::pair<RPCDetId, RPCDigi>(det_id,
RPCDigi(
strip,
bx)));
500 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPCDigi " << det_id.rawId() <<
", " <<
strip <<
", " <<
bx;
512 std::vector<RPCDigi> local_digis;
513 for (std::pair<RPCDetId, RPCDigi>
const &rpc_digi : digis) {
514 LogDebug(
"RPCTwinMuxRawToDigi") <<
"RPCDigi " << rpc_digi.first.rawId() <<
", " << rpc_digi.second.strip() <<
", " 515 << rpc_digi.second.bx();
516 if (rpc_digi.first != rpc_det_id) {
517 if (!local_digis.empty()) {
521 rpc_det_id = rpc_digi.first;
523 local_digis.push_back(rpc_digi.second);
525 if (!local_digis.empty()) {
529 event.put(
std::move(rpc_digi_collection));
unsigned int getAMCNumber() const
static unsigned int const fed_amc13_amc_number_invalid_
static unsigned int const fed_trailer_crc_mismatch_
static unsigned int const input_connector_not_used_
static unsigned int const amc_payload_incomplete_
static unsigned int const amc_event_
static unsigned int const fed_header_check_fail_
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_)
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t uint32_t CAHitNtupletGeneratorKernelsGPU::Counters * counters
size_t size() const
Lenght of the data buffer in bytes.
static unsigned int const amc_amc13_evc_bc_invalid_
static unsigned int const fed_trailer_length_mismatch_
unsigned int getSize() const
~RPCTwinMuxRawToDigi() override
edm::ESGetToken< RPCAMCLinkMap, RPCTwinMuxLinkMapRcd > es_tm_link_map_br_token_
static int const max_amcnumber_
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
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
RPCTwinMuxRawToDigi(edm::ParameterSet const &config)
static unsigned int const amc_link_invalid_
void set(unsigned int word, std::uint64_t const record)
RPCDetId getRPCDetId() 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
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
edm::ESGetToken< RPCAMCLinkMap, RPCTwinMuxLinkMapRcd > es_tm_link_map_token_
static unsigned int const rpc_first_type_
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_header_id_mismatch_
static unsigned int const amc_number_mismatch_
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static unsigned int const fed_amc13_block_incomplete_
static unsigned int const input_event_
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_
edm::ESGetToken< RPCLBLinkMap, RPCLBLinkMapRcd > es_lb_link_map_token_
unsigned long long uint64_t
std::pair< const_iterator, const_iterator > Range
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)
char data[epos_bytes_allocation]
unsigned int getStrip(unsigned int channel) const
static void fillDescriptions(edm::ConfigurationDescriptions &descs)
void produce(edm::Event &event, edm::EventSetup const &setup) override
unsigned int getType() const
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
bool processCDFHeaders(int fed, std::uint64_t const *&word, std::uint64_t const *&word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters) const
void putCounters(edm::Event &event, std::unique_ptr< RPCAMCLinkCounters > counters)
static void compute_crc_64bit(std::uint16_t &crc, std::uint64_t const &word)
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
Log< level::Warning, false > LogWarning
edm::ESHandle< RPCLBLinkMap > es_lb_link_map_
RPCLBLink & setLinkBoard(int linkboard=wildcard_)
static int const wildcard_
edm::ESHandle< RPCAMCLinkMap > es_tm_link_map_
bool check() const
Check that the trailer is OK.
static unsigned int const fed_trailer_check_fail_
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_