Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:13

0001 #ifndef EventFilter_RPCRawToDigi_RPCAMC13Record_h
0002 #define EventFilter_RPCRawToDigi_RPCAMC13Record_h
0003 
0004 #include <cstdint>
0005 #include <vector>
0006 
0007 namespace rpcamc13 {
0008 
0009   class Header {  // http://joule.bu.edu/~hazen/CMS/AMC13/UpdatedDAQPath.pdf
0010   protected:
0011     static std::uint64_t const ufov_mask_ = 0xf000000000000000;
0012     static std::uint64_t const n_amc_mask_ = 0x00f0000000000000;
0013     static std::uint64_t const orbit_counter_mask_ = 0x0000000ffffffff0;
0014 
0015     static unsigned int const ufov_offset_ = 60;
0016     static unsigned int const n_amc_offset_ = 52;
0017     static unsigned int const orbit_counter_offset_ = 4;
0018 
0019   public:
0020     Header(std::uint64_t const record = 0x0);
0021     Header(unsigned int ufov, unsigned int n_amc, unsigned int orbit_counter);
0022 
0023     void set(std::uint64_t const record);
0024     void reset();
0025 
0026     std::uint64_t const& getRecord() const;
0027 
0028     unsigned int getFirmwareVersion() const;
0029     unsigned int getNAMC() const;
0030     unsigned int getOrbitCounter() const;
0031 
0032     void setFirmwareVersion(unsigned int ufov);
0033     void setNAMC(unsigned int n_amc);
0034     void setOrbitCounter(unsigned int orbit_counter);
0035 
0036   protected:
0037     std::uint64_t record_;
0038   };
0039 
0040   class Trailer {  // http://joule.bu.edu/~hazen/CMS/AMC13/UpdatedDAQPath.pdf
0041   protected:
0042     static std::uint64_t const crc_mask_ = 0xffffffff00000000;
0043     static std::uint64_t const block_number_mask_ = 0x000000000ff00000;
0044     static std::uint64_t const event_counter_mask_ = 0x00000000000ff000;
0045     static std::uint64_t const bx_counter_mask_ = 0x0000000000000fff;
0046 
0047     static unsigned int const crc_offset_ = 32;
0048     static unsigned int const block_number_offset_ = 20;
0049     static unsigned int const event_counter_offset_ = 12;
0050     static unsigned int const bx_counter_offset_ = 0;
0051 
0052   public:
0053     Trailer(std::uint64_t const record = 0x0);
0054     Trailer(std::uint32_t crc, unsigned int block_number, unsigned int event_counter, unsigned int bx_counter);
0055 
0056     void set(std::uint64_t const record);
0057     void reset();
0058 
0059     std::uint64_t const& getRecord() const;
0060 
0061     std::uint32_t getCRC() const;
0062     unsigned int getBlockNumber() const;
0063     unsigned int getEventCounter() const;
0064     unsigned int getBXCounter() const;
0065 
0066     void setCRC(std::uint32_t crc);
0067     void setBlockNumber(unsigned int block_number);
0068     void setEventCounter(unsigned int event_counter);
0069     void setBXCounter(unsigned int bx_counter);
0070 
0071   protected:
0072     std::uint64_t record_;
0073   };
0074 
0075   class AMCHeader {  // http://joule.bu.edu/~hazen/CMS/AMC13/UpdatedDAQPath.pdf
0076   protected:
0077     static std::uint64_t const length_incorrect_mask_ = 0x4000000000000000;
0078     static std::uint64_t const more_blocks_mask_ = 0x2000000000000000;  // is not last block
0079     static std::uint64_t const segmented_mask_ = 0x1000000000000000;    // is not first block
0080     static std::uint64_t const enabled_mask_ = 0x0800000000000000;
0081     static std::uint64_t const present_mask_ = 0x0400000000000000;
0082     static std::uint64_t const valid_mask_ = 0x0200000000000000;  // evn, bcn match
0083     static std::uint64_t const crc_ok_mask_ = 0x0100000000000000;
0084     static std::uint64_t const size_mask_ = 0x00ffffff00000000;
0085     static std::uint64_t const block_number_mask_ = 0x000000000ff00000;
0086     static std::uint64_t const amc_number_mask_ = 0x00000000000f0000;
0087     static std::uint64_t const board_id_mask_ = 0x000000000000ffff;
0088 
0089     static unsigned int const size_offset_ = 32;
0090     static unsigned int const block_number_offset_ = 20;
0091     static unsigned int const amc_number_offset_ = 16;
0092     static unsigned int const board_id_offset_ = 0;
0093 
0094     static unsigned int const size_limit_ = 0x1400;
0095     static unsigned int const size_max_ = 0x1000;
0096 
0097   public:
0098     AMCHeader(std::uint64_t const record = enabled_mask_ | present_mask_ | valid_mask_ | crc_ok_mask_);
0099     AMCHeader(bool length_correct,
0100               bool last_block,
0101               bool first_block,
0102               bool enabled,
0103               bool present,
0104               bool valid,
0105               bool crc_ok,
0106               unsigned int size,
0107               unsigned int block_number,
0108               unsigned int amc_number,
0109               unsigned int board_id);
0110 
0111     void set(std::uint64_t const record);
0112     void reset();
0113 
0114     std::uint64_t const& getRecord() const;
0115 
0116     bool isLengthCorrect() const;
0117     bool isLastBlock() const;
0118     bool isFirstBlock() const;
0119     bool isEnabled() const;
0120     bool isPresent() const;
0121     bool isValid() const;
0122     bool isCRCOk() const;
0123     unsigned int getSize() const;
0124     unsigned int getSizeInBlock() const;  // derived
0125     bool hasTotalSize() const;            // derived
0126     unsigned int getBlockNumber() const;
0127     unsigned int getAMCNumber() const;
0128     unsigned int getBoardId() const;
0129 
0130     void setLengthCorrect(bool length_correct);
0131     void setLastBlock(bool last_block);
0132     void setFirstBlock(bool first_block);
0133     void setEnabled(bool enabled);
0134     void setPresent(bool present);
0135     void setValid(bool valid);
0136     void setCRCOk(bool crc_ok);
0137     void setSize(unsigned int size);
0138     void setBlockNumber(unsigned int block_number);
0139     void setAMCNumber(unsigned int amc_number);
0140     void setBoardId(unsigned int board_id);
0141 
0142   protected:
0143     std::uint64_t record_;
0144   };
0145 
0146   class AMCPayload {
0147   public:
0148     AMCPayload();
0149 
0150     bool isValid() const;
0151     AMCHeader const& getAMCHeader() const;
0152     AMCHeader& getAMCHeader();
0153     std::vector<std::uint64_t> const& getData() const;
0154     std::vector<std::uint64_t>& getData();
0155 
0156     void setValid(bool valid);
0157     void setAMCHeader(AMCHeader const& header);
0158     void insert(std::uint64_t const* word_begin, unsigned int size);
0159     void clear();
0160 
0161   protected:
0162     bool valid_;
0163     AMCHeader amc_header_;
0164     std::vector<std::uint64_t> data_;
0165   };
0166 
0167 }  // namespace rpcamc13
0168 
0169 #include "EventFilter/RPCRawToDigi/interface/RPCAMC13Record.icc"
0170 
0171 #endif  // EventFilter_RPCRawToDigi_RPCAMC13Record_h