#ifndef HTRBCTDCMESSAGE_H #define HTRBCTDCMESSAGE_H #include "Rtypes.h" #include #include /** TdcMessage is wrapper for data, produced by FPGA- ClockTDC * struct is used to avoid any potential overhead * JAM 04-Sep-2024: adjust trb3 tdc message to new clockTDC data format (v0 for mdc, v1 for the future)*/ //All time information is encoded in units of 0.4 ns. #define CLOCKTDC_TIMEUNIT_S 4.0E-10 //the maximum value of 13 bit timestamps, for overflow corrections // Overflow happens after 3276.8 ns =(8192 * 0.4) ns #define CLOCKTDC_MAXVALUE_S (3276.8 * 1e-9) //signal suppression limit in ns to handle timestamp overflow #define CLOCKTDC_LIMIT_S (500.0 * 1e-9) // JAM 11-feb-25: same overflow limits as in stream framework #define CLOCKTDC_OVERFLOW_LOW (-2100.0 * 1e-9) #define CLOCKTDC_OVERFLOW_HI (700.0 * 1e-9) struct HTrbCtdcMessage { protected: UInt_t fData; UChar_t fVersion; //! current data format version in use public: HTrbCtdcMessage() : fData(0),fVersion(0) {} HTrbCtdcMessage(UInt_t d) : fData(d),fVersion(0) {} void assign(UInt_t d) { fData=d; if(isHeaderMsg()) fVersion= getFormatVersion(); } ////////// check message kinds: Bool_t isHeaderMsg() const { return (((fData >> 24) & 0xFF) == 0xDC); } Bool_t isCalibMsg() const { return (((fData >> 24) & 0xFF) == 0xE0); } Bool_t isHitMsg() const { if(fVersion==1) return (((fData >> 31) & 0x1) == 0); else return (!isHeaderMsg() && !isCalibMsg()); // Hits in v0 have no specific marker; everything expect header or calibration msg is a hit } //////////////////////////////////// methods for hit /** Returns hit channel ID from current message */ UInt_t getHitChannelRaw() const { if(fVersion==1) return (fData >> 27) & 0xF; else return (fData >> 27) & 0x1F; } /** Returns hit leading edge time counter, 13 bit */ UInt_t getHitTmLeading() const { return (fData >> 13) & 0x1FFF; } /** Returns hit trailing edge time counter, 13 bit */ UInt_t getHitTmTrailing() const { return fData & 0x1FFF; } /** Check error flag*/ Bool_t isHitError() const { return (((fData >> 26) & 0x1) == 0x1); } //////////////// methods for header /** Return data format version from header */ UChar_t getFormatVersion() const { return (fData >> 16) & 0xF;} /** Return data format version from header */ UShort_t getReferenceTime() const { return (fData & 0x1FFF);} /** Return channel group from header */ UShort_t getChannelGroup() const { return (fVersion==1 ? ((fData>>20) & 0xF) : 0); } ///////////////// optional calibration messages from event builders TODO: /** Return first value in calibration message */ UInt_t getCalibFirst() const { return (fData & 0x3fff); } /** Return second value in calibration message */ UInt_t getCalibSecond() const { return ((fData >> 14) & 0x3fff);} void printDataword(); static Double_t coarseUnit() { return CLOCKTDC_TIMEUNIT_S; } // ClassDef(HTrbCtdcMessage, 0) }; #endif