Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 "EventFilter/CTPPSRawToDigi/interface/CTPPSRawToDigiErrorSummary.h"
0046 
0047 #include <cstdint>
0048 #include <vector>
0049 #include <map>
0050 #include <unordered_map>
0051 
0052 class FEDRawData;
0053 class RPixErrorChecker;
0054 
0055 class CTPPSPixelDataFormatter {
0056 public:
0057   typedef edm::DetSetVector<CTPPSPixelDigi> Collection;
0058 
0059   typedef std::unordered_map<int, FEDRawData> RawData;
0060   typedef std::vector<CTPPSPixelDigi> DetDigis;
0061 
0062   typedef std::vector<CTPPSPixelDataError> DetErrors;
0063   typedef std::map<uint32_t, DetErrors> Errors;
0064 
0065   typedef uint32_t Word32;
0066   typedef uint64_t Word64;
0067 
0068   typedef std::unordered_map<cms_uint32_t, DetDigis> Digis;
0069 
0070   CTPPSPixelDataFormatter(std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo> const& mapping,
0071                           CTPPSRawToDigiErrorSummary&);
0072 
0073   void setErrorStatus(bool theErrorStatus);
0074 
0075   int nWords() const { return m_WordCounter; }
0076 
0077   void interpretRawData(
0078       const bool& isRun3, bool& errorsInEvent, int fedId, const FEDRawData& data, Collection& digis, Errors& errors);
0079 
0080   int nDigis() const { return m_DigiCounter; }
0081 
0082   struct PPSPixelIndex {
0083     uint32_t id;
0084     unsigned int roc;
0085     short unsigned int rocch;
0086     short unsigned int fedid;
0087     short unsigned int fedch;
0088   };
0089 
0090   void formatRawData(const bool& isRun3,
0091                      unsigned int lvl1_ID,
0092                      RawData& fedRawData,
0093                      const Digis& digis,
0094                      std::vector<PPSPixelIndex> v_iDdet2fed);
0095 
0096   static bool compare(const PPSPixelIndex& a, const PPSPixelIndex& b) {
0097     return a.id < b.id || (a.id == b.id && a.roc < b.roc);
0098   }
0099 
0100   void printErrorSummary() const { m_ErrorSummary.printSummary(); }
0101 
0102 private:
0103   int m_WordCounter;
0104 
0105   bool m_IncludeErrors;
0106   RPixErrorChecker m_ErrorCheck;
0107 
0108   int m_ADC_shift, m_PXID_shift, m_DCOL_shift, m_ROC_shift, m_LINK_shift, m_COL_shift, m_ROW_shift;
0109   Word32 m_LINK_mask, m_ROC_mask, m_DCOL_mask, m_PXID_mask, m_ADC_mask, m_COL_mask, m_ROW_mask;
0110 
0111   int checkError(const Word32& data) const;
0112 
0113   std::string print(const Word64& word) const;
0114 
0115   const std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>& m_Mapping;
0116 
0117   int m_DigiCounter;
0118   int m_allDetDigis;
0119   int m_hasDetDigis;
0120   CTPPSPixelIndices m_Indices;
0121   CTPPSRawToDigiErrorSummary& m_ErrorSummary;
0122 };
0123 
0124 #endif