Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:59:51

0001 /* -*- C++ -*- */
0002 #ifndef HcalDTCHeader_H
0003 #define HcalDTCHeader_H
0004 
0005 #include <iostream>
0006 #include <cstdint>
0007 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
0008 class HcalHTRData;
0009 
0010 /**  \class HcalDTCHeader
0011  *
0012  *  Interpretive class for the header of a FED-format data block
0013  *  from the DTC -- the uTCA DAQ and timing card also called an AMC13
0014  *
0015  *  \author J. Mans - UMD
0016  */
0017 
0018 class HcalDTCHeader {
0019 public:
0020   static const int SLOT_COUNT;
0021   static const int MINIMUM_SLOT;
0022   static const int MAXIMUM_SLOT;
0023 
0024   HcalDTCHeader();
0025 
0026   /** Determine the expected total length of this packet in bytes*/
0027   unsigned int getTotalLengthBytes() const;
0028 
0029   //// The First Common Data Format Slink64 word.
0030   /** get the bit indicating that another CDF header Slink64 word follows the first one.*/
0031   inline bool thereIsASecondCDFHeaderWord() const { return ((commondataformat0 >> 3) & 0x0001); }
0032   /** Get the Format Version of the Common Data Format */
0033   inline short getCDFversionNumber() const { return ((commondataformat0 >> 4) & 0x0F); }
0034   /** get the source id from the CDF header */
0035   inline int getSourceId() const { return (commondataformat0 >> 8) & 0xFFF; }
0036   /** get the bunch id from the CDF header */
0037   inline int getBunchId() const { return (commondataformat0 >> 20) & 0xFFF; }
0038   /** get the Event Number from the CDF header */
0039   inline unsigned long getDTCEventNumber() const { return (commondataformat1 & 0x00FFFFFF); }
0040   /** Get the Event Type value (2007.11.03 - Not defined, but should stay consistent among events.) */
0041   inline unsigned short getCDFEventType() const { return ((commondataformat1 >> 24) & 0x0F); }
0042   /** Get the inviolable '5' in the highest 4 bits of the CDF header.*/
0043   inline unsigned short BOEshouldBe5Always() const { return ((commondataformat1 >> 28) & 0x0F); }
0044 
0045   //// The Second Common Data Format Slink64 word.
0046   /** Check the third bit of second Slink64 CDF word */
0047   inline bool thereIsAThirdCDFHeaderWord() const { return ((commondataformat2 >> 3) & 0x0001); }
0048   /** Get the Orbit Number from the CDF. */
0049   inline unsigned int getOrbitNumber() const { return (((commondataformat3 & 0xF) << 28) + (commondataformat2 >> 4)); }
0050   /** get the (undefined) 'Reserved' part of the second Slink64 CDF word */
0051   inline unsigned int getSlink64ReservedBits() const { return ((commondataformat3 >> 4) & 0x00FFFFFF); }
0052   /** Get the Beginning Of Event bits.  If it's not the first or last CDF Slink64 word, the high 4 bits must be zero.*/
0053   inline short BOEshouldBeZeroAlways() const { return ((commondataformat3 >> 28) & 0x0F); }
0054 
0055   /** Get the Calibration Type*/
0056   inline bool isCalibType() const { return (0 != getCalibType()); }
0057   inline HcalCalibrationEventType getCalibType() const {
0058     return HcalCalibrationEventType((commondataformat3 >> 24) & 0x0000000F);
0059   }
0060 
0061   //// The 64-bit DTC Header
0062   inline short getDTCDataFormatVersion() const { return (dcch0 & 0xFF); }
0063   inline int nSlotWords() const { return ((dcch0 >> 20) & 0x0000000F); }
0064   inline int nDTCWords() const { return ((dcch0 >> 8) & 0x00000FFF); }
0065 
0066   /** Get a given slot summary from the DTC Header **/
0067   inline int getSlotSummary(int nslot) const { return slotInfo[nslot]; }
0068 
0069   /** Load the given decoder with the pointer and length from this slot 
0070       Returns 0 on success
0071       Returns -1 if slot points to data area beyond validSize
0072    */
0073   int getSlotData(int nslot, HcalHTRData& decodeTool, int validSize) const;
0074 
0075   /** Get the size (in 16-bit words) of the data from this slot */
0076   inline unsigned int getSlotDataLength(int nslot) const {
0077     return (nslot < 1 || nslot > 12) ? (0) : (slotInfo[nslot - 1] & 0xfff);
0078   }
0079 
0080   /** \brief Read the "ENABLED" bit for this slot */
0081   inline bool getSlotEnabled(unsigned int nslot) const {
0082     return (nslot < 1 || nslot > 12) ? (false) : (slotInfo[nslot - 1] & 0x8000);
0083   }
0084   /** \brief Read the "PRESENT" bit for this slot */
0085   inline bool getSlotPresent(unsigned int nslot) const {
0086     return (nslot < 1 || nslot > 12) ? (false) : (slotInfo[nslot - 1] & 0x4000);
0087   }
0088   /** \brief Read the "VALID" bit for this slot; TTC EvN matched HTR EvN */
0089   inline bool getSlotValid(unsigned int nslot) const {
0090     return (nslot < 1 || nslot > 12) ? (false) : (slotInfo[nslot - 1] & 0x2000);
0091   }
0092   /** \brief Read the "CRC-Mismatch" bit for this slot */
0093   inline bool getSlotCRCError(unsigned int nslot) const {
0094     return (nslot < 1 || nslot > 12) ? (false) : (slotInfo[nslot - 1] & 0x1000);
0095   }
0096 
0097   /* (for packing only) */
0098   /** \brief Add the given HcalHTRData as the given slot's data.  This should be done in increasing slot order!
0099       \param slot_id 
0100       \param slot_data 
0101       \param valid flag
0102       \param LRB_error_word
0103   */
0104   void copySlotData(unsigned int slot_id, const HcalHTRData& data, bool valid = true);
0105 
0106   /** clear the contents of this header */
0107   void clear();
0108   /** setup the header */
0109   void setHeader(int sourceid, int bcn, int l1aN, int orbN);
0110 
0111 private:
0112   // CURRENTLY VALID FOR LITTLE-ENDIAN (LINUX/x86) ONLY
0113   uint32_t commondataformat0;
0114   uint32_t commondataformat1;
0115   uint32_t commondataformat2;
0116   uint32_t commondataformat3;
0117   uint32_t dcch0;
0118   uint32_t dcch1;
0119   uint16_t slotInfo[12];
0120 };
0121 
0122 std::ostream& operator<<(std::ostream&, const HcalDTCHeader& head);
0123 
0124 #endif