Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:15:02

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