/**************************************************************************
-* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
-* *
-* Author: The ALICE Off-line Project. *
-* Contributors are mentioned in the code where appropriate. *
-* *
-* Permission to use, copy, modify and distribute this software and its *
-* documentation strictly for non-commercial purposes is hereby granted *
-* without fee, provided that the above copyright notice appears in all *
-* copies and that both the copyright notice and this permission notice *
-* appear in the supporting documentation. The authors make no claims *
-* about the suitability of this software for any purpose. It is *
-* provided "as is" without express or implied warranty. *
-**************************************************************************/
-
-/* $Id: AliTRDrawStream.cxx 27797 2008-08-05 14:37:22Z cblume $ */
-
-///////////////////////////////////////////////////////////////////////////////
-// //
-// This class provides access to TRD digits in raw data. //
-// //
-// It loops over all TRD digits in the raw data given by the AliRawReader. //
-// The Next method goes to the next digit. If there are no digits left //
-// it returns kFALSE. //
-// Several getters provide information about the current digit. //
-// //
-// Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) //
-// Author: MinJung Kweon (minjung@physi.uni-heidelberg.de) //
-// //
-///////////////////////////////////////////////////////////////////////////////
-
-#include "TString.h"
-#include "TFile.h"
-//#include "TTreeStream.h"
-
-#include "AliTRDrawStream.h"
-#include "AliTRDgeometry.h"
-#include "AliTRDfeeParam.h"
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * *
+ * Author: The ALICE Off-line Project. *
+ * Contributors are mentioned in the code where appropriate. *
+ * *
+ * Permission to use, copy, modify and distribute this software and its *
+ * documentation strictly for non-commercial purposes is hereby granted *
+ * without fee, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission notice *
+ * appear in the supporting documentation. The authors make no claims *
+ * about the suitability of this software for any purpose. It is *
+ * provided "as is" without express or implied warranty. *
+ **************************************************************************/
+
+////////////////////////////////////////////////////////////////////////////
+// //
+// Decoding data from the TRD raw stream //
+// and translation into ADC values, on-line tracklets and tracks //
+// //
+// CRC checks rely on boost, and are enabled only when TRD_RAW_CRC //
+// is defined //
+// //
+// Additional debug features can be enabled by defining TRD_RAW_DEBUG //
+// //
+// Author: J. Klein (jochen.klein@cern.ch) //
+// //
+////////////////////////////////////////////////////////////////////////////
+
+#include <cstdio>
+#include <cstdarg>
+
+#if defined(TRD_RAW_CRC)
+#include <boost/crc.hpp>
+#endif
+
+#include "TClonesArray.h"
+#include "TTree.h"
+
+#include "AliLog.h"
+#include "AliRawReader.h"
+#include "AliTRDcalibDB.h"
#include "AliTRDdigitsManager.h"
-#include "AliTRDarrayDictionary.h"
+#include "AliTRDdigitsParam.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDmcmSim.h"
+#include "AliTRDtrapConfig.h"
#include "AliTRDarrayADC.h"
+#include "AliTRDarrayDictionary.h"
#include "AliTRDSignalIndex.h"
-#include "AliTRDdigitsParam.h"
-#include "AliTRDrawTPStream.h"
+#include "AliTRDtrackletWord.h"
+#include "AliTRDtrackletMCM.h"
+#include "AliESDTrdTrack.h"
-//#include "AliLog.h"
-#include "AliRawReader.h"
+#include "AliTRDrawStream.h"
-#define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa
-#define END_OF_TRACKLET_MARKERNEW 0x10001000
-#define ENDOFRAWDATAMARKER 0x00000000
-#define WORD_SIZE sizeof(UInt_t) // size of a word in bytes
-#define EXTRA_LEAD_WORDS 24
-#define CDH_WORDS 8
-
-#define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w
-#define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m
-
-// SM index word masks:
-#define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
-#define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)
-#define STACK_MASK(w) ((w) & 0x1f)
-
-// Stack word masks
-#define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)
-#define STACK_LINK_WORD(w) ((w) & 0xfff)
-#define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1) // 0 if physics data
-#define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data
-#define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1) // 0 if OK
-#define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1) // 0 if OK
-
-// HC word masks
-#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK
-
-// HC word 0
-#define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)
-#define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)
-#define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)
-#define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)
-#define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)
-#define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)
-#define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)
-#define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)
-#define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)
-#define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)
-
-// HC word 1
-#define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)
-#define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)
-#define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)
-#define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,2)
-
-// MCM word and ADC mask
-#define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK
-#define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK
-#define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)
-#define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)
-#define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)
-#define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)
-#define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)
-
-#define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated
-#define ADCDATA_VAL1 0x2 // updated
-#define ADCDATA_VAL2 0x3 // updated
-
-#define ADC_WORD_MASK(w) ((w) & 0x3)
-
-//--------------------------------------------------------
ClassImp(AliTRDrawStream)
-Bool_t AliTRDrawStream::fgExtraSkip = kFALSE;
-Bool_t AliTRDrawStream::fgSkipCDH = kFALSE;
-Bool_t AliTRDrawStream::fgWarnError = kTRUE;
-Bool_t AliTRDrawStream::fgCleanDataOnly = kFALSE;
-Bool_t AliTRDrawStream::fgDebugFlag = kTRUE;
-Bool_t AliTRDrawStream::fgEnableMemoryReset = kTRUE;
-Bool_t AliTRDrawStream::fgStackNumberChecker = kTRUE;
-Bool_t AliTRDrawStream::fgStackLinkNumberChecker = kFALSE;
-Bool_t AliTRDrawStream::fgSkipData = kTRUE;
-Bool_t AliTRDrawStream::fgEnableDecodeConfigData = kFALSE;
-Int_t AliTRDrawStream::fgDumpHead = -1;
-Int_t AliTRDrawStream::fgEmptySignals[] =
- {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
- };
-Short_t AliTRDrawStream::fgMCMordering[] =
- {
- 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3
- };
-Short_t AliTRDrawStream::fgROBordering[] =
- {
- 0, 1, 2, 3
- };
-Int_t AliTRDrawStream::fgLastHC = -1;
-Int_t AliTRDrawStream::fgLastROB = -1;
-Int_t AliTRDrawStream::fgLastIndex = -1;
-Int_t AliTRDrawStream::fgDumpingSM = -1;
-Int_t AliTRDrawStream::fgDumpingStack = -1;
-Int_t AliTRDrawStream::fgDumpingLayer = -1;
-Int_t AliTRDrawStream::fgDumpingROB = -1;
-Int_t AliTRDrawStream::fgDumpingMCM = -1;
-Bool_t AliTRDrawStream::fgDumpingEnable = kFALSE;
-
-
-AliTRDrawStream::AliTRDrawStream()
- : AliTRDrawStreamBase()
- , fSM()
- , fStack(0)
- , fHC(0)
- , fLastHC(0)
- , fMCM(0)
- , fADC(0)
- , fpPos(0)
- , fpBegin(0)
- , fpEnd(0)
- , fWordLength(0)
- , fIsGlobalDigitsParamSet(kFALSE)
- , fStackNumber(-1)
- , fStackLinkNumber(-1)
- , fhcMCMcounter(0)
- , fmcmADCcounter(0)
- , fLinkTrackletCounter(-1)
- , fEndOfTrackletCount(-1)
- , fNWordsCounter(-1)
- , fMaskADCword(0)
- , fTbinADC(0)
- , fDecodedADCs(-1)
- , fEventCounter(0)
- , fLastEventCounter(0)
- , fSharedPadsOn(kTRUE)
- , fMaxADCgeom(0)
- , fBufferRead(0)
- , fGeometry(0)
- , fRawReader(0)
- , fTRDfeeParam(0)
+// some static information
+Int_t AliTRDrawStream::fgMcmOrder[] = {12, 13, 14, 15,
+ 8, 9, 10, 11,
+ 4, 5, 6, 7,
+ 0, 1, 2, 3};
+Int_t AliTRDrawStream::fgRobOrder [] = {0, 1, 2, 3};
+const Int_t AliTRDrawStream::fgkNlinks = 12;
+const Int_t AliTRDrawStream::fgkNstacks = 5;
+const Int_t AliTRDrawStream::fgkNsectors = 18;
+const Int_t AliTRDrawStream::fgkNtriggers = 12;
+const UInt_t AliTRDrawStream::fgkDataEndmarker = 0x00000000;
+const UInt_t AliTRDrawStream::fgkTrackletEndmarker = 0x10001000;
+const UInt_t AliTRDrawStream::fgkStackEndmarker[] = { 0xe0d01000, 0xe0d10000 };
+
+const char* AliTRDrawStream::fgkErrorMessages[] = {
+ "Unknown error",
+ "Link monitor active",
+ "Event counter mismatch",
+ "not a TRD equipment (1024-1041)",
+ "Invalid Stack header",
+ "Invalid detector number",
+ "Invalid pad row",
+ "No digits could be retrieved from the digitsmanager",
+ "HC header mismatch",
+ "HC check bits wrong",
+ "Unexpected position in readout stream",
+ "Invalid testpattern mode",
+ "Testpattern mismatch",
+ "Number of timebins changed",
+ "ADC mask inconsistent",
+ "ADC check bits invalid",
+ "Missing ADC data",
+ "Missing expected ADC channels",
+ "Missing MCM headers",
+ "Missing TP data",
+ "CRC mismatch"
+};
+
+Int_t AliTRDrawStream::fgErrorDebugLevel[] = {
+ 0,
+ 0,
+ 2,
+ 1,
+ 0,
+ 1,
+ 0,
+ 1,
+ 0,
+ 1,
+ 2,
+ 1,
+ 0,
+ 1,
+ 1,
+ 2,
+ 1,
+ 1,
+ 1,
+ 0,
+ 0
+};
+
+AliTRDrawStream::ErrorBehav_t AliTRDrawStream::fgErrorBehav[] = {
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kDiscardHC,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kAbort,
+ AliTRDrawStream::kAbort,
+ AliTRDrawStream::kAbort,
+ AliTRDrawStream::kDiscardMCM,
+ AliTRDrawStream::kAbort,
+ AliTRDrawStream::kDiscardHC,
+ AliTRDrawStream::kDiscardHC,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate,
+ AliTRDrawStream::kTolerate
+};
+
+AliTRDrawStream::AliTRDrawStream(AliRawReader *rawReader) :
+ fStoreError(&AliTRDrawStream::ForgetError),
+ fRawReader(rawReader),
+ fDigitsManager(0x0),
+ fDigitsParam(0x0),
+ fErrors(0x0),
+ fLastError(),
+ fErrorFlags(0),
+ fStats(),
+ fPayloadStart(0x0),
+ fPayloadCurr(0x0),
+ fPayloadSize(0),
+ fNtimebins(-1),
+ fLastEvId(-1),
+ fCurrSlot(-1),
+ fCurrLink(-1),
+ fCurrRobPos(-1),
+ fCurrMcmPos(-1),
+ fCurrEquipmentId(0),
+ fCurrSmHeaderSize(0),
+ fCurrSmHeaderVersion(0),
+ fCurrTrailerReadout(0),
+ fCurrTrgHeaderAvail(0),
+ fCurrTrgHeaderReadout(0),
+ fCurrTrkHeaderAvail(0),
+ fCurrStackEndmarkerAvail(0),
+ fCurrEvType(0),
+ fCurrTriggerEnable(0),
+ fCurrTriggerFired(0),
+ fCurrTrackEnable(0),
+ fCurrTrackletEnable(0),
+ fCurrStackMask(0),
+#ifdef TRD_RAW_DEBUG
+ fCurrL0Count(),
+ fCurrL1aCount(),
+ fCurrL1rCount(),
+ fCurrL2aCount(),
+ fCurrL2rCount(),
+ fCurrL0offset(),
+#endif
+ fCurrTrkHeaderIndexWord(0x0),
+ fCurrTrkHeaderSize(0x0),
+ fCurrTrkFlags(0x0),
+ fCurrTrgHeaderIndexWord(0x0),
+ fCurrTrgHeaderSize(0x0),
+ fCurrTrgFlags(0x0),
+ fCurrStackIndexWord(0x0),
+ fCurrStackHeaderSize(0x0),
+ fCurrStackHeaderVersion(0x0),
+ fCurrLinkMask(0x0),
+ fCurrCleanCheckout(0x0),
+ fCurrBoardId(0x0),
+ fCurrHwRev(-1),
+ fCurrHwRevTMU(0x0),
+ fCurrLinkMonitorFlags(0x0),
+ fCurrLinkDataTypeFlags(0x0),
+ fCurrLinkDebugFlags(0x0),
+ fCurrMatchFlagsSRAM(),
+ fCurrMatchFlagsPostBP(),
+ fCurrChecksumStack(),
+ fCurrChecksumSIU(0),
+ fCurrSpecial(-1),
+ fCurrMajor(-1),
+ fCurrMinor(-1),
+ fCurrAddHcWords(-1),
+ fCurrSm(-1),
+ fCurrStack(-1),
+ fCurrLayer(-1),
+ fCurrSide(-1),
+ fCurrHC(-1),
+ fCurrCheck(-1),
+ fCurrNtimebins(-1),
+ fCurrPtrgCnt(-1),
+ fCurrPtrgPhase(-1),
+#ifdef TRD_RAW_DEBUG
+ fCurrBC(),
+#endif
+ fNDumpMCMs(0),
+ fAdcArray(0x0),
+ fSignalIndex(0x0),
+ fTracklets(0x0),
+ fTracks(0x0),
+ fMarkers(0x0)
{
- //
// default constructor
- //
- if (Init() == kFALSE) {
- AliWarning("Unable to Init.");
- }
-}
-//--------------------------------------------------------
-AliTRDrawStream::AliTRDrawStream(AliRawReader *rawReader)
- : AliTRDrawStreamBase(rawReader)
- , fSM()
- , fStack(0)
- , fHC(0)
- , fLastHC(0)
- , fMCM(0)
- , fADC(0)
- , fpPos(0)
- , fpBegin(0)
- , fpEnd(0)
- , fWordLength(0)
- , fIsGlobalDigitsParamSet(kFALSE)
- , fStackNumber(-1)
- , fStackLinkNumber(-1)
- , fhcMCMcounter(0)
- , fmcmADCcounter(0)
- , fLinkTrackletCounter(-1)
- , fEndOfTrackletCount(-1)
- , fNWordsCounter(-1)
- , fMaskADCword(0)
- , fTbinADC(0)
- , fDecodedADCs(-1)
- , fEventCounter(0)
- , fLastEventCounter(0)
- , fSharedPadsOn(kTRUE)
- , fMaxADCgeom(0)
- , fBufferRead(0)
- , fGeometry(0)
- , fRawReader(rawReader)
- , fTRDfeeParam(0)
-{
- //
- // default constructor
- //
- if (fRawReader) {
- if (Init() == kFALSE) {
- AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");
- }
- }
- else {
- AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");
+ fCurrTrkHeaderIndexWord = new UInt_t[fgkNstacks];
+ fCurrTrkHeaderSize = new UInt_t[fgkNstacks];
+ fCurrTrkFlags = new ULong64_t[fgkNsectors*fgkNstacks];
+ fCurrTrgHeaderIndexWord = new UInt_t[fgkNtriggers];
+ fCurrTrgHeaderSize = new UInt_t[fgkNtriggers];
+ fCurrTrgFlags = new UInt_t[fgkNsectors];
+#ifdef TRD_RAW_DEBUG
+ fCurrL0Count = new UInt_t[fgkNsectors];
+ fCurrL1aCount = new UInt_t[fgkNsectors];
+ fCurrL1rCount = new UInt_t[fgkNsectors];
+ fCurrL2aCount = new UInt_t[fgkNsectors];
+ fCurrL2rCount = new UInt_t[fgkNsectors];
+#endif
+ fCurrStackIndexWord = new UInt_t[fgkNstacks];
+ fCurrStackHeaderSize = new UInt_t[fgkNstacks];
+ fCurrStackHeaderVersion = new UInt_t[fgkNstacks];
+ fCurrLinkMask = new UInt_t[fgkNstacks];
+ fCurrCleanCheckout = new UInt_t[fgkNstacks];
+ fCurrBoardId = new UInt_t[fgkNstacks];
+ fCurrHwRevTMU = new UInt_t[fgkNstacks];
+ fCurrLinkMonitorFlags = new UInt_t[fgkNsectors * fgkNstacks * fgkNlinks];
+ fCurrLinkDataTypeFlags = new UInt_t[fgkNstacks * fgkNlinks];
+ fCurrLinkDebugFlags = new UInt_t[fgkNstacks * fgkNlinks];
+ for (Int_t iSector = 0; iSector < fgkNsectors; iSector++)
+ fCurrTrgFlags[iSector] = 0;
+ for (Int_t i = 0; i < 100; i++)
+ fDumpMCM[i] = 0;
+
+ // setting up the error tree
+ fErrors = new TTree("errorStats", "Error statistics");
+ fErrors->SetDirectory(0x0);
+ fErrors->Branch("error", &fLastError);
+ fErrors->SetCircular(1000);
+ for (Int_t i = 0; i < 100; i++) {
+ fErrorBuffer[i] = 0;
}
-}
-
-//------------------------------------------------------------
-
-AliTRDrawStream::AliTRDrawStream(const AliTRDrawStream& /*st*/)
- : AliTRDrawStreamBase()
- , fSM()
- , fStack(0)
- , fHC(0)
- , fLastHC(0)
- , fMCM(0)
- , fADC(0)
- , fpPos(0)
- , fpBegin(0)
- , fpEnd(0)
- , fWordLength(0)
- , fIsGlobalDigitsParamSet(kFALSE)
- , fStackNumber(-1)
- , fStackLinkNumber(-1)
- , fhcMCMcounter(0)
- , fmcmADCcounter(0)
- , fLinkTrackletCounter(-1)
- , fEndOfTrackletCount(-1)
- , fNWordsCounter(-1)
- , fMaskADCword(0)
- , fTbinADC(0)
- , fDecodedADCs(-1)
- , fEventCounter(0)
- , fLastEventCounter(0)
- , fSharedPadsOn(kTRUE)
- , fMaxADCgeom(0)
- , fBufferRead(0)
- , fGeometry(0)
- , fRawReader(0)
- , fTRDfeeParam(0)
-{
- //
- // Copy constructor
- //
- AliError("Not implemeneted.");
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SetRawVersion(Int_t fraw)
-{
- //
- // function provided for backward compatibility
- //
- AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");
- fraw = 0; // avoid warnings
- return kFALSE;
}
-//------------------------------------------------------------
AliTRDrawStream::~AliTRDrawStream()
{
- //
// destructor
- //
- delete fGeometry;
-}
-
-//------------------------------------------------------------
-AliTRDrawStream & AliTRDrawStream::operator=(const AliTRDrawStream &)
-{
- //
- // we are not using this functionality
- //
- AliFatal("May not use.");
- return *this;
+ delete fErrors;
+
+ delete [] fCurrTrkHeaderIndexWord;
+ delete [] fCurrTrkHeaderSize;
+ delete [] fCurrTrkFlags;
+ delete [] fCurrTrgHeaderIndexWord;
+ delete [] fCurrTrgHeaderSize;
+ delete [] fCurrTrgFlags;
+ delete [] fCurrStackIndexWord;
+ delete [] fCurrStackHeaderSize;
+ delete [] fCurrStackHeaderVersion;
+ delete [] fCurrLinkMask;
+ delete [] fCurrCleanCheckout;
+ delete [] fCurrBoardId;
+ delete [] fCurrHwRevTMU;
+ delete [] fCurrLinkMonitorFlags;
+ delete [] fCurrLinkDataTypeFlags;
+ delete [] fCurrLinkDebugFlags;
}
-//___________________________________________________________
-void AliTRDrawStream::SwapOnEndian()
+Bool_t AliTRDrawStream::ReadEvent()
{
- //
- // Check the endian and swap if needed
- //
- int itemp = 1;
- char* ptemp = (char*) &itemp;
- if (ptemp[0] != 1) {
- if (fgDebugFlag) AliDebug(8, "Swapping.");
-
- fpPos = fpBegin;
- UInt_t iutmp = 0;
- while (fpPos < fpEnd) {
- fpPos += 1;
- iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |
- ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));
- // here we override the value in the buffer!
- *fpPos = iutmp;
- }
- fpPos = fpBegin;
- }
-}
+ // read the current event from the raw reader and fill it to the digits manager
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)
-{
- //
- // dump given number of words for debugging
- //
- TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);
- for (UInt_t i = 0; i < iw; i++) {
- if ( iw != 0 && px + iw > fpEnd) return kFALSE;
-
- if (i % 8 == 0) tsreturn += "\n ";
- if (marker != 0 && marker == px[i]) tsreturn += Form(" *>0x%08x<* ", px[i]);
- else tsreturn += Form("0x%08x ", px[i]);
+ if (!fRawReader) {
+ AliError("No raw reader available");
+ return kFALSE;
}
- tsreturn += "\n";
- AliInfo(tsreturn.Data());
+ // some preparations
+ fDigitsParam = 0x0;
- return kTRUE;
-}
+ // loop over all DDLs
+ // data starts with GTU payload, i.e. SM index word
+ UChar_t *buffer = 0x0;
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SkipWords(UInt_t iw)
-{
- //
- // Skip words corresponding to iw
- //
- if ( fpPos + iw < fpEnd ) {
- fpPos += iw;
- return kTRUE;
- }
- else {
- if (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
- return kFALSE;
- }
+ while (fRawReader->ReadNextData(buffer)) {
- return kTRUE;
-}
+ fCurrEquipmentId = fRawReader->GetEquipmentId();
+ AliDebug(2, Form("equipment: %i", fCurrEquipmentId));
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SetReader(AliRawReader * reader)
-{
- //
- // Set reader pointer
- //
- if (reader != 0) {
- fRawReader = reader;
- if (fRawReader) {
- return Init();
+ if (fCurrEquipmentId < kDDLOffset || fCurrEquipmentId > kDDLMax) {
+ EquipmentError(kNonTrdEq, "Skipping");
+ continue;
}
- else {
- AliWarning("Unable to setup reader.");
- return kFALSE;
- }
- }
- else {
- AliWarning("AliRawReader argument is 0.");
- fRawReader = 0;
- }
- return kFALSE;
-}
+ if (fMarkers)
+ new ((*fMarkers)[fMarkers->GetEntriesFast()])
+ AliTRDrawStreamError(-kSecactive, fCurrEquipmentId - kDDLOffset);
-//------------------------------------------------------------
-Int_t AliTRDrawStream::NextBuffer()
-{
- //
- // return -1 if no more buffers available
- // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come
- // return 1 DecodeSM OK
- //
- if (fRawReader != 0) {
- UChar_t *buffer = 0;
- UInt_t length = 0;
- Bool_t kBufferSet = fRawReader->ReadNextData(buffer);
- if (kBufferSet == kTRUE) {
- if (fgDebugFlag) AliDebug(9, "Buffer is set.");
- length = fRawReader->GetDataSize();
- if (fgExtraSkip == kTRUE) {
- buffer += EXTRA_LEAD_WORDS * WORD_SIZE;
- length -= EXTRA_LEAD_WORDS * WORD_SIZE;
- }
+ ReadGTUHeaders((UInt_t*) buffer);
- if (fgSkipCDH == kTRUE) {
- buffer += CDH_WORDS * WORD_SIZE;
- length -= CDH_WORDS * WORD_SIZE;
- }
+ if (fCurrTrailerReadout)
+ ReadGTUTrailer();
- if (length > 0) {
- if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
- if (fgEnableMemoryReset) ResetMemory(); //[mj]
- if (DecodeSM((void*)buffer, length) == kTRUE)
- return 1;
- else
- return 0;
- }
+#ifdef TRD_RAW_CRC
+ boost::crc_optimal<16, 0x8005, 0, 0, false, false> checksumStack[5];
+ boost::crc_optimal<32, 0x04C11DB7, 0, 0, false, false> checksumSIU;
+ checksumSIU.reset();
+
+ // process CDH, replace size with 0xffffffff
+ UInt_t temp = 0xffffffff;
+ checksumSIU.process_bytes(&temp, sizeof(UInt_t));
+ UInt_t *data = (UInt_t*) fRawReader->GetDataHeader();
+ checksumSIU.process_bytes(&data[1], 7*sizeof(UInt_t));
+ // process payload including everything but the SIU checksum
+ checksumSIU.process_bytes(buffer, fRawReader->GetDataSize()-4);
+
+ if (checksumSIU() != fCurrChecksumSIU) {
+ EquipmentError(kCRCmismatch, "SIU data - recalc: 0x%08x - 0x%08x", fCurrChecksumSIU, checksumSIU());
}
- else {
- return -1;
+#endif
+
+ // loop over all active links
+ AliDebug(2, Form("Stack mask 0x%02x", fCurrStackMask));
+ for (Int_t iStack = 0; iStack < fgkNstacks; iStack++) {
+ fCurrSlot = iStack;
+#ifdef TRD_RAW_CRC
+ checksumStack[iStack].reset();
+#endif
+
+ if ((fCurrStackMask & (1 << fCurrSlot)) == 0)
+ continue;
+
+ AliDebug(2, Form("Stack %i, Link mask: 0x%02x", fCurrSlot, fCurrLinkMask[fCurrSlot]));
+ for (Int_t iLink = 0; iLink < fgkNlinks; iLink++) {
+ fCurrLink = iLink;
+ fCurrHC = (fCurrEquipmentId - kDDLOffset) * fgkNstacks * fgkNlinks +
+ fCurrSlot * fgkNlinks + iLink;
+ if ((fCurrLinkMask[fCurrSlot] & (1 << fCurrLink)) == 0)
+ continue;
+
+#ifdef TRD_RAW_CRC
+ UInt_t *start = fPayloadCurr;
+#endif
+ Int_t size = 0;
+
+ fErrorFlags = 0;
+ // check for link monitor error flag
+ if (fCurrLinkMonitorFlags[(((fCurrEquipmentId - kDDLOffset) * fgkNstacks) + fCurrSlot) * fgkNlinks + fCurrLink] != 0) {
+ LinkError(kLinkMonitor);
+ if (fgErrorBehav[kLinkMonitor] == kTolerate)
+ size += ReadLinkData();
+ }
+ else
+ // read the data from one HC
+ size += ReadLinkData();
+
+ // read all data endmarkers
+ size += SeekNextLink();
+
+#ifdef TRD_RAW_CRC
+ // always use data for CRC calculation
+ // (even if link monitor active)
+ UShort_t crc = CalcLinkChecksum(start, size);
+ checksumStack[iStack].process_bytes(&crc, sizeof(UShort_t));
+#endif
+ }
+#ifdef TRD_RAW_CRC
+ if (fDigitsManager && (checksumStack[iStack]() != fCurrChecksumStack[fCurrEquipmentId - kDDLOffset][iStack])) {
+ StackError(kCRCmismatch, "data - recalc: 0x%04x - 0x%04x", fCurrChecksumStack[fCurrEquipmentId - kDDLOffset][iStack], checksumStack[iStack]());
+ }
+#endif
+
+ // continue with next stack
+ SeekNextStack();
}
}
- return -1;
+ return kTRUE;
}
-//------------------------------------------------------------
-void AliTRDrawStream::ResetCounters()
+
+Bool_t AliTRDrawStream::NextDDL()
{
- //
- // reset some global counters
- //
- fBufferRead = kFALSE; // read buffer if it is false (important to read buffer)
+ // continue reading with the next equipment
- fStackNumber = 0;
- fStackLinkNumber = 0;
- fDecodedADCs = 0;
+ if (!fRawReader)
+ return kFALSE;
- fSM.fActiveStacks = 0;
- fSM.fNexpectedHalfChambers = 0;
+ fCurrEquipmentId = 0;
+ fCurrSlot = 0;
+ fCurrLink = 0;
- fLinkTrackletCounter = 0;
- fLastEventCounter = 0;
- fEventCounter = 0;
-}
+ UChar_t *buffer = 0x0;
-//------------------------------------------------------------
-void AliTRDrawStream::ResetIterators()
-{
- //
- // reset data which should be reset every sm
- //
- fStackNumber = 0; // reset for Next() function
- fStackLinkNumber = 0; // reset for Next() function
- fhcMCMcounter = 0;
- fmcmADCcounter = 0;
-}
+ while (fRawReader->ReadNextData(buffer)) {
-//------------------------------------------------------------
-void AliTRDrawStream::ResetPerSM()
-{
- //
- // reset every SM
- //
- fSM.fHeaderSize = 0;
- fSM.fTrackletEnable = kFALSE;
- fSM.fCorrupted = 0;
- fSM.fNexpectedHalfChambers = 0;
- fSM.fNexpectedHalfChambers = 0;
- fSM.fClean = kTRUE;
- fSM.fPos = NULL;
- for (Int_t i=0; i<5; i++){
- fSM.fStackActive[i] = kFALSE;
- }
-}
+ fCurrEquipmentId = fRawReader->GetEquipmentId();
+ AliDebug(2, Form("equipment: %i", fCurrEquipmentId));
-//------------------------------------------------------------
-void AliTRDrawStream::ResetPerStack()
-{
- //
- // reset every Stack
- //
- fStack->fHeaderSize = 0;
- fStack->fActiveLinks = 0;
- fStack->fPos = NULL;
- for (Int_t i=0; i<12; i++){
- fStack->fLinksActive[i] = kFALSE;
- fStack->fLinksDataType[i] = 0;
- fStack->fLinksMonitor[i] = 0;
- fStack->fLinkMonitorError[i] = 0;
+ if (fCurrEquipmentId < kDDLOffset || fCurrEquipmentId > kDDLMax) {
+ EquipmentError(kNonTrdEq, "Skipping");
+ continue;
+ }
+
+ if (fMarkers)
+ new ((*fMarkers)[fMarkers->GetEntriesFast()])
+ AliTRDrawStreamError(-kSecactive, fCurrEquipmentId - kDDLOffset);
+
+ ReadGTUHeaders((UInt_t*) buffer);
+
+ if (fCurrTrailerReadout)
+ ReadGTUTrailer();
+
+ return kTRUE;
}
-}
-//------------------------------------------------------------
-void AliTRDrawStream::ResetPerHC()
-{
- //
- // reset every HC
- //
- fEventCounter = 0;
- fHC->fTrackletError = 0;
- fHC->fNTracklets = 0;
- fHC->fSpecialRawV = 0;
- fHC->fRawVMajor = 0;
- fHC->fRawVMajorOpt = 0;
- fHC->fRawVMinor = 0;
- fHC->fNExtraWords = 0;
- fHC->fDCSboard = 0;
- fHC->fSM = 0;
- fHC->fStack = 0;
- fHC->fLayer = 0;
- fHC->fSide = 0;
- fHC->fTimeBins = 0;
- fHC->fBunchCrossCounter = 0;
- fHC->fPreTriggerCounter = 0;
- fHC->fPreTriggerPhase = 0;
- fHC->fDET = 0;
- fHC->fROC = 0;
- fHC->fRowMax = 0;
- fHC->fColMax = 0;
- fHC->fMCMmax = 0;
- fHC->fH0Corrupted = 0;
- fHC->fH1Corrupted = 0;
- fHC->fCorrupted = 0;
+ return kFALSE;
}
-//------------------------------------------------------------
-void AliTRDrawStream::ResetPerMCM()
-{
- //
- // reset every MCM
- //
- fMCM->fROB = 0;
- fMCM->fMCM = 0;
- fMCM->fROW = 0;
- fMCM->fEvCounter = 0;
- fMCM->fADCMask = 0;
- fMCM->fADCMaskWord = 0;
- fMCM->fADCmax = 0;
- fMCM->fADCcount = 0;
- fMCM->fMCMADCWords = 0;
- fMCM->fSingleADCwords = 0;
- fMCM->fMCMhdCorrupted = 0;
- fMCM->fADCmaskCorrupted = 0;
- fMCM->fCorrupted = 0;
- fMCM->fPos = NULL;
- fMCM->fAdcDataPos = NULL;
- fMCM->fADCcounter = 0;
-
- memset(fMCM->fADCchannel, 0, TRDMAXADC*sizeof(UInt_t));
-}
-//------------------------------------------------------------
-void AliTRDrawStream::ResetPerADC()
+Int_t AliTRDrawStream::NextChamber(AliTRDdigitsManager *digMgr)
{
- //
- // reset every ADC
- //
- fADC->fPos = NULL;
- fADC->fADCnumber = 0;
- fADC->fExtendedCOL = 0;
- fADC->fCOL = 0;
- fADC->fIsShared = kTRUE;
- fADC->fCorrupted = 0;
-
- //memset(fADC->fSignals, 0, GetNumberOfTimeBins()*sizeof(Int_t));
- memset(fADC->fSignals, 0, TRDMAXTBINS*sizeof(Int_t));
-}
+ // read the data for the next chamber
+ // in case you only want to read the data of a single chamber
+ // to read all data ReadEvent(...) is recommended
-//------------------------------------------------------------
-void AliTRDrawStream::ResetMemory()
-{
- //
- // initialize all the data members to prevent read data from memory for previous buffer
- //
- ResetPerSM();
- for (Int_t istack=0; istack<5; istack++){
- fStack = &fSM.fStacks[istack];
- ResetPerStack();
- for (Int_t ilink=0; ilink<12; ilink++){
- fHC = &fStack->fHalfChambers[ilink];
- ResetPerHC();
- for (Int_t imcm=0; imcm<TRDMAXMCM; imcm++){
- fMCM = &fHC->fMCMs[imcm];
- ResetPerMCM();
- for (Int_t iadc=0; iadc<TRDMAXADC; iadc++){
- fADC = &fMCM->fADCs[iadc];
- ResetPerADC();
- } // iadc
- } // imcm
- } // ilink
- } // istack
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::Next()
-{
- //
- // returns with true on next adc read
- // returns false on errors and end of buffer
- //
- if (fBufferRead) {
- while (fStackNumber < 5 && fSM.fActiveStacks > 0) {
- if (fSM.fStackActive[fStackNumber] == kTRUE) {
- fStack = &fSM.fStacks[fStackNumber];
- while (fStackLinkNumber < 12) {
- if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0) {
- fHC = &fStack->fHalfChambers[fStackLinkNumber];
- if (!fHC) {
- AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
- return kFALSE;
- }
- if (fHC->fCorrupted == 0 && (fHC->fH0Corrupted == 0 && fHC->fH1Corrupted == 0) | !fgSkipData) { // if HC data corrupted(in any case), we don't read data at all from this HC
- while (fhcMCMcounter < fHC->fMCMmax) {
- fMCM = &fHC->fMCMs[fhcMCMcounter];
- if (!fMCM) {
- AliError(Form("HC missing at stack %d link %d atMCMslot %d",
- fStackNumber, fStackLinkNumber, fhcMCMcounter));
- return kFALSE;
- }
- while(fmcmADCcounter < fMCM->fADCmax) {
- fADC = &fMCM->fADCs[fmcmADCcounter];
- if (!fADC) {
- AliError(Form("ADC missing at stack %d link %d MCMslot %d ADCslot %d",
- fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));
- return kFALSE;
- }
- fmcmADCcounter++;
- if (fSharedPadsOn) {
- return kTRUE;
- }
- else {
- if (fADC->fIsShared == kFALSE)
- return kTRUE;
- }
- } // while fmcmADCcounter
- fhcMCMcounter++;
- fmcmADCcounter = 0; // next MCM should go through all active ADCs - start from 0
- } // while fhcMCMcounter
- } // if HC OK
- } // if link active
- fStackLinkNumber++;
- fhcMCMcounter = 0; // next stack link (HC) should go through all active MCMs - start from 0
- } // while fStackLinkNumber
- } // if stack active
- fStackNumber++;
- fStackLinkNumber = 0; // next stack should go through all links - start from 0
- } // while fStackNumber
- } // if fBufferRead
-
- // in case rawreader manages the mem buffers, go for the next buffer
- if (fRawReader) {
- Int_t nextBuff = NextBuffer();
- while (nextBuff != -1) {
- if (nextBuff > 0) {
- fBufferRead = kTRUE;
- return Next();
+ fDigitsManager = digMgr;
+ fDigitsParam = 0x0;
+
+ fErrorFlags = 0;
+
+ if (!fRawReader) {
+ AliError("No raw reader available");
+ return -1;
+ }
+
+ while (fCurrSlot < 0 || fCurrSlot >= fgkNstacks) {
+ if (!NextDDL()) {
+ fCurrSlot = -1;
+ return -1;
+ }
+ while ((fCurrSlot < fgkNstacks) &&
+ (((fCurrStackMask & (1 << fCurrSlot)) == 0) ||
+ ((fCurrLinkMask[fCurrSlot] & (1 << fCurrLink))) == 0)) {
+ if ((fCurrStackMask & (1 << fCurrSlot)) == 0) {
+ ++fCurrSlot;
+ fCurrSlot = 0;
+ continue;
+ }
+ fCurrLink++;
+ if (fCurrLink >= fgkNlinks) {
+ SeekNextStack();
+ fCurrLink = 0;
+ fCurrSlot++;
}
- nextBuff = NextBuffer();
}
}
- return kFALSE;
-}
+ AliDebug(2, Form("Stack %i, Link %i, mask: 0x%02x", fCurrSlot, fCurrLink, fCurrLinkMask[fCurrSlot]));
+ fCurrHC = (fCurrEquipmentId - kDDLOffset) * fgkNlinks * fgkNstacks +
+ fCurrSlot * fgkNlinks + fCurrLink;
-//------------------------------------------------------------
-Int_t AliTRDrawStream::NextChamber(AliTRDdigitsManager *const digitsManager, UInt_t **trackletContainer, UShort_t **errorCodeContainer)
-{
- //
- // Fills single chamber digit array
- // Return value is the detector number
- //
- AliTRDarrayADC *digits = 0;
- AliTRDarrayDictionary *track0 = 0;
- AliTRDarrayDictionary *track1 = 0;
- AliTRDarrayDictionary *track2 = 0;
- AliTRDSignalIndex *indexes = 0;
- AliTRDdigitsParam *digitsparam = 0;
-
- // Loop through the digits
- Int_t lastdet = -1;
- Int_t det = -1;
- Int_t lastside = -1;
- Int_t side = -1;
- Int_t it = 0;
- Int_t ntracklets = 0;
-
- if (trackletContainer) {
- for (Int_t i = 0; i < 2; i++)
- for (Int_t j = 0; j < MAXTRACKLETSPERHC; j++)
- trackletContainer[i][j] = 0;
+ if (fCurrLinkMonitorFlags[(((fCurrEquipmentId - kDDLOffset) * fgkNstacks) + fCurrSlot) * fgkNlinks + fCurrLink] != 0) {
+ LinkError(kLinkMonitor);
+ if (fgErrorBehav[kLinkMonitor] == kTolerate)
+ ReadLinkData();
}
-
- while (Next()) {
- det = GetDet();
- side = GetSide();
-
- if (trackletContainer) {
- if ((det + side*AliTRDgeometry::kNdet) != (lastdet + lastside*AliTRDgeometry::kNdet)) {
- if (det != lastdet) {
- if (lastdet != -1) {
- fmcmADCcounter--;
- return lastdet;
- }
- }
- ntracklets = GetNTracklets();
- if (ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets); //copy tracklet words to trackletContainer array
- lastside = side;
- }
- }
-
- if (det != lastdet) {
- // If new detector found
- if (lastdet == -1) {
- lastdet = det;
- fLastHC = fHC;
+ else
+ // read the data from one HC
+ ReadLinkData();
+
+ // read all data endmarkers
+ SeekNextLink();
+
+ if (fCurrLink % 2 == 0) {
+ // if we just read the A-side HC then also check the B-side
+ fCurrLink++;
+ fCurrHC++;
+ if (fCurrLinkMask[fCurrSlot] & (1 << fCurrLink)) {
+ if (fCurrLinkMonitorFlags[(((fCurrEquipmentId - kDDLOffset) * fgkNstacks) + fCurrSlot) * fgkNlinks + fCurrLink] != 0) {
+ LinkError(kLinkMonitor);
+ if (fgErrorBehav[kLinkMonitor] == kTolerate)
+ ReadLinkData();
}
else {
- fmcmADCcounter--;
- fHC = fLastHC ;
- return lastdet;
+ ReadLinkData();
}
+ SeekNextLink();
+ }
+ }
- if (det < 0 || det >= AliTRDgeometry::kNdet) {
- if (fSM.fClean == kTRUE) {
- AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));
- }
- else {
- AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));
- }
- continue;
+ do {
+ if ((fCurrStackMask & (1 << fCurrSlot)) == 0) {
+ fCurrLink = 0;
+ fCurrSlot++;
+ }
+ else {
+ fCurrLink++;
+ if (fCurrLink >= fgkNlinks) {
+ SeekNextStack();
+ fCurrLink = 0;
+ fCurrSlot++;
}
+ }
+ } while ((fCurrSlot < fgkNstacks) &&
+ (((fCurrStackMask & (1 << fCurrSlot)) == 0) ||
+ ((fCurrLinkMask[fCurrSlot] & (1 << fCurrLink))) == 0));
+
+ // return chamber information from HC if it is valid
+ // otherwise return information from link position
+ if (fCurrSm < 0 || fCurrSm >= fgkNsectors || fCurrStack < 0 || fCurrStack >= fgkNstacks || fCurrLayer < 0 || fCurrLayer >= fgkNlinks/2)
+ return ((fCurrEquipmentId-kDDLOffset) + fCurrSlot * fgkNlinks/2 + fCurrLink/2);
+ else
+ return (fCurrSm * fgkNstacks*fgkNlinks/2 + fCurrStack * fgkNlinks/2 + fCurrLayer);
+}
- // Add a container for the digits of this detector
- digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);
- if (digitsManager->UsesDictionaries()) {
- track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);
- track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);
- track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);
- }
+Int_t AliTRDrawStream::ReadGTUHeaders(UInt_t *buffer)
+{
+ // check the data source and read the headers
- if (!digits) {
- if (fSM.fClean == kTRUE) {
- AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));
- }
- else {
- AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));
- }
- return -1;
- }
+ if (fCurrEquipmentId >= kDDLOffset && fCurrEquipmentId <= kDDLMax) {
+ // this is ROC data
- Int_t rowMax = GetRowMax();
- Int_t colMax = GetColMax();
- Int_t ntbins = GetNumberOfTimeBins();
-
- // Set number of timebin into digitparam
- if (!fIsGlobalDigitsParamSet){
- digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();
- digitsparam->SetCheckOCDB(kFALSE);
- digitsparam->SetNTimeBins(ntbins);
- digitsparam->SetADCbaseline(10);\r\r
- digitsparam->SetPretiggerPhase(det,GetPreTriggerPhase());\r\r
- fIsGlobalDigitsParamSet = kTRUE;
- }
- if(!digitsparam){ \r\r
- digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();
- digitsparam->SetPretiggerPhase(det,GetPreTriggerPhase());\r\r
- }\r\r
-
- // Allocate memory space for the digits buffer
- if (digits->GetNtime() == 0) {
- digits->Allocate(rowMax, colMax, ntbins);
- digits->SetBaseline(digitsparam->GetADCbaseline());
- if (digitsManager->UsesDictionaries()) {
- track0->Allocate(rowMax, colMax, ntbins);
- track1->Allocate(rowMax, colMax, ntbins);
- track2->Allocate(rowMax, colMax, ntbins);
- }
- }
+ // setting the pointer to data and current reading position
+ fPayloadCurr = fPayloadStart = buffer;
+ fPayloadSize = fRawReader->GetDataSize() / sizeof(UInt_t);
+ fStats.fStatsSector[fCurrEquipmentId - kDDLOffset].fBytes = fRawReader->GetDataSize();
+ AliDebug(2, Form("Read buffer of size: %i", fRawReader->GetDataSize()));
- indexes = digitsManager->GetIndexes(det);
- indexes->SetSM(GetSM());
- indexes->SetStack(GetStack());
- indexes->SetLayer(GetLayer());
- indexes->SetDetNumber(det);
- if (indexes->IsAllocated() == kFALSE)
- indexes->Allocate(rowMax, colMax, ntbins);
- }
-
- // ntimebins data are ready to read
- for (it = 0; it < GetNumberOfTimeBins(); it++) {
- if (GetSignals()[it] > 0) {
-
- if (fSharedPadsOn)
- digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), it, GetSignals()[it]);
- else
- digits->SetData(GetRow(), GetCol(), it, GetSignals()[it]);
-
- indexes->AddIndexRC(GetRow(), GetCol());
- if (digitsManager->UsesDictionaries()) {
- track0->SetData(GetRow(), GetCol(), it, 0);
- track1->SetData(GetRow(), GetCol(), it, 0);
- track2->SetData(GetRow(), GetCol(), it, 0);
- }
- }
- } // it
- } // while Next()
-
- return det;
-}
+ AliDebug(1, DumpRaw("raw data", fPayloadCurr, TMath::Min(fPayloadSize, 1000)));
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::Init()
-{
- //
- // Initialize geometry and fee parameters
- //
- TDirectory *saveDir = gDirectory;
-
- if (!fGeometry) {
- fGeometry = new AliTRDgeometry();
- if (!fGeometry) {
- AliError("Geometry FAILED!");
- return kFALSE;
+ // read SM header
+ if (ReadSmHeader() < 0) {
+ AliError(Form("Reading SM header failed, skipping this DDL %i", fCurrEquipmentId));
+ return -1;
}
- }
- fTRDfeeParam = AliTRDfeeParam::Instance();
- if (!fTRDfeeParam) {
- AliError("AliTRDfeeParam FAILED!");
- return kFALSE;
- }
-
- fMaxADCgeom = (Int_t)fGeometry->ADCmax();
+ // read tracking headers (if available)
+ if (fCurrTrkHeaderAvail) {
+ for (Int_t iStack = 0; iStack < fgkNstacks; iStack++) {
+ if ((fCurrStackMask & (1 << iStack)) != 0)
+ ReadTrackingHeader(iStack);
+ }
+ }
- ResetCounters(); // fBufferRead is set to kFALSE - important
+ // read trigger header(s) (if available)
+ if (fCurrTrgHeaderAvail)
+ ReadTriggerHeaders();
- saveDir->cd();
+ // read stack header
+ for (Int_t iStack = 0; iStack < fgkNstacks; iStack++) {
+ if ((fCurrStackMask & (1 << iStack)) != 0)
+ ReadStackHeader(iStack);
+ }
- return kTRUE;
+ return 0;
+ }
+ else
+ return -1;
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::InitBuffer(void * const buffer, UInt_t length)
+Int_t AliTRDrawStream::ReadSmHeader()
{
- //
- // set initial information about the buffer
- //
- if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));
- if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041) // tmp protection
- return kFALSE;
-
- if (WORD_SIZE == 0) {
- AliFatal("Strange word size. size of UInt_t == 0");
- return kFALSE;
- }
+ // read the SMU index header at the current reading position
+ // and store the information in the corresponding variables
- ResetCounters();
+ if (fPayloadCurr - fPayloadStart >= fPayloadSize - 1) {
+ EquipmentError(kUnknown, "SM Header incomplete");
+ return -1;
+ }
- fpBegin = (UInt_t *)buffer;
- fWordLength = length/WORD_SIZE;
- fpEnd = fpBegin + fWordLength;
- fpPos = fpBegin;
+ fCurrTrgFlags[fCurrEquipmentId-kDDLOffset] = 0;
+
+ fCurrSmHeaderSize = ((*fPayloadCurr) >> 16) & 0xffff;
+ fCurrSmHeaderVersion = ((*fPayloadCurr) >> 12) & 0xf;
+ fCurrTrackEnable = ((*fPayloadCurr) >> 6) & 0x1;
+ fCurrTrackletEnable = ((*fPayloadCurr) >> 5) & 0x1;
+ fCurrStackMask = ((*fPayloadCurr) ) & 0x1f;
+ fCurrHwRev = (fPayloadCurr[1] >> 12) & 0xffff;
+ fCurrStackEndmarkerAvail = 0;
+
+ switch (fCurrSmHeaderVersion) {
+ case 0xb:
+ fCurrTrailerReadout = 0;
+ fCurrTrgHeaderAvail = 0;
+ fCurrEvType = 0;
+ fCurrTrkHeaderAvail = 0;
+
+ DecodeGTUtracks();
+ break;
+
+ case 0xc:
+ fCurrTrailerReadout = ((*fPayloadCurr) >> 10) & 0x1;
+ fCurrTrgHeaderAvail = 1;
+ fCurrTrgHeaderReadout = ((*fPayloadCurr) >> 9) & 0x1;
+ fCurrEvType = ((*fPayloadCurr) >> 7) & 0x3;
+ fCurrTrkHeaderAvail = fCurrTrackEnable;
+ fCurrTriggerEnable = (fPayloadCurr[2] >> 8) & 0xfff;
+ fCurrTriggerFired = (fPayloadCurr[2] >> 20) & 0xfff;
+ fCurrTrgFlags[fCurrEquipmentId-kDDLOffset] = fCurrTriggerFired;
+ break;
+
+ case 0xd:
+ fCurrTrailerReadout = ((*fPayloadCurr) >> 10) & 0x1;
+ fCurrTrgHeaderAvail = 1;
+ fCurrTrgHeaderReadout = ((*fPayloadCurr) >> 9) & 0x1;
+ fCurrEvType = ((*fPayloadCurr) >> 7) & 0x3;
+ fCurrTrkHeaderAvail = fCurrTrackEnable;
+ fCurrTriggerEnable = (fPayloadCurr[2] >> 8) & 0xfff;
+ fCurrTriggerFired = (fPayloadCurr[2] >> 20) & 0xfff;
+ fCurrTrgFlags[fCurrEquipmentId-kDDLOffset] = fCurrTriggerFired;
+ fCurrStackEndmarkerAvail = 1;
+#ifdef TRD_RAW_DEBUG
+ if (fCurrSmHeaderSize > 7) {
+ fCurrL0Count[fCurrEquipmentId-kDDLOffset] = fPayloadCurr[3];
+ fCurrL1aCount[fCurrEquipmentId-kDDLOffset] = fPayloadCurr[4];
+ fCurrL1rCount[fCurrEquipmentId-kDDLOffset] = fPayloadCurr[5];
+ fCurrL2aCount[fCurrEquipmentId-kDDLOffset] = fPayloadCurr[6];
+ fCurrL2rCount[fCurrEquipmentId-kDDLOffset] = fPayloadCurr[7];
+ }
+#endif
+ break;
- if (fpBegin == 0 || length <= 0) {
- AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));
- return kFALSE;
+ default:
+ AliError(Form("unknown SM header version: 0x%x", fCurrSmHeaderVersion));
}
- SwapOnEndian();
+ AliDebug(5, Form("SM header: size: %i, version: %i, track enable: %i, tracklet enable: %i, stack mask: %2x, trailer: %i, trgheader: %i, trkheader: %i",
+ fCurrSmHeaderSize,
+ fCurrSmHeaderVersion,
+ fCurrTrackEnable,
+ fCurrTrackletEnable,
+ fCurrStackMask,
+ fCurrTrailerReadout,
+ fCurrTrgHeaderAvail,
+ fCurrTrkHeaderAvail ));
- if (fgDumpHead >= 0) {
- if ( fgDumpHead == 0 ) { // dump all words
- AliInfo(Form("---------- Dumping all words from the beginnig of the buffer ----------"));
- if (DumpWords(fpBegin, fWordLength) == kFALSE) AliError("Dump failed. Not enough data.");
- }
- else {
- AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));
- if (DumpWords(fpBegin, fgDumpHead) == kFALSE) AliError("Dump failed. Not enough data.");
- }
- AliInfo(Form("---------- Dumping ended ----------------------------------------------"));
- }
+ // jump to the first word after the SM header
+ fPayloadCurr += fCurrSmHeaderSize + 1;
- return kTRUE;
+ return fCurrSmHeaderSize + 1;
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeGTUheader()
+Int_t AliTRDrawStream::DecodeGTUtracks()
{
- // Decode Supermodule Index Word
- DecodeSMInfo(fpPos, &fSM);
-
- if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));
-
- fpPos++;
- if (fpPos < fpEnd) {
- // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.
- // For the moment, we skip decoding these words
- if (SkipWords(fSM.fHeaderSize) == kTRUE) {
- for (Int_t istack = 0; istack < 5; istack++) {
- if (fSM.fStackActive[istack] == kFALSE)
- continue;
-
- fStack = &fSM.fStacks[istack];
-
- // Decode Stack Index Word of given stack
- DecodeStackInfo(fpPos, fStack);
- fpPos++;
-
- fSM.fNexpectedHalfChambers += fStack->fActiveLinks;
-
- if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));
-
- if (SkipWords(fStack->fHeaderSize-6) == kFALSE) { // 6 is the 6 stack header words for 12 links
- if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");
- return kFALSE;
- }
- for (Int_t iword=0; iword<6; iword++) { // decode 6 stack header words
- // Decode Stack Header Word of given stack
- DecodeStackHeader(fpPos, fStack, iword);
- fpPos++;
- }
+ // decode GTU track words
+ // this depends on the hardware revision of the SMU
+
+ Int_t sector = fCurrEquipmentId-kDDLOffset;
+
+ if ((sector < 0) || (sector > 17)) {
+ AliError(Form("Invalid sector %i for GTU tracks", sector));
+ return -1;
+ }
+
+ AliDebug(1, DumpRaw(Form("GTU tracks in sector %2i (hw rev %i)", sector, fCurrHwRev),
+ fPayloadCurr + 4, 10, 0xffe0ffff));
+
+ fCurrTrgFlags[sector] = 0;
+
+ if (fCurrHwRev < 1772) {
+ UInt_t fastWord; // fast trigger word
+ ULong64_t trackWord = 0; // extended track word
+ Int_t stack = 0;
+ Int_t idx = 0;
+ for (UInt_t iWord = 4; iWord < fCurrSmHeaderSize; iWord++) {
+ if (fPayloadCurr[iWord] == 0x10000000) { // stack boundary marker
+ stack++;
+ idx = 0;
+ }
+ else {
+ if ((idx == 0) &&
+ ((fPayloadCurr[iWord] & 0xfffff0f0) == 0x13370000)) {
+ fastWord = fPayloadCurr[iWord];
+ fCurrTrgFlags[sector] |= 1 << (stack+11); // assume tracking done if fast word sent
+ AliDebug(1, Form("stack %i: fast trigger word: 0x%08x", stack, fastWord));
+ continue;
+ }
+ else if ((idx & 0x1) == 0x1) {
+ trackWord |= ((ULong64_t) fPayloadCurr[iWord]) << 32;
+ AliDebug(1,Form("track debug word: 0x%016llx", trackWord));
+ if (fTracks) {
+ AliESDTrdTrack *trk = new ((*fTracks)[fTracks->GetEntriesFast()])
+ AliESDTrdTrack();
+
+ trk->SetSector(sector);
+ trk->SetStack((trackWord >> 60) & 0x7);
+ trk->SetA(0);
+ trk->SetB(0);
+ trk->SetPID(0);
+ trk->SetLayerMask((trackWord >> 16) & 0x3f);
+ trk->SetTrackletIndex((trackWord >> 22) & 0x3f, 0);
+ trk->SetTrackletIndex((trackWord >> 28) & 0x3f, 1);
+ trk->SetTrackletIndex((trackWord >> 34) & 0x3f, 2);
+ trk->SetTrackletIndex((trackWord >> 40) & 0x3f, 3);
+ trk->SetTrackletIndex((trackWord >> 46) & 0x3f, 4);
+ trk->SetTrackletIndex((trackWord >> 52) & 0x3f, 5);
+
+ trk->SetFlags(0);
+ trk->SetReserved(0);
+ trk->SetLabel(-3);
+
+ Float_t pt = (((Int_t) (trackWord & 0xffff) ^ 0x8000) - 0x8000)/128.;
+ if (TMath::Abs(pt) > 0.1) {
+ trk->SetA((Int_t) (0.15*51625./100./pt / 160e-4 * 2));
+ }
+ }
+ }
+ else {
+ trackWord = fPayloadCurr[iWord];
+ }
+ idx++;
}
}
- else {
- return kFALSE;
+ }
+ else if (fCurrHwRev < 1804) {
+ UInt_t fastWord; // fast trigger word
+ ULong64_t trackWord = 0; // extended track word
+ Int_t stack = 0;
+ Int_t idx = 0;
+ for (UInt_t iWord = 4; iWord < fCurrSmHeaderSize; iWord++) {
+ if (fPayloadCurr[iWord] == 0xffe0ffff) { // stack boundary marker
+ stack++;
+ idx = 0;
+ }
+ else {
+ if ((idx == 0) &&
+ ((fPayloadCurr[iWord] & 0xfffff0f0) == 0x13370000)) {
+ fastWord = fPayloadCurr[iWord];
+ fCurrTrgFlags[sector] |= 1 << (stack+11); // assume tracking done if fast word sent
+ AliDebug(1, Form("stack %i: fast trigger word: 0x%08x", stack, fastWord));
+ continue;
+ }
+ else if ((idx & 0x1) == 0x1) {
+ trackWord |= ((ULong64_t) fPayloadCurr[iWord]) << 32;
+ AliDebug(1, Form("track debug word: 0x%016llx", trackWord));
+ if (fTracks) {
+ AliESDTrdTrack *trk = new ((*fTracks)[fTracks->GetEntriesFast()])
+ AliESDTrdTrack();
+
+ trk->SetSector(fCurrEquipmentId-kDDLOffset);
+ trk->SetStack((trackWord >> 60) & 0x7);
+ trk->SetA(0);
+ trk->SetB(0);
+ trk->SetPID(0);
+ trk->SetLayerMask((trackWord >> 16) & 0x3f);
+ trk->SetTrackletIndex((trackWord >> 22) & 0x3f, 0);
+ trk->SetTrackletIndex((trackWord >> 28) & 0x3f, 1);
+ trk->SetTrackletIndex((trackWord >> 34) & 0x3f, 2);
+ trk->SetTrackletIndex((trackWord >> 40) & 0x3f, 3);
+ trk->SetTrackletIndex((trackWord >> 46) & 0x3f, 4);
+ trk->SetTrackletIndex((trackWord >> 52) & 0x3f, 5);
+
+ trk->SetFlags(0);
+ trk->SetReserved(0);
+ trk->SetLabel(-3);
+
+ Float_t pt = (((Int_t) (trackWord & 0xffff) ^ 0x8000) - 0x8000)/128.;
+ if (TMath::Abs(pt) > 0.1) {
+ trk->SetA((Int_t) (-0.15*51625./100./pt / 160e-4 * 2));
+ }
+ }
+ }
+ else {
+ trackWord = fPayloadCurr[iWord];
+ }
+ idx++;
+ }
}
}
- else {
- if (fgWarnError) AliWarning("No additional sm headers and stack index words present.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
- return kFALSE;
+ else if (fCurrHwRev < 1819) {
+ UInt_t fastWord; // fast trigger word
+ ULong64_t trackWord = 0; // extended track word
+ Int_t stack = 0;
+ Int_t idx = 0;
+ for (UInt_t iWord = 4; iWord < fCurrSmHeaderSize; iWord++) {
+ if (fPayloadCurr[iWord] == 0xffe0ffff) { // stack boundary marker
+ stack++;
+ idx = 0;
+ }
+ else {
+ if ((idx == 0) &&
+ ((fPayloadCurr[iWord] & 0xfffff0f0) == 0x13370000)) {
+ fastWord = fPayloadCurr[iWord];
+ if (fastWord & (1 << 13))
+ fCurrTrgFlags[sector] |= 1 << (stack+11);
+ AliDebug(1, Form("stack %i: fast trigger word: 0x%08x", stack, fastWord));
+ continue;
+ }
+ else if ((idx & 0x1) == 0x1) {
+ trackWord |= ((ULong64_t) fPayloadCurr[iWord]) << 32;
+ AliDebug(1, Form("track debug word: 0x%016llx", trackWord));
+
+ if (fTracks) {
+ AliESDTrdTrack *trk = new ((*fTracks)[fTracks->GetEntriesFast()])
+ AliESDTrdTrack();
+
+ trk->SetSector(fCurrEquipmentId-kDDLOffset);
+ trk->SetStack((trackWord >> 60) & 0x7);
+ trk->SetA(0);
+ trk->SetB(0);
+ // trk->SetPt(((trackWord & 0xffff) ^ 0x8000) - 0x8000);
+ trk->SetPID(0);
+ trk->SetLayerMask((trackWord >> 16) & 0x3f);
+ trk->SetTrackletIndex((trackWord >> 22) & 0x3f, 0);
+ trk->SetTrackletIndex((trackWord >> 28) & 0x3f, 1);
+ trk->SetTrackletIndex((trackWord >> 34) & 0x3f, 2);
+ trk->SetTrackletIndex((trackWord >> 40) & 0x3f, 3);
+ trk->SetTrackletIndex((trackWord >> 46) & 0x3f, 4);
+ trk->SetTrackletIndex((trackWord >> 52) & 0x3f, 5);
+
+ trk->SetFlags(0);
+ trk->SetReserved(0);
+ trk->SetLabel(-3);
+
+ Float_t pt = (((Int_t) (trackWord & 0xffff) ^ 0x8000) - 0x8000)/128.;
+ if (TMath::Abs(pt) > 0.1) {
+ trk->SetA((Int_t) (0.15*51625./100./trk->Pt() / 160e-4 * 2));
+ }
+ }
+ }
+ else {
+ trackWord = fPayloadCurr[iWord];
+ }
+ idx++;
+ }
+ }
}
+ else if (fCurrHwRev < 1860) {
+ UInt_t fastWord; // fast trigger word
+ ULong64_t trackWord = 0; // extended track word
+ Int_t stack = 0;
+ Int_t idx = 0;
+ Bool_t upperWord = kFALSE;
+ Int_t word = 0;
+ for (UInt_t iWord = 4; iWord < fCurrSmHeaderSize; iWord++) {
+ if (fPayloadCurr[iWord] == 0xffe0ffff) { // stack boundary marker
+ stack++;
+ idx = 0;
+ upperWord = kFALSE;
+ }
+ else {
+ // assemble the 32-bit words out of 16-bit blocks
+ if (upperWord) {
+ word |= (fPayloadCurr[iWord] & 0xffff0000);
+ upperWord = kFALSE;
+ }
+ else {
+ // lower word is read first
+ word = (fPayloadCurr[iWord] & 0xffff0000) >> 16;
+ upperWord = kTRUE;
+ continue;
+ }
+
+ if ((word & 0xffff0008) == 0x13370008) {
+ fastWord = word;
+ AliDebug(1, Form("stack %i: fast track word: 0x%08x", stack, fastWord));
+ if (fastWord & (1 << 13))
+ fCurrTrgFlags[sector] |= 1 << (stack+11);
+ continue;
+ }
+ else if ((idx & 0x1) == 0x1) {
+ trackWord |= ((ULong64_t) word) << 32;
+ AliDebug(1, Form("track debug word: 0x%016llx", trackWord));
+ if (fTracks) {
+ AliESDTrdTrack *trk = new ((*fTracks)[fTracks->GetEntriesFast()])
+ AliESDTrdTrack();
+
+ trk->SetSector(fCurrEquipmentId-kDDLOffset);
+ trk->SetStack((trackWord >> 60) & 0x7);
+ trk->SetA(0);
+ trk->SetB(0);
+ trk->SetPID(0);
+ trk->SetLayerMask((trackWord >> 16) & 0x3f);
+ trk->SetTrackletIndex((trackWord >> 22) & 0x3f, 0);
+ trk->SetTrackletIndex((trackWord >> 28) & 0x3f, 1);
+ trk->SetTrackletIndex((trackWord >> 34) & 0x3f, 2);
+ trk->SetTrackletIndex((trackWord >> 40) & 0x3f, 3);
+ trk->SetTrackletIndex((trackWord >> 46) & 0x3f, 4);
+ trk->SetTrackletIndex((trackWord >> 52) & 0x3f, 5);
+
+ trk->SetFlags(0);
+ trk->SetReserved(0);
+ trk->SetLabel(-3);
+
+ Float_t pt = (((Int_t) (trackWord & 0xffff) ^ 0x8000) - 0x8000)/128.;
+ if (TMath::Abs(pt) > 0.1) {
+ trk->SetA((Int_t) (0.15*51625./100./pt / 160e-4 * 2));
+ }
+ }
+ }
+ else {
+ trackWord = word;
+ }
+ idx++;
+ }
+ }
- if (fpPos < fpEnd) {
- if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
}
else {
- if (fgWarnError) AliWarning("No data just after GTU headers.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
- return kFALSE;
+ ULong64_t trackWord = 0; // this is the debug word
+ Int_t stack = 0;
+ Int_t idx = 0;
+ Bool_t upperWord = kFALSE;
+ Int_t word = 0;
+ for (UInt_t iWord = 4; iWord < fCurrSmHeaderSize; iWord++) {
+ if (fPayloadCurr[iWord] == 0xffe0ffff) {
+ stack++;
+ idx = 0;
+ upperWord = kFALSE;
+ }
+ else {
+ // assemble the 32-bit words out of 16-bit blocks
+ if (upperWord) {
+ word |= (fPayloadCurr[iWord] & 0xffff0000);
+ upperWord = kFALSE;
+ }
+ else {
+ // lower word is read first
+ word = (fPayloadCurr[iWord] & 0xffff0000) >> 16;
+ upperWord = kTRUE;
+ continue;
+ }
+
+ if ((word & 0xffff0008) == 0x13370008) {
+ AliDebug(1, Form("stack %i: fast track word: 0x%08x", stack, word));
+ continue;
+ }
+ else if ((word & 0xffff0010) == 0x13370010) {
+ AliDebug(1, Form("stack %i: tracking done word: 0x%08x", stack, word));
+ fCurrTrgFlags[sector] |= 1 << (stack+11);
+ continue;
+ }
+ else if ((idx & 0x1) == 0x1) {
+ trackWord |= ((ULong64_t) word) << 32;
+ AliDebug(1, Form("track debug word: 0x%16llx", trackWord));
+ if (fTracks) {
+ AliESDTrdTrack *trk = new ((*fTracks)[fTracks->GetEntriesFast()])
+ AliESDTrdTrack();
+ trk->SetSector(fCurrEquipmentId-kDDLOffset);
+ trk->SetStack((trackWord >> 60) & 0x7);
+ trk->SetA(0);
+ trk->SetB(0);
+ trk->SetPID(0);
+ trk->SetLayerMask((trackWord >> 16) & 0x3f);
+ trk->SetTrackletIndex((trackWord >> 22) & 0x3f, 0);
+ trk->SetTrackletIndex((trackWord >> 28) & 0x3f, 1);
+ trk->SetTrackletIndex((trackWord >> 34) & 0x3f, 2);
+ trk->SetTrackletIndex((trackWord >> 40) & 0x3f, 3);
+ trk->SetTrackletIndex((trackWord >> 46) & 0x3f, 4);
+ trk->SetTrackletIndex((trackWord >> 52) & 0x3f, 5);
+
+ trk->SetFlags(0);
+ trk->SetReserved(0);
+ trk->SetLabel(-3);
+
+ Float_t pt = (((Int_t) (trackWord & 0xffff) ^ 0x8000) - 0x8000)/128.;
+ if (TMath::Abs(pt) > 0.1) {
+ trk->SetA(-(Int_t) (0.15*51625./100./pt / 160e-4 * 2));
+ }
+ }
+ }
+ else {
+ trackWord = word;
+ }
+ idx++;
+ }
+ }
}
-
- if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
-
- return kTRUE;
+ return 0;
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeSM(void * const buffer, UInt_t length)
+Int_t AliTRDrawStream::ReadTrackingHeader(Int_t stack)
{
- //
- // decode one sm data in buffer
- //
- ResetIterators();
-
- fSM.fClean = kTRUE;
- if (InitBuffer(buffer, length) == kFALSE) {
- if (fgWarnError) AliError("InitBuffer failed.");
- fSM.fClean = kFALSE;
- return kFALSE;
- }
+ // read the tracking information and store it for the given stack
- if (DecodeGTUheader()== kFALSE)
- return kFALSE;
+ // index word
- for (Int_t istack = 0; istack < 5; istack++) {
- fStackNumber = istack;
- if (fSM.fStackActive[istack] == kFALSE)
- continue;
-
- fStack = &fSM.fStacks[istack];
-
- fgLastHC = -1; // to check rob number odering
- for (Int_t ilink = 0; ilink < 12; ilink++) {
- fStackLinkNumber = ilink;
- if (fStack->fLinksActive[ilink] == kFALSE)
- continue;
-
- // check GTU link monitor
- if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0)) {
- fStack->fLinkMonitorError[ilink] = 1;
- SeekEndOfData(); // skip this HC data if GTU link monitor report error
- fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error
- continue;
- }
+ fCurrTrkHeaderIndexWord[stack] = *fPayloadCurr;
+ fCurrTrkHeaderSize[stack] = ((*fPayloadCurr) >> 16) & 0x3ff;
- if (fpPos >= fpEnd) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
- if (fgWarnError) AliError("Link data missing.");
- fSM.fClean = kFALSE;
- break;
- }
-
- fHC = &fStack->fHalfChambers[ilink];
- ResetPerHC();
+ AliDebug(1, Form("tracking header index word: 0x%08x, size: %i (hw rev: %i)",
+ fCurrTrkHeaderIndexWord[stack], fCurrTrkHeaderSize[stack], fCurrHwRev));
+ Int_t trackingTime = *fPayloadCurr & 0x3ff;
- if (fSM.fTrackletEnable == kTRUE) {
- if (DecodeTracklets() == kFALSE) {
- fSM.fClean = kFALSE;
- SeekEndOfData();
-
- if (fgWarnError) {
- AliError(Form("Tracklet decoding failed stack %d link %d", fStackNumber, fStackLinkNumber));
- }
- continue;
- }
- }
+ fCurrTrgFlags[fCurrEquipmentId-kDDLOffset] |= ((fCurrTrkHeaderIndexWord[stack] >> 10) & 0x1) << (22 + stack);
+ fPayloadCurr++;
- if (fpPos >= fpEnd) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
- if (fgWarnError) AliError("HC data missing.");
- fSM.fClean = kFALSE;
- break;
- }
-
- fgLastROB = -1; // to check mcm number odering
- fgLastIndex = -1 ; // to check mcm number odering
- if (DecodeHC() == kFALSE) {
- fSM.fClean = kFALSE;
- if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW
- // during ADC data decoding or MCM header decoding
- // we don't seek ENDOFRAWDATAMARKER
- if (fgWarnError) {
- AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
- AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
- }
-
- continue;
- }
- else {
- SeekEndOfData(); // make sure that finish off with the end of data markers
- }
- } // ilink
- } // istack
+ // data words
+ ULong64_t trackWord = 0;
+ Int_t idx = 0;
+ Int_t trackIndex = fTracks ? fTracks->GetEntriesFast() : -1;
- ResetIterators(); // need to do it again for Next() function
+ for (UInt_t iWord = 0; iWord < fCurrTrkHeaderSize[stack]; iWord++) {
- if (fSM.fClean == kTRUE)
- return kTRUE;
-
- if (fgCleanDataOnly && (fSM.fClean == kFALSE)) {
- if (fgWarnError) {
- AliWarning("Buffer with errors. Returning FALSE.");
- AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
+ if (!(idx & 0x1)) {
+ // first part of 64-bit word
+ trackWord = fPayloadCurr[iWord];
}
- fSM.fActiveStacks = 0; // Next() will not give data
- return kFALSE;
+ else {
+ trackWord |= ((ULong64_t) fPayloadCurr[iWord]) << 32;
+
+ if (trackWord & (1ul << 63)) {
+ if ((trackWord & (0x3ful << 56)) != 0) {
+ // track word
+ AliDebug(2, Form("track word: 0x%016llx", trackWord));
+
+ if (fTracks) {
+ AliESDTrdTrack *trk = new ((*fTracks)[fTracks->GetEntriesFast()])
+ AliESDTrdTrack();
+
+ trk->SetSector(fCurrEquipmentId-kDDLOffset);
+ trk->SetLayerMask((trackWord >> 56) & 0x3f);
+ trk->SetA( (((trackWord >> 38) & 0x3ffff) ^ 0x20000) - 0x20000);
+ trk->SetB( (((trackWord >> 20) & 0x3ffff) ^ 0x20000) - 0x20000);
+ trk->SetC( (((trackWord >> 8) & 0xffff) ^ 0x8000) - 0x8000);
+ trk->SetPID((trackWord >> 0) & 0xff);
+ trk->SetStack(stack);
+ trk->SetLabel(-3);
+
+ // now compare the track word with the one generated from the ESD information
+ if (trackWord != trk->GetTrackWord(0)) {
+ AliError(Form("track word 0x%016llx does not match the read one 0x%016llx",
+ trk->GetTrackWord(0), trackWord));
+ }
+ }
+ }
+ else {
+ // done marker (so far only used to set trigger flag)
+ fCurrTrgFlags[fCurrEquipmentId-kDDLOffset] |= 1 << (27 + stack);
+ fCurrTrkFlags[(fCurrEquipmentId-kDDLOffset)*fgkNstacks + stack] = trackWord;
+
+ AliDebug(2, Form("tracking done marker: 0x%016llx, trigger flags: 0x%08x",
+ trackWord, fCurrTrgFlags[fCurrEquipmentId-kDDLOffset]));
+ AliDebug(2, Form("seg / stack / first / last / done / index : %i %i %lli %lli %lli %i",
+ fCurrEquipmentId - kDDLOffset, stack,
+ (trackWord >> 20) & 0x3ff,
+ (trackWord >> 10) & 0x3ff,
+ (trackWord >> 0) & 0x3ff,
+ trackingTime));
+ }
+ }
+ else {
+ // extended track word
+ AliDebug(2, Form("extended track word: 0x%016llx", trackWord));
+
+ if (fTracks) {
+ AliESDTrdTrack *trk = (AliESDTrdTrack*) (*fTracks)[trackIndex];
+
+ trk->SetFlags((trackWord >> 52) & 0x7ff);
+ trk->SetFlagsTiming((trackWord >> 51) & 0x1);
+ trk->SetReserved((trackWord >> 49) & 0x3);
+ trk->SetY((trackWord >> 36) & 0x1fff);
+ trk->SetTrackletIndex((trackWord >> 0) & 0x3f, 0);
+ trk->SetTrackletIndex((trackWord >> 6) & 0x3f, 1);
+ trk->SetTrackletIndex((trackWord >> 12) & 0x3f, 2);
+ trk->SetTrackletIndex((trackWord >> 18) & 0x3f, 3);
+ trk->SetTrackletIndex((trackWord >> 24) & 0x3f, 4);
+ trk->SetTrackletIndex((trackWord >> 30) & 0x3f, 5);
+
+ if (trk->GetFlagsTiming() == 0) {
+ AliError(Form("*** track not in time: 0x%016llx", trk->GetExtendedTrackWord(0)));
+ }
+
+ if (trackWord != trk->GetExtendedTrackWord(0)) {
+ AliError(Form("extended track word 0x%016llx does not match the read one 0x%016llx",
+ trk->GetExtendedTrackWord(0), trackWord));
+ }
+
+ trackIndex++;
+ }
+ }
+ }
+ idx++;
}
- return kTRUE;
+ fPayloadCurr += fCurrTrkHeaderSize[stack];
+
+ return fCurrTrkHeaderSize[stack];
}
-//------------------------------------------------------------
-Int_t AliTRDrawStream::DecodeSM()
+Int_t AliTRDrawStream::ReadTriggerHeaders()
{
- //
- // decode SM data in case AliRawReader is in use
- //
- if (fRawReader) {
- Int_t nextBuff = NextBuffer();
- while (nextBuff != -1) {
- if (nextBuff > 0)
- return nextBuff;
- nextBuff = NextBuffer();
+ // read all trigger headers present
+
+ AliDebug(1, Form("trigger mask: 0x%03x, fired: 0x%03x\n",
+ fCurrTriggerEnable, fCurrTriggerFired));
+ // loop over potential trigger blocks
+ for (Int_t iTrigger = 0; iTrigger < fgkNtriggers; iTrigger++) {
+ // check for trigger enable
+ if (fCurrTriggerEnable & (1 << iTrigger)) {
+ // check for readout mode and trigger fired
+ if ((fCurrTrgHeaderReadout == 0) || (fCurrTriggerFired & (1 << iTrigger))) {
+ // index word
+ AliDebug(1, Form("trigger index word %i: 0x%08x\n", iTrigger, *fPayloadCurr));
+ fCurrTrgHeaderIndexWord[iTrigger] = *fPayloadCurr;
+ fCurrTrgHeaderSize[iTrigger] = ((*fPayloadCurr) >> 16) & 0x3ff;
+ if (iTrigger == 7) {
+ // timeout trigger, use to extract tracking time
+ fCurrTrgFlags[fCurrEquipmentId-kDDLOffset] |= (*fPayloadCurr & 0x3ff) << 12;
+ }
+
+ fPayloadCurr++;
+ // data words
+ fPayloadCurr += fCurrTrgHeaderSize[iTrigger];
+ }
}
- return -1;
- }
- else {
- AliWarning("AliRawReader not set.");
}
- return kFALSE;
+ return 0;
}
-//------------------------------------------------------------
-Int_t AliTRDrawStream::DecodeSM(AliRawReader *reader)
+Int_t AliTRDrawStream::ReadStackHeader(Int_t stack)
{
- //
- // decode SM with the AliRawReader
- //
- if (reader != 0) {
- fRawReader = reader;
- return DecodeSM();
- }
- else {
- AliWarning("Argument AliRawReader is 0.");
- }
+ // read the stack header
+ // and store the information in the corresponding variables
- return kFALSE;
-}
+ fCurrStackIndexWord[stack] = *fPayloadCurr;
+ fCurrStackHeaderSize[stack] = (((*fPayloadCurr) >> 16) & 0xffff) + 1;
+ fCurrStackHeaderVersion[stack] = ((*fPayloadCurr) >> 12) & 0xf;
+ fCurrLinkMask[stack] = (*fPayloadCurr) & 0xfff;
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SeekEndOfData()
-{
- //
- // go to end of data marker
- //
- Int_t fEndOfDataCount = 0;
- fNWordsCounter = 0;
-
- while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
- fpPos++;
- fNWordsCounter++;
- }
- while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
- fEndOfDataCount++;
- fpPos++;
- }
-
- return kTRUE;
-}
+ // dumping stack header
+ AliDebug(1, DumpRaw(Form("stack %i header", stack), fPayloadCurr, fCurrStackHeaderSize[stack]));
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SkipMCMdata(UInt_t iw)
-{
- //
- // skip mcm data words due to corruption
- //
- if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));
- UInt_t iwcounter = 0;
- while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw) {
- if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
- if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");
- fMCM->fCorrupted += 16;
- fHC->fCorrupted += 16;
- return kFALSE;
- }
- fpPos++;
- iwcounter++;
+ if (fPayloadCurr - fPayloadStart >= fPayloadSize - (Int_t) fCurrStackHeaderSize[stack]) {
+ EquipmentError(kStackHeaderInvalid, "Stack index header %i incomplete", stack);
+ // dumping stack header
+ AliError(DumpRaw(Form("stack %i header", stack), fPayloadCurr, fCurrStackHeaderSize[stack]));
+
+ return -1;
}
- if (iwcounter == iw) {
- fpPos++;
- return kTRUE;
+ switch (fCurrStackHeaderVersion[stack]) {
+ case 0xa:
+ case 0xb:
+ if (fCurrStackHeaderSize[stack] < 8) {
+ LinkError(kStackHeaderInvalid, "Stack header smaller than expected!");
+ return -1;
+ }
+
+ fCurrCleanCheckout[stack] = fPayloadCurr[1] & 0x1;
+ fCurrBoardId[stack] = (fPayloadCurr[1] >> 8) & 0xff;
+ fCurrHwRevTMU[stack] = (fPayloadCurr[1] >> 16) & 0xffff;
+
+ for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
+ // A side
+ fCurrLinkMonitorFlags [((fCurrEquipmentId - kDDLOffset) * fgkNstacks + stack) *fgkNlinks + iLayer*2] = fPayloadCurr[iLayer+2] & 0xf;
+ fCurrLinkDataTypeFlags [stack * fgkNlinks + iLayer*2] = (fPayloadCurr[iLayer+2] >> 4) & 0x3;
+ fCurrLinkDebugFlags [stack * fgkNlinks + iLayer*2] = (fPayloadCurr[iLayer+2] >> 12) & 0xf;
+ // B side
+ fCurrLinkMonitorFlags [((fCurrEquipmentId - kDDLOffset) * fgkNstacks + stack) *fgkNlinks + iLayer*2 + 1] = (fPayloadCurr[iLayer+2] >> 16) & 0xf;
+ fCurrLinkDataTypeFlags [stack * fgkNlinks + iLayer*2 + 1] = (fPayloadCurr[iLayer+2] >> 20) & 0x3;
+ fCurrLinkDebugFlags [stack * fgkNlinks + iLayer*2 + 1] = (fPayloadCurr[iLayer+2] >> 28) & 0xf;
+ }
+ break;
+
+ default:
+ EquipmentError(kStackHeaderInvalid, "Invalid Stack Header version %x", fCurrStackHeaderVersion[stack]);
}
- if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
+ fPayloadCurr += fCurrStackHeaderSize[stack];
- return kFALSE;
+ return fCurrStackHeaderSize[stack];
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SeekNextMCMheader()
+Int_t AliTRDrawStream::ReadGTUTrailer()
{
- //
- // go to mcm marker
- //
- fpPos++;
-
- while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {
- if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0) {
- if (fgDebugFlag) AliDebug(11,Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));
- return kTRUE;
+ // read the SM trailer containing CRCs from various stages
+
+ UInt_t* trailer = fPayloadStart + fPayloadSize -1;
+
+ // look for the trailer index word from the end
+ for (Int_t iWord = 0; iWord < fPayloadSize-2; iWord++) {
+ if ((fPayloadStart[fPayloadSize-3-iWord] == fgkStackEndmarker[0]) &&
+ (fPayloadStart[fPayloadSize-2-iWord] == fgkStackEndmarker[1]) &&
+ ((fPayloadStart[fPayloadSize-1-iWord] & 0xfff) == 0xf51)) {
+ trailer = fPayloadStart + fPayloadSize - 1 - iWord;
+ break;
}
- if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
- fMCM->fCorrupted += 16;
- fHC->fCorrupted += 16;
- return kFALSE;
- }
- fpPos++;
}
- SeekEndOfData();
+ if (((*trailer) & 0xfff) == 0xf51) {
+ UInt_t trailerIndexWord = (*trailer);
+ Int_t trailerSize = (trailerIndexWord >> 16) & 0xffff;
+ // Int_t trailerVersion = (trailerIndexWord >> 12) & 0xf;
+ AliDebug(2, DumpRaw("GTU trailer", trailer, trailerSize+1));
+ // parse the trailer
+ if (trailerSize >= 4) {
+ // match flags from GTU
+ fCurrMatchFlagsSRAM[fCurrEquipmentId-kDDLOffset] = (trailer[1] >> 0) & 0x1f;
+ fCurrMatchFlagsPostBP[fCurrEquipmentId-kDDLOffset] = (trailer[1] >> 5) & 0x1f;
+ // individual checksums
+ fCurrChecksumStack[fCurrEquipmentId - kDDLOffset][0] = (trailer[1] >> 16) & 0xffff;
+ fCurrChecksumStack[fCurrEquipmentId - kDDLOffset][1] = (trailer[2] >> 0) & 0xffff;
+ fCurrChecksumStack[fCurrEquipmentId - kDDLOffset][2] = (trailer[2] >> 16) & 0xffff;
+ fCurrChecksumStack[fCurrEquipmentId - kDDLOffset][3] = (trailer[3] >> 0) & 0xffff;
+ fCurrChecksumStack[fCurrEquipmentId - kDDLOffset][4] = (trailer[3] >> 16) & 0xffff;
+ fCurrChecksumSIU = trailer[trailerSize];
+
+ if ((fCurrMatchFlagsSRAM[fCurrEquipmentId-kDDLOffset] & fCurrStackMask) != fCurrStackMask)
+ EquipmentError(kCRCmismatch, "CRC mismatch SRAM: 0x%02x", fCurrMatchFlagsSRAM[fCurrEquipmentId-kDDLOffset]);
+ if ((fCurrMatchFlagsPostBP[fCurrEquipmentId-kDDLOffset] & fCurrStackMask) != fCurrStackMask)
+ EquipmentError(kCRCmismatch, "CRC mismatch BP: 0x%02x", fCurrMatchFlagsPostBP[fCurrEquipmentId-kDDLOffset]);
- return kFALSE;
+ }
+ else {
+ LinkError(kUnknown, "Invalid GTU trailer");
+ }
+ }
+ else
+ EquipmentError(kUnknown, "trailer index marker mismatch");
+
+ return 0;
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeTracklets()
+Int_t AliTRDrawStream::ReadLinkData()
{
- //
- // decode tracklets
- //
- fLinkTrackletCounter = 0;
- fEndOfTrackletCount = 0;
- fHC->fNTracklets = 0;
-
- for (Int_t i = 0; i < MAXTRACKLETSPERHC; i++)
- fHC->fTrackletWords[i] = 0;
+ // read the data in one link (one HC) until the data endmarker is reached
+ // returns the number of words read!
- if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
+ Int_t count = 0;
+ UInt_t* startPosLink = fPayloadCurr;
- while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd ) {
- if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));
+ AliDebug(1, DumpRaw(Form("link data from seg %2i slot %i link %2i", fCurrEquipmentId-kDDLOffset, fCurrSlot, fCurrLink),
+ fPayloadCurr, TMath::Min((Int_t) (fPayloadSize - (fPayloadCurr-fPayloadStart)), 100), 0x00000000));
- fLinkTrackletCounter++;
+ if (fMarkers)
+ new ((*fMarkers)[fMarkers->GetEntriesFast()])
+ AliTRDrawStreamError(-kHCactive, fCurrEquipmentId-kDDLOffset, fCurrSlot, fCurrLink);
- if (fLinkTrackletCounter > MAXTRACKLETSPERHC) {
- if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d.",
- fLinkTrackletCounter, MAXTRACKLETSPERHC));
- if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
- fHC->fTrackletError = 1;
- return kFALSE;
- }
+ if (fErrorFlags & kDiscardHC)
+ return count;
- fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into array
- fHC->fNTracklets = fLinkTrackletCounter;
- fpPos++;
+ if (fCurrTrackletEnable) {
+ count += ReadTracklets();
+ if (fErrorFlags & kDiscardHC)
+ return count;
}
- while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd ) {
- if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));
+ AliDebug(1, DumpRaw("HC header", fPayloadCurr, 4, 0x00000000));
+ count += ReadHcHeader();
+ if (fErrorFlags & kDiscardHC)
+ return count;
- fEndOfTrackletCount++;
- fpPos++;
- }
+ Int_t det = fCurrSm * 30 + fCurrStack * 6 + fCurrLayer;
- if ( fEndOfTrackletCount < 2 ) {
- if (fgDebugFlag) AliDebug(11,"End of tracklets word missing");
- if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
- fHC->fTrackletError += 2;
- return kFALSE;
- }
+ if (det > -1 && det < 540) {
- return kTRUE;
-}
+ // ----- check which kind of data -----
+ if (fCurrMajor & 0x40) {
+ if ((fCurrMajor & 0x7) == 0x7) {
+ AliDebug(1, "This is a config event");
+ UInt_t *startPos = fPayloadCurr;
+ while (fPayloadCurr - fPayloadStart < fPayloadSize &&
+ *fPayloadCurr != fgkDataEndmarker)
+ fPayloadCurr++;
+ count += fPayloadCurr - startPos;
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::IsRowValid()
-{
- //
- // check if the row number is in valid range
- //
- if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||
- (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 ) {
- if (fgDebugFlag) AliDebug(11,Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
- , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));
- return kFALSE;
+ // feeding TRAP config
+ AliTRDtrapConfig *trapcfg = AliTRDcalibDB::Instance()->GetTrapConfig();
+ AliTRDmcmSim::ReadPackedConfig(trapcfg, fCurrHC, startPos, fPayloadCurr - startPos);
+ }
+ else {
+ Int_t tpmode = fCurrMajor & 0x7;
+ AliDebug(1, Form("Checking testpattern (mode %i) data", tpmode));
+ count += ReadTPData(tpmode);
+ }
+ }
+ else {
+ // reading real data
+ if (fDigitsManager) {
+ if ((fAdcArray = fDigitsManager->GetDigits(det))) {
+ //fAdcArray->Expand();
+ if (fAdcArray->GetNtime() != fCurrNtimebins)
+ fAdcArray->Allocate(16, 144, fCurrNtimebins);
+ }
+ else {
+ LinkError(kNoDigits);
+ }
+
+ if (!fDigitsParam) {
+ fDigitsParam = fDigitsManager->GetDigitsParam();
+ }
+ if (fDigitsParam) {
+ fDigitsParam->SetPretriggerPhase(det, fCurrPtrgPhase);
+ fDigitsParam->SetNTimeBins(det, fCurrNtimebins);
+ fDigitsParam->SetADCbaseline(det, 10);
+ }
+
+ if (fDigitsManager->UsesDictionaries()) {
+ fDigitsManager->GetDictionary(det, 0)->Reset();
+ fDigitsManager->GetDictionary(det, 1)->Reset();
+ fDigitsManager->GetDictionary(det, 2)->Reset();
+ }
+
+ if ((fSignalIndex = fDigitsManager->GetIndexes(det))) {
+ fSignalIndex->SetSM(fCurrSm);
+ fSignalIndex->SetStack(fCurrStack);
+ fSignalIndex->SetLayer(fCurrLayer);
+ fSignalIndex->SetDetNumber(det);
+ if (!fSignalIndex->IsAllocated())
+ fSignalIndex->Allocate(16, 144, fCurrNtimebins);
+ }
+
+ if (fCurrMajor & 0x20) {
+ AliDebug(1, "This is a zs event");
+ count += ReadZSData();
+ }
+ else {
+ AliDebug(1, "This is a nozs event");
+ count += ReadNonZSData();
+ }
+ }
+ else {
+ // just read until data endmarkers
+ while (fPayloadCurr - fPayloadStart < fPayloadSize &&
+ *fPayloadCurr != fgkDataEndmarker)
+ fPayloadCurr++;
+ }
+ }
+ }
+ else {
+ LinkError(kInvalidDetector, "%i", det);
+ while (fPayloadCurr - fPayloadStart < fPayloadSize &&
+ *fPayloadCurr != fgkDataEndmarker)
+ fPayloadCurr++;
}
- return kTRUE;
+ if (fCurrSm > -1 && fCurrSm < 18) {
+ fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fBytes += (fPayloadCurr - startPosLink) * sizeof(UInt_t);
+ fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fBytesRead += count * sizeof(UInt_t);
+ fStats.fStatsSector[fCurrSm].fBytesRead += count * sizeof(UInt_t);
+ fStats.fBytesRead += count * sizeof(UInt_t);
+ }
+
+ if ((fErrorFlags & kDiscardHC) && fAdcArray)
+ fAdcArray->SetDataInvalid(); // invalidate the data
+
+ return count;
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::IsMCMheaderOK()
+Int_t AliTRDrawStream::ReadTracklets()
{
- //
- // check the mcm header
- //
- if (fgLastROB != fMCM->fROB) {
- fgLastIndex = 0;
- if (fgLastROB== -1) fgLastROB = fMCM->fROB;
- }
- else {
- Int_t matchingcounter = 0;
- for (Int_t i=fgLastIndex+1; i<16; i++) {
- if ( fMCM->fMCM == fgMCMordering[i] ) {
- fgLastIndex = i;
- matchingcounter++;
- break;
- }
- }
- if (matchingcounter == 0) {
- fMCM->fMCMhdCorrupted += 2;
- AliDebug(11,Form("MCM number from last MCM is larger: MCM # from last MCM %d, MCM # from current MCM %d \n",(fMCM-1)->fMCM, fMCM->fMCM));
- }
- }
+ // read the tracklets from one HC
- if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) {
- if ( fMCM->fROB < (fMCM-1)->fROB ) {
- fMCM->fMCMhdCorrupted += 2;
- AliDebug(11,Form("ROB number from last MCM is larger: ROB # from last MCM %d, ROB # from current MCM %d \n",(fMCM-1)->fROB, fMCM->fROB));
- }
- else fgLastROB = fMCM->fROB;
- }
+ Int_t nTracklets = 0;
- fgLastHC = fHC->fLayer*2 + fHC->fSide;
-
- /*
- // this check will come back later again when we have "patched MCM map"
- int expectedROB = -1;
- if(!fHC->fSide) expectedROB = int(fHC->fMCMmax/16)*2;
- else expectedROB = int(fHC->fMCMmax/16)*2 + 1;
- int expectedMCM = 4*(3-int((fHC->fMCMmax%16)/4)) + fHC->fMCMmax%4;
-
- if ( expectedROB != fMCM->fROB || expectedMCM != fMCM->fMCM)
- {
- fMCM->fMCMhdCorrupted += 2;
- AliDebug(11,Form("ROB expected %d ROB read %d, MCM expected %d MCM read %d\n",expectedROB, fMCM->fROB, expectedMCM, fMCM->fMCM));
- }
- */
-
- // below two conditions are redundant
- /*
- if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 )
- {
- fMCM->fMCMhdCorrupted += 8; // need to assign new number
- if (fgDebugFlag) AliDebug(11,Form("ROB or MCM number is out of range. %s\n", DumpMCMinfo(fMCM)));
- }
- if (IsRowValid() == kFALSE)
- {
- fMCM->fMCMhdCorrupted += 16; // need to assign new number
- }
- */
-
- if (fEventCounter == 0) {
- fEventCounter = fMCM->fEvCounter;
- }
+ UInt_t *start = fPayloadCurr;
+ while (*(fPayloadCurr) != fgkTrackletEndmarker &&
+ *(fPayloadCurr) != fgkStackEndmarker[0] &&
+ *(fPayloadCurr) != fgkStackEndmarker[1] &&
+ fPayloadCurr - fPayloadStart < (fPayloadSize - 1)) {
+ ++nTracklets;
+ if (fTracklets)
+ new ((*fTracklets)[fTracklets->GetEntriesFast()]) AliTRDtrackletWord(*(fPayloadCurr), fCurrHC);
- if (fEventCounter != fMCM->fEvCounter) {
- fMCM->fMCMhdCorrupted += 4;
- if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n"
- , fMCM->fEvCounter, fEventCounter, DumpMCMinfo(fMCM)));
+ fPayloadCurr++;
}
- if (fEventCounter < fLastEventCounter) {
- fMCM->fMCMhdCorrupted += 8;
- if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));
+ if (nTracklets > 0) {
+ AliDebug(1, Form("Found %i tracklets in %i %i %i (ev. %i)", nTracklets,
+ (fCurrEquipmentId-kDDLOffset), fCurrSlot, fCurrLink, fRawReader->GetEventIndex()));
+ if (fCurrSm > -1 && fCurrSm < 18) {
+ fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fNTracklets += nTracklets;
+ fStats.fStatsSector[fCurrSm].fNTracklets += nTracklets;
+ }
}
- if ( fMCM->fADCmaskCorrupted > 0 )
- return kFALSE;
+ // loop over remaining tracklet endmarkers
+ while ((*(fPayloadCurr) == fgkTrackletEndmarker &&
+ fPayloadCurr - fPayloadStart < fPayloadSize))
+ fPayloadCurr++;
- if ( fMCM->fMCMhdCorrupted > 0 )
- return kFALSE;
+ return fPayloadCurr - start;
+}
- return kTRUE;
+Int_t AliTRDrawStream::ReadHcHeader()
+{
+ // read and parse the HC header of one HC
+ // and store the information in the corresponding variables
+
+ AliDebug(1, Form("HC header: 0x%08x", *fPayloadCurr));
+ UInt_t *start = fPayloadCurr;
+ // check not to be at the data endmarker
+ if (*fPayloadCurr == fgkDataEndmarker ||
+ *(fPayloadCurr) == fgkStackEndmarker[0] ||
+ *(fPayloadCurr) == fgkStackEndmarker[1]) {
+ LinkError(kHCmismatch, "found endmarker where HC header should be");
+ return 0;
+ }
+
+ fCurrSpecial = (*fPayloadCurr >> 31) & 0x1;
+ fCurrMajor = (*fPayloadCurr >> 24) & 0x7f;
+ fCurrMinor = (*fPayloadCurr >> 17) & 0x7f;
+ fCurrAddHcWords = (*fPayloadCurr >> 14) & 0x7;
+ fCurrSm = (*fPayloadCurr >> 9) & 0x1f;
+ fCurrLayer = (*fPayloadCurr >> 6) & 0x7;
+ fCurrStack = (*fPayloadCurr >> 3) & 0x7;
+ fCurrSide = (*fPayloadCurr >> 2) & 0x1;
+ fCurrCheck = (*fPayloadCurr) & 0x3;
+
+ if ((fCurrSm != (((Int_t) fCurrEquipmentId) - kDDLOffset)) ||
+ (fCurrStack != fCurrSlot) ||
+ (fCurrLayer != fCurrLink / 2) ||
+ (fCurrSide != fCurrLink % 2)) {
+ LinkError(kHCmismatch,
+ "HC: %i, %i, %i, %i\n 0x%08x 0x%08x 0x%08x 0x%08x",
+ fCurrSm, fCurrStack, fCurrLayer, fCurrSide,
+ fPayloadCurr[0], fPayloadCurr[1], fPayloadCurr[2], fPayloadCurr[3]);
+ }
+ if (fCurrCheck != 0x1) {
+ LinkError(kHCcheckFailed);
+ }
+
+ if (fCurrAddHcWords > 0) {
+ fCurrNtimebins = (fPayloadCurr[1] >> 26) & 0x3f;
+#ifdef TRD_RAW_DEBUG
+ fCurrBC[fCurrHC] = (fPayloadCurr[1] >> 10) & 0xffff;
+#endif
+ fCurrPtrgCnt = (fPayloadCurr[1] >> 6) & 0xf;
+ fCurrPtrgPhase = (fPayloadCurr[1] >> 2) & 0xf;
+ }
+
+ fPayloadCurr += 1 + fCurrAddHcWords;
+
+ return (fPayloadCurr - start);
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeMCMheader()
+Int_t AliTRDrawStream::ReadTPData(Int_t mode)
{
- //
- // decode the mcm header
- //
- DecodeMCMheader(fpPos, fMCM);
-
- if (fgDumpingEnable) {
- if (fMCM->fMCM == fgDumpingMCM) {
- if (fMCM->fROB == fgDumpingROB && fHC->fLayer == fgDumpingLayer) {
- if (fHC->fSM == fgDumpingSM && fHC->fStack == fgDumpingStack) {
- if (fgDebugFlag) {
- AliDebug(5,DumpHCinfoH0(fHC));
- AliDebug(5,DumpMCMinfo(fMCM));
- }
- DumpWords(fpPos, 212);
- }
- }
+ // testing of testpattern 1 to 3 (hardcoded), 0 missing
+ // evcnt checking missing
+ Int_t cpu = 0;
+ Int_t cpufromchannel[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3};
+ Int_t evno = -1;
+ Int_t evcnt = 0;
+ Int_t count = 0;
+ Int_t mcmcount = -1;
+ Int_t wordcount = 0;
+ Int_t channelcount = 0;
+ UInt_t expword = 0;
+ UInt_t expadcval = 0;
+ UInt_t diff = 0;
+ Int_t lastmcmpos = -1;
+ Int_t lastrobpos = -1;
+
+ UInt_t* start = fPayloadCurr;
+
+ while (*(fPayloadCurr) != fgkDataEndmarker &&
+ fPayloadCurr - fPayloadStart < fPayloadSize - 1) {
+
+ // ----- Checking MCM Header -----
+ AliDebug(2, DumpMcmHeader("MCM header: ", *fPayloadCurr));
+ UInt_t *startPosMCM = fPayloadCurr;
+ mcmcount++;
+
+ // ----- checking for proper readout order - ROB -----
+ fCurrRobPos = ROB(*fPayloadCurr);
+ if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) >= lastrobpos) {
+ if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) > lastrobpos)
+ lastmcmpos = -1;
+ lastrobpos = GetROBReadoutPos(ROB(*fPayloadCurr) / 2);
+ }
+ else {
+ ROBError(kPosUnexp, Form("#%i after #%i in readout order", GetROBReadoutPos(ROB(*fPayloadCurr) / 2), lastrobpos));
}
- }
- if (fHC->fCorrupted >= 16) {
- fpPos--;
- return kFALSE;
- }
+ // ----- checking for proper readout order - MCM -----
+ fCurrMcmPos = MCM(*fPayloadCurr);
+ if (GetMCMReadoutPos(MCM(*fPayloadCurr)) > lastmcmpos) {
+ lastmcmpos = GetMCMReadoutPos(MCM(*fPayloadCurr));
+ }
+ else {
+ MCMError(kPosUnexp, Form("#%i after #%i in readout order", GetMCMReadoutPos(MCM(*fPayloadCurr)), lastmcmpos));
+ }
+
+ if (EvNo(*fPayloadCurr) != (evno & 0xfffff)) {
+ if (evno == -1) {
+ evno = EvNo(*fPayloadCurr);
+ }
+ else {
+ MCMError(kEvCntMismatch, "%i <-> %i", evno, EvNo(*fPayloadCurr));
+#ifdef TRD_RAW_DEBUG
+ if (fCurrL0offset[fCurrHC/2] != 0)
+ LinkError(kEvCntMismatch, "offset for %i %i %i changed from %i to %i = %i - %i",
+ fCurrEquipmentId, fCurrSlot, fCurrLink/2, fCurrL0offset[fCurrHC/2],
+ EvNo(*fPayloadCurr) - fCurrL0Count[fCurrEquipmentId-kDDLOffset],
+ EvNo(*fPayloadCurr), fCurrL0Count[fCurrEquipmentId-kDDLOffset]);
+ fCurrL0offset[fCurrHC/2] = EvNo(*fPayloadCurr) - fCurrL0Count[fCurrEquipmentId-kDDLOffset];
+ evno = fCurrL0Count[fCurrEquipmentId-kDDLOffset] + fCurrL0offset[fCurrHC/2];
+#endif
+ }
+ }
- fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
+ fPayloadCurr++;
+
+ evcnt = 0x3f & *fPayloadCurr >> 26;
+ cpu = -1;
+ channelcount = 0;
+ while (channelcount < 21) {
+ count = 0;
+ if (cpu != cpufromchannel[channelcount]) {
+ cpu = cpufromchannel[channelcount];
+ expadcval = (1 << 9) | (fCurrRobPos << 6) | (fCurrMcmPos << 2) | cpu;
+ wordcount = 0;
+ }
- if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || ((fHC->fRawVMajor & 32) == 32)) { //cover old and new version definition of ZS data
- fpPos++;
- if ( fpPos < fpEnd ) {
- DecodeMask(fpPos, fMCM);
- if (fHC->fCorrupted >= 16) {
- fpPos--;
- return kFALSE;
+ while (count < 10) {
+ if (*fPayloadCurr == fgkDataEndmarker) {
+ MCMError(kMissTpData);
+ return (fPayloadCurr - start);
+ }
+
+ if (channelcount % 2 == 0)
+ expword = 0x3;
+ else
+ expword = 0x2;
+
+ if (mode == 1) {
+ // ----- TP 1 -----
+ expword |= expadcval << 2;
+ expadcval = ( (expadcval << 1) | ( ( (expadcval >> 9) ^ (expadcval >> 6) ) & 1) ) & 0x3FF;
+ expword |= expadcval << 12;
+ expadcval = ( (expadcval << 1) | ( ( (expadcval >> 9) ^ (expadcval >> 6) ) & 1) ) & 0x3FF;
+ expword |= expadcval << 22;
+ expadcval = ( (expadcval << 1) | ( ( (expadcval >> 9) ^ (expadcval >> 6) ) & 1) ) & 0x3FF;
+ }
+ else if (mode == 2) {
+ // ----- TP 2 ------
+ expword = ((0x3f & evcnt) << 26) | ((fCurrSm + 1) << 21) | ((fCurrLayer + 1) << 18) |
+ ((fCurrStack + 1) << 15) |
+ (fCurrRobPos << 12) | (fCurrMcmPos << 8) | (cpu << 6) | (wordcount + 1);
+ }
+ else if (mode == 3) {
+ // ----- TP 3 -----
+ expword = ((0xfff & evcnt) << 20) | (fCurrSm << 15) | (fCurrLink/2 << 12) | (fCurrStack << 9) |
+ (fCurrRobPos << 6) | (fCurrMcmPos << 2) | (cpu << 0);
+ }
+ else {
+ expword = 0;
+ LinkError(kTPmodeInvalid, "Just reading");
+ }
+
+ diff = *fPayloadCurr ^ expword;
+ AliDebug(11, Form("Comparing ch %2i, word %2i (cpu %i): 0x%08x <-> 0x%08x",
+ channelcount, wordcount, cpu, *fPayloadCurr, expword));
+
+ if (diff != 0) {
+ MCMError(kTPmismatch,
+ "Seen 0x%08x, expected 0x%08x, diff: 0x%08x, 0x%04x, 0x%02x - word %2i (cpu %i, ch %i)",
+ *fPayloadCurr, expword, diff,
+ 0xffff & (diff | diff >> 16),
+ 0xff & (diff | diff >> 8 | diff >> 16 | diff >> 24),
+ wordcount, cpu, channelcount);;
+ }
+ fPayloadCurr++;
+ count++;
+ wordcount++;
+ if (*fPayloadCurr == fgkDataEndmarker)
+ return (fPayloadCurr - start);
}
- MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
- fMCM->fAdcDataPos = fpPos + 1;
+ channelcount++;
}
- else {
- if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
- fHC->fCorrupted += 32;
- return kFALSE;
+ // continue with next MCM
+
+ if (IsDumping() && DumpingMCM(fCurrHC/2, fCurrRobPos, fCurrMcmPos)) {
+ AliInfo(DumpRaw(Form("Event %i: Det %3i ROB %i MCM %2i", fRawReader->GetEventIndex(), fCurrHC/2, fCurrRobPos, fCurrMcmPos),
+ startPosMCM, fPayloadCurr - startPosMCM));
}
- }
- else {
- UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
- DecodeMask(&dummyMask, fMCM);
- MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
- fMCM->fAdcDataPos = fpPos + 1;
- }
- if (fgDebugFlag) {
- AliDebug(6, DumpMCMinfo(fMCM));
- AliDebug(7, DumpMCMadcMask(fMCM));
}
-
- if (IsMCMheaderOK() == kFALSE)
- return kFALSE;
-
- return kTRUE;
+ return fPayloadCurr - start;
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::IsHCheaderOK()
+
+Int_t AliTRDrawStream::ReadZSData()
{
- //
- // check insanity of half chamber header
- //
- if (fHC->fStack < 0 || fHC->fStack > 4) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStack));
- return kFALSE;
- }
+ // read the zs data from one link from the current reading position
+
+ UInt_t *start = fPayloadCurr;
+
+ Int_t mcmcount = 0;
+ Int_t mcmcountExp = fCurrStack == 2 ? 48 : 64;
+ Int_t channelcount = 0;
+ Int_t channelcountExp = 0;
+ Int_t channelcountMax = 0;
+ Int_t timebins;
+ Int_t currentTimebin = 0;
+ Int_t adcwc = 0;
+ Int_t evno = -1;
+ Int_t lastmcmpos = -1;
+ Int_t lastrobpos = -1;
+
+ if (fCurrNtimebins != fNtimebins) {
+ if (fNtimebins > 0)
+ LinkError(kNtimebinsChanged,
+ "No. of timebins changed from %i to %i", fNtimebins, fCurrNtimebins);
+ fNtimebins = fCurrNtimebins;
+ }
+
+ timebins = fNtimebins;
+
+ while (*(fPayloadCurr) != fgkDataEndmarker &&
+ *(fPayloadCurr) != fgkStackEndmarker[0] &&
+ *(fPayloadCurr) != fgkStackEndmarker[1] &&
+ fPayloadCurr - fPayloadStart < fPayloadSize) {
+
+ // ----- Checking MCM Header -----
+ AliDebug(2, DumpMcmHeader("MCM header: ", *fPayloadCurr));
+ UInt_t *startPosMCM = fPayloadCurr;
+
+ // ----- checking for proper readout order - ROB -----
+ fCurrRobPos = ROB(*fPayloadCurr);
+ if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) >= lastrobpos) {
+ if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) > lastrobpos)
+ lastmcmpos = -1;
+ lastrobpos = GetROBReadoutPos(ROB(*fPayloadCurr) / 2);
+ }
+ else {
+ ROBError(kPosUnexp, Form("#%i after #%i and #%i in readout order",
+ GetROBReadoutPos(ROB(*fPayloadCurr) / 2), lastrobpos, GetROBReadoutPos(fCurrRobPos)));
+ }
- if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayer));
- return kFALSE;
- }
+ // ----- checking for proper readout order - MCM -----
+ fCurrMcmPos = MCM(*fPayloadCurr);
+ if (GetMCMReadoutPos(MCM(*fPayloadCurr)) > lastmcmpos) {
+ lastmcmpos = GetMCMReadoutPos(MCM(*fPayloadCurr));
+ }
+ else {
+ MCMError(kPosUnexp, Form("#%i after #%i and #%i in readout order",
+ GetMCMReadoutPos(MCM(*fPayloadCurr)), lastmcmpos, GetMCMReadoutPos(fCurrMcmPos)));
+ }
- if (fHC->fSide < 0 || fHC->fSide > 1) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSide));
- return kFALSE;
- }
+#ifdef TRD_RAW_DEBUG
+ if (fCurrL0Count[fCurrEquipmentId-kDDLOffset] > 0) {
+ evno = fCurrL0Count[fCurrEquipmentId-kDDLOffset] + fCurrL0offset[fCurrHC/2];
+ }
+ fCurrEvCount[fCurrEquipmentId-kDDLOffset] = EvNo(*fPayloadCurr);
+#endif
- if (fgStackNumberChecker) {
- if (fHC->fStack != fStackNumber) {
- if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",
- fHC->fStack, fStackNumber));
- fStackNumber = -1;
- return kFALSE;
+ if (EvNo(*fPayloadCurr) != (evno & 0xfffff)) {
+ if (evno == -1) {
+ evno = EvNo(*fPayloadCurr);
+ }
+ else {
+ MCMError(kEvCntMismatch, "exp <-> SM: %i <-> %i", evno & 0xfffff, EvNo(*fPayloadCurr));
+#ifdef TRD_RAW_DEBUG
+ Int_t prevOffset = fCurrL0offset[fCurrHC/2];
+ fCurrL0offset[fCurrHC/2] = (- fCurrL0Count[fCurrEquipmentId-kDDLOffset] + EvNo(*fPayloadCurr)) % (1 << 20);
+ if (fCurrL0offset[fCurrHC/2] < 0)
+ fCurrL0offset[fCurrHC/2] += 0xfffff;
+ evno = (fCurrL0Count[fCurrEquipmentId-kDDLOffset] + fCurrL0offset[fCurrHC/2]) & 0xfffff;
+ if (prevOffset != 0)
+ LinkError(kEvCntMismatch, "offset for %i %i %i changed from %i to %i = %i - %i",
+ fCurrEquipmentId, fCurrSlot, fCurrLink/2,
+ prevOffset,
+ fCurrL0offset[fCurrHC/2],
+ fCurrL0Count[fCurrEquipmentId-kDDLOffset],
+ EvNo(*fPayloadCurr));
+#endif
+ }
}
- }
+ Int_t adccoloff = AdcColOffset(*fPayloadCurr);
+ Int_t padcoloff = PadColOffset(*fPayloadCurr);
+ Int_t row = Row(*fPayloadCurr);
+ fPayloadCurr++;
- if (fgStackLinkNumberChecker) {
- if (fHC->fLayer * 2 + fHC->fSide != fStackLinkNumber) {
- // let it make flexible to consider known fiber swapping
- //if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1)) {
- if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",
- fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));
- fStackLinkNumber = -1;
- return kFALSE;
+ if ((row > 11) && (fCurrStack == 2)) {
+ MCMError(kInvalidPadRow, "Data in padrow > 11 for stack 2");
}
- }
- // SLOW GEOM : consistancy check with geometry
- fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
- if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");
- return kFALSE;
- }
+ if (fErrorFlags & (kDiscardHC | kDiscardDDL))
+ break;
+
+ // ----- Reading ADC channels -----
+ AliDebug(2, DumpAdcMask("ADC mask: ", *fPayloadCurr));
+
+ // ----- analysing the ADC mask -----
+ channelcount = 0;
+ channelcountExp = GetNActiveChannelsFromMask(*fPayloadCurr);
+ channelcountMax = GetNActiveChannels(*fPayloadCurr);
+ Int_t channelmask = GetActiveChannels(*fPayloadCurr);
+ Int_t channelno = -1;
+ fPayloadCurr++;
+
+ if (channelcountExp != channelcountMax) {
+ if (channelcountExp > channelcountMax) {
+ Int_t temp = channelcountExp;
+ channelcountExp = channelcountMax;
+ channelcountMax = temp;
+ }
+ while (channelcountExp < channelcountMax && channelcountExp < 21 &&
+ fPayloadCurr - fPayloadStart < fPayloadSize - 10 * channelcountExp - 1) {
+ MCMError(kAdcMaskInconsistent,
+ "Possible MCM-H: 0x%08x, possible ADC-mask: 0x%08x",
+ *(fPayloadCurr + 10 * channelcountExp),
+ *(fPayloadCurr + 10 * channelcountExp + 1) );
+ if (!CouldBeMCMhdr( *(fPayloadCurr + 10 * channelcountExp)) && !CouldBeADCmask( *(fPayloadCurr + 10 * channelcountExp + 1)))
+ channelcountExp++;
+ else {
+ break;
+ }
+ }
+ MCMError(kAdcMaskInconsistent,
+ "Inconsistency in no. of active channels: Counter: %i, Mask: %i, chosen: %i!",
+ GetNActiveChannels(fPayloadCurr[-1]), GetNActiveChannelsFromMask(fPayloadCurr[-1]), channelcountExp);
+ }
+ AliDebug(2, Form("expecting %i active channels, %i timebins", channelcountExp, fCurrNtimebins));
+
+ // ----- reading marked ADC channels -----
+ while (channelcount < channelcountExp && *(fPayloadCurr) != fgkDataEndmarker) {
+ if (channelno < 20)
+ channelno++;
+ while (channelno < 20 && (channelmask & 1 << channelno) == 0)
+ channelno++;
+
+ if (fCurrNtimebins > 30) {
+ currentTimebin = ((*fPayloadCurr >> 2) & 0x3f);
+ timebins = ((*fPayloadCurr >> 8) & 0xf) * 3;
+ }
+ else {
+ currentTimebin = 0;
+ }
- if (fHC->fSM != fGeometry->GetSector(fHC->fDET) || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",
- fHC->fSM, fGeometry->GetSector(fHC->fDET), fHC->fStack, fHC->fLayer, fHC->fDET));
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");
- return kFALSE;
- }
+ adcwc = 0;
+ Int_t nADCwords = (timebins + 2) / 3;
+ AliDebug(3, Form("Now reading %i words for channel %2i", nADCwords, channelno));
+ Int_t adccol = adccoloff - channelno;
+ Int_t padcol = padcoloff - channelno;
+// if (adccol < 3 || adccol > 165)
+// AliInfo(Form("writing channel %i of det %3i %i:%2i to adcrow/-col: %i/%i padcol: %i",
+// channelno, fCurrHC/2, fCurrRobPos, fCurrMcmPos, row, adccol, padcol));
+
+ while ((adcwc < nADCwords) &&
+ (*(fPayloadCurr) != fgkDataEndmarker) &&
+ (fPayloadCurr - fPayloadStart < fPayloadSize)) {
+ int check = 0x3 & *fPayloadCurr;
+ if (channelno % 2 != 0) { // odd channel
+ if (check != 0x2 && channelno < 21) {
+ MCMError(kAdcCheckInvalid,
+ "%i for %2i. ADC word in odd channel %i",
+ check, adcwc+1, channelno);
+ }
+ }
+ else { // even channel
+ if (check != 0x3 && channelno < 21) {
+ MCMError(kAdcCheckInvalid,
+ "%i for %2i. ADC word in even channel %i",
+ check, adcwc+1, channelno);
+ }
+ }
+
+ if ((fErrorFlags & kDiscardMCM) == 0) {
+ // filling the actual timebin data
+ int tb2 = 0x3ff & (*fPayloadCurr >> 22);
+ int tb1 = 0x3ff & (*fPayloadCurr >> 12);
+ int tb0 = 0x3ff & (*fPayloadCurr >> 2);
+ if (adcwc != 0 || fCurrNtimebins <= 30)
+ fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb0);
+ else
+ tb0 = -1;
+ if (currentTimebin < fCurrNtimebins)
+ fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb1);
+ if (currentTimebin < fCurrNtimebins)
+ fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb2);
+ }
+
+ adcwc++;
+ fPayloadCurr++;
+ }
- fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
- if (fHC->fROC < 0) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
- return kFALSE;
- }
+ if (adcwc != nADCwords)
+ MCMError(kAdcDataAbort);
- fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
- if (fHC->fRowMax < 1) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
- return kFALSE;
- }
+ // adding index
+ if (padcol > 0 && padcol < 144) {
+ fSignalIndex->AddIndexRC(row, padcol);
+ }
- fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
- if (fHC->fColMax < 1) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
- return kFALSE;
- }
-
- return kTRUE;
-}
+ channelcount++;
+ }
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeHCheader()
-{
- //
- // decode the half chamber header
- //
- if (DecodeHCwordH0(fpPos, fHC) == kFALSE)
- return kFALSE;
-
- if (fHC->fNExtraWords > 0) {
- fpPos++;
- if (fpPos < fpEnd) {
- if (DecodeHCwordH1(fpPos, fHC) == kFALSE)
- return kFALSE;
+ if (fCurrSm > -1 && fCurrSm < 18) {
+ fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fNChannels += channelcount;
+ fStats.fStatsSector[fCurrSm].fNChannels += channelcount;
}
- else {
- if (fgDebugFlag) AliDebug(11,"Expected HC header word 1. Fail due to buffer END.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing");
- return kFALSE;
+ if (channelcount != channelcountExp)
+ MCMError(kAdcChannelsMiss);
+
+ mcmcount++;
+ if (fCurrSm > -1 && fCurrSm < 18) {
+ fStats.fStatsSector[fCurrSm].fStatsHC[fCurrHC%60].fNMCMs++;
+ fStats.fStatsSector[fCurrSm].fNMCMs++;
}
- }
- if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
- if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
+ if (IsDumping() && DumpingMCM(fCurrHC/2, fCurrRobPos, fCurrMcmPos)) {
+ AliInfo(DumpRaw(Form("Event %i: Det %3i ROB %i MCM %2i", fRawReader->GetEventIndex(), fCurrHC/2, fCurrRobPos, fCurrMcmPos),
+ startPosMCM, fPayloadCurr - startPosMCM));
+ }
- fHC->fDET = -1;
- if (IsHCheaderOK() == kFALSE) {
- fHC->fH0Corrupted += 2;
- if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
- return kFALSE;
+ // continue with next MCM
}
-
- return kTRUE;
+
+ // check for missing MCMs (if header suppression is inactive)
+ if (((fCurrMajor & 0x1) == 0) && (mcmcount != mcmcountExp)) {
+ LinkError(kMissMcmHeaders,
+ "No. of MCM headers %i not as expected: %i",
+ mcmcount, mcmcountExp);
+ }
+
+ return (fPayloadCurr - start);
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeHC()
+Int_t AliTRDrawStream::ReadNonZSData()
{
- //
- // decode hc header and data
- //
- if (DecodeHCheader() == kFALSE) {
- if (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted");
- return kFALSE;
- }
- else {
- fpPos++;
- if (fpPos >= fpEnd) {
- fHC->fCorrupted += 1;
- if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing");
- return kFALSE;
+ // read the non-zs data from one link from the current reading position
+
+ UInt_t *start = fPayloadCurr;
+
+ Int_t mcmcount = 0;
+ Int_t mcmcountExp = fCurrStack == 2 ? 48 : 64;
+ Int_t channelcount = 0;
+ Int_t channelcountExp = 0;
+ Int_t timebins;
+ Int_t currentTimebin = 0;
+ Int_t adcwc = 0;
+ Int_t evno = -1;
+ Int_t lastmcmpos = -1;
+ Int_t lastrobpos = -1;
+
+ if (fCurrNtimebins != fNtimebins) {
+ if (fNtimebins > 0)
+ LinkError(kNtimebinsChanged,
+ "No. of timebins changed from %i to %i", fNtimebins, fCurrNtimebins);
+ fNtimebins = fCurrNtimebins;
+ }
+
+ timebins = fNtimebins;
+
+ while (*(fPayloadCurr) != fgkDataEndmarker &&
+ fPayloadCurr - fPayloadStart < fPayloadSize - 2) {
+
+ // ----- Checking MCM Header -----
+ AliDebug(2, Form("MCM header: 0x%08x", *fPayloadCurr));
+
+ // ----- checking for proper readout order - ROB -----
+ fCurrRobPos = ROB(*fPayloadCurr);
+ if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) >= lastrobpos) {
+ if (GetROBReadoutPos(ROB(*fPayloadCurr) / 2) > lastrobpos)
+ lastmcmpos = -1;
+ lastrobpos = GetROBReadoutPos(ROB(*fPayloadCurr) / 2);
+ }
+ else {
+ ROBError(kPosUnexp, Form("#%i after #%i in readout order", GetROBReadoutPos(ROB(*fPayloadCurr) / 2), lastrobpos));
}
- }
- if ((fHC->fRawVMajor & 64) == 64) { // test pattern data
- AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);
- if (tpStream->DecodeTPdata() == kFALSE) {
- if (fgWarnError) AliError("failed to decode test pattern data");
- return kFALSE;
+ // ----- checking for proper readout order - MCM -----
+ fCurrMcmPos = MCM(*fPayloadCurr);
+ if (GetMCMReadoutPos(MCM(*fPayloadCurr)) > lastmcmpos) {
+ lastmcmpos = GetMCMReadoutPos(MCM(*fPayloadCurr));
}
- return kTRUE;
- }
-
- fHC->fMCMmax = 0;
- while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) {
- if (fHC->fMCMmax > TRDMAXMCM) {
- fHC->fCorrupted += 2;
- if (fgDebugFlag) AliDebug(11,"More mcm data than expected!");
- if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!");
- return kFALSE;
- }
-
- fMCM = &fHC->fMCMs[fHC->fMCMmax];
-
- if (DecodeMCMheader() == kFALSE) {
- if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
-
- if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) { // stop HC data reading
- fHC->fMCMmax++;
- return kFALSE;
- }
-
- fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number
-
- // in case we decide to keep reading data, skip this mcm data and find next mcm header
- if (fMCM->fADCmaskCorrupted < 2) {
- if (SkipMCMdata(fMCM->fADCcount*fMCM->fSingleADCwords) == kFALSE)
- return kFALSE;
- continue;
+ else {
+ MCMError(kPosUnexp, Form("#%i after #%i in readout order", GetMCMReadoutPos(MCM(*fPayloadCurr)), lastmcmpos));
+ }
+
+ if (EvNo(*fPayloadCurr) != (evno & 0xfffff)) {
+ if (evno == -1) {
+ evno = EvNo(*fPayloadCurr);
}
else {
- if (SeekNextMCMheader() == kFALSE)
- return kFALSE;
- continue;
+ MCMError(kEvCntMismatch, "%i <-> %i", evno, EvNo(*fPayloadCurr));
+#ifdef TRD_RAW_DEBUG
+ if (fCurrL0offset[fCurrHC/2] != 0)
+ LinkError(kEvCntMismatch, "offset for %i %i %i changed from %i to %i = %i - %i",
+ fCurrEquipmentId, fCurrSlot, fCurrLink/2, fCurrL0offset[fCurrHC/2],
+ EvNo(*fPayloadCurr) - fCurrL0Count[fCurrEquipmentId-kDDLOffset],
+ EvNo(*fPayloadCurr), fCurrL0Count[fCurrEquipmentId-kDDLOffset]);
+ fCurrL0offset[fCurrHC/2] = EvNo(*fPayloadCurr) - fCurrL0Count[fCurrEquipmentId-kDDLOffset];
+ evno = fCurrL0Count[fCurrEquipmentId-kDDLOffset] + fCurrL0offset[fCurrHC/2];
+#endif
}
}
- fHC->fMCMmax++;
+ channelcount = 0;
+ channelcountExp = 21;
+ int channelno = -1;
+
+ Int_t adccoloff = AdcColOffset(*fPayloadCurr);
+ Int_t padcoloff = PadColOffset(*fPayloadCurr);
+ Int_t row = Row(*fPayloadCurr);
+ fPayloadCurr++;
+
+ if ((row > 11) && (fCurrStack == 2)) {
+ MCMError(kInvalidPadRow, "Data in padrow > 11 for stack 2");
+ }
+
+ if (fErrorFlags & (kDiscardHC | kDiscardDDL))
+ break;
+
+ // ----- reading marked ADC channels -----
+ while (channelcount < channelcountExp &&
+ *(fPayloadCurr) != fgkDataEndmarker) {
+ if (channelno < 20)
+ channelno++;
+
+ currentTimebin = 0;
+
+ adcwc = 0;
+ Int_t nADCwords = (timebins + 2) / 3;
+ AliDebug(2, Form("Now looking %i words", nADCwords));
+ Int_t adccol = adccoloff - channelno;
+ Int_t padcol = padcoloff - channelno;
+ while ((adcwc < nADCwords) &&
+ (*(fPayloadCurr) != fgkDataEndmarker) &&
+ (fPayloadCurr - fPayloadStart < fPayloadSize)) {
+ int check = 0x3 & *fPayloadCurr;
+ if (channelno % 2 != 0) { // odd channel
+ if (check != 0x2 && channelno < 21) {
+ MCMError(kAdcCheckInvalid,
+ "%i for %2i. ADC word in odd channel %i",
+ check, adcwc+1, channelno);
+ }
+ }
+ else { // even channel
+ if (check != 0x3 && channelno < 21) {
+ MCMError(kAdcCheckInvalid,
+ "%i for %2i. ADC word in even channel %i",
+ check, adcwc+1, channelno);
+ }
+ }
+
+ if ((fErrorFlags & kDiscardMCM) == 0) {
+ // filling the actual timebin data
+ int tb2 = 0x3ff & (*fPayloadCurr >> 22);
+ int tb1 = 0x3ff & (*fPayloadCurr >> 12);
+ int tb0 = 0x3ff & (*fPayloadCurr >> 2);
+ if (adcwc != 0 || fCurrNtimebins <= 30)
+ fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb0);
+ else
+ tb0 = -1;
+ if (currentTimebin < fCurrNtimebins)
+ fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb1);
+ if (currentTimebin < fCurrNtimebins)
+ fAdcArray->SetDataByAdcCol(row, adccol, currentTimebin++, tb2);
+ }
+
+ adcwc++;
+ fPayloadCurr++;
+ }
+
+ if (adcwc != nADCwords)
+ MCMError(kAdcDataAbort);
- if (fMCM->fADCmax > 0) {
- fpPos++;
- if (fpPos >= fpEnd) {
- fMCM->fCorrupted += 1;
- if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
- if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected."));
- return kFALSE;
+ // adding index
+ if (padcol > 0 && padcol < 144) {
+ fSignalIndex->AddIndexRC(row, padcol);
}
- for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++) {
- fADC = &fMCM->fADCs[iadc];
- fADC->fADCnumber = fMCM->fADCchannel[iadc];
- if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.",
- iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));
- if (fpPos + fMCM->fSingleADCwords >= fpEnd) {
- fMCM->fCorrupted += 2;
- if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
- if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");
- return kFALSE;
- }
-
- if (fHC->fRawVMajor < 64) { // normal(real) ADC data
- if (fHC->fTimeBins < 31) {
- if (DecodeADC() == kFALSE) {
- if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4
- if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
- if (fADC->fIsShared && fADC->fCorrupted == 32) { // check if we are out of the det when the pad is shared
- fADC->fExtendedCOL = -1;
- fADC->fCOL = -1;
- fpPos = fADC->fPos + fMCM->fSingleADCwords;
- }
- else {
- if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));
- if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
- return kFALSE; // stop HC data reading
- }
- }
- }
- else if (fHC->fTimeBins > 32) {
- if (DecodeADCExtended() == kFALSE) { // decoding TRAP data with ZS and more than 32 samples
- if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4
- if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4
- if (fADC->fIsShared && fADC->fCorrupted == 32) { // check if we are out of the det when the pad is shared
- fADC->fExtendedCOL = -1;
- fADC->fCOL = -1;
- fpPos = fADC->fPos + fMCM->fSingleADCwords;
- }
- else {
- if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));
- if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)
- return kFALSE; // stop HC data reading
- }
- }
- }
- else { // nsamples = 31, 32 are not implemented in the TRAP and should never happen
- if (fgWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!");
- }
- } // if fHC->fRawVMajor
- else { // test pattern data
- if (fgWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class
- }
- } // for iadc
- } // if fMCM->fADCmax
- else {
- fpPos++;
+ channelcount++;
}
- }//while eof data
- if (fpPos >= fpEnd) {
- if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. There should be one more word left.");
- return kFALSE;
+ if (channelcount != channelcountExp)
+ MCMError(kAdcChannelsMiss);
+ mcmcount++;
+ // continue with next MCM
}
- return kTRUE;
+ // check for missing MCMs (if header suppression is inactive)
+ if (mcmcount != mcmcountExp) {
+ LinkError(kMissMcmHeaders,
+ "%i not as expected: %i", mcmcount, mcmcountExp);
+ }
+
+ return (fPayloadCurr - start);
}
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeADC()
+#ifdef TRD_RAW_CRC
+UShort_t AliTRDrawStream::CalcLinkChecksum(UInt_t *data, Int_t size)
{
- //
- // decode single ADC channel
- //
-
- UInt_t commonAdditive = AliTRDrawStreamBase::fgCommonAdditive;
-
- fADC->fCorrupted = 0;
- if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
- if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
-
- fADC->fPos = fpPos;
- fTbinADC = 0;
-
- for (Int_t i = 0; i < GetNumberOfTimeBins(); i++)
- //for (Int_t i = 0; i < TRDMAXTBINS; i++)
- fADC->fSignals[i] = 0;
-
- for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++) {
- if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
- if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
- fADC->fCorrupted += 16;
- fHC->fCorrupted += 16;
- fpPos--;
- return kFALSE;
- }
- if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
- fADC->fCorrupted += 1;
- if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d",
- fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));
- fpPos++;
- continue;
- }
-
- // here we subtract the baseline ( == common additive)
- fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - commonAdditive;
- fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive;
- fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive;
-
- fTbinADC += 3;
- fpPos++;
- } // iw
-
- if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {
- fADC->fIsShared = kTRUE;
- }
- else {
- fADC->fIsShared = kFALSE;
- }
+ // calculate the CRC for the data from this link
+ // must not change the pointers to the data
- fADC->fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
- fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
-
- if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) {
- if (fADC->fIsShared == kFALSE) {
- fADC->fCorrupted += 32;
- if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
- fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
- }
- //else {
- // we are out of the det when the pad is shared
- //if (fgDebugFlag) AliDebug(11, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
- // fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
- //fADC->fCorrupted += 32;
- //}
+ // always count two endmarkers
+ Int_t nEndmarkers = 0;
+ for (Int_t i = 0; i < size; i++) {
+ if (data[size-1 - i] != fgkDataEndmarker)
+ break;
+ nEndmarkers++;
}
- if (fADC->fCorrupted > 0) {
- return kFALSE;
- }
+ size = size - (nEndmarkers-2);
- fDecodedADCs++;
+ boost::crc_optimal<16, 0x8005, 0, 0, false, false> checksumLink;
- return kTRUE;
+ checksumLink.reset();
+ checksumLink.process_bytes(data, size*sizeof(UInt_t));
+ return checksumLink();
+}
+#else
+UShort_t AliTRDrawStream::CalcLinkChecksum(UInt_t * /* data */, Int_t /* size */)
+{
+ // checksum calculation relies on boost,
+ // we return 0 if we cannot calculate it
+
+ AliError("Checksum calculation relies on boost CRC implementation!");
+
+ return 0;
}
+#endif
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeADCExtended()
+Int_t AliTRDrawStream::SeekNextStack()
{
- //
- // decode single ADC channel
- //
-
- UInt_t commonAdditive = AliTRDrawStreamBase::fgCommonAdditive;
-
- fADC->fCorrupted = 0;
- if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
- if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
-
- fADC->fPos = fpPos;
-
- fTbinADC = ((*fpPos & 0x000000fc) >> 2);
- fMCM->fSingleADCwords = ((*fpPos & 0x00000f00) >> 8);
- fADC->fSignals[fTbinADC] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive;
- fADC->fSignals[fTbinADC+1] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive;
-
- fpPos++;
- for (Int_t iw = 0; iw < fMCM->fSingleADCwords-1; iw++) { // it goes up to fMCM->fSingleADCwords-1 since the first word was already decoded above
- if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
- if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
- fADC->fCorrupted += 16;
- fHC->fCorrupted += 16;
- fpPos--;
- return kFALSE;
- }
- if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
- fADC->fCorrupted += 1;
- if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d",
- fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));
- fpPos++;
- continue;
- }
-
- // here we subtract the baseline ( == common additive)
- fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0x00000ffc) >> 2) - commonAdditive;
- fADC->fSignals[fTbinADC + 3] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive;
- fADC->fSignals[fTbinADC + 4] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive;
-
- fTbinADC += 3;
- fpPos++;
- } // iw
-
-// for(int i=0; i )
-// printf();
-
-
- if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {
- fADC->fIsShared = kTRUE;
- }
- else {
- fADC->fIsShared = kFALSE;
- }
+ // proceed in raw data stream till the next stack
- fADC->fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
- fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);
+ if (!fCurrStackEndmarkerAvail)
+ return 0;
- if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) {
- if (fADC->fIsShared == kFALSE) {
- fADC->fCorrupted += 32;
- if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s",
- fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));
- }
- }
+ UInt_t *start = fPayloadCurr;
- if (fADC->fCorrupted > 0) {
- return kFALSE;
- }
+ // read until data endmarkers
+ while ((fPayloadCurr - fPayloadStart < fPayloadSize-1) &&
+ ((fPayloadCurr[0] != fgkStackEndmarker[0]) ||
+ (fPayloadCurr[1] != fgkStackEndmarker[1])))
+ fPayloadCurr++;
- fDecodedADCs++;
+ if ((fPayloadCurr - start) != 0)
+ StackError(kUnknown, "skipped %i words to reach stack endmarker", fPayloadCurr - start);
- return kTRUE;
-}
+ AliDebug(2, Form("stack endmarker: 0x%08x 0x%08x", fPayloadCurr[0], fPayloadCurr[1]));
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const
-{
- //
- // Decode Supermodule Index Word
- // The Supermodule Index Word is a 32-Bit word wit following structure
- // ssssssss ssssssss vvvv rrrr r d t mmmm
- // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use
- // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask
- //
- sm->fPos = (UInt_t*)word;
-
- UInt_t vword = *word;
- sm->fHeaderSize = SM_HEADER_SIZE(vword);
-
- if (TRACKLETS_ENABLED(vword) > 0)
- sm->fTrackletEnable = kTRUE;
- else
- sm->fTrackletEnable = kFALSE;
-
- UInt_t stackMask = STACK_MASK(vword);
- sm->fActiveStacks = 0;
- for (Int_t i = 0; i < 5; i++) {
- if (IS_BIT_SET(stackMask,i) > 0) {
- sm->fStackActive[i] = kTRUE;
- sm->fActiveStacks++;
- }
- else {
- sm->fStackActive[i] = kFALSE;
- }
- }
+ // goto next stack
+ fPayloadCurr++;
+ fPayloadCurr++;
+
+ return (fPayloadCurr-start);
}
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpSMInfo(const struct AliTRDrawSM *sm)
+Int_t AliTRDrawStream::SeekNextLink()
{
- //
- // Get SM structure into a const char
- //
- return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",
- *sm->fPos, sm->fHeaderSize, sm->fTrackletEnable,
- sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],
- sm->fStackActive[3], sm->fStackActive[4]);
+ // proceed in raw data stream till the next link
+
+ UInt_t *start = fPayloadCurr;
+
+ // read until data endmarkers
+ while (fPayloadCurr - fPayloadStart < fPayloadSize &&
+ ((fPayloadCurr[0] != fgkStackEndmarker[0]) ||
+ (fPayloadCurr[1] != fgkStackEndmarker[1])) &&
+ *fPayloadCurr != fgkDataEndmarker)
+ fPayloadCurr++;
+
+ // read all data endmarkers
+ while (fPayloadCurr - fPayloadStart < fPayloadSize &&
+ *fPayloadCurr == fgkDataEndmarker)
+ fPayloadCurr++;
+
+ return (fPayloadCurr - start);
}
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
+
+void AliTRDrawStream::EquipmentError(ErrorCode_t err, const char *const msg, ...)
{
- //
- // Decode Stack #i Index Word
- // The Stack #i Index Word is a 32-Bit word wit following structure
- // ssssssss ssssssss vvvv mmmm mmmmmmmm
- // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask
- //
- st->fPos = (UInt_t*)word;
-
- UInt_t vword = *word;
- st->fHeaderSize = STACK_HEADER_SIZE(vword);
-
- UInt_t linkMask = STACK_LINK_WORD(vword);
- st->fActiveLinks = 0;
- for (Int_t i = 0; i < 12; i++) {
- if (IS_BIT_SET(linkMask,i) > 0) {
- st->fLinksActive[i] = kTRUE;
- st->fActiveLinks++;
- }
- else {
- st->fLinksActive[i] = kFALSE;
- }
- }
+ // register error according to error code on equipment level
+ // and return the corresponding error message
+
+ fLastError.fSector = fCurrEquipmentId - kDDLOffset;
+ fLastError.fStack = -1;
+ fLastError.fLink = -1;
+ fLastError.fRob = -1;
+ fLastError.fMcm = -1;
+ fLastError.fError = err;
+ (this->*fStoreError)();
+
+ va_list ap;
+ if (fgErrorDebugLevel[err] > 10)
+ AliDebug(fgErrorDebugLevel[err],
+ Form("Event %6i: Eq. %2d - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ else
+ AliError(Form("Event %6i: Eq. %2d - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ fErrorFlags |= fgErrorBehav[err];
}
-
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
+
+
+void AliTRDrawStream::StackError(ErrorCode_t err, const char *const msg, ...)
{
- //
- // decode gtu header for stack info
- //
- st->fPos = (UInt_t*)word;
-
- UInt_t vword = *word;
- st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);
- st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);
- st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);
- st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);
+ // register error according to error code on stack level
+ // and return the corresponding error message
+
+ fLastError.fSector = fCurrEquipmentId - kDDLOffset;
+ fLastError.fStack = fCurrSlot;
+ fLastError.fLink = -1;
+ fLastError.fRob = -1;
+ fLastError.fMcm = -1;
+ fLastError.fError = err;
+ (this->*fStoreError)();
+
+ va_list ap;
+ if (fgErrorDebugLevel[err] > 0)
+ AliDebug(fgErrorDebugLevel[err],
+ Form("Event %6i: Eq. %2d S %i - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ else
+ AliError(Form("Event %6i: Eq. %2d S %i - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ fErrorFlags |= fgErrorBehav[err];
}
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpStackInfo(const struct AliTRDrawStack *st)
+
+void AliTRDrawStream::LinkError(ErrorCode_t err, const char *const msg, ...)
{
- //
- // format the string with the stack info
- //
-
- return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",
- *st->fPos, st->fHeaderSize,
- st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],
- st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],
- st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);
+ // register error according to error code on link level
+ // and return the corresponding error message
+
+ fLastError.fSector = fCurrEquipmentId - kDDLOffset;
+ fLastError.fStack = fCurrSlot;
+ fLastError.fLink = fCurrLink;
+ fLastError.fRob = -1;
+ fLastError.fMcm = -1;
+ fLastError.fError = err;
+ (this->*fStoreError)();
+
+ va_list ap;
+ if (fgErrorDebugLevel[err] > 0)
+ AliDebug(fgErrorDebugLevel[err],
+ Form("Event %6i: Eq. %2d S %i l %2i - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ else
+ AliError(Form("Event %6i: Eq. %2d S %i l %2i - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ fErrorFlags |= fgErrorBehav[err];
}
-//--------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const
-{
- //
- // decode the hc header word 0
- //
- UInt_t vword = *word;
- hc->fPos[0] = (UInt_t*)word;
-
- hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);
- if (hc->fH0Corrupted > 0) {
- if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x", *fHC->fPos));
- return kFALSE;
- }
- hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);
- hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);
- hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);
- hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);
- hc->fNExtraWords = HC_EXTRA_WORDS(vword);
- hc->fDCSboard = HC_DCS_BOARD(vword);
- hc->fSM = HC_SM_NUMBER(vword);
- hc->fStack = HC_STACK_NUMBER(vword);
- hc->fLayer = HC_LAYER_NUMBER(vword);
- hc->fSide = HC_SIDE_NUMBER(vword);
+void AliTRDrawStream::ROBError(ErrorCode_t err, const char *const msg, ...)
+{
+ // register error according to error code on ROB level
+ // and return the corresponding error message
+
+ fLastError.fSector = fCurrEquipmentId - kDDLOffset;
+ fLastError.fStack = fCurrSlot;
+ fLastError.fLink = fCurrLink;
+ fLastError.fRob = fCurrRobPos;
+ fLastError.fMcm = -1;
+ fLastError.fError = err;
+ (this->*fStoreError)();
+
+ va_list ap;
+ if (fgErrorDebugLevel[err] > 0)
+ AliDebug(fgErrorDebugLevel[err],
+ Form("Event %6i: Eq. %2d S %i l %2i ROB %i - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fCurrRobPos, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ else
+ AliError(Form("Event %6i: Eq. %2d S %i l %2i ROB %i - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fCurrRobPos, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ fErrorFlags |= fgErrorBehav[err];
+}
- return kTRUE;
+void AliTRDrawStream::MCMError(ErrorCode_t err, const char *const msg, ...)
+{
+ // register error according to error code on MCM level
+ // and return the corresponding error message
+
+ fLastError.fSector = fCurrEquipmentId - kDDLOffset;
+ fLastError.fStack = fCurrSlot;
+ fLastError.fLink = fCurrLink;
+ fLastError.fRob = fCurrRobPos;
+ fLastError.fMcm = fCurrMcmPos;
+ fLastError.fError = err;
+ (this->*fStoreError)();
+
+ va_list ap;
+ if (fgErrorDebugLevel[err] > 0)
+ AliDebug(fgErrorDebugLevel[err],
+ Form("Event %6i: Eq. %2d S %i l %2i ROB %i MCM %2i - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fCurrRobPos, fCurrMcmPos, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ else
+ AliError(Form("Event %6i: Eq. %2d S %i l %2i ROB %i MCM %2i - %s : %s",
+ fRawReader->GetEventIndex(), fCurrEquipmentId, fCurrSlot, fCurrLink, fCurrRobPos, fCurrMcmPos, fgkErrorMessages[err],
+ (va_start(ap, msg), vsprintf(fErrorBuffer, msg, ap), va_end(ap), fErrorBuffer) ));
+ fErrorFlags |= fgErrorBehav[err];
}
-//--------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
+const char* AliTRDrawStream::GetErrorMessage(ErrorCode_t errCode)
{
- //
- // decode the hc header word 1
- //
- UInt_t vword = *word;
-
- hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);
- if (hc->fH1Corrupted > 0) {
- if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *fHC->fPos));
- return kFALSE;
- }
+ // return the error message for the given error code
- hc->fTimeBins = HC_NTIMEBINS(vword);
- hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
- hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
- hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
-
- hc->fPos[1] = (UInt_t*)word;
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpHCinfoH0(const struct AliTRDrawHC *hc)
-{
- //
- // dump the hc header word 0
- //
- if (!hc)
- return Form("Unable to dump. Null received as parameter!?!");
+ if (errCode > 0 && errCode < kLastErrorCode)
+ return fgkErrorMessages[errCode];
else
- return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",
- hc->fPos[0], (hc->fPos[0]) ? *(hc->fPos[0]) : 0, hc->fRawVMajor, hc->fSM, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
+ return "";
}
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpHCinfoH1(const struct AliTRDrawHC *hc)
+void AliTRDrawStream::AliTRDrawStats::ClearStats()
{
- //
- // dump the hc header word 1
- //
- if (!hc)
- return Form("Unable to dump. Null received as parameter!?!");
- else
- return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",
- hc->fPos[1], (hc->fPos[1]) ? *(hc->fPos[1]) : 0, hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
+ // clear statistics (includes clearing sector-wise statistics)
+
+ fBytesRead = 0;
+ for (Int_t iSector = 0; iSector < 18; iSector++) {
+ fStatsSector[iSector].ClearStats();
+ }
+
}
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
+void AliTRDrawStream::AliTRDrawStats::AliTRDrawStatsSector::ClearStats()
{
- //
- // decode the mcm header
- //
- UInt_t vword = *word;
-
- if (vword == END_OF_TRACKLET_MARKERNEW) {
- if (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
- mcm->fMCMhdCorrupted += 16;
- fHC->fCorrupted += 16; //to finish data reading of this HC
+ // clear statistics (includes clearing HC-wise statistics)
+
+ fBytes = 0;
+ fBytesRead = 0;
+ fNTracklets = 0;
+ fNMCMs = 0;
+ fNChannels = 0;
+
+ for (Int_t iHC = 0; iHC < 60; iHC++) {
+ fStatsHC[iHC].ClearStats();
}
+}
- mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error
- if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));
+void AliTRDrawStream::AliTRDrawStats::AliTRDrawStatsSector::AliTRDrawStatsHC::ClearStats()
+{
+ // clear statistics
- mcm->fROB = MCM_ROB_NUMBER(vword);
- mcm->fMCM = MCM_MCM_NUMBER(vword);
- mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
- mcm->fPos = (UInt_t*)word;
+ fBytes = 0;
+ fBytesRead = 0;
+ fNTracklets = 0;
+ fNMCMs = 0;
+ fNChannels = 0;
}
-//--------------------------------------------------------
-UInt_t AliTRDrawStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
+void AliTRDrawStream::SetDumpMCM(Int_t det, Int_t rob, Int_t mcm, Bool_t dump)
{
- //
- // get the adc mask
- //
- UInt_t vword = *word;
-
- mcm->fADCmax = 0;
- mcm->fADCMask = 0;
- mcm->fADCcount = 0;
- mcm->fADCMaskWord = vword;
-
- if (vword == END_OF_TRACKLET_MARKERNEW) {
- if (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
- mcm->fADCmaskCorrupted += 16;
- fHC->fCorrupted += 16; //to finish data reading of this HC
- }
+ // mark MCM for dumping of raw data
- if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {
- mcm->fADCMask = MCM_ADCMASK_VAL(vword);
- mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
+ if (dump) {
+ fDumpMCM[fNDumpMCMs++] = (det << 7) | (rob << 4) | mcm;
}
else {
- mcm->fADCMask = 0xffffffff;
- mcm->fADCmaskCorrupted = 1; // mcm adc mask error
- if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
+ Int_t iMCM;
+ for (iMCM = 0; iMCM < fNDumpMCMs; iMCM++) {
+ if (fDumpMCM[iMCM] == ((det << 7) | (rob << 4) | mcm)) {
+ fNDumpMCMs--;
+ break;
+ }
+ }
+ for ( ; iMCM < fNDumpMCMs; iMCM++) {
+ fDumpMCM[iMCM] = fDumpMCM[iMCM+1];
+ }
}
-
- return mcm->fADCMask;
}
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
+Bool_t AliTRDrawStream::DumpingMCM(Int_t det, Int_t rob, Int_t mcm) const
{
- //
- // decode the adc mask - adcs to be read out
- //
- mcm->fMCMADCWords = 0;
- mcm->fSingleADCwords = 0;
- mcm->fADCmax = 0;
- mcm->fADCMask = GetMCMadcMask(word, mcm);
-
- if (mcm->fADCMask > 0) {
- for (Int_t i = 0; i < TRDMAXADC; i++) {
- mcm->fADCchannel[mcm->fADCmax] = 0;
- if ( IS_BIT_SET(mcm->fADCMask,i) ) {
- mcm->fADCchannel[mcm->fADCmax] = i;
- mcm->fADCmax++;
- }
+ // check if MCM data should be dumped
+
+ for (Int_t iMCM = 0; iMCM < fNDumpMCMs; iMCM++) {
+ if (fDumpMCM[iMCM] == ((det << 7) | (rob << 4) | mcm)) {
+ return kTRUE;
}
}
- if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility
- mcm->fADCmaskCorrupted += 2;
- if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", mcm->fADCcount, mcm->fADCmax, *fMCM->fPos));
- }
+ return kFALSE;
}
-//--------------------------------------------------------
-void AliTRDrawStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
+TString AliTRDrawStream::DumpRaw(TString title, const UInt_t *start, Int_t length, UInt_t endmarker)
{
- //
- // count the expected mcm words for a given tbins
- //
- mcm->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 );
- mcm->fSingleADCwords = 0;
- if (mcm->fADCmax > 0) {
- mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax;
+ // dump raw data
+
+ title += "\n";
+ for (Int_t pos = 0; pos < length; pos += 4) {
+ if ((start[pos+0] != endmarker) && pos+0 < length)
+ if ((start[pos+1] != endmarker && pos+1 < length))
+ if ((start[pos+2] != endmarker && pos+2 < length))
+ if ((start[pos+3] != endmarker && pos+3 < length))
+ title += Form(" 0x%08x 0x%08x 0x%08x 0x%08x\n",
+ start[pos+0], start[pos+1], start[pos+2], start[pos+3]);
+ else {
+ title += Form(" 0x%08x 0x%08x 0x%08x 0x%08x\n",
+ start[pos+0], start[pos+1], start[pos+2], start[pos+3]);
+ return title;
+ }
+ else {
+ title += Form(" 0x%08x 0x%08x 0x%08x\n",
+ start[pos+0], start[pos+1], start[pos+2]);
+ return title;
+ }
+ else {
+ title += Form(" 0x%08x 0x%08x\n",
+ start[pos+0], start[pos+1]);
+ return title;
+ }
+ else {
+ title += Form(" 0x%08x\n",
+ start[pos+0]);
+ return title;
+ }
}
- if (fTbins > 32) mcm->fSingleADCwords = 10; // if the timebin is more than 30, then fix the number of adc words to 10
+ return title;
}
-
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
+
+TString AliTRDrawStream::DumpMcmHeader(TString title, UInt_t word)
{
- //
- // mcm info in a string
- //
- if (!mcm)
- return Form("Unable to dump. Null received as parameter!?!");
- else
- return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);
+ title += Form("0x%08x -> ROB: %i, MCM: %2i",
+ word, ROB(word), MCM(word));
+ return title;
}
-
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
+
+TString AliTRDrawStream::DumpAdcMask(TString title, UInt_t word)
{
- //
- // mcm adc mask in a string
- //
- if (!mcm)
- return Form("Unable to dump. Null received as parameter!?!");
-
- TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);
- for (Int_t i = 0; i < TRDMAXADC; i++) {
- tsreturn += Form("%d ", mcm->fADCchannel[i]);
+ title += Form("0x%08x -> #ch : %2i, 0x%06x (%2i ch)",
+ word, GetNActiveChannels(word), GetActiveChannels(word), GetNActiveChannelsFromMask(word));
+ return title;
+}
+
+AliTRDrawStream::AliTRDrawStreamError::AliTRDrawStreamError(Int_t error, Int_t sector, Int_t stack, Int_t link, Int_t rob, Int_t mcm) :
+ fError(error),
+ fSector(sector),
+ fStack(stack),
+ fLink(link),
+ fRob(rob),
+ fMcm(mcm)
+{
+ // ctor
+
+}
+
+void AliTRDrawStream::SortTracklets(TClonesArray *trklArray, TList &sortedTracklets, Int_t *indices)
+{
+ // sort tracklets for referencing from GTU tracks
+
+ if (!trklArray)
+ return;
+
+ Int_t nTracklets = trklArray->GetEntriesFast();
+
+ Int_t lastHC = -1;
+ for (Int_t iTracklet = 0; iTracklet < nTracklets; iTracklet++) {
+ AliTRDtrackletBase *trkl = (AliTRDtrackletBase*) ((*trklArray)[iTracklet]);
+ Int_t hc = trkl->GetHCId();
+ if ((hc < 0) || (hc >= 1080)) {
+ AliErrorClass(Form("HC for tracklet: 0x%08x out of range: %i", trkl->GetTrackletWord(), trkl->GetHCId()));
+ continue;
+ }
+ AliDebugClass(5, Form("hc: %4i : 0x%08x z: %2i", hc, trkl->GetTrackletWord(), trkl->GetZbin()));
+ if (hc != lastHC) {
+ AliDebugClass(2, Form("set tracklet index for HC %i to %i", hc, iTracklet));
+ indices[hc] = iTracklet + 1;
+ lastHC = hc;
+ }
+ }
+
+ for (Int_t iDet = 0; iDet < 540; iDet++) {
+ Int_t trklIndexA = indices[2*iDet + 0] - 1;
+ Int_t trklIndexB = indices[2*iDet + 1] - 1;
+ Int_t trklIndex = sortedTracklets.GetEntries();
+ AliTRDtrackletBase *trklA = trklIndexA > -1 ? (AliTRDtrackletBase*) ((*trklArray)[trklIndexA]) : 0x0;
+ AliTRDtrackletBase *trklB = trklIndexB > -1 ? (AliTRDtrackletBase*) ((*trklArray)[trklIndexB]) : 0x0;
+ AliTRDtrackletBase *trklNext = 0x0;
+ while (trklA != 0x0 || trklB != 0x0) {
+ AliDebugClass(5, Form("det %i - A: %i/%i -> %p, B: %i/%i -> %p",
+ iDet, trklIndexA, nTracklets, trklA, trklIndexB, nTracklets, trklB));
+ if (trklA == 0x0) {
+ trklNext = trklB;
+ trklIndexB++;
+ trklB = trklIndexB < nTracklets ? (AliTRDtrackletBase*) ((*trklArray)[trklIndexB]) : 0x0;
+ if (trklB && trklB->GetHCId() != 2*iDet + 1)
+ trklB = 0x0;
+ }
+ else if (trklB == 0x0) {
+ trklNext = trklA;
+ trklIndexA++;
+ trklA = trklIndexA < nTracklets ? (AliTRDtrackletBase*) ((*trklArray)[trklIndexA]) : 0x0;
+ if (trklA && trklA->GetHCId() != 2*iDet)
+ trklA = 0x0;
+ }
+ else {
+ if (trklA->GetZbin() <= trklB->GetZbin()) {
+ trklNext = trklA;
+ trklIndexA++;
+ trklA = trklIndexA < nTracklets ? (AliTRDtrackletBase*) ((*trklArray)[trklIndexA]) : 0x0;
+ if (trklA && trklA->GetHCId() != 2*iDet)
+ trklA = 0x0;
+ }
+ else {
+ trklNext = trklB;
+ trklIndexB++;
+ trklB = trklIndexB < nTracklets ? (AliTRDtrackletBase*) ((*trklArray)[trklIndexB]) : 0x0;
+ if (trklB && trklB->GetHCId() != 2*iDet + 1)
+ trklB = 0x0;
+ }
+ }
+ if (trklNext) {
+ sortedTracklets.Add(trklNext);
+
+ }
+ }
+
+ // updating tracklet indices as in output
+ if (sortedTracklets.GetEntries() != trklIndex) {
+ indices[2*iDet + 0] = trklIndex;
+ indices[2*iDet + 1] = sortedTracklets.GetEntries();
+ } else {
+ indices[2*iDet + 0] = indices[2*iDet + 1] = -1;
+ }
}
- tsreturn += "";
- return tsreturn.Data();
}
+void AliTRDrawStream::AssignTracklets(AliESDTrdTrack *trdTrack, Int_t *trackletIndex, Int_t refIndex[6])
+{
+ UInt_t mask = trdTrack->GetLayerMask();
+ UInt_t stack = trdTrack->GetStack();
+
+ for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
+ refIndex[iLayer] = -1;
+
+ if (mask & (1 << iLayer)) {
+
+ Int_t det = trdTrack->GetSector()*30 + stack*6 + iLayer;
+ Int_t idx = trdTrack->GetTrackletIndex(iLayer);
+
+ if ((det < 0) || (det > 539)) {
+ AliErrorClass(Form("Invalid detector no. from track: %i", 2*det));
+ continue;
+ }
+ if (trackletIndex[2*det] >= 0) {
+ if ((trackletIndex[2*det] + idx > -1) &&
+ (trackletIndex[2*det] + idx < trackletIndex[2*det+1])) {
+ refIndex[iLayer] = trackletIndex[2*det] + idx;
+ } else {
+ AliErrorClass(Form("Requested tracklet index %i out of range", idx));
+ }
+ } else {
+ AliErrorClass(Form("Non-existing tracklets requested in det %i", det));
+ }
+ }
+ }
+}