Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /* -*- C++ -*- */
0002 #ifndef CastorCTDCHeader_H
0003 #define CastorCTDCHeader_H
0004 
0005 #include <iostream>
0006 class CastorCORData;
0007 class CastorMergerData;
0008 
0009 /**  \class CastorCTDCHeader
0010  *
0011  *  Interpretive class for an CastorCTDCHeader
0012  *   
0013  *
0014  *  \author A. Campbell - DESY
0015  */
0016 
0017 class CastorCTDCHeader {
0018 public:
0019   static const int SPIGOT_COUNT;
0020 
0021   CastorCTDCHeader();
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 (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   //// The 64-bit DCC Header
0053   inline short getDCCDataFormatVersion() const { return (ctdch0 & 0xFF); }
0054   inline int getAcceptTimeTTS() const { return ((ctdch0 >> 8) & 0x0000000F); }
0055   inline int getByte1Zeroes() const { return ((ctdch0 >> 12) & 0x00000003); }
0056   inline int getHTRStatusBits() const { return ((ctdch0 >> 14) & 0x00007FFF); }
0057   inline int getByte3Zeroes() const { return ((ctdch0 >> 29) & 0x00000007); }
0058   inline int getDCCStatus() const { return (ctdch1 & 0x000003FF); }
0059   inline int getByte567Zeroes() const { return (ctdch1 & 0xFF00FC00); }
0060 
0061   /** Get the value flagging a spigot's summary of error flags. */
0062   inline bool getSpigotErrorFlag(int nspigot) const { return ((ctdch0 >> (14 + nspigot)) & 0x0001); }
0063 
0064   /** Get the status of these error counters in the DCC motherboard. **/
0065   inline bool SawTTS_OFW() const { return ((getDCCStatus() >> 0) & 0x00000001); }
0066   inline bool SawTTS_BSY() const { return ((getDCCStatus() >> 1) & 0x00000001); }
0067   inline bool SawTTS_SYN() const { return ((getDCCStatus() >> 2) & 0x00000001); }
0068   inline bool SawL1A_EvN_MxMx() const { return ((getDCCStatus() >> 3) & 0x00000001); }
0069   inline bool SawL1A_BcN_MxMx() const { return ((getDCCStatus() >> 4) & 0x00000001); }
0070   inline bool SawCT_EvN_MxMx() const { return ((getDCCStatus() >> 5) & 0x00000001); }
0071   inline bool SawCT_BcN_MxMx() const { return ((getDCCStatus() >> 6) & 0x00000001); }
0072   inline bool SawOrbitLengthErr() const { return ((getDCCStatus() >> 7) & 0x00000001); }
0073   inline bool SawTTC_SingErr() const { return ((getDCCStatus() >> 8) & 0x00000001); }
0074   inline bool SawTTC_DoubErr() const { return ((getDCCStatus() >> 9) & 0x00000001); }
0075 
0076   /** Get a given spigot summary from the DCC Header **/
0077   inline int getSpigotSummary(int nspigot) const { return spigotInfo[nspigot]; }
0078 
0079   /** Load the given decoder with the pointer and length from this spigot 
0080       Returns 0 on success
0081       Returns -1 if spigot points to data area beyond validSize
0082    */
0083   int getSpigotData(int nspigot, CastorCORData& decodeTool, int validSize) const;
0084 
0085   /** Get the size (in 32-bit words) of the data from this spigot */
0086   inline unsigned int getSpigotDataLength(int nspigot) const {
0087     return (nspigot >= 3) ? (0) : (spigotInfo[nspigot] & 0x3ff);
0088   }
0089 
0090   /** \brief Read the "ENABLED" bit for this spigot */
0091   inline bool getSpigotEnabled(unsigned int nspigot) const {
0092     return (nspigot >= 3) ? (false) : (spigotInfo[nspigot] & 0x8000);
0093   }
0094   /** \brief Read the "PRESENT" bit for this spigot */
0095   inline bool getSpigotPresent(unsigned int nspigot) const {
0096     return (nspigot >= 3) ? (false) : (spigotInfo[nspigot] & 0x4000);
0097   }
0098   /** \brief Read the "BxID FAILS TO MATCH WITH DCC" bit for this spigot */
0099   inline bool getBxMismatchWithDCC(unsigned int nspigot) const {
0100     return (nspigot >= 3) ? (false) : (spigotInfo[nspigot] & 0x2000);
0101   }
0102   /** \brief Read the "VALID" bit for this spigot; TTC EvN matched HTR EvN */
0103   inline bool getSpigotValid(unsigned int nspigot) const {
0104     return (nspigot >= 3) ? (false) : (spigotInfo[nspigot] & 0x1000);
0105   }
0106   /** \brief Read the "TRUNCATED" bit for this spigot; LRB truncated data (took too long) */
0107   inline bool getSpigotDataTruncated(unsigned int nspigot) const {
0108     return (nspigot >= 3) ? (false) : (spigotInfo[nspigot] & 0x0800);
0109   }
0110   /** \brief Read the "CRC-Mismatch" bit for this spigot */
0111   inline bool getSpigotCRCError(unsigned int nspigot) const {
0112     return (nspigot >= 3) ? (false) : (spigotInfo[nspigot] & 0x0400);
0113   }
0114   /** \brief Access the HTR error bits (decoding tbd) */
0115   inline unsigned char getSpigotErrorBits(unsigned int nspigot) const {
0116     return (nspigot >= 3) ? (0) : ((unsigned char)(spigotInfo[nspigot] >> 24));
0117   }
0118   /** \brief Access the Link Receiver Board error bits (decoding tbd) */
0119   inline unsigned char getLRBErrorBits(unsigned int nspigot) const {
0120     return (nspigot >= 3) ? (0) : ((unsigned char)(spigotInfo[nspigot] >> 16));
0121   }
0122 
0123   /* (for packing only) */
0124   /** \brief Add the given CastorCORData as the given spigot's data.  This should be done in increasing spigot order!
0125       \param spigot_id 
0126       \param spigot_data 
0127       \param valid flag
0128       \param LRB_error_word
0129   */
0130   void copySpigotData(unsigned int spigot_id,
0131                       const CastorCORData& data,
0132                       bool valid = true,
0133                       unsigned char LRB_error_word = 0);
0134 
0135   void copyMergerData(const CastorMergerData& data, bool valid);
0136 
0137   /** clear the contents of this header */
0138   void clear();
0139   /** setup the header */
0140   void setHeader(int sourceid, int bcn, int l1aN, int orbN);
0141 
0142 private:
0143   // CURRENTLY VALID FOR LITTLE-ENDIAN (LINUX/x86) ONLY
0144   unsigned int commondataformat0;
0145   unsigned int commondataformat1;
0146   unsigned int commondataformat2;
0147   unsigned int commondataformat3;
0148   unsigned int ctdch0;
0149   unsigned int ctdch1;
0150   unsigned int spigotInfo[4];  //The last of these 32bit words should be "end header pattern"
0151 };
0152 
0153 std::ostream& operator<<(std::ostream&, const CastorCTDCHeader& head);
0154 
0155 #endif