Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef EventFilter_HGCalRawToDigi_HGCalRawDataPackingTools_h
0002 #define EventFilter_HGCalRawToDigi_HGCalRawDataPackingTools_h
0003 
0004 #include "EventFilter/HGCalRawToDigi/interface/SlinkTypes.h"
0005 
0006 namespace hgcal {
0007   namespace econd {
0008     struct ERxData;
0009     /// pack the ROC data to the ECON-D format dependending on:
0010     ///   - characterization mode : (TcTp + ADC + TOT + TOA) fixed 32b
0011     ///   - normal mode : size and fields depend on the TcTp flags
0012     /// \note based on Fig. 20 of ECON-D specifications
0013     /// \return a vector of new words
0014     std::vector<uint32_t> produceERxData(
0015         const ERxChannelEnable&, const ERxData&, bool passZS, bool passZSm1, bool hasToA, bool char_mode);
0016 
0017     /// returns the words for a new eRx header
0018     /// \note based on Fig. 33 of ECON-D specifications
0019     /// \return a vector with 1 or 2 32b words
0020     std::vector<uint32_t> eRxSubPacketHeader(uint8_t stat,
0021                                              uint8_t ham,
0022                                              bool bitE,
0023                                              uint16_t common_mode0,
0024                                              uint16_t common_mode1,
0025                                              const ERxChannelEnable& channel_enable);
0026     std::vector<uint32_t> eRxSubPacketHeader(
0027         uint8_t stat, uint8_t ham, bool bitE, uint16_t common_mode0, uint16_t common_mode1, uint64_t channels_map);
0028 
0029     /// builds the two ECON-D header words
0030     /// \note based on Fig. 33 of the ECON-D specs
0031     /// \return a vector of size 2 with the ECON-D header
0032     std::vector<uint32_t> eventPacketHeader(uint16_t header,
0033                                             uint16_t payload,
0034                                             bool bitP,
0035                                             bool bitE,
0036                                             uint8_t ht,
0037                                             uint8_t ebo,
0038                                             bool bitM,
0039                                             bool bitT,
0040                                             uint8_t hamming,
0041                                             uint16_t bx,
0042                                             uint16_t l1a,
0043                                             uint8_t orb,
0044                                             bool bitS,
0045                                             uint8_t RR);
0046     /// builds a trailing idle word
0047     /// \note based on Fig. 33 of the ECON-D specs
0048     /// \return a 32b word with the idle word
0049     uint32_t buildIdleWord(uint8_t bufStat, uint8_t err, uint8_t rr, uint32_t progPattern);
0050   }  // namespace econd
0051 
0052   namespace backend {
0053     enum ECONDPacketStatus {
0054       Normal = 0x0,
0055       PayloadCRCError = 0x1,
0056       EventIDMismatch = 0x2,
0057       EBTimeout = 0x4,
0058       BCIDOrbitIDMismatch = 0x5,
0059       MainBufferOverflow = 0x6,
0060       InactiveECOND = 0x7
0061     };
0062 
0063     /// builds the capture block header (see page 16 of "HGCAL BE DAQ firmware description")
0064     /// \return a vector of size 2 with the 2 32b words of the capture block header
0065     std::vector<uint32_t> buildCaptureBlockHeader(uint32_t bunch_crossing,
0066                                                   uint32_t event_counter,
0067                                                   uint32_t orbit_counter,
0068                                                   const std::vector<ECONDPacketStatus>& econd_statuses);
0069 
0070     /// builds the slink frame header (128 bits header = 4 words)
0071     /// \return a vector with 4 32b words
0072     std::vector<uint32_t> buildSlinkHeader(
0073         uint8_t boe, uint8_t v, uint64_t global_event_id, uint32_t content_id, uint32_t fed_id);
0074 
0075     /// builds the slink frame trailer (128 bits trailer = 4 words)
0076     /// \return a vector with 4 32b words
0077     std::vector<uint32_t> buildSlinkTrailer(uint8_t eoe,
0078                                             uint16_t daqcrc,
0079                                             uint32_t event_length,
0080                                             uint16_t bxid,
0081                                             uint32_t orbit_id,
0082                                             uint16_t crc,
0083                                             uint16_t status);
0084 
0085     enum SlinkEmulationFlag { Subsystem = 0, SlinkRocketSenderCore = 1, DTH = 2 };
0086     /// builds the slink rocket event data content ID
0087     /// \return a 32b word
0088     uint32_t buildSlinkContentId(SlinkEmulationFlag, uint8_t l1a_subtype, uint16_t l1a_fragment_cnt);
0089 
0090     /// builds the SlinkRocket sender core status field
0091     /// \return a 16b word
0092     uint16_t buildSlinkRocketStatus(
0093         bool fed_crc_err, bool slinkrocket_crc_err, bool source_id_err, bool sync_lost, bool fragment_trunc);
0094   }  // namespace backend
0095 }  // namespace hgcal
0096 
0097 #endif