Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /****************************************************************************
0002  *
0003  * This is a part of HGCAL offline software.
0004  * Authors:
0005  *   Yulun Miao, Northwestern University
0006  *   Huilin Qu, CERN
0007  *   Laurent Forthomme, CERN
0008  *
0009  ****************************************************************************/
0010 
0011 #ifndef EventFilter_HGCalRawToDigi_HGCalUnpacker_h
0012 #define EventFilter_HGCalRawToDigi_HGCalUnpacker_h
0013 
0014 #include "DataFormats/HGCalDigi/interface/HGCROCChannelDataFrame.h"
0015 #include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"
0016 
0017 #include <cstdint>
0018 #include <functional>
0019 #include <vector>
0020 
0021 struct HGCalUnpackerConfig {
0022   uint32_t sLinkBOE{0x0};               ///< S-Link BOE pattern
0023   uint32_t captureBlockReserved{0x3f};  ///< Capture block reserved pattern
0024   uint32_t econdHeaderMarker{0x154};    ///< ECON-D header Marker pattern
0025   uint32_t sLinkCaptureBlockMax{10};    ///< maximum number of capture blocks in one S-Link
0026   uint32_t captureBlockECONDMax{12};    ///< maximum number of ECON-Ds in one capture block
0027   uint32_t econdERXMax{12};             ///< maximum number of eRxs in one ECON-D
0028   uint32_t erxChannelMax{37};           ///< maximum number of channels in one eRx
0029   uint32_t payloadLengthMax{469};       ///< maximum length of payload length
0030   uint32_t channelMax{7000000};         ///< maximum number of channels unpacked
0031   uint32_t commonModeMax{4000000};      ///< maximum number of common modes unpacked
0032 };
0033 
0034 /// This class is designed to unpack raw data from HGCal, formatted as S-Links, capture blocks, and ECON-Ds, to HGCROC channel data.
0035 template <class D>
0036 class HGCalUnpacker {
0037 public:
0038   enum SLinkHeaderShift {
0039     kSLinkBOEShift = 24,
0040   };
0041   enum SLinkHeaderMask {
0042     kSLinkBOEMask = 0b11111111,
0043   };
0044   enum CaptureBlockHeaderShift {
0045     kCaptureBlockReservedShift = 26,
0046   };
0047   enum CaptureBlockMask {
0048     kCaptureBlockReservedMask = 0b111111,
0049     kCaptureBlockECONDStatusMask = 0b111,
0050   };
0051   enum ECONDHeaderShift {
0052     kHeaderShift = 23,
0053     kPayloadLengthShift = 14,
0054     kPassThroughShift = 13,
0055     kHTShift = 10,
0056     kEBOShift = 8,
0057     kMatchShift = 7,
0058     kTruncatedShift = 6,
0059   };
0060   enum ECONDHeaderMask {
0061     kHeaderMask = 0b111111111,
0062     kPayloadLengthMask = 0b111111111,
0063     kPassThroughMask = 0b1,
0064     kHTMask = 0b11,
0065     kEBOMask = 0b11,
0066     kMatchMask = 0b1,
0067     kTruncatedMask = 0b1,
0068   };
0069   enum ERXHeaderShift {
0070     kFormatShift = 25,
0071     kCommonmode0Shift = 15,
0072     kCommonmode1Shift = 5,
0073   };
0074   enum ERXHeaderMask {
0075     kFormatMask = 0b1,
0076     kCommonmode0Mask = 0b1111111111,
0077     kCommonmode1Mask = 0b1111111111,
0078   };
0079 
0080   explicit HGCalUnpacker(HGCalUnpackerConfig config);
0081 
0082   /// parse input in S-Link format
0083   /// \param[in] inputArray input as 32-bits words vector.
0084   /// \param[in] enabledERXMapping map from S-Link indices to enabled eRx in this ECON-D
0085   /// \param[in] logicalMapping logical mapping from HGCalElectronicsId to class D as ID
0086   void parseSLink(const std::vector<uint32_t>& inputArray,
0087                   const std::function<uint16_t(uint16_t sLink, uint8_t captureBlock, uint8_t econd)>& enabledERXMapping,
0088                   const std::function<D(HGCalElectronicsId elecID)>& logicalMapping);
0089   /// parse input in capture block format
0090   /// \param[in] inputArray input as 32-bits words vector.
0091   /// \param[in] enabledERXMapping map from capture block indices to enabled eRx in this ECON-D
0092   /// \param[in] logicalMapping logical mapping from HGCalElectronicsId to class D as ID
0093   void parseCaptureBlock(
0094       const std::vector<uint32_t>& inputArray,
0095       const std::function<uint16_t(uint16_t sLink, uint8_t captureBlock, uint8_t econd)>& enabledERXMapping,
0096       const std::function<D(HGCalElectronicsId elecID)>& logicalMapping);
0097   /// parse input in ECON-D format
0098   /// \param[in] inputArray input as 32-bits words vector.
0099   /// \param[in] enabledERXMapping map from ECON-D indices to enabled eRx in this ECON-D
0100   /// \param[in] logicalMapping logical mapping from HGCalElectronicsId to class D as ID
0101   void parseECOND(const std::vector<uint32_t>& inputArray,
0102                   const std::function<uint16_t(uint16_t sLink, uint8_t captureBlock, uint8_t econd)>& enabledERXMapping,
0103                   const std::function<D(HGCalElectronicsId elecID)>& logicalMapping);
0104 
0105   /// \return vector of HGCROCChannelDataFrame<D>(ID, value)
0106   const std::vector<HGCROCChannelDataFrame<D> >& channelData() const { return channelData_; }
0107   /// \return vector of 32-bit index, the length is the same as channelData(), link from channel data to the first common mode on ROC (+0,+1,+2,+3 for all four common modes)
0108   const std::vector<uint32_t>& commonModeIndex() const { return commonModeIndex_; }
0109   /// \return vector of 16-bit common mode data, lowest 10 bits is the ADC of the common mode, padding to 4 for half ROC turned on
0110   const std::vector<uint16_t>& commonModeData() const { return commonModeData_; }
0111   const std::vector<uint32_t>& badECOND() const { return badECOND_; }
0112 
0113 private:
0114   const uint32_t erxBodyLeftShift_[16] = {2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0115   const uint32_t erxBodyRightShift_[16] = {0, 8, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0116   const uint32_t erxBodyMask_[16] = {0b00111111111111111111110000000000,
0117                                      0b00000000000011111111110000000000,
0118                                      0b00111111111111111111110000000000,
0119                                      0b00000000000011111111111111111111,
0120                                      0b00111111111111111111111111111111,
0121                                      0b00111111111111111111111111111111,
0122                                      0b00111111111111111111111111111111,
0123                                      0b00111111111111111111111111111111,
0124                                      0b11111111111111111111111111111111,
0125                                      0b11111111111111111111111111111111,
0126                                      0b11111111111111111111111111111111,
0127                                      0b11111111111111111111111111111111,
0128                                      0b11111111111111111111111111111111,
0129                                      0b11111111111111111111111111111111,
0130                                      0b11111111111111111111111111111111,
0131                                      0b11111111111111111111111111111111};
0132   const uint32_t erxBodyBits_[16] = {24, 16, 24, 24, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32};
0133   HGCalUnpackerConfig config_;
0134   size_t channelDataSize_{0};                            ///< Size of unpacked channels
0135   size_t commonModeDataSize_{0};                         ///< Size of unpacked common modes
0136   std::vector<HGCROCChannelDataFrame<D> > channelData_;  ///< Array for unpacked channels
0137   std::vector<uint32_t> commonModeIndex_;  ///< Array for logicalMapping between unpacked channels to first common mode
0138   std::vector<uint16_t> commonModeData_;   ///< Array for unpacked common modes
0139   std::vector<uint32_t> badECOND_;         ///< Array of indices of bad ECON-Ds
0140 };
0141 
0142 #endif