Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef GctFormatTranslateMCLegacy_h_
0002 #define GctFormatTranslateMCLegacy_h_
0003 
0004 #include "EventFilter/GctRawToDigi/src/GctFormatTranslateBase.h"
0005 
0006 /*!
0007 * \class GctFormatTranslateMCLegacy
0008 * \brief Unpacks/packs the MC Legacy data originally produced by the GctBlockPacker class.
0009 * 
0010 * The data produced by the legacy GctBlockPacker class should have a firmware version header
0011 * that wasn't set to anything, i.e.: 0x00000000
0012 *  
0013 * \author Robert Frazier
0014 */
0015 
0016 // ************************************************************************
0017 // ***  THE TRANSLATION PROCESS MUST NEVER THROW ANY KIND OF EXCEPTION! ***
0018 // ************************************************************************
0019 
0020 class GctFormatTranslateMCLegacy : public GctFormatTranslateBase {
0021 public:
0022   /* PUBLIC METHODS */
0023 
0024   /// Constructor.
0025   /*! \param hltMode - set true to unpack only BX zero and GCT output data (i.e. to run as quick as possible).
0026    *  \param unpackSharedRegions - this is a commissioning option to unpack the shared RCT calo regions. */
0027   explicit GctFormatTranslateMCLegacy(bool hltMode = false, bool unpackSharedRegions = false);
0028 
0029   ~GctFormatTranslateMCLegacy() override;  ///< Destructor.
0030 
0031   /// Generate a block header from four 8-bit values.
0032   GctBlockHeader generateBlockHeader(const unsigned char* data) const override;
0033 
0034   /// Get digis from the block - will return true if it succeeds, false otherwise.
0035   bool convertBlock(const unsigned char* d, const GctBlockHeader& hdr) override;
0036 
0037   /* ------------------------------ */
0038   /* Public Block Packing Functions */
0039   /* ------------------------------ */
0040 
0041   /// Writes GCT output EM and energy sums block into an unsigned char array, starting at the position pointed to by d.
0042   /*! \param d must be pointing at the position where the EM Output block header should be written! */
0043   void writeGctOutEmAndEnergyBlock(unsigned char* d,
0044                                    const L1GctEmCandCollection* iso,
0045                                    const L1GctEmCandCollection* nonIso,
0046                                    const L1GctEtTotalCollection* etTotal,
0047                                    const L1GctEtHadCollection* etHad,
0048                                    const L1GctEtMissCollection* etMiss);
0049 
0050   /// Writes GCT output jet cands and counts into an unsigned char array, starting at the position pointed to by d.
0051   /*! \param d must be pointing at the position where the Jet Output block header should be written! */
0052   void writeGctOutJetBlock(unsigned char* d,
0053                            const L1GctJetCandCollection* cenJets,
0054                            const L1GctJetCandCollection* forJets,
0055                            const L1GctJetCandCollection* tauJets,
0056                            const L1GctHFRingEtSumsCollection* hfRingSums,
0057                            const L1GctHFBitCountsCollection* hfBitCounts,
0058                            const L1GctHtMissCollection* htMiss);
0059 
0060   /// Writes the 4 RCT EM Candidate blocks.
0061   void writeRctEmCandBlocks(unsigned char* d, const L1CaloEmCollection* rctEm);
0062 
0063   /// Writes the giant hack that is the RCT Calo Regions block.
0064   void writeAllRctCaloRegionBlock(unsigned char* d, const L1CaloRegionCollection* rctCalo);
0065 
0066 protected:
0067   /* PROTECTED METHODS */
0068 
0069   /* Static data member access methods */
0070   const BlockLengthMap& blockLengthMap() const final {
0071     return m_blockLength;
0072   }  ///< get the static block ID to block-length map.
0073 
0074   const BlockNameMap& blockNameMap() const final { return m_blockName; }  ///< get the static block ID to blockname map.
0075 
0076   const BlkToRctCrateMap& rctEmCrateMap() const final {
0077     return m_rctEmCrate;
0078   }  ///< get static the block ID to RCT crate map for electrons.
0079 
0080   const BlkToRctCrateMap& rctJetCrateMap() const final {
0081     return m_rctJetCrate;
0082   }  ///< get the static block ID to RCT crate map for jets
0083 
0084   const BlockIdToEmCandIsoBoundMap& internEmIsoBounds() const final {
0085     return m_internEmIsoBounds;
0086   }  ///< get the static intern EM cand isolated boundary map.
0087 
0088   /* Other general methods */
0089   /// Returns a raw 32-bit header word generated from the blockId, number of time samples, bunch-crossing and event IDs.
0090   uint32_t generateRawHeader(const uint32_t blockId,
0091                              const uint32_t nSamples,
0092                              const uint32_t bxId,
0093                              const uint32_t eventId) const override;
0094 
0095 private:
0096   /* PRIVATE TYPES & TYPEDEFS */
0097 
0098   /// Function pointer typdef to a block unpack function.
0099   typedef void (GctFormatTranslateMCLegacy::*PtrToUnpackFn)(const unsigned char*, const GctBlockHeader&);
0100   /// Typedef for a block ID to unpack function map.
0101   typedef std::map<unsigned int, PtrToUnpackFn> BlockIdToUnpackFnMap;
0102 
0103   /* PRIVATE MEMBER DATA */
0104 
0105   /// Map to translate block number to fundamental size of a block (i.e. for 1 time-sample).
0106   static const BlockLengthMap m_blockLength;
0107 
0108   /// Map to hold a description for each block number.
0109   static const BlockNameMap m_blockName;
0110 
0111   /// Map to relate capture block ID to the RCT crate the data originated from (for electrons).
0112   static const BlkToRctCrateMap m_rctEmCrate;
0113 
0114   /// Map to relate capture block ID to the RCT crate the data originated from (for jets).
0115   static const BlkToRctCrateMap m_rctJetCrate;
0116 
0117   /*! A map of Block IDs to IsoBoundaryPairs for storing the location of the isolated
0118    *  Internal EM cands in the pipeline, as this differs with Block ID. */
0119   static const BlockIdToEmCandIsoBoundMap m_internEmIsoBounds;
0120 
0121   /// Block ID to unpack function map.
0122   static const BlockIdToUnpackFnMap m_blockUnpackFn;
0123 
0124   /* PRIVATE METHODS */
0125 
0126   /* --------------------------------- */
0127   /* Private Block Unpacking Functions */
0128   /* --------------------------------- */
0129 
0130   /// unpack GCT EM Candidates and energy sums.
0131   void blockToGctEmCandsAndEnergySums(const unsigned char* d, const GctBlockHeader& hdr);
0132 
0133   /// Unpack GCT Jet Candidates and jet counts.
0134   void blockToGctJetCandsAndCounts(const unsigned char* d, const GctBlockHeader& hdr);
0135 
0136   /// unpack RCT EM Candidates
0137   void blockToRctEmCand(const unsigned char* d, const GctBlockHeader& hdr);
0138 
0139   /// unpack Fibres
0140   void blockToFibres(const unsigned char* d, const GctBlockHeader& hdr);
0141 
0142   /// unpack Fibres and RCT EM Candidates
0143   void blockToFibresAndToRctEmCand(const unsigned char* d, const GctBlockHeader& hdr);
0144 
0145   /// Unpack All RCT Calo Regions ('orrible hack for DigiToRaw use)
0146   void blockToAllRctCaloRegions(const unsigned char* d, const GctBlockHeader& hdr);
0147 
0148   /* ----------------------------- */
0149   /* Miscellaneous Private Methods */
0150   /* ----------------------------- */
0151 
0152   /// Template function (used in packing) that will find the offset to first item in a collection vector where bx=0.
0153   /*! Returns false if fails to find any item in the collection with bx=0 */
0154   template <typename Collection>
0155   bool findBx0OffsetInCollection(unsigned& bx0Offset, const Collection* coll);
0156 };
0157 
0158 #endif