Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-06 23:49:38

0001 #ifndef EventFilter_SiPixelRawToDigi_interface_PixelDataFormatter_h
0002 #define EventFilter_SiPixelRawToDigi_interface_PixelDataFormatter_h
0003 /** \class PixelDataFormatter
0004  *
0005  *  Transforms Pixel raw data of a given  FED to orca digi
0006  *  and vice versa.
0007  *
0008  * FED OUTPUT DATA FORMAT 6/02, d.k.  (11/02 updated for 100*150 pixels)
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 PixelDataFormatter interpret/format ONLY detector data words
0031  * (not FED headers or trailer, which are treated elsewhere).
0032  */
0033 //
0034 // Add the phase1 format
0035 //
0036 // CMSSW include(s)
0037 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameReverter.h"
0038 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0039 #include "DataFormats/Common/interface/DetSetVector.h"
0040 #include "DataFormats/SiPixelRawData/interface/SiPixelRawDataError.h"
0041 #include "DataFormats/SiPixelDigi/interface/SiPixelDigiConstants.h"
0042 #include "DataFormats/DetId/interface/DetIdCollection.h"
0043 #include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h"
0044 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0045 #include "EventFilter/SiPixelRawToDigi/interface/ErrorChecker.h"
0046 #include "EventFilter/SiPixelRawToDigi/interface/ErrorCheckerPhase0.h"
0047 #include "FWCore/Utilities/interface/typedefs.h"
0048 
0049 // standard include(s)
0050 #include <vector>
0051 #include <map>
0052 #include <set>
0053 
0054 class FEDRawData;
0055 class SiPixelFedCabling;
0056 class SiPixelQuality;
0057 class SiPixelFrameConverter;
0058 class SiPixelFrameReverter;
0059 class SiPixelFedCablingTree;
0060 
0061 class PixelDataFormatter {
0062 public:
0063   using DetErrors = std::vector<SiPixelRawDataError>;
0064   using Errors = std::map<cms_uint32_t, DetErrors>;
0065   using Collection = edm::DetSetVector<PixelDigi>;
0066   using RawData = std::map<int, FEDRawData>;
0067   using DetDigis = std::vector<PixelDigi>;
0068   using Digis = std::map<cms_uint32_t, DetDigis>;
0069   using DetBadChannels = std::vector<PixelFEDChannel>;
0070   using BadChannels = std::map<cms_uint32_t, DetBadChannels>;
0071   using FEDWordsMap = std::map<int, std::vector<Word32>>;
0072   using ModuleIDSet = std::set<unsigned int>;
0073 
0074   PixelDataFormatter(const SiPixelFedCablingTree* map, bool phase1_ = false);
0075 
0076   void setErrorStatus(bool ErrorStatus);
0077   void setQualityStatus(bool QualityStatus, const SiPixelQuality* QualityInfo);
0078   void setModulesToUnpack(const ModuleIDSet* moduleIds);
0079   void passFrameReverter(const SiPixelFrameReverter* reverter);
0080 
0081   int nDigis() const { return theDigiCounter_; }
0082   int nWords() const { return theWordCounter_; }
0083 
0084   void interpretRawData(bool& errorsInEvent, int fedId, const FEDRawData& data, Collection& digis, Errors& errors);
0085 
0086   void formatRawData(unsigned int lvl1_ID, RawData& fedRawData, const Digis& digis, const BadChannels& badChannels);
0087 
0088   void unpackFEDErrors(Errors const& errors,
0089                        std::vector<int> const& tkerrorlist,
0090                        std::vector<int> const& usererrorlist,
0091                        edm::DetSetVector<SiPixelRawDataError>& errorcollection,
0092                        DetIdCollection& tkerror_detidcollection,
0093                        DetIdCollection& usererror_detidcollection,
0094                        edmNew::DetSetVector<PixelFEDChannel>& disabled_channelcollection,
0095                        DetErrors& nodeterrors);
0096 
0097 private:
0098   mutable int theDigiCounter_;
0099   mutable int theWordCounter_;
0100 
0101   SiPixelFedCablingTree const* theCablingTree_;
0102   const SiPixelFrameReverter* theFrameReverter_;
0103   const SiPixelQuality* badPixelInfo_;
0104   const ModuleIDSet* modulesToUnpack_;
0105 
0106   bool includeErrors_;
0107   bool useQualityInfo_;
0108   int allDetDigis_;
0109   int hasDetDigis_;
0110   std::unique_ptr<ErrorCheckerBase> errorcheck_;
0111 
0112   int maxROCIndex_;
0113   bool phase1_;
0114 
0115   int checkError(const Word32& data) const;
0116 
0117   int digi2word(cms_uint32_t detId, const PixelDigi& digi, FEDWordsMap& words) const;
0118   int digi2wordPhase1Layer1(cms_uint32_t detId, const PixelDigi& digi, FEDWordsMap& words) const;
0119 
0120   std::string print(const PixelDigi& digi) const;
0121   std::string print(const Word64& word) const;
0122 
0123   cms_uint32_t errorDetId(const SiPixelFrameConverter* converter, int fedId, int errorType, const Word32& word) const;
0124 };
0125 
0126 #endif  // EventFilter_SiPixelRawToDigi_interface_PixelDataFormatter_h