Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:45:25

0001 #ifndef GctFormatTranslateBase_h_
0002 #define GctFormatTranslateBase_h_
0003 
0004 // C++ includes
0005 #include <map>
0006 #include <utility>
0007 #include <string>
0008 
0009 // CMSSW includes
0010 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0011 #include "L1Trigger/TextToDigi/interface/SourceCardRouting.h"
0012 #include "EventFilter/GctRawToDigi/src/GctBlockHeader.h"
0013 #include "EventFilter/GctRawToDigi/src/GctUnpackCollections.h"
0014 
0015 /*!
0016 * \class GctFormatTranslateBase
0017 * \brief Abstract interface for RawToDigi/DigiToRaw conversions of GCT data.
0018 * 
0019 * This class provides the common interface/functionality for the various
0020 * concrete classes that can translate to/from specific RAW formats.
0021 *
0022 * \author Robert Frazier
0023 */
0024 
0025 class GctFormatTranslateBase {
0026 public:
0027   /// Constructor.
0028   /*! \param hltMode - set true to unpack only BX zero and GCT output data (i.e. to run as quick as possible).
0029    *  \param unpackSharedRegions - this is a commissioning option to unpack the shared RCT calo regions. */
0030   explicit GctFormatTranslateBase(bool hltMode = false, bool unpackSharedRegions = false);
0031 
0032   virtual ~GctFormatTranslateBase();  ///< Destructor.
0033 
0034   /// Set the pointer to the unpack collections
0035   void setUnpackCollections(GctUnpackCollections* const collections) { m_collections = collections; }
0036 
0037   // Set the bunch crossing ID that will be put into the block headers when packing raw data (i.e. Digi -> Raw).
0038   void setPackingBxId(uint32_t bxId) { m_packingBxId = bxId; }
0039 
0040   // Set the event ID that will be put into the block headers when packing raw data (i.e. Digi -> Raw).
0041   void setPackingEventId(uint32_t eventId) { m_packingEventId = eventId; }
0042 
0043   /// Generate a block header from four 8-bit values
0044   virtual GctBlockHeader generateBlockHeader(const unsigned char* data) const = 0;
0045 
0046   /// Get block description
0047   const std::string& getBlockDescription(const GctBlockHeader& header) const;
0048 
0049   /// Get digis from the block - will return true if it succeeds, false otherwise.
0050   virtual bool convertBlock(const unsigned char* d, const GctBlockHeader& hdr) = 0;
0051 
0052 protected:
0053   /* PROTECTED TYPDEFS, ENUMS, AND CLASS CONSTANTS. */
0054 
0055   /// An enum of the EM candidate types.
0056   /*! Note that the order here mimicks the order in the RAW data format. */
0057   enum EmCandCatagory { NON_ISO_EM_CANDS, ISO_EM_CANDS, NUM_EM_CAND_CATEGORIES };
0058 
0059   /// Useful enumeration for jet candidate pack/unpack.
0060   /*! Note that the order here mimicks the order in the RAW data format. */
0061   enum JetCandCategory { TAU_JETS, FORWARD_JETS, CENTRAL_JETS, NUM_JET_CATEGORIES };
0062 
0063   typedef std::map<unsigned int, unsigned int> BlockLengthMap;    ///< Block ID to Block Length map
0064   typedef std::pair<unsigned int, unsigned int> BlockLengthPair;  ///< Block ID/length pair
0065   typedef std::map<unsigned int, std::string> BlockNameMap;       ///< Block ID to Block Description map
0066   typedef std::pair<unsigned int, std::string> BlockNamePair;     ///< Block ID/Description pair
0067 
0068   /// Typedef for mapping block ID to RCT crate.
0069   typedef std::map<unsigned int, unsigned int> BlkToRctCrateMap;
0070 
0071   /*! A typedef that holds the inclusive lower and upper bounds of pipeline
0072    *  gct trigger object pair number for isolated EM candidates.
0073    *  I.e. if the first and second trig object pair in the pipeline payload
0074    *  are isolated cands (4 iso in total), then the IsoBoundaryPair would
0075    *  be (0,1). */
0076   typedef std::pair<unsigned int, unsigned int> IsoBoundaryPair;
0077 
0078   /// A typdef for mapping Block IDs to IsoBoundaryPairs.
0079   typedef std::map<unsigned int, IsoBoundaryPair> BlockIdToEmCandIsoBoundMap;
0080 
0081   /* PROTECTED METHODS */
0082 
0083   /* Static data member access methods */
0084   virtual const BlockLengthMap& blockLengthMap() const = 0;  ///< get the static block ID to block-length map.
0085 
0086   virtual const BlockNameMap& blockNameMap() const = 0;  ///< get the static block ID to blockname map.
0087 
0088   virtual const BlkToRctCrateMap& rctEmCrateMap()
0089       const = 0;  ///< get static the block ID to RCT crate map for electrons.
0090 
0091   virtual const BlkToRctCrateMap& rctJetCrateMap() const = 0;  ///< get the static block ID to RCT crate map for jets
0092 
0093   virtual const BlockIdToEmCandIsoBoundMap& internEmIsoBounds()
0094       const = 0;  ///< get the static intern EM cand isolated boundary map.
0095 
0096   /* Data member access methods */
0097   GctUnpackCollections* const colls() const {
0098     return m_collections;
0099   }                                           ///< Protected access to the GCT Unpack Collections.
0100   bool hltMode() const { return m_hltMode; }  ///< Protected interface to get HLT optimisation mode flag.
0101   bool unpackSharedRegions() const {
0102     return m_unpackSharedRegions;
0103   }  /// Protected interface to the unpackSharedRegions commissioning option.
0104   const SourceCardRouting& srcCardRouting() const {
0105     return m_srcCardRouting;
0106   }                                                                   ///< Protected access to SourceCardRouting.
0107   const uint32_t packingBxId() const { return m_packingBxId; }        ///< Get the BxId to be used when packing data.
0108   const uint32_t packingEventId() const { return m_packingEventId; }  ///< Get the EventId to be used when packing data.
0109 
0110   /* Other general methods */
0111   /// Get a specific jet candandiate collection using the JetCandCategory enumeration.
0112   L1GctJetCandCollection* const gctJets(const unsigned cat) const;
0113 
0114   /// Returns a raw 32-bit header word generated from the blockId, number of time samples, bunch-crossing and event IDs.
0115   virtual uint32_t generateRawHeader(const uint32_t blockId,
0116                                      const uint32_t nSamples,
0117                                      const uint32_t bxId,
0118                                      const uint32_t eventId) const = 0;
0119 
0120   /// Writes a raw block header into the raw data array for a given block ID and number of time-samples.
0121   /*! BxId and EventId values for the raw header are set via the setPackingBxId() and setPackingEventId() methods. */
0122   void writeRawHeader(unsigned char* data, uint32_t blockId, uint32_t nSamples) const;
0123 
0124   /// Performs checks on the block header to see if the block is possible to unpack or not.
0125   bool checkBlock(const GctBlockHeader& hdr) const;
0126 
0127   /// The null unpack function - obviously common to all formats.
0128   void blockDoNothing(const unsigned char* d, const GctBlockHeader& hdr) {}
0129 
0130 private:
0131   /* PRIVATE STATIC CONSTS */
0132   static const std::string INVALID_BLOCK_HEADER_STR;
0133 
0134   /* PRIVATE MEMBER DATA */
0135 
0136   /// Pointer to the output collections object.
0137   GctUnpackCollections* m_collections;
0138 
0139   /// If true, unpack only BX zero and GCT output data (i.e. to run as quickly as possible)
0140   bool m_hltMode;
0141 
0142   /// If true, the shared RCT Calo regions will be unpacked also
0143   /*! This is a commissioning option only - may not be relevant to all concrete implementations! */
0144   bool m_unpackSharedRegions;
0145 
0146   /// Source card mapping info
0147   SourceCardRouting m_srcCardRouting;
0148 
0149   /// The bunch-crossing ID to be used by the data packing methods
0150   uint32_t m_packingBxId;
0151 
0152   /// The event ID to be used by the data packing methods
0153   uint32_t m_packingEventId;
0154 };
0155 
0156 #endif /* GctFormatTranslateBase_h_ */