//printf(" iCol %d iRow %d iRowMax %d rob %d mcm %d adc %d extCol %d\n",iCol,iRow,iRowMax,rob,mcm,adc,extCol);
// Signal for regular pads
- Int_t nbtimebin = digitParam->GetNTimeBins(); // number of time bins read from data
+ Int_t nbtimebin = digitParam->GetNTimeBins(idetector); // number of time bins read from data
for(Int_t k = 0; k < nbtimebin; k++){
Short_t signal = 0;
signal = digits->GetData(iRow,iCol,k);
// nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
- nbtimebin = digitParam->GetNTimeBins(); // number of time bins read from data
- baseline = digitParam->GetADCbaseline(); // baseline
+ nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
+ baseline = digitParam->GetADCbaseline(det); // baseline
if(nbtimebin == 0) return 0;
if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
TClonesArray *AliTRDReconstructor::fgClusters = NULL;
TClonesArray *AliTRDReconstructor::fgTracklets = NULL;
-AliTRDdigitsParam *AliTRDReconstructor::fgDigitsParam = NULL;
Char_t const * AliTRDReconstructor::fgSteerNames[kNsteer] = {
"DigitsConversion "
,"Write Clusters "
// Destructor
//
- if(fgDigitsParam){
- delete fgDigitsParam;
- fgDigitsParam = NULL;
- }
if(fgClusters) {
fgClusters->Delete();
delete fgClusters;
}
-//_____________________________________________________________________________
-void AliTRDReconstructor::SetDigitsParam(AliTRDdigitsParam const *par)
-{
- if(fgDigitsParam) (*fgDigitsParam) = (*par);
- else fgDigitsParam = new AliTRDdigitsParam(*par);
-}
-
-
//_____________________________________________________________________________
void AliTRDReconstructor::SetOption(Option_t *opt)
{
static Int_t GetNTimeBins() {return fgNTimeBins;}
Int_t GetNdEdxSlices() const { return (Int_t)AliTRDpidUtil::GetNdEdxSlices(GetPIDMethod());}
AliTRDpidUtil::ETRDPIDMethod GetPIDMethod() const { return GetRecoParam()->IsPIDNeuralNetwork() ? AliTRDpidUtil::kNN : AliTRDpidUtil::kLQ;}
- static AliTRDdigitsParam* GetDigitsParam() { return fgDigitsParam;}
static const AliTRDrecoParam* GetRecoParam() { return dynamic_cast<const AliTRDrecoParam*>(AliReconstructor::GetRecoParam(2)); }
+
virtual Bool_t HasDigitConversion() const { return fSteerParam&kDigitsConversion; };
- Bool_t HasDigitsParam() const { return Bool_t(fgDigitsParam);}
Bool_t IsCosmic() const { return GetRecoParam()->GetEventSpecie() & AliRecoParam::kCosmic;}
Bool_t IsWritingClusters() const { return fSteerParam&kWriteClusters;}
Bool_t IsWritingTracklets() const { return fSteerParam&kWriteTracklets;}
static void SetClusters(TClonesArray *clusters) { fgClusters = clusters;}
static void SetTracklets(TClonesArray *tracklets) { fgTracklets = tracklets;}
- static void SetDigitsParam(AliTRDdigitsParam const *par);
void SetOption(Option_t *opt);
private:
UInt_t fSteerParam; // steering bits
TTreeSRedirector *fDebugStream[AliTRDrecoParam::kTRDreconstructionTasks];// Debug Streamer container;
- static AliTRDdigitsParam *fgDigitsParam; // Digits Param information
static TClonesArray *fgClusters; // list of clusters for local reconstructor
static TClonesArray *fgTracklets; // list of online tracklets for local reconstructor
static Int_t fgNTimeBins; // number of time bins as given by the clusterizer
- ClassDef(AliTRDReconstructor, 2) // Class for the TRD reconstruction
+ ClassDef(AliTRDReconstructor, 3) // Class for the TRD reconstruction
};
fDigitsManager->RemoveDictionaries(i);
fDigitsManager->ClearIndexes(i);
}
- fReconstructor->SetDigitsParam(fDigitsManager->GetDigitsParam());
if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
if (!fReconstructor->IsWritingTracklets()) continue;
if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
}
- fReconstructor->SetDigitsParam(fDigitsManager->GetDigitsParam());
if (fTrackletContainer){
delete [] fTrackletContainer[0];
// Get the digits
fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
- fBaseline = fDigitsManager->GetDigitsParam()->GetADCbaseline();
+ fBaseline = fDigitsManager->GetDigitsParam()->GetADCbaseline(det);
// This is to take care of switched off super modules
if (!fDigits->HasData()) return kFALSE;
delete [] nhit;
// Save the values for the raw data headers
- fDigitsManager->GetDigitsParam()->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
- fDigitsManager->GetDigitsParam()->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
+ fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
+ fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
return kTRUE;
Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
- Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins();
+ Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins(det);
// Get the calibration objects
//calGainFactorROC = calibration->GetGainFactorROC(det);
tracks2->Allocate(nRowMax,nColMax,nTimeTotal);
// Keep the digits param
- manSDig->GetDigitsParam()->SetNTimeBins(manDig->GetDigitsParam()->GetNTimeBins());
- manSDig->GetDigitsParam()->SetADCbaseline(manDig->GetDigitsParam()->GetADCbaseline());
+ manSDig->GetDigitsParam()->SetNTimeBinsAll(manDig->GetDigitsParam()->GetNTimeBins(0));
+ manSDig->GetDigitsParam()->SetADCbaselineAll(manDig->GetDigitsParam()->GetADCbaseline(0));
if (digits->HasData()) {
AliDebug(1,"Only one input file.");
}
- Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins();
Int_t iMerge = 0;
while (mergeSDigitsManager) {
- if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins() != nTimeTotal) {
- AliError(Form("Mismatch in the number of time bins [%d,%d]"
- ,nTimeTotal
- ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins()));
- return kFALSE;
- }
-
iMerge++;
// Loop through the detectors
for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
+ Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet);
+ if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet) != nTimeTotal) {
+ AliError(Form("Mismatch in the number of time bins [%d,%d] in detector %d"
+ ,nTimeTotal
+ ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet)
+ ,iDet));
+ return kFALSE;
+ }
+
Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")->WriteData("OVERWRITE");
// Save the values for the raw data headers
- fDigitsManager->GetDigitsParam()->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
- fDigitsManager->GetDigitsParam()->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
+ fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
+ fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
return kTRUE;
AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
,AliTRDSimParam::Instance()->GetNTimeBins()));
fDigitsParam = new AliTRDdigitsParam();
- fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
- fDigitsParam->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
+ fDigitsParam->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
+ fDigitsParam->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
}
return status;
//_____________________________________________________________________________
AliTRDdigitsParam::AliTRDdigitsParam()
:TObject()
- ,fNTimeBins(0)
- ,fADCbaseline(0)
{
//
// Default constructor
//
for (Int_t i = 0; i < 540; i++) {
+ fNTimeBins[i] = 0;
fPretriggerPhase[i] = 0;
+ fADCbaseline[i] = 0;
}
}
//_____________________________________________________________________________
AliTRDdigitsParam::AliTRDdigitsParam(const AliTRDdigitsParam &p)
:TObject(p)
- ,fNTimeBins(p.fNTimeBins)
- ,fADCbaseline(p.fADCbaseline)
{
//
// Copy constructor
//
for (Int_t i = 0; i < 540; i++) {
+ fNTimeBins[i] = p.fNTimeBins[i];
fPretriggerPhase[i] = p.fPretriggerPhase[i];
+ fADCbaseline[i] = p.fADCbaseline[i];
}
}
return;
}
- target->fNTimeBins = fNTimeBins;
- target->fADCbaseline = fADCbaseline;
-
for (Int_t i = 0; i < 540; i++) {
+ target->fNTimeBins[i] = fNTimeBins[i];
target->fPretriggerPhase[i] = fPretriggerPhase[i];
+ target->fADCbaseline[i] = fADCbaseline[i];
}
}
virtual void Copy(TObject &p) const;
- void SetNTimeBins(Int_t ntb) { fNTimeBins = ntb; }
+ void SetNTimeBins(Int_t det, Int_t ntb) { fNTimeBins[det] = ntb; }
void SetPretriggerPhase(Int_t det, UInt_t phase) { fPretriggerPhase[det] = phase; }
- void SetADCbaseline(Int_t baseline) { fADCbaseline = baseline; }
+ void SetADCbaseline(Int_t det, Int_t baseline) { fADCbaseline[det] = baseline; }
- Int_t GetNTimeBins() const { return fNTimeBins; }
+ void SetNTimeBinsAll(Int_t ntb) { for (Int_t i = 0; i < 540; i++)
+ { fNTimeBins[i] = ntb; } }
+ void SetPretriggerPhaseAll(UInt_t phase) { for (Int_t i = 0; i < 540; i++)
+ { fPretriggerPhase[i] = phase; } }
+ void SetADCbaselineAll(Int_t baseline) { for (Int_t i = 0; i < 540; i++)
+ { fADCbaseline[i] = baseline; } }
+
+ Int_t GetNTimeBins(Int_t det) const { return fNTimeBins[det]; }
UInt_t GetPretriggerPhase(Int_t det) const { return fPretriggerPhase[det]; }
- Int_t GetADCbaseline() const { return fADCbaseline; }
+ Int_t GetADCbaseline(Int_t det) const { return fADCbaseline[det]; }
protected:
- Int_t fNTimeBins; // Number of timebins
+ Int_t fNTimeBins[540]; // Number of timebins for each detector
UInt_t fPretriggerPhase[540]; // Pretrigger phase for each detector
- Int_t fADCbaseline; // ADC baseline, given in ADC channels
+ Int_t fADCbaseline[540]; // ADC baseline for each detector, given in ADC channels
- ClassDef(AliTRDdigitsParam,4) // The parameters for digits
+ ClassDef(AliTRDdigitsParam,5) // The parameters for digits
};
#endif
,fNumberOfDDLs(0)
,fTrackletTree(NULL)
,fTrackletContainer(NULL)
- ,fNTimeBins(0)
,fSMindexPos(0)
,fStackindexPos(0)
,fEventCounter(0)
+ ,fDigitsParam(NULL)
{
//
// Default constructor
,fNumberOfDDLs(0)
,fTrackletTree(NULL)
,fTrackletContainer(NULL)
- ,fNTimeBins(0)
,fSMindexPos(0)
,fStackindexPos(0)
,fEventCounter(0)
+ ,fDigitsParam(NULL)
{
//
// Copy constructor
// Buffer to temporary store half chamber data
UInt_t *hcBuffer = new UInt_t[kMaxHcWords];
-
- // set the number of time bin
- fNTimeBins = digitsManager->GetDigitsParam()->GetNTimeBins();
Bool_t newEvent = kFALSE; // only for correct readout tree
Bool_t newSM = kFALSE; // new SM flag, for writing SM index words
Bool_t newStack = kFALSE; // new stack flag, for writing stack index words
+ // Get digits parameter
+ fDigitsParam = digitsManager->GetDigitsParam();
+
// sect is same as iDDL, so I use only sect here.
for (Int_t sect = 0; sect < fGeo->Nsector(); sect++) {
Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
Int_t nCol = fGeo->GetColMax( layer );
- //const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
- const Int_t kNTBin = fNTimeBins;
+ const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
+
Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
UInt_t x = 0; // General used number
Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
Int_t nRow = fGeo->GetRowMax( layer, stack, sect );
Int_t nCol = fGeo->GetColMax( layer );
- //const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
- const Int_t kNTBin = fNTimeBins;
+ const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
Int_t kCtype = 0; // Chamber type (0:C0, 1:C1)
//Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id?
Int_t stack = fGeo->GetStack( det ); // Stack
Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
Int_t rv = fFee->GetRAWversion();
- //const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
- const Int_t kNTBin = fNTimeBins;
+ const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
UInt_t x = 0;
// Write end of tracklet marker
Int_t stack = fGeo->GetStack( det ); // Stack
Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL)
Int_t rv = fFee->GetRAWversion();
- //const Int_t kNTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins(); // old method, fetch the info from OCDB
- const Int_t kNTBin = fNTimeBins;
+ const Int_t kNTBin = fDigitsParam->GetNTimeBins(det);
Bool_t trackletOn = fFee->GetTracklet();
UInt_t x = 0;
class AliTRDgeometry;
class AliTRDfeeParam;
class AliTRDarrayADC;
+class AliTRDdigitsParam;
// Some constants:
const UInt_t kEndoftrackletmarker = 0xAAAAAAAA; /*This marks the end of tracklet data words*/
TTree *fTrackletTree; //! Tree for tracklets
UInt_t **fTrackletContainer; //! tracklet container
- ClassDef(AliTRDrawData,5) // TRD raw data class
-
private:
static Int_t fgRawFormatVersion; // simulation raw data version - 0:old , 1:new(real data format)
static const UInt_t fgkEndOfTrackletMarker = 0x10001000; // This marks the end of tracklet data words
static const UInt_t fgkEndOfDataMarker = 0x00000000; // This marks the end of HC data words
- Int_t fNTimeBins; // number of time bin
Int_t fSMindexPos; // Position of SM index word
Int_t fStackindexPos; // Position of SM index word
UInt_t fEventCounter; // Event counter(starting from 1)
+ AliTRDdigitsParam *fDigitsParam; // Digits parameter
-
-
+ ClassDef(AliTRDrawData,6) // TRD raw data class
};
#endif
-/**************************************************************************
-* 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: AliTRDrawFastStream.cxx 27797 2008-08-05 14:37:22Z cblume $ */
-
-////////////////////////////////////////////////////////////////////////////////
-// //
-// This class provides access to TRD digits in raw data in a way of streaming //
-// //
-// 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 "TFile.h"
-
-#include "AliTRDrawFastStream.h"
-#include "AliTRDgeometry.h"
-#include "AliTRDfeeParam.h"
-#include "AliTRDdigitsManager.h"
-#include "AliTRDarrayDictionary.h"
-#include "AliTRDarrayADC.h"
-#include "AliTRDSignalIndex.h"
-#include "AliTRDdigitsParam.h"
-#include "AliTRDrawTPStream.h"
-
-#include "AliRawReader.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) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!
-#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(AliTRDrawFastStream)
-
-Bool_t AliTRDrawFastStream::fgExtraSkip = kFALSE;
-Bool_t AliTRDrawFastStream::fgSkipCDH = kFALSE;
-Bool_t AliTRDrawFastStream::fgCleanDataOnly = kFALSE;
-Bool_t AliTRDrawFastStream::fgDebugFlag = kTRUE;
-Bool_t AliTRDrawFastStream::fgEnableMemoryReset = kTRUE;
-Bool_t AliTRDrawFastStream::fgStackNumberChecker = kTRUE;
-Bool_t AliTRDrawFastStream::fgStackLinkNumberChecker = kFALSE;
-Bool_t AliTRDrawFastStream::fgSkipData = kTRUE;
-Bool_t AliTRDrawFastStream::fgEnableDecodeConfigData = kFALSE;
-Int_t AliTRDrawFastStream::fgDumpHead = -1;
-Short_t AliTRDrawFastStream::fgMCMordering[] =
- {
- 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3
- };
-Short_t AliTRDrawFastStream::fgROBordering[] =
- {
- 0, 1, 2, 3
- };
-
-Int_t AliTRDrawFastStream::fgLastHC = -1;
-Int_t AliTRDrawFastStream::fgLastROB = -1;
-Int_t AliTRDrawFastStream::fgLastIndex = -1;
-
-//--------------------------------------------------------
-AliTRDrawFastStream::AliTRDrawFastStream()
- : AliTRDrawStreamBase()
- , fSM()
- , fStack(0)
- , fHC(0)
- , fLastHC(0)
- , fMCM()
- , fpPos(0)
- , fpBegin(0)
- , fpEnd(0)
- , fWordLength(0)
- , fpPosTemp(0)
- , fGlobalNTimeBins(0)
- , fIsTimeBinSet(kFALSE)
- , fIsGlobalDigitsParamSet(kFALSE)
- , fStackNumber(-1)
- , fStackLinkNumber(-1)
- , fLinkTrackletCounter(-1)
- , fEndOfTrackletCount(-1)
- , fNWordsCounter(-1)
- , fMaskADCword(0)
- , fTbinADC(0)
- , fEventCounter(0)
- , fLastEventCounter(0)
- , fSharedPadsOn(kTRUE)
- , fMaxADCgeom(0)
- , fADCnumber(0)
- , fCOL(0)
- , fExtendedCOL(0)
- , fIsShared(0)
- , fWarnError(kTRUE)
- , fBufferRead(0)
- , fGeometry(0)
- , fRawReader(0)
- , fTRDfeeParam(0)
- , fCommonAdditive(0)
-{
- //
- // default constructor
- //
-
- if (Init() == kFALSE) {
- AliWarning("Unable to Init.");
- }
-}
-
-//--------------------------------------------------------
-AliTRDrawFastStream::AliTRDrawFastStream(AliRawReader *rawReader)
- : AliTRDrawStreamBase(rawReader)
- , fSM()
- , fStack(0)
- , fHC(0)
- , fLastHC(0)
- , fMCM()
- , fpPos(0)
- , fpBegin(0)
- , fpEnd(0)
- , fWordLength(0)
- , fpPosTemp(0)
- , fGlobalNTimeBins(0)
- , fIsTimeBinSet(kFALSE)
- , fIsGlobalDigitsParamSet(kFALSE)
- , fStackNumber(-1)
- , fStackLinkNumber(-1)
- , fLinkTrackletCounter(-1)
- , fEndOfTrackletCount(-1)
- , fNWordsCounter(-1)
- , fMaskADCword(0)
- , fTbinADC(0)
- , fEventCounter(0)
- , fLastEventCounter(0)
- , fSharedPadsOn(kTRUE)
- , fMaxADCgeom(0)
- , fADCnumber(0)
- , fCOL(0)
- , fExtendedCOL(0)
- , fIsShared(0)
- , fWarnError(kTRUE)
- , fBufferRead(0)
- , fGeometry(0)
- , fRawReader(rawReader)
- , fTRDfeeParam(0)
- , fCommonAdditive(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*).");
- }
-}
-
-//------------------------------------------------------------
-AliTRDrawFastStream::AliTRDrawFastStream(const AliTRDrawFastStream& /*st*/)
- : AliTRDrawStreamBase()
- , fSM()
- , fStack(0)
- , fHC(0)
- , fLastHC(0)
- , fMCM()
- , fpPos(0)
- , fpBegin(0)
- , fpEnd(0)
- , fWordLength(0)
- , fpPosTemp(0)
- , fGlobalNTimeBins(0)
- , fIsTimeBinSet(kFALSE)
- , fIsGlobalDigitsParamSet(kFALSE)
- , fStackNumber(-1)
- , fStackLinkNumber(-1)
- , fLinkTrackletCounter(-1)
- , fEndOfTrackletCount(-1)
- , fNWordsCounter(-1)
- , fMaskADCword(0)
- , fTbinADC(0)
- , fEventCounter(0)
- , fLastEventCounter(0)
- , fSharedPadsOn(kTRUE)
- , fMaxADCgeom(0)
- , fADCnumber(0)
- , fCOL(0)
- , fExtendedCOL(0)
- , fIsShared(0)
- , fWarnError(kTRUE)
- , fBufferRead(0)
- , fGeometry(0)
- , fRawReader(0)
- , fTRDfeeParam(0)
- , fCommonAdditive(0)
-{
- //
- // Copy constructor
- //
- AliError("Not implemeneted.");
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::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;
-}
-
-//------------------------------------------------------------
-AliTRDrawFastStream::~AliTRDrawFastStream()
-{
- //
- // destructor
- //
- delete fGeometry;
-}
-
-//------------------------------------------------------------
-
-AliTRDrawFastStream &
-AliTRDrawFastStream::operator=(const AliTRDrawFastStream &)
-{
- //
- // we are not using this functionality
- //
- AliFatal("May not use.");
- return *this;
-}
-
-//___________________________________________________________
-void AliTRDrawFastStream::SwapOnEndian()
-{
- //
- // 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;
- }
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::SkipWords(UInt_t iw)
-{
- //
- // Skip words corresponding to iw
- //
- if ( fpPos + iw < fpEnd ) {
- fpPos += iw;
- return kTRUE;
- }
- else {
- if (fWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::SetReader(AliRawReader *reader)
-{
- //
- // set raw reader pointer
- //
- if (reader != 0) {
- fRawReader = reader;
- if (fRawReader) {
- return Init();
- }
- else {
- AliWarning("Unable to setup reader.");
- return kFALSE;
- }
- }
- else {
- AliWarning("AliRawReader argument is 0.");
- fRawReader = 0;
- }
-
- return kFALSE;
-}
-
-//------------------------------------------------------------
-Int_t AliTRDrawFastStream::NextBuffer()
-{
- //
- // return -1 if no more buffers available
- // return 0 if SMHeader decoding failed
- // return 1 if SMHeader dedoding is 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;
- }
-
- if (fgSkipCDH == kTRUE) {
- buffer += CDH_WORDS * WORD_SIZE;
- length -= CDH_WORDS * WORD_SIZE;
- }
-
- if (length > 0) {
- if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));
- if (fgEnableMemoryReset) ResetMemory();
- if (DecodeSMHeader((void*)buffer, length) == kTRUE)
- return 1;
- else
- return 0;
- }
- }
- else {
- return -1;
- }
- }
-
- return -1;
-}
-
-//------------------------------------------------------------
-void AliTRDrawFastStream::ResetCounters()
-{
- //
- // reset some global counters
- //
- fBufferRead = kFALSE; // kFALSE if no buffer read
-
- fSM.fActiveStacks = 0;
- fSM.fNexpectedHalfChambers = 0;
-
- fLastEventCounter = 0;
- fEventCounter = 0;
-
- ResetIterators();
-}
-
-//------------------------------------------------------------
-void AliTRDrawFastStream::ResetIterators()
-{
- //
- // reset data which should be reset every sm
- //
- fStackNumber = 0;
- fStackLinkNumber = 0;
-}
-
-//------------------------------------------------------------
-void AliTRDrawFastStream::ResetPerSM()
-{
- //
- // reset every SM
- //
- fSM.fHeaderSize = 0;
- fSM.fTrackletEnable = kFALSE;
- fSM.fCorrupted = 0;
- fSM.fNexpectedHalfChambers = 0;
- fSM.fNexpectedHalfChambers = 0;
- fSM.fPos = NULL;
- for (Int_t i=0; i<5; i++) {
- fSM.fStackActive[i] = kFALSE;
- }
-}
-
-//------------------------------------------------------------
-void AliTRDrawFastStream::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;
- }
-}
-
-//------------------------------------------------------------
-void AliTRDrawFastStream::ResetPerHC()
-{
- //
- // reset every HC
- //
- fEventCounter = 0;
- fHC->fNTracklets = 0;
- fHC->fSpecialRawV = 0;
- fHC->fRawVMajor = 0;
- fHC->fRawVMajorOpt = 0;
- fHC->fRawVMinor = 0;
- fHC->fNExtraWords = 0;
- fHC->fDCSboard = 0;
- fHC->fTimeBins = 0;
- fHC->fBunchCrossCounter = 0;
- fHC->fPreTriggerCounter = 0;
- fHC->fPreTriggerPhase = 0;
- fHC->fMCMmax = 0;
-
- fHC->fSM = 0;
- fHC->fStack = 0;
- fHC->fStackHCheader = 0;
- fHC->fLayer = 0;
- fHC->fLayerHCheader = 0;
- fHC->fSide = 0;
- fHC->fSideHCheader = 0;
- fHC->fDET = 0;
- fHC->fROC = 0;
- fHC->fRowMax = 0;
- fHC->fColMax = 0;
-
- fHC->fH0Corrupted = 0;
- fHC->fH1Corrupted = 0;
- fHC->fCorrupted = 0;
- fHC->fEOTECorrupted = kFALSE;
- fHC->fBufferCorrupted = kFALSE;
- fHC->fDataCorrupted = kFALSE;
-
- fHC->fNErrors= 0;
- memset(fHC->fErrorCodes, 0, 1411*sizeof(UShort_t)); // initialize error container
- memset(fHC->fTrackletWords, 0, MAXTRACKLETSPERHC*sizeof(UInt_t)); // initialize tracklet container
-}
-
-//------------------------------------------------------------
-void AliTRDrawFastStream::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.fSingleADCwords = 0;
- fMCM.fMCMhdCorrupted = 0;
- fMCM.fADCmaskCorrupted = 0;
- fMCM.fDataCorrupted = kFALSE;
- fMCM.fPos = NULL;
- fMCM.fAdcDataPos = NULL;
- fMCM.fADCcounter = 0;
-
- memset(fMCM.fADCchannel, 0, TRDMAXADC*sizeof(UInt_t));
-}
-
-//------------------------------------------------------------
-void AliTRDrawFastStream::ResetMemory()
-{
- //
- // initialize all the data members to prevent read data
- // from 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();
- }
- }
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::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) {
- //if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0)
- fHC = &fStack->fHalfChambers[fStackLinkNumber];
- //ResetPerHC(); // [mj - you don't need to do? ]
- if (!fHC) {
- AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));
- return kFALSE;
- }
- fStackLinkNumber++;
- return kTRUE;
- } //link active ?
- else fStackLinkNumber++;
- } //stack link number loop
- } //stack active ?
- fStackNumber++;
- fStackLinkNumber = 0;
- } //stack number loop
- } //fBufferRead
-
- // go for the next buffer
- if (fRawReader) {
- Int_t nextBuff = NextBuffer();
- while (nextBuff != -1) {
- if (nextBuff > 0) {
- fBufferRead = kTRUE;
- return Next();
- }
- nextBuff = NextBuffer();
- }
- }
-
- return kFALSE;
-}
-
-//------------------------------------------------------------
-Int_t AliTRDrawFastStream::NextChamber(AliTRDdigitsManager *digitsManager, UInt_t **trackletContainer, UShort_t **errorCodeContainer)
-{
-
- //
- // Fills single chamber digit array
- // Return value is the detector number
- //
- // first of all, you do the SM header decoding only at the beginning of the SM data reading
- // then, every HC, you call Next() which points next HC. then, there you decode the given HC
- // and at the same time, put the digit into digitmanager
- //
- AliTRDarrayADC *digits = 0;
- AliTRDarrayDictionary *track0 = 0;
- AliTRDarrayDictionary *track1 = 0;
- AliTRDarrayDictionary *track2 = 0;
- AliTRDSignalIndex *indexes = 0;
- AliTRDdigitsParam *digitsparam = 0;
-
- Int_t lastdet = -1;
- Int_t det = -1;
- Int_t side = -1;
- //Int_t it = 0;
- Int_t ntracklets = 0;
- Int_t nErrors = 0;
-
- if (trackletContainer){
- for (Int_t i = 0; i < 2; i++)
- memset(trackletContainer[i], 0, MAXTRACKLETSPERHC*sizeof(UInt_t));
- }
-
- if (errorCodeContainer){
- for (Int_t i = 0; i < 2; i++)
- memset(errorCodeContainer[i], 0, 1411*sizeof(UShort_t));
- }
-
- while ( Next() ) { // loop over HC
-
- // get this information from the GTU header
- det = GetDet();
- side = GetSide();
-
- if (det != lastdet) {
- // If new detector found
- if (lastdet == -1) {lastdet = det; fLastHC = fHC;}
- else {fStackLinkNumber--; fHC = fLastHC ; return lastdet;}
-
- if (det < 0 || det >= AliTRDgeometry::kNdet) continue;
-
- // 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);
- }
-
- if (!digits) return -1;
-
- //Int_t rowMax = GetRowMax();
- Int_t rowMax = fGeometry->RowmaxC1(); // we use maximum row number among all detectors to reuse memory
- Int_t colMax = GetColMax();
- Int_t ntbins = GetGlobalNTimeBins();
-
- // Set digitparam variables
- digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();
- if (!fIsGlobalDigitsParamSet){
- digitsparam->SetNTimeBins(ntbins);
- fCommonAdditive=10;
- digitsparam->SetADCbaseline(fCommonAdditive);
- fIsGlobalDigitsParamSet = kTRUE;
- }
-
- // Allocate memory space for the digits buffer
- if (digits->GetNtime() == 0) {
- digits->Allocate(rowMax, colMax, ntbins);
- if (digitsManager->UsesDictionaries()) {
- track0->Allocate(rowMax, colMax, ntbins);
- track1->Allocate(rowMax, colMax, ntbins);
- track2->Allocate(rowMax, colMax, ntbins);
- }
- }
-
- 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);
- }
-
- if (fSM.fTrackletEnable == kTRUE) {
- if (DecodeTracklets() == kFALSE) {
- SeekEndOfData();
-
- if (fWarnError) AliError(Form("Tracklet decoding failed stack %d link %d", GetStack(), fStackLinkNumber));
-
- // copy error codes in memory into error container
- if (errorCodeContainer) {
- nErrors = GetNErrors();
- if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411); // [mj temp - optimize]
- }
-
- continue; // if it fails to decode tracklets of this HC, it skips further decoding and goes to next HC
- }
- }
-
- // decode hc data
- fgLastROB = -1; // to check mcm number odering
- fgLastIndex = -1 ; // to check mcm number odering
- if (DecodeHC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {
- // encode HC error code
- fHC->fErrorCodes[2] += fHC->fH0Corrupted;
- fHC->fErrorCodes[2] += (fHC->fH1Corrupted << 2);
- fHC->fErrorCodes[2] += (fHC->fCorrupted << 3);
- fHC->fErrorCodes[2] += ((fHC->fBufferCorrupted & 1) << 6);
- fHC->fErrorCodes[2] += ((fHC->fEOTECorrupted & 1) << 7);
- fHC->fErrorCodes[2] += ((fHC->fDataCorrupted & 1) << 8);
-
- if (fHC->fEOTECorrupted != kTRUE) SeekEndOfData();
-
-/*
- if (fWarnError) {
- AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));
- AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));
- }
-*/ // [mj temp]
- }
- else SeekEndOfData(); // make sure that finish off with the end of data markers
-
- // set pritrigger phase since it is only avaliable after decoding HC header
- digitsparam->SetPretriggerPhase(det,GetPreTriggerPhase());
-
- // copy tracklets in memory into tracklet container
- if (trackletContainer) {
- ntracklets = GetNTracklets();
- // copy tracklet words to trackletContainer array
- if(ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets);
- }
-
- // copy error codes in memory into error container
- if (errorCodeContainer) {
- nErrors = GetNErrors();
- if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411);
- }
-
- }// end of while
-
- return det;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::Init()
-{
- //
- // Initialize geometry and fee parameters
- //
- TDirectory *saveDir = gDirectory;
-
- if (!fGeometry) {
- fGeometry = new AliTRDgeometry();
- }
-
- if (!fGeometry) {
- AliError("Geometry FAILED!");
- return kFALSE;
- }
-
- fTRDfeeParam = AliTRDfeeParam::Instance();
- if (!fTRDfeeParam) {
- AliError("AliTRDfeeParam FAILED!");
- return kFALSE;
- }
-
- fMaxADCgeom = (Int_t)fGeometry->ADCmax();
-
- ResetCounters(); // fBufferRead is set to kFALSE - important
-
- saveDir->cd();
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::InitBuffer(void *buffer, UInt_t length)
-{
- //
- // set initial information about the buffer
- //
- if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));
- if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041)
- return kFALSE;
-
- ResetCounters();
-
- fpBegin = (UInt_t *)buffer;
-
- if (WORD_SIZE == 0) {
- AliFatal("Strange word size. size of UInt_t == 0");
- return kFALSE;
- }
-
- fWordLength = length/WORD_SIZE;
- fpEnd = fpBegin + fWordLength;
- fpPos = fpBegin;
-
- 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;
- }
-
- SwapOnEndian();
-
- 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 ----------------------------------------------"));
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeSMHeader(void *buffer, UInt_t length)
-{
- //
- // decode one sm data in buffer
- //
- ResetIterators();
-
- if (InitBuffer(buffer, length) == kFALSE) {
- if (fWarnError) AliError("InitBuffer failed.");
- return kFALSE;
- }
-
- if (DecodeGTUheader()== kFALSE)
- return kFALSE;
-
- Int_t nLinkErrors=0;
- 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;
- fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error
- nLinkErrors++;
- //continue;
- }
-
- if (fpPos >= fpEnd) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
- if (fWarnError) AliError("Link data missing.");
- break;
- }
-
- // set det number using SM header
- fHC = &fStack->fHalfChambers[ilink];
- fHC->fSM = fRawReader->GetEquipmentId() - 1024;
- fHC->fStack = fStackNumber;
- fHC->fLayer = Int_t(fStackLinkNumber/2.);
- fHC->fSide = fStackLinkNumber%2;
- fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);
- fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);
- fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
- fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
- }
- }
-
- // set number of timebin to be used in the digit container
- if (nLinkErrors>30) fGlobalNTimeBins=30;
- else if (!fIsTimeBinSet) {
- fpPosTemp = fpPos;
- SetGlobalNTimebins();
- fIsTimeBinSet = kTRUE;
- }
-
- ResetIterators(); // need to do it again for Next() function
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeGTUheader()
-{
- //
- // 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++;
- } // iword
- } // istack
- }
- else {
- return kFALSE;
- }
- }
- else {
- if (fWarnError) AliWarning("No additional sm headers and stack index words present.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
- return kFALSE;
- }
-
- if (fpPos < fpEnd) {
- if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
- }
- else {
- if (fWarnError) AliWarning("No data just after GTU headers.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
- return kFALSE;
- }
-
- if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-void AliTRDrawFastStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
-{
- //
- // decode Stack #i Index Word
- // The Stack #i Index Word is a 32-Bit word with 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;
- }
- }
-}
-
-//--------------------------------------------------------
-void AliTRDrawFastStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
-{
- //
- // decode stack header
- //
- 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);
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeTracklets()
-{
- //
- // decode tracklets
- //
- fLinkTrackletCounter = 0; // tracklet counter of this link
- fEndOfTrackletCount = 0; // tracklet endmarker counter of this link
- fHC->fNTracklets = 0; // number of tracklet of this link, should be less than 256
-
- if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
-
- 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));
-
- fLinkTrackletCounter++;
-
- if (fLinkTrackletCounter > MAXTRACKLETSPERHC) {
- if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d. Tracklets are wrong either GTU header has problem",
- fLinkTrackletCounter, MAXTRACKLETSPERHC));
- if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets");
- fHC->fErrorCodes[1] = 1;
- return kFALSE;
- }
-
- fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into memory
- fpPos++;
- }
-
- fHC->fNTracklets = fLinkTrackletCounter;
-
- 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));
-
- fEndOfTrackletCount++;
- fpPos++;
- }
-
- if (fEndOfTrackletCount < 2) {
- if (fgDebugFlag) AliDebug(11,"End of tracklets word missing");
- if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing");
- fHC->fErrorCodes[1] += 2;
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-void AliTRDrawFastStream::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;
- }
- }
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeHC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits,
- AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2,
- AliTRDSignalIndex *indexes)
-{
- //
- // decode hc header and data
- //
- if (fpPos >= fpEnd) {
- fHC->fCorrupted += 1;
- if (fWarnError) AliError("No data(including HC header) in the buffer");
- return kFALSE;;
- }
-
- if (DecodeHCheader() == kFALSE) {
- if (fWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));
- return kFALSE;
- }
- else {
- fpPos++;
- if (fpPos >= fpEnd) {
- fHC->fCorrupted += 2;
- if (fWarnError) AliError("No data right after HC header in the buffer");
- return kFALSE;
- }
- }
-
- if ((fHC->fRawVMajor & 64) == 64) { // test pattern data
- AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);
- if (tpStream->DecodeTPdata() == kFALSE) {
- if (fWarnError) AliError("Failed to decode test pattern data");
- return kFALSE;
- }
- return kTRUE;
- }
-
- fHC->fMCMmax = 0; // count number of mcms in a hc
- while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) {
-
- ResetPerMCM(); // reset for every mcm
-
- if (fHC->fMCMmax > TRDMAXMCM) {
- fHC->fCorrupted += 4;
- if (fgDebugFlag) AliDebug(11,"More mcm data than expected");
- return kFALSE;
- }
-
- if (DecodeMCMheader() == kFALSE) {
-
- // encode mcm level error codes
- fHC->fErrorCodes[fHC->fMCMmax+2] += fMCM.fMCMhdCorrupted;
- fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fADCmaskCorrupted << 4);
- fHC->fErrorCodes[fHC->fMCMmax+2] += ((fMCM.fDataCorrupted & 1) << 6);
- fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fMCM << 7); // encode MCM number
- fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fROB << 11); // encode ROB number
-
- 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 {
- if (SeekNextMCMheader() == kFALSE)
- return kFALSE;
- continue;
- }
- }
-
- fHC->fMCMmax++;
-
- if (fMCM.fADCmax > 0) {
- fpPos++;
- if (fpPos >= fpEnd) {
- fHC->fBufferCorrupted = kTRUE;
- if (fgDebugFlag) AliDebug(11, Form("Buffer ends in the middle of data"));
- return kFALSE;
- }
-
- fADCnumber = 0;
- for (Int_t iadc = 0; iadc < fMCM.fADCmax; iadc++) {
- fADCnumber = fMCM.fADCchannel[iadc];
- fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber);
- fCOL = fTRDfeeParam->GetPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber);
-
- if (fADCnumber <= 1 || fADCnumber == fMaxADCgeom - 1) // if adc number = 0, 1, 20
- fIsShared = kTRUE;
- else
- fIsShared = kFALSE;
-
- if (fpPos + fMCM.fSingleADCwords >= fpEnd) {
- fHC->fBufferCorrupted = kTRUE;
- if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");
- return kFALSE;
- }
-
- //if (GetGlobalNTimeBins() < 31){
- if (fHC->fTimeBins < 31){
- if (DecodeADC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {
- return kFALSE;
- }
- }
- //else if (GetGlobalNTimeBins() > 32) {
- else if (fHC->fTimeBins > 32) {
- if (DecodeADCExtended(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {
- return kFALSE;
- }
- }
- else { // nsamples = 31, 32 are not implemented in the TRAP and should never happen
- if (fWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!");
- }
-
- } // iadc
- }
- else { // if there is no adc activated
- fpPos++;
- }
- } // mcm loop
-
- if (fpPos >= fpEnd) {
- fHC->fBufferCorrupted = kTRUE;
- if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. Not enough data in the buffer.");
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeHCheader()
-{
- //
- // decode the half chamber header
- // if it fails to decode HC header for both H0 and H1, return kFALSE
- //
- if (DecodeHCwordH0(fpPos, fHC) == kFALSE)
- return kFALSE;
-
- if (fHC->fNExtraWords > 0) {
- fpPos++;
- if (fpPos < fpEnd) {
- if (DecodeHCwordH1(fpPos, fHC) == kFALSE)
- return kFALSE;
- }
- else {
- fHC->fBufferCorrupted = kTRUE;
- if (fgDebugFlag) AliDebug(11,"Expected HC header word H1. Fail due to buffer END.");
- return kFALSE;
- }
- }
-
- if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
- if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
-
- if (IsHCheaderOK() == kFALSE) {
- fHC->fH0Corrupted += 2;
- if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-Bool_t AliTRDrawFastStream::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->fSMHCheader = HC_SM_NUMBER(vword);
- hc->fStackHCheader = HC_STACK_NUMBER(vword);
- hc->fLayerHCheader = HC_LAYER_NUMBER(vword);
- hc->fSideHCheader = HC_SIDE_NUMBER(vword);
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
-{
- //
- // decode the hc header word 1
- //
- UInt_t vword = *word;
- hc->fPos[1] = (UInt_t*)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+1) ));
- return kFALSE;
- }
- hc->fTimeBins = HC_NTIMEBINS(vword);
- hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);
- hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);
- hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::IsHCheaderOK()
-{
- //
- // check insanity of half chamber header
- //
- if (fHC->fStackHCheader < 0 || fHC->fStackHCheader > 4) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStackHCheader));
- return kFALSE;
- }
-
- if (fHC->fLayerHCheader < 0 || fHC->fLayerHCheader >= AliTRDgeometry::kNlayer) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayerHCheader));
- return kFALSE;
- }
-
- if (fHC->fSideHCheader < 0 || fHC->fSideHCheader > 1) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSideHCheader));
- return kFALSE;
- }
-
- if (fHC->fSMHCheader != fHC->fSM) {
- if (fgDebugFlag) AliDebug(11,Form("Missmatch: SM number between HC header %d and GTU link mask %d",
- fHC->fSMHCheader, fHC->fSM));
- return kFALSE;
- }
-
- if (fgStackNumberChecker) {
- if (fHC->fStackHCheader != fHC->fStack) {
- if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",
- fHC->fStackHCheader, fHC->fStack));
- return kFALSE;
- }
- }
-
- if (fgStackLinkNumberChecker) {
- if (fHC->fLayerHCheader * 2 + fHC->fSideHCheader != fHC->fLayer * 2 + fHC->fSide) {
- if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",
- fHC->fLayerHCheader, fHC->fLayer, DumpStackInfo(fStack)));
- return kFALSE;
- }
- }
-
- // SLOW GEOM : consistancy check with geometry
- 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 (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;
- }
-
- if (fHC->fROC < 0) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
- return kFALSE;
- }
-
- if (fHC->fRowMax < 1) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");
- return kFALSE;
- }
-
- if (fHC->fColMax < 1) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeMCMheader()
-{
- //
- // decode the mcm header
- //
- DecodeMCMheader(fpPos, &fMCM);
-
- if (fHC->fEOTECorrupted == kTRUE) {
- fpPos--;
- return kFALSE;
- }
-
- fMCM.fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM.fROB, fMCM.fMCM);
-
- 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->fEOTECorrupted == kTRUE) {
- fpPos--;
- return kFALSE;
- }
- MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM);
- fMCM.fAdcDataPos = fpPos + 1;
- }
- else {
- if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");
- fHC->fBufferCorrupted = kTRUE;
- return kFALSE;
- }
- }
- else {
- UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;
- DecodeMask(&dummyMask, &fMCM);
- MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM);
- fMCM.fAdcDataPos = fpPos + 1;
- }
- if (IsMCMheaderOK() == kFALSE)
- return kFALSE;
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-void AliTRDrawFastStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
-{
- //
- // decode the mcm header
- //
- UInt_t vword = *word;
-
- if (vword == END_OF_TRACKLET_MARKERNEW) {
- if (fWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
- fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC
- }
-
- mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error
- if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) {
- fHC->fDataCorrupted = kTRUE;
- AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));
- }
-
- mcm->fROB = MCM_ROB_NUMBER(vword);
- mcm->fMCM = MCM_MCM_NUMBER(vword);
- mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
- mcm->fPos = (UInt_t*)word;
-}
-
-//--------------------------------------------------------
-UInt_t AliTRDrawFastStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
-{
- //
- // get the adc mask
- //
- UInt_t vword = *word;
-
- mcm->fADCMask = 0;
- mcm->fADCcount = 0;
- mcm->fADCMaskWord = vword;
-
- if (vword == END_OF_TRACKLET_MARKERNEW) {
- if (fWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));
- fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC
- }
-
- if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {
- mcm->fADCMask = MCM_ADCMASK_VAL(vword);
- mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
- }
- else {
- mcm->fADCMask = 0xffffffff;
- mcm->fADCmaskCorrupted = 1; // mcm adc mask error
- fHC->fDataCorrupted = kTRUE;
- if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
- }
-
- return mcm->fADCMask;
-}
-
-//--------------------------------------------------------
-void AliTRDrawFastStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
-{
- //
- // decode the adc mask - adcs to be read out
- //
- 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++;
- }
- }
- }
- if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility
- mcm->fADCmaskCorrupted += 2;
- fHC->fDataCorrupted = kTRUE;
- if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n",
- mcm->fADCcount, mcm->fADCmax, *fMCM.fPos));
- }
-}
-
-//--------------------------------------------------------
-void AliTRDrawFastStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
-{
- //
- // count the expected mcm words for a given tbins
- //
- mcm->fSingleADCwords = 0;
- mcm->fSingleADCwords = (fTbins-1)/3+1;
- if (fTbins > 32) mcm->fSingleADCwords = 10; // if the timebin is more than 30, then fix the number of adc words to 10
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::IsMCMheaderOK()
-{
- //
- // 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 current MCM %d \n", fMCM.fMCM));
- }
- }
-
- if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) {
- if ( fMCM.fROB < fgLastROB ) {
- if((fMCM.fMCMhdCorrupted & 2) == 0) fMCM.fMCMhdCorrupted += 2;
- AliDebug(11,Form("ROB number from last MCM is larger: ROB # from current MCM %d \n", fMCM.fROB));
- }
- else fgLastROB = fMCM.fROB;
- }
-
- fgLastHC = fHC->fLayer*2 + fHC->fSide;
-
- if (fEventCounter == 0) {
- fEventCounter = fMCM.fEvCounter;
- }
-
- 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)));
- }
-
- 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 ( fMCM.fADCmaskCorrupted > 0 )
- return kFALSE;
-
- if ( fMCM.fMCMhdCorrupted > 0 )
- return kFALSE;
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeADC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits,
- AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2,
- AliTRDSignalIndex *indexes)
-{
- //
- // decode single ADC channel
- //
- if(fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
- if(fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
-
- fTbinADC = 0;
- Bool_t isWritten = kFALSE;
-
- for (Int_t iw = 0; iw < fMCM.fSingleADCwords; iw++) {
- if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
- if (fWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
- fHC->fEOTECorrupted = kTRUE;
- fpPos--;
- return kFALSE;
- }
- if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! [Expected mask: 0x%08x Current mask: 0x%08x] ADC channel number: %02d MCM= %s ",
- fMaskADCword, ADC_WORD_MASK(*fpPos), fADCnumber, DumpMCMinfo(&fMCM)));
- // encode adc level error codes
- Int_t index = 21*(fMCM.fMCM + 16*int(fMCM.fROB/2)) + fADCnumber;
- fHC->fErrorCodes[index+66] += 1;
- if (!isWritten) {
- fHC->fErrorCodes[index+66] += (fADCnumber << 4);;
- fHC->fErrorCodes[index+66] += (fMCM.fMCM << 9);;
- fHC->fErrorCodes[index+66] += (fMCM.fROB << 13);;
- isWritten = kTRUE;
- }
- fMCM.fDataCorrupted = kTRUE;
- fHC->fDataCorrupted = kTRUE;
- fpPos++;
- continue;
- }
- // decode and put into the digit container
- Int_t adcSignals[3];
- adcSignals[0] = ((*fpPos & 0x00000ffc) >> 2);
- adcSignals[1] = ((*fpPos & 0x003ff000) >> 12);
- adcSignals[2] = ((*fpPos & 0xffc00000) >> 22);
-
- if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;};
-
- for (Int_t i = 0; i < 3; i++) {
- digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcSignals[i]);
- indexes->AddIndexRC(GetRow(), GetCol());
- if (digitsManager->UsesDictionaries()) {
- track0->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
- track1->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
- track2->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
- }
- } // i
- fTbinADC += 3;
- fpPos++;
- } // iw
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::DecodeADCExtended(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits,
- AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2,
- AliTRDSignalIndex *indexes)
-{
- //
- // decode single ADC channel
- //
- if(fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);
- if(fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);
-
- Bool_t isWritten = kFALSE; //for error code recording
-
- fTbinADC = ((*fpPos & 0x000000fc) >> 2);
- fMCM.fSingleADCwords = ((*fpPos & 0x00000f00) >> 8);
-
- Int_t adcFirst2Signals[2];
- adcFirst2Signals[0] = ((*fpPos & 0x003ff000) >> 12);
- adcFirst2Signals[1] = ((*fpPos & 0xffc00000) >> 22);
-
- for (Int_t i = 0; i < 2; i++) {
- digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcFirst2Signals[i]);
- indexes->AddIndexRC(GetRow(), GetCol());
- if (digitsManager->UsesDictionaries()) {
- track0->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
- track1->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
- track2->SetData(GetRow(), GetCol(), fTbinADC + i, 0);
- }
- } // i
-
- fpPos++;
- for (Int_t iw = 0; iw < fMCM.fSingleADCwords-1; iw++) {
- if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {
- if (fWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));
- fHC->fEOTECorrupted = kTRUE;
- fpPos--;
- return kFALSE;
- }
- if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! [Expected mask: 0x%08x Current mask: 0x%08x] ADC channel number: %02d MCM= %s ",
- fMaskADCword, ADC_WORD_MASK(*fpPos), fADCnumber, DumpMCMinfo(&fMCM)));
- // encode adc level error codes
- Int_t index = 21*(fMCM.fMCM + 16*int(fMCM.fROB/2)) + fADCnumber;
- fHC->fErrorCodes[index+66] += 1;
- if (!isWritten) {
- fHC->fErrorCodes[index+66] += (fADCnumber << 4);;
- fHC->fErrorCodes[index+66] += (fMCM.fMCM << 9);;
- fHC->fErrorCodes[index+66] += (fMCM.fROB << 13);;
- isWritten = kTRUE;
- }
- fMCM.fDataCorrupted = kTRUE;
- fHC->fDataCorrupted = kTRUE;
- fpPos++;
- continue;
- }
- // decode and put into the digit container
- Int_t adcSignals[3];
- adcSignals[0] = ((*fpPos & 0x00000ffc) >> 2);
- adcSignals[1] = ((*fpPos & 0x003ff000) >> 12);
- adcSignals[2] = ((*fpPos & 0xffc00000) >> 22);
-
- if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;};
- for (Int_t i = 0; i < 3; i++) {
- digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + 2 + i, adcSignals[i]);
- indexes->AddIndexRC(GetRow(), GetCol());
- if (digitsManager->UsesDictionaries()) {
- track0->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);
- track1->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);
- track2->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);
- }
- } // i
- fTbinADC += 3;
- fpPos++;
- } // iw
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::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;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::SeekNextMCMheader()
-{
- //
- // 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;
- }
- if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
- fHC->fEOTECorrupted = kTRUE;
- return kFALSE;
- }
- fpPos++;
- }
-
- SeekEndOfData();
- return kFALSE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::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");
- fHC->fEOTECorrupted = kTRUE;
- return kFALSE;
- }
- fpPos++;
- iwcounter++;
- } // while
-
- if (iwcounter == iw) {
- fpPos++;
- return kTRUE;
- }
-
- if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
- return kFALSE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::SetGlobalNTimebins()
-{
- // get number of time bin info from HC headers then set
- Int_t nHCs=0;
- while (SetNTimebins()==kFALSE){
- if (fgDebugFlag) AliDebug(11,Form("Failed to get number of time bin information from the %sth HC",nHCs));
- nHCs++;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::SetNTimebins()
-{
- // goes to the HC header position
- while (!(*fpPosTemp == END_OF_TRACKLET_MARKERNEW) && fpPosTemp < fpEnd) {
- fpPosTemp++;
- }
- while (*fpPosTemp == END_OF_TRACKLET_MARKERNEW) {
- fpPosTemp++;
- }
- // skip H0
- fpPosTemp++;
-
- UInt_t vword = 0;
- if (!(vword = *fpPosTemp)) {
- fGlobalNTimeBins = 30; // default number of timebins
- return kFALSE;
- }
-
- // get the number of time bins
- if (HC_HEADER_MASK_ERR(vword) == 0) {
- fGlobalNTimeBins = HC_NTIMEBINS(vword);
- if (fGlobalNTimeBins > 64 || fGlobalNTimeBins < 10) return kFALSE; // minimal protection
- }
- else
- return kFALSE;
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawFastStream::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]);
- }
- tsreturn += "\n";
-
- AliInfo(tsreturn.Data());
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawFastStream::DumpSMInfo(const struct AliTRDrawSM *sm)
-{
- //
- // format the string with the sm info
- //
- 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]);
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawFastStream::DumpStackInfo(const struct AliTRDrawStack *st)
-{
- //
- // 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]);
-
-}
-//--------------------------------------------------------
-const char *AliTRDrawFastStream::DumpHCinfoH0(const struct AliTRDrawHC *hc)
-{
- //
- // dump the hc header word 0 in strings
- //
- if (!hc)
- return Form("Unable to dump. Null received as parameter!?!");
- 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->fRawVMajor, fRawReader->GetEquipmentId()-1024, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawFastStream::DumpHCinfoH1(const struct AliTRDrawHC *hc)
-{
- //
- // dump the hc header word 1 in strings
- //
- 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->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawFastStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
-{
- //
- // dump mcm info in strings
- //
- 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);
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawFastStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
-{
- //
- // mcm adc mask in strings
- //
- 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]);
- }
- tsreturn += "";
- return tsreturn.Data();
-}
-
-
+/**************************************************************************\r
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
+* *\r
+* Author: The ALICE Off-line Project. *\r
+* Contributors are mentioned in the code where appropriate. *\r
+* *\r
+* Permission to use, copy, modify and distribute this software and its *\r
+* documentation strictly for non-commercial purposes is hereby granted *\r
+* without fee, provided that the above copyright notice appears in all *\r
+* copies and that both the copyright notice and this permission notice *\r
+* appear in the supporting documentation. The authors make no claims *\r
+* about the suitability of this software for any purpose. It is *\r
+* provided "as is" without express or implied warranty. *\r
+**************************************************************************/\r
+\r
+/* $Id: AliTRDrawFastStream.cxx 27797 2008-08-05 14:37:22Z cblume $ */\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+// //\r
+// This class provides access to TRD digits in raw data in a way of streaming //\r
+// //\r
+// It loops over all TRD digits in the raw data given by the AliRawReader. //\r
+// The Next method goes to the next digit. If there are no digits left //\r
+// it returns kFALSE. //\r
+// Several getters provide information about the current digit. //\r
+// //\r
+// Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) // \r
+// Author: MinJung Kweon (minjung@physi.uni-heidelberg.de) //\r
+// //\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+#include "TFile.h"\r
+\r
+#include "AliTRDrawFastStream.h"\r
+#include "AliTRDgeometry.h"\r
+#include "AliTRDfeeParam.h"\r
+#include "AliTRDdigitsManager.h"\r
+#include "AliTRDarrayDictionary.h"\r
+#include "AliTRDarrayADC.h"\r
+#include "AliTRDSignalIndex.h"\r
+#include "AliTRDdigitsParam.h"\r
+#include "AliTRDrawTPStream.h"\r
+\r
+#include "AliRawReader.h"\r
+\r
+#define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa\r
+#define END_OF_TRACKLET_MARKERNEW 0x10001000\r
+#define ENDOFRAWDATAMARKER 0x00000000\r
+#define WORD_SIZE sizeof(UInt_t) // size of a word in bytes\r
+#define EXTRA_LEAD_WORDS 24\r
+#define CDH_WORDS 8\r
+\r
+#define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w\r
+#define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m\r
+\r
+// SM index word masks:\r
+#define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16) \r
+#define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)\r
+#define STACK_MASK(w) ((w) & 0x1f)\r
+\r
+// Stack word masks\r
+#define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)\r
+#define STACK_LINK_WORD(w) ((w) & 0xfff)\r
+#define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1) // 0 if physics data\r
+#define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data\r
+#define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1) // 0 if OK\r
+#define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1) // 0 if OK\r
+\r
+// HC word masks\r
+//#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x80000003)) == (0x80000001) ? 0 : 1) // 0 if OK!!!\r
+#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK!!!\r
+\r
+// HC word 0\r
+#define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)\r
+#define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)\r
+#define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)\r
+#define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)\r
+#define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)\r
+#define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)\r
+#define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)\r
+#define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)\r
+#define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)\r
+#define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)\r
+\r
+// HC word 1\r
+#define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)\r
+#define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)\r
+#define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)\r
+#define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,2)\r
+\r
+// MCM word and ADC mask\r
+#define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!\r
+#define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK!!!\r
+#define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)\r
+#define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)\r
+#define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)\r
+#define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)\r
+#define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)\r
+\r
+#define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated \r
+#define ADCDATA_VAL1 0x2 // updated \r
+#define ADCDATA_VAL2 0x3 // updated \r
+\r
+//--------------------------------------------------------\r
+#define ADC_WORD_MASK(w) ((w) & 0x3)\r
+//--------------------------------------------------------\r
+ClassImp(AliTRDrawFastStream)\r
+\r
+Bool_t AliTRDrawFastStream::fgExtraSkip = kFALSE;\r
+Bool_t AliTRDrawFastStream::fgSkipCDH = kFALSE;\r
+Bool_t AliTRDrawFastStream::fgCleanDataOnly = kFALSE;\r
+Bool_t AliTRDrawFastStream::fgDebugFlag = kTRUE;\r
+Bool_t AliTRDrawFastStream::fgEnableMemoryReset = kTRUE;\r
+Bool_t AliTRDrawFastStream::fgStackNumberChecker = kTRUE;\r
+Bool_t AliTRDrawFastStream::fgStackLinkNumberChecker = kFALSE;\r
+Bool_t AliTRDrawFastStream::fgSkipData = kTRUE;\r
+Bool_t AliTRDrawFastStream::fgEnableDecodeConfigData = kFALSE;\r
+Int_t AliTRDrawFastStream::fgDumpHead = -1;\r
+Short_t AliTRDrawFastStream::fgMCMordering[] =\r
+ {\r
+ 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 \r
+ };\r
+Short_t AliTRDrawFastStream::fgROBordering[] =\r
+ {\r
+ 0, 1, 2, 3\r
+ };\r
+\r
+Int_t AliTRDrawFastStream::fgLastHC = -1;\r
+Int_t AliTRDrawFastStream::fgLastROB = -1;\r
+Int_t AliTRDrawFastStream::fgLastIndex = -1;\r
+\r
+//--------------------------------------------------------\r
+AliTRDrawFastStream::AliTRDrawFastStream()\r
+ : AliTRDrawStreamBase()\r
+ , fSM()\r
+ , fStack(0)\r
+ , fHC(0)\r
+ , fLastHC(0)\r
+ , fMCM()\r
+ , fpPos(0)\r
+ , fpBegin(0)\r
+ , fpEnd(0)\r
+ , fWordLength(0)\r
+ , fpPosTemp(0)\r
+ , fGlobalNTimeBins(0)\r
+ , fIsTimeBinSet(kFALSE)\r
+ , fStackNumber(-1)\r
+ , fStackLinkNumber(-1)\r
+ , fLinkTrackletCounter(-1)\r
+ , fEndOfTrackletCount(-1)\r
+ , fNWordsCounter(-1)\r
+ , fMaskADCword(0)\r
+ , fTbinADC(0)\r
+ , fEventCounter(0)\r
+ , fLastEventCounter(0)\r
+ , fSharedPadsOn(kTRUE)\r
+ , fMaxADCgeom(0)\r
+ , fADCnumber(0)\r
+ , fCOL(0)\r
+ , fExtendedCOL(0)\r
+ , fIsShared(0)\r
+ , fWarnError(kTRUE)\r
+ , fBufferRead(0)\r
+ , fGeometry(0)\r
+ , fRawReader(0)\r
+ , fTRDfeeParam(0)\r
+ , fCommonAdditive(0)\r
+{\r
+ //\r
+ // default constructor\r
+ //\r
+\r
+ if (Init() == kFALSE) {\r
+ AliWarning("Unable to Init."); \r
+ }\r
+}\r
+\r
+//--------------------------------------------------------\r
+AliTRDrawFastStream::AliTRDrawFastStream(AliRawReader *rawReader)\r
+ : AliTRDrawStreamBase(rawReader)\r
+ , fSM()\r
+ , fStack(0)\r
+ , fHC(0)\r
+ , fLastHC(0)\r
+ , fMCM()\r
+ , fpPos(0)\r
+ , fpBegin(0)\r
+ , fpEnd(0)\r
+ , fWordLength(0)\r
+ , fpPosTemp(0)\r
+ , fGlobalNTimeBins(0)\r
+ , fIsTimeBinSet(kFALSE)\r
+ , fStackNumber(-1)\r
+ , fStackLinkNumber(-1)\r
+ , fLinkTrackletCounter(-1)\r
+ , fEndOfTrackletCount(-1)\r
+ , fNWordsCounter(-1)\r
+ , fMaskADCword(0)\r
+ , fTbinADC(0)\r
+ , fEventCounter(0)\r
+ , fLastEventCounter(0)\r
+ , fSharedPadsOn(kTRUE)\r
+ , fMaxADCgeom(0)\r
+ , fADCnumber(0)\r
+ , fCOL(0)\r
+ , fExtendedCOL(0)\r
+ , fIsShared(0)\r
+ , fWarnError(kTRUE)\r
+ , fBufferRead(0)\r
+ , fGeometry(0)\r
+ , fRawReader(rawReader)\r
+ , fTRDfeeParam(0)\r
+ , fCommonAdditive(0)\r
+{\r
+ //\r
+ // default constructor\r
+ //\r
+ if (fRawReader) {\r
+ if (Init() == kFALSE) {\r
+ AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )"); \r
+ }\r
+ }\r
+ else {\r
+ AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+AliTRDrawFastStream::AliTRDrawFastStream(const AliTRDrawFastStream& /*st*/)\r
+ : AliTRDrawStreamBase()\r
+ , fSM()\r
+ , fStack(0)\r
+ , fHC(0)\r
+ , fLastHC(0)\r
+ , fMCM()\r
+ , fpPos(0)\r
+ , fpBegin(0)\r
+ , fpEnd(0)\r
+ , fWordLength(0)\r
+ , fpPosTemp(0)\r
+ , fGlobalNTimeBins(0)\r
+ , fIsTimeBinSet(kFALSE)\r
+ , fStackNumber(-1)\r
+ , fStackLinkNumber(-1)\r
+ , fLinkTrackletCounter(-1)\r
+ , fEndOfTrackletCount(-1)\r
+ , fNWordsCounter(-1)\r
+ , fMaskADCword(0)\r
+ , fTbinADC(0)\r
+ , fEventCounter(0)\r
+ , fLastEventCounter(0)\r
+ , fSharedPadsOn(kTRUE)\r
+ , fMaxADCgeom(0)\r
+ , fADCnumber(0)\r
+ , fCOL(0)\r
+ , fExtendedCOL(0)\r
+ , fIsShared(0)\r
+ , fWarnError(kTRUE)\r
+ , fBufferRead(0)\r
+ , fGeometry(0)\r
+ , fRawReader(0)\r
+ , fTRDfeeParam(0)\r
+ , fCommonAdditive(0)\r
+{\r
+ //\r
+ // Copy constructor\r
+ // \r
+ AliError("Not implemeneted.");\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::SetRawVersion(Int_t fraw)\r
+{\r
+ //\r
+ // function provided for backward compatibility\r
+ //\r
+ AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");\r
+ fraw = 0; // avoid warnings\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+AliTRDrawFastStream::~AliTRDrawFastStream()\r
+{\r
+ //\r
+ // destructor\r
+ //\r
+ delete fGeometry;\r
+}\r
+\r
+//------------------------------------------------------------\r
+\r
+AliTRDrawFastStream &\r
+AliTRDrawFastStream::operator=(const AliTRDrawFastStream &)\r
+{\r
+ //\r
+ // we are not using this functionality\r
+ //\r
+ AliFatal("May not use.");\r
+ return *this;\r
+}\r
+\r
+//___________________________________________________________\r
+void AliTRDrawFastStream::SwapOnEndian()\r
+{\r
+ //\r
+ // Check the endian and swap if needed\r
+ //\r
+ int itemp = 1;\r
+ char* ptemp = (char*) &itemp;\r
+ if (ptemp[0] != 1)\r
+ {\r
+ if (fgDebugFlag) AliDebug(8, "Swapping.");\r
+\r
+ fpPos = fpBegin;\r
+ UInt_t iutmp = 0;\r
+ while (fpPos < fpEnd)\r
+ {\r
+ fpPos += 1;\r
+ iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |\r
+ ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));\r
+ // here we override the value in the buffer!\r
+ *fpPos = iutmp; \r
+ }\r
+ fpPos = fpBegin;\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::SkipWords(UInt_t iw)\r
+{\r
+ //\r
+ // Skip words corresponding to iw\r
+ //\r
+ if ( fpPos + iw < fpEnd ) {\r
+ fpPos += iw;\r
+ return kTRUE;\r
+ }\r
+ else {\r
+ if (fWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::SetReader(AliRawReader *reader)\r
+{\r
+ // \r
+ // set raw reader pointer\r
+ // \r
+ if (reader != 0) {\r
+ fRawReader = reader;\r
+ if (fRawReader) {\r
+ return Init();\r
+ }\r
+ else {\r
+ AliWarning("Unable to setup reader.");\r
+ return kFALSE;\r
+ }\r
+ }\r
+ else {\r
+ AliWarning("AliRawReader argument is 0.");\r
+ fRawReader = 0;\r
+ }\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Int_t AliTRDrawFastStream::NextBuffer()\r
+{\r
+ //\r
+ // return -1 if no more buffers available\r
+ // return 0 if SMHeader decoding failed \r
+ // return 1 if SMHeader dedoding is OK\r
+ // \r
+ if (fRawReader != 0) {\r
+ UChar_t *buffer = 0;\r
+ UInt_t length = 0;\r
+ Bool_t kBufferSet = fRawReader->ReadNextData(buffer);\r
+ if (kBufferSet == kTRUE) {\r
+ if (fgDebugFlag) AliDebug(9, "Buffer is set.");\r
+ length = fRawReader->GetDataSize();\r
+ if (fgExtraSkip == kTRUE) {\r
+ buffer += EXTRA_LEAD_WORDS * WORD_SIZE;\r
+ length -= EXTRA_LEAD_WORDS * WORD_SIZE;\r
+ }\r
+\r
+ if (fgSkipCDH == kTRUE) {\r
+ buffer += CDH_WORDS * WORD_SIZE;\r
+ length -= CDH_WORDS * WORD_SIZE; \r
+ }\r
+\r
+ if (length > 0) {\r
+ if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));\r
+ if (fgEnableMemoryReset) ResetMemory(); \r
+ if (DecodeSMHeader((void*)buffer, length) == kTRUE)\r
+ return 1;\r
+ else\r
+ return 0;\r
+ }\r
+ }\r
+ else {\r
+ return -1;\r
+ }\r
+ }\r
+\r
+ return -1;\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawFastStream::ResetCounters()\r
+{\r
+ //\r
+ // reset some global counters\r
+ //\r
+ fBufferRead = kFALSE; // kFALSE if no buffer read\r
+\r
+ fSM.fActiveStacks = 0;\r
+ fSM.fNexpectedHalfChambers = 0;\r
+\r
+ fLastEventCounter = 0;\r
+ fEventCounter = 0;\r
+\r
+ ResetIterators();\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawFastStream::ResetIterators()\r
+{\r
+ //\r
+ // reset data which should be reset every sm\r
+ //\r
+ fStackNumber = 0; \r
+ fStackLinkNumber = 0; \r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawFastStream::ResetPerSM()\r
+{\r
+ //\r
+ // reset every SM\r
+ //\r
+ fSM.fHeaderSize = 0;\r
+ fSM.fTrackletEnable = kFALSE;\r
+ fSM.fCorrupted = 0;\r
+ fSM.fNexpectedHalfChambers = 0;\r
+ fSM.fNexpectedHalfChambers = 0;\r
+ fSM.fPos = NULL;\r
+ for (Int_t i=0; i<5; i++) {\r
+ fSM.fStackActive[i] = kFALSE;\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawFastStream::ResetPerStack()\r
+{\r
+ //\r
+ // reset every Stack\r
+ //\r
+ fStack->fHeaderSize = 0;\r
+ fStack->fActiveLinks = 0;\r
+ fStack->fPos = NULL;\r
+ for (Int_t i=0; i<12; i++) {\r
+ fStack->fLinksActive[i] = kFALSE;\r
+ fStack->fLinksDataType[i] = 0;\r
+ fStack->fLinksMonitor[i] = 0;\r
+ fStack->fLinkMonitorError[i] = 0;\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawFastStream::ResetPerHC()\r
+{\r
+ //\r
+ // reset every HC\r
+ //\r
+ fEventCounter = 0;\r
+ fHC->fNTracklets = 0;\r
+ fHC->fSpecialRawV = 0;\r
+ fHC->fRawVMajor = 0;\r
+ fHC->fRawVMajorOpt = 0;\r
+ fHC->fRawVMinor = 0;\r
+ fHC->fNExtraWords = 0;\r
+ fHC->fDCSboard = 0;\r
+ fHC->fTimeBins = 0;\r
+ fHC->fBunchCrossCounter = 0;\r
+ fHC->fPreTriggerCounter = 0;\r
+ fHC->fPreTriggerPhase = 0;\r
+ fHC->fMCMmax = 0;\r
+\r
+ fHC->fSM = 0;\r
+ fHC->fStack = 0;\r
+ fHC->fStackHCheader = 0;\r
+ fHC->fLayer = 0;\r
+ fHC->fLayerHCheader = 0;\r
+ fHC->fSide = 0;\r
+ fHC->fSideHCheader = 0;\r
+ fHC->fDET = 0;\r
+ fHC->fROC = 0;\r
+ fHC->fRowMax = 0;\r
+ fHC->fColMax = 0;\r
+\r
+ fHC->fH0Corrupted = 0;\r
+ fHC->fH1Corrupted = 0;\r
+ fHC->fCorrupted = 0;\r
+ fHC->fEOTECorrupted = kFALSE;\r
+ fHC->fBufferCorrupted = kFALSE;\r
+ fHC->fDataCorrupted = kFALSE;\r
+\r
+ fHC->fNErrors= 0;\r
+ memset(fHC->fErrorCodes, 0, 1411*sizeof(UShort_t)); // initialize error container\r
+ memset(fHC->fTrackletWords, 0, MAXTRACKLETSPERHC*sizeof(UInt_t)); // initialize tracklet container\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawFastStream::ResetPerMCM()\r
+{\r
+ //\r
+ // reset every MCM\r
+ //\r
+ fMCM.fROB = 0;\r
+ fMCM.fMCM = 0;\r
+ fMCM.fROW = 0;\r
+ fMCM.fEvCounter = 0;\r
+ fMCM.fADCMask = 0;\r
+ fMCM.fADCMaskWord = 0;\r
+ fMCM.fADCmax = 0;\r
+ fMCM.fADCcount = 0;\r
+ fMCM.fSingleADCwords = 0;\r
+ fMCM.fMCMhdCorrupted = 0;\r
+ fMCM.fADCmaskCorrupted = 0;\r
+ fMCM.fDataCorrupted = kFALSE;\r
+ fMCM.fPos = NULL;\r
+ fMCM.fAdcDataPos = NULL;\r
+ fMCM.fADCcounter = 0;\r
+\r
+ memset(fMCM.fADCchannel, 0, TRDMAXADC*sizeof(UInt_t));\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawFastStream::ResetMemory()\r
+{\r
+ //\r
+ // initialize all the data members to prevent read data\r
+ // from previous buffer\r
+ //\r
+ ResetPerSM();\r
+ for (Int_t istack=0; istack<5; istack++) {\r
+ fStack = &fSM.fStacks[istack];\r
+ ResetPerStack();\r
+ for (Int_t ilink=0; ilink<12; ilink++) {\r
+ fHC = &fStack->fHalfChambers[ilink];\r
+ ResetPerHC();\r
+ }\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::Next()\r
+{\r
+ //\r
+ // returns with true on next adc read, returns false on errors and end of buffer\r
+ // \r
+ if (fBufferRead) {\r
+ while (fStackNumber < 5 && fSM.fActiveStacks > 0) {\r
+ if (fSM.fStackActive[fStackNumber] == kTRUE) {\r
+ fStack = &fSM.fStacks[fStackNumber];\r
+ while (fStackLinkNumber < 12) {\r
+ if (fStack->fLinksActive[fStackLinkNumber] == kTRUE) {\r
+ //if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0)\r
+ fHC = &fStack->fHalfChambers[fStackLinkNumber];\r
+ //ResetPerHC(); // [mj - you don't need to do? ]\r
+ if (!fHC) {\r
+ AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));\r
+ return kFALSE;\r
+ }\r
+ fStackLinkNumber++;\r
+ return kTRUE;\r
+ } //link active ?\r
+ else fStackLinkNumber++;\r
+ } //stack link number loop \r
+ } //stack active ?\r
+ fStackNumber++;\r
+ fStackLinkNumber = 0;\r
+ } //stack number loop\r
+ } //fBufferRead\r
+\r
+ // go for the next buffer \r
+ if (fRawReader) {\r
+ Int_t nextBuff = NextBuffer();\r
+ while (nextBuff != -1) {\r
+ if (nextBuff > 0) {\r
+ fBufferRead = kTRUE;\r
+ return Next(); \r
+ }\r
+ nextBuff = NextBuffer();\r
+ }\r
+ }\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Int_t AliTRDrawFastStream::NextChamber(AliTRDdigitsManager *digitsManager, UInt_t **trackletContainer, UShort_t **errorCodeContainer) \r
+{\r
+ \r
+ //\r
+ // Fills single chamber digit array \r
+ // Return value is the detector number\r
+ //\r
+ // first of all, you do the SM header decoding only at the beginning of the SM data reading\r
+ // then, every HC, you call Next() which points next HC. then, there you decode the given HC \r
+ // and at the same time, put the digit into digitmanager \r
+ //\r
+ AliTRDarrayADC *digits = 0;\r
+ AliTRDarrayDictionary *track0 = 0;\r
+ AliTRDarrayDictionary *track1 = 0;\r
+ AliTRDarrayDictionary *track2 = 0; \r
+ AliTRDSignalIndex *indexes = 0;\r
+ AliTRDdigitsParam *digitsparam = 0;\r
+\r
+ Int_t lastdet = -1;\r
+ Int_t det = -1;\r
+ Int_t side = -1;\r
+ //Int_t it = 0;\r
+ Int_t ntracklets = 0;\r
+ Int_t nErrors = 0;\r
+\r
+ if (trackletContainer){\r
+ for (Int_t i = 0; i < 2; i++)\r
+ memset(trackletContainer[i], 0, MAXTRACKLETSPERHC*sizeof(UInt_t));\r
+ }\r
+\r
+ if (errorCodeContainer){\r
+ for (Int_t i = 0; i < 2; i++)\r
+ memset(errorCodeContainer[i], 0, 1411*sizeof(UShort_t));\r
+ }\r
+\r
+ while ( Next() ) { // loop over HC \r
+\r
+ // get this information from the GTU header\r
+ det = GetDet();\r
+ side = GetSide();\r
+\r
+ if (det != lastdet) {\r
+ // If new detector found\r
+ if (lastdet == -1) {lastdet = det; fLastHC = fHC;}\r
+ else {fStackLinkNumber--; fHC = fLastHC ; return lastdet;}\r
+\r
+ if (det < 0 || det >= AliTRDgeometry::kNdet) continue;\r
+\r
+ // Add a container for the digits of this detector\r
+ digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);\r
+\r
+ if (digitsManager->UsesDictionaries()) {\r
+ track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);\r
+ track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);\r
+ track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);\r
+ }\r
+\r
+ if (!digits) return -1;\r
+\r
+ //Int_t rowMax = GetRowMax();\r
+ Int_t rowMax = fGeometry->RowmaxC1(); // we use maximum row number among all detectors to reuse memory\r
+ Int_t colMax = GetColMax();\r
+ Int_t ntbins = GetGlobalNTimeBins(); \r
+\r
+ // Set digitsparam variables\r
+ digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();\r
+ digitsparam->SetNTimeBins(det,ntbins);\r
+ fCommonAdditive=10;\r
+ digitsparam->SetADCbaseline(det,fCommonAdditive);\r
+\r
+ // Allocate memory space for the digits buffer\r
+ //if (digits->GetNtime() == 0) {\r
+ if (ntbins != digits->GetNtime()) {\r
+ digits->Allocate(rowMax, colMax, ntbins);\r
+ if (digitsManager->UsesDictionaries()) {\r
+ track0->Allocate(rowMax, colMax, ntbins);\r
+ track1->Allocate(rowMax, colMax, ntbins);\r
+ track2->Allocate(rowMax, colMax, ntbins);\r
+ }\r
+ }\r
+\r
+ indexes = digitsManager->GetIndexes(det);\r
+ indexes->SetSM(GetSM());\r
+ indexes->SetStack(GetStack());\r
+ indexes->SetLayer(GetLayer());\r
+ indexes->SetDetNumber(det);\r
+ if (indexes->IsAllocated() == kFALSE)\r
+ indexes->Allocate(rowMax, colMax, ntbins);\r
+ }\r
+\r
+ if (fSM.fTrackletEnable == kTRUE) { \r
+ if (DecodeTracklets() == kFALSE) {\r
+ SeekEndOfData();\r
+\r
+ if (fWarnError) AliError(Form("Tracklet decoding failed stack %d link %d", GetStack(), fStackLinkNumber));\r
+\r
+ // copy error codes in memory into error container\r
+ if (errorCodeContainer) {\r
+ nErrors = GetNErrors();\r
+ if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411); // [mj temp - optimize] \r
+ }\r
+ \r
+ continue; // if it fails to decode tracklets of this HC, it skips further decoding and goes to next HC \r
+ } \r
+ } \r
+\r
+ // decode hc data\r
+ fgLastROB = -1; // to check mcm number odering \r
+ fgLastIndex = -1 ; // to check mcm number odering \r
+ if (DecodeHC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {\r
+ // encode HC error code\r
+ fHC->fErrorCodes[2] += fHC->fH0Corrupted;\r
+ fHC->fErrorCodes[2] += (fHC->fH1Corrupted << 2);\r
+ fHC->fErrorCodes[2] += (fHC->fCorrupted << 3);\r
+ fHC->fErrorCodes[2] += ((fHC->fBufferCorrupted & 1) << 6); \r
+ fHC->fErrorCodes[2] += ((fHC->fEOTECorrupted & 1) << 7); \r
+ fHC->fErrorCodes[2] += ((fHC->fDataCorrupted & 1) << 8); \r
+\r
+ if (fHC->fEOTECorrupted != kTRUE) SeekEndOfData();\r
+\r
+/*\r
+ if (fWarnError) {\r
+ AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));\r
+ AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));\r
+ }\r
+*/ // [mj temp]\r
+ }\r
+ else SeekEndOfData(); // make sure that finish off with the end of data markers\r
+\r
+ // set pretrigger phase since it is only avaliable after decoding HC header \r
+ digitsparam->SetPretriggerPhase(det,GetPreTriggerPhase());\r
+\r
+ // copy tracklets in memory into tracklet container\r
+ if (trackletContainer) {\r
+ ntracklets = GetNTracklets();\r
+ // copy tracklet words to trackletContainer array \r
+ if(ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets); \r
+ }\r
+\r
+ // copy error codes in memory into error container\r
+ if (errorCodeContainer) {\r
+ nErrors = GetNErrors();\r
+ if(nErrors > 0) memcpy(errorCodeContainer[side], GetErrorCodes(), sizeof(UShort_t) * 1411); \r
+ }\r
+\r
+ }// end of while \r
+\r
+ return det;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::Init()\r
+{\r
+ //\r
+ // Initialize geometry and fee parameters \r
+ //\r
+ TDirectory *saveDir = gDirectory; \r
+ \r
+ if (!fGeometry) {\r
+ fGeometry = new AliTRDgeometry();\r
+ }\r
+ \r
+ if (!fGeometry) {\r
+ AliError("Geometry FAILED!");\r
+ return kFALSE;\r
+ }\r
+\r
+ fTRDfeeParam = AliTRDfeeParam::Instance();\r
+ if (!fTRDfeeParam) {\r
+ AliError("AliTRDfeeParam FAILED!");\r
+ return kFALSE;\r
+ }\r
+\r
+ fMaxADCgeom = (Int_t)fGeometry->ADCmax();\r
+\r
+ ResetCounters(); // fBufferRead is set to kFALSE - important\r
+\r
+ saveDir->cd();\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::InitBuffer(void *buffer, UInt_t length)\r
+{\r
+ // \r
+ // set initial information about the buffer\r
+ //\r
+ if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));\r
+ if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041) \r
+ return kFALSE; \r
+\r
+ ResetCounters();\r
+\r
+ fpBegin = (UInt_t *)buffer;\r
+\r
+ if (WORD_SIZE == 0) {\r
+ AliFatal("Strange word size. size of UInt_t == 0");\r
+ return kFALSE;\r
+ }\r
+\r
+ fWordLength = length/WORD_SIZE;\r
+ fpEnd = fpBegin + fWordLength;\r
+ fpPos = fpBegin;\r
+\r
+ if (fpBegin == 0 || length <= 0) {\r
+ AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));\r
+ return kFALSE;\r
+ }\r
+\r
+ SwapOnEndian();\r
+\r
+ if (fgDumpHead >= 0) {\r
+ if ( fgDumpHead == 0 ) { // dump all words\r
+ AliInfo(Form("---------- Dumping all words from the beginnig of the buffer ----------"));\r
+ if (DumpWords(fpBegin, fWordLength) == kFALSE) AliError("Dump failed. Not enough data.");\r
+ } \r
+ else { \r
+ AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));\r
+ if (DumpWords(fpBegin, fgDumpHead) == kFALSE) AliError("Dump failed. Not enough data.");\r
+ }\r
+ AliInfo(Form("---------- Dumping ended ----------------------------------------------"));\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeSMHeader(void *buffer, UInt_t length)\r
+{\r
+ // \r
+ // decode one sm data in buffer\r
+ // \r
+ ResetIterators(); \r
+\r
+ if (InitBuffer(buffer, length) == kFALSE) {\r
+ if (fWarnError) AliError("InitBuffer failed."); \r
+ return kFALSE;\r
+ }\r
+\r
+ if (DecodeGTUheader()== kFALSE)\r
+ return kFALSE;\r
+\r
+ Int_t nLinkErrors=0;\r
+ for (Int_t istack = 0; istack < 5; istack++) {\r
+ fStackNumber = istack; \r
+ if (fSM.fStackActive[istack] == kFALSE) continue;\r
+ \r
+ fStack = &fSM.fStacks[istack];\r
+ \r
+ fgLastHC = -1; // to check rob number odering \r
+ for (Int_t ilink = 0; ilink < 12; ilink++) {\r
+ fStackLinkNumber = ilink; \r
+ if (fStack->fLinksActive[ilink] == kFALSE) continue;\r
+ \r
+ // check GTU link monitor \r
+ if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0)) {\r
+ fStack->fLinkMonitorError[ilink] = 1;\r
+ fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error\r
+ nLinkErrors++;\r
+ //continue;\r
+ }\r
+\r
+ if (fpPos >= fpEnd) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing"); \r
+ if (fWarnError) AliError("Link data missing.");\r
+ break;\r
+ }\r
+\r
+ // set det number using SM header \r
+ fHC = &fStack->fHalfChambers[ilink];\r
+ fHC->fSM = fRawReader->GetEquipmentId() - 1024;\r
+ fHC->fStack = fStackNumber;\r
+ fHC->fLayer = Int_t(fStackLinkNumber/2.);\r
+ fHC->fSide = fStackLinkNumber%2;\r
+ fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);\r
+ fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);\r
+ fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);\r
+ fHC->fColMax = fGeometry->GetColMax(fHC->fROC);\r
+ }\r
+ } \r
+\r
+ // set number of timebin to be used in the digit container \r
+ if (nLinkErrors>30) fGlobalNTimeBins=30;\r
+ else if (!fIsTimeBinSet) {\r
+ fpPosTemp = fpPos;\r
+ SetGlobalNTimebins();\r
+ fIsTimeBinSet = kTRUE;\r
+ }\r
+\r
+ ResetIterators(); // need to do it again for Next() function\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeGTUheader()\r
+{\r
+ //\r
+ // decode Supermodule Index Word\r
+ //\r
+ DecodeSMInfo(fpPos, &fSM);\r
+\r
+ if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));\r
+\r
+ fpPos++;\r
+ if (fpPos < fpEnd) {\r
+ // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.\r
+ // For the moment, we skip decoding these words \r
+ if (SkipWords(fSM.fHeaderSize) == kTRUE) {\r
+ for (Int_t istack = 0; istack < 5; istack++) {\r
+ if (fSM.fStackActive[istack] == kFALSE)\r
+ continue;\r
+\r
+ fStack = &fSM.fStacks[istack];\r
+\r
+ // Decode Stack Index Word of given stack\r
+ DecodeStackInfo(fpPos, fStack);\r
+ fpPos++;\r
+\r
+ fSM.fNexpectedHalfChambers += fStack->fActiveLinks;\r
+ \r
+ if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));\r
+ \r
+ if (SkipWords(fStack->fHeaderSize-6) == kFALSE) { // 6 is the 6 stack header words for 12 links \r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");\r
+ return kFALSE;\r
+ }\r
+ for (Int_t iword=0; iword<6; iword++) { // decode 6 stack header words\r
+ // Decode Stack Header Word of given stack\r
+ DecodeStackHeader(fpPos, fStack, iword); \r
+ fpPos++;\r
+ } // iword\r
+ } // istack\r
+ }\r
+ else {\r
+ return kFALSE;\r
+ }\r
+ }\r
+ else {\r
+ if (fWarnError) AliWarning("No additional sm headers and stack index words present.");\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fpPos < fpEnd) {\r
+ if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");\r
+ }\r
+ else {\r
+ if (fWarnError) AliWarning("No data just after GTU headers.");\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawFastStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const\r
+{\r
+ //\r
+ // decode Stack #i Index Word\r
+ // The Stack #i Index Word is a 32-Bit word with following structure\r
+ // ssssssss ssssssss vvvv mmmm mmmmmmmm\r
+ // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask\r
+ //\r
+ st->fPos = (UInt_t*)word;\r
+\r
+ UInt_t vword = *word;\r
+ st->fHeaderSize = STACK_HEADER_SIZE(vword);\r
+\r
+ UInt_t linkMask = STACK_LINK_WORD(vword);\r
+ st->fActiveLinks = 0;\r
+ for (Int_t i = 0; i < 12; i++) {\r
+ if (IS_BIT_SET(linkMask,i) > 0) {\r
+ st->fLinksActive[i] = kTRUE;\r
+ st->fActiveLinks++;\r
+ }\r
+ else {\r
+ st->fLinksActive[i] = kFALSE;\r
+ }\r
+ }\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawFastStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const\r
+{\r
+ //\r
+ // decode stack header\r
+ //\r
+ st->fPos = (UInt_t*)word;\r
+\r
+ UInt_t vword = *word;\r
+ st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);\r
+ st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);\r
+ st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);\r
+ st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeTracklets()\r
+{\r
+ //\r
+ // decode tracklets\r
+ //\r
+ fLinkTrackletCounter = 0; // tracklet counter of this link \r
+ fEndOfTrackletCount = 0; // tracklet endmarker counter of this link\r
+ fHC->fNTracklets = 0; // number of tracklet of this link, should be less than 256\r
+\r
+ if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));\r
+\r
+ while (!(*fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW) && fpPos < fpEnd) {\r
+ if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));\r
+\r
+ fLinkTrackletCounter++;\r
+\r
+ if (fLinkTrackletCounter > MAXTRACKLETSPERHC) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d. Tracklets are wrong either GTU header has problem",\r
+ fLinkTrackletCounter, MAXTRACKLETSPERHC));\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets"); \r
+ fHC->fErrorCodes[1] = 1; \r
+ return kFALSE;\r
+ }\r
+\r
+ fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into memory \r
+ fpPos++;\r
+ }\r
+\r
+ fHC->fNTracklets = fLinkTrackletCounter;\r
+\r
+ while ((*fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW) && fpPos < fpEnd) {\r
+ if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));\r
+\r
+ fEndOfTrackletCount++;\r
+ fpPos++;\r
+ }\r
+\r
+ if (fEndOfTrackletCount < 2) {\r
+ if (fgDebugFlag) AliDebug(11,"End of tracklets word missing"); \r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing"); \r
+ fHC->fErrorCodes[1] += 2; \r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawFastStream::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const\r
+{\r
+ //\r
+ // decode Supermodule Index Word\r
+ // The Supermodule Index Word is a 32-Bit word wit following structure\r
+ // ssssssss ssssssss vvvv rrrr r d t mmmm\r
+ // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use\r
+ // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask \r
+ //\r
+ sm->fPos = (UInt_t*)word; \r
+\r
+ UInt_t vword = *word;\r
+ sm->fHeaderSize = SM_HEADER_SIZE(vword);\r
+ \r
+ if (TRACKLETS_ENABLED(vword) > 0)\r
+ sm->fTrackletEnable = kTRUE;\r
+ else\r
+ sm->fTrackletEnable = kFALSE;\r
+ \r
+ UInt_t stackMask = STACK_MASK(vword);\r
+ sm->fActiveStacks = 0;\r
+ for (Int_t i = 0; i < 5; i++)\r
+ {\r
+ if (IS_BIT_SET(stackMask,i) > 0)\r
+ {\r
+ sm->fStackActive[i] = kTRUE;\r
+ sm->fActiveStacks++;\r
+ }\r
+ else\r
+ {\r
+ sm->fStackActive[i] = kFALSE;\r
+ }\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeHC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, \r
+ AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, \r
+ AliTRDSignalIndex *indexes)\r
+{\r
+ //\r
+ // decode hc header and data\r
+ //\r
+ if (fpPos >= fpEnd) {\r
+ fHC->fCorrupted += 1; \r
+ if (fWarnError) AliError("No data(including HC header) in the buffer");\r
+ return kFALSE;;\r
+ }\r
+\r
+ if (DecodeHCheader() == kFALSE) {\r
+ if (fWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));\r
+ return kFALSE;\r
+ }\r
+ else {\r
+ fpPos++;\r
+ if (fpPos >= fpEnd) {\r
+ fHC->fCorrupted += 2; \r
+ if (fWarnError) AliError("No data right after HC header in the buffer");\r
+ return kFALSE;\r
+ }\r
+ }\r
+\r
+ if ((fHC->fRawVMajor & 64) == 64) { // test pattern data\r
+ AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);\r
+ if (tpStream->DecodeTPdata() == kFALSE) {\r
+ if (fWarnError) AliError("Failed to decode test pattern data");\r
+ return kFALSE;\r
+ }\r
+ return kTRUE;\r
+ }\r
+\r
+ fHC->fMCMmax = 0; // count number of mcms in a hc \r
+ while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) {\r
+\r
+ ResetPerMCM(); // reset for every mcm \r
+\r
+ if (fHC->fMCMmax > TRDMAXMCM) {\r
+ fHC->fCorrupted += 4; \r
+ if (fgDebugFlag) AliDebug(11,"More mcm data than expected");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (DecodeMCMheader() == kFALSE) {\r
+\r
+ // encode mcm level error codes\r
+ fHC->fErrorCodes[fHC->fMCMmax+2] += fMCM.fMCMhdCorrupted;\r
+ fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fADCmaskCorrupted << 4);\r
+ fHC->fErrorCodes[fHC->fMCMmax+2] += ((fMCM.fDataCorrupted & 1) << 6);\r
+ fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fMCM << 7); // encode MCM number\r
+ fHC->fErrorCodes[fHC->fMCMmax+2] += (fMCM.fROB << 11); // encode ROB number\r
+\r
+ fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number\r
+\r
+ // in case we decide to keep reading data, skip this mcm data and find next mcm header\r
+ if (fMCM.fADCmaskCorrupted < 2) {\r
+ if (SkipMCMdata(fMCM.fADCcount*fMCM.fSingleADCwords) == kFALSE)\r
+ return kFALSE;\r
+ continue;\r
+ }\r
+ else {\r
+ if (SeekNextMCMheader() == kFALSE)\r
+ return kFALSE;\r
+ continue;\r
+ }\r
+ }\r
+\r
+ fHC->fMCMmax++;\r
+\r
+ if (fMCM.fADCmax > 0) {\r
+ fpPos++;\r
+ if (fpPos >= fpEnd) {\r
+ fHC->fBufferCorrupted = kTRUE; \r
+ if (fgDebugFlag) AliDebug(11, Form("Buffer ends in the middle of data"));\r
+ return kFALSE;\r
+ }\r
+\r
+ fADCnumber = 0;\r
+ for (Int_t iadc = 0; iadc < fMCM.fADCmax; iadc++) {\r
+ fADCnumber = fMCM.fADCchannel[iadc];\r
+ fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber);\r
+ fCOL = fTRDfeeParam->GetPadColFromADC(fMCM.fROB, fMCM.fMCM, fADCnumber);\r
+\r
+ if (fADCnumber <= 1 || fADCnumber == fMaxADCgeom - 1) // if adc number = 0, 1, 20\r
+ fIsShared = kTRUE;\r
+ else \r
+ fIsShared = kFALSE;\r
+\r
+ if (fpPos + fMCM.fSingleADCwords >= fpEnd) {\r
+ fHC->fBufferCorrupted = kTRUE;\r
+ if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");\r
+ return kFALSE;\r
+ }\r
+\r
+ //if (GetGlobalNTimeBins() < 31){\r
+ if (fHC->fTimeBins < 31){\r
+ if (DecodeADC(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {\r
+ return kFALSE;\r
+ }\r
+ }\r
+ //else if (GetGlobalNTimeBins() > 32) {\r
+ else if (fHC->fTimeBins > 32) {\r
+ if (DecodeADCExtended(digitsManager, digits, track0, track1, track2, indexes) == kFALSE) {\r
+ return kFALSE;\r
+ }\r
+ }\r
+ else { // nsamples = 31, 32 are not implemented in the TRAP and should never happen \r
+ if (fWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!");\r
+ }\r
+\r
+ } // iadc\r
+ }\r
+ else { // if there is no adc activated\r
+ fpPos++;\r
+ }\r
+ } // mcm loop\r
+\r
+ if (fpPos >= fpEnd) {\r
+ fHC->fBufferCorrupted = kTRUE; \r
+ if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. Not enough data in the buffer.");\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeHCheader()\r
+{\r
+ //\r
+ // decode the half chamber header\r
+ // if it fails to decode HC header for both H0 and H1, return kFALSE\r
+ //\r
+ if (DecodeHCwordH0(fpPos, fHC) == kFALSE)\r
+ return kFALSE;\r
+\r
+ if (fHC->fNExtraWords > 0) {\r
+ fpPos++;\r
+ if (fpPos < fpEnd) {\r
+ if (DecodeHCwordH1(fpPos, fHC) == kFALSE)\r
+ return kFALSE;\r
+ }\r
+ else {\r
+ fHC->fBufferCorrupted = kTRUE;\r
+ if (fgDebugFlag) AliDebug(11,"Expected HC header word H1. Fail due to buffer END.");\r
+ return kFALSE;\r
+ }\r
+ }\r
+\r
+ if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));\r
+ if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));\r
+\r
+ if (IsHCheaderOK() == kFALSE) {\r
+ fHC->fH0Corrupted += 2;\r
+ if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//--------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const\r
+{\r
+ //\r
+ // decode the hc header word 0\r
+ //\r
+ UInt_t vword = *word;\r
+ hc->fPos[0] = (UInt_t*)word;\r
+\r
+ hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);\r
+ if (hc->fH0Corrupted > 0) {\r
+ if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x",*fHC->fPos ));\r
+ return kFALSE;\r
+ }\r
+ hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);\r
+ hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);\r
+ hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword);\r
+ hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);\r
+ hc->fNExtraWords = HC_EXTRA_WORDS(vword);\r
+ hc->fDCSboard = HC_DCS_BOARD(vword);\r
+ hc->fSMHCheader = HC_SM_NUMBER(vword);\r
+ hc->fStackHCheader = HC_STACK_NUMBER(vword);\r
+ hc->fLayerHCheader = HC_LAYER_NUMBER(vword);\r
+ hc->fSideHCheader = HC_SIDE_NUMBER(vword);\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//--------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const\r
+{\r
+ //\r
+ // decode the hc header word 1\r
+ //\r
+ UInt_t vword = *word;\r
+ hc->fPos[1] = (UInt_t*)word;\r
+\r
+ hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);\r
+ if (hc->fH1Corrupted > 0) {\r
+ if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *(fHC->fPos+1) ));\r
+ return kFALSE;\r
+ }\r
+ hc->fTimeBins = HC_NTIMEBINS(vword);\r
+ hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);\r
+ hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);\r
+ hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::IsHCheaderOK()\r
+{\r
+ //\r
+ // check insanity of half chamber header\r
+ //\r
+ if (fHC->fStackHCheader < 0 || fHC->fStackHCheader > 4) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStackHCheader));\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fLayerHCheader < 0 || fHC->fLayerHCheader >= AliTRDgeometry::kNlayer) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayerHCheader));\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fSideHCheader < 0 || fHC->fSideHCheader > 1) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSideHCheader));\r
+ return kFALSE;\r
+ } \r
+ \r
+ if (fHC->fSMHCheader != fHC->fSM) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Missmatch: SM number between HC header %d and GTU link mask %d",\r
+ fHC->fSMHCheader, fHC->fSM));\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fgStackNumberChecker) {\r
+ if (fHC->fStackHCheader != fHC->fStack) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d",\r
+ fHC->fStackHCheader, fHC->fStack));\r
+ return kFALSE;\r
+ }\r
+ }\r
+\r
+ if (fgStackLinkNumberChecker) {\r
+ if (fHC->fLayerHCheader * 2 + fHC->fSideHCheader != fHC->fLayer * 2 + fHC->fSide) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s",\r
+ fHC->fLayerHCheader, fHC->fLayer, DumpStackInfo(fStack)));\r
+ return kFALSE;\r
+ }\r
+ }\r
+\r
+ // SLOW GEOM : consistancy check with geometry\r
+ if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fSM != fGeometry->GetSector(fHC->fDET) || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d",\r
+ fHC->fSM, fGeometry->GetSector(fHC->fDET), fHC->fStack, fHC->fLayer, fHC->fDET));\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fROC < 0) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fRowMax < 1) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fColMax < 1) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeMCMheader()\r
+{ \r
+ //\r
+ // decode the mcm header\r
+ //\r
+ DecodeMCMheader(fpPos, &fMCM);\r
+\r
+ if (fHC->fEOTECorrupted == kTRUE) {\r
+ fpPos--;\r
+ return kFALSE;\r
+ }\r
+\r
+ fMCM.fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM.fROB, fMCM.fMCM);\r
+\r
+ if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || ((fHC->fRawVMajor & 32) == 32)) { //cover old and new version definition of ZS data\r
+ fpPos++;\r
+ if ( fpPos < fpEnd ) {\r
+ DecodeMask(fpPos, &fMCM);\r
+ if (fHC->fEOTECorrupted == kTRUE) {\r
+ fpPos--;\r
+ return kFALSE;\r
+ }\r
+ MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM);\r
+ fMCM.fAdcDataPos = fpPos + 1;\r
+ }\r
+ else {\r
+ if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing");\r
+ fHC->fBufferCorrupted = kTRUE;\r
+ return kFALSE;\r
+ }\r
+ }\r
+ else {\r
+ UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;\r
+ DecodeMask(&dummyMask, &fMCM);\r
+ MCMADCwordsWithTbins(fHC->fTimeBins, &fMCM);\r
+ fMCM.fAdcDataPos = fpPos + 1;\r
+ }\r
+ if (IsMCMheaderOK() == kFALSE)\r
+ return kFALSE;\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawFastStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r
+{\r
+ //\r
+ // decode the mcm header\r
+ //\r
+ UInt_t vword = *word;\r
+\r
+ if (vword == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));\r
+ fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC\r
+ }\r
+\r
+ mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error\r
+ if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) { \r
+ fHC->fDataCorrupted = kTRUE;\r
+ AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));\r
+ }\r
+\r
+ mcm->fROB = MCM_ROB_NUMBER(vword);\r
+ mcm->fMCM = MCM_MCM_NUMBER(vword);\r
+ mcm->fEvCounter = MCM_EVENT_COUNTER(vword);\r
+ mcm->fPos = (UInt_t*)word;\r
+}\r
+\r
+//--------------------------------------------------------\r
+UInt_t AliTRDrawFastStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r
+{\r
+ //\r
+ // get the adc mask\r
+ //\r
+ UInt_t vword = *word;\r
+\r
+ mcm->fADCMask = 0;\r
+ mcm->fADCcount = 0;\r
+ mcm->fADCMaskWord = vword;\r
+\r
+ if (vword == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));\r
+ fHC->fEOTECorrupted = kTRUE; //to finish data reading of this HC\r
+ }\r
+\r
+ if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {\r
+ mcm->fADCMask = MCM_ADCMASK_VAL(vword);\r
+ mcm->fADCcount = MCM_ADCMASK_NADC(~vword);\r
+ }\r
+ else {\r
+ mcm->fADCMask = 0xffffffff;\r
+ mcm->fADCmaskCorrupted = 1; // mcm adc mask error\r
+ fHC->fDataCorrupted = kTRUE;\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));\r
+ }\r
+\r
+ return mcm->fADCMask;\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawFastStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r
+{\r
+ //\r
+ // decode the adc mask - adcs to be read out\r
+ //\r
+ mcm->fSingleADCwords = 0;\r
+ mcm->fADCmax = 0;\r
+ mcm->fADCMask = GetMCMadcMask(word, mcm);\r
+\r
+ if (mcm->fADCMask > 0) {\r
+ for (Int_t i = 0; i < TRDMAXADC; i++) {\r
+ mcm->fADCchannel[mcm->fADCmax] = 0;\r
+ if ( IS_BIT_SET(mcm->fADCMask,i) ) {\r
+ mcm->fADCchannel[mcm->fADCmax] = i;\r
+ mcm->fADCmax++;\r
+ }\r
+ }\r
+ }\r
+ if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility\r
+ mcm->fADCmaskCorrupted += 2;\r
+ fHC->fDataCorrupted = kTRUE;\r
+ if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", \r
+ mcm->fADCcount, mcm->fADCmax, *fMCM.fPos));\r
+ }\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawFastStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const\r
+{\r
+ //\r
+ // count the expected mcm words for a given tbins\r
+ //\r
+ mcm->fSingleADCwords = 0;\r
+ mcm->fSingleADCwords = (fTbins-1)/3+1;\r
+ if (fTbins > 32) mcm->fSingleADCwords = 10; // if the timebin is more than 30, then fix the number of adc words to 10\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::IsMCMheaderOK()\r
+{\r
+ //\r
+ // check the mcm header\r
+ //\r
+ if (fgLastROB != fMCM.fROB) {\r
+ fgLastIndex = 0;\r
+ if (fgLastROB== -1) fgLastROB = fMCM.fROB;\r
+ }\r
+ else {\r
+ Int_t matchingcounter = 0; \r
+ for (Int_t i=fgLastIndex+1; i<16; i++) {\r
+ if ( fMCM.fMCM == fgMCMordering[i] ) {\r
+ fgLastIndex = i;\r
+ matchingcounter++;\r
+ break;\r
+ }\r
+ }\r
+ if (matchingcounter == 0) {\r
+ fMCM.fMCMhdCorrupted += 2;\r
+ AliDebug(11,Form("MCM number from last MCM is larger: MCM # from current MCM %d \n", fMCM.fMCM));\r
+ }\r
+ } \r
+ \r
+ if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) {\r
+ if ( fMCM.fROB < fgLastROB ) {\r
+ if((fMCM.fMCMhdCorrupted & 2) == 0) fMCM.fMCMhdCorrupted += 2;\r
+ AliDebug(11,Form("ROB number from last MCM is larger: ROB # from current MCM %d \n", fMCM.fROB));\r
+ }\r
+ else fgLastROB = fMCM.fROB;\r
+ }\r
+\r
+ fgLastHC = fHC->fLayer*2 + fHC->fSide;\r
+\r
+ if (fEventCounter == 0) {\r
+ fEventCounter = fMCM.fEvCounter;\r
+ }\r
+\r
+ if (fEventCounter != fMCM.fEvCounter) {\r
+ fMCM.fMCMhdCorrupted += 4;\r
+ if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n"\r
+ , fMCM.fEvCounter, fEventCounter, DumpMCMinfo(&fMCM)));\r
+ }\r
+\r
+ if (fEventCounter < fLastEventCounter) {\r
+ fMCM.fMCMhdCorrupted += 8;\r
+ if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(&fMCM)));\r
+ }\r
+\r
+ if ( fMCM.fADCmaskCorrupted > 0 )\r
+ return kFALSE;\r
+\r
+ if ( fMCM.fMCMhdCorrupted > 0 )\r
+ return kFALSE;\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeADC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, \r
+ AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, \r
+ AliTRDSignalIndex *indexes)\r
+{\r
+ //\r
+ // decode single ADC channel\r
+ //\r
+ if(fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);\r
+ if(fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);\r
+\r
+ fTbinADC = 0;\r
+ Bool_t isWritten = kFALSE;\r
+\r
+ for (Int_t iw = 0; iw < fMCM.fSingleADCwords; iw++) {\r
+ if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));\r
+ fHC->fEOTECorrupted = kTRUE; \r
+ fpPos--;\r
+ return kFALSE;\r
+ }\r
+ if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! [Expected mask: 0x%08x Current mask: 0x%08x] ADC channel number: %02d MCM= %s ",\r
+ fMaskADCword, ADC_WORD_MASK(*fpPos), fADCnumber, DumpMCMinfo(&fMCM)));\r
+ // encode adc level error codes\r
+ Int_t index = 21*(fMCM.fMCM + 16*int(fMCM.fROB/2)) + fADCnumber;\r
+ fHC->fErrorCodes[index+66] += 1; \r
+ if (!isWritten) { \r
+ fHC->fErrorCodes[index+66] += (fADCnumber << 4);; \r
+ fHC->fErrorCodes[index+66] += (fMCM.fMCM << 9);; \r
+ fHC->fErrorCodes[index+66] += (fMCM.fROB << 13);; \r
+ isWritten = kTRUE; \r
+ }\r
+ fMCM.fDataCorrupted = kTRUE;\r
+ fHC->fDataCorrupted = kTRUE;\r
+ fpPos++;\r
+ continue;\r
+ }\r
+ // decode and put into the digit container\r
+ Int_t adcSignals[3];\r
+ adcSignals[0] = ((*fpPos & 0x00000ffc) >> 2);\r
+ adcSignals[1] = ((*fpPos & 0x003ff000) >> 12);\r
+ adcSignals[2] = ((*fpPos & 0xffc00000) >> 22);\r
+\r
+ if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;}; \r
+\r
+ for (Int_t i = 0; i < 3; i++) {\r
+ digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcSignals[i]);\r
+ indexes->AddIndexRC(GetRow(), GetCol());\r
+ if (digitsManager->UsesDictionaries()) {\r
+ track0->SetData(GetRow(), GetCol(), fTbinADC + i, 0);\r
+ track1->SetData(GetRow(), GetCol(), fTbinADC + i, 0);\r
+ track2->SetData(GetRow(), GetCol(), fTbinADC + i, 0);\r
+ }\r
+ } // i\r
+ fTbinADC += 3;\r
+ fpPos++;\r
+ } // iw\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DecodeADCExtended(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, \r
+ AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, \r
+ AliTRDSignalIndex *indexes)\r
+{\r
+ //\r
+ // decode single ADC channel\r
+ //\r
+ if(fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);\r
+ if(fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);\r
+\r
+ Bool_t isWritten = kFALSE; //for error code recording\r
+\r
+ fTbinADC = ((*fpPos & 0x000000fc) >> 2);\r
+ fMCM.fSingleADCwords = ((*fpPos & 0x00000f00) >> 8);\r
+ \r
+ Int_t adcFirst2Signals[2];\r
+ adcFirst2Signals[0] = ((*fpPos & 0x003ff000) >> 12);\r
+ adcFirst2Signals[1] = ((*fpPos & 0xffc00000) >> 22);\r
+\r
+ for (Int_t i = 0; i < 2; i++) {\r
+ digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcFirst2Signals[i]);\r
+ indexes->AddIndexRC(GetRow(), GetCol());\r
+ if (digitsManager->UsesDictionaries()) {\r
+ track0->SetData(GetRow(), GetCol(), fTbinADC + i, 0);\r
+ track1->SetData(GetRow(), GetCol(), fTbinADC + i, 0);\r
+ track2->SetData(GetRow(), GetCol(), fTbinADC + i, 0);\r
+ }\r
+ } // i\r
+\r
+ fpPos++;\r
+ for (Int_t iw = 0; iw < fMCM.fSingleADCwords-1; iw++) {\r
+ if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));\r
+ fHC->fEOTECorrupted = kTRUE; \r
+ fpPos--;\r
+ return kFALSE;\r
+ }\r
+ if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! [Expected mask: 0x%08x Current mask: 0x%08x] ADC channel number: %02d MCM= %s ",\r
+ fMaskADCword, ADC_WORD_MASK(*fpPos), fADCnumber, DumpMCMinfo(&fMCM)));\r
+ // encode adc level error codes\r
+ Int_t index = 21*(fMCM.fMCM + 16*int(fMCM.fROB/2)) + fADCnumber;\r
+ fHC->fErrorCodes[index+66] += 1; \r
+ if (!isWritten) { \r
+ fHC->fErrorCodes[index+66] += (fADCnumber << 4);; \r
+ fHC->fErrorCodes[index+66] += (fMCM.fMCM << 9);; \r
+ fHC->fErrorCodes[index+66] += (fMCM.fROB << 13);; \r
+ isWritten = kTRUE; \r
+ }\r
+ fMCM.fDataCorrupted = kTRUE;\r
+ fHC->fDataCorrupted = kTRUE;\r
+ fpPos++;\r
+ continue;\r
+ }\r
+ // decode and put into the digit container\r
+ Int_t adcSignals[3];\r
+ adcSignals[0] = ((*fpPos & 0x00000ffc) >> 2);\r
+ adcSignals[1] = ((*fpPos & 0x003ff000) >> 12);\r
+ adcSignals[2] = ((*fpPos & 0xffc00000) >> 22);\r
+\r
+ if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;}; \r
+ for (Int_t i = 0; i < 3; i++) {\r
+ digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + 2 + i, adcSignals[i]);\r
+ indexes->AddIndexRC(GetRow(), GetCol());\r
+ if (digitsManager->UsesDictionaries()) {\r
+ track0->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);\r
+ track1->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);\r
+ track2->SetData(GetRow(), GetCol(), fTbinADC + 2 + i, 0);\r
+ }\r
+ } // i\r
+ fTbinADC += 3;\r
+ fpPos++;\r
+ } // iw\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::SeekEndOfData()\r
+{\r
+ //\r
+ // go to end of data marker\r
+ //\r
+ Int_t fEndOfDataCount = 0;\r
+ fNWordsCounter = 0;\r
+\r
+ while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r
+ fpPos++;\r
+ fNWordsCounter++;\r
+ }\r
+ while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r
+ fEndOfDataCount++;\r
+ fpPos++;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::SeekNextMCMheader()\r
+{\r
+ //\r
+ // go to mcm marker\r
+ //\r
+ fpPos++;\r
+\r
+ while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r
+ if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));\r
+ return kTRUE;\r
+ }\r
+ if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {\r
+ fHC->fEOTECorrupted = kTRUE;\r
+ return kFALSE;\r
+ }\r
+ fpPos++;\r
+ }\r
+\r
+ SeekEndOfData();\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::SkipMCMdata(UInt_t iw)\r
+{\r
+ //\r
+ // skip mcm data words due to corruption\r
+ //\r
+ if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));\r
+ UInt_t iwcounter = 0;\r
+ while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw) {\r
+ if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");\r
+ fHC->fEOTECorrupted = kTRUE;\r
+ return kFALSE;\r
+ }\r
+ fpPos++;\r
+ iwcounter++;\r
+ } // while\r
+\r
+ if (iwcounter == iw) {\r
+ fpPos++;\r
+ return kTRUE;\r
+ }\r
+\r
+ if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::SetGlobalNTimebins()\r
+{\r
+ // get number of time bin info from HC headers then set \r
+ Int_t nHCs=0;\r
+ while (SetNTimebins()==kFALSE){\r
+ if (fgDebugFlag) AliDebug(11,Form("Failed to get number of time bin information from the %sth HC",nHCs));\r
+ nHCs++;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::SetNTimebins()\r
+{\r
+ // goes to the HC header position\r
+ while (!(*fpPosTemp == END_OF_TRACKLET_MARKERNEW) && fpPosTemp < fpEnd) {\r
+ fpPosTemp++;\r
+ }\r
+ while (*fpPosTemp == END_OF_TRACKLET_MARKERNEW) {\r
+ fpPosTemp++;\r
+ }\r
+ // skip H0 \r
+ fpPosTemp++;\r
+\r
+ UInt_t vword = 0;\r
+ if (!(vword = *fpPosTemp)) {\r
+ fGlobalNTimeBins = 30; // default number of timebins \r
+ return kFALSE;\r
+ }\r
+\r
+ // get the number of time bins \r
+ if (HC_HEADER_MASK_ERR(vword) == 0) {\r
+ fGlobalNTimeBins = HC_NTIMEBINS(vword);\r
+ if (fGlobalNTimeBins > 64 || fGlobalNTimeBins < 10) return kFALSE; // minimal protection\r
+ }\r
+ else\r
+ return kFALSE;\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawFastStream::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)\r
+{\r
+ //\r
+ // dump given number of words for debugging\r
+ //\r
+ TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);\r
+ for (UInt_t i = 0; i < iw; i++) {\r
+ if ( iw != 0 && px + iw > fpEnd) \r
+ return kFALSE;\r
+ if (i % 8 == 0) tsreturn += "\n ";\r
+ if (marker != 0 && marker == px[i]) tsreturn += Form(" *>0x%08x<* ", px[i]);\r
+ else tsreturn += Form("0x%08x ", px[i]);\r
+ }\r
+ tsreturn += "\n";\r
+\r
+ AliInfo(tsreturn.Data());\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//--------------------------------------------------------\r
+const char *AliTRDrawFastStream::DumpSMInfo(const struct AliTRDrawSM *sm)\r
+{\r
+ //\r
+ // format the string with the sm info\r
+ //\r
+ return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",\r
+ *sm->fPos, sm->fHeaderSize, sm->fTrackletEnable,\r
+ sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],\r
+ sm->fStackActive[3], sm->fStackActive[4]); \r
+}\r
+\r
+//--------------------------------------------------------\r
+const char *AliTRDrawFastStream::DumpStackInfo(const struct AliTRDrawStack *st)\r
+{\r
+ //\r
+ // format the string with the stack info\r
+ //\r
+ return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",\r
+ *st->fPos, st->fHeaderSize,\r
+ st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],\r
+ st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],\r
+ st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);\r
+\r
+}\r
+//--------------------------------------------------------\r
+const char *AliTRDrawFastStream::DumpHCinfoH0(const struct AliTRDrawHC *hc)\r
+{\r
+ //\r
+ // dump the hc header word 0 in strings\r
+ //\r
+ if (!hc)\r
+ return Form("Unable to dump. Null received as parameter!?!");\r
+ else\r
+ return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",\r
+ hc->fPos[0], *(hc->fPos[0]), hc->fRawVMajor, fRawReader->GetEquipmentId()-1024, \r
+ hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);\r
+}\r
+\r
+//--------------------------------------------------------\r
+const char *AliTRDrawFastStream::DumpHCinfoH1(const struct AliTRDrawHC *hc)\r
+{\r
+ //\r
+ // dump the hc header word 1 in strings\r
+ //\r
+ if (!hc)\r
+ return Form("Unable to dump. Null received as parameter!?!");\r
+ else\r
+ return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",\r
+ hc->fPos[1], *(hc->fPos[1]), hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);\r
+}\r
+\r
+//--------------------------------------------------------\r
+const char *AliTRDrawFastStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm)\r
+{\r
+ //\r
+ // dump mcm info in strings\r
+ //\r
+ if (!mcm)\r
+ return Form("Unable to dump. Null received as parameter!?!");\r
+ else\r
+ return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);\r
+}\r
+\r
+//--------------------------------------------------------\r
+const char *AliTRDrawFastStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)\r
+{\r
+ //\r
+ // mcm adc mask in strings\r
+ //\r
+ if (!mcm)\r
+ return Form("Unable to dump. Null received as parameter!?!");\r
+\r
+ TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);\r
+ for (Int_t i = 0; i < TRDMAXADC; i++) {\r
+ tsreturn += Form("%d ", mcm->fADCchannel[i]);\r
+ }\r
+ tsreturn += "";\r
+ return tsreturn.Data();\r
+}\r
+\r
+\r
UInt_t *fpPosTemp; // specific position in the buffer \r
Int_t fGlobalNTimeBins; // number of time bin to be used in the digit container\r
Bool_t fIsTimeBinSet; // set true if the global time bin is set to avoid multiple search\r
- Bool_t fIsGlobalDigitsParamSet; // set true if the global digit parameters are already set\r
\r
Int_t fStackNumber; // current stack number\r
Int_t fStackLinkNumber; // current link in the stack\r
, kWrongPadcolumn = 24 //\r
}; \r
\r
- ClassDef(AliTRDrawFastStream, 0)\r
+ ClassDef(AliTRDrawFastStream, 1)\r
}; //clas def end\r
\r
#endif\r
-/**************************************************************************
-* 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"
-#include "AliTRDdigitsManager.h"
-#include "AliTRDarrayDictionary.h"
-#include "AliTRDarrayADC.h"
-#include "AliTRDSignalIndex.h"
-#include "AliTRDdigitsParam.h"
-#include "AliTRDrawTPStream.h"
-
-//#include "AliLog.h"
-#include "AliRawReader.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::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)
- , fCommonAdditive(0)
- , fWarnError(kTRUE)
-{
- //
- // 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)
- , fCommonAdditive(0)
- , fWarnError(kTRUE)
-{
- //
- // 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*).");
- }
-}
-
-//------------------------------------------------------------
-
-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)
- , fCommonAdditive(0)
- , fWarnError(kTRUE)
-{
- //
- // 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;
-}
-
-//___________________________________________________________
-void AliTRDrawStream::SwapOnEndian()
-{
- //
- // 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;
- }
-}
-
-//------------------------------------------------------------
-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]);
- }
- tsreturn += "\n";
-
- AliInfo(tsreturn.Data());
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SkipWords(UInt_t iw)
-{
- //
- // Skip words corresponding to iw
- //
- if ( fpPos + iw < fpEnd ) {
- fpPos += iw;
- return kTRUE;
- }
- else {
- if (fWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SetReader(AliRawReader * reader)
-{
- //
- // Set reader pointer
- //
- if (reader != 0) {
- fRawReader = reader;
- if (fRawReader) {
- return Init();
- }
- else {
- AliWarning("Unable to setup reader.");
- return kFALSE;
- }
- }
- else {
- AliWarning("AliRawReader argument is 0.");
- fRawReader = 0;
- }
-
- return kFALSE;
-}
-
-//------------------------------------------------------------
-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;
- }
-
- if (fgSkipCDH == kTRUE) {
- buffer += CDH_WORDS * WORD_SIZE;
- length -= CDH_WORDS * WORD_SIZE;
- }
-
- 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;
- }
- }
- else {
- return -1;
- }
- }
-
- return -1;
-}
-
-//------------------------------------------------------------
-void AliTRDrawStream::ResetCounters()
-{
- //
- // reset some global counters
- //
- fBufferRead = kFALSE; // read buffer if it is false (important to read buffer)
-
- fStackNumber = 0;
- fStackLinkNumber = 0;
- fDecodedADCs = 0;
-
- fSM.fActiveStacks = 0;
- fSM.fNexpectedHalfChambers = 0;
-
- fLinkTrackletCounter = 0;
- fLastEventCounter = 0;
- fEventCounter = 0;
-}
-
-//------------------------------------------------------------
-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;
-}
-
-//------------------------------------------------------------
-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;
- }
-}
-
-//------------------------------------------------------------
-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;
- }
-}
-
-//------------------------------------------------------------
-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;
-}
-
-//------------------------------------------------------------
-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->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()
-{
- //
- // 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));
-}
-
-//------------------------------------------------------------
-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();
- }
- nextBuff = NextBuffer();
- }
- }
-
- return kFALSE;
-}
-
-//------------------------------------------------------------
-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;
- }
-
- 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 {
- fmcmADCcounter--;
- fHC = fLastHC ;
- return lastdet;
- }
-
- 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;
- }
-
- // 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);
- }
-
- 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;
- }
-
- //Int_t rowMax = GetRowMax();
- Int_t rowMax = fGeometry->RowmaxC1(); // we use maximum row number among all detectors to reuse memory
- Int_t colMax = GetColMax();
- Int_t ntbins = GetNumberOfTimeBins();
-
- // Set digitparam variables
- digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();
- digitsparam->SetPretriggerPhase(det,GetPreTriggerPhase());
- if (!fIsGlobalDigitsParamSet){
- digitsparam->SetNTimeBins(ntbins);
- fCommonAdditive=10;
- digitsparam->SetADCbaseline(fCommonAdditive);
- fIsGlobalDigitsParamSet = kTRUE;
- }
-
- // Allocate memory space for the digits buffer
- if (digits->GetNtime() == 0) {
- digits->Allocate(rowMax, colMax, ntbins);
- if (digitsManager->UsesDictionaries()) {
- track0->Allocate(rowMax, colMax, ntbins);
- track1->Allocate(rowMax, colMax, ntbins);
- track2->Allocate(rowMax, colMax, ntbins);
- }
- }
-
- 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++) {
- digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), it, GetSignals()[it]);
- if (!(GetCol()<0)) 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;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::Init()
-{
- //
- // Initialize geometry and fee parameters
- //
- TDirectory *saveDir = gDirectory;
-
- if (!fGeometry) {
- fGeometry = new AliTRDgeometry();
- if (!fGeometry) {
- AliError("Geometry FAILED!");
- return kFALSE;
- }
- }
-
- fTRDfeeParam = AliTRDfeeParam::Instance();
- if (!fTRDfeeParam) {
- AliError("AliTRDfeeParam FAILED!");
- return kFALSE;
- }
-
- fMaxADCgeom = (Int_t)fGeometry->ADCmax();
-
- ResetCounters(); // fBufferRead is set to kFALSE - important
-
- saveDir->cd();
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::InitBuffer(void * const buffer, UInt_t length)
-{
- //
- // 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;
- }
-
- ResetCounters();
-
- fpBegin = (UInt_t *)buffer;
- fWordLength = length/WORD_SIZE;
- fpEnd = fpBegin + fWordLength;
- fpPos = fpBegin;
-
- 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;
- }
-
- SwapOnEndian();
-
- 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 ----------------------------------------------"));
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeGTUheader()
-{
- // 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++;
- }
- }
- }
- else {
- return kFALSE;
- }
- }
- else {
- if (fWarnError) AliWarning("No additional sm headers and stack index words present.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");
- return kFALSE;
- }
-
- if (fpPos < fpEnd) {
- if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");
- }
- else {
- if (fWarnError) AliWarning("No data just after GTU headers.");
- if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");
- return kFALSE;
- }
-
- if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeSM(void * const buffer, UInt_t length)
-{
- //
- // decode one sm data in buffer
- //
- ResetIterators();
-
- fSM.fClean = kTRUE;
- if (InitBuffer(buffer, length) == kFALSE) {
- if (fWarnError) AliError("InitBuffer failed.");
- fSM.fClean = kFALSE;
- return kFALSE;
- }
-
- if (DecodeGTUheader()== kFALSE)
- return kFALSE;
-
- 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;
- }
-
- if (fpPos >= fpEnd) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");
- if (fWarnError) AliError("Link data missing.");
- fSM.fClean = kFALSE;
- break;
- }
-
- fHC = &fStack->fHalfChambers[ilink];
- ResetPerHC();
-
- if (fSM.fTrackletEnable == kTRUE) {
- if (DecodeTracklets() == kFALSE) {
- fSM.fClean = kFALSE;
- SeekEndOfData();
-
- if (fWarnError) {
- AliError(Form("Tracklet decoding failed stack %d link %d", fStackNumber, fStackLinkNumber));
- }
- continue;
- }
- }
-
- if (fpPos >= fpEnd) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");
- if (fWarnError) 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 (fWarnError) {
- 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
-
- ResetIterators(); // need to do it again for Next() function
-
- if (fSM.fClean == kTRUE)
- return kTRUE;
-
- if (fgCleanDataOnly && (fSM.fClean == kFALSE)) {
- if (fWarnError) {
- AliWarning("Buffer with errors. Returning FALSE.");
- AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));
- }
- fSM.fActiveStacks = 0; // Next() will not give data
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Int_t AliTRDrawStream::DecodeSM()
-{
- //
- // 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();
- }
- return -1;
- }
- else {
- AliWarning("AliRawReader not set.");
- }
-
- return kFALSE;
-}
-
-//------------------------------------------------------------
-Int_t AliTRDrawStream::DecodeSM(AliRawReader *reader)
-{
- //
- // decode SM with the AliRawReader
- //
- if (reader != 0) {
- fRawReader = reader;
- return DecodeSM();
- }
- else {
- AliWarning("Argument AliRawReader is 0.");
- }
-
- return kFALSE;
-}
-
-//------------------------------------------------------------
-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;
-}
-
-//------------------------------------------------------------
-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 (iwcounter == iw) {
- fpPos++;
- return kTRUE;
- }
-
- if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");
-
- return kFALSE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::SeekNextMCMheader()
-{
- //
- // 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;
- }
- if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {
- fMCM->fCorrupted += 16;
- fHC->fCorrupted += 16;
- return kFALSE;
- }
- fpPos++;
- }
-
- SeekEndOfData();
-
- return kFALSE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeTracklets()
-{
- //
- // decode tracklets
- //
- fLinkTrackletCounter = 0;
- fEndOfTrackletCount = 0;
- fHC->fNTracklets = 0;
-
- for (Int_t i = 0; i < MAXTRACKLETSPERHC; i++)
- fHC->fTrackletWords[i] = 0;
-
- if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));
-
- 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));
-
- fLinkTrackletCounter++;
-
- 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;
- }
-
- fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into array
- fHC->fNTracklets = fLinkTrackletCounter;
- fpPos++;
- }
-
- 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));
-
- fEndOfTrackletCount++;
- fpPos++;
- }
-
- 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;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-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;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::IsMCMheaderOK()
-{
- //
- // 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));
- }
- }
-
- 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;
- }
-
- 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;
- }
-
- 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)));
- }
-
- 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 ( fMCM->fADCmaskCorrupted > 0 ) {
- return kFALSE;
- }
-
- if ( fMCM->fMCMhdCorrupted > 0 ) {
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeMCMheader()
-{
- //
- // 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);
- }
- }
- }
- }
-
- if (fHC->fCorrupted >= 16) {
- fpPos--;
- return kFALSE;
- }
- fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM);
-
- 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;
- }
- MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);
- fMCM->fAdcDataPos = fpPos + 1;
- }
- 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;
- }
- }
- 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;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::IsHCheaderOK()
-{
- //
- // 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;
- }
-
- if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayer));
- return kFALSE;
- }
-
- if (fHC->fSide < 0 || fHC->fSide > 1) {
- if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSide));
- return kFALSE;
- }
-
- 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 (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;
- }
- }
-
- // 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 (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;
- }
-
- fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);
- if (fHC->fROC < 0) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");
- return kFALSE;
- }
-
- 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;
- }
-
- fHC->fColMax = fGeometry->GetColMax(fHC->fROC);
- if (fHC->fColMax < 1) {
- if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-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;
- }
- 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 (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));
- if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));
-
- fHC->fDET = -1;
- if (IsHCheaderOK() == kFALSE) {
- fHC->fH0Corrupted += 2;
- if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));
- return kFALSE;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeHC()
-{
- //
- // decode hc header and data
- //
-
- if (DecodeHCheader() == kFALSE) {
- if (fWarnError) 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;
- }
- }
-
- if ((fHC->fRawVMajor & 64) == 64) { // test pattern data
- AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);
- if (tpStream->DecodeTPdata() == kFALSE) {
- if (fWarnError) AliError("failed to decode test pattern data");
- return kFALSE;
- }
- 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 {
- if (SeekNextMCMheader() == kFALSE)
- return kFALSE;
- continue;
- }
- }
-
- fHC->fMCMmax++;
-
- 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;
- }
-
- 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 (fWarnError) 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 (fWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class
- }
- } // for iadc
- } // if fMCM->fADCmax
- else {
- fpPos++;
- }
- }//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;
- }
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeADC()
-{
- //
- // decode single ADC channel
- //
-
- 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 (fWarnError) 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;
- }
-
- fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2);
- fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12);
- fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22);
-
- fTbinADC += 3;
- fpPos++;
- } // iw
-
- if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {
- fADC->fIsShared = kTRUE;
- }
- else {
- fADC->fIsShared = kFALSE;
- }
-
- 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;
- //}
- }
-
- if (fADC->fCorrupted > 0) {
- return kFALSE;
- }
-
- fDecodedADCs++;
-
- return kTRUE;
-}
-
-//------------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeADCExtended()
-{
- //
- // decode single ADC channel
- //
-
- 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);
- fADC->fSignals[fTbinADC+1] = ((*fpPos & 0xffc00000) >> 22);
-
- 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 (fWarnError) 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;
- }
-
- fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0x00000ffc) >> 2);
- fADC->fSignals[fTbinADC + 3] = ((*fpPos & 0x003ff000) >> 12);
- fADC->fSignals[fTbinADC + 4] = ((*fpPos & 0xffc00000) >> 22);
-
- 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;
- }
-
- 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)));
- }
- }
-
- if (fADC->fCorrupted > 0) {
- return kFALSE;
- }
-
- fDecodedADCs++;
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-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;
- }
- }
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpSMInfo(const struct AliTRDrawSM *sm)
-{
- //
- // 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]);
-}
-
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const
-{
- //
- // 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;
- }
- }
-}
-
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const
-{
- //
- // 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);
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpStackInfo(const struct AliTRDrawStack *st)
-{
- //
- // 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]);
-}
-
-//--------------------------------------------------------
-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);
-
-
- return kTRUE;
-}
-
-//--------------------------------------------------------
-Bool_t AliTRDrawStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const
-{
- //
- // 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;
- }
-
- 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!?!");
- 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, fRawReader->GetEquipmentId()-1024, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpHCinfoH1(const struct AliTRDrawHC *hc)
-{
- //
- // 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);
-}
-
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const
-{
- //
- // decode the mcm header
- //
- UInt_t vword = *word;
-
- if (vword == END_OF_TRACKLET_MARKERNEW) {
- if (fWarnError) 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
- }
-
- 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));
-
- mcm->fROB = MCM_ROB_NUMBER(vword);
- mcm->fMCM = MCM_MCM_NUMBER(vword);
- mcm->fEvCounter = MCM_EVENT_COUNTER(vword);
- mcm->fPos = (UInt_t*)word;
-}
-
-//--------------------------------------------------------
-UInt_t AliTRDrawStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
-{
- //
- // 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 (fWarnError) 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
- }
-
- if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {
- mcm->fADCMask = MCM_ADCMASK_VAL(vword);
- mcm->fADCcount = MCM_ADCMASK_NADC(~vword);
- }
- else {
- mcm->fADCMask = 0xffffffff;
- mcm->fADCmaskCorrupted = 1; // mcm adc mask error
- if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));
- }
-
- return mcm->fADCMask;
-}
-
-//--------------------------------------------------------
-void AliTRDrawStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const
-{
- //
- // decode the adc mask - adcs to be read out
- //
- 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++;
- }
- }
- }
- 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));
- }
-}
-
-//--------------------------------------------------------
-void AliTRDrawStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const
-{
- //
- // count the expected mcm words for a given tbins
- //
- mcm->fSingleADCwords = 0;
- mcm->fSingleADCwords = (fTbins-1)/3+1;
- if (fTbins > 32) mcm->fSingleADCwords = 10; // if the timebin is more than 30, then fix the number of adc words to 10
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm)
-{
- //
- // 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);
-}
-
-//--------------------------------------------------------
-const char *AliTRDrawStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)
-{
- //
- // 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]);
- }
- tsreturn += "";
- return tsreturn.Data();
-}
-
+/**************************************************************************\r
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
+* *\r
+* Author: The ALICE Off-line Project. *\r
+* Contributors are mentioned in the code where appropriate. *\r
+* *\r
+* Permission to use, copy, modify and distribute this software and its *\r
+* documentation strictly for non-commercial purposes is hereby granted *\r
+* without fee, provided that the above copyright notice appears in all *\r
+* copies and that both the copyright notice and this permission notice *\r
+* appear in the supporting documentation. The authors make no claims *\r
+* about the suitability of this software for any purpose. It is *\r
+* provided "as is" without express or implied warranty. *\r
+**************************************************************************/\r
+\r
+/* $Id: AliTRDrawStream.cxx 27797 2008-08-05 14:37:22Z cblume $ */\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// //\r
+// This class provides access to TRD digits in raw data. //\r
+// //\r
+// It loops over all TRD digits in the raw data given by the AliRawReader. //\r
+// The Next method goes to the next digit. If there are no digits left //\r
+// it returns kFALSE. //\r
+// Several getters provide information about the current digit. //\r
+// //\r
+// Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de) //\r
+// Author: MinJung Kweon (minjung@physi.uni-heidelberg.de) //\r
+// //\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
+#include "TString.h"\r
+#include "TFile.h"\r
+//#include "TTreeStream.h"\r
+\r
+#include "AliTRDrawStream.h"\r
+#include "AliTRDgeometry.h"\r
+#include "AliTRDfeeParam.h"\r
+#include "AliTRDdigitsManager.h"\r
+#include "AliTRDarrayDictionary.h"\r
+#include "AliTRDarrayADC.h"\r
+#include "AliTRDSignalIndex.h"\r
+#include "AliTRDdigitsParam.h"\r
+#include "AliTRDrawTPStream.h"\r
+\r
+//#include "AliLog.h"\r
+#include "AliRawReader.h"\r
+\r
+#define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa\r
+#define END_OF_TRACKLET_MARKERNEW 0x10001000\r
+#define ENDOFRAWDATAMARKER 0x00000000\r
+#define WORD_SIZE sizeof(UInt_t) // size of a word in bytes\r
+#define EXTRA_LEAD_WORDS 24\r
+#define CDH_WORDS 8\r
+\r
+#define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 ) // 1 if bit b is set in word w\r
+#define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m\r
+\r
+// SM index word masks:\r
+#define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16) \r
+#define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)\r
+#define STACK_MASK(w) ((w) & 0x1f)\r
+\r
+// Stack word masks\r
+#define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)\r
+#define STACK_LINK_WORD(w) ((w) & 0xfff)\r
+#define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1) // 0 if physics data\r
+#define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data\r
+#define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1) // 0 if OK\r
+#define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1) // 0 if OK\r
+\r
+// HC word masks\r
+#define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK\r
+\r
+// HC word 0\r
+#define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)\r
+#define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)\r
+#define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)\r
+#define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)\r
+#define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)\r
+#define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)\r
+#define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)\r
+#define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)\r
+#define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)\r
+#define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)\r
+\r
+// HC word 1\r
+#define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)\r
+#define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)\r
+#define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)\r
+#define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,2)\r
+\r
+// MCM word and ADC mask\r
+#define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK\r
+#define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK\r
+#define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)\r
+#define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)\r
+#define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)\r
+#define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)\r
+#define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)\r
+\r
+#define MCM_DUMMY_ADCMASK_VAL 0x015fffffc // updated \r
+#define ADCDATA_VAL1 0x2 // updated \r
+#define ADCDATA_VAL2 0x3 // updated \r
+\r
+#define ADC_WORD_MASK(w) ((w) & 0x3)\r
+\r
+//--------------------------------------------------------\r
+ClassImp(AliTRDrawStream)\r
+\r
+Bool_t AliTRDrawStream::fgExtraSkip = kFALSE;\r
+Bool_t AliTRDrawStream::fgSkipCDH = kFALSE;\r
+Bool_t AliTRDrawStream::fgCleanDataOnly = kFALSE;\r
+Bool_t AliTRDrawStream::fgDebugFlag = kTRUE;\r
+Bool_t AliTRDrawStream::fgEnableMemoryReset = kTRUE;\r
+Bool_t AliTRDrawStream::fgStackNumberChecker = kTRUE;\r
+Bool_t AliTRDrawStream::fgStackLinkNumberChecker = kFALSE;\r
+Bool_t AliTRDrawStream::fgSkipData = kTRUE;\r
+Bool_t AliTRDrawStream::fgEnableDecodeConfigData = kFALSE;\r
+Int_t AliTRDrawStream::fgDumpHead = -1;\r
+Int_t AliTRDrawStream::fgEmptySignals[] = \r
+ {\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1\r
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1\r
+ };\r
+Short_t AliTRDrawStream::fgMCMordering[] =\r
+ {\r
+ 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 \r
+ };\r
+Short_t AliTRDrawStream::fgROBordering[] =\r
+ {\r
+ 0, 1, 2, 3\r
+ };\r
+Int_t AliTRDrawStream::fgLastHC = -1;\r
+Int_t AliTRDrawStream::fgLastROB = -1;\r
+Int_t AliTRDrawStream::fgLastIndex = -1;\r
+Int_t AliTRDrawStream::fgDumpingSM = -1;\r
+Int_t AliTRDrawStream::fgDumpingStack = -1;\r
+Int_t AliTRDrawStream::fgDumpingLayer = -1;\r
+Int_t AliTRDrawStream::fgDumpingROB = -1;\r
+Int_t AliTRDrawStream::fgDumpingMCM = -1;\r
+Bool_t AliTRDrawStream::fgDumpingEnable = kFALSE;\r
+\r
+\r
+AliTRDrawStream::AliTRDrawStream()\r
+ : AliTRDrawStreamBase()\r
+ , fSM()\r
+ , fStack(0)\r
+ , fHC(0)\r
+ , fLastHC(0)\r
+ , fMCM(0)\r
+ , fADC(0)\r
+ , fpPos(0)\r
+ , fpBegin(0)\r
+ , fpEnd(0)\r
+ , fWordLength(0)\r
+ , fStackNumber(-1)\r
+ , fStackLinkNumber(-1)\r
+ , fhcMCMcounter(0)\r
+ , fmcmADCcounter(0)\r
+ , fLinkTrackletCounter(-1)\r
+ , fEndOfTrackletCount(-1)\r
+ , fNWordsCounter(-1)\r
+ , fMaskADCword(0)\r
+ , fTbinADC(0)\r
+ , fDecodedADCs(-1)\r
+ , fEventCounter(0)\r
+ , fLastEventCounter(0)\r
+ , fSharedPadsOn(kTRUE)\r
+ , fMaxADCgeom(0)\r
+ , fBufferRead(0)\r
+ , fGeometry(0)\r
+ , fRawReader(0)\r
+ , fTRDfeeParam(0)\r
+ , fCommonAdditive(0)\r
+ , fWarnError(kTRUE)\r
+{\r
+ //\r
+ // default constructor\r
+ //\r
+ if (Init() == kFALSE) {\r
+ AliWarning("Unable to Init."); \r
+ }\r
+}\r
+\r
+//--------------------------------------------------------\r
+AliTRDrawStream::AliTRDrawStream(AliRawReader *rawReader)\r
+ : AliTRDrawStreamBase(rawReader)\r
+ , fSM()\r
+ , fStack(0)\r
+ , fHC(0)\r
+ , fLastHC(0)\r
+ , fMCM(0)\r
+ , fADC(0)\r
+ , fpPos(0)\r
+ , fpBegin(0)\r
+ , fpEnd(0)\r
+ , fWordLength(0)\r
+ , fStackNumber(-1)\r
+ , fStackLinkNumber(-1)\r
+ , fhcMCMcounter(0)\r
+ , fmcmADCcounter(0)\r
+ , fLinkTrackletCounter(-1)\r
+ , fEndOfTrackletCount(-1)\r
+ , fNWordsCounter(-1)\r
+ , fMaskADCword(0)\r
+ , fTbinADC(0)\r
+ , fDecodedADCs(-1)\r
+ , fEventCounter(0)\r
+ , fLastEventCounter(0)\r
+ , fSharedPadsOn(kTRUE)\r
+ , fMaxADCgeom(0)\r
+ , fBufferRead(0)\r
+ , fGeometry(0)\r
+ , fRawReader(rawReader)\r
+ , fTRDfeeParam(0)\r
+ , fCommonAdditive(0)\r
+ , fWarnError(kTRUE)\r
+{\r
+ //\r
+ // default constructor\r
+ //\r
+ if (fRawReader) {\r
+ if (Init() == kFALSE) {\r
+ AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )"); \r
+ }\r
+ }\r
+ else {\r
+ AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+\r
+AliTRDrawStream::AliTRDrawStream(const AliTRDrawStream& /*st*/)\r
+ : AliTRDrawStreamBase()\r
+ , fSM()\r
+ , fStack(0)\r
+ , fHC(0)\r
+ , fLastHC(0)\r
+ , fMCM(0)\r
+ , fADC(0)\r
+ , fpPos(0)\r
+ , fpBegin(0)\r
+ , fpEnd(0)\r
+ , fWordLength(0)\r
+ , fStackNumber(-1)\r
+ , fStackLinkNumber(-1)\r
+ , fhcMCMcounter(0)\r
+ , fmcmADCcounter(0)\r
+ , fLinkTrackletCounter(-1)\r
+ , fEndOfTrackletCount(-1)\r
+ , fNWordsCounter(-1)\r
+ , fMaskADCword(0)\r
+ , fTbinADC(0)\r
+ , fDecodedADCs(-1)\r
+ , fEventCounter(0)\r
+ , fLastEventCounter(0)\r
+ , fSharedPadsOn(kTRUE)\r
+ , fMaxADCgeom(0)\r
+ , fBufferRead(0)\r
+ , fGeometry(0)\r
+ , fRawReader(0)\r
+ , fTRDfeeParam(0)\r
+ , fCommonAdditive(0)\r
+ , fWarnError(kTRUE)\r
+{\r
+ //\r
+ // Copy constructor\r
+ // \r
+ AliError("Not implemeneted.");\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::SetRawVersion(Int_t fraw)\r
+{\r
+ //\r
+ // function provided for backward compatibility\r
+ //\r
+ AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");\r
+ fraw = 0; // avoid warnings\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+AliTRDrawStream::~AliTRDrawStream()\r
+{\r
+ //\r
+ // destructor\r
+ //\r
+ delete fGeometry;\r
+}\r
+\r
+//------------------------------------------------------------\r
+AliTRDrawStream & AliTRDrawStream::operator=(const AliTRDrawStream &)\r
+{\r
+ //\r
+ // we are not using this functionality\r
+ //\r
+ AliFatal("May not use.");\r
+\r
+ return *this;\r
+}\r
+\r
+//___________________________________________________________\r
+void AliTRDrawStream::SwapOnEndian()\r
+{\r
+ //\r
+ // Check the endian and swap if needed\r
+ //\r
+ int itemp = 1;\r
+ char* ptemp = (char*) &itemp;\r
+ if (ptemp[0] != 1) {\r
+ if (fgDebugFlag) AliDebug(8, "Swapping.");\r
+\r
+ fpPos = fpBegin;\r
+ UInt_t iutmp = 0;\r
+ while (fpPos < fpEnd) {\r
+ fpPos += 1;\r
+ iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) << 8) |\r
+ ((*fpPos & 0x00ff0000U) >> 8) | ((*fpPos & 0xff000000U) >> 24));\r
+ // here we override the value in the buffer!\r
+ *fpPos = iutmp; \r
+ }\r
+ fpPos = fpBegin;\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)\r
+{\r
+ //\r
+ // dump given number of words for debugging\r
+ //\r
+ TString tsreturn = Form("\n[ Dump Sequence at 0x%08x ] : ", px);\r
+ for (UInt_t i = 0; i < iw; i++) {\r
+ if ( iw != 0 && px + iw > fpEnd) return kFALSE;\r
+\r
+ if (i % 8 == 0) tsreturn += "\n ";\r
+ if (marker != 0 && marker == px[i]) tsreturn += Form(" *>0x%08x<* ", px[i]);\r
+ else tsreturn += Form("0x%08x ", px[i]);\r
+ }\r
+ tsreturn += "\n";\r
+\r
+ AliInfo(tsreturn.Data());\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::SkipWords(UInt_t iw)\r
+{\r
+ //\r
+ // Skip words corresponding to iw\r
+ //\r
+ if ( fpPos + iw < fpEnd ) {\r
+ fpPos += iw;\r
+ return kTRUE;\r
+ }\r
+ else {\r
+ if (fWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1));\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::SetReader(AliRawReader * reader)\r
+{\r
+ //\r
+ // Set reader pointer\r
+ //\r
+ if (reader != 0) {\r
+ fRawReader = reader;\r
+ if (fRawReader) {\r
+ return Init();\r
+ }\r
+ else {\r
+ AliWarning("Unable to setup reader.");\r
+ return kFALSE;\r
+ }\r
+ }\r
+ else {\r
+ AliWarning("AliRawReader argument is 0.");\r
+ fRawReader = 0;\r
+ }\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Int_t AliTRDrawStream::NextBuffer()\r
+{\r
+ //\r
+ // return -1 if no more buffers available\r
+ // return 0 DecodeSM failed (clean data required for example) but still maybe more data to come\r
+ // return 1 DecodeSM OK\r
+ // \r
+ if (fRawReader != 0) {\r
+ UChar_t *buffer = 0;\r
+ UInt_t length = 0;\r
+ Bool_t kBufferSet = fRawReader->ReadNextData(buffer);\r
+ if (kBufferSet == kTRUE) {\r
+ if (fgDebugFlag) AliDebug(9, "Buffer is set.");\r
+ length = fRawReader->GetDataSize();\r
+ if (fgExtraSkip == kTRUE) {\r
+ buffer += EXTRA_LEAD_WORDS * WORD_SIZE;\r
+ length -= EXTRA_LEAD_WORDS * WORD_SIZE;\r
+ }\r
+\r
+ if (fgSkipCDH == kTRUE) {\r
+ buffer += CDH_WORDS * WORD_SIZE;\r
+ length -= CDH_WORDS * WORD_SIZE;\r
+ }\r
+\r
+ if (length > 0) {\r
+ if (fgDebugFlag) AliDebug(9, Form("Buffer length : %d", length));\r
+ if (fgEnableMemoryReset) ResetMemory(); //[mj]\r
+ if (DecodeSM((void*)buffer, length) == kTRUE)\r
+ return 1;\r
+ else\r
+ return 0;\r
+ }\r
+ }\r
+ else {\r
+ return -1;\r
+ }\r
+ }\r
+\r
+ return -1;\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawStream::ResetCounters()\r
+{\r
+ //\r
+ // reset some global counters\r
+ //\r
+ fBufferRead = kFALSE; // read buffer if it is false (important to read buffer)\r
+\r
+ fStackNumber = 0;\r
+ fStackLinkNumber = 0;\r
+ fDecodedADCs = 0;\r
+\r
+ fSM.fActiveStacks = 0;\r
+ fSM.fNexpectedHalfChambers = 0;\r
+\r
+ fLinkTrackletCounter = 0;\r
+ fLastEventCounter = 0;\r
+ fEventCounter = 0;\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawStream::ResetIterators()\r
+{\r
+ //\r
+ // reset data which should be reset every sm\r
+ //\r
+ fStackNumber = 0; // reset for Next() function \r
+ fStackLinkNumber = 0; // reset for Next() function\r
+ fhcMCMcounter = 0; \r
+ fmcmADCcounter = 0;\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawStream::ResetPerSM()\r
+{\r
+ //\r
+ // reset every SM\r
+ //\r
+ fSM.fHeaderSize = 0;\r
+ fSM.fTrackletEnable = kFALSE;\r
+ fSM.fCorrupted = 0;\r
+ fSM.fNexpectedHalfChambers = 0;\r
+ fSM.fNexpectedHalfChambers = 0;\r
+ fSM.fClean = kTRUE;\r
+ fSM.fPos = NULL;\r
+ for (Int_t i=0; i<5; i++){\r
+ fSM.fStackActive[i] = kFALSE;\r
+ }\r
+} \r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawStream::ResetPerStack()\r
+{\r
+ //\r
+ // reset every Stack\r
+ //\r
+ fStack->fHeaderSize = 0;\r
+ fStack->fActiveLinks = 0;\r
+ fStack->fPos = NULL;\r
+ for (Int_t i=0; i<12; i++){\r
+ fStack->fLinksActive[i] = kFALSE;\r
+ fStack->fLinksDataType[i] = 0;\r
+ fStack->fLinksMonitor[i] = 0;\r
+ fStack->fLinkMonitorError[i] = 0;\r
+ }\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawStream::ResetPerHC()\r
+{\r
+ //\r
+ // reset every HC\r
+ //\r
+ fEventCounter = 0;\r
+ fHC->fTrackletError = 0;\r
+ fHC->fNTracklets = 0;\r
+ fHC->fSpecialRawV = 0;\r
+ fHC->fRawVMajor = 0;\r
+ fHC->fRawVMajorOpt = 0;\r
+ fHC->fRawVMinor = 0;\r
+ fHC->fNExtraWords = 0;\r
+ fHC->fDCSboard = 0;\r
+ fHC->fSM = 0;\r
+ fHC->fStack = 0;\r
+ fHC->fLayer = 0;\r
+ fHC->fSide = 0;\r
+ fHC->fTimeBins = 0;\r
+ fHC->fBunchCrossCounter = 0;\r
+ fHC->fPreTriggerCounter = 0;\r
+ fHC->fPreTriggerPhase = 0;\r
+ fHC->fDET = 0;\r
+ fHC->fROC = 0;\r
+ fHC->fRowMax = 0;\r
+ fHC->fColMax = 0;\r
+ fHC->fMCMmax = 0;\r
+ fHC->fH0Corrupted = 0;\r
+ fHC->fH1Corrupted = 0;\r
+ fHC->fCorrupted = 0;\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawStream::ResetPerMCM()\r
+{\r
+ //\r
+ // reset every MCM \r
+ //\r
+ fMCM->fROB = 0;\r
+ fMCM->fMCM = 0;\r
+ fMCM->fROW = 0;\r
+ fMCM->fEvCounter = 0;\r
+ fMCM->fADCMask = 0;\r
+ fMCM->fADCMaskWord = 0;\r
+ fMCM->fADCmax = 0;\r
+ fMCM->fADCcount = 0;\r
+ fMCM->fSingleADCwords = 0;\r
+ fMCM->fMCMhdCorrupted = 0;\r
+ fMCM->fADCmaskCorrupted = 0;\r
+ fMCM->fCorrupted = 0;\r
+ fMCM->fPos = NULL;\r
+ fMCM->fAdcDataPos = NULL;\r
+ fMCM->fADCcounter = 0;\r
+\r
+ memset(fMCM->fADCchannel, 0, TRDMAXADC*sizeof(UInt_t));\r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawStream::ResetPerADC()\r
+{\r
+ //\r
+ // reset every ADC \r
+ //\r
+ fADC->fPos = NULL;\r
+ fADC->fADCnumber = 0;\r
+ fADC->fExtendedCOL = 0;\r
+ fADC->fCOL = 0;\r
+ fADC->fIsShared = kTRUE;\r
+ fADC->fCorrupted = 0;\r
+\r
+ //memset(fADC->fSignals, 0, GetNumberOfTimeBins()*sizeof(Int_t));\r
+ memset(fADC->fSignals, 0, TRDMAXTBINS*sizeof(Int_t)); \r
+}\r
+\r
+//------------------------------------------------------------\r
+void AliTRDrawStream::ResetMemory()\r
+{ \r
+ // \r
+ // initialize all the data members to prevent read data from memory for previous buffer \r
+ // \r
+ ResetPerSM();\r
+ for (Int_t istack=0; istack<5; istack++){\r
+ fStack = &fSM.fStacks[istack];\r
+ ResetPerStack();\r
+ for (Int_t ilink=0; ilink<12; ilink++){\r
+ fHC = &fStack->fHalfChambers[ilink];\r
+ ResetPerHC();\r
+ for (Int_t imcm=0; imcm<TRDMAXMCM; imcm++){\r
+ fMCM = &fHC->fMCMs[imcm];\r
+ ResetPerMCM();\r
+ for (Int_t iadc=0; iadc<TRDMAXADC; iadc++){\r
+ fADC = &fMCM->fADCs[iadc];\r
+ ResetPerADC();\r
+ } // iadc\r
+ } // imcm\r
+ } // ilink \r
+ } // istack\r
+} \r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::Next()\r
+{\r
+ //\r
+ // returns with true on next adc read\r
+ // returns false on errors and end of buffer\r
+ // \r
+ if (fBufferRead) {\r
+ while (fStackNumber < 5 && fSM.fActiveStacks > 0) {\r
+ if (fSM.fStackActive[fStackNumber] == kTRUE) {\r
+ fStack = &fSM.fStacks[fStackNumber];\r
+ while (fStackLinkNumber < 12) {\r
+ if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0) {\r
+ fHC = &fStack->fHalfChambers[fStackLinkNumber];\r
+ if (!fHC) {\r
+ AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));\r
+ return kFALSE;\r
+ }\r
+ 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 \r
+ while (fhcMCMcounter < fHC->fMCMmax) {\r
+ fMCM = &fHC->fMCMs[fhcMCMcounter];\r
+ if (!fMCM) {\r
+ AliError(Form("HC missing at stack %d link %d atMCMslot %d", \r
+ fStackNumber, fStackLinkNumber, fhcMCMcounter));\r
+ return kFALSE;\r
+ }\r
+ while(fmcmADCcounter < fMCM->fADCmax) {\r
+ fADC = &fMCM->fADCs[fmcmADCcounter];\r
+ if (!fADC) {\r
+ AliError(Form("ADC missing at stack %d link %d MCMslot %d ADCslot %d", \r
+ fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));\r
+ return kFALSE;\r
+ }\r
+ fmcmADCcounter++;\r
+ if (fSharedPadsOn) {\r
+ return kTRUE;\r
+ }\r
+ else {\r
+ if (fADC->fIsShared == kFALSE)\r
+ return kTRUE;\r
+ }\r
+ } // while fmcmADCcounter\r
+ fhcMCMcounter++;\r
+ fmcmADCcounter = 0; // next MCM should go through all active ADCs - start from 0\r
+ } // while fhcMCMcounter\r
+ } // if HC OK\r
+ } // if link active\r
+ fStackLinkNumber++;\r
+ fhcMCMcounter = 0; // next stack link (HC) should go through all active MCMs - start from 0\r
+ } // while fStackLinkNumber\r
+ } // if stack active\r
+ fStackNumber++;\r
+ fStackLinkNumber = 0; // next stack should go through all links - start from 0\r
+ } // while fStackNumber\r
+ } // if fBufferRead\r
+\r
+ // in case rawreader manages the mem buffers, go for the next buffer \r
+ if (fRawReader) {\r
+ Int_t nextBuff = NextBuffer();\r
+ while (nextBuff != -1) {\r
+ if (nextBuff > 0) {\r
+ fBufferRead = kTRUE;\r
+ return Next(); \r
+ }\r
+ nextBuff = NextBuffer();\r
+ }\r
+ }\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Int_t AliTRDrawStream::NextChamber(AliTRDdigitsManager *const digitsManager, UInt_t **trackletContainer, UShort_t **/*errorCodeContainer*/) \r
+{\r
+ //\r
+ // Fills single chamber digit array \r
+ // Return value is the detector number\r
+ //\r
+ AliTRDarrayADC *digits = 0;\r
+ AliTRDarrayDictionary *track0 = 0;\r
+ AliTRDarrayDictionary *track1 = 0;\r
+ AliTRDarrayDictionary *track2 = 0; \r
+ AliTRDSignalIndex *indexes = 0;\r
+ AliTRDdigitsParam *digitsparam = 0;\r
+\r
+ // Loop through the digits\r
+ Int_t lastdet = -1;\r
+ Int_t det = -1;\r
+ Int_t lastside = -1; \r
+ Int_t side = -1;\r
+ Int_t it = 0;\r
+ Int_t ntracklets = 0;\r
+\r
+ if (trackletContainer) { \r
+ for (Int_t i = 0; i < 2; i++) \r
+ for (Int_t j = 0; j < MAXTRACKLETSPERHC; j++) \r
+ trackletContainer[i][j] = 0; \r
+ }\r
+\r
+ while (Next()) {\r
+ det = GetDet();\r
+ side = GetSide();\r
+\r
+ if (trackletContainer) {\r
+ if ((det + side*AliTRDgeometry::kNdet) != (lastdet + lastside*AliTRDgeometry::kNdet)) {\r
+ if (det != lastdet) {\r
+ if (lastdet != -1) {\r
+ fmcmADCcounter--; \r
+ return lastdet;\r
+ }\r
+ }\r
+ ntracklets = GetNTracklets();\r
+ if (ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets); //copy tracklet words to trackletContainer array\r
+ lastside = side; \r
+ } \r
+ } \r
+\r
+ if (det != lastdet) {\r
+ // If new detector found\r
+ if (lastdet == -1) {\r
+ lastdet = det;\r
+ fLastHC = fHC;\r
+ }\r
+ else {\r
+ fmcmADCcounter--; \r
+ fHC = fLastHC ;\r
+ return lastdet;\r
+ }\r
+\r
+ if (det < 0 || det >= AliTRDgeometry::kNdet) {\r
+ if (fSM.fClean == kTRUE) {\r
+ AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));\r
+ }\r
+ else {\r
+ AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));\r
+ }\r
+ continue;\r
+ }\r
+\r
+ // Add a container for the digits of this detector\r
+ digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);\r
+\r
+ if (digitsManager->UsesDictionaries()) {\r
+ track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);\r
+ track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);\r
+ track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);\r
+ }\r
+\r
+ if (!digits) {\r
+ if (fSM.fClean == kTRUE) {\r
+ AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));\r
+ }\r
+ else {\r
+ AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));\r
+ }\r
+ return -1;\r
+ }\r
+\r
+ //Int_t rowMax = GetRowMax();\r
+ Int_t rowMax = fGeometry->RowmaxC1(); // we use maximum row number among all detectors to reuse memory\r
+ Int_t colMax = GetColMax();\r
+ Int_t ntbins = GetNumberOfTimeBins();\r
+\r
+ // Set digitparam variables\r
+ digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();\r
+ digitsparam->SetPretriggerPhase(det,GetPreTriggerPhase());\r
+ digitsparam->SetNTimeBins(det,ntbins);\r
+ fCommonAdditive=10;\r
+ digitsparam->SetADCbaseline(det,fCommonAdditive);\r
+\r
+ // Allocate memory space for the digits buffer\r
+ //if (digits->GetNtime() == 0) {\r
+ if (ntbins != digits->GetNtime()) {\r
+ digits->Allocate(rowMax, colMax, ntbins);\r
+ if (digitsManager->UsesDictionaries()) {\r
+ track0->Allocate(rowMax, colMax, ntbins);\r
+ track1->Allocate(rowMax, colMax, ntbins);\r
+ track2->Allocate(rowMax, colMax, ntbins);\r
+ }\r
+ }\r
+\r
+ indexes = digitsManager->GetIndexes(det);\r
+ indexes->SetSM(GetSM());\r
+ indexes->SetStack(GetStack());\r
+ indexes->SetLayer(GetLayer());\r
+ indexes->SetDetNumber(det);\r
+ if (indexes->IsAllocated() == kFALSE)\r
+ indexes->Allocate(rowMax, colMax, ntbins);\r
+ }\r
+\r
+ // ntimebins data are ready to read\r
+ for (it = 0; it < GetNumberOfTimeBins(); it++) {\r
+ digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), it, GetSignals()[it]);\r
+ if (!(GetCol()<0)) indexes->AddIndexRC(GetRow(), GetCol());\r
+ if (digitsManager->UsesDictionaries()) {\r
+ track0->SetData(GetRow(), GetCol(), it, 0);\r
+ track1->SetData(GetRow(), GetCol(), it, 0);\r
+ track2->SetData(GetRow(), GetCol(), it, 0);\r
+ }\r
+ } // it\r
+ } // while Next()\r
+\r
+ return det;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::Init()\r
+{\r
+ //\r
+ // Initialize geometry and fee parameters \r
+ //\r
+ TDirectory *saveDir = gDirectory; \r
+ \r
+ if (!fGeometry) {\r
+ fGeometry = new AliTRDgeometry();\r
+ if (!fGeometry) {\r
+ AliError("Geometry FAILED!");\r
+ return kFALSE;\r
+ }\r
+ }\r
+\r
+ fTRDfeeParam = AliTRDfeeParam::Instance();\r
+ if (!fTRDfeeParam) {\r
+ AliError("AliTRDfeeParam FAILED!");\r
+ return kFALSE;\r
+ }\r
+\r
+ fMaxADCgeom = (Int_t)fGeometry->ADCmax();\r
+\r
+ ResetCounters(); // fBufferRead is set to kFALSE - important\r
+\r
+ saveDir->cd();\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::InitBuffer(void * const buffer, UInt_t length)\r
+{\r
+ // \r
+ // set initial information about the buffer\r
+ //\r
+ if (fgDebugFlag) AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));\r
+ if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041) // tmp protection\r
+ return kFALSE; \r
+\r
+ if (WORD_SIZE == 0) {\r
+ AliFatal("Strange word size. size of UInt_t == 0");\r
+ return kFALSE;\r
+ }\r
+\r
+ ResetCounters();\r
+\r
+ fpBegin = (UInt_t *)buffer;\r
+ fWordLength = length/WORD_SIZE;\r
+ fpEnd = fpBegin + fWordLength;\r
+ fpPos = fpBegin;\r
+\r
+ if (fpBegin == 0 || length <= 0) {\r
+ AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%08x of size %d", fpBegin, length));\r
+ return kFALSE;\r
+ }\r
+\r
+ SwapOnEndian();\r
+\r
+ if (fgDumpHead >= 0) {\r
+ if ( fgDumpHead == 0 ) { // dump all words\r
+ AliInfo(Form("---------- Dumping all words from the beginnig of the buffer ----------"));\r
+ if (DumpWords(fpBegin, fWordLength) == kFALSE) AliError("Dump failed. Not enough data.");\r
+ } \r
+ else {\r
+ AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));\r
+ if (DumpWords(fpBegin, fgDumpHead) == kFALSE) AliError("Dump failed. Not enough data.");\r
+ }\r
+ AliInfo(Form("---------- Dumping ended ----------------------------------------------"));\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeGTUheader()\r
+{\r
+ // Decode Supermodule Index Word\r
+ DecodeSMInfo(fpPos, &fSM);\r
+\r
+ if (fgDebugFlag) AliDebug(5, DumpSMInfo(&fSM));\r
+\r
+ fpPos++;\r
+ if (fpPos < fpEnd) {\r
+ // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.\r
+ // For the moment, we skip decoding these words \r
+ if (SkipWords(fSM.fHeaderSize) == kTRUE) {\r
+ for (Int_t istack = 0; istack < 5; istack++) {\r
+ if (fSM.fStackActive[istack] == kFALSE)\r
+ continue;\r
+\r
+ fStack = &fSM.fStacks[istack];\r
+\r
+ // Decode Stack Index Word of given stack\r
+ DecodeStackInfo(fpPos, fStack);\r
+ fpPos++;\r
+\r
+ fSM.fNexpectedHalfChambers += fStack->fActiveLinks;\r
+ \r
+ if (fgDebugFlag) AliDebug(5, DumpStackInfo(fStack));\r
+ \r
+ if (SkipWords(fStack->fHeaderSize-6) == kFALSE) { // 6 is the 6 stack header words for 12 links \r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");\r
+ return kFALSE;\r
+ }\r
+ for (Int_t iword=0; iword<6; iword++) { // decode 6 stack header words\r
+ // Decode Stack Header Word of given stack\r
+ DecodeStackHeader(fpPos, fStack, iword); \r
+ fpPos++;\r
+ }\r
+ }\r
+ }\r
+ else {\r
+ return kFALSE;\r
+ }\r
+ }\r
+ else {\r
+ if (fWarnError) AliWarning("No additional sm headers and stack index words present.");\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fpPos < fpEnd) {\r
+ if (fgDebugFlag) AliDebug(5, "GTU headers are OK.");\r
+ }\r
+ else {\r
+ if (fWarnError) AliWarning("No data just after GTU headers.");\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fgDebugFlag) AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeSM(void * const buffer, UInt_t length)\r
+{\r
+ //\r
+ // decode one sm data in buffer\r
+ //\r
+ ResetIterators(); \r
+\r
+ fSM.fClean = kTRUE;\r
+ if (InitBuffer(buffer, length) == kFALSE) {\r
+ if (fWarnError) AliError("InitBuffer failed."); \r
+ fSM.fClean = kFALSE;\r
+ return kFALSE;\r
+ }\r
+\r
+ if (DecodeGTUheader()== kFALSE)\r
+ return kFALSE;\r
+\r
+ for (Int_t istack = 0; istack < 5; istack++) {\r
+ fStackNumber = istack; \r
+ if (fSM.fStackActive[istack] == kFALSE)\r
+ continue;\r
+ \r
+ fStack = &fSM.fStacks[istack];\r
+\r
+ fgLastHC = -1; // to check rob number odering \r
+ for (Int_t ilink = 0; ilink < 12; ilink++) {\r
+ fStackLinkNumber = ilink; \r
+ if (fStack->fLinksActive[ilink] == kFALSE)\r
+ continue;\r
+\r
+ // check GTU link monitor \r
+ if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0)) {\r
+ fStack->fLinkMonitorError[ilink] = 1;\r
+ SeekEndOfData(); // skip this HC data if GTU link monitor report error\r
+ fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error\r
+ continue; \r
+ }\r
+\r
+ if (fpPos >= fpEnd) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing"); \r
+ if (fWarnError) AliError("Link data missing."); \r
+ fSM.fClean = kFALSE;\r
+ break;\r
+ }\r
+\r
+ fHC = &fStack->fHalfChambers[ilink];\r
+ ResetPerHC();\r
+\r
+ if (fSM.fTrackletEnable == kTRUE) {\r
+ if (DecodeTracklets() == kFALSE) {\r
+ fSM.fClean = kFALSE;\r
+ SeekEndOfData();\r
+\r
+ if (fWarnError) {\r
+ AliError(Form("Tracklet decoding failed stack %d link %d", fStackNumber, fStackLinkNumber));\r
+ }\r
+ continue;\r
+ }\r
+ }\r
+\r
+ if (fpPos >= fpEnd) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing"); \r
+ if (fWarnError) AliError("HC data missing."); \r
+ fSM.fClean = kFALSE;\r
+ break;\r
+ }\r
+ \r
+ fgLastROB = -1; // to check mcm number odering \r
+ fgLastIndex = -1 ; // to check mcm number odering \r
+ if (DecodeHC() == kFALSE) {\r
+ fSM.fClean = kFALSE;\r
+ if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW \r
+ // during ADC data decoding or MCM header decoding\r
+ // we don't seek ENDOFRAWDATAMARKER\r
+ if (fWarnError) {\r
+ AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));\r
+ AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));\r
+ }\r
+ \r
+ continue;\r
+ }\r
+ else {\r
+ SeekEndOfData(); // make sure that finish off with the end of data markers\r
+ }\r
+ } // ilink\r
+ } // istack\r
+\r
+ ResetIterators(); // need to do it again for Next() function \r
+\r
+ if (fSM.fClean == kTRUE)\r
+ return kTRUE;\r
+ \r
+ if (fgCleanDataOnly && (fSM.fClean == kFALSE)) {\r
+ if (fWarnError) {\r
+ AliWarning("Buffer with errors. Returning FALSE.");\r
+ AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));\r
+ }\r
+ fSM.fActiveStacks = 0; // Next() will not give data\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Int_t AliTRDrawStream::DecodeSM()\r
+{\r
+ //\r
+ // decode SM data in case AliRawReader is in use\r
+ // \r
+ if (fRawReader) {\r
+ Int_t nextBuff = NextBuffer();\r
+ while (nextBuff != -1) {\r
+ if (nextBuff > 0)\r
+ return nextBuff; \r
+ nextBuff = NextBuffer();\r
+ }\r
+ return -1;\r
+ }\r
+ else {\r
+ AliWarning("AliRawReader not set.");\r
+ }\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Int_t AliTRDrawStream::DecodeSM(AliRawReader *reader)\r
+{\r
+ //\r
+ // decode SM with the AliRawReader\r
+ //\r
+ if (reader != 0) {\r
+ fRawReader = reader;\r
+ return DecodeSM();\r
+ }\r
+ else {\r
+ AliWarning("Argument AliRawReader is 0.");\r
+ }\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::SeekEndOfData()\r
+{\r
+ //\r
+ // go to end of data marker\r
+ //\r
+ Int_t fEndOfDataCount = 0;\r
+ fNWordsCounter = 0;\r
+\r
+ while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r
+ fpPos++;\r
+ fNWordsCounter++;\r
+ }\r
+ while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r
+ fEndOfDataCount++;\r
+ fpPos++; \r
+ }\r
+ \r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::SkipMCMdata(UInt_t iw)\r
+{\r
+ //\r
+ // skip mcm data words due to corruption \r
+ //\r
+ if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));\r
+ UInt_t iwcounter = 0; \r
+ while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw) {\r
+ if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");\r
+ fMCM->fCorrupted += 16;\r
+ fHC->fCorrupted += 16;\r
+ return kFALSE;\r
+ } \r
+ fpPos++;\r
+ iwcounter++; \r
+ }\r
+\r
+ if (iwcounter == iw) {\r
+ fpPos++;\r
+ return kTRUE;\r
+ }\r
+\r
+ if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::SeekNextMCMheader()\r
+{\r
+ //\r
+ // go to mcm marker\r
+ //\r
+ fpPos++;\r
+\r
+ while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r
+ if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0) { \r
+ if (fgDebugFlag) AliDebug(11,Form("^^^ Found : Pos 0x%08x : Val 0x%08x", fpPos, *fpPos));\r
+ return kTRUE;\r
+ }\r
+ if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {\r
+ fMCM->fCorrupted += 16;\r
+ fHC->fCorrupted += 16;\r
+ return kFALSE;\r
+ } \r
+ fpPos++;\r
+ }\r
+\r
+ SeekEndOfData();\r
+\r
+ return kFALSE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeTracklets()\r
+{\r
+ //\r
+ // decode tracklets\r
+ //\r
+ fLinkTrackletCounter = 0;\r
+ fEndOfTrackletCount = 0;\r
+ fHC->fNTracklets = 0;\r
+\r
+ for (Int_t i = 0; i < MAXTRACKLETSPERHC; i++) \r
+ fHC->fTrackletWords[i] = 0; \r
+\r
+ if (fgDebugFlag) AliDebug(10, Form("Decode tracklets at 0x%08x : 0x%08x", fpPos, *fpPos));\r
+\r
+ while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd ) {\r
+ if (fgDebugFlag) AliDebug(10, Form("Tracklet found at 0x%08x : 0x%08x", fpPos, *fpPos));\r
+\r
+ fLinkTrackletCounter++;\r
+\r
+ if (fLinkTrackletCounter > MAXTRACKLETSPERHC) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d.", \r
+ fLinkTrackletCounter, MAXTRACKLETSPERHC));\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets"); \r
+ fHC->fTrackletError = 1;\r
+ return kFALSE;\r
+ }\r
+\r
+ fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into array \r
+ fHC->fNTracklets = fLinkTrackletCounter;\r
+ fpPos++;\r
+ }\r
+\r
+ while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd ) {\r
+ if (fgDebugFlag) AliDebug(10, Form("EoTracklets found at 0x%08x : 0x%08x", fpPos, *fpPos));\r
+\r
+ fEndOfTrackletCount++;\r
+ fpPos++;\r
+ }\r
+\r
+ if ( fEndOfTrackletCount < 2 ) {\r
+ if (fgDebugFlag) AliDebug(11,"End of tracklets word missing"); \r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing"); \r
+ fHC->fTrackletError += 2;\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::IsRowValid()\r
+{\r
+ //\r
+ // check if the row number is in valid range\r
+ //\r
+ if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||\r
+ (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 ) {\r
+ if (fgDebugFlag) AliDebug(11,Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"\r
+ , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::IsMCMheaderOK()\r
+{\r
+ //\r
+ // check the mcm header\r
+ //\r
+ if (fgLastROB != fMCM->fROB) {\r
+ fgLastIndex = 0;\r
+ if (fgLastROB== -1) fgLastROB = fMCM->fROB;\r
+ }\r
+ else {\r
+ Int_t matchingcounter = 0; \r
+ for (Int_t i=fgLastIndex+1; i<16; i++) {\r
+ if ( fMCM->fMCM == fgMCMordering[i] ) {\r
+ fgLastIndex = i;\r
+ matchingcounter++;\r
+ break;\r
+ }\r
+ }\r
+ if (matchingcounter == 0) { \r
+ fMCM->fMCMhdCorrupted += 2;\r
+ 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));\r
+ }\r
+ }\r
+\r
+ if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) {\r
+ if ( fMCM->fROB < (fMCM-1)->fROB ) {\r
+ fMCM->fMCMhdCorrupted += 2;\r
+ 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));\r
+ }\r
+ else fgLastROB = fMCM->fROB; \r
+ }\r
+\r
+ fgLastHC = fHC->fLayer*2 + fHC->fSide; \r
+\r
+ /*\r
+ // this check will come back later again when we have "patched MCM map"\r
+ int expectedROB = -1;\r
+ if(!fHC->fSide) expectedROB = int(fHC->fMCMmax/16)*2;\r
+ else expectedROB = int(fHC->fMCMmax/16)*2 + 1;\r
+ int expectedMCM = 4*(3-int((fHC->fMCMmax%16)/4)) + fHC->fMCMmax%4;\r
+\r
+ if ( expectedROB != fMCM->fROB || expectedMCM != fMCM->fMCM)\r
+ {\r
+ fMCM->fMCMhdCorrupted += 2;\r
+ AliDebug(11,Form("ROB expected %d ROB read %d, MCM expected %d MCM read %d\n",expectedROB, fMCM->fROB, expectedMCM, fMCM->fMCM));\r
+ }\r
+ */\r
+\r
+ // below two conditions are redundant \r
+ /*\r
+ if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 ) \r
+ {\r
+ fMCM->fMCMhdCorrupted += 8; // need to assign new number\r
+ if (fgDebugFlag) AliDebug(11,Form("ROB or MCM number is out of range. %s\n", DumpMCMinfo(fMCM)));\r
+ }\r
+ if (IsRowValid() == kFALSE)\r
+ {\r
+ fMCM->fMCMhdCorrupted += 16; // need to assign new number\r
+ }\r
+ */ \r
+ \r
+ if (fEventCounter == 0) {\r
+ fEventCounter = fMCM->fEvCounter;\r
+ }\r
+\r
+ if (fEventCounter != fMCM->fEvCounter) {\r
+ fMCM->fMCMhdCorrupted += 4; \r
+ if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n"\r
+ , fMCM->fEvCounter, fEventCounter, DumpMCMinfo(fMCM)));\r
+ }\r
+\r
+ if (fEventCounter < fLastEventCounter) {\r
+ fMCM->fMCMhdCorrupted += 8; \r
+ if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));\r
+ }\r
+\r
+ if ( fMCM->fADCmaskCorrupted > 0 ) {\r
+ return kFALSE;\r
+ }\r
+\r
+ if ( fMCM->fMCMhdCorrupted > 0 ) {\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeMCMheader()\r
+{\r
+ //\r
+ // decode the mcm header\r
+ //\r
+ DecodeMCMheader(fpPos, fMCM); \r
+\r
+ if (fgDumpingEnable) { \r
+ if (fMCM->fMCM == fgDumpingMCM) {\r
+ if (fMCM->fROB == fgDumpingROB && fHC->fLayer == fgDumpingLayer) {\r
+ if (fHC->fSM == fgDumpingSM && fHC->fStack == fgDumpingStack) {\r
+ if (fgDebugFlag) {\r
+ AliDebug(5,DumpHCinfoH0(fHC));\r
+ AliDebug(5,DumpMCMinfo(fMCM));\r
+ }\r
+ DumpWords(fpPos, 212);\r
+ } \r
+ }\r
+ }\r
+ }\r
+\r
+ if (fHC->fCorrupted >= 16) {\r
+ fpPos--; \r
+ return kFALSE;\r
+ }\r
+ fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM); \r
+\r
+ if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || ((fHC->fRawVMajor & 32) == 32)) { //cover old and new version definition of ZS data\r
+ fpPos++;\r
+ if ( fpPos < fpEnd ) {\r
+ DecodeMask(fpPos, fMCM); \r
+ if (fHC->fCorrupted >= 16) {\r
+ fpPos--; \r
+ return kFALSE;\r
+ }\r
+ MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);\r
+ fMCM->fAdcDataPos = fpPos + 1;\r
+ }\r
+ else {\r
+ if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END."); \r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing"); \r
+ fHC->fCorrupted += 32;\r
+ return kFALSE;\r
+ }\r
+ }\r
+ else {\r
+ UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;\r
+ DecodeMask(&dummyMask, fMCM); \r
+ MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);\r
+ fMCM->fAdcDataPos = fpPos + 1;\r
+ }\r
+\r
+ if (fgDebugFlag) { \r
+ AliDebug(6, DumpMCMinfo(fMCM));\r
+ AliDebug(7, DumpMCMadcMask(fMCM));\r
+ }\r
+\r
+ if (IsMCMheaderOK() == kFALSE) {\r
+ return kFALSE;\r
+ } \r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::IsHCheaderOK()\r
+{\r
+ //\r
+ // check insanity of half chamber header\r
+ //\r
+ if (fHC->fStack < 0 || fHC->fStack > 4) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStack));\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayer));\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fSide < 0 || fHC->fSide > 1) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSide));\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fgStackNumberChecker) {\r
+ if (fHC->fStack != fStackNumber) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d", \r
+ fHC->fStack, fStackNumber));\r
+ fStackNumber = -1;\r
+ return kFALSE;\r
+ }\r
+ }\r
+\r
+ if (fgStackLinkNumberChecker) {\r
+ if (fHC->fLayer * 2 + fHC->fSide != fStackLinkNumber) {\r
+ // let it make flexible to consider known fiber swapping\r
+ //if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1)) { \r
+ if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s", \r
+ fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));\r
+ fStackLinkNumber = -1;\r
+ return kFALSE; \r
+ }\r
+ }\r
+\r
+ // SLOW GEOM : consistancy check with geometry\r
+ fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);\r
+ if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET)); \r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det"); \r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fSM != fGeometry->GetSector(fHC->fDET) || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector) {\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d", \r
+ fHC->fSM, fGeometry->GetSector(fHC->fDET), fHC->fStack, fHC->fLayer, fHC->fDET));\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM"); \r
+ return kFALSE;\r
+ }\r
+\r
+ fHC->fROC = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);\r
+ if (fHC->fROC < 0) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC"); \r
+ return kFALSE;\r
+ }\r
+\r
+ fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);\r
+ if (fHC->fRowMax < 1) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max"); \r
+ return kFALSE;\r
+ }\r
+\r
+ fHC->fColMax = fGeometry->GetColMax(fHC->fROC);\r
+ if (fHC->fColMax < 1) {\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max"); \r
+ return kFALSE;\r
+ }\r
+ \r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeHCheader()\r
+{ \r
+ //\r
+ // decode the half chamber header\r
+ //\r
+ if (DecodeHCwordH0(fpPos, fHC) == kFALSE)\r
+ return kFALSE;\r
+ \r
+ if (fHC->fNExtraWords > 0) {\r
+ fpPos++;\r
+ if (fpPos < fpEnd) {\r
+ if (DecodeHCwordH1(fpPos, fHC) == kFALSE)\r
+ return kFALSE;\r
+ }\r
+ else {\r
+ if (fgDebugFlag) AliDebug(11,"Expected HC header word 1. Fail due to buffer END.");\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing"); \r
+ return kFALSE;\r
+ }\r
+ }\r
+\r
+ if (fgDebugFlag) AliDebug(5, DumpHCinfoH0(fHC));\r
+ if (fgDebugFlag) AliDebug(5, DumpHCinfoH1(fHC));\r
+\r
+ fHC->fDET = -1;\r
+ if (IsHCheaderOK() == kFALSE) {\r
+ fHC->fH0Corrupted += 2;\r
+ if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%08x", *fHC->fPos));\r
+ return kFALSE;\r
+ }\r
+ \r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeHC()\r
+{\r
+ //\r
+ // decode hc header and data\r
+ //\r
+\r
+ if (DecodeHCheader() == kFALSE) {\r
+ if (fWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted"); \r
+ return kFALSE;\r
+ }\r
+ else {\r
+ fpPos++;\r
+ if (fpPos >= fpEnd) {\r
+ fHC->fCorrupted += 1;\r
+ if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer.");\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing"); \r
+ return kFALSE;\r
+ }\r
+ }\r
+\r
+ if ((fHC->fRawVMajor & 64) == 64) { // test pattern data\r
+ AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);\r
+ if (tpStream->DecodeTPdata() == kFALSE) {\r
+ if (fWarnError) AliError("failed to decode test pattern data");\r
+ return kFALSE; \r
+ }\r
+ return kTRUE;\r
+ } \r
+\r
+ fHC->fMCMmax = 0;\r
+ while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) {\r
+ if (fHC->fMCMmax > TRDMAXMCM) {\r
+ fHC->fCorrupted += 2;\r
+ if (fgDebugFlag) AliDebug(11,"More mcm data than expected!");\r
+ if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!"); \r
+ return kFALSE;\r
+ }\r
+\r
+ fMCM = &fHC->fMCMs[fHC->fMCMmax];\r
+\r
+ if (DecodeMCMheader() == kFALSE) {\r
+ if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4\r
+ \r
+ if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) { // stop HC data reading\r
+ fHC->fMCMmax++;\r
+ return kFALSE;\r
+ } \r
+ \r
+ fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number\r
+\r
+ // in case we decide to keep reading data, skip this mcm data and find next mcm header \r
+ if (fMCM->fADCmaskCorrupted < 2) {\r
+ if (SkipMCMdata(fMCM->fADCcount*fMCM->fSingleADCwords) == kFALSE)\r
+ return kFALSE;\r
+ continue;\r
+ }\r
+ else {\r
+ if (SeekNextMCMheader() == kFALSE)\r
+ return kFALSE;\r
+ continue;\r
+ }\r
+ }\r
+\r
+ fHC->fMCMmax++;\r
+\r
+ if (fMCM->fADCmax > 0) {\r
+ fpPos++;\r
+ if (fpPos >= fpEnd) {\r
+ fMCM->fCorrupted += 1;\r
+ if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4\r
+ if (fgDebugFlag) AliDebug(9, Form("Buffer short of data. ADC data expected.")); \r
+ return kFALSE;\r
+ }\r
+\r
+ for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++) {\r
+ fADC = &fMCM->fADCs[iadc];\r
+ fADC->fADCnumber = fMCM->fADCchannel[iadc];\r
+ if (fgDebugFlag) AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.", \r
+ iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));\r
+ if (fpPos + fMCM->fSingleADCwords >= fpEnd) {\r
+ fMCM->fCorrupted += 2;\r
+ if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4\r
+ if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");\r
+ return kFALSE;\r
+ }\r
+\r
+ if (fHC->fRawVMajor < 64) { // normal(real) ADC data\r
+ if (fHC->fTimeBins < 31) {\r
+ if (DecodeADC() == kFALSE) {\r
+ if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4\r
+ if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4\r
+ if (fADC->fIsShared && fADC->fCorrupted == 32) { // check if we are out of the det when the pad is shared\r
+ fADC->fExtendedCOL = -1;\r
+ fADC->fCOL = -1;\r
+ fpPos = fADC->fPos + fMCM->fSingleADCwords;\r
+ }\r
+ else {\r
+ if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));\r
+ if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) \r
+ return kFALSE; // stop HC data reading\r
+ }\r
+ }\r
+ }\r
+ else if (fHC->fTimeBins > 32) {\r
+ if (DecodeADCExtended() == kFALSE) { // decoding TRAP data with ZS and more than 32 samples\r
+ if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4\r
+ if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4\r
+ if (fADC->fIsShared && fADC->fCorrupted == 32) { // check if we are out of the det when the pad is shared\r
+ fADC->fExtendedCOL = -1;\r
+ fADC->fCOL = -1;\r
+ fpPos = fADC->fPos + fMCM->fSingleADCwords;\r
+ }\r
+ else {\r
+ if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));\r
+ if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)\r
+ return kFALSE; // stop HC data reading\r
+ }\r
+ }\r
+ }\r
+ else { // nsamples = 31, 32 are not implemented in the TRAP and should never happen \r
+ if (fWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!"); \r
+ }\r
+ } // if fHC->fRawVMajor\r
+ else { // test pattern data\r
+ if (fWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class\r
+ }\r
+ } // for iadc \r
+ } // if fMCM->fADCmax\r
+ else {\r
+ fpPos++;\r
+ }\r
+ }//while eof data\r
+\r
+ if (fpPos >= fpEnd) {\r
+ if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. There should be one more word left.");\r
+ return kFALSE;\r
+ }\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeADC()\r
+{\r
+ //\r
+ // decode single ADC channel\r
+ //\r
+\r
+ fADC->fCorrupted = 0;\r
+ if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);\r
+ if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);\r
+\r
+ fADC->fPos = fpPos;\r
+ fTbinADC = 0;\r
+\r
+ for (Int_t i = 0; i < GetNumberOfTimeBins(); i++)\r
+ //for (Int_t i = 0; i < TRDMAXTBINS; i++)\r
+ fADC->fSignals[i] = 0;\r
+\r
+ for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++) {\r
+ if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));\r
+ fADC->fCorrupted += 16;\r
+ fHC->fCorrupted += 16; \r
+ fpPos--;\r
+ return kFALSE;\r
+ }\r
+ if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {\r
+ fADC->fCorrupted += 1;\r
+ 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",\r
+ fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));\r
+ fpPos++;\r
+ continue;\r
+ }\r
+\r
+ fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2);\r
+ fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12);\r
+ fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22);\r
+\r
+ fTbinADC += 3;\r
+ fpPos++;\r
+ } // iw\r
+\r
+ if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {\r
+ fADC->fIsShared = kTRUE;\r
+ }\r
+ else {\r
+ fADC->fIsShared = kFALSE;\r
+ }\r
+\r
+ fADC->fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);\r
+ fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);\r
+\r
+ if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) {\r
+ if (fADC->fIsShared == kFALSE) {\r
+ fADC->fCorrupted += 32;\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s", \r
+ fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));\r
+ }\r
+ //else {\r
+ // we are out of the det when the pad is shared\r
+ //if (fgDebugFlag) AliDebug(11, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s", \r
+ // fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));\r
+ //fADC->fCorrupted += 32;\r
+ //}\r
+ }\r
+\r
+ if (fADC->fCorrupted > 0) {\r
+ return kFALSE;\r
+ }\r
+\r
+ fDecodedADCs++;\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//------------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeADCExtended()\r
+{\r
+ //\r
+ // decode single ADC channel\r
+ //\r
+\r
+ fADC->fCorrupted = 0;\r
+ if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);\r
+ if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);\r
+\r
+ fADC->fPos = fpPos;\r
+\r
+ fTbinADC = ((*fpPos & 0x000000fc) >> 2);\r
+ fMCM->fSingleADCwords = ((*fpPos & 0x00000f00) >> 8);\r
+ fADC->fSignals[fTbinADC] = ((*fpPos & 0x003ff000) >> 12);\r
+ fADC->fSignals[fTbinADC+1] = ((*fpPos & 0xffc00000) >> 22);\r
+\r
+ fpPos++; \r
+ 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\r
+ if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));\r
+ fADC->fCorrupted += 16;\r
+ fHC->fCorrupted += 16; \r
+ fpPos--;\r
+ return kFALSE;\r
+ }\r
+ if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {\r
+ fADC->fCorrupted += 1;\r
+ 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",\r
+ fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));\r
+ fpPos++;\r
+ continue;\r
+ }\r
+\r
+ fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0x00000ffc) >> 2);\r
+ fADC->fSignals[fTbinADC + 3] = ((*fpPos & 0x003ff000) >> 12);\r
+ fADC->fSignals[fTbinADC + 4] = ((*fpPos & 0xffc00000) >> 22);\r
+\r
+ fTbinADC += 3;\r
+ fpPos++;\r
+ } // iw\r
+\r
+// for(int i=0; i )\r
+// printf();\r
+\r
+\r
+ if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {\r
+ fADC->fIsShared = kTRUE;\r
+ }\r
+ else {\r
+ fADC->fIsShared = kFALSE;\r
+ }\r
+\r
+ fADC->fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);\r
+ fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);\r
+\r
+ if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) {\r
+ if (fADC->fIsShared == kFALSE) {\r
+ fADC->fCorrupted += 32;\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s", \r
+ fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));\r
+ }\r
+ }\r
+\r
+ if (fADC->fCorrupted > 0) {\r
+ return kFALSE;\r
+ }\r
+\r
+ fDecodedADCs++;\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawStream::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const\r
+{\r
+ //\r
+ // Decode Supermodule Index Word\r
+ // The Supermodule Index Word is a 32-Bit word wit following structure\r
+ // ssssssss ssssssss vvvv rrrr r d t mmmm\r
+ // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use\r
+ // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask \r
+ //\r
+ sm->fPos = (UInt_t*)word; \r
+\r
+ UInt_t vword = *word;\r
+ sm->fHeaderSize = SM_HEADER_SIZE(vword);\r
+ \r
+ if (TRACKLETS_ENABLED(vword) > 0)\r
+ sm->fTrackletEnable = kTRUE;\r
+ else\r
+ sm->fTrackletEnable = kFALSE;\r
+ \r
+ UInt_t stackMask = STACK_MASK(vword);\r
+ sm->fActiveStacks = 0;\r
+ for (Int_t i = 0; i < 5; i++) {\r
+ if (IS_BIT_SET(stackMask,i) > 0) {\r
+ sm->fStackActive[i] = kTRUE;\r
+ sm->fActiveStacks++;\r
+ }\r
+ else {\r
+ sm->fStackActive[i] = kFALSE;\r
+ }\r
+ }\r
+}\r
+\r
+//--------------------------------------------------------\r
+const char *AliTRDrawStream::DumpSMInfo(const struct AliTRDrawSM *sm)\r
+{\r
+ //\r
+ // Get SM structure into a const char\r
+ //\r
+ return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",\r
+ *sm->fPos, sm->fHeaderSize, sm->fTrackletEnable,\r
+ sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],\r
+ sm->fStackActive[3], sm->fStackActive[4]); \r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawStream::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const\r
+{\r
+ //\r
+ // Decode Stack #i Index Word\r
+ // The Stack #i Index Word is a 32-Bit word wit following structure\r
+ // ssssssss ssssssss vvvv mmmm mmmmmmmm\r
+ // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask\r
+ //\r
+ st->fPos = (UInt_t*)word;\r
+ \r
+ UInt_t vword = *word;\r
+ st->fHeaderSize = STACK_HEADER_SIZE(vword);\r
+\r
+ UInt_t linkMask = STACK_LINK_WORD(vword);\r
+ st->fActiveLinks = 0;\r
+ for (Int_t i = 0; i < 12; i++) {\r
+ if (IS_BIT_SET(linkMask,i) > 0) {\r
+ st->fLinksActive[i] = kTRUE;\r
+ st->fActiveLinks++;\r
+ }\r
+ else {\r
+ st->fLinksActive[i] = kFALSE;\r
+ }\r
+ }\r
+}\r
+ \r
+//--------------------------------------------------------\r
+void AliTRDrawStream::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const\r
+{\r
+ //\r
+ // decode gtu header for stack info\r
+ //\r
+ st->fPos = (UInt_t*)word;\r
+ \r
+ UInt_t vword = *word;\r
+ st->fLinksDataType[2*iword] = LINK0_DATA_TYPE_FLAG(vword);\r
+ st->fLinksMonitor[2*iword] = LINK0_MONITOR_FLAG(vword);\r
+ st->fLinksDataType[2*iword+1] = LINK1_DATA_TYPE_FLAG(vword);\r
+ st->fLinksMonitor[2*iword+1] = LINK1_MONITOR_FLAG(vword);\r
+}\r
+\r
+//--------------------------------------------------------\r
+const char *AliTRDrawStream::DumpStackInfo(const struct AliTRDrawStack *st)\r
+{\r
+ //\r
+ // format the string with the stack info\r
+ //\r
+\r
+ return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",\r
+ *st->fPos, st->fHeaderSize,\r
+ st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],\r
+ st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],\r
+ st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);\r
+}\r
+\r
+//--------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const\r
+{\r
+ //\r
+ // decode the hc header word 0\r
+ //\r
+ UInt_t vword = *word;\r
+ hc->fPos[0] = (UInt_t*)word;\r
+\r
+ hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);\r
+ if (hc->fH0Corrupted > 0) {\r
+ if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%08x", *fHC->fPos));\r
+ return kFALSE;\r
+ }\r
+\r
+ hc->fSpecialRawV = HC_SPECIAL_RAW_VERSION(vword);\r
+ hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);\r
+ hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword); \r
+ hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);\r
+ hc->fNExtraWords = HC_EXTRA_WORDS(vword);\r
+ hc->fDCSboard = HC_DCS_BOARD(vword);\r
+ hc->fSM = HC_SM_NUMBER(vword);\r
+ hc->fStack = HC_STACK_NUMBER(vword);\r
+ hc->fLayer = HC_LAYER_NUMBER(vword);\r
+ hc->fSide = HC_SIDE_NUMBER(vword);\r
+\r
+\r
+ return kTRUE;\r
+}\r
+\r
+//--------------------------------------------------------\r
+Bool_t AliTRDrawStream::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const\r
+{\r
+ //\r
+ // decode the hc header word 1\r
+ //\r
+ UInt_t vword = *word;\r
+\r
+ hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);\r
+ if (hc->fH1Corrupted > 0) {\r
+ if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%08x", *fHC->fPos));\r
+ return kFALSE;\r
+ }\r
+\r
+ hc->fTimeBins = HC_NTIMEBINS(vword);\r
+ hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);\r
+ hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);\r
+ hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);\r
+\r
+ hc->fPos[1] = (UInt_t*)word;\r
+\r
+ return kTRUE;\r
+}\r
+ \r
+//--------------------------------------------------------\r
+const char *AliTRDrawStream::DumpHCinfoH0(const struct AliTRDrawHC *hc)\r
+{\r
+ //\r
+ // dump the hc header word 0\r
+ //\r
+ if (!hc)\r
+ return Form("Unable to dump. Null received as parameter!?!");\r
+ else\r
+ return Form("[ HC[0] at 0x%08x ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",\r
+ hc->fPos[0], (hc->fPos[0]) ? *(hc->fPos[0]) : 0, hc->fRawVMajor, \r
+ fRawReader->GetEquipmentId()-1024, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);\r
+}\r
+\r
+//--------------------------------------------------------\r
+const char *AliTRDrawStream::DumpHCinfoH1(const struct AliTRDrawHC *hc)\r
+{\r
+ //\r
+ // dump the hc header word 1\r
+ //\r
+ if (!hc)\r
+ return Form("Unable to dump. Null received as parameter!?!");\r
+ else\r
+ return Form("[ HC[1] at 0x%08x ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",\r
+ hc->fPos[1], (hc->fPos[1]) ? *(hc->fPos[1]) : 0, hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawStream::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r
+{\r
+ //\r
+ // decode the mcm header\r
+ //\r
+ UInt_t vword = *word;\r
+\r
+ if (vword == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));\r
+ mcm->fMCMhdCorrupted += 16;\r
+ fHC->fCorrupted += 16; //to finish data reading of this HC\r
+ }\r
+\r
+ mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error\r
+ if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));\r
+\r
+ mcm->fROB = MCM_ROB_NUMBER(vword);\r
+ mcm->fMCM = MCM_MCM_NUMBER(vword);\r
+ mcm->fEvCounter = MCM_EVENT_COUNTER(vword);\r
+ mcm->fPos = (UInt_t*)word;\r
+}\r
+\r
+//--------------------------------------------------------\r
+UInt_t AliTRDrawStream::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r
+{\r
+ //\r
+ // get the adc mask\r
+ //\r
+ UInt_t vword = *word;\r
+\r
+ mcm->fADCmax = 0;\r
+ mcm->fADCMask = 0;\r
+ mcm->fADCcount = 0;\r
+ mcm->fADCMaskWord = vword;\r
+\r
+ if (vword == END_OF_TRACKLET_MARKERNEW) {\r
+ if (fWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));\r
+ mcm->fADCmaskCorrupted += 16;\r
+ fHC->fCorrupted += 16; //to finish data reading of this HC\r
+ }\r
+\r
+ if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {\r
+ mcm->fADCMask = MCM_ADCMASK_VAL(vword);\r
+ mcm->fADCcount = MCM_ADCMASK_NADC(~vword);\r
+ }\r
+ else {\r
+ mcm->fADCMask = 0xffffffff;\r
+ mcm->fADCmaskCorrupted = 1; // mcm adc mask error\r
+ if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));\r
+ }\r
+\r
+ return mcm->fADCMask;\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawStream::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r
+{\r
+ //\r
+ // decode the adc mask - adcs to be read out\r
+ //\r
+ mcm->fSingleADCwords = 0;\r
+ mcm->fADCmax = 0;\r
+ mcm->fADCMask = GetMCMadcMask(word, mcm);\r
+\r
+ if (mcm->fADCMask > 0) {\r
+ for (Int_t i = 0; i < TRDMAXADC; i++) {\r
+ mcm->fADCchannel[mcm->fADCmax] = 0;\r
+ if ( IS_BIT_SET(mcm->fADCMask,i) ) {\r
+ mcm->fADCchannel[mcm->fADCmax] = i;\r
+ mcm->fADCmax++;\r
+ }\r
+ }\r
+ }\r
+ if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility\r
+ mcm->fADCmaskCorrupted += 2; \r
+ if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", mcm->fADCcount, mcm->fADCmax, *fMCM->fPos));\r
+ }\r
+}\r
+\r
+//--------------------------------------------------------\r
+void AliTRDrawStream::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const\r
+{\r
+ //\r
+ // count the expected mcm words for a given tbins\r
+ //\r
+ mcm->fSingleADCwords = 0;\r
+ mcm->fSingleADCwords = (fTbins-1)/3+1;\r
+ if (fTbins > 32) mcm->fSingleADCwords = 10; // if the timebin is more than 30, then fix the number of adc words to 10\r
+}\r
+ \r
+//--------------------------------------------------------\r
+const char *AliTRDrawStream::DumpMCMinfo(const struct AliTRDrawMCM *mcm)\r
+{\r
+ //\r
+ // mcm info in a string\r
+ //\r
+ if (!mcm)\r
+ return Form("Unable to dump. Null received as parameter!?!");\r
+ else\r
+ return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);\r
+}\r
+ \r
+//--------------------------------------------------------\r
+const char *AliTRDrawStream::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)\r
+{\r
+ //\r
+ // mcm adc mask in a string\r
+ //\r
+ if (!mcm)\r
+ return Form("Unable to dump. Null received as parameter!?!");\r
+\r
+ TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);\r
+ for (Int_t i = 0; i < TRDMAXADC; i++) {\r
+ tsreturn += Form("%d ", mcm->fADCchannel[i]);\r
+ }\r
+ tsreturn += "";\r
+ return tsreturn.Data();\r
+}\r
+\r
\r
UInt_t fWordLength; // length of the buffer in 32bit words\r
\r
- Bool_t fIsGlobalDigitsParamSet; // set true if the global digit parameters are already set\r
-\r
Int_t fStackNumber; // current stack number\r
Int_t fStackLinkNumber; // current link in the stack\r
\r
, kWrongPadcolumn = 24 //\r
}; \r
\r
- ClassDef(AliTRDrawStream, 0)\r
+ ClassDef(AliTRDrawStream, 1)\r
}; //clas def end\r
\r
#endif\r