Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /* -*- C++ -*- */
0002 #ifndef HcalDCCHeader_H
0003 #define HcalDCCHeader_H
0004 
0005 #include <iostream>
0006 #include <cstdint>
0007 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
0008 class HcalHTRData;
0009 
0010 /**  \class HcalDCCHeader
0011  *
0012  *  Interpretive class for an HcalDCCHeader
0013  *   
0014  *
0015  *  \author J. Mans - UMD
0016  */
0017 
0018 class HcalDCCHeader {
0019 public:
0020   static const int SPIGOT_COUNT;
0021 
0022   HcalDCCHeader();
0023 
0024   /** Determine the expected total length of this packet in bytes*/
0025   unsigned int getTotalLengthBytes() const;
0026 
0027   //// The First Common Data Format Slink64 word.
0028   /** get the bit indicating that another CDF header Slink64 word follows the first one.*/
0029   inline bool thereIsASecondCDFHeaderWord() const { return ((commondataformat0 >> 3) & 0x0001); }
0030   /** Get the Format Version of the Common Data Format */
0031   inline short getCDFversionNumber() const { return ((commondataformat0 >> 4) & 0x0F); }
0032   /** get the source id from the CDF header */
0033   inline int getSourceId() const { return (commondataformat0 >> 8) & 0xFFF; }
0034   /** get the bunch id from the CDF header */
0035   inline int getBunchId() const { return (commondataformat0 >> 20) & 0xFFF; }
0036   /** get the Event Number from the CDF header */
0037   inline unsigned long getDCCEventNumber() const { return (commondataformat1 & 0x00FFFFFF); }
0038   /** Get the Event Type value (2007.11.03 - Not defined, but should stay consistent among events.) */
0039   inline unsigned short getCDFEventType() const { return ((commondataformat1 >> 24) & 0x0F); }
0040   /** Get the inviolable '5' in the highest 4 bits of the CDF header.*/
0041   inline unsigned short BOEshouldBe5Always() const { return ((commondataformat1 >> 28) & 0x0F); }
0042 
0043   //// The Second Common Data Format Slink64 word.
0044   /** Check the third bit of second Slink64 CDF word */
0045   inline bool thereIsAThirdCDFHeaderWord() const { return ((commondataformat2 >> 3) & 0x0001); }
0046   /** Get the Orbit Number from the CDF. */
0047   inline unsigned int getOrbitNumber() const { return (((commondataformat3 & 0xF) << 28) + (commondataformat2 >> 4)); }
0048   /** get the (undefined) 'Reserved' part of the second Slink64 CDF word */
0049   inline unsigned int getSlink64ReservedBits() const { return ((commondataformat3 >> 4) & 0x00FFFFFF); }
0050   /** Get the Beginning Of Event bits.  If it's not the first or last CDF Slink64 word, the high 4 bits must be zero.*/
0051   inline short BOEshouldBeZeroAlways() const { return ((commondataformat3 >> 28) & 0x0F); }
0052 
0053   /** Get the Calibration Type*/
0054   inline bool isCalibType() const { return (0 != getCalibType()); }
0055   inline HcalCalibrationEventType getCalibType() const {
0056     return HcalCalibrationEventType((commondataformat3 >> 24) & 0x0000000F);
0057   }
0058 
0059   //// The 64-bit DCC Header
0060   inline short getDCCDataFormatVersion() const { return (dcch0 & 0xFF); }
0061   inline int getAcceptTimeTTS() const { return ((dcch0 >> 8) & 0x0000000F); }
0062   inline int getByte1Zeroes() const { return ((dcch0 >> 12) & 0x00000003); }
0063   inline int getHTRStatusBits() const { return ((dcch0 >> 14) & 0x00007FFF); }
0064   inline int getByte3Zeroes() const { return ((dcch0 >> 29) & 0x00000007); }
0065   inline int getDCCStatus() const { return (dcch1 & 0x000003FF); }
0066   inline int getByte567Zeroes() const { return (dcch1 & 0xFF00FC00); }
0067 
0068   /** Get the value flagging a spigot's summary of error flags. */
0069   inline bool getSpigotErrorFlag(int nspigot) const { return ((dcch0 >> (14 + nspigot)) & 0x0001); }
0070 
0071   /** Get the status of these error counters in the DCC motherboard. **/
0072   inline bool SawTTS_OFW() const { return ((getDCCStatus() >> 0) & 0x00000001); }
0073   inline bool SawTTS_BSY() const { return ((getDCCStatus() >> 1) & 0x00000001); }
0074   inline bool SawTTS_SYN() const { return ((getDCCStatus() >> 2) & 0x00000001); }
0075   inline bool SawL1A_EvN_MxMx() const { return ((getDCCStatus() >> 3) & 0x00000001); }
0076   inline bool SawL1A_BcN_MxMx() const { return ((getDCCStatus() >> 4) & 0x00000001); }
0077   inline bool SawCT_EvN_MxMx() const { return ((getDCCStatus() >> 5) & 0x00000001); }
0078   inline bool SawCT_BcN_MxMx() const { return ((getDCCStatus() >> 6) & 0x00000001); }
0079   inline bool SawOrbitLengthErr() const { return ((getDCCStatus() >> 7) & 0x00000001); }
0080   inline bool SawTTC_SingErr() const { return ((getDCCStatus() >> 8) & 0x00000001); }
0081   inline bool SawTTC_DoubErr() const { return ((getDCCStatus() >> 9) & 0x00000001); }
0082 
0083   /** Get a given spigot summary from the DCC Header **/
0084   inline int getSpigotSummary(int nspigot) const { return spigotInfo[nspigot]; }
0085 
0086   /** Load the given decoder with the pointer and length from this spigot 
0087       Returns 0 on success
0088       Returns -1 if spigot points to data area beyond validSize
0089    */
0090   int getSpigotData(int nspigot, HcalHTRData& decodeTool, int validSize) const;
0091 
0092   /** Old (unsafe) getSpigotData.  All calls should be replaced by the new call.
0093       This call will generate WARN log messages.
0094    */
0095   void getSpigotData(int nspigot, HcalHTRData& decodeTool) const;
0096 
0097   /** Get the size (in 32-bit words) of the data from this spigot */
0098   inline unsigned int getSpigotDataLength(int nspigot) const {
0099     return (nspigot >= 15) ? (0) : (spigotInfo[nspigot] & 0x3ff);
0100   }
0101 
0102   /** \brief Read the "ENABLED" bit for this spigot */
0103   inline bool getSpigotEnabled(unsigned int nspigot) const {
0104     return (nspigot >= 15) ? (false) : (spigotInfo[nspigot] & 0x8000);
0105   }
0106   /** \brief Read the "PRESENT" bit for this spigot */
0107   inline bool getSpigotPresent(unsigned int nspigot) const {
0108     return (nspigot >= 15) ? (false) : (spigotInfo[nspigot] & 0x4000);
0109   }
0110   /** \brief Read the "BxID FAILS TO MATCH WITH DCC" bit for this spigot */
0111   inline bool getBxMismatchWithDCC(unsigned int nspigot) const {
0112     return (nspigot >= 15) ? (false) : (spigotInfo[nspigot] & 0x2000);
0113   }
0114   /** \brief Read the "VALID" bit for this spigot; TTC EvN matched HTR EvN */
0115   inline bool getSpigotValid(unsigned int nspigot) const {
0116     return (nspigot >= 15) ? (false) : (spigotInfo[nspigot] & 0x1000);
0117   }
0118   /** \brief Read the "TRUNCATED" bit for this spigot; LRB truncated data (took too long) */
0119   inline bool getSpigotDataTruncated(unsigned int nspigot) const {
0120     return (nspigot >= 15) ? (false) : (spigotInfo[nspigot] & 0x0800);
0121   }
0122   /** \brief Read the "CRC-Mismatch" bit for this spigot */
0123   inline bool getSpigotCRCError(unsigned int nspigot) const {
0124     return (nspigot >= 15) ? (false) : (spigotInfo[nspigot] & 0x0400);
0125   }
0126   /** \brief Access the HTR error bits (decoding tbd) */
0127   inline unsigned char getSpigotErrorBits(unsigned int nspigot) const {
0128     return (nspigot >= 15) ? (0) : ((unsigned char)(spigotInfo[nspigot] >> 24));
0129   }
0130   /** \brief Access the Link Receiver Board error bits (decoding tbd) */
0131   inline unsigned char getLRBErrorBits(unsigned int nspigot) const {
0132     return (nspigot >= 15) ? (0) : ((unsigned char)(spigotInfo[nspigot] >> 16));
0133   }
0134 
0135   /* (for packing only) */
0136   /** \brief Add the given HcalHTRData as the given spigot's data.  This should be done in increasing spigot order!
0137       \param spigot_id 
0138       \param spigot_data 
0139       \param valid flag
0140       \param LRB_error_word
0141   */
0142   void copySpigotData(unsigned int spigot_id,
0143                       const HcalHTRData& data,
0144                       bool valid = true,
0145                       unsigned char LRB_error_word = 0);
0146 
0147   /** clear the contents of this header */
0148   void clear();
0149   /** setup the header */
0150   void setHeader(int sourceid, int bcn, int l1aN, int orbN);
0151 
0152 private:
0153   // CURRENTLY VALID FOR LITTLE-ENDIAN (LINUX/x86) ONLY
0154   uint32_t commondataformat0;
0155   uint32_t commondataformat1;
0156   uint32_t commondataformat2;
0157   uint32_t commondataformat3;
0158   uint32_t dcch0;
0159   uint32_t dcch1;
0160   uint32_t spigotInfo[18];  //The last three of these 32bit words should always be zero!
0161 };
0162 
0163 std::ostream& operator<<(std::ostream&, const HcalDCCHeader& head);
0164 
0165 #endif