#ifndef HTRBCTDCITERATOR_H #define HTRBCTDCITERATOR_H #include "htrbctdcmessage.h" /** JAM 4-september-2024: adjust exisiting trb3 iterator for new clock tdc */ class HTrbCtdcIterator { protected: enum { DummyReftime = 0xffff }; UInt_t *fBuf; //! pointer on raw data UInt_t fBuflen; //! length of raw data Bool_t fSwapped; //! true if raw data are swapped HTrbCtdcMessage fMsg; //! current message UChar_t fCurVersion; //! current data format version found in stream UShort_t fCurReftime; //! most recent reference time stamp from header UChar_t fCurChannelGroup; //! most recent channel group from header (version 1 only!) public: HTrbCtdcIterator() : fBuf(0), fBuflen(0), fSwapped(false), fMsg(), fCurVersion(0), fCurReftime( DummyReftime), fCurChannelGroup(0) { } void assign(UInt_t *buf, UInt_t len, Bool_t swapped = true) { fBuf = buf; fBuflen = len; fSwapped = swapped; fMsg.assign(0); if (fBuflen == 0) fBuf = 0; fCurReftime = DummyReftime; fCurVersion = 0; fCurChannelGroup = 0; } Bool_t next() { if (fBuf == 0) return kFALSE; if (fSwapped) fMsg.assign( (((UChar_t*) fBuf)[0] << 24) | (((UChar_t*) fBuf)[1] << 16) | (((UChar_t*) fBuf)[2] << 8) | (((UChar_t*) fBuf)[3])); else fMsg.assign(*fBuf); //if (fMsg.isEpochMsg()) fCurEpoch = fMsg.getEpochValue(); if (fMsg.isHeaderMsg()) { fCurVersion = fMsg.getFormatVersion(); fCurReftime = fMsg.getReferenceTime(); fCurChannelGroup = fMsg.getChannelGroup(); } fBuf++; if (--fBuflen == 0) fBuf = 0; return kTRUE; } HTrbCtdcMessage& msg() { return fMsg; } /** return raw value of hit message leading edge time stamp*/ inline UShort_t getMsgStampLeading() const { return (fMsg.isHitMsg() ? fMsg.getHitTmLeading() : 0); } /** return raw value of hit message trailng edge time stamp*/ inline UShort_t getMsgStampTrailing() const { return (fMsg.isHitMsg() ? fMsg.getHitTmTrailing() : 0); } inline Int_t getHitChannel() const { if (!fMsg.isHitMsg()) return -1; return (getCurrentChannelGroup() * 16 + fMsg.getHitChannelRaw()); // channel group is always 0 for format version 0 } /** return value of hit message leading edge time in seconds*/ inline Double_t getMsgTimeLeading() const { return getMsgStampLeading() * HTrbCtdcMessage::coarseUnit(); } /** return value of hit message trailing edge time in seconds*/ inline Double_t getMsgTimeTrailing() const { return getMsgStampTrailing() * HTrbCtdcMessage::coarseUnit(); } /** return value of current reference time in seconds*/ inline Double_t getReferenceTime() const { return getCurrentReferenceStamp() * HTrbCtdcMessage::coarseUnit(); } inline Double_t getMsgToT() const { return (getMsgStampLeading() - getMsgStampTrailing()) * HTrbCtdcMessage::coarseUnit(); } inline UShort_t getCurrentReferenceStamp() const { return fCurReftime; } inline UChar_t getCurrentChannelGroup() const { return fCurChannelGroup; } inline UChar_t getCurrentVersion() const { return fCurVersion; } void printmsg() { if (fMsg.isHeaderMsg()) { printf("Clock tdc header:\n"); fMsg.printDataword(); printf( "Format version %d, Channel group: %d: reference tm%9.2f s \n", fMsg.getFormatVersion(), (fMsg.getFormatVersion() == 1 ? fMsg.getChannelGroup() : -1), getReferenceTime()); } else if (fMsg.isHitMsg()) { printf(" Clock tdc hit"); fMsg.printDataword(); printf( " ch %3u leading tm:%9.2f s trailing tm:%9.2f s -> Tot: %E s", (UInt_t) getHitChannel(), getMsgTimeLeading(), getMsgTimeTrailing(), getMsgToT()); if (fMsg.isHitError()) printf(" -ERROR FLAG set!!\n"); else printf("\n"); } else { printf(" tdc unknown data word:\n"); fMsg.printDataword(); } } // ClassDef(HTrbCtdcIterator,0); }; #endif