Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-05 22:26:05

0001 #ifndef CTPPS_CTPPSRawToDigi_CTPPSPixelDataFormatter_h
0002 #define CTPPS_CTPPSRawToDigi_CTPPSPixelDataFormatter_h
0003 /** \class CTPPSPixelDataFormatter
0004  *
0005  *  Transform CTPPSPixel raw data of a given  FED to digi
0006  *  
0007  *
0008  * FED OUTPUT DATA FORMAT (F.Ferro from SiPixel code)
0009  * ----------------------
0010  * The output is transmitted through a 64 bit S-link connection.
0011  * The packet format is defined by the CMS RU group to be :
0012  * 1st packet header, 64 bits, includes a 6 bit FED id.
0013  * 2nd packet header, 64 bits.
0014  * .......................... (detector data)
0015  * packet trailer, 64 bits.
0016  * of the 64 bit pixel data records consists of 2
0017  * 32 bit words. Each 32 bit word includes data from 1 pixel,
0018  * the bit fields are the following:
0019  *
0020  * 6 bit link ID (max 36)   - this defines the input link within 1 FED.
0021  * 5 bit ROC ID (max 24)    - this defines the readout chip within one link.
0022  * 5 bit DCOL ID (max 26)   - this defines the double column index with 1 chip.
0023  * 8 bit pixel ID (max 180) - this defines the pixel address within 1 DCOL.
0024  * 8 bit ADC vales          - this has the charge amplitude.
0025  *
0026  * So, 1 pixel occupies 4 bytes.
0027  * If the number of pixels is odd, one extra 32 bit word is added (value 0)
0028  * to fill all 64 bits.
0029  *
0030  * The CTPPSPixelDataFormatter interpret/format ONLY detector data words
0031  * (not FED headers or trailer, which are treated elsewhere).
0032  */
0033 
0034 #include "DataFormats/CTPPSDigi/interface/CTPPSPixelDigi.h"
0035 #include "DataFormats/CTPPSDigi/interface/CTPPSPixelDataError.h"
0036 #include "CondFormats/PPSObjects/interface/CTPPSPixelDAQMapping.h"
0037 #include "DataFormats/Common/interface/DetSetVector.h"
0038 
0039 #include "EventFilter/CTPPSRawToDigi/interface/RPixErrorChecker.h"
0040 
0041 #include "CondFormats/PPSObjects/interface/CTPPSPixelIndices.h"
0042 #include "EventFilter/CTPPSRawToDigi/interface/ElectronicIndex.h"
0043 #include "FWCore/Utilities/interface/typedefs.h"
0044 
0045 #include <cstdint>
0046 #include <vector>
0047 #include <map>
0048 #include <unordered_map>
0049 
0050 class FEDRawData;
0051 class RPixErrorChecker;
0052 
0053 class CTPPSPixelDataFormatter {
0054 public:
0055   typedef edm::DetSetVector<CTPPSPixelDigi> Collection;
0056 
0057   typedef std::unordered_map<int, FEDRawData> RawData;
0058   typedef std::vector<CTPPSPixelDigi> DetDigis;
0059 
0060   typedef std::vector<CTPPSPixelDataError> DetErrors;
0061   typedef std::map<uint32_t, DetErrors> Errors;
0062 
0063   typedef uint32_t Word32;
0064   typedef uint64_t Word64;
0065 
0066   typedef std::unordered_map<cms_uint32_t, DetDigis> Digis;
0067 
0068   CTPPSPixelDataFormatter(std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo> const& mapping);
0069 
0070   void setErrorStatus(bool theErrorStatus);
0071 
0072   int nWords() const { return m_WordCounter; }
0073 
0074   void interpretRawData(
0075       const bool& isRun3, bool& errorsInEvent, int fedId, const FEDRawData& data, Collection& digis, Errors& errors);
0076 
0077   int nDigis() const { return m_DigiCounter; }
0078 
0079   struct PPSPixelIndex {
0080     uint32_t id;
0081     unsigned int roc;
0082     short unsigned int rocch;
0083     short unsigned int fedid;
0084     short unsigned int fedch;
0085   };
0086 
0087   void formatRawData(const bool& isRun3,
0088                      unsigned int lvl1_ID,
0089                      RawData& fedRawData,
0090                      const Digis& digis,
0091                      std::vector<PPSPixelIndex> v_iDdet2fed);
0092 
0093   static bool compare(const PPSPixelIndex& a, const PPSPixelIndex& b) {
0094     return a.id < b.id || (a.id == b.id && a.roc < b.roc);
0095   }
0096 
0097 private:
0098   int m_WordCounter;
0099 
0100   bool m_IncludeErrors;
0101   RPixErrorChecker m_ErrorCheck;
0102 
0103   int m_ADC_shift, m_PXID_shift, m_DCOL_shift, m_ROC_shift, m_LINK_shift, m_COL_shift, m_ROW_shift;
0104   Word32 m_LINK_mask, m_ROC_mask, m_DCOL_mask, m_PXID_mask, m_ADC_mask, m_COL_mask, m_ROW_mask;
0105 
0106   int checkError(const Word32& data) const;
0107 
0108   std::string print(const Word64& word) const;
0109 
0110   const std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>& m_Mapping;
0111 
0112   int m_DigiCounter;
0113   int m_allDetDigis;
0114   int m_hasDetDigis;
0115   CTPPSPixelIndices m_Indices;
0116 };
0117 
0118 #endif