21 : calculate_crc_(config.getParameter<
bool>(
"calculateCRC"))
22 , fill_counters_(config.getParameter<
bool>(
"fillCounters"))
28 produces<RPCAMCLinkCounters>();
41 desc.
add<
bool>(
"calculateCRC",
true);
42 desc.
add<
bool>(
"fillCounters",
true);
45 descs.
add(
"RPCAMCRawToDigi", desc);
57 event.getByToken(
raw_token_, raw_data_collection);
61 std::map<RPCAMCLink, rpcamc13::AMCPayload> amc_payload;
70 std::uint16_t crc(0xffff);
78 std::uint64_t const * word(reinterpret_cast<std::uint64_t const *>(raw_data.
data()));
81 LogDebug(
"RPCAMCRawToDigi") <<
"Handling FED " << fed <<
" with length " << nwords;
100 , crc, *counters, amc_payload)) {
107 word_end =
reinterpret_cast<std::uint64_t const *
>(raw_data.
data()) + nwords - 1;
108 for ( ; word < word_end ; ++word) {
112 FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
113 if ((
unsigned int)(trailer.
crc()) != crc) {
117 edm::LogWarning(
"RPCAMCRawToDigi") <<
"FED Trailer CRC doesn't match for FED id " << fed;
134 , std::uint16_t & crc
137 bool more_headers(
true);
138 for ( ; word < word_end && more_headers ; ++word) {
143 LogDebug(
"RPCAMCRawToDigi") <<
"CDF Header " << std::hex << *word <<
std::dec;
145 if (!header.
check()) {
149 edm::LogWarning(
"RPCAMCRawToDigi") <<
"FED Header check failed for FED id " << fed;
158 <<
" does not match requested FED id " << fed;
165 more_headers =
false;
168 return !more_headers;
173 , std::uint16_t & crc
176 bool more_trailers(
true);
177 for (--word_end ; word_end > word && more_trailers ; --word_end) {
178 FEDTrailer trailer(reinterpret_cast<unsigned char const *>(word_end));
179 LogDebug(
"RPCAMCRawToDigi") <<
"CDF Trailer " << std::hex << *word_end <<
std::dec 181 if (!trailer.
check()) {
185 edm::LogWarning(
"RPCAMCRawToDigi") <<
"FED Trailer check failed for FED id " << fed;
193 <<
" does not match actual data size " << nwords
194 <<
" for FED id " << fed;
200 more_trailers =
false;
205 return !more_trailers;
210 , std::uint16_t & crc
212 , std::map<RPCAMCLink, rpcamc13::AMCPayload> & amc_payload)
const 214 while (word < word_end) {
221 unsigned int n_amc(header.
getNAMC());
222 if (word + n_amc + 1 >= word_end) {
226 edm::LogWarning(
"RPCAMCRawToDigi") <<
"AMC13 Block can not be complete for FED " << fed;
233 for (
unsigned int amc = 0 ;
amc < n_amc ; ++
amc) {
241 if (size_in_block == 0) {
244 payload_word = payload_word_end;
245 payload_word_end += size_in_block;
247 unsigned int amc_number(amc13_amc_header.
getAMCNumber());
252 edm::LogWarning(
"RPCAMCRawToDigi") <<
"Invalid AMC Number " << amc_number <<
" for FED " << fed;
256 if (payload_word_end > word_end) {
260 edm::LogWarning(
"RPCAMCRawToDigi") <<
"AMC Block can not be complete for FED " << fed
261 <<
" at AMC " << amc_number;
273 if (!amc13_amc_header.
isValid()) {
277 edm::LogWarning(
"RPCAMCRawToDigi") <<
"AMC13 AMC Header is reporting an invalid " 278 <<
"Event Counter or Bunch Counter for FED " << fed
279 <<
", AMC " << amc_number;
288 edm::LogWarning(
"RPCAMCRawToDigi") <<
"AMC Number inconsistent in AMC13 AMC Header vs AMC Header: " << amc_number
299 edm::LogWarning(
"RPCAMCRawToDigi") <<
"AMC size inconsistent in AMC13 AMC Header vs AMC Header: " << amc13_amc_header.
getSize()
312 if (!amc13_amc_header.
isCRCOk()) {
316 edm::LogWarning(
"RPCAMCRawToDigi") <<
"AMC13 AMC Header is reporting a mismatched " 317 <<
"Event Counter or Bunch Counter for FED " << fed
318 <<
", AMC " << amc_number;
326 edm::LogWarning(
"RPCAMCRawToDigi") <<
"AMC13 AMC Header is reporting an incorrect length " 327 <<
"for FED " << fed <<
", AMC " << amc_number;
332 && amc13_amc_header.
getSize() != (payload.
getData().size() + size_in_block)) {
336 edm::LogWarning(
"RPCAMCRawToDigi") <<
"Size in AMC13 AMC Header doesn't match payload size " 337 <<
"for FED " << fed <<
", AMC " << amc_number;
341 if (!payload.
getData().empty() && (payload.
getData().size() + size_in_block) < 3) {
345 edm::LogWarning(
"RPCAMCRawToDigi") <<
"Size in AMC13 AMC Header doesn't match payload size " 346 <<
"for FED " << fed <<
", AMC " << amc_number;
351 if (size_in_block > 0) {
352 payload.
insert(payload_word, size_in_block);
357 for ( ; word < payload_word_end ; ++word) {
361 word = payload_word_end;
static unsigned int const fed_amc13_amc_number_invalid_
T getParameter(std::string const &) const
static unsigned int const fed_trailer_crc_mismatch_
static unsigned int const amc_payload_incomplete_
static unsigned int const amc_size_mismatch_
void setAMCHeader(AMCHeader const &header)
static void compute_crc16_64bit(std::uint16_t &crc, std::uint64_t const &word)
static unsigned int const amc_event_
def create(alignables, pedeDump, additionalData, outputFile, config)
static unsigned int const fed_header_check_fail_
RPCAMCRawToDigi(edm::ParameterSet const &config)
edm::EDGetTokenT< FEDRawDataCollection > raw_token_
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_
void produce(edm::Event &event, edm::EventSetup const &setup) override
std::vector< std::uint64_t > const & getData() 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.
static int const max_amcnumber_
AMCHeader const & getAMCHeader() const
static void fillDescription(edm::ParameterSetDescription &desc)
#define DEFINE_FWK_MODULE(type)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void insert(std::uint64_t const *word_begin, unsigned int size)
static unsigned int const amc_amc13_length_incorrect_
static void fillDescriptions(edm::ConfigurationDescriptions &descs)
static unsigned int const amc_amc13_size_inconsistent_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static unsigned int const fed_header_id_mismatch_
static unsigned int const amc_number_mismatch_
static unsigned int const fed_amc13_block_incomplete_
void setValid(bool valid)
void add(unsigned int event, RPCAMCLink const &link, unsigned int count=1)
static unsigned int const fed_event_
unsigned long long uint64_t
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
bool processBlocks(int fed, std::uint64_t const *&word, std::uint64_t const *word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters, std::map< RPCAMCLink, rpcamc13::AMCPayload > &amc_payload) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static unsigned int const amc_amc13_block_incomplete_
static unsigned int const amc_amc13_crc_mismatch_
bool processCDFHeaders(int fed, std::uint64_t const *&word, std::uint64_t const *&word_end, std::uint16_t &crc, RPCAMCLinkCounters &counters) const
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
static int const wildcard_
void beginRun(edm::Run const &run, edm::EventSetup const &setup) override
std::unique_ptr< RPCAMCUnpacker > rpc_unpacker_
static unsigned int const fed_trailer_check_fail_
T get(const Candidate &c)