Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:58

0001 #ifndef EventFilter_RPCRawToDigi_RPCTwinMuxRecord_h
0002 #define EventFilter_RPCRawToDigi_RPCTwinMuxRecord_h
0003 
0004 #include <cstdint>
0005 
0006 namespace rpctwinmux {
0007 
0008   class TwinMuxRecord {
0009   public:
0010     /** Some of the types as defined in TwinMux_uROS_payload_v12.xlsx  **/
0011     static unsigned int const rpc_first_type_ = 0;
0012     static unsigned int const rpc_second_type_ = 1;
0013     static unsigned int const error_type_ = 2;
0014     static unsigned int const unknown_type_ = 3;
0015 
0016     static std::uint64_t const rpc_first_identifier_mask_ = 0xf000000000000000;
0017     static std::uint64_t const rpc_first_identifier_ = 0x9000000000000000;
0018     static std::uint64_t const rpc_second_identifier_mask_ = 0xf000000000000000;
0019     static std::uint64_t const rpc_second_identifier_ = 0xe000000000000000;
0020     static std::uint64_t const error_identifier_mask_ = 0xf000000000000000;
0021     static std::uint64_t const error_identifier_ = 0xf000000000000000;
0022 
0023   public:
0024     TwinMuxRecord(std::uint64_t const record = 0x0);
0025 
0026     static unsigned int getType(std::uint64_t const record);
0027     unsigned int getType() const;
0028 
0029     void set(std::uint64_t const record);
0030     void reset();
0031 
0032     std::uint64_t const& getRecord() const;
0033 
0034   protected:
0035     std::uint64_t record_;
0036   };
0037 
0038   class BlockHeader {
0039   public:
0040     static std::uint64_t const ufov_mask_ = 0xf000000000000000;
0041     static std::uint64_t const n_amc_mask_ = 0x00f0000000000000;
0042     static std::uint64_t const orbit_counter_mask_ = 0x0000000ffffffff0;
0043 
0044     static unsigned int const ufov_offset_ = 60;
0045     static unsigned int const n_amc_offset_ = 52;
0046     static unsigned int const orbit_counter_offset_ = 4;
0047 
0048   public:
0049     BlockHeader(std::uint64_t const record = 0x0);
0050     BlockHeader(unsigned int ufov, unsigned int n_amc, unsigned int orbit_counter);
0051 
0052     void set(std::uint64_t const record);
0053     void reset();
0054 
0055     std::uint64_t const& getRecord() const;
0056 
0057     unsigned int getFirmwareVersion() const;
0058     unsigned int getNAMC() const;
0059     unsigned int getOrbitCounter() const;
0060 
0061     void setFirmwareVersion(unsigned int ufov);
0062     void setNAMC(unsigned int n_amc);
0063     void setOrbitCounter(unsigned int orbit_counter);
0064 
0065   protected:
0066     std::uint64_t record_;
0067   };
0068 
0069   class BlockTrailer {
0070   public:
0071     static std::uint64_t const crc_mask_ = 0xffffffff00000000;
0072     static std::uint64_t const block_number_mask_ = 0x000000000ff00000;
0073     static std::uint64_t const event_counter_mask_ = 0x00000000000ff000;
0074     static std::uint64_t const bx_counter_mask_ = 0x0000000000000fff;
0075 
0076     static unsigned int const crc_offset_ = 32;
0077     static unsigned int const block_number_offset_ = 20;
0078     static unsigned int const event_counter_offset_ = 12;
0079     static unsigned int const bx_counter_offset_ = 0;
0080 
0081   public:
0082     BlockTrailer(std::uint64_t const record = 0x0);
0083     BlockTrailer(std::uint32_t crc, unsigned int block_number, unsigned int event_counter, unsigned int bx_counter);
0084 
0085     void set(std::uint64_t const record);
0086     void reset();
0087 
0088     std::uint64_t const& getRecord() const;
0089 
0090     std::uint32_t getCRC() const;
0091     unsigned int getBlockNumber() const;
0092     unsigned int getEventCounter() const;
0093     unsigned int getBXCounter() const;
0094 
0095     void setCRC(std::uint32_t crc);
0096     void setBlockNumber(unsigned int block_number);
0097     void setEventCounter(unsigned int event_counter);
0098     void setBXCounter(unsigned int bx_counter);
0099 
0100   protected:
0101     std::uint64_t record_;
0102   };
0103 
0104   class BlockAMCContent {
0105   public:
0106     static std::uint64_t const length_correct_mask_ = 0x4000000000000000;
0107     static std::uint64_t const more_blocks_mask_ = 0x2000000000000000;  // is not last block
0108     static std::uint64_t const segmented_mask_ = 0x1000000000000000;    // is not first block
0109     static std::uint64_t const enabled_mask_ = 0x0800000000000000;
0110     static std::uint64_t const present_mask_ = 0x0400000000000000;
0111     static std::uint64_t const valid_mask_ = 0x0200000000000000;  // evn, bcn match
0112     static std::uint64_t const crc_ok_mask_ = 0x0100000000000000;
0113     static std::uint64_t const size_mask_ = 0x00ffffff00000000;
0114     static std::uint64_t const block_number_mask_ = 0x000000000ff00000;
0115     static std::uint64_t const amc_number_mask_ = 0x00000000000f0000;
0116     static std::uint64_t const board_id_mask_ = 0x000000000000ffff;
0117 
0118     static unsigned int const size_offset_ = 32;
0119     static unsigned int const block_number_offset_ = 20;
0120     static unsigned int const amc_number_offset_ = 16;
0121     static unsigned int const board_id_offset_ = 0;
0122 
0123   public:
0124     BlockAMCContent(std::uint64_t const record = 0x0);
0125     BlockAMCContent(bool length_correct,
0126                     bool last_block,
0127                     bool first_block,
0128                     bool enabled,
0129                     bool present,
0130                     bool valid,
0131                     bool crc_ok,
0132                     unsigned int size,
0133                     unsigned int block_number,
0134                     unsigned int amc_number,
0135                     unsigned int board_id);
0136 
0137     void set(std::uint64_t const record);
0138     void reset();
0139 
0140     std::uint64_t const& getRecord() const;
0141 
0142     bool isLengthCorrect() const;
0143     bool isLastBlock() const;
0144     bool isFirstBlock() const;
0145     bool isEnabled() const;
0146     bool isPresent() const;
0147     bool isValid() const;
0148     bool isCRCOk() const;
0149     unsigned int getSize() const;
0150     unsigned int getBlockNumber() const;
0151     unsigned int getAMCNumber() const;
0152     unsigned int getBoardId() const;
0153 
0154     void setLengthCorrect(bool length_correct);
0155     void setLastBlock(bool last_block);
0156     void setFirstBlock(bool first_block);
0157     void setEnabled(bool enabled);
0158     void setPresent(bool present);
0159     void setValid(bool valid);
0160     void setCRCOk(bool crc_ok);
0161     void setSize(unsigned int size);
0162     void setBlockNumber(unsigned int block_number);
0163     void setAMCNumber(unsigned int amc_number);
0164     void setBoardId(unsigned int board_id);
0165 
0166   protected:
0167     std::uint64_t record_;
0168   };
0169 
0170   class TwinMuxHeader {
0171   public:
0172     // First Word
0173     static std::uint64_t const amc_number_mask_ = 0x0f00000000000000;
0174     static std::uint64_t const event_counter_mask_ = 0x00ffffff00000000;
0175     static std::uint64_t const bx_counter_mask_ = 0x00000000fff00000;
0176     static std::uint64_t const data_length_mask_ = 0x00000000000fffff;
0177 
0178     static unsigned int const amc_number_offset_ = 56;
0179     static unsigned int const event_counter_offset_ = 32;
0180     static unsigned int const bx_counter_offset_ = 20;
0181     static unsigned int const data_length_offset_ = 0;
0182 
0183     // Second word
0184     static std::uint64_t const orbit_counter_mask_ = 0x00000000ffff0000;
0185     static std::uint64_t const board_id_mask_ = 0x000000000000ffff;
0186 
0187     static unsigned int const orbit_counter_offset_ = 16;
0188     static unsigned int const board_id_offset_ = 0;
0189 
0190     static std::uint64_t const dt_bx_window_mask_ = 0x0000001f00000000;
0191     static std::uint64_t const rpc_bx_window_mask_ = 0x000003e000000000;
0192     static std::uint64_t const ho_bx_window_mask_ = 0x00001c0000000000;
0193 
0194     static unsigned int const dt_bx_window_offset_ = 32;
0195     static unsigned int const rpc_bx_window_offset_ = 37;
0196     static unsigned int const ho_bx_window_offset_ = 42;
0197 
0198   public:
0199     TwinMuxHeader();
0200     TwinMuxHeader(std::uint64_t const record[2]);
0201     TwinMuxHeader(unsigned int amc_number,
0202                   unsigned int event_counter,
0203                   unsigned int bx_counter,
0204                   unsigned int data_length,
0205                   unsigned int orbit_counter,
0206                   unsigned int board_id,
0207                   unsigned int dt_bx_window = 0x1f,
0208                   int rpc_bx_min = 10,
0209                   int rpc_bx_max = 5  // values for !hasRPCBXWindows
0210                   ,
0211                   unsigned int ho_bx_window = 0x7);
0212 
0213     void set(unsigned int nword, std::uint64_t const word);
0214     void reset();
0215 
0216     std::uint64_t const* getRecord() const;
0217 
0218     unsigned int getAMCNumber() const;
0219     unsigned int getEventCounter() const;
0220     unsigned int getBXCounter() const;
0221     unsigned int getDataLength() const;
0222 
0223     unsigned int getOrbitCounter() const;
0224     unsigned int getBoardId() const;
0225 
0226     bool hasDTBXWindow() const;
0227     unsigned int getDTBXWindow() const;
0228     bool hasRPCBXWindow() const;
0229     int getRPCBXMin() const;
0230     int getRPCBXMax() const;
0231     bool hasHOBXWindow() const;
0232     unsigned int getHOBXWindow() const;
0233 
0234     void setAMCNumber(unsigned int amc_number);
0235     void setEventCounter(unsigned int event_counter);
0236     void setBXCounter(unsigned int bx_counter);
0237     void setDataLength(unsigned int data_length);
0238 
0239     void setOrbitCounter(unsigned int orbit_counter);
0240     void setBoardId(unsigned int board_id);
0241 
0242     void setDTBXWindow(unsigned int bx_window = 0x1f);
0243     void setRPCBXWindow(int bx_min = 10, int bx_max = 5);  // values for !hasRPCBXWindows
0244     void setHOBXWindow(unsigned int bx_window = 0x7);
0245 
0246   protected:
0247     std::uint64_t record_[2];
0248   };
0249 
0250   class TwinMuxTrailer {
0251   public:
0252     static std::uint64_t const crc_mask_ = 0xffffffff00000000;
0253     static std::uint64_t const event_counter_mask_ = 0x00000000ff000000;
0254     static std::uint64_t const data_length_mask_ = 0x00000000000fffff;
0255 
0256     static unsigned int const crc_offset_ = 32;
0257     static unsigned int const event_counter_offset_ = 24;
0258     static unsigned int const data_length_offset_ = 0;
0259 
0260   public:
0261     TwinMuxTrailer(std::uint64_t const record = 0x0);
0262     TwinMuxTrailer(std::uint32_t crc, unsigned int event_counter, unsigned int data_length);
0263 
0264     void set(std::uint64_t const record);
0265     void reset();
0266 
0267     std::uint64_t const& getRecord() const;
0268 
0269     std::uint32_t getCRC() const;
0270     unsigned int getEventCounter() const;
0271     unsigned int getDataLength() const;
0272 
0273     void setCRC(std::uint32_t crc);
0274     void setEventCounter(unsigned int event_counter);
0275     void setDataLength(unsigned int data_length);
0276 
0277   protected:
0278     std::uint64_t record_;
0279   };
0280 
0281   class RPCLinkRecord {
0282   public:
0283     static std::uint32_t const da_mask_ = 0x080000;
0284     static std::uint32_t const de_mask_ = 0x040000;
0285     static std::uint32_t const eod_mask_ = 0x020000;
0286     static std::uint32_t const delay_mask_ = 0x01c000;
0287     static std::uint32_t const link_board_mask_ = 0x003000;
0288     static std::uint32_t const connector_mask_ = 0x000e00;
0289     static std::uint32_t const partition_mask_ = 0x000100;
0290     static std::uint32_t const partition_data_mask_ = 0x0000ff;
0291 
0292     static unsigned int const delay_offset_ = 14;
0293     static unsigned int const link_board_offset_ = 12;
0294     static unsigned int const connector_offset_ = 9;
0295     static unsigned int const partition_offset_ = 8;
0296     static unsigned int const partition_data_offset_ = 0;
0297 
0298   public:
0299     RPCLinkRecord(std::uint32_t const record = da_mask_);
0300 
0301     void set(std::uint32_t const record = da_mask_);
0302     void reset();
0303 
0304     std::uint32_t const& getRecord() const;
0305 
0306     bool isAcknowledge() const;
0307     bool isError() const;
0308     bool isEOD() const;
0309     unsigned int getDelay() const;
0310     unsigned int getLinkBoard() const;
0311     unsigned int getConnector() const;
0312     unsigned int getPartition() const;
0313     std::uint8_t getPartitionData() const;
0314 
0315     void setAcknowledge(bool da);
0316     void setError(bool de);
0317     void setEOD(bool eod);
0318     void setDelay(unsigned int delay);
0319     void setLinkBoard(unsigned int link_board);
0320     void setConnector(unsigned int connector);
0321     void setPartition(unsigned int partition);
0322     void setPartitionData(std::uint8_t data);
0323 
0324   protected:
0325     std::uint32_t record_;
0326   };
0327 
0328   class RPCBXRecord {
0329   public:
0330     static std::uint8_t const bc0_mask_ = 0x04;
0331     static std::uint8_t const bcn_mask_ = 0x03;
0332     static unsigned int const bcn_offset_ = 0;
0333 
0334   public:
0335     RPCBXRecord(std::uint8_t const record = 0x0);
0336 
0337     void set(std::uint8_t const record = 0x0);
0338     void reset();
0339 
0340     std::uint8_t const& getRecord() const;
0341 
0342     bool isBC0() const;
0343     unsigned int getBXCounter() const;
0344 
0345     void setBC0(bool bc0);
0346     void setBXCounter(unsigned int bcn);
0347 
0348   protected:
0349     std::uint8_t record_;
0350   };
0351 
0352   class RPCRecord {
0353   public:
0354     static std::uint64_t const bx_offset_mask_ = 0x0f00000000000000;
0355     static std::uint64_t const overflow_mask_ = 0x0080000000000000;
0356 
0357     static unsigned int const bx_offset_offset_ = 56;
0358 
0359     static std::uint64_t const link_record_mask_ = 0x0fffff;
0360     static unsigned int const link_record_word_[5];
0361     static unsigned int const link_record_offset_[5];
0362 
0363     static std::uint64_t const bx_record_mask_ = 0x07;
0364     static unsigned int const bx_record_offset_[5];
0365 
0366   public:
0367     RPCRecord();
0368     RPCRecord(std::uint64_t const record[2]);
0369 
0370     void set(unsigned int word, std::uint64_t const record);
0371     void reset();
0372 
0373     std::uint64_t const* getRecord() const;
0374 
0375     int getBXOffset() const;
0376     bool hasOverflow() const;
0377     RPCBXRecord getRPCBXRecord(unsigned int link) const;
0378     RPCLinkRecord getRPCLinkRecord(unsigned int link) const;
0379 
0380     void setBXOffset(int bx_offset);
0381     void setOverflow(bool overflow);
0382     void setRPCBXRecord(unsigned int link, RPCBXRecord const& bx_record);
0383     void setRPCLinkRecord(unsigned int link, RPCLinkRecord const& link_record);
0384 
0385   protected:
0386     std::uint64_t record_[2];
0387   };
0388 
0389 }  // namespace rpctwinmux
0390 
0391 #include "EventFilter/RPCRawToDigi/interface/RPCTwinMuxRecord.icc"
0392 
0393 #endif  // EventFilter_RPCRawToDigi_RPCTwinMuxRecord_h