File indexing completed on 2024-04-06 12:10:58
0001 #ifndef EventFilter_RPCRawToDigi_RPCAMCRawToDigi_h
0002 #define EventFilter_RPCRawToDigi_RPCAMCRawToDigi_h
0003
0004 #include "FWCore/Framework/interface/stream/EDProducer.h"
0005 #include "FWCore/Utilities/interface/CRC16.h"
0006
0007 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0008 #include "DataFormats/RPCDigi/interface/RPCAMCLinkCounters.h"
0009 #include "EventFilter/RPCRawToDigi/interface/RPCAMC13Record.h"
0010
0011 namespace edm {
0012 class ConfigurationDescriptions;
0013 class Event;
0014 class EventSetup;
0015 class ParameterSet;
0016 class Run;
0017 }
0018
0019 class RPCAMCUnpacker;
0020
0021 class RPCAMCRawToDigi : public edm::stream::EDProducer<> {
0022 public:
0023 RPCAMCRawToDigi(edm::ParameterSet const &config);
0024 ~RPCAMCRawToDigi() override;
0025
0026 static void compute_crc16_64bit(std::uint16_t &crc, std::uint64_t const &word);
0027
0028 static void fillDescriptions(edm::ConfigurationDescriptions &descs);
0029
0030 void beginRun(edm::Run const &run, edm::EventSetup const &setup) override;
0031 void produce(edm::Event &event, edm::EventSetup const &setup) override;
0032
0033 protected:
0034 bool processCDFHeaders(int fed,
0035 std::uint64_t const *&word,
0036 std::uint64_t const *&word_end,
0037 std::uint16_t &crc,
0038 RPCAMCLinkCounters &counters) const;
0039 bool processCDFTrailers(int fed,
0040 unsigned int nwords,
0041 std::uint64_t const *&word,
0042 std::uint64_t const *&word_end,
0043 std::uint16_t &crc,
0044 RPCAMCLinkCounters &counters) const;
0045 bool processBlocks(int fed,
0046 std::uint64_t const *&word,
0047 std::uint64_t const *word_end,
0048 std::uint16_t &crc,
0049 RPCAMCLinkCounters &counters,
0050 std::map<RPCAMCLink, rpcamc13::AMCPayload> &amc_payload) const;
0051
0052 protected:
0053 edm::EDGetTokenT<FEDRawDataCollection> raw_token_;
0054
0055 bool calculate_crc_, fill_counters_;
0056
0057 std::unique_ptr<RPCAMCUnpacker> rpc_unpacker_;
0058 };
0059
0060 inline void RPCAMCRawToDigi::compute_crc16_64bit(
0061 std::uint16_t &crc, std::uint64_t const &word) {
0062 unsigned char const *uchars(reinterpret_cast<unsigned char const *>(&word));
0063 for (unsigned char const *uchar = uchars + 7; uchar >= uchars; --uchar) {
0064 crc = evf::compute_crc_8bit(crc, *uchar);
0065 }
0066 }
0067
0068 #endif