#ifndef ALITRDRAWSTREAM_H
#define ALITRDRAWSTREAM_H
#include "TTree.h"
#include "AliLog.h"
#include "TClonesArray.h"
class TObject;
class TObjArray;
class TString;
class TBranch;
class AliRawReader;
class AliTRDdigitsManager;
class AliTRDdigitsParam;
class AliTRDarrayADC;
class AliTRDSignalIndex;
class AliTRDtrackletContainer;
class AliESDTrdTrack;
class AliTRDrawStream : public TObject
{
public:
AliTRDrawStream(AliRawReader *rawReader = 0x0);
~AliTRDrawStream();
enum { kDDLOffset = 0x400,
kDDLMax = 0x411 };
Bool_t SetReader(AliRawReader *rawReader) { fRawReader = rawReader; return kTRUE; }
void SetDigitsManager(AliTRDdigitsManager *digMgr) { fDigitsManager = digMgr; }
void SetTrackletArray(TClonesArray *ar) { fTracklets = ar; }
void SetTrackArray(TClonesArray *ar) { fTracks = ar; }
void SetMarkerArray(TClonesArray *ar) { fMarkers = ar; }
TClonesArray* GetTrackletArray() const { return fTracklets; }
TClonesArray* GetTrackArray() const { return fTracks; }
TClonesArray* GetMarkerArray() const { return fMarkers; }
AliTRDdigitsManager* GetDigitsManager() const { return fDigitsManager; }
Bool_t ReadEvent();
Bool_t NextDDL();
Int_t NextChamber(AliTRDdigitsManager *digMgr);
Int_t NextChamber(AliTRDdigitsManager *digMgr,
UInt_t ** , UShort_t ** ) { AliError("Deprecated, use NextChamber(AliTRDdigitsManger*) instead!"); return NextChamber(digMgr); }
void StoreErrorsInTree() { fStoreError = &AliTRDrawStream::StoreErrorTree; }
void StoreErrorsInArray() { fStoreError = &AliTRDrawStream::StoreErrorArray; }
void EnableErrorStorage() { fStoreError = &AliTRDrawStream::StoreErrorTree; }
void DisableErrorStorage() { fStoreError = &AliTRDrawStream::ForgetError; }
enum ErrorCode_t {
kUnknown = 0,
kLinkMonitor,
kEvCntMismatch,
kNonTrdEq,
kStackHeaderInvalid,
kInvalidDetector,
kInvalidPadRow,
kNoDigits,
kHCmismatch,
kHCcheckFailed,
kPosUnexp,
kTPmodeInvalid,
kTPmismatch,
kNtimebinsChanged,
kAdcMaskInconsistent,
kAdcCheckInvalid,
kAdcDataAbort,
kAdcChannelsMiss,
kMissMcmHeaders,
kMissTpData,
kCRCmismatch,
kLastErrorCode
};
enum ErrorBehav_t {
kTolerate = 0,
kDiscardMCM = 1,
kDiscardHC = 2,
kDiscardDDL = 4,
kAbort = 8
};
enum MarkerCode_t {
kHCactive = 1,
kSecactive = 2
};
TTree* GetErrorTree() const { return fErrors; }
static const char* GetErrorMessage(ErrorCode_t errCode);
static void SetErrorDebugLevel(ErrorCode_t error, Int_t level) { fgErrorDebugLevel[error] = level; }
static void SetErrorBehaviour(ErrorCode_t error, ErrorBehav_t behav) { fgErrorBehav[error] = behav; }
class AliTRDrawStreamError : public TObject {
public:
AliTRDrawStreamError(Int_t error = 0, Int_t sector = -1, Int_t stack = -1, Int_t link = -1, Int_t rob = -1, Int_t mcm = -1);
virtual ~AliTRDrawStreamError() {}
Int_t fError;
Int_t fSector;
Int_t fStack;
Int_t fLink;
Int_t fRob;
Int_t fMcm;
ClassDef(AliTRDrawStreamError, 1);
};
class AliTRDrawStats : public TObject {
public:
AliTRDrawStats() : TObject(), fBytesRead(0) {}
void ClearStats();
class AliTRDrawStatsSector : public TObject {
public:
AliTRDrawStatsSector() : TObject(), fBytes(0), fBytesRead(0), fNTracklets(0), fNMCMs(0), fNChannels(0) {}
void ClearStats();
class AliTRDrawStatsHC : public TObject {
public:
AliTRDrawStatsHC() : TObject(), fBytes(0), fBytesRead(0), fNTracklets(0), fNMCMs(0), fNChannels(0) {}
void ClearStats();
Int_t fBytes;
Int_t fBytesRead;
Int_t fNTracklets;
Int_t fNMCMs;
Int_t fNChannels;
ClassDef(AliTRDrawStatsHC, 1);
};
Int_t fBytes;
Int_t fBytesRead;
Int_t fNTracklets;
Int_t fNMCMs;
Int_t fNChannels;
AliTRDrawStatsHC fStatsHC[60];
ClassDef(AliTRDrawStatsSector, 1);
};
AliTRDrawStatsSector fStatsSector[18];
Int_t fBytesRead;
ClassDef(AliTRDrawStats, 1);
};
AliTRDrawStats* GetStats() { return &fStats; }
Int_t GetEventSize(Int_t sector) const { return fStats.fStatsSector[sector].fBytes; }
Int_t GetEventSize(Int_t sector, Int_t stack) const {
Int_t size = 0;
for (Int_t iHC = 0; iHC < 12; iHC++) {
size += fStats.fStatsSector[sector].fStatsHC[12*stack + iHC].fBytes;
}
return size;
}
Int_t GetEventSize(Int_t sector, Int_t stack, Int_t hc) const {
return fStats.fStatsSector[sector].fStatsHC[12*stack + hc].fBytes;
}
Int_t GetNTracklets(Int_t sector) const { return fStats.fStatsSector[sector].fNTracklets; }
Int_t GetNMCMs(Int_t sector) const { return fStats.fStatsSector[sector].fNMCMs; }
Int_t GetNChannels(Int_t sector) const { return fStats.fStatsSector[sector].fNChannels; }
ULong64_t GetTrkFlags(Int_t sector, Int_t stack) const { return (fCurrTrgFlags[sector] & (1 << (27 + stack))) ? fCurrTrkFlags[sector*fgkNstacks + stack] : 0; }
UInt_t GetTriggerFlags(Int_t sector) const { return fCurrTrgFlags[sector]; }
UInt_t GetLinkMonitorFlags(Int_t sector, Int_t stack) const {
UInt_t temp = 0;
for (Int_t iLink = 0; iLink < 12; iLink++)
temp |= (fCurrLinkMonitorFlags[(sector * fgkNstacks + stack) * fgkNlinks + iLink] & 0x3) << (iLink * 2);
temp |= ((GetMatchFlagsBP(sector) >> stack) & 0x1) << 24;
temp |= ((GetMatchFlagsSRAM(sector) >> stack) & 0x1) << 25;
return temp;
}
UInt_t GetMatchFlagsSRAM(Int_t sector) const { return fCurrMatchFlagsSRAM[sector]; }
UInt_t GetMatchFlagsBP(Int_t sector) const { return fCurrMatchFlagsPostBP[sector]; }
#ifdef TRD_RAW_DEBUG
UInt_t GetBC(Int_t hc) const { return fCurrBC[hc]; }
UInt_t GetEvCount(Int_t det) const { return fCurrEvCount[det]; }
UInt_t GetL0Count(Int_t sector) const { return fCurrL0Count[sector]; }
UInt_t GetL1aCount(Int_t sector) const { return fCurrL1aCount[sector]; }
UInt_t GetL1rCount(Int_t sector) const { return fCurrL1rCount[sector]; }
UInt_t GetL2aCount(Int_t sector) const { return fCurrL2aCount[sector]; }
UInt_t GetL2rCount(Int_t sector) const { return fCurrL2rCount[sector]; }
UInt_t GetChecksumStack(Int_t sector, Int_t stack) const { return fCurrChecksumStack[sector][stack]; }
#endif
void SetDumpMCM(Int_t det, Int_t rob, Int_t mcm, Bool_t dump = kTRUE);
Bool_t IsDumping() const { return (fNDumpMCMs > 0); }
Bool_t DumpingMCM(Int_t det, Int_t rob, Int_t mcm) const;
TString DumpRaw(TString title, const UInt_t *start, Int_t length, UInt_t endmarker = 0xffffffff);
TString DumpMcmHeader(TString title, UInt_t word);
TString DumpAdcMask(TString title, UInt_t word);
static void SortTracklets(TClonesArray *trklArray, TList &sortedTracklets, Int_t *indices);
static void AssignTracklets(AliESDTrdTrack *trdTrack, Int_t *trackletIndex, Int_t refIndex[6]);
static void SetMCMReadoutPos(Int_t mcm, Int_t pos) { if (mcm > -1 && mcm < 16) fgMcmOrder[mcm] = pos; }
static void SetROBReadoutPos(Int_t robpair, Int_t pos) { if (robpair > -1 && robpair < 4) fgMcmOrder[robpair] = pos; }
protected:
Int_t ReadGTUHeaders(UInt_t *buffer);
Int_t ReadSmHeader();
Int_t ReadTrackingHeader(Int_t stack);
Int_t ReadTriggerHeaders();
Int_t ReadStackHeader(Int_t stack);
Int_t DecodeGTUtracks();
Int_t ReadGTUTrailer();
Int_t ReadLinkData();
Int_t ReadTracklets();
Int_t ReadHcHeader();
Int_t ReadTPData(Int_t mode = 1);
Int_t ReadZSData();
Int_t ReadNonZSData();
UShort_t CalcLinkChecksum(UInt_t *data, Int_t size);
Int_t SeekNextStack();
Int_t SeekNextLink();
Int_t ROB(UInt_t mcmhdr) const { return 0x7 & mcmhdr >> 28; }
Int_t MCM(UInt_t mcmhdr) const { return 0xf & mcmhdr >> 24; }
Int_t Row(UInt_t mcmhdr) const { return (ROB(mcmhdr) / 2) * 4 + MCM(mcmhdr) / 4; }
Int_t AdcColOffset(UInt_t mcmhdr) const { return (MCM(mcmhdr) % 4 + 1) * 21 + (ROB(mcmhdr) % 2) * 84 - 1; }
Int_t PadColOffset(UInt_t mcmhdr) const { return (MCM(mcmhdr) % 4 + 1) * 18 + (ROB(mcmhdr) % 2) * 72 + 1; }
Int_t EvNo(UInt_t mcmhdr) const { return 0xfffff & mcmhdr >> 4; }
Int_t Check(UInt_t mcmhdr) const { return 0xf & mcmhdr; }
Int_t CouldBeMCMhdr(UInt_t mcmhdr) const { return ((0xf & mcmhdr) == 0xc); }
Int_t GetMCMReadoutPos(Int_t mcm) const { return (mcm > -1 && mcm < 16) ? fgMcmOrder[mcm] : -1; }
Int_t GetROBReadoutPos(Int_t rob) const { return (rob > -1 && rob < 4) ? fgRobOrder[rob] : -1; }
Int_t GetActiveChannels(UInt_t adcmask) const { return 0x1fffff & adcmask >> 4; }
inline Int_t GetNActiveChannelsFromMask(UInt_t adcmask) const;
Int_t GetNActiveChannels(UInt_t adcmask) const { return (0x1f & ~(adcmask >> 25)); }
Int_t CouldBeADCmask(UInt_t adcmask) const { return ((0xf & adcmask) == 0xc && (0x3 & adcmask >> 30) == 0x1); }
void EquipmentError(ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
void StackError (ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
void LinkError (ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
void ROBError (ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
void MCMError (ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
void StoreErrorTree() { fErrors->Fill(); }
void StoreErrorArray() { new ((*fMarkers)[fMarkers->GetEntriesFast()]) AliTRDrawStreamError(fLastError); }
void ForgetError() { return; }
void (AliTRDrawStream::*fStoreError)();
static const char* fgkErrorMessages[kLastErrorCode];
static Int_t fgErrorDebugLevel[kLastErrorCode];
static ErrorBehav_t fgErrorBehav[kLastErrorCode];
AliRawReader *fRawReader;
AliTRDdigitsManager *fDigitsManager;
AliTRDdigitsParam *fDigitsParam;
TTree *fErrors;
AliTRDrawStreamError fLastError;
UInt_t fErrorFlags;
char fErrorBuffer[100];
AliTRDrawStats fStats;
UInt_t *fPayloadStart;
UInt_t *fPayloadCurr;
Int_t fPayloadSize;
static const Int_t fgkNlinks;
static const Int_t fgkNsectors;
static const Int_t fgkNstacks;
static const Int_t fgkNtriggers;
static const UInt_t fgkDataEndmarker;
static const UInt_t fgkTrackletEndmarker;
static const UInt_t fgkStackEndmarker[];
static Int_t fgMcmOrder [];
static Int_t fgRobOrder [];
Int_t fNtimebins;
Int_t fLastEvId;
Int_t fCurrSlot;
Int_t fCurrLink;
Int_t fCurrRobPos;
Int_t fCurrMcmPos;
UInt_t fCurrEquipmentId;
UInt_t fCurrSmHeaderSize;
UInt_t fCurrSmHeaderVersion;
UInt_t fCurrTrailerReadout;
UInt_t fCurrTrgHeaderAvail;
UInt_t fCurrTrgHeaderReadout;
UInt_t fCurrTrkHeaderAvail;
UInt_t fCurrStackEndmarkerAvail;
UInt_t fCurrEvType;
UInt_t fCurrTriggerEnable;
UInt_t fCurrTriggerFired;
UInt_t fCurrTrackEnable;
UInt_t fCurrTrackletEnable;
UInt_t fCurrStackMask;
#ifdef TRD_RAW_DEBUG
UInt_t *fCurrL0Count;
UInt_t *fCurrL1aCount;
UInt_t *fCurrL1rCount;
UInt_t *fCurrL2aCount;
UInt_t *fCurrL2rCount;
Int_t fCurrL0offset[540];
UInt_t fCurrEvCount[540];
#endif
UInt_t *fCurrTrkHeaderIndexWord;
UInt_t *fCurrTrkHeaderSize;
ULong64_t *fCurrTrkFlags;
UInt_t *fCurrTrgHeaderIndexWord;
UInt_t *fCurrTrgHeaderSize;
UInt_t *fCurrTrgFlags;
UInt_t *fCurrStackIndexWord;
UInt_t *fCurrStackHeaderSize;
UInt_t *fCurrStackHeaderVersion;
UInt_t *fCurrLinkMask;
UInt_t *fCurrCleanCheckout;
UInt_t *fCurrBoardId;
UInt_t fCurrHwRev;
UInt_t *fCurrHwRevTMU;
UInt_t *fCurrLinkMonitorFlags;
UInt_t *fCurrLinkDataTypeFlags;
UInt_t *fCurrLinkDebugFlags;
Char_t fCurrMatchFlagsSRAM[18];
Char_t fCurrMatchFlagsPostBP[18];
UInt_t fCurrChecksumStack[18][5];
UInt_t fCurrChecksumSIU;
Int_t fCurrSpecial;
Int_t fCurrMajor;
Int_t fCurrMinor;
Int_t fCurrAddHcWords;
Int_t fCurrSm;
Int_t fCurrStack;
Int_t fCurrLayer;
Int_t fCurrSide;
Int_t fCurrHC;
Int_t fCurrCheck;
Int_t fCurrNtimebins;
Int_t fCurrPtrgCnt;
Int_t fCurrPtrgPhase;
#ifdef TRD_RAW_DEBUG
Int_t fCurrBC[1080];
#endif
Int_t fDumpMCM[100];
Int_t fNDumpMCMs;
AliTRDarrayADC *fAdcArray;
AliTRDSignalIndex *fSignalIndex;
TClonesArray *fTracklets;
TClonesArray *fTracks;
TClonesArray *fMarkers;
AliTRDrawStream(const AliTRDrawStream&);
AliTRDrawStream& operator=(const AliTRDrawStream&);
ClassDef(AliTRDrawStream, 0);
};
Int_t AliTRDrawStream::GetNActiveChannelsFromMask(UInt_t adcmask) const
{
adcmask = GetActiveChannels(adcmask);
adcmask = adcmask - ((adcmask >> 1) & 0x55555555);
adcmask = (adcmask & 0x33333333) + ((adcmask >> 2) & 0x33333333);
return (((adcmask + (adcmask >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
}
#endif