From 615f08263c67287c12bc076f8f228c90a05d908c Mon Sep 17 00:00:00 2001 From: cblume Date: Wed, 30 Sep 2009 15:16:47 +0000 Subject: [PATCH] - put baseline subtraction into the clusterizer and remove all other places (rawStreamers) where this could be done - use gain calibration outside of TailCancallaion - inline AliTRDarrayADC::SetData and GetData --- TRD/AliTRDReconstructor.cxx | 1 - TRD/AliTRDarrayADC.cxx | 34 - TRD/AliTRDarrayADC.h | 39 +- TRD/AliTRDclusterizer.cxx | 119 +- TRD/AliTRDclusterizer.h | 15 +- TRD/AliTRDrawFastStream.cxx | 3913 ++++++++++++++++---------------- TRD/AliTRDrawFastStream.h | 1233 +++++----- TRD/AliTRDrawStream.cxx | 4203 +++++++++++++++++------------------ TRD/AliTRDrawStream.h | 1403 ++++++------ TRD/AliTRDrawStreamBase.cxx | 307 ++- TRD/AliTRDrawStreamBase.h | 273 ++- 11 files changed, 5769 insertions(+), 5771 deletions(-) diff --git a/TRD/AliTRDReconstructor.cxx b/TRD/AliTRDReconstructor.cxx index 6b9e963547b..139b05b27ac 100644 --- a/TRD/AliTRDReconstructor.cxx +++ b/TRD/AliTRDReconstructor.cxx @@ -155,7 +155,6 @@ void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader rawReader->Select("TRD"); rawData.OpenOutput(); AliTRDrawStreamBase::SetRawStreamVersion(GetRecoParam()->GetRawStreamVersion()->Data()); - AliTRDrawStreamBase::SetSubtractBaseline(10); AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader); manager->MakeBranch(digitsTree); manager->WriteDigits(); diff --git a/TRD/AliTRDarrayADC.cxx b/TRD/AliTRDarrayADC.cxx index ee855799701..2fc826df672 100644 --- a/TRD/AliTRDarrayADC.cxx +++ b/TRD/AliTRDarrayADC.cxx @@ -41,7 +41,6 @@ AliTRDarrayADC::AliTRDarrayADC() ,fNumberOfChannels(0) ,fNtime(0) ,fNAdim(0) - ,fBaseline(0) ,fADC(0) { // @@ -61,7 +60,6 @@ AliTRDarrayADC::AliTRDarrayADC(Int_t nrow, Int_t ncol, Int_t ntime) ,fNumberOfChannels(0) ,fNtime(0) ,fNAdim(0) - ,fBaseline(0) ,fADC(0) { // @@ -82,7 +80,6 @@ AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b) ,fNumberOfChannels(b.fNumberOfChannels) ,fNtime(b.fNtime) ,fNAdim(b.fNAdim) - ,fBaseline(b.fBaseline) ,fADC(0) { // @@ -590,37 +587,6 @@ void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx) } } -} -//________________________________________________________________________________ -Short_t AliTRDarrayADC::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const -{ - // - // Get the data using the pad numbering. - // To access data using the mcm scheme use instead - // the method GetDataByAdcCol - // - - Int_t corrcolumn = fgLutPadNumbering[ncol]; - - return fADC[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime]; - -} -//________________________________________________________________________________ -void AliTRDarrayADC::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Short_t value) -{ - // - // Set the data using the pad numbering. - // To write data using the mcm scheme use instead - // the method SetDataByAdcCol - // - // This function also subtracts the ADC baseline and - // imposes a lower limit of zero to the ADC values! - // - - Int_t colnumb = fgLutPadNumbering[ncol]; - - fADC[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime] = TMath::Max(value-fBaseline,0); - } //________________________________________________________________________________ diff --git a/TRD/AliTRDarrayADC.h b/TRD/AliTRDarrayADC.h index 9e84c7fef73..1a291cf955a 100644 --- a/TRD/AliTRDarrayADC.h +++ b/TRD/AliTRDarrayADC.h @@ -28,7 +28,7 @@ class AliTRDarrayADC: public TObject void SetNdet(Int_t ndet) {fNdet=ndet;}; Int_t GetNdet() const {return fNdet;}; void SetDataByAdcCol(Int_t nrow, Int_t ncol, Int_t ntime, Short_t value) - {fADC[(nrow*fNumberOfChannels+ncol)*fNtime+ntime]=value-fBaseline;}; + {fADC[(nrow*fNumberOfChannels+ncol)*fNtime+ntime]=value;} Bool_t HasData() const {return fNtime ? 1 : 0;}; Short_t GetDataByAdcCol(Int_t nrow, Int_t ncol, Int_t ntime) const {return fADC[(nrow*fNumberOfChannels+ncol)*fNtime+ntime];}; @@ -46,10 +46,9 @@ class AliTRDarrayADC: public TObject void DeleteNegatives(); void Reset(); void ConditionalReset(AliTRDSignalIndex* idx); - Short_t GetData(Int_t nrow, Int_t ncol, Int_t ntime) const; - void SetData(Int_t nrow, Int_t ncol, Int_t ntime, Short_t value); + inline Short_t GetData(Int_t nrow, Int_t ncol, Int_t ntime) const; + inline void SetData(Int_t nrow, Int_t ncol, Int_t ntime, Short_t value); static void CreateLut(); - void SetBaseline(Short_t baseline) {fBaseline=baseline;} protected: @@ -59,7 +58,6 @@ class AliTRDarrayADC: public TObject Int_t fNumberOfChannels; // Number of MCM channels per row Int_t fNtime; //Number of time bins Int_t fNAdim; //Dimension of the ADC array - Short_t fBaseline; Short_t* fADC; //[fNAdim] //Pointer to adc values static Short_t *fgLutPadNumbering; // [fNcol] Look Up Table @@ -67,7 +65,36 @@ class AliTRDarrayADC: public TObject }; -inline void AliTRDarrayADC::GetData(Int_t r, Int_t c, Int_t t, Int_t n, Short_t *vals) const +//________________________________________________________________________________ +Short_t AliTRDarrayADC::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const +{ + // + // Get the data using the pad numbering. + // To access data using the mcm scheme use instead + // the method GetDataByAdcCol + // + + Int_t corrcolumn = fgLutPadNumbering[ncol]; + + return fADC[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime]; + +} +//________________________________________________________________________________ +void AliTRDarrayADC::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Short_t value) +{ + // + // Set the data using the pad numbering. + // To write data using the mcm scheme use instead + // the method SetDataByAdcCol + // + + Int_t colnumb = fgLutPadNumbering[ncol]; + + fADC[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime] = value; + +} + +void AliTRDarrayADC::GetData(Int_t r, Int_t c, Int_t t, Int_t n, Short_t *vals) const { Int_t colNum = fgLutPadNumbering[c]; for(Int_t ic=n, idx = (r*fNumberOfChannels+colNum)*fNtime+t; ic--; idx+=fNtime) vals[ic] = fADC[idx]; diff --git a/TRD/AliTRDclusterizer.cxx b/TRD/AliTRDclusterizer.cxx index f5f2cc07691..380596e4837 100644 --- a/TRD/AliTRDclusterizer.cxx +++ b/TRD/AliTRDclusterizer.cxx @@ -84,6 +84,7 @@ AliTRDclusterizer::AliTRDclusterizer(const AliTRDReconstructor *const rec) ,fClusterROC(0) ,firstClusterROC(0) ,fNoOfClusters(0) + ,fBaseline(0) { // // AliTRDclusterizer default constructor @@ -142,6 +143,7 @@ AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title, co ,fClusterROC(0) ,firstClusterROC(0) ,fNoOfClusters(0) + ,fBaseline(0) { // // AliTRDclusterizer constructor @@ -195,6 +197,7 @@ AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c) ,fClusterROC(0) ,firstClusterROC(0) ,fNoOfClusters(0) + ,fBaseline(0) { // // AliTRDclusterizer copy constructor @@ -292,6 +295,8 @@ void AliTRDclusterizer::Copy(TObject &c) const ((AliTRDclusterizer &) c).fClusterROC = 0; ((AliTRDclusterizer &) c).firstClusterROC= 0; ((AliTRDclusterizer &) c).fNoOfClusters = 0; + ((AliTRDclusterizer &) c).fBaseline = 0; + } //_____________________________________________________________________________ @@ -736,7 +741,8 @@ Bool_t AliTRDclusterizer::MakeClusters(Int_t det) // // Get the digits - fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod + fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod + fBaseline = fDigitsManager->GetDigitsParam()->GetADCbaseline(); // This is to take care of switched off super modules if (!fDigits->HasData()) return kFALSE; @@ -821,21 +827,18 @@ Bool_t AliTRDclusterizer::MakeClusters(Int_t det) // Here the clusterfining is happening - for(curr.Time = 0; curr.Time < fTimeTotal; curr.Time++){ - while(fIndexes->NextRCIndex(curr.Row, curr.Col)){ - //printf("\nCHECK r[%2d] c[%3d] t[%d]\n", curr.Row, curr.Col, curr.Time); - if(IsMaximum(curr, curr.padStatus, &curr.Signals[0])){ - //printf("\tMAX s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]); - if(last.Row>-1){ - if(curr.Time==last.Time && curr.Row==last.Row && curr.Col==last.Col+2) FivePadCluster(last, curr); + for(curr.time = 0; curr.time < fTimeTotal; curr.time++){ + while(fIndexes->NextRCIndex(curr.row, curr.col)){ + if(IsMaximum(curr, curr.padStatus, &curr.signals[0])){ + if(last.row>-1){ + if(curr.time==last.time && curr.row==last.row && curr.col==last.col+2) FivePadCluster(last, curr); CreateCluster(last); } - last=curr; curr.FivePad=kFALSE; + last=curr; curr.fivePad=kFALSE; } - //printf("\t--- s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]); } } - if(last.Row>-1) CreateCluster(last); + if(last.row>-1) CreateCluster(last); if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){ TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer); @@ -860,29 +863,32 @@ Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Sh // Gives back the padStatus and the signals of the center pad and the two neighbouring pads. // - Signals[1] = fDigits->GetData(Max.Row, Max.Col, Max.Time); + Float_t gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col,Max.row); + Signals[1] = (Short_t)((fDigits->GetData(Max.row, Max.col, Max.time) - fBaseline) / gain + 0.5f); if(Signals[1] < fMaxThresh) return kFALSE; - Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.Col, Max.Row); + Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.col, Max.row); if (Signals[1] < noiseMiddleThresh) return kFALSE; - if (Max.Col + 1 >= fColMax || Max.Col < 1) return kFALSE; + if (Max.col + 1 >= fColMax || Max.col < 1) return kFALSE; UChar_t status[3]={ - fCalPadStatusROC->GetStatus(Max.Col-1, Max.Row) - ,fCalPadStatusROC->GetStatus(Max.Col, Max.Row) - ,fCalPadStatusROC->GetStatus(Max.Col+1, Max.Row) + fCalPadStatusROC->GetStatus(Max.col-1, Max.row) + ,fCalPadStatusROC->GetStatus(Max.col, Max.row) + ,fCalPadStatusROC->GetStatus(Max.col+1, Max.row) }; - Signals[0] = fDigits->GetData(Max.Row, Max.Col-1, Max.Time); - Signals[2] = fDigits->GetData(Max.Row, Max.Col+1, Max.Time); +gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-1,Max.row); + Signals[0] = (Short_t)((fDigits->GetData(Max.row, Max.col-1, Max.time) - fBaseline) / gain + 0.5f); + gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-1,Max.row); + Signals[2] = (Short_t)((fDigits->GetData(Max.row, Max.col+1, Max.time) - fBaseline) / gain + 0.5f); if(!(status[0] | status[1] | status[2])) {//all pads are good if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) { if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) { Float_t noiseSumThresh = fMinLeftRightCutSigma * fCalNoiseDetValue - * fCalNoiseROC->GetValue(Max.Col, Max.Row); + * fCalNoiseROC->GetValue(Max.col, Max.row); if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE; padStatus = 0; return kTRUE; @@ -900,7 +906,7 @@ Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Sh return kTRUE; } else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) { - Signals[1]=TMath::Nint(fMaxThresh); + Signals[1] = (Short_t)(fMaxThresh + 0.5f); SetPadStatus(status[1], padStatus); return kTRUE; } @@ -915,27 +921,31 @@ Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &Neighbou // Look for 5 pad cluster with minimum in the middle // Gives back the ratio // - if (ThisMax.Col >= fColMax - 3) return kFALSE; - if (ThisMax.Col < fColMax - 5){ - if (fDigits->GetData(ThisMax.Row, ThisMax.Col+4, ThisMax.Time) >= fSigThresh) + + if (ThisMax.col >= fColMax - 3) return kFALSE; + Float_t gain; + if (ThisMax.col < fColMax - 5){ + gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col+4,ThisMax.row); + if (fDigits->GetData(ThisMax.row, ThisMax.col+4, ThisMax.time) - fBaseline >= fSigThresh * gain) return kFALSE; } - if (ThisMax.Col > 1) { - if (fDigits->GetData(ThisMax.Row, ThisMax.Col-2, ThisMax.Time) >= fSigThresh) + if (ThisMax.col > 1) { + gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col-2,ThisMax.row); + if (fDigits->GetData(ThisMax.row, ThisMax.col-2, ThisMax.time) - fBaseline >= fSigThresh * gain) return kFALSE; } const Float_t kEpsilon = 0.01; - Double_t padSignal[5] = {ThisMax.Signals[0], ThisMax.Signals[1], ThisMax.Signals[2], - NeighbourMax.Signals[1], NeighbourMax.Signals[2]}; + Double_t padSignal[5] = {ThisMax.signals[0], ThisMax.signals[1], ThisMax.signals[2], + NeighbourMax.signals[1], NeighbourMax.signals[2]}; // Unfold the two maxima and set the signal on // the overlapping pad to the ratio Float_t ratio = Unfold(kEpsilon,fLayer,padSignal); - ThisMax.Signals[2] = TMath::Nint(ThisMax.Signals[2]*ratio); - NeighbourMax.Signals[0] = TMath::Nint(NeighbourMax.Signals[0]*(1-ratio)); - ThisMax.FivePad=kTRUE; - NeighbourMax.FivePad=kTRUE; + ThisMax.signals[2] = (Short_t)(ThisMax.signals[2]*ratio + 0.5f); + NeighbourMax.signals[0] = (Short_t)(NeighbourMax.signals[0]*(1-ratio) + 0.5f); + ThisMax.fivePad=kTRUE; + NeighbourMax.fivePad=kTRUE; return kTRUE; } @@ -948,16 +958,16 @@ void AliTRDclusterizer::CreateCluster(const MaxStruct &Max) // Int_t nPadCount = 1; - Short_t signals[7] = { 0, 0, Max.Signals[0], Max.Signals[1], Max.Signals[2], 0, 0 }; + Short_t signals[7] = { 0, 0, Max.signals[0], Max.signals[1], Max.signals[2], 0, 0 }; if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount); - AliTRDcluster cluster(fDet, ((UChar_t) Max.Col), ((UChar_t) Max.Row), ((UChar_t) Max.Time), signals, fVolid); + AliTRDcluster cluster(fDet, ((UChar_t) Max.col), ((UChar_t) Max.row), ((UChar_t) Max.time), signals, fVolid); cluster.SetNPads(nPadCount); if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT); else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS); else cluster.SetRPhiMethod(AliTRDcluster::kCOG); - cluster.SetFivePad(Max.FivePad); + cluster.SetFivePad(Max.fivePad); // set pads status for the cluster UChar_t maskPosition = GetCorruption(Max.padStatus); if (maskPosition) { @@ -971,9 +981,9 @@ void AliTRDclusterizer::CreateCluster(const MaxStruct &Max) if(!fTransform->Transform(&cluster)) return; // Temporarily store the Max.Row, column and time bin of the center pad // Used to later on assign the track indices - cluster.SetLabel(Max.Row, 0); - cluster.SetLabel(Max.Col, 1); - cluster.SetLabel(Max.Time,2); + cluster.SetLabel(Max.row, 0); + cluster.SetLabel(Max.col, 1); + cluster.SetLabel(Max.time,2); //needed for HLT reconstruction AddClusterToArray(&cluster); @@ -990,30 +1000,35 @@ void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const { // Look to the right Int_t ii = 1; - while (fDigits->GetData(Max.Row, Max.Col-ii, Max.Time) >= fSigThresh) { + while (fDigits->GetData(Max.row, Max.col-ii, Max.time) >= fSigThresh) { nPadCount++; ii++; - if (Max.Col < ii) break; + if (Max.col < ii) break; } // Look to the left ii = 1; - while (fDigits->GetData(Max.Row, Max.Col+ii, Max.Time) >= fSigThresh) { + while (fDigits->GetData(Max.row, Max.col+ii, Max.time) >= fSigThresh) { nPadCount++; ii++; - if (Max.Col+ii >= fColMax) break; + if (Max.col+ii >= fColMax) break; } // Store the amplitudes of the pads in the cluster for later analysis // and check whether one of these pads is masked in the database - signals[2]=Max.Signals[0]; - signals[3]=Max.Signals[1]; - signals[4]=Max.Signals[2]; + signals[2]=Max.signals[0]; + signals[3]=Max.signals[1]; + signals[4]=Max.signals[2]; + Float_t gain; for(Int_t i = 0; i<2; i++) { - if(Max.Col+i >= 3) - signals[i] = fDigits->GetData(Max.Row, Max.Col-3+i, Max.Time); - if(Max.Col+3-i < fColMax) - signals[6-i] = fDigits->GetData(Max.Row, Max.Col+3-i, Max.Time); + if(Max.col+i >= 3){ + gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-3+i,Max.row); + signals[i] = (Short_t)((fDigits->GetData(Max.row, Max.col-3+i, Max.time) - fBaseline) / gain + 0.5f); + } + if(Max.col+3-i < fColMax){ + gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col+3-i,Max.row); + signals[6-i] = (Short_t)((fDigits->GetData(Max.row, Max.col+3-i, Max.time) - fBaseline) / gain + 0.5f); + } } /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) { if ((jPad >= 0) && (jPad < fColMax)) @@ -1199,17 +1214,12 @@ void AliTRDclusterizer::TailCancelation() TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer); while(fIndexes->NextRCIndex(iRow, iCol)) { - Float_t fCalGainFactorROCValue = fCalGainFactorROC->GetValue(iCol,iRow); - Double_t gain = fCalGainFactorDetValue - * fCalGainFactorROCValue; - Bool_t corrupted = kFALSE; for (iTime = 0; iTime < fTimeTotal; iTime++) { // Apply gain gain factor inADC[iTime] = fDigits->GetData(iRow,iCol,iTime); if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE; - inADC[iTime] /= gain; outADC[iTime] = inADC[iTime]; if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming()){ (*fDebugStream) << "TailCancellation" @@ -1217,7 +1227,6 @@ void AliTRDclusterizer::TailCancelation() << "row=" << iRow << "time=" << iTime << "inADC=" << inADC[iTime] - << "gain=" << gain << "outADC=" << outADC[iTime] << "corrupted=" << corrupted << "\n"; diff --git a/TRD/AliTRDclusterizer.h b/TRD/AliTRDclusterizer.h index ef16b65f27f..3de5448cede 100644 --- a/TRD/AliTRDclusterizer.h +++ b/TRD/AliTRDclusterizer.h @@ -50,14 +50,14 @@ class AliTRDclusterizer : public TNamed struct MaxStruct { - Int_t Row; - Int_t Col; - Int_t Time; - Short_t Signals[3]; + Int_t row; + Int_t col; + Int_t time; + Short_t signals[3]; UChar_t padStatus; - Bool_t FivePad; - MaxStruct():Row(-1),Col(0),Time(0),padStatus(0),FivePad(kFALSE) - {memset(Signals, 0, 3*sizeof(Short_t));} + Bool_t fivePad; + MaxStruct():row(-1),col(0),time(0),padStatus(0),fivePad(kFALSE) + {memset(signals, 0, 3*sizeof(Short_t));} MaxStruct &operator=(const MaxStruct &a) {memcpy(this, &a, sizeof(MaxStruct)); return *this;} }; @@ -157,6 +157,7 @@ protected: Int_t fClusterROC; // The index to the first cluster of a given ROC Int_t firstClusterROC; // The number of cluster in a given ROC Int_t fNoOfClusters; // Number of Clusters already processed and still owned by the clusterizer + Int_t fBaseline; // Baseline of the ADC values ClassDef(AliTRDclusterizer,6) // TRD clusterfinder diff --git a/TRD/AliTRDrawFastStream.cxx b/TRD/AliTRDrawFastStream.cxx index c6da32320bb..2b6093ac435 100644 --- a/TRD/AliTRDrawFastStream.cxx +++ b/TRD/AliTRDrawFastStream.cxx @@ -1,1955 +1,1958 @@ -/************************************************************************** -* 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 "TString.h" -#include "TFile.h" -#include "TTreeStream.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 "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) & (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::fgWarnError = kTRUE; -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 - }; -Bool_t AliTRDrawFastStream::fDumpingEnable = kFALSE; -Int_t AliTRDrawFastStream::fDumpingSM = -1; -Int_t AliTRDrawFastStream::fDumpingStack = -1; -Int_t AliTRDrawFastStream::fDumpingLayer = -1; -Int_t AliTRDrawFastStream::fDumpingROB = -1; -Int_t AliTRDrawFastStream::fDumpingMCM = -1; - -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) - , fBufferRead(0) - , fGeometry(0) - , fRawReader(0) - , fTRDfeeParam(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) - , fBufferRead(0) - , fGeometry(0) - , fRawReader(rawReader) - , fTRDfeeParam(0) -{ - // - // default constructor - // - if (fRawReader) { - if (Init() == kFALSE) { - AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )"); - } - } - else { - AliWarning("Unable to setup reader. Use SetReader(AliRawReader*)."); - } -} - -//------------------------------------------------------------ -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) - , fBufferRead(0) - , fGeometry(0) - , fRawReader(0) - , fTRDfeeParam(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 (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1)); - return kFALSE; - } - - return kTRUE; -} - -//------------------------------------------------------------ -Bool_t AliTRDrawFastStream::SetReader(AliRawReader *reader) -{ - - 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.fMCMADCWords = 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->SetCheckOCDB(kFALSE); - digitsparam->SetNTimeBins(ntbins); - digitsparam->SetADCbaseline(10); - fIsGlobalDigitsParamSet = kTRUE; - } - - // Allocate memory space for the digits buffer - if (digits->GetNtime() == 0) { - digits->Allocate(rowMax, colMax, ntbins); - digits->SetBaseline(digitsparam->GetADCbaseline()); - if (digitsManager->UsesDictionaries()) { - track0->Allocate(rowMax, colMax, ntbins); - track1->Allocate(rowMax, colMax, ntbins); - track2->Allocate(rowMax, colMax, ntbins); - } - } - - 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 (fgWarnError) 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 (fgWarnError) { - 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->SetPretiggerPhase(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 (fgWarnError) AliError("InitBuffer failed."); - 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; - 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 (fgWarnError) AliError("Link data missing."); - break; - } - - // HLT streamer 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 (!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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) AliError("No data(including HC header) in the buffer"); - return kFALSE;; - } - - if (DecodeHCheader() == kFALSE) { - if (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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->fMCMADCWords = 0; - mcm->fSingleADCwords = 0; - mcm->fADCmax = 0; - mcm->fADCMask = GetMCMadcMask(word, mcm); - - if (mcm->fADCMask > 0) { - for (Int_t i = 0; i < TRDMAXADC; i++) { - mcm->fADCchannel[mcm->fADCmax] = 0; - if ( IS_BIT_SET(mcm->fADCMask,i) ) { - mcm->fADCchannel[mcm->fADCmax] = i; - mcm->fADCmax++; - } - } - } - 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->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 ); - mcm->fSingleADCwords = 0; - if (mcm->fADCmax > 0) { - mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax; - } - 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 (fgWarnError) 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) - fgCommonAdditive; - adcSignals[1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive; - adcSignals[2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive; - - if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;}; - for (Int_t i = 0; i < 3; i++) { - if (adcSignals[i] > 0) { - if (fSharedPadsOn) - digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcSignals[i]); - else - digits->SetData(GetRow(), GetCol(), 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) - fgCommonAdditive; - adcFirst2Signals[1] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive; - - for (Int_t i = 0; i < 2; i++) { - if (adcFirst2Signals[i] > 0) { - if (fSharedPadsOn) - digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcFirst2Signals[i]); - else - digits->SetData(GetRow(), GetCol(), 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 (fgWarnError) 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) - fgCommonAdditive; - adcSignals[1] = ((*fpPos & 0x003ff000) >> 12) - fgCommonAdditive; - adcSignals[2] = ((*fpPos & 0xffc00000) >> 22) - fgCommonAdditive; - - if(GetCol() < 0 || (!fSharedPadsOn & fIsShared)) {fpPos++; continue;}; - for (Int_t i = 0; i < 3; i++) { - if (adcSignals[i] > 0) { - if (fSharedPadsOn) - digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + 2 + i, adcSignals[i]); - else - digits->SetData(GetRow(), GetCol(), 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() -{ - 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 = *fpPosTemp; - - // 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, hc->fSM, 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(); -} - - +/************************************************************************** +* 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 "TString.h" +#include "TFile.h" +#include "TTreeStream.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 "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) & (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::fgWarnError = kTRUE; +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 + }; +Bool_t AliTRDrawFastStream::fDumpingEnable = kFALSE; +Int_t AliTRDrawFastStream::fDumpingSM = -1; +Int_t AliTRDrawFastStream::fDumpingStack = -1; +Int_t AliTRDrawFastStream::fDumpingLayer = -1; +Int_t AliTRDrawFastStream::fDumpingROB = -1; +Int_t AliTRDrawFastStream::fDumpingMCM = -1; + +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) + , 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) + , 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) + , 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 (fgWarnError) AliWarning(Form("Skip %d words failed. %d available", iw, fpEnd - fpPos - 1)); + return kFALSE; + } + + return kTRUE; +} + +//------------------------------------------------------------ +Bool_t AliTRDrawFastStream::SetReader(AliRawReader *reader) +{ + + 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.fMCMADCWords = 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->SetCheckOCDB(kFALSE); + 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 (fgWarnError) 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 (fgWarnError) { + 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->SetPretiggerPhase(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 (fgWarnError) AliError("InitBuffer failed."); + 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; + 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 (fgWarnError) AliError("Link data missing."); + break; + } + + // HLT streamer 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 (!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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) AliError("No data(including HC header) in the buffer"); + return kFALSE;; + } + + if (DecodeHCheader() == kFALSE) { + if (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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->fMCMADCWords = 0; + mcm->fSingleADCwords = 0; + mcm->fADCmax = 0; + mcm->fADCMask = GetMCMadcMask(word, mcm); + + if (mcm->fADCMask > 0) { + for (Int_t i = 0; i < TRDMAXADC; i++) { + mcm->fADCchannel[mcm->fADCmax] = 0; + if ( IS_BIT_SET(mcm->fADCMask,i) ) { + mcm->fADCchannel[mcm->fADCmax] = i; + mcm->fADCmax++; + } + } + } + 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->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 ); + mcm->fSingleADCwords = 0; + if (mcm->fADCmax > 0) { + mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax; + } + 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 (fgWarnError) 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++) { + if (adcSignals[i] > fCommonAdditive) { + if (fSharedPadsOn) + digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcSignals[i]); + else + digits->SetData(GetRow(), GetCol(), 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++) { + if (adcFirst2Signals[i] > fCommonAdditive) { + if (fSharedPadsOn) + digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + i, adcFirst2Signals[i]); + else + digits->SetData(GetRow(), GetCol(), 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 (fgWarnError) 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++) { + if (adcSignals[i] > fCommonAdditive) { + if (fSharedPadsOn) + digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), fTbinADC + 2 + i, adcSignals[i]); + else + digits->SetData(GetRow(), GetCol(), 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() +{ + 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 = *fpPosTemp; + + // 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, hc->fSM, 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(); +} + + diff --git a/TRD/AliTRDrawFastStream.h b/TRD/AliTRDrawFastStream.h index 2d31cad4a92..a890af6d0a0 100644 --- a/TRD/AliTRDrawFastStream.h +++ b/TRD/AliTRDrawFastStream.h @@ -1,616 +1,617 @@ -#ifndef ALITRDRAWHLTSTREAM_H -#define ALITRDRAWHLTSTREAM_H - -/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * - * See cxx source for full Copyright notice */ - -/* $Id: AliTRDrawFastStream.h 27696 2008-07-31 09:18:53Z cblume $ */ - -///////////////////////////////////////////////////////////////////////////////// -// // -// This class provides access to TRD digits in raw data in a way of streaming. // -// // -///////////////////////////////////////////////////////////////////////////////// - -#include "TObject.h" -#include "TString.h" -#include "AliTRDrawStreamBase.h" -#include "AliTRDarrayADC.h" -#include "AliTRDarrayDictionary.h" -#include "AliTRDSignalIndex.h" - -class AliTRDgeometry; -class AliRawReader; -class AliTRDdigitsManager; -class TTreeSRedirector; -class AliTRDfeeParam; - - -class AliTRDrawFastStream : public AliTRDrawStreamBase -{ // class def begin - - public: - - //-------------------------------------------------------- - // THE STRUCTURES - //-------------------------------------------------------- - - struct AliTRDrawMCM - { // mcm struct - Int_t fROB; // ROB number - Int_t fMCM; // MCM number - Int_t fROW; // row number filed during decoding - - UInt_t fEvCounter; // MCM event counter - UInt_t fADCMask; // ADC mask - UInt_t fADCMaskWord; // word with ADC mask in - UInt_t fADCchannel[TRDMAXADC]; // channels to be decoded accrording to ADC mask - - Int_t fADCmax; // number of ADCs fired - Int_t fADCcount; // number of ADCs fired from double checking bit - Int_t fMCMADCWords; // mcm words to expect - Int_t fSingleADCwords; // n of words per ADC - - Int_t fMCMhdCorrupted; // is mcm header corrupted - Int_t fADCmaskCorrupted; // is mcm adc mask corrupted - Bool_t fDataCorrupted; // true if the corruption is in ADC data level - - UInt_t *fPos; //! position of mcm header in the buffer - UInt_t *fAdcDataPos; //! start of ADC data for this mcm - - Int_t fADCcounter; // count the adcs decoded - - - AliTRDrawMCM() - : fROB(-1) - , fMCM(-1) - , fROW(-1) - , fEvCounter(0) - , fADCMask(0) - , fADCMaskWord(0) - , fADCchannel() - , fADCmax(0) - , fADCcount(0) - , fMCMADCWords(0) - , fSingleADCwords(0) - , fMCMhdCorrupted(0) - , fADCmaskCorrupted(0) - , fDataCorrupted(0) - , fPos(0) - , fAdcDataPos(0) - , fADCcounter(0) - { - // default constructor - }; - - AliTRDrawMCM(const AliTRDrawMCM & p): - fROB(p.fROB) - , fMCM(p.fMCM) - , fROW(p.fROW) - , fEvCounter(p.fEvCounter) - , fADCMask(p.fADCMask) - , fADCMaskWord(p.fADCMaskWord) - , fADCchannel() - , fADCmax(p.fADCmax) - , fADCcount(p.fADCcount) - , fMCMADCWords(p.fMCMADCWords) - , fSingleADCwords(p.fSingleADCwords) - , fMCMhdCorrupted(p.fMCMhdCorrupted) - , fADCmaskCorrupted(p.fADCmaskCorrupted) - , fDataCorrupted(p.fDataCorrupted) - , fPos(p.fPos) - , fAdcDataPos(p.fAdcDataPos) - , fADCcounter(p.fADCcounter) - { - // copy constructor - }; - - AliTRDrawMCM &operator=(const AliTRDrawMCM &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - struct AliTRDrawHC - { // hc struct - - //tacklet words of given HC - UInt_t fTrackletWords[MAXTRACKLETSPERHC]; // array to keep tracklet words - Short_t fNTracklets; // number of tracklet - - // header word 0 - Int_t fSpecialRawV; // Raw data version - Int_t fRawVMajor; // Raw data version - Int_t fRawVMajorOpt; // Raw data version - Int_t fRawVMinor; // Raw data version - Int_t fNExtraWords; // N extra HC header words - Int_t fDCSboard; // DCS board number - Int_t fSM; // Super Module number - Int_t fSMHCheader; // Super Module number from HC header - Int_t fStack; // Stack number (some people might call it a chamber) - Int_t fStackHCheader; // Stack number from HC header(some people might call it a chamber) - Int_t fLayer; // Layer number (some people might call it a plane) - Int_t fLayerHCheader; // Layer number from HC header(some people might call it a plane) - Int_t fSide; // Side of HC - Int_t fSideHCheader; // Side of HC from HC header - - // header word 1 - Int_t fTimeBins; // N of t bins - UInt_t fBunchCrossCounter; // Bunch crossing counter - UInt_t fPreTriggerCounter; // Pre Trigger counter - UInt_t fPreTriggerPhase; // Pre Trigger phase - - // error - UShort_t fErrorCodes[1411]; // array to keep encoded errors - UInt_t fNErrors; // number of total errors of given hc - - Short_t fH0Corrupted; // is hc header 0 corrupted - Short_t fH1Corrupted; // is hc header 1 corrupted - Short_t fCorrupted; // is hc data corrupted - Bool_t fEOTECorrupted; // if the corruption is due to meet END_OF_TRACKLET_MARKERNEW - Bool_t fBufferCorrupted; // if the corruption is due to buffer end - Bool_t fDataCorrupted; // if the corruption is on the MCM data - - Short_t fMCMCorrupted[TRDMAXMCM]; // is hc data corrupted - - UInt_t *fPos[2]; //! position of the header words in buffer - - Int_t fDET; // filled while decoding - Int_t fROC; // filled while decoding - Int_t fRowMax; // filled while decoding - Int_t fColMax; // filled while decoding - - // hc data - Int_t fMCMmax; // number of mcm found - - AliTRDrawHC() - : fTrackletWords() - , fNTracklets(0) - , fSpecialRawV(0) - , fRawVMajor(0) - , fRawVMajorOpt(0) - , fRawVMinor(0) - , fNExtraWords(0) - , fDCSboard(-1) - , fSM(-1) - , fSMHCheader(-1) - , fStack(-1) - , fStackHCheader(-1) - , fLayer(-1) - , fLayerHCheader(-1) - , fSide(-1) - , fSideHCheader(-1) - , fTimeBins(0) - , fBunchCrossCounter(0) - , fPreTriggerCounter(0) - , fPreTriggerPhase(0) - , fNErrors(0) - , fH0Corrupted(0) - , fH1Corrupted(0) - , fCorrupted(0) - , fEOTECorrupted(0) - , fBufferCorrupted(0) - , fDataCorrupted(0) - , fPos() - , fDET(-1) - , fROC(-1) - , fRowMax(-1) - , fColMax(-1) - , fMCMmax(0) - { - // default constructor hc info - }; - - AliTRDrawHC(const AliTRDrawHC & p): - fTrackletWords() - , fNTracklets(p.fNTracklets) - , fSpecialRawV(p.fSpecialRawV) - , fRawVMajor(p.fRawVMajor) - , fRawVMajorOpt(p.fRawVMajorOpt) - , fRawVMinor(p.fRawVMinor) - , fNExtraWords(p.fNExtraWords) - , fDCSboard(p.fDCSboard) - , fSM(p.fSM) - , fSMHCheader(p.fSMHCheader) - , fStack(p.fStack) - , fStackHCheader(p.fStackHCheader) - , fLayer(p.fLayer) - , fLayerHCheader(p.fLayerHCheader) - , fSide(p.fSide) - , fSideHCheader(p.fSideHCheader) - , fTimeBins(p.fTimeBins) - , fBunchCrossCounter(p.fBunchCrossCounter) - , fPreTriggerCounter(p.fPreTriggerCounter) - , fPreTriggerPhase(p.fPreTriggerPhase) - , fNErrors(p.fNErrors) - , fH0Corrupted(p.fH0Corrupted) - , fH1Corrupted(p.fH1Corrupted) - , fCorrupted(p.fCorrupted) - , fEOTECorrupted(p.fEOTECorrupted) - , fBufferCorrupted(p.fBufferCorrupted) - , fDataCorrupted(p.fDataCorrupted) - , fPos() - , fDET(p.fDET) - , fROC(p.fROC) - , fRowMax(p.fRowMax) - , fColMax(p.fColMax) - , fMCMmax(p.fMCMmax) - { - // copy constructor - }; - - AliTRDrawHC &operator=(const AliTRDrawHC &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - struct AliTRDrawStack - { - UInt_t fHeaderSize; // header size of the stack info - Bool_t fLinksActive[12]; // data links active - 1 per half chamber - Short_t fLinksDataType[12]; // 0 indicating real data for the front-end electronics - Short_t fLinksMonitor[12]; // 0 indicating properly operating link - Short_t fLinkMonitorError[12]; // record link monitor error - Int_t fActiveLinks; // number of active links - UInt_t *fPos; //! position in the buffer - - AliTRDrawHC fHalfChambers[12]; // 12 half chambers in a stack - - AliTRDrawStack() - : fHeaderSize(0) - , fLinksActive() - , fLinksDataType() - , fLinksMonitor() - , fLinkMonitorError() - , fActiveLinks(0) - , fPos(0) - , fHalfChambers() - { - // default constructor - }; - - AliTRDrawStack(const AliTRDrawStack & p): - fHeaderSize(p.fHeaderSize) - , fLinksActive() - , fLinksDataType() - , fLinksMonitor() - , fLinkMonitorError() - , fActiveLinks(p.fActiveLinks) - , fPos(p.fPos) - , fHalfChambers() - { - // copy constructor - }; - - AliTRDrawStack &operator=(const AliTRDrawStack &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - struct AliTRDrawSM - { - UInt_t fHeaderSize; // size of the header in words - Bool_t fTrackletEnable; // tracklet enable bit - Bool_t fStackActive[5]; // map of active/expected stacks - Int_t fActiveStacks; // number of active stacks - Int_t fCorrupted; // is sm info corrupted - Int_t fNexpectedHalfChambers; // number of half chambers to be read out in this sm - UInt_t *fPos; // location of the sm info - should be the first word (after CDH if not DDL buffer) - - AliTRDrawStack fStacks[5]; - - AliTRDrawSM() - : fHeaderSize(0) - , fTrackletEnable(0) - , fStackActive() - , fActiveStacks(0) - , fCorrupted(0) - , fNexpectedHalfChambers(0) - , fPos(0) - , fStacks() - { - // Default constructor - }; - - AliTRDrawSM(const AliTRDrawSM & p): - fHeaderSize(p.fHeaderSize) - , fTrackletEnable(p.fTrackletEnable) - , fStackActive() - , fActiveStacks(p.fActiveStacks) - , fCorrupted(p.fCorrupted) - , fNexpectedHalfChambers(p.fNexpectedHalfChambers) - , fPos(p.fPos) - , fStacks() - { - // copy constructor - }; - - AliTRDrawSM &operator=(const AliTRDrawSM &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - AliTRDrawFastStream(); - AliTRDrawFastStream(AliRawReader *rawReader); - virtual ~AliTRDrawFastStream(); - - //-------------------------------------------------------- - - virtual Bool_t Next(); // read the next data in the memory - virtual Int_t NextChamber(AliTRDdigitsManager *man, UInt_t **trackletContainer, UShort_t **errorCodeContainer); // read next chamber data in the memory - virtual Bool_t Init(); // initialize some internal variables - - Int_t NextBuffer(); // go and init next buffer if available - check the implementation file for return values - - Bool_t SetRawVersion(Int_t fraw); // set the raw version - used for backward compat. - - void SetSharedPadReadout(Bool_t fv) {fSharedPadsOn = fv;} // set the flag on if the reader should return the shared pads - - Bool_t DecodeSMHeader(void *buffer, UInt_t length); // decode a buffer - Bool_t SetReader(AliRawReader *reader); // set the raw reader to use - - // from MCM Header Word - // rob and mcm ordering - // side 0(even link) - ROB: 0 2 4 6 MCM: 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3 - // side 1( odd link) - ROB: 1 3 5 7 MCM: 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3 - - - UShort_t *GetErrorCodes() const { return fHC->fErrorCodes;} // return error codes pointer per hc - UInt_t GetNErrors() const {return fHC ? fHC->fNErrors: 0;} // [mj temp] - - // info from ADC data words - // from here, only works with returning ADC channel pointer using Next() - - UInt_t *GetTrackletWords() const { return fHC->fTrackletWords;} // return tracklet words pointer per hc - Int_t GetNTracklets() const {return fHC ? fHC->fNTracklets : -1;} // get number of tracklets - - Int_t GetSpecialRawVersion() const {return fHC ? fHC->fSpecialRawV : -1;} // return special raw version - Int_t GetMajorRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // major raw version getter - Int_t GetRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // compatibility see funtion above - Int_t GetMinorRawVersion() const {return fHC ? fHC->fRawVMinor : -1;} // minor raw version - - Int_t GetSM() const {return fHC ? fHC->fSM : -1;} // SM Position of CURRENT half chamber in full TRD - Int_t GetLayer() const {return fHC ? fHC->fLayer : -1;} // Layer Position of CURRENT half chamber in full TRD - Int_t GetStack() const {return fHC ? fHC->fStack : -1;} // Stack Position of CURRENT half chamber in full TRD - Int_t GetSide() const {return fHC ? fHC->fSide : -1;} // get side - Int_t GetDCS() const { return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header) - Int_t GetROC() const { return fHC ? fHC->fROC : -1;} // ROB Position of CURRENT half chamber in full TRD - Int_t GetNumberOfTimeBins() const { return fHC ? fHC->fTimeBins : 0;} // Get Ntime bins - UInt_t GetBunchCrossCounter() const {return fHC ? fHC->fBunchCrossCounter : 0;} // get bunch cross counter - UInt_t GetPreTriggerCounter() const {return fHC ? fHC->fPreTriggerCounter : 0;} // get pre trigger info - UInt_t GetPreTriggerPhase() const {return fHC ? fHC->fPreTriggerPhase : 0;} // get trigger phase - - Int_t GetRow() const {return fMCM.fROW;} // get current row number - Int_t GetCol() const {return fCOL;} - Int_t GetExtendedCol() const {return fExtendedCOL;} - Int_t GetRowMax() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC - Int_t GetColMax() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC - // compatibility - Int_t GetMaxRow() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC - Int_t GetMaxCol() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC - - UInt_t GetHCword0() const {return fHC ? *fHC->fPos[0] : 0;} // get the HC word 0 - UInt_t GetHCword1() const {return fHC ? *fHC->fPos[1] : 0;} // get the HC word 1 - - Int_t GetDET() const {return fHC ? fHC->fDET : -1;} // get current det number - Int_t GetDet() const {return fHC ? fHC->fDET : -1;} // get current det number - - Int_t GetROB() const {return fMCM.fROB;} // get current ROB number - Int_t GetMCM() const {return fMCM.fMCM;} // get current MCM number - Int_t GetEventNumber() const { return fMCM.fEvCounter;} // MCM Event number and position of current MCM on TRD chamber - - Int_t GetTimeBin() const { return 0;} // MCM ADC channel and Time Bin of word 1 - - UInt_t *GetSMstreamPosition() const {return fSM.fPos;} // get position of the SM index word in the buffer - - - //---------------------------------------------------------- - - static void SetNoDebug() {fgDebugFlag = kFALSE;} // allow debug info - static void EnableMemoryReset() {fgEnableMemoryReset = kTRUE;} // allow memory reset - static void SetNoErrorWarning() {fgWarnError = kFALSE;} // disable warning and error info - static void SetForceCleanDataOnly() {fgCleanDataOnly = kTRUE;} // clean data only - static void AllowCorruptedData() {fgCleanDataOnly = kFALSE;} // accept corrupted data - - static void SetExtraWordsFix() {fgExtraSkip = kTRUE;} // extra skip of 24 32-bit words - static void SetSkipCDH() {fgSkipCDH = kTRUE;} // skip of 8 32-bit words - static void SetDumpHead(Int_t iv) {fgDumpHead = iv;} - static void DisableStackNumberChecker() {fgStackNumberChecker = kFALSE;} // set false to cleanroom data - static void DisableStackLinkNumberChecker() {fgStackLinkNumberChecker = kFALSE;} - static void DisableSkipData() {fgSkipData = kFALSE;} // keep reading next words even previous words were corrupted - debugging purpose - static void SetDumpingEnable() {fDumpingEnable = kTRUE;} - - static void EnableDecodeConfigData() {fgEnableDecodeConfigData = kTRUE;} // allow configuration data decoding - static Bool_t fgEnableDecodeConfigData; - - Int_t GetGlobalNTimeBins() {return fGlobalNTimeBins;} // get number of time information for the digit container - - //-------------------------------------------------------- - // Decoding functions - //-------------------------------------------------------- - - void DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const ; - const char *DumpSMInfo(const struct AliTRDrawSM *sm); - void DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const; - void DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const; - const char *DumpStackInfo(const struct AliTRDrawStack *st); - Bool_t DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const; - Bool_t DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const; - const char *DumpHCinfoH0(const struct AliTRDrawHC *hc); - const char *DumpHCinfoH1(const struct AliTRDrawHC *hc); - void DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const; - UInt_t GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const; - void DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const; - void MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const; - const char *DumpMCMinfo(const struct AliTRDrawMCM *mcm); - const char *DumpMCMadcMask(const struct AliTRDrawMCM *mcm); - - - protected: - - Bool_t InitBuffer(void *buffer, UInt_t length); // init the buffer - called by DecodeSM(void*, UInt_t) - Bool_t DumpWords(UInt_t *px, UInt_t iw, UInt_t marker = 0); // dump some words onto the screen - - void SwapOnEndian(); // swap if endian is BIG - Bool_t SkipWords(UInt_t iw); // skip number of words - Bool_t DecodeGTUheader(); // decode data in GTU header - Bool_t DecodeTracklets(); // decode tracklets - Bool_t DecodeHC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, AliTRDSignalIndex *indexes); // decode data in HC - - Bool_t DecodeADC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, AliTRDSignalIndex *indexes); // decode 10 ADC words - Bool_t DecodeADCExtended(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, AliTRDSignalIndex *indexes); // decode 10 ADC words - - Bool_t DecodeHCheader(); // decode HC header - Bool_t SeekEndOfData(); // go to next end of raw data marker (actually 1 word after) - Bool_t SkipMCMdata(UInt_t iw); // skip this mcm data due to mcm header corruption - Bool_t SeekNextMCMheader(); // go to next mcm header - Bool_t DecodeMCMheader(); // decode mcm header - - Bool_t IsRowValid(); // check if row within the range - Bool_t IsHCheaderOK(); // check if current hc header data make sense - Bool_t IsMCMheaderOK(); // check if current mcm header data make sense - - Bool_t SetGlobalNTimebins(); // set number of timebin based on the value read from HC header, this value will be used in the digit container - Bool_t SetNTimebins(); // set number of timebin based on the value read from HC header - - void ResetCounters(); // reset some counters - void ResetIterators(); // needed for Next() - void ResetPerSM(); // reset every SM - void ResetPerStack(); // reset every Stack - void ResetPerHC(); // reset every HC - void ResetPerMCM(); // reset every MCM - void ResetMemory(); // reset all data members - - AliTRDrawFastStream(const AliTRDrawFastStream& st); - AliTRDrawFastStream &operator=(const AliTRDrawFastStream &); - - // ----------------- DATA MEMBERS START - - struct AliTRDrawSM fSM; // one SM per buffer - struct AliTRDrawStack *fStack; //! pointer to the current stack - struct AliTRDrawHC *fHC; //! current HC - struct AliTRDrawHC *fLastHC; //! last HC - struct AliTRDrawMCM fMCM; //! current MCM - - UInt_t *fpPos; // current position in the buffer - UInt_t *fpBegin; // begin - pointer to the buffer word 0 - UInt_t *fpEnd; // end of the buffer - - UInt_t fWordLength; // length of the buffer in 32bit words - - UInt_t *fpPosTemp; // specific position in the buffer - Int_t fGlobalNTimeBins; // number of time bin to be used in the digit container - Bool_t fIsTimeBinSet; // set true if the global time bin is set to avoid multiple search - Bool_t fIsGlobalDigitsParamSet; // set true if the global digit parameters are already set - - Int_t fStackNumber; // current stack number - Int_t fStackLinkNumber; // current link in the stack - - Int_t fLinkTrackletCounter; // count the tracklets in the current HC - Int_t fEndOfTrackletCount; // count link by link (hc by hc) used for debug - Int_t fNWordsCounter; // counts words of given hc having link monitor error - - UInt_t fMaskADCword; // temp mask when decoding adcs - UInt_t fTbinADC; // temp adc - - UInt_t fEventCounter; // stores the valid/current MCM event counter - UInt_t fLastEventCounter; // last known event counter of MCM - - Bool_t fSharedPadsOn; // do we want to output shared pads - default is off - Int_t fMaxADCgeom; // maximum ADC channels per mcm - - Short_t fADCnumber; // number of the ADC 0 .. 20 - Short_t fCOL; // column - row from MCM - Short_t fExtendedCOL; // virtual column for extended digit container - Bool_t fIsShared; - - Bool_t fBufferRead; - - AliTRDgeometry *fGeometry; //! TRD geometry - AliRawReader *fRawReader; //! raw reader - - AliTRDfeeParam *fTRDfeeParam; // pointer to the fee params - - // STATIC - - static Bool_t fgExtraSkip; // whether we should skip the leading 24 words - static Bool_t fgSkipCDH; // whether we should skip CDH (8 words) - static Bool_t fgWarnError; // no errors no warnings - static Bool_t fgCleanDataOnly; // release only clean events = no errors - static Bool_t fgDebugFlag; // allow debugging info - static Bool_t fgEnableMemoryReset; // allow memory reset - static Bool_t fgStackNumberChecker; // decide if we check stack number insanity - set false to cleanroom data - static Bool_t fgStackLinkNumberChecker; // decide if we check stack link number insanity - debuging purpose - static Bool_t fgSkipData; // decide if we skip corrupted data of given HC - static Int_t fgDumpHead; // number of words to dump (from the start of the buffer) on each Init - static Short_t fgMCMordering[16]; // mcm number odering for mcm header corruption check - static Short_t fgROBordering[16]; // mcm number odering for mcm header corruption check - static Int_t fgLastHC; // HC number indicator to check HC numbering - static Int_t fgLastROB; // ROB number indicator to check ROB numbering - static Int_t fgLastIndex; // variable to check mcm number odering - - static Bool_t fDumpingEnable; - - static Int_t fDumpingSM; - static Int_t fDumpingStack; - static Int_t fDumpingLayer; - static Int_t fDumpingROB; - static Int_t fDumpingMCM; - - // ----------------- DATA MEMBERS STOP - - enum ETRDzRawStreamError - { - kDecodeStackInfo = 1 // - , kMissingData = 2 // - , kLinkDataMissing = 3 // - , kHCdataMissing = 4 // - , kTrackletOverflow = 5 // - , kEOTrackeltsMissing = 6 // - , kWrongPadrow = 7 // - , kMCMheaderCorrupted = 8 // - , kWrongMCMorROB = 9 // - , kMCMeventMissmatch = 10 // - , kMCMADCMaskMissing = 11 // - , kHCHeaderCorrupt = 12 // - , kHCHeaderWrongStack = 13 // - , kHCHeaderWrongLayer = 14 // - , kHCHeaderWrongSide = 15 // - , kHCHeaderWrongSM = 16 // - , kHCHeaderWrongDet = 17 // - , kHCHeaderWrongROC = 18 // - , kHCWordMissing = 19 // - , kMCMdataMissing = 20 // - , kMCMoverflow = 21 // - , kADCdataMissing = 22 // - , kADCmaskMissmatch = 23 // - , kWrongPadcolumn = 24 // - }; - - ClassDef(AliTRDrawFastStream, 0) -}; //clas def end - -#endif +#ifndef ALITRDRAWHLTSTREAM_H +#define ALITRDRAWHLTSTREAM_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id: AliTRDrawFastStream.h 27696 2008-07-31 09:18:53Z cblume $ */ + +///////////////////////////////////////////////////////////////////////////////// +// // +// This class provides access to TRD digits in raw data in a way of streaming. // +// // +///////////////////////////////////////////////////////////////////////////////// + +#include "TObject.h" +#include "TString.h" +#include "AliTRDrawStreamBase.h" +#include "AliTRDarrayADC.h" +#include "AliTRDarrayDictionary.h" +#include "AliTRDSignalIndex.h" + +class AliTRDgeometry; +class AliRawReader; +class AliTRDdigitsManager; +class TTreeSRedirector; +class AliTRDfeeParam; + + +class AliTRDrawFastStream : public AliTRDrawStreamBase +{ // class def begin + + public: + + //-------------------------------------------------------- + // THE STRUCTURES + //-------------------------------------------------------- + + struct AliTRDrawMCM + { // mcm struct + Int_t fROB; // ROB number + Int_t fMCM; // MCM number + Int_t fROW; // row number filed during decoding + + UInt_t fEvCounter; // MCM event counter + UInt_t fADCMask; // ADC mask + UInt_t fADCMaskWord; // word with ADC mask in + UInt_t fADCchannel[TRDMAXADC]; // channels to be decoded accrording to ADC mask + + Int_t fADCmax; // number of ADCs fired + Int_t fADCcount; // number of ADCs fired from double checking bit + Int_t fMCMADCWords; // mcm words to expect + Int_t fSingleADCwords; // n of words per ADC + + Int_t fMCMhdCorrupted; // is mcm header corrupted + Int_t fADCmaskCorrupted; // is mcm adc mask corrupted + Bool_t fDataCorrupted; // true if the corruption is in ADC data level + + UInt_t *fPos; //! position of mcm header in the buffer + UInt_t *fAdcDataPos; //! start of ADC data for this mcm + + Int_t fADCcounter; // count the adcs decoded + + + AliTRDrawMCM() + : fROB(-1) + , fMCM(-1) + , fROW(-1) + , fEvCounter(0) + , fADCMask(0) + , fADCMaskWord(0) + , fADCchannel() + , fADCmax(0) + , fADCcount(0) + , fMCMADCWords(0) + , fSingleADCwords(0) + , fMCMhdCorrupted(0) + , fADCmaskCorrupted(0) + , fDataCorrupted(0) + , fPos(0) + , fAdcDataPos(0) + , fADCcounter(0) + { + // default constructor + }; + + AliTRDrawMCM(const AliTRDrawMCM & p): + fROB(p.fROB) + , fMCM(p.fMCM) + , fROW(p.fROW) + , fEvCounter(p.fEvCounter) + , fADCMask(p.fADCMask) + , fADCMaskWord(p.fADCMaskWord) + , fADCchannel() + , fADCmax(p.fADCmax) + , fADCcount(p.fADCcount) + , fMCMADCWords(p.fMCMADCWords) + , fSingleADCwords(p.fSingleADCwords) + , fMCMhdCorrupted(p.fMCMhdCorrupted) + , fADCmaskCorrupted(p.fADCmaskCorrupted) + , fDataCorrupted(p.fDataCorrupted) + , fPos(p.fPos) + , fAdcDataPos(p.fAdcDataPos) + , fADCcounter(p.fADCcounter) + { + // copy constructor + }; + + AliTRDrawMCM &operator=(const AliTRDrawMCM &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + struct AliTRDrawHC + { // hc struct + + //tacklet words of given HC + UInt_t fTrackletWords[MAXTRACKLETSPERHC]; // array to keep tracklet words + Short_t fNTracklets; // number of tracklet + + // header word 0 + Int_t fSpecialRawV; // Raw data version + Int_t fRawVMajor; // Raw data version + Int_t fRawVMajorOpt; // Raw data version + Int_t fRawVMinor; // Raw data version + Int_t fNExtraWords; // N extra HC header words + Int_t fDCSboard; // DCS board number + Int_t fSM; // Super Module number + Int_t fSMHCheader; // Super Module number from HC header + Int_t fStack; // Stack number (some people might call it a chamber) + Int_t fStackHCheader; // Stack number from HC header(some people might call it a chamber) + Int_t fLayer; // Layer number (some people might call it a plane) + Int_t fLayerHCheader; // Layer number from HC header(some people might call it a plane) + Int_t fSide; // Side of HC + Int_t fSideHCheader; // Side of HC from HC header + + // header word 1 + Int_t fTimeBins; // N of t bins + UInt_t fBunchCrossCounter; // Bunch crossing counter + UInt_t fPreTriggerCounter; // Pre Trigger counter + UInt_t fPreTriggerPhase; // Pre Trigger phase + + // error + UShort_t fErrorCodes[1411]; // array to keep encoded errors + UInt_t fNErrors; // number of total errors of given hc + + Short_t fH0Corrupted; // is hc header 0 corrupted + Short_t fH1Corrupted; // is hc header 1 corrupted + Short_t fCorrupted; // is hc data corrupted + Bool_t fEOTECorrupted; // if the corruption is due to meet END_OF_TRACKLET_MARKERNEW + Bool_t fBufferCorrupted; // if the corruption is due to buffer end + Bool_t fDataCorrupted; // if the corruption is on the MCM data + + Short_t fMCMCorrupted[TRDMAXMCM]; // is hc data corrupted + + UInt_t *fPos[2]; //! position of the header words in buffer + + Int_t fDET; // filled while decoding + Int_t fROC; // filled while decoding + Int_t fRowMax; // filled while decoding + Int_t fColMax; // filled while decoding + + // hc data + Int_t fMCMmax; // number of mcm found + + AliTRDrawHC() + : fTrackletWords() + , fNTracklets(0) + , fSpecialRawV(0) + , fRawVMajor(0) + , fRawVMajorOpt(0) + , fRawVMinor(0) + , fNExtraWords(0) + , fDCSboard(-1) + , fSM(-1) + , fSMHCheader(-1) + , fStack(-1) + , fStackHCheader(-1) + , fLayer(-1) + , fLayerHCheader(-1) + , fSide(-1) + , fSideHCheader(-1) + , fTimeBins(0) + , fBunchCrossCounter(0) + , fPreTriggerCounter(0) + , fPreTriggerPhase(0) + , fNErrors(0) + , fH0Corrupted(0) + , fH1Corrupted(0) + , fCorrupted(0) + , fEOTECorrupted(0) + , fBufferCorrupted(0) + , fDataCorrupted(0) + , fPos() + , fDET(-1) + , fROC(-1) + , fRowMax(-1) + , fColMax(-1) + , fMCMmax(0) + { + // default constructor hc info + }; + + AliTRDrawHC(const AliTRDrawHC & p): + fTrackletWords() + , fNTracklets(p.fNTracklets) + , fSpecialRawV(p.fSpecialRawV) + , fRawVMajor(p.fRawVMajor) + , fRawVMajorOpt(p.fRawVMajorOpt) + , fRawVMinor(p.fRawVMinor) + , fNExtraWords(p.fNExtraWords) + , fDCSboard(p.fDCSboard) + , fSM(p.fSM) + , fSMHCheader(p.fSMHCheader) + , fStack(p.fStack) + , fStackHCheader(p.fStackHCheader) + , fLayer(p.fLayer) + , fLayerHCheader(p.fLayerHCheader) + , fSide(p.fSide) + , fSideHCheader(p.fSideHCheader) + , fTimeBins(p.fTimeBins) + , fBunchCrossCounter(p.fBunchCrossCounter) + , fPreTriggerCounter(p.fPreTriggerCounter) + , fPreTriggerPhase(p.fPreTriggerPhase) + , fNErrors(p.fNErrors) + , fH0Corrupted(p.fH0Corrupted) + , fH1Corrupted(p.fH1Corrupted) + , fCorrupted(p.fCorrupted) + , fEOTECorrupted(p.fEOTECorrupted) + , fBufferCorrupted(p.fBufferCorrupted) + , fDataCorrupted(p.fDataCorrupted) + , fPos() + , fDET(p.fDET) + , fROC(p.fROC) + , fRowMax(p.fRowMax) + , fColMax(p.fColMax) + , fMCMmax(p.fMCMmax) + { + // copy constructor + }; + + AliTRDrawHC &operator=(const AliTRDrawHC &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + struct AliTRDrawStack + { + UInt_t fHeaderSize; // header size of the stack info + Bool_t fLinksActive[12]; // data links active - 1 per half chamber + Short_t fLinksDataType[12]; // 0 indicating real data for the front-end electronics + Short_t fLinksMonitor[12]; // 0 indicating properly operating link + Short_t fLinkMonitorError[12]; // record link monitor error + Int_t fActiveLinks; // number of active links + UInt_t *fPos; //! position in the buffer + + AliTRDrawHC fHalfChambers[12]; // 12 half chambers in a stack + + AliTRDrawStack() + : fHeaderSize(0) + , fLinksActive() + , fLinksDataType() + , fLinksMonitor() + , fLinkMonitorError() + , fActiveLinks(0) + , fPos(0) + , fHalfChambers() + { + // default constructor + }; + + AliTRDrawStack(const AliTRDrawStack & p): + fHeaderSize(p.fHeaderSize) + , fLinksActive() + , fLinksDataType() + , fLinksMonitor() + , fLinkMonitorError() + , fActiveLinks(p.fActiveLinks) + , fPos(p.fPos) + , fHalfChambers() + { + // copy constructor + }; + + AliTRDrawStack &operator=(const AliTRDrawStack &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + struct AliTRDrawSM + { + UInt_t fHeaderSize; // size of the header in words + Bool_t fTrackletEnable; // tracklet enable bit + Bool_t fStackActive[5]; // map of active/expected stacks + Int_t fActiveStacks; // number of active stacks + Int_t fCorrupted; // is sm info corrupted + Int_t fNexpectedHalfChambers; // number of half chambers to be read out in this sm + UInt_t *fPos; // location of the sm info - should be the first word (after CDH if not DDL buffer) + + AliTRDrawStack fStacks[5]; + + AliTRDrawSM() + : fHeaderSize(0) + , fTrackletEnable(0) + , fStackActive() + , fActiveStacks(0) + , fCorrupted(0) + , fNexpectedHalfChambers(0) + , fPos(0) + , fStacks() + { + // Default constructor + }; + + AliTRDrawSM(const AliTRDrawSM & p): + fHeaderSize(p.fHeaderSize) + , fTrackletEnable(p.fTrackletEnable) + , fStackActive() + , fActiveStacks(p.fActiveStacks) + , fCorrupted(p.fCorrupted) + , fNexpectedHalfChambers(p.fNexpectedHalfChambers) + , fPos(p.fPos) + , fStacks() + { + // copy constructor + }; + + AliTRDrawSM &operator=(const AliTRDrawSM &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + AliTRDrawFastStream(); + AliTRDrawFastStream(AliRawReader *rawReader); + virtual ~AliTRDrawFastStream(); + + //-------------------------------------------------------- + + virtual Bool_t Next(); // read the next data in the memory + virtual Int_t NextChamber(AliTRDdigitsManager *man, UInt_t **trackletContainer, UShort_t **errorCodeContainer); // read next chamber data in the memory + virtual Bool_t Init(); // initialize some internal variables + + Int_t NextBuffer(); // go and init next buffer if available - check the implementation file for return values + + Bool_t SetRawVersion(Int_t fraw); // set the raw version - used for backward compat. + + void SetSharedPadReadout(Bool_t fv) {fSharedPadsOn = fv;} // set the flag on if the reader should return the shared pads + + Bool_t DecodeSMHeader(void *buffer, UInt_t length); // decode a buffer + Bool_t SetReader(AliRawReader *reader); // set the raw reader to use + + // from MCM Header Word + // rob and mcm ordering + // side 0(even link) - ROB: 0 2 4 6 MCM: 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3 + // side 1( odd link) - ROB: 1 3 5 7 MCM: 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3 + + + UShort_t *GetErrorCodes() const { return fHC->fErrorCodes;} // return error codes pointer per hc + UInt_t GetNErrors() const {return fHC ? fHC->fNErrors: 0;} // [mj temp] + + // info from ADC data words + // from here, only works with returning ADC channel pointer using Next() + + UInt_t *GetTrackletWords() const { return fHC->fTrackletWords;} // return tracklet words pointer per hc + Int_t GetNTracklets() const {return fHC ? fHC->fNTracklets : -1;} // get number of tracklets + + Int_t GetSpecialRawVersion() const {return fHC ? fHC->fSpecialRawV : -1;} // return special raw version + Int_t GetMajorRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // major raw version getter + Int_t GetRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // compatibility see funtion above + Int_t GetMinorRawVersion() const {return fHC ? fHC->fRawVMinor : -1;} // minor raw version + + Int_t GetSM() const {return fHC ? fHC->fSM : -1;} // SM Position of CURRENT half chamber in full TRD + Int_t GetLayer() const {return fHC ? fHC->fLayer : -1;} // Layer Position of CURRENT half chamber in full TRD + Int_t GetStack() const {return fHC ? fHC->fStack : -1;} // Stack Position of CURRENT half chamber in full TRD + Int_t GetSide() const {return fHC ? fHC->fSide : -1;} // get side + Int_t GetDCS() const { return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header) + Int_t GetROC() const { return fHC ? fHC->fROC : -1;} // ROB Position of CURRENT half chamber in full TRD + Int_t GetNumberOfTimeBins() const { return fHC ? fHC->fTimeBins : 0;} // Get Ntime bins + UInt_t GetBunchCrossCounter() const {return fHC ? fHC->fBunchCrossCounter : 0;} // get bunch cross counter + UInt_t GetPreTriggerCounter() const {return fHC ? fHC->fPreTriggerCounter : 0;} // get pre trigger info + UInt_t GetPreTriggerPhase() const {return fHC ? fHC->fPreTriggerPhase : 0;} // get trigger phase + + Int_t GetRow() const {return fMCM.fROW;} // get current row number + Int_t GetCol() const {return fCOL;} + Int_t GetExtendedCol() const {return fExtendedCOL;} + Int_t GetRowMax() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC + Int_t GetColMax() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC + // compatibility + Int_t GetMaxRow() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC + Int_t GetMaxCol() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC + + UInt_t GetHCword0() const {return fHC ? *fHC->fPos[0] : 0;} // get the HC word 0 + UInt_t GetHCword1() const {return fHC ? *fHC->fPos[1] : 0;} // get the HC word 1 + + Int_t GetDET() const {return fHC ? fHC->fDET : -1;} // get current det number + Int_t GetDet() const {return fHC ? fHC->fDET : -1;} // get current det number + + Int_t GetROB() const {return fMCM.fROB;} // get current ROB number + Int_t GetMCM() const {return fMCM.fMCM;} // get current MCM number + Int_t GetEventNumber() const { return fMCM.fEvCounter;} // MCM Event number and position of current MCM on TRD chamber + + Int_t GetTimeBin() const { return 0;} // MCM ADC channel and Time Bin of word 1 + + UInt_t *GetSMstreamPosition() const {return fSM.fPos;} // get position of the SM index word in the buffer + + + //---------------------------------------------------------- + + static void SetNoDebug() {fgDebugFlag = kFALSE;} // allow debug info + static void EnableMemoryReset() {fgEnableMemoryReset = kTRUE;} // allow memory reset + static void SetNoErrorWarning() {fgWarnError = kFALSE;} // disable warning and error info + static void SetForceCleanDataOnly() {fgCleanDataOnly = kTRUE;} // clean data only + static void AllowCorruptedData() {fgCleanDataOnly = kFALSE;} // accept corrupted data + + static void SetExtraWordsFix() {fgExtraSkip = kTRUE;} // extra skip of 24 32-bit words + static void SetSkipCDH() {fgSkipCDH = kTRUE;} // skip of 8 32-bit words + static void SetDumpHead(Int_t iv) {fgDumpHead = iv;} + static void DisableStackNumberChecker() {fgStackNumberChecker = kFALSE;} // set false to cleanroom data + static void DisableStackLinkNumberChecker() {fgStackLinkNumberChecker = kFALSE;} + static void DisableSkipData() {fgSkipData = kFALSE;} // keep reading next words even previous words were corrupted - debugging purpose + static void SetDumpingEnable() {fDumpingEnable = kTRUE;} + + static void EnableDecodeConfigData() {fgEnableDecodeConfigData = kTRUE;} // allow configuration data decoding + static Bool_t fgEnableDecodeConfigData; + + Int_t GetGlobalNTimeBins() {return fGlobalNTimeBins;} // get number of time information for the digit container + + //-------------------------------------------------------- + // Decoding functions + //-------------------------------------------------------- + + void DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const ; + const char *DumpSMInfo(const struct AliTRDrawSM *sm); + void DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const; + void DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const; + const char *DumpStackInfo(const struct AliTRDrawStack *st); + Bool_t DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const; + Bool_t DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const; + const char *DumpHCinfoH0(const struct AliTRDrawHC *hc); + const char *DumpHCinfoH1(const struct AliTRDrawHC *hc); + void DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const; + UInt_t GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const; + void DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const; + void MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const; + const char *DumpMCMinfo(const struct AliTRDrawMCM *mcm); + const char *DumpMCMadcMask(const struct AliTRDrawMCM *mcm); + + + protected: + + Bool_t InitBuffer(void *buffer, UInt_t length); // init the buffer - called by DecodeSM(void*, UInt_t) + Bool_t DumpWords(UInt_t *px, UInt_t iw, UInt_t marker = 0); // dump some words onto the screen + + void SwapOnEndian(); // swap if endian is BIG + Bool_t SkipWords(UInt_t iw); // skip number of words + Bool_t DecodeGTUheader(); // decode data in GTU header + Bool_t DecodeTracklets(); // decode tracklets + Bool_t DecodeHC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, AliTRDSignalIndex *indexes); // decode data in HC + + Bool_t DecodeADC(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, AliTRDSignalIndex *indexes); // decode 10 ADC words + Bool_t DecodeADCExtended(AliTRDdigitsManager *digitsManager, AliTRDarrayADC *digits, AliTRDarrayDictionary *track0, AliTRDarrayDictionary *track1, AliTRDarrayDictionary *track2, AliTRDSignalIndex *indexes); // decode 10 ADC words + + Bool_t DecodeHCheader(); // decode HC header + Bool_t SeekEndOfData(); // go to next end of raw data marker (actually 1 word after) + Bool_t SkipMCMdata(UInt_t iw); // skip this mcm data due to mcm header corruption + Bool_t SeekNextMCMheader(); // go to next mcm header + Bool_t DecodeMCMheader(); // decode mcm header + + Bool_t IsRowValid(); // check if row within the range + Bool_t IsHCheaderOK(); // check if current hc header data make sense + Bool_t IsMCMheaderOK(); // check if current mcm header data make sense + + Bool_t SetGlobalNTimebins(); // set number of timebin based on the value read from HC header, this value will be used in the digit container + Bool_t SetNTimebins(); // set number of timebin based on the value read from HC header + + void ResetCounters(); // reset some counters + void ResetIterators(); // needed for Next() + void ResetPerSM(); // reset every SM + void ResetPerStack(); // reset every Stack + void ResetPerHC(); // reset every HC + void ResetPerMCM(); // reset every MCM + void ResetMemory(); // reset all data members + + AliTRDrawFastStream(const AliTRDrawFastStream& st); + AliTRDrawFastStream &operator=(const AliTRDrawFastStream &); + + // ----------------- DATA MEMBERS START + + struct AliTRDrawSM fSM; // one SM per buffer + struct AliTRDrawStack *fStack; //! pointer to the current stack + struct AliTRDrawHC *fHC; //! current HC + struct AliTRDrawHC *fLastHC; //! last HC + struct AliTRDrawMCM fMCM; //! current MCM + + UInt_t *fpPos; // current position in the buffer + UInt_t *fpBegin; // begin - pointer to the buffer word 0 + UInt_t *fpEnd; // end of the buffer + + UInt_t fWordLength; // length of the buffer in 32bit words + + UInt_t *fpPosTemp; // specific position in the buffer + Int_t fGlobalNTimeBins; // number of time bin to be used in the digit container + Bool_t fIsTimeBinSet; // set true if the global time bin is set to avoid multiple search + Bool_t fIsGlobalDigitsParamSet; // set true if the global digit parameters are already set + + Int_t fStackNumber; // current stack number + Int_t fStackLinkNumber; // current link in the stack + + Int_t fLinkTrackletCounter; // count the tracklets in the current HC + Int_t fEndOfTrackletCount; // count link by link (hc by hc) used for debug + Int_t fNWordsCounter; // counts words of given hc having link monitor error + + UInt_t fMaskADCword; // temp mask when decoding adcs + UInt_t fTbinADC; // temp adc + + UInt_t fEventCounter; // stores the valid/current MCM event counter + UInt_t fLastEventCounter; // last known event counter of MCM + + Bool_t fSharedPadsOn; // do we want to output shared pads - default is off + Int_t fMaxADCgeom; // maximum ADC channels per mcm + + Short_t fADCnumber; // number of the ADC 0 .. 20 + Short_t fCOL; // column - row from MCM + Short_t fExtendedCOL; // virtual column for extended digit container + Bool_t fIsShared; + + Bool_t fBufferRead; + + AliTRDgeometry *fGeometry; //! TRD geometry + AliRawReader *fRawReader; //! raw reader + + AliTRDfeeParam *fTRDfeeParam; // pointer to the fee params + Int_t fCommonAdditive; + + // STATIC + + static Bool_t fgExtraSkip; // whether we should skip the leading 24 words + static Bool_t fgSkipCDH; // whether we should skip CDH (8 words) + static Bool_t fgWarnError; // no errors no warnings + static Bool_t fgCleanDataOnly; // release only clean events = no errors + static Bool_t fgDebugFlag; // allow debugging info + static Bool_t fgEnableMemoryReset; // allow memory reset + static Bool_t fgStackNumberChecker; // decide if we check stack number insanity - set false to cleanroom data + static Bool_t fgStackLinkNumberChecker; // decide if we check stack link number insanity - debuging purpose + static Bool_t fgSkipData; // decide if we skip corrupted data of given HC + static Int_t fgDumpHead; // number of words to dump (from the start of the buffer) on each Init + static Short_t fgMCMordering[16]; // mcm number odering for mcm header corruption check + static Short_t fgROBordering[16]; // mcm number odering for mcm header corruption check + static Int_t fgLastHC; // HC number indicator to check HC numbering + static Int_t fgLastROB; // ROB number indicator to check ROB numbering + static Int_t fgLastIndex; // variable to check mcm number odering + + static Bool_t fDumpingEnable; + + static Int_t fDumpingSM; + static Int_t fDumpingStack; + static Int_t fDumpingLayer; + static Int_t fDumpingROB; + static Int_t fDumpingMCM; + + // ----------------- DATA MEMBERS STOP + + enum ETRDzRawStreamError + { + kDecodeStackInfo = 1 // + , kMissingData = 2 // + , kLinkDataMissing = 3 // + , kHCdataMissing = 4 // + , kTrackletOverflow = 5 // + , kEOTrackeltsMissing = 6 // + , kWrongPadrow = 7 // + , kMCMheaderCorrupted = 8 // + , kWrongMCMorROB = 9 // + , kMCMeventMissmatch = 10 // + , kMCMADCMaskMissing = 11 // + , kHCHeaderCorrupt = 12 // + , kHCHeaderWrongStack = 13 // + , kHCHeaderWrongLayer = 14 // + , kHCHeaderWrongSide = 15 // + , kHCHeaderWrongSM = 16 // + , kHCHeaderWrongDet = 17 // + , kHCHeaderWrongROC = 18 // + , kHCWordMissing = 19 // + , kMCMdataMissing = 20 // + , kMCMoverflow = 21 // + , kADCdataMissing = 22 // + , kADCmaskMissmatch = 23 // + , kWrongPadcolumn = 24 // + }; + + ClassDef(AliTRDrawFastStream, 0) +}; //clas def end + +#endif diff --git a/TRD/AliTRDrawStream.cxx b/TRD/AliTRDrawStream.cxx index 28b184ffecd..dc315775343 100644 --- a/TRD/AliTRDrawStream.cxx +++ b/TRD/AliTRDrawStream.cxx @@ -1,2103 +1,2100 @@ -/************************************************************************** -* 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::fgWarnError = kTRUE; -Bool_t AliTRDrawStream::fgCleanDataOnly = kFALSE; -Bool_t AliTRDrawStream::fgDebugFlag = kTRUE; -Bool_t AliTRDrawStream::fgEnableMemoryReset = kTRUE; -Bool_t AliTRDrawStream::fgStackNumberChecker = kTRUE; -Bool_t AliTRDrawStream::fgStackLinkNumberChecker = kFALSE; -Bool_t AliTRDrawStream::fgSkipData = kTRUE; -Bool_t AliTRDrawStream::fgEnableDecodeConfigData = kFALSE; -Int_t AliTRDrawStream::fgDumpHead = -1; -Int_t AliTRDrawStream::fgEmptySignals[] = - { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 - }; -Short_t AliTRDrawStream::fgMCMordering[] = - { - 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 - }; -Short_t AliTRDrawStream::fgROBordering[] = - { - 0, 1, 2, 3 - }; -Int_t AliTRDrawStream::fgLastHC = -1; -Int_t AliTRDrawStream::fgLastROB = -1; -Int_t AliTRDrawStream::fgLastIndex = -1; -Int_t AliTRDrawStream::fgDumpingSM = -1; -Int_t AliTRDrawStream::fgDumpingStack = -1; -Int_t AliTRDrawStream::fgDumpingLayer = -1; -Int_t AliTRDrawStream::fgDumpingROB = -1; -Int_t AliTRDrawStream::fgDumpingMCM = -1; -Bool_t AliTRDrawStream::fgDumpingEnable = kFALSE; - - -AliTRDrawStream::AliTRDrawStream() - : AliTRDrawStreamBase() - , fSM() - , fStack(0) - , fHC(0) - , fLastHC(0) - , fMCM(0) - , fADC(0) - , fpPos(0) - , fpBegin(0) - , fpEnd(0) - , fWordLength(0) - , fIsGlobalDigitsParamSet(kFALSE) - , fStackNumber(-1) - , fStackLinkNumber(-1) - , fhcMCMcounter(0) - , fmcmADCcounter(0) - , fLinkTrackletCounter(-1) - , fEndOfTrackletCount(-1) - , fNWordsCounter(-1) - , fMaskADCword(0) - , fTbinADC(0) - , fDecodedADCs(-1) - , fEventCounter(0) - , fLastEventCounter(0) - , fSharedPadsOn(kTRUE) - , fMaxADCgeom(0) - , fBufferRead(0) - , fGeometry(0) - , fRawReader(0) - , fTRDfeeParam(0) -{ - // - // default constructor - // - if (Init() == kFALSE) { - AliWarning("Unable to Init."); - } -} - -//-------------------------------------------------------- -AliTRDrawStream::AliTRDrawStream(AliRawReader *rawReader) - : AliTRDrawStreamBase(rawReader) - , fSM() - , fStack(0) - , fHC(0) - , fLastHC(0) - , fMCM(0) - , fADC(0) - , fpPos(0) - , fpBegin(0) - , fpEnd(0) - , fWordLength(0) - , fIsGlobalDigitsParamSet(kFALSE) - , fStackNumber(-1) - , fStackLinkNumber(-1) - , fhcMCMcounter(0) - , fmcmADCcounter(0) - , fLinkTrackletCounter(-1) - , fEndOfTrackletCount(-1) - , fNWordsCounter(-1) - , fMaskADCword(0) - , fTbinADC(0) - , fDecodedADCs(-1) - , fEventCounter(0) - , fLastEventCounter(0) - , fSharedPadsOn(kTRUE) - , fMaxADCgeom(0) - , fBufferRead(0) - , fGeometry(0) - , fRawReader(rawReader) - , fTRDfeeParam(0) -{ - // - // default constructor - // - if (fRawReader) { - if (Init() == kFALSE) { - AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )"); - } - } - else { - AliWarning("Unable to setup reader. Use SetReader(AliRawReader*)."); - } -} - -//------------------------------------------------------------ - -AliTRDrawStream::AliTRDrawStream(const AliTRDrawStream& /*st*/) - : AliTRDrawStreamBase() - , fSM() - , fStack(0) - , fHC(0) - , fLastHC(0) - , fMCM(0) - , fADC(0) - , fpPos(0) - , fpBegin(0) - , fpEnd(0) - , fWordLength(0) - , fIsGlobalDigitsParamSet(kFALSE) - , fStackNumber(-1) - , fStackLinkNumber(-1) - , fhcMCMcounter(0) - , fmcmADCcounter(0) - , fLinkTrackletCounter(-1) - , fEndOfTrackletCount(-1) - , fNWordsCounter(-1) - , fMaskADCword(0) - , fTbinADC(0) - , fDecodedADCs(-1) - , fEventCounter(0) - , fLastEventCounter(0) - , fSharedPadsOn(kTRUE) - , fMaxADCgeom(0) - , fBufferRead(0) - , fGeometry(0) - , fRawReader(0) - , fTRDfeeParam(0) -{ - // - // Copy constructor - // - AliError("Not implemeneted."); -} - -//------------------------------------------------------------ -Bool_t AliTRDrawStream::SetRawVersion(Int_t fraw) -{ - // - // function provided for backward compatibility - // - AliWarning("Raw data version is read from raw data stream! No point of setting it in here."); - fraw = 0; // avoid warnings - - return kFALSE; -} - -//------------------------------------------------------------ -AliTRDrawStream::~AliTRDrawStream() -{ - // - // destructor - // - delete fGeometry; -} - -//------------------------------------------------------------ -AliTRDrawStream & AliTRDrawStream::operator=(const AliTRDrawStream &) -{ - // - // we are not using this functionality - // - AliFatal("May not use."); - - return *this; -} - -//___________________________________________________________ -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 (fgWarnError) 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->fMCMADCWords = 0; - fMCM->fSingleADCwords = 0; - fMCM->fMCMhdCorrupted = 0; - fMCM->fADCmaskCorrupted = 0; - fMCM->fCorrupted = 0; - fMCM->fPos = NULL; - fMCM->fAdcDataPos = NULL; - fMCM->fADCcounter = 0; - - memset(fMCM->fADCchannel, 0, TRDMAXADC*sizeof(UInt_t)); -} - -//------------------------------------------------------------ -void AliTRDrawStream::ResetPerADC() -{ - // - // 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; imcmfMCMs[imcm]; - ResetPerMCM(); - for (Int_t iadc=0; iadcfADCs[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->SetPretiggerPhase(det,GetPreTriggerPhase()); - if (!fIsGlobalDigitsParamSet){ - digitsparam->SetCheckOCDB(kFALSE); - digitsparam->SetNTimeBins(ntbins); - digitsparam->SetADCbaseline(10); - fIsGlobalDigitsParamSet = kTRUE; - } - - // Allocate memory space for the digits buffer - if (digits->GetNtime() == 0) { - digits->Allocate(rowMax, colMax, ntbins); - digits->SetBaseline(digitsparam->GetADCbaseline()); - if (digitsManager->UsesDictionaries()) { - track0->Allocate(rowMax, colMax, ntbins); - track1->Allocate(rowMax, colMax, ntbins); - track2->Allocate(rowMax, colMax, ntbins); - } - } - - indexes = digitsManager->GetIndexes(det); - indexes->SetSM(GetSM()); - indexes->SetStack(GetStack()); - indexes->SetLayer(GetLayer()); - indexes->SetDetNumber(det); - if (indexes->IsAllocated() == kFALSE) - indexes->Allocate(rowMax, colMax, ntbins); - } - - // ntimebins data are ready to read - for (it = 0; it < GetNumberOfTimeBins(); it++) { - if (GetSignals()[it] > 0) { - - if (fSharedPadsOn) - digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), it, GetSignals()[it]); - else - digits->SetData(GetRow(), GetCol(), it, GetSignals()[it]); - - indexes->AddIndexRC(GetRow(), GetCol()); - if (digitsManager->UsesDictionaries()) { - track0->SetData(GetRow(), GetCol(), it, 0); - track1->SetData(GetRow(), GetCol(), it, 0); - track2->SetData(GetRow(), GetCol(), it, 0); - } - } - } // it - } // while Next() - - return det; -} - -//------------------------------------------------------------ -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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) { - AliError(Form("Tracklet decoding failed stack %d link %d", fStackNumber, fStackLinkNumber)); - } - continue; - } - } - - if (fpPos >= fpEnd) { - if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing"); - if (fgWarnError) AliError("HC data missing."); - fSM.fClean = kFALSE; - break; - } - - fgLastROB = -1; // to check mcm number odering - fgLastIndex = -1 ; // to check mcm number odering - if (DecodeHC() == kFALSE) { - fSM.fClean = kFALSE; - if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW - // during ADC data decoding or MCM header decoding - // we don't seek ENDOFRAWDATAMARKER - if (fgWarnError) { - AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC))); - AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC))); - } - - continue; - } - else { - SeekEndOfData(); // make sure that finish off with the end of data markers - } - } // ilink - } // istack - - ResetIterators(); // need to do it again for Next() function - - if (fSM.fClean == kTRUE) - return kTRUE; - - if (fgCleanDataOnly && (fSM.fClean == kFALSE)) { - if (fgWarnError) { - AliWarning("Buffer with errors. Returning FALSE."); - AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM))); - } - 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 (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted)); - if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted"); - return kFALSE; - } - else { - fpPos++; - if (fpPos >= fpEnd) { - fHC->fCorrupted += 1; - if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer."); - if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing"); - return kFALSE; - } - } - - if ((fHC->fRawVMajor & 64) == 64) { // test pattern data - AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos); - if (tpStream->DecodeTPdata() == kFALSE) { - if (fgWarnError) AliError("failed to decode test pattern data"); - return kFALSE; - } - 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 (fgWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!"); - } - } // if fHC->fRawVMajor - else { // test pattern data - if (fgWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class - } - } // for iadc - } // if fMCM->fADCmax - else { - fpPos++; - } - }//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 - // - - UInt_t commonAdditive = AliTRDrawStreamBase::fgCommonAdditive; - - fADC->fCorrupted = 0; - if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1); - if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2); - - fADC->fPos = fpPos; - fTbinADC = 0; - - for (Int_t i = 0; i < GetNumberOfTimeBins(); i++) - //for (Int_t i = 0; i < TRDMAXTBINS; i++) - fADC->fSignals[i] = 0; - - for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++) { - if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) { - if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos)); - fADC->fCorrupted += 16; - fHC->fCorrupted += 16; - fpPos--; - return kFALSE; - } - if (fMaskADCword != ADC_WORD_MASK(*fpPos)) { - fADC->fCorrupted += 1; - if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d", - fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted)); - fpPos++; - continue; - } - - // here we subtract the baseline ( == common additive) - fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >> 2) - commonAdditive; - fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive; - fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive; - - fTbinADC += 3; - fpPos++; - } // iw - - if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) { - fADC->fIsShared = kTRUE; - } - else { - fADC->fIsShared = kFALSE; - } - - 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 - // - - UInt_t commonAdditive = AliTRDrawStreamBase::fgCommonAdditive; - - fADC->fCorrupted = 0; - if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1); - if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2); - - fADC->fPos = fpPos; - - fTbinADC = ((*fpPos & 0x000000fc) >> 2); - fMCM->fSingleADCwords = ((*fpPos & 0x00000f00) >> 8); - fADC->fSignals[fTbinADC] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive; - fADC->fSignals[fTbinADC+1] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive; - - fpPos++; - for (Int_t iw = 0; iw < fMCM->fSingleADCwords-1; iw++) { // it goes up to fMCM->fSingleADCwords-1 since the first word was already decoded above - if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) { - if (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos)); - fADC->fCorrupted += 16; - fHC->fCorrupted += 16; - fpPos--; - return kFALSE; - } - if (fMaskADCword != ADC_WORD_MASK(*fpPos)) { - fADC->fCorrupted += 1; - if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d", - fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted)); - fpPos++; - continue; - } - - // here we subtract the baseline ( == common additive) - fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0x00000ffc) >> 2) - commonAdditive; - fADC->fSignals[fTbinADC + 3] = ((*fpPos & 0x003ff000) >> 12) - commonAdditive; - fADC->fSignals[fTbinADC + 4] = ((*fpPos & 0xffc00000) >> 22) - commonAdditive; - - fTbinADC += 3; - fpPos++; - } // iw - -// for(int i=0; i ) -// printf(); - - - if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) { - fADC->fIsShared = kTRUE; - } - else { - fADC->fIsShared = kFALSE; - } - - 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, hc->fSM, 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 (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword)); - mcm->fMCMhdCorrupted += 16; - fHC->fCorrupted += 16; //to finish data reading of this HC - } - - 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 (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword)); - mcm->fADCmaskCorrupted += 16; - fHC->fCorrupted += 16; //to finish data reading of this HC - } - - 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->fMCMADCWords = 0; - mcm->fSingleADCwords = 0; - mcm->fADCmax = 0; - mcm->fADCMask = GetMCMadcMask(word, mcm); - - if (mcm->fADCMask > 0) { - for (Int_t i = 0; i < TRDMAXADC; i++) { - mcm->fADCchannel[mcm->fADCmax] = 0; - if ( IS_BIT_SET(mcm->fADCMask,i) ) { - mcm->fADCchannel[mcm->fADCmax] = i; - mcm->fADCmax++; - } - } - } - 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->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 ); - mcm->fSingleADCwords = 0; - if (mcm->fADCmax > 0) { - mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax; - } - 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(); -} - +/************************************************************************** +* 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::fgWarnError = kTRUE; +Bool_t AliTRDrawStream::fgCleanDataOnly = kFALSE; +Bool_t AliTRDrawStream::fgDebugFlag = kTRUE; +Bool_t AliTRDrawStream::fgEnableMemoryReset = kTRUE; +Bool_t AliTRDrawStream::fgStackNumberChecker = kTRUE; +Bool_t AliTRDrawStream::fgStackLinkNumberChecker = kFALSE; +Bool_t AliTRDrawStream::fgSkipData = kTRUE; +Bool_t AliTRDrawStream::fgEnableDecodeConfigData = kFALSE; +Int_t AliTRDrawStream::fgDumpHead = -1; +Int_t AliTRDrawStream::fgEmptySignals[] = + { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + }; +Short_t AliTRDrawStream::fgMCMordering[] = + { + 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 + }; +Short_t AliTRDrawStream::fgROBordering[] = + { + 0, 1, 2, 3 + }; +Int_t AliTRDrawStream::fgLastHC = -1; +Int_t AliTRDrawStream::fgLastROB = -1; +Int_t AliTRDrawStream::fgLastIndex = -1; +Int_t AliTRDrawStream::fgDumpingSM = -1; +Int_t AliTRDrawStream::fgDumpingStack = -1; +Int_t AliTRDrawStream::fgDumpingLayer = -1; +Int_t AliTRDrawStream::fgDumpingROB = -1; +Int_t AliTRDrawStream::fgDumpingMCM = -1; +Bool_t AliTRDrawStream::fgDumpingEnable = kFALSE; + + +AliTRDrawStream::AliTRDrawStream() + : AliTRDrawStreamBase() + , fSM() + , fStack(0) + , fHC(0) + , fLastHC(0) + , fMCM(0) + , fADC(0) + , fpPos(0) + , fpBegin(0) + , fpEnd(0) + , fWordLength(0) + , fIsGlobalDigitsParamSet(kFALSE) + , fStackNumber(-1) + , fStackLinkNumber(-1) + , fhcMCMcounter(0) + , fmcmADCcounter(0) + , fLinkTrackletCounter(-1) + , fEndOfTrackletCount(-1) + , fNWordsCounter(-1) + , fMaskADCword(0) + , fTbinADC(0) + , fDecodedADCs(-1) + , fEventCounter(0) + , fLastEventCounter(0) + , fSharedPadsOn(kTRUE) + , fMaxADCgeom(0) + , fBufferRead(0) + , fGeometry(0) + , fRawReader(0) + , fTRDfeeParam(0) + , fCommonAdditive(0) +{ + // + // 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) +{ + // + // 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) +{ + // + // 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 (fgWarnError) 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->fMCMADCWords = 0; + fMCM->fSingleADCwords = 0; + fMCM->fMCMhdCorrupted = 0; + fMCM->fADCmaskCorrupted = 0; + fMCM->fCorrupted = 0; + fMCM->fPos = NULL; + fMCM->fAdcDataPos = NULL; + fMCM->fADCcounter = 0; + + memset(fMCM->fADCchannel, 0, TRDMAXADC*sizeof(UInt_t)); +} + +//------------------------------------------------------------ +void AliTRDrawStream::ResetPerADC() +{ + // + // 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; imcmfMCMs[imcm]; + ResetPerMCM(); + for (Int_t iadc=0; iadcfADCs[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->SetPretiggerPhase(det,GetPreTriggerPhase()); + if (!fIsGlobalDigitsParamSet){ + digitsparam->SetCheckOCDB(kFALSE); + 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++) { + if (GetSignals()[it] > fCommonAdditive) { + + if (fSharedPadsOn) + digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), it, GetSignals()[it]); + else + digits->SetData(GetRow(), GetCol(), it, GetSignals()[it]); + + indexes->AddIndexRC(GetRow(), GetCol()); + if (digitsManager->UsesDictionaries()) { + track0->SetData(GetRow(), GetCol(), it, 0); + track1->SetData(GetRow(), GetCol(), it, 0); + track2->SetData(GetRow(), GetCol(), it, 0); + } + } + } // it + } // while Next() + + return det; +} + +//------------------------------------------------------------ +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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) 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 (fgWarnError) { + AliError(Form("Tracklet decoding failed stack %d link %d", fStackNumber, fStackLinkNumber)); + } + continue; + } + } + + if (fpPos >= fpEnd) { + if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing"); + if (fgWarnError) AliError("HC data missing."); + fSM.fClean = kFALSE; + break; + } + + fgLastROB = -1; // to check mcm number odering + fgLastIndex = -1 ; // to check mcm number odering + if (DecodeHC() == kFALSE) { + fSM.fClean = kFALSE; + if (fHC->fCorrupted < 16) SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW + // during ADC data decoding or MCM header decoding + // we don't seek ENDOFRAWDATAMARKER + if (fgWarnError) { + AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC))); + AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC))); + } + + continue; + } + else { + SeekEndOfData(); // make sure that finish off with the end of data markers + } + } // ilink + } // istack + + ResetIterators(); // need to do it again for Next() function + + if (fSM.fClean == kTRUE) + return kTRUE; + + if (fgCleanDataOnly && (fSM.fClean == kFALSE)) { + if (fgWarnError) { + AliWarning("Buffer with errors. Returning FALSE."); + AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM))); + } + 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 (fgWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted)); + if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted"); + return kFALSE; + } + else { + fpPos++; + if (fpPos >= fpEnd) { + fHC->fCorrupted += 1; + if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer."); + if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing"); + return kFALSE; + } + } + + if ((fHC->fRawVMajor & 64) == 64) { // test pattern data + AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos); + if (tpStream->DecodeTPdata() == kFALSE) { + if (fgWarnError) AliError("failed to decode test pattern data"); + return kFALSE; + } + 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 (fgWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!"); + } + } // if fHC->fRawVMajor + else { // test pattern data + if (fgWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class + } + } // for iadc + } // if fMCM->fADCmax + else { + fpPos++; + } + }//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 (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos)); + fADC->fCorrupted += 16; + fHC->fCorrupted += 16; + fpPos--; + return kFALSE; + } + if (fMaskADCword != ADC_WORD_MASK(*fpPos)) { + fADC->fCorrupted += 1; + if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d", + fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted)); + fpPos++; + continue; + } + + 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 (fgWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos)); + fADC->fCorrupted += 16; + fHC->fCorrupted += 16; + fpPos--; + return kFALSE; + } + if (fMaskADCword != ADC_WORD_MASK(*fpPos)) { + fADC->fCorrupted += 1; + if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x Current mask: 0x%08x] MCM= %s Error : %d", + fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted)); + fpPos++; + continue; + } + + 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, hc->fSM, 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 (fgWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword)); + mcm->fMCMhdCorrupted += 16; + fHC->fCorrupted += 16; //to finish data reading of this HC + } + + 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 (fgWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword)); + mcm->fADCmaskCorrupted += 16; + fHC->fCorrupted += 16; //to finish data reading of this HC + } + + 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->fMCMADCWords = 0; + mcm->fSingleADCwords = 0; + mcm->fADCmax = 0; + mcm->fADCMask = GetMCMadcMask(word, mcm); + + if (mcm->fADCMask > 0) { + for (Int_t i = 0; i < TRDMAXADC; i++) { + mcm->fADCchannel[mcm->fADCmax] = 0; + if ( IS_BIT_SET(mcm->fADCMask,i) ) { + mcm->fADCchannel[mcm->fADCmax] = i; + mcm->fADCmax++; + } + } + } + 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->fMCMADCWords = ( mcm->fADCmax ) * ( fTbins / 3 ); + mcm->fSingleADCwords = 0; + if (mcm->fADCmax > 0) { + mcm->fSingleADCwords = mcm->fMCMADCWords/mcm->fADCmax; + } + 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(); +} + diff --git a/TRD/AliTRDrawStream.h b/TRD/AliTRDrawStream.h index 14af8d7fe9e..9d75b8765c7 100644 --- a/TRD/AliTRDrawStream.h +++ b/TRD/AliTRDrawStream.h @@ -1,701 +1,702 @@ -#ifndef ALITRDRAWSTREAM_H -#define ALITRDRAWSTREAM_H - -/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * - * See cxx source for full Copyright notice */ - -/* $Id: AliTRDrawStream.h 27696 2008-07-31 09:18:53Z cblume $ */ - -/////////////////////////////////////////////////////////////////////////////// -// // -// This class provides access to TRD digits in raw data. // -// // -/////////////////////////////////////////////////////////////////////////////// - -#include "AliTRDrawStreamBase.h" - -class AliTRDgeometry; -class AliRawReader; -class AliTRDdigitsManager; -class TTreeSRedirector; -class AliTRDfeeParam; - - -class AliTRDrawStream : public AliTRDrawStreamBase -{ // class def begin - - public: - - //-------------------------------------------------------- - // THE STRUCTURES - //-------------------------------------------------------- - - struct AliTRDrawADC - {//adc struct - - UInt_t *fPos; //! position of ADC 1st word in the buffer - Short_t fADCnumber; // number of the ADC 0 .. 20 - Short_t fExtendedCOL; // column - row from MCM - Short_t fCOL; // column - row from MCM - Int_t fSignals[TRDMAXTBINS]; // signals for this adc - Bool_t fIsShared; // is pad chared between MCMs - Short_t fCorrupted; // is adc word corrupted - - AliTRDrawADC() - : fPos(0) - , fADCnumber(0) - , fExtendedCOL(0) - , fCOL(0) - , fSignals() - , fIsShared(kFALSE) - , fCorrupted(0) - { - // default constructor - }; - - AliTRDrawADC(const AliTRDrawADC& p): - fPos(p.fPos) - , fADCnumber(p.fADCnumber) - , fExtendedCOL(p.fExtendedCOL) - , fCOL(p.fCOL) - , fSignals() - , fIsShared(p.fIsShared) - , fCorrupted(p.fCorrupted) - { - // copy constructor - }; - - AliTRDrawADC &operator=(const AliTRDrawADC &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - struct AliTRDrawMCM - { // mcm struct - Int_t fROB; // ROB number - Int_t fMCM; // MCM number - Int_t fROW; // row number filed during decoding - - UInt_t fEvCounter; // MCM event counter - UInt_t fADCMask; // ADC mask - UInt_t fADCMaskWord; // word with ADC mask in - UInt_t fADCchannel[TRDMAXADC]; // channels to be decoded accrording to ADC mask - - Int_t fADCmax; // number of ADCs fired - Int_t fADCcount; // number of ADCs fired from double checking bit - Int_t fMCMADCWords; // mcm words to expect - Int_t fSingleADCwords; // n of words per ADC - - Int_t fMCMhdCorrupted; // is mcm header corrupted - Int_t fADCmaskCorrupted; // is mcm adc mask corrupted - Int_t fCorrupted; // is mcm data missing - - UInt_t *fPos; //! position of mcm header in the buffer - UInt_t *fAdcDataPos; //! start of ADC data for this mcm - - Int_t fADCcounter; // count the adcs decoded - AliTRDrawADC fADCs[TRDMAXADC]; // 21 adcs - - AliTRDrawMCM() - : fROB(-1) - , fMCM(-1) - , fROW(-1) - , fEvCounter(0) - , fADCMask(0) - , fADCMaskWord(0) - , fADCchannel() - , fADCmax(0) - , fADCcount(0) - , fMCMADCWords(0) - , fSingleADCwords(0) - , fMCMhdCorrupted(0) - , fADCmaskCorrupted(0) - , fCorrupted(0) - , fPos(0) - , fAdcDataPos(0) - , fADCcounter(0) - , fADCs() - { - // default constructor - }; - - AliTRDrawMCM(const AliTRDrawMCM & p): - fROB(p.fROB) - , fMCM(p.fMCM) - , fROW(p.fROW) - , fEvCounter(p.fEvCounter) - , fADCMask(p.fADCMask) - , fADCMaskWord(p.fADCMaskWord) - , fADCchannel() - , fADCmax(p.fADCmax) - , fADCcount(p.fADCcount) - , fMCMADCWords(p.fMCMADCWords) - , fSingleADCwords(p.fSingleADCwords) - , fMCMhdCorrupted(p.fMCMhdCorrupted) - , fADCmaskCorrupted(p.fADCmaskCorrupted) - , fCorrupted(p.fCorrupted) - , fPos(p.fPos) - , fAdcDataPos(p.fAdcDataPos) - , fADCcounter(p.fADCcounter) - , fADCs() - { - // copy constructor - }; - - AliTRDrawMCM &operator=(const AliTRDrawMCM &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - struct AliTRDrawHC - { // hc struct - - //tacklet words of given HC - UInt_t fTrackletWords[MAXTRACKLETSPERHC]; // array to keep tracklet words [mj] - Short_t fTrackletError; // tracklet error - Short_t fNTracklets; // number of tracklet - - // header word 0 - Int_t fSpecialRawV; // Raw data version - Int_t fRawVMajor; // Raw data version - Int_t fRawVMajorOpt; // Raw data version - Int_t fRawVMinor; // Raw data version - Int_t fNExtraWords; // N extra HC header words - Int_t fDCSboard; // DCS board number - Int_t fSM; // Super Module number - Int_t fStack; // Stack number (some people might call it a chamber) - Int_t fLayer; // Layer number (some people might call it a plane) - Int_t fSide; // Side of HC - - // header word 1 - Int_t fTimeBins; // N of t bins - UInt_t fBunchCrossCounter; // Bunch crossing counter - UInt_t fPreTriggerCounter; // Pre Trigger counter - UInt_t fPreTriggerPhase; // Pre Trigger phase - - // error - Int_t fH0Corrupted; // is hc header 0 corrupted - Int_t fH1Corrupted; // is hc header 1 corrupted - Int_t fCorrupted; // is hc data corrupted - - UInt_t *fPos[2]; //! position of the header words in buffer - - Int_t fDET; // filled while decoding - Int_t fROC; // filled while decoding - Int_t fRowMax; // filled while decoding - Int_t fColMax; // filled while decoding - - // hc data - Int_t fMCMmax; // number of mcm found - AliTRDrawMCM fMCMs[TRDMAXMCM]; // 4 ROBS 16 each - - AliTRDrawHC() - : fTrackletWords() //[mj] - , fTrackletError(0) - , fNTracklets(0) - , fSpecialRawV(0) - , fRawVMajor(0) - , fRawVMajorOpt(0) - , fRawVMinor(0) - , fNExtraWords(0) - , fDCSboard(-1) - , fSM(-1) - , fStack(-1) - , fLayer(-1) - , fSide(-1) - , fTimeBins(0) - , fBunchCrossCounter(0) - , fPreTriggerCounter(0) - , fPreTriggerPhase(0) - , fH0Corrupted(0) - , fH1Corrupted(0) - , fCorrupted(0) - , fPos() - , fDET(-1) - , fROC(-1) - , fRowMax(-1) - , fColMax(-1) - , fMCMmax(0) - , fMCMs() - { - // default constructor hc info - }; - - AliTRDrawHC(const AliTRDrawHC & p): - fTrackletWords() //[mj] - , fTrackletError(p.fTrackletError) - , fNTracklets(p.fNTracklets) - , fSpecialRawV(p.fSpecialRawV) - , fRawVMajor(p.fRawVMajor) - , fRawVMajorOpt(p.fRawVMajorOpt) - , fRawVMinor(p.fRawVMinor) - , fNExtraWords(p.fNExtraWords) - , fDCSboard(p.fDCSboard) - , fSM(p.fSM) - , fStack(p.fStack) - , fLayer(p.fLayer) - , fSide(p.fSide) - , fTimeBins(p.fTimeBins) - , fBunchCrossCounter(p.fBunchCrossCounter) - , fPreTriggerCounter(p.fPreTriggerCounter) - , fPreTriggerPhase(p.fPreTriggerPhase) - , fH0Corrupted(p.fH0Corrupted) - , fH1Corrupted(p.fH1Corrupted) - , fCorrupted(p.fCorrupted) - , fPos() - , fDET(p.fDET) - , fROC(p.fROC) - , fRowMax(p.fRowMax) - , fColMax(p.fColMax) - , fMCMmax(p.fMCMmax) - , fMCMs() - { - // copy constructor - }; - - AliTRDrawHC &operator=(const AliTRDrawHC &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - struct AliTRDrawStack - { - UInt_t fHeaderSize; // header size of the stack info - Bool_t fLinksActive[12]; // data links active - 1 per half chamber - Short_t fLinksDataType[12]; // 0 indicating real data for the front-end electronics - Short_t fLinksMonitor[12]; // 0 indicating properly operating link - Short_t fLinkMonitorError[12]; // record link monitor error - Int_t fActiveLinks; // number of active links - UInt_t *fPos; //! position in the buffer - - AliTRDrawHC fHalfChambers[12]; // 12 half chambers in a stack - - AliTRDrawStack() - : fHeaderSize(0) - , fLinksActive() - , fLinksDataType() - , fLinksMonitor() - , fLinkMonitorError() - , fActiveLinks(0) - , fPos(0) - , fHalfChambers() - { - // default constructor - }; - - AliTRDrawStack(const AliTRDrawStack & p): - fHeaderSize(p.fHeaderSize) - , fLinksActive() - , fLinksDataType() - , fLinksMonitor() - , fLinkMonitorError() - , fActiveLinks(p.fActiveLinks) - , fPos(p.fPos) - , fHalfChambers() - { - // copy constructor - }; - - AliTRDrawStack &operator=(const AliTRDrawStack &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - struct AliTRDrawSM - { - UInt_t fHeaderSize; // size of the header in words - Bool_t fTrackletEnable; // tracklet enable bit - Bool_t fStackActive[5]; // map of active/expected stacks - Int_t fActiveStacks; // number of active stacks - Int_t fCorrupted; // is sm info corrupted - Int_t fNexpectedHalfChambers; // number of half chambers to be read out in this sm - Bool_t fClean; // true if everything went OK - false is some error occured - UInt_t *fPos; // location of the sm info - should be the first word (after CDH if not DDL buffer) - - AliTRDrawStack fStacks[5]; // objects for 5 stacks - - AliTRDrawSM() - : fHeaderSize(0) - , fTrackletEnable(0) - , fStackActive() - , fActiveStacks(0) - , fCorrupted(0) - , fNexpectedHalfChambers(0) - , fClean(kTRUE) - , fPos(0) - , fStacks() - { - // Default constructor - }; - - AliTRDrawSM(const AliTRDrawSM & p): - fHeaderSize(p.fHeaderSize) - , fTrackletEnable(p.fTrackletEnable) - , fStackActive() - , fActiveStacks(p.fActiveStacks) - , fCorrupted(p.fCorrupted) - , fNexpectedHalfChambers(p.fNexpectedHalfChambers) - , fClean(p.fClean) - , fPos(p.fPos) - , fStacks() - { - // copy constructor - }; - - AliTRDrawSM &operator=(const AliTRDrawSM &) - { - // assignment operator - // not implemented - return *this; - }; - - }; - - //-------------------------------------------------------- - - AliTRDrawStream(); - AliTRDrawStream(AliRawReader *rawReader); - virtual ~AliTRDrawStream(); - - //-------------------------------------------------------- - - virtual Bool_t Next(); // read the next data in the memory - //virtual Int_t NextChamber(AliTRDdigitsManager *man); // read next chamber data in the momory - virtual Int_t NextChamber(AliTRDdigitsManager *man, UInt_t **trackletContainer, UShort_t **/*errorCodeContainer*/=NULL); // read next chamber data in the memory - virtual Bool_t Init(); // initialize some internal variables - - Int_t NextBuffer(); // go and init next buffer if available - check the implementation file for return values - - Bool_t SetRawVersion(Int_t fraw); // set the raw version - used for backward compat. - - Bool_t IsCurrentPadShared() const {return fADC->fIsShared;} // is current pad shared between mcms - void SetSharedPadReadout(Bool_t fv) {fSharedPadsOn = fv;} // set the flag on if the reader should return the shared pads - - Bool_t DecodeSM(void *buffer, UInt_t length); // decode a buffer - Int_t DecodeSM(); // used with raw reader - Int_t DecodeSM(AliRawReader *reader); // used with raw reader - - Bool_t SetReader(AliRawReader *reader); // set the raw reader to use - - // info from Supermodule Index Word - Bool_t IsTrackletEnableBitSet() const {return fSM.fTrackletEnable;} // get status of tracklet enable bit - Bool_t IsStackActive(Int_t is) const {return fSM.fStackActive[is];} // get status of stack enable bit - Int_t GetNofActiveStacks() const {return fSM.fActiveStacks;} // get number of active stacks from stack mask - UInt_t *GetGTUheaderWords() const {return fSM.fPos;} // get number of active stacks from stack mask - - // info from Stack Index Word - Int_t GetNexpectedHalfChambers() const {return fSM.fNexpectedHalfChambers;} // get number of expected HC in a sm - Int_t GetNofActiveLinksInStack(Int_t is) const {return fSM.fStacks[is].fActiveLinks;} // get number of active links in a stack - Bool_t IsLinkActiveInStack(Int_t is, Int_t il) const {return fSM.fStacks[is].fLinksActive[il];} // check whether the link is active - - // info from Stack Header Word - Short_t GetLinkMonitorError(Int_t is, Int_t il) const {return fSM.fStacks[is].fLinkMonitorError[il];} // get link monitor error - - // info from Tracklet Data - Int_t GetTrackletErrorCode(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fTrackletError;} - Int_t GetNTracklets(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fNTracklets;} // get number of tracklets - - // info from HC Header Word - Int_t GetSM(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fSM;} - Int_t GetLayer(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fLayer;} - Int_t GetStack(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fStack;} - Int_t GetSide(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fSide;} - Int_t GetH0ErrorCode(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fH0Corrupted;} - Int_t GetH1ErrorCode(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fH1Corrupted;} - Int_t GetNumberOfTimeBins(Int_t is, Int_t il) const { return fSM.fStacks[is].fHalfChambers[il].fTimeBins;} - UInt_t *GetTrackletWords(Int_t is, Int_t il) { return fSM.fStacks[is].fHalfChambers[il].fTrackletWords;} - - // info from HC data - Int_t GetHCErrorCode(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fCorrupted;} - Int_t GetHCMCMmax(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fMCMmax;} - - // from MCM Header Word - // rob and mcm ordering - // side 0(even link) - ROB: 0 2 4 6 MCM: 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3 - // side 1( odd link) - ROB: 1 3 5 7 MCM: 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3 - Int_t GetMCM(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fMCM;} - Int_t GetROB(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fROB;} - Int_t GetMCMhdErrorCode(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fMCMhdCorrupted;} - Int_t GetMCMADCMaskErrorCode(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCmaskCorrupted;} - Int_t GetEventNumber(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fEvCounter;} - Int_t GetADCcount(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCcount;} - - // info from MCM data words - Int_t GetMCMErrorCode(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fCorrupted;} // get MCM data error code - Int_t GetADCErrorCode(Int_t stack, Int_t link, Int_t mcm, Int_t adc) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fCorrupted;} // get ADC error code - Int_t GetADCnumber(Int_t stack, Int_t link, Int_t mcm, Int_t adc) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fADCnumber;} // get ADC error code - - Int_t GetRow(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fROW;} // get current row number - Int_t GetCol(Int_t stack, Int_t link, Int_t mcm, Int_t adc) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fCOL;} // get current column number - Int_t GetExtendedCol(Int_t stack, Int_t link, Int_t mcm, Int_t adc) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fExtendedCOL;} // get current column number - - // info from ADC data words - Int_t *GetSignalDirect(Int_t stack, Int_t link, Int_t mcm, Int_t adc) {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fSignals;} - - - // from here, only works with returning ADC channel pointer using Next() - UInt_t *GetTrackletWords() const { return fHC->fTrackletWords;} // return tracklet words pointer per hc [mj] - Int_t GetTrackletErrorCode() const {return fHC ? fHC->fTrackletError : -1;} // get tracklet error code - Int_t GetNTracklets() const {return fHC ? fHC->fNTracklets : -1;} // get number of tracklets - - Int_t GetSpecialRawVersion() const {return fHC ? fHC->fSpecialRawV : -1;} // return special raw version - Int_t GetMajorRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // major raw version getter - Int_t GetRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // compatibility see funtion above - Int_t GetMinorRawVersion() const {return fHC ? fHC->fRawVMinor : -1;} // minor raw version - - Int_t GetSM() const {return fHC ? fHC->fSM : -1;} // SM Position of CURRENT half chamber in full TRD - Int_t GetLayer() const {return fHC ? fHC->fLayer : -1;} // Layer Position of CURRENT half chamber in full TRD - Int_t GetStack() const {return fHC ? fHC->fStack : -1;} // Stack Position of CURRENT half chamber in full TRD - Int_t GetSide() const {return fHC ? fHC->fSide : -1;} // get side - Int_t GetDCS() const { return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header) - Int_t GetROC() const { return fHC ? fHC->fROC : -1;} // ROB Position of CURRENT half chamber in full TRD - Int_t GetNumberOfTimeBins() const { return fHC ? fHC->fTimeBins : 0;} // Get Ntime bins - UInt_t GetBunchCrossCounter() const {return fHC ? fHC->fBunchCrossCounter : 0;} // get bunch cross counter - UInt_t GetPreTriggerCounter() const {return fHC ? fHC->fPreTriggerCounter : 0;} // get pre trigger info - UInt_t GetPreTriggerPhase() const {return fHC ? fHC->fPreTriggerPhase : 0;} // get trigger phase - - Int_t GetRow() const {return fMCM ? fMCM->fROW : -1;} // get current row number - Int_t GetExtendedCol() const {return fADC ? fADC->fExtendedCOL : -1;} // get current column number - Int_t GetCol() const {return fADC ? fADC->fCOL : -1;} // get current column number - Int_t GetRowMax() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC - Int_t GetColMax() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC - // compatibility - Int_t GetMaxRow() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC - Int_t GetMaxCol() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC - - UInt_t GetHCword0() const {return fHC ? *fHC->fPos[0] : 0;} // get the HC word 0 - UInt_t GetHCword1() const {return fHC ? *fHC->fPos[1] : 0;} // get the HC word 1 - - Int_t GetDET() const {return fHC ? fHC->fDET : -1;} // get current det number - Int_t GetDet() const {return fHC ? fHC->fDET : -1;} // get current det number - - Int_t GetROB() const {return fMCM ? fMCM->fROB : -1;} // get current ROB number - Int_t GetMCM() const {return fMCM ? fMCM->fMCM : -1;} // get current MCM number - Int_t GetEventNumber() const { return fMCM->fEvCounter;} // MCM Event number and position of current MCM on TRD chamber - - Int_t GetADC() const { return fADC ? fADC->fADCnumber : -1;} // MCM ADC channel and Time Bin of word 1 - Int_t GetTimeBin() const { return 0;} // MCM ADC channel and Time Bin of word 1 - Int_t *GetSignals() const { return fADC ? fADC->fSignals : (Int_t *)fgEmptySignals;} // signals in the n-time bins from data word - - Int_t GetHCErrorCode() const {return fHC ? fHC->fCorrupted : -1;} // get HC error code - Int_t GetH0ErrorCode() const {return fHC ? fHC->fH0Corrupted : -1;} // get HC header word0 error code - Int_t GetH1ErrorCode() const {return fHC ? fHC->fH1Corrupted : -1;} // get HC header word1 error code - Int_t GetMCMErrorCode() const {return fMCM ? fMCM->fCorrupted : -1;} // get MCM data error code - Int_t GetADCErrorCode() const {return fADC ? fADC->fCorrupted : -1;} // get ADC data error code - Int_t GetMCMhdErrorCode() const {return fMCM ? fMCM->fMCMhdCorrupted: -1;} // get MCM header word error code - Int_t GetMCMADCMaskErrorCode() const {return fMCM ? fMCM->fADCmaskCorrupted: -1;} // get MCM adc mask error code - - UInt_t *GetSMstreamPosition() const {return fSM.fPos;} // get position of the SM index word in the buffer - - Bool_t IsSMbufferClean() const {return fSM.fClean;} // is data clean - - //---------------------------------------------------------- - - static void SetNoDebug() {fgDebugFlag = kFALSE;} // allow debug info - static void EnableMemoryReset() {fgEnableMemoryReset = kTRUE;} // allow memory reset - static void SetNoErrorWarning() {fgWarnError = kFALSE;} // disable warning and error info - static void SetForceCleanDataOnly() {fgCleanDataOnly = kTRUE;} // clean data only - static void AllowCorruptedData() {fgCleanDataOnly = kFALSE;} // accept corrupted data - - static void SetExtraWordsFix() {fgExtraSkip = kTRUE;} // extra skip of 24 32-bit words - static void SetSkipCDH() {fgSkipCDH = kTRUE;} // skip of 8 32-bit words - static void SetDumpHead(Int_t iv) {fgDumpHead = iv;} - static void DisableStackNumberChecker() {fgStackNumberChecker = kFALSE;} // set false to cleanroom data - static void DisableStackLinkNumberChecker() {fgStackLinkNumberChecker = kFALSE;} - static void DisableSkipData() {fgSkipData = kFALSE;} // keep reading next words even previous words were corrupted - debugging purpose - static void SetDumpingEnable() {fgDumpingEnable = kTRUE;} - static void SetDumpingMCM(Int_t sm, Int_t stack, Int_t layer, Int_t rob, Int_t mcm) {fgDumpingSM = sm; fgDumpingStack = stack; fgDumpingLayer = layer; fgDumpingROB = rob; fgDumpingMCM = mcm;} - - // this is a temporary solution! - // baseline should come with the HC header word 2 (count from 0!) - - static void EnableDecodeConfigData() {fgEnableDecodeConfigData = kTRUE;} // allow configuration data decoding - static Bool_t fgEnableDecodeConfigData; // flag to decode configuration data - - - //-------------------------------------------------------- - // Decoding functions - //-------------------------------------------------------- - - void DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const ; - const char *DumpSMInfo(const struct AliTRDrawSM *sm); - void DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const; - void DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const; - const char *DumpStackInfo(const struct AliTRDrawStack *st); - Bool_t DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const; - Bool_t DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const; - const char *DumpHCinfoH0(const struct AliTRDrawHC *hc); - const char *DumpHCinfoH1(const struct AliTRDrawHC *hc); - void DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const; - UInt_t GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const; - void DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const; - void MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const; - const char *DumpMCMinfo(const struct AliTRDrawMCM *mcm); - const char *DumpMCMadcMask(const struct AliTRDrawMCM *mcm); - - - protected: - - Bool_t InitBuffer(void *buffer, UInt_t length); // init the buffer - called by DecodeSM(void*, UInt_t) - Bool_t DumpWords(UInt_t *px, UInt_t iw, UInt_t marker = 0); // dump some words onto the screen - - void SwapOnEndian(); // swap if endian is BIG - Bool_t SkipWords(UInt_t iw); // skip number of words - Bool_t DecodeGTUheader(); // decode data in GTU header - Bool_t DecodeTracklets(); // decode tracklets - Bool_t DecodeHC(); // decode data in HC - - Bool_t DecodeADC(); // decode 10 ADC words - Bool_t DecodeADCExtended(); // decode TRAP data with ZS and more than 32 samples - - Bool_t DecodeHCheader(); // decode HC header - Bool_t SeekEndOfData(); // go to next end of raw data marker (actually 1 word after) - Bool_t SkipMCMdata(UInt_t iw); // skip this mcm data due to mcm header corruption - Bool_t SeekNextMCMheader(); // go to next mcm header - Bool_t DecodeMCMheader(); // decode mcm header - - Bool_t IsRowValid(); // check if row within the range - Bool_t IsHCheaderOK(); // check if current hc header data make sense - Bool_t IsMCMheaderOK(); // check if current mcm header data make sense - - void ResetCounters(); // reset some counters - void ResetIterators(); // needed for Next() - void ResetPerSM(); // reset every SM - void ResetPerStack(); // reset every Stack - void ResetPerHC(); // reset every HC - void ResetPerMCM(); // reset every MCM - void ResetPerADC(); // reset every ADC - void ResetMemory(); // reset all data members - - AliTRDrawStream(const AliTRDrawStream& st); - AliTRDrawStream &operator=(const AliTRDrawStream &); - - // ----------------- DATA MEMBERS START - - struct AliTRDrawSM fSM; // one SM per buffer - struct AliTRDrawStack *fStack; //! pointer to the current stack - struct AliTRDrawHC *fHC; //! current HC - struct AliTRDrawHC *fLastHC; //! last HC - struct AliTRDrawMCM *fMCM; //! current MCM - struct AliTRDrawADC *fADC; //! current ADC - - UInt_t *fpPos; // current position in the buffer - UInt_t *fpBegin; // begin - pointer to the buffer word 0 - UInt_t *fpEnd; // end of the buffer - - UInt_t fWordLength; // length of the buffer in 32bit words - - Bool_t fIsGlobalDigitsParamSet; // set true if the global digit parameters are already set - - Int_t fStackNumber; // current stack number - Int_t fStackLinkNumber; // current link in the stack - - Int_t fhcMCMcounter; // mcm counter inside single hc - used in Next() - Int_t fmcmADCcounter; // adc counrer inside single adc - used in Next() - - Int_t fLinkTrackletCounter; // count the tracklets in the current HC - Int_t fEndOfTrackletCount; // count link by link (hc by hc) used for debug - Int_t fNWordsCounter; // counts words of given hc having link monitor error - - UInt_t fMaskADCword; // temp mask when decoding adcs - UInt_t fTbinADC; // temp adc - Int_t fDecodedADCs; // counter of decoded adcs [mj] do we need? - - UInt_t fEventCounter; // stores the valid/current MCM event counter - UInt_t fLastEventCounter; // last known event counter of MCM - - Bool_t fSharedPadsOn; // do we want to output shared pads - default is off - Int_t fMaxADCgeom; // maximum ADC channels per mcm - - Bool_t fBufferRead; // set to be true if buffer is read for a given equipment - - AliTRDgeometry *fGeometry; //! TRD geometry - AliRawReader *fRawReader; //! raw reader - - AliTRDfeeParam *fTRDfeeParam; // pointer to the fee params - - // STATIC - - static Bool_t fgExtraSkip; // whether we should skip the leading 24 words - static Bool_t fgSkipCDH; // whether we should skip CDH (8 words) - static Bool_t fgWarnError; // no errors no warnings - static Bool_t fgCleanDataOnly; // release only clean events = no errors - static Bool_t fgDebugFlag; // allow debugging info - static Bool_t fgEnableMemoryReset; // allow memory reset - static Bool_t fgStackNumberChecker; // decide if we check stack number insanity - set false to cleanroom data - static Bool_t fgStackLinkNumberChecker; // decide if we check stack link number insanity - debuging purpose - static Bool_t fgSkipData; // decide if we skip corrupted data of given HC - static Int_t fgDumpHead; // number of words to dump (from the start of the buffer) on each Init - static Int_t fgEmptySignals[30]; // empty signals in case of ADC pointer = NULL - static Short_t fgMCMordering[16]; // mcm number odering for mcm header corruption check - static Short_t fgROBordering[16]; // mcm number odering for mcm header corruption check - static Int_t fgLastHC; // HC number indicator to check HC numbering - static Int_t fgLastROB; // ROB number indicator to check ROB numbering - static Int_t fgLastIndex; // variable to check mcm number odering - - static Bool_t fgDumpingEnable; // flag to dump MCM data words - - static Int_t fgDumpingSM; // sm number to dump MCM data words - static Int_t fgDumpingStack; // stack number to dump MCM data words - static Int_t fgDumpingLayer; // layer number to dump MCM data words - static Int_t fgDumpingROB; // rob number to dump MCM data words - static Int_t fgDumpingMCM; // mcm number to dump MCM data words - - // ----------------- DATA MEMBERS STOP - - enum ETRDzRawStreamError - { - kDecodeStackInfo = 1 // - , kMissingData = 2 // - , kLinkDataMissing = 3 // - , kHCdataMissing = 4 // - , kTrackletOverflow = 5 // - , kEOTrackeltsMissing = 6 // - , kWrongPadrow = 7 // - , kMCMheaderCorrupted = 8 // - , kWrongMCMorROB = 9 // - , kMCMeventMissmatch = 10 // - , kMCMADCMaskMissing = 11 // - , kHCHeaderCorrupt = 12 // - , kHCHeaderWrongStack = 13 // - , kHCHeaderWrongLayer = 14 // - , kHCHeaderWrongSide = 15 // - , kHCHeaderWrongSM = 16 // - , kHCHeaderWrongDet = 17 // - , kHCHeaderWrongROC = 18 // - , kHCWordMissing = 19 // - , kMCMdataMissing = 20 // - , kMCMoverflow = 21 // - , kADCdataMissing = 22 // - , kADCmaskMissmatch = 23 // - , kWrongPadcolumn = 24 // - }; - - ClassDef(AliTRDrawStream, 0) -}; //clas def end - -#endif +#ifndef ALITRDRAWSTREAM_H +#define ALITRDRAWSTREAM_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id: AliTRDrawStream.h 27696 2008-07-31 09:18:53Z cblume $ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This class provides access to TRD digits in raw data. // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include "AliTRDrawStreamBase.h" + +class AliTRDgeometry; +class AliRawReader; +class AliTRDdigitsManager; +class TTreeSRedirector; +class AliTRDfeeParam; + + +class AliTRDrawStream : public AliTRDrawStreamBase +{ // class def begin + + public: + + //-------------------------------------------------------- + // THE STRUCTURES + //-------------------------------------------------------- + + struct AliTRDrawADC + {//adc struct + + UInt_t *fPos; //! position of ADC 1st word in the buffer + Short_t fADCnumber; // number of the ADC 0 .. 20 + Short_t fExtendedCOL; // column - row from MCM + Short_t fCOL; // column - row from MCM + Int_t fSignals[TRDMAXTBINS]; // signals for this adc + Bool_t fIsShared; // is pad chared between MCMs + Short_t fCorrupted; // is adc word corrupted + + AliTRDrawADC() + : fPos(0) + , fADCnumber(0) + , fExtendedCOL(0) + , fCOL(0) + , fSignals() + , fIsShared(kFALSE) + , fCorrupted(0) + { + // default constructor + }; + + AliTRDrawADC(const AliTRDrawADC& p): + fPos(p.fPos) + , fADCnumber(p.fADCnumber) + , fExtendedCOL(p.fExtendedCOL) + , fCOL(p.fCOL) + , fSignals() + , fIsShared(p.fIsShared) + , fCorrupted(p.fCorrupted) + { + // copy constructor + }; + + AliTRDrawADC &operator=(const AliTRDrawADC &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + struct AliTRDrawMCM + { // mcm struct + Int_t fROB; // ROB number + Int_t fMCM; // MCM number + Int_t fROW; // row number filed during decoding + + UInt_t fEvCounter; // MCM event counter + UInt_t fADCMask; // ADC mask + UInt_t fADCMaskWord; // word with ADC mask in + UInt_t fADCchannel[TRDMAXADC]; // channels to be decoded accrording to ADC mask + + Int_t fADCmax; // number of ADCs fired + Int_t fADCcount; // number of ADCs fired from double checking bit + Int_t fMCMADCWords; // mcm words to expect + Int_t fSingleADCwords; // n of words per ADC + + Int_t fMCMhdCorrupted; // is mcm header corrupted + Int_t fADCmaskCorrupted; // is mcm adc mask corrupted + Int_t fCorrupted; // is mcm data missing + + UInt_t *fPos; //! position of mcm header in the buffer + UInt_t *fAdcDataPos; //! start of ADC data for this mcm + + Int_t fADCcounter; // count the adcs decoded + AliTRDrawADC fADCs[TRDMAXADC]; // 21 adcs + + AliTRDrawMCM() + : fROB(-1) + , fMCM(-1) + , fROW(-1) + , fEvCounter(0) + , fADCMask(0) + , fADCMaskWord(0) + , fADCchannel() + , fADCmax(0) + , fADCcount(0) + , fMCMADCWords(0) + , fSingleADCwords(0) + , fMCMhdCorrupted(0) + , fADCmaskCorrupted(0) + , fCorrupted(0) + , fPos(0) + , fAdcDataPos(0) + , fADCcounter(0) + , fADCs() + { + // default constructor + }; + + AliTRDrawMCM(const AliTRDrawMCM & p): + fROB(p.fROB) + , fMCM(p.fMCM) + , fROW(p.fROW) + , fEvCounter(p.fEvCounter) + , fADCMask(p.fADCMask) + , fADCMaskWord(p.fADCMaskWord) + , fADCchannel() + , fADCmax(p.fADCmax) + , fADCcount(p.fADCcount) + , fMCMADCWords(p.fMCMADCWords) + , fSingleADCwords(p.fSingleADCwords) + , fMCMhdCorrupted(p.fMCMhdCorrupted) + , fADCmaskCorrupted(p.fADCmaskCorrupted) + , fCorrupted(p.fCorrupted) + , fPos(p.fPos) + , fAdcDataPos(p.fAdcDataPos) + , fADCcounter(p.fADCcounter) + , fADCs() + { + // copy constructor + }; + + AliTRDrawMCM &operator=(const AliTRDrawMCM &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + struct AliTRDrawHC + { // hc struct + + //tacklet words of given HC + UInt_t fTrackletWords[MAXTRACKLETSPERHC]; // array to keep tracklet words [mj] + Short_t fTrackletError; // tracklet error + Short_t fNTracklets; // number of tracklet + + // header word 0 + Int_t fSpecialRawV; // Raw data version + Int_t fRawVMajor; // Raw data version + Int_t fRawVMajorOpt; // Raw data version + Int_t fRawVMinor; // Raw data version + Int_t fNExtraWords; // N extra HC header words + Int_t fDCSboard; // DCS board number + Int_t fSM; // Super Module number + Int_t fStack; // Stack number (some people might call it a chamber) + Int_t fLayer; // Layer number (some people might call it a plane) + Int_t fSide; // Side of HC + + // header word 1 + Int_t fTimeBins; // N of t bins + UInt_t fBunchCrossCounter; // Bunch crossing counter + UInt_t fPreTriggerCounter; // Pre Trigger counter + UInt_t fPreTriggerPhase; // Pre Trigger phase + + // error + Int_t fH0Corrupted; // is hc header 0 corrupted + Int_t fH1Corrupted; // is hc header 1 corrupted + Int_t fCorrupted; // is hc data corrupted + + UInt_t *fPos[2]; //! position of the header words in buffer + + Int_t fDET; // filled while decoding + Int_t fROC; // filled while decoding + Int_t fRowMax; // filled while decoding + Int_t fColMax; // filled while decoding + + // hc data + Int_t fMCMmax; // number of mcm found + AliTRDrawMCM fMCMs[TRDMAXMCM]; // 4 ROBS 16 each + + AliTRDrawHC() + : fTrackletWords() //[mj] + , fTrackletError(0) + , fNTracklets(0) + , fSpecialRawV(0) + , fRawVMajor(0) + , fRawVMajorOpt(0) + , fRawVMinor(0) + , fNExtraWords(0) + , fDCSboard(-1) + , fSM(-1) + , fStack(-1) + , fLayer(-1) + , fSide(-1) + , fTimeBins(0) + , fBunchCrossCounter(0) + , fPreTriggerCounter(0) + , fPreTriggerPhase(0) + , fH0Corrupted(0) + , fH1Corrupted(0) + , fCorrupted(0) + , fPos() + , fDET(-1) + , fROC(-1) + , fRowMax(-1) + , fColMax(-1) + , fMCMmax(0) + , fMCMs() + { + // default constructor hc info + }; + + AliTRDrawHC(const AliTRDrawHC & p): + fTrackletWords() //[mj] + , fTrackletError(p.fTrackletError) + , fNTracklets(p.fNTracklets) + , fSpecialRawV(p.fSpecialRawV) + , fRawVMajor(p.fRawVMajor) + , fRawVMajorOpt(p.fRawVMajorOpt) + , fRawVMinor(p.fRawVMinor) + , fNExtraWords(p.fNExtraWords) + , fDCSboard(p.fDCSboard) + , fSM(p.fSM) + , fStack(p.fStack) + , fLayer(p.fLayer) + , fSide(p.fSide) + , fTimeBins(p.fTimeBins) + , fBunchCrossCounter(p.fBunchCrossCounter) + , fPreTriggerCounter(p.fPreTriggerCounter) + , fPreTriggerPhase(p.fPreTriggerPhase) + , fH0Corrupted(p.fH0Corrupted) + , fH1Corrupted(p.fH1Corrupted) + , fCorrupted(p.fCorrupted) + , fPos() + , fDET(p.fDET) + , fROC(p.fROC) + , fRowMax(p.fRowMax) + , fColMax(p.fColMax) + , fMCMmax(p.fMCMmax) + , fMCMs() + { + // copy constructor + }; + + AliTRDrawHC &operator=(const AliTRDrawHC &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + struct AliTRDrawStack + { + UInt_t fHeaderSize; // header size of the stack info + Bool_t fLinksActive[12]; // data links active - 1 per half chamber + Short_t fLinksDataType[12]; // 0 indicating real data for the front-end electronics + Short_t fLinksMonitor[12]; // 0 indicating properly operating link + Short_t fLinkMonitorError[12]; // record link monitor error + Int_t fActiveLinks; // number of active links + UInt_t *fPos; //! position in the buffer + + AliTRDrawHC fHalfChambers[12]; // 12 half chambers in a stack + + AliTRDrawStack() + : fHeaderSize(0) + , fLinksActive() + , fLinksDataType() + , fLinksMonitor() + , fLinkMonitorError() + , fActiveLinks(0) + , fPos(0) + , fHalfChambers() + { + // default constructor + }; + + AliTRDrawStack(const AliTRDrawStack & p): + fHeaderSize(p.fHeaderSize) + , fLinksActive() + , fLinksDataType() + , fLinksMonitor() + , fLinkMonitorError() + , fActiveLinks(p.fActiveLinks) + , fPos(p.fPos) + , fHalfChambers() + { + // copy constructor + }; + + AliTRDrawStack &operator=(const AliTRDrawStack &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + struct AliTRDrawSM + { + UInt_t fHeaderSize; // size of the header in words + Bool_t fTrackletEnable; // tracklet enable bit + Bool_t fStackActive[5]; // map of active/expected stacks + Int_t fActiveStacks; // number of active stacks + Int_t fCorrupted; // is sm info corrupted + Int_t fNexpectedHalfChambers; // number of half chambers to be read out in this sm + Bool_t fClean; // true if everything went OK - false is some error occured + UInt_t *fPos; // location of the sm info - should be the first word (after CDH if not DDL buffer) + + AliTRDrawStack fStacks[5]; // objects for 5 stacks + + AliTRDrawSM() + : fHeaderSize(0) + , fTrackletEnable(0) + , fStackActive() + , fActiveStacks(0) + , fCorrupted(0) + , fNexpectedHalfChambers(0) + , fClean(kTRUE) + , fPos(0) + , fStacks() + { + // Default constructor + }; + + AliTRDrawSM(const AliTRDrawSM & p): + fHeaderSize(p.fHeaderSize) + , fTrackletEnable(p.fTrackletEnable) + , fStackActive() + , fActiveStacks(p.fActiveStacks) + , fCorrupted(p.fCorrupted) + , fNexpectedHalfChambers(p.fNexpectedHalfChambers) + , fClean(p.fClean) + , fPos(p.fPos) + , fStacks() + { + // copy constructor + }; + + AliTRDrawSM &operator=(const AliTRDrawSM &) + { + // assignment operator + // not implemented + return *this; + }; + + }; + + //-------------------------------------------------------- + + AliTRDrawStream(); + AliTRDrawStream(AliRawReader *rawReader); + virtual ~AliTRDrawStream(); + + //-------------------------------------------------------- + + virtual Bool_t Next(); // read the next data in the memory + //virtual Int_t NextChamber(AliTRDdigitsManager *man); // read next chamber data in the momory + virtual Int_t NextChamber(AliTRDdigitsManager *man, UInt_t **trackletContainer, UShort_t **/*errorCodeContainer*/=NULL); // read next chamber data in the memory + virtual Bool_t Init(); // initialize some internal variables + + Int_t NextBuffer(); // go and init next buffer if available - check the implementation file for return values + + Bool_t SetRawVersion(Int_t fraw); // set the raw version - used for backward compat. + + Bool_t IsCurrentPadShared() const {return fADC->fIsShared;} // is current pad shared between mcms + void SetSharedPadReadout(Bool_t fv) {fSharedPadsOn = fv;} // set the flag on if the reader should return the shared pads + + Bool_t DecodeSM(void *buffer, UInt_t length); // decode a buffer + Int_t DecodeSM(); // used with raw reader + Int_t DecodeSM(AliRawReader *reader); // used with raw reader + + Bool_t SetReader(AliRawReader *reader); // set the raw reader to use + + // info from Supermodule Index Word + Bool_t IsTrackletEnableBitSet() const {return fSM.fTrackletEnable;} // get status of tracklet enable bit + Bool_t IsStackActive(Int_t is) const {return fSM.fStackActive[is];} // get status of stack enable bit + Int_t GetNofActiveStacks() const {return fSM.fActiveStacks;} // get number of active stacks from stack mask + UInt_t *GetGTUheaderWords() const {return fSM.fPos;} // get number of active stacks from stack mask + + // info from Stack Index Word + Int_t GetNexpectedHalfChambers() const {return fSM.fNexpectedHalfChambers;} // get number of expected HC in a sm + Int_t GetNofActiveLinksInStack(Int_t is) const {return fSM.fStacks[is].fActiveLinks;} // get number of active links in a stack + Bool_t IsLinkActiveInStack(Int_t is, Int_t il) const {return fSM.fStacks[is].fLinksActive[il];} // check whether the link is active + + // info from Stack Header Word + Short_t GetLinkMonitorError(Int_t is, Int_t il) const {return fSM.fStacks[is].fLinkMonitorError[il];} // get link monitor error + + // info from Tracklet Data + Int_t GetTrackletErrorCode(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fTrackletError;} + Int_t GetNTracklets(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fNTracklets;} // get number of tracklets + + // info from HC Header Word + Int_t GetSM(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fSM;} + Int_t GetLayer(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fLayer;} + Int_t GetStack(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fStack;} + Int_t GetSide(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fSide;} + Int_t GetH0ErrorCode(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fH0Corrupted;} + Int_t GetH1ErrorCode(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fH1Corrupted;} + Int_t GetNumberOfTimeBins(Int_t is, Int_t il) const { return fSM.fStacks[is].fHalfChambers[il].fTimeBins;} + UInt_t *GetTrackletWords(Int_t is, Int_t il) { return fSM.fStacks[is].fHalfChambers[il].fTrackletWords;} + + // info from HC data + Int_t GetHCErrorCode(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fCorrupted;} + Int_t GetHCMCMmax(Int_t is, Int_t il) const {return fSM.fStacks[is].fHalfChambers[il].fMCMmax;} + + // from MCM Header Word + // rob and mcm ordering + // side 0(even link) - ROB: 0 2 4 6 MCM: 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3 + // side 1( odd link) - ROB: 1 3 5 7 MCM: 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3 + Int_t GetMCM(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fMCM;} + Int_t GetROB(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fROB;} + Int_t GetMCMhdErrorCode(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fMCMhdCorrupted;} + Int_t GetMCMADCMaskErrorCode(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCmaskCorrupted;} + Int_t GetEventNumber(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fEvCounter;} + Int_t GetADCcount(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCcount;} + + // info from MCM data words + Int_t GetMCMErrorCode(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fCorrupted;} // get MCM data error code + Int_t GetADCErrorCode(Int_t stack, Int_t link, Int_t mcm, Int_t adc) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fCorrupted;} // get ADC error code + Int_t GetADCnumber(Int_t stack, Int_t link, Int_t mcm, Int_t adc) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fADCnumber;} // get ADC error code + + Int_t GetRow(Int_t stack, Int_t link, Int_t mcm) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fROW;} // get current row number + Int_t GetCol(Int_t stack, Int_t link, Int_t mcm, Int_t adc) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fCOL;} // get current column number + Int_t GetExtendedCol(Int_t stack, Int_t link, Int_t mcm, Int_t adc) const {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fExtendedCOL;} // get current column number + + // info from ADC data words + Int_t *GetSignalDirect(Int_t stack, Int_t link, Int_t mcm, Int_t adc) {return fSM.fStacks[stack].fHalfChambers[link].fMCMs[mcm].fADCs[adc].fSignals;} + + + // from here, only works with returning ADC channel pointer using Next() + UInt_t *GetTrackletWords() const { return fHC->fTrackletWords;} // return tracklet words pointer per hc [mj] + Int_t GetTrackletErrorCode() const {return fHC ? fHC->fTrackletError : -1;} // get tracklet error code + Int_t GetNTracklets() const {return fHC ? fHC->fNTracklets : -1;} // get number of tracklets + + Int_t GetSpecialRawVersion() const {return fHC ? fHC->fSpecialRawV : -1;} // return special raw version + Int_t GetMajorRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // major raw version getter + Int_t GetRawVersion() const {return fHC ? fHC->fRawVMajor : -1;} // compatibility see funtion above + Int_t GetMinorRawVersion() const {return fHC ? fHC->fRawVMinor : -1;} // minor raw version + + Int_t GetSM() const {return fHC ? fHC->fSM : -1;} // SM Position of CURRENT half chamber in full TRD + Int_t GetLayer() const {return fHC ? fHC->fLayer : -1;} // Layer Position of CURRENT half chamber in full TRD + Int_t GetStack() const {return fHC ? fHC->fStack : -1;} // Stack Position of CURRENT half chamber in full TRD + Int_t GetSide() const {return fHC ? fHC->fSide : -1;} // get side + Int_t GetDCS() const { return fHC ? fHC->fDCSboard : -1;} // DCS board number read from data (HC header) + Int_t GetROC() const { return fHC ? fHC->fROC : -1;} // ROB Position of CURRENT half chamber in full TRD + Int_t GetNumberOfTimeBins() const { return fHC ? fHC->fTimeBins : 0;} // Get Ntime bins + UInt_t GetBunchCrossCounter() const {return fHC ? fHC->fBunchCrossCounter : 0;} // get bunch cross counter + UInt_t GetPreTriggerCounter() const {return fHC ? fHC->fPreTriggerCounter : 0;} // get pre trigger info + UInt_t GetPreTriggerPhase() const {return fHC ? fHC->fPreTriggerPhase : 0;} // get trigger phase + + Int_t GetRow() const {return fMCM ? fMCM->fROW : -1;} // get current row number + Int_t GetExtendedCol() const {return fADC ? fADC->fExtendedCOL : -1;} // get current column number + Int_t GetCol() const {return fADC ? fADC->fCOL : -1;} // get current column number + Int_t GetRowMax() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC + Int_t GetColMax() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC + // compatibility + Int_t GetMaxRow() const { return fHC ? fHC->fRowMax : -1;} // Get maximum rows in the current HC + Int_t GetMaxCol() const { return fHC ? fHC->fColMax : -1;} // Get maximum cols in the current HC + + UInt_t GetHCword0() const {return fHC ? *fHC->fPos[0] : 0;} // get the HC word 0 + UInt_t GetHCword1() const {return fHC ? *fHC->fPos[1] : 0;} // get the HC word 1 + + Int_t GetDET() const {return fHC ? fHC->fDET : -1;} // get current det number + Int_t GetDet() const {return fHC ? fHC->fDET : -1;} // get current det number + + Int_t GetROB() const {return fMCM ? fMCM->fROB : -1;} // get current ROB number + Int_t GetMCM() const {return fMCM ? fMCM->fMCM : -1;} // get current MCM number + Int_t GetEventNumber() const { return fMCM->fEvCounter;} // MCM Event number and position of current MCM on TRD chamber + + Int_t GetADC() const { return fADC ? fADC->fADCnumber : -1;} // MCM ADC channel and Time Bin of word 1 + Int_t GetTimeBin() const { return 0;} // MCM ADC channel and Time Bin of word 1 + Int_t *GetSignals() const { return fADC ? fADC->fSignals : (Int_t *)fgEmptySignals;} // signals in the n-time bins from data word + + Int_t GetHCErrorCode() const {return fHC ? fHC->fCorrupted : -1;} // get HC error code + Int_t GetH0ErrorCode() const {return fHC ? fHC->fH0Corrupted : -1;} // get HC header word0 error code + Int_t GetH1ErrorCode() const {return fHC ? fHC->fH1Corrupted : -1;} // get HC header word1 error code + Int_t GetMCMErrorCode() const {return fMCM ? fMCM->fCorrupted : -1;} // get MCM data error code + Int_t GetADCErrorCode() const {return fADC ? fADC->fCorrupted : -1;} // get ADC data error code + Int_t GetMCMhdErrorCode() const {return fMCM ? fMCM->fMCMhdCorrupted: -1;} // get MCM header word error code + Int_t GetMCMADCMaskErrorCode() const {return fMCM ? fMCM->fADCmaskCorrupted: -1;} // get MCM adc mask error code + + UInt_t *GetSMstreamPosition() const {return fSM.fPos;} // get position of the SM index word in the buffer + + Bool_t IsSMbufferClean() const {return fSM.fClean;} // is data clean + + //---------------------------------------------------------- + + static void SetNoDebug() {fgDebugFlag = kFALSE;} // allow debug info + static void EnableMemoryReset() {fgEnableMemoryReset = kTRUE;} // allow memory reset + static void SetNoErrorWarning() {fgWarnError = kFALSE;} // disable warning and error info + static void SetForceCleanDataOnly() {fgCleanDataOnly = kTRUE;} // clean data only + static void AllowCorruptedData() {fgCleanDataOnly = kFALSE;} // accept corrupted data + + static void SetExtraWordsFix() {fgExtraSkip = kTRUE;} // extra skip of 24 32-bit words + static void SetSkipCDH() {fgSkipCDH = kTRUE;} // skip of 8 32-bit words + static void SetDumpHead(Int_t iv) {fgDumpHead = iv;} + static void DisableStackNumberChecker() {fgStackNumberChecker = kFALSE;} // set false to cleanroom data + static void DisableStackLinkNumberChecker() {fgStackLinkNumberChecker = kFALSE;} + static void DisableSkipData() {fgSkipData = kFALSE;} // keep reading next words even previous words were corrupted - debugging purpose + static void SetDumpingEnable() {fgDumpingEnable = kTRUE;} + static void SetDumpingMCM(Int_t sm, Int_t stack, Int_t layer, Int_t rob, Int_t mcm) {fgDumpingSM = sm; fgDumpingStack = stack; fgDumpingLayer = layer; fgDumpingROB = rob; fgDumpingMCM = mcm;} + + // this is a temporary solution! + // baseline should come with the HC header word 2 (count from 0!) + + static void EnableDecodeConfigData() {fgEnableDecodeConfigData = kTRUE;} // allow configuration data decoding + static Bool_t fgEnableDecodeConfigData; // flag to decode configuration data + + + //-------------------------------------------------------- + // Decoding functions + //-------------------------------------------------------- + + void DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const ; + const char *DumpSMInfo(const struct AliTRDrawSM *sm); + void DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const; + void DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const; + const char *DumpStackInfo(const struct AliTRDrawStack *st); + Bool_t DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const; + Bool_t DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const; + const char *DumpHCinfoH0(const struct AliTRDrawHC *hc); + const char *DumpHCinfoH1(const struct AliTRDrawHC *hc); + void DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const; + UInt_t GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const; + void DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const; + void MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const; + const char *DumpMCMinfo(const struct AliTRDrawMCM *mcm); + const char *DumpMCMadcMask(const struct AliTRDrawMCM *mcm); + + + protected: + + Bool_t InitBuffer(void *buffer, UInt_t length); // init the buffer - called by DecodeSM(void*, UInt_t) + Bool_t DumpWords(UInt_t *px, UInt_t iw, UInt_t marker = 0); // dump some words onto the screen + + void SwapOnEndian(); // swap if endian is BIG + Bool_t SkipWords(UInt_t iw); // skip number of words + Bool_t DecodeGTUheader(); // decode data in GTU header + Bool_t DecodeTracklets(); // decode tracklets + Bool_t DecodeHC(); // decode data in HC + + Bool_t DecodeADC(); // decode 10 ADC words + Bool_t DecodeADCExtended(); // decode TRAP data with ZS and more than 32 samples + + Bool_t DecodeHCheader(); // decode HC header + Bool_t SeekEndOfData(); // go to next end of raw data marker (actually 1 word after) + Bool_t SkipMCMdata(UInt_t iw); // skip this mcm data due to mcm header corruption + Bool_t SeekNextMCMheader(); // go to next mcm header + Bool_t DecodeMCMheader(); // decode mcm header + + Bool_t IsRowValid(); // check if row within the range + Bool_t IsHCheaderOK(); // check if current hc header data make sense + Bool_t IsMCMheaderOK(); // check if current mcm header data make sense + + void ResetCounters(); // reset some counters + void ResetIterators(); // needed for Next() + void ResetPerSM(); // reset every SM + void ResetPerStack(); // reset every Stack + void ResetPerHC(); // reset every HC + void ResetPerMCM(); // reset every MCM + void ResetPerADC(); // reset every ADC + void ResetMemory(); // reset all data members + + AliTRDrawStream(const AliTRDrawStream& st); + AliTRDrawStream &operator=(const AliTRDrawStream &); + + // ----------------- DATA MEMBERS START + + struct AliTRDrawSM fSM; // one SM per buffer + struct AliTRDrawStack *fStack; //! pointer to the current stack + struct AliTRDrawHC *fHC; //! current HC + struct AliTRDrawHC *fLastHC; //! last HC + struct AliTRDrawMCM *fMCM; //! current MCM + struct AliTRDrawADC *fADC; //! current ADC + + UInt_t *fpPos; // current position in the buffer + UInt_t *fpBegin; // begin - pointer to the buffer word 0 + UInt_t *fpEnd; // end of the buffer + + UInt_t fWordLength; // length of the buffer in 32bit words + + Bool_t fIsGlobalDigitsParamSet; // set true if the global digit parameters are already set + + Int_t fStackNumber; // current stack number + Int_t fStackLinkNumber; // current link in the stack + + Int_t fhcMCMcounter; // mcm counter inside single hc - used in Next() + Int_t fmcmADCcounter; // adc counrer inside single adc - used in Next() + + Int_t fLinkTrackletCounter; // count the tracklets in the current HC + Int_t fEndOfTrackletCount; // count link by link (hc by hc) used for debug + Int_t fNWordsCounter; // counts words of given hc having link monitor error + + UInt_t fMaskADCword; // temp mask when decoding adcs + UInt_t fTbinADC; // temp adc + Int_t fDecodedADCs; // counter of decoded adcs [mj] do we need? + + UInt_t fEventCounter; // stores the valid/current MCM event counter + UInt_t fLastEventCounter; // last known event counter of MCM + + Bool_t fSharedPadsOn; // do we want to output shared pads - default is off + Int_t fMaxADCgeom; // maximum ADC channels per mcm + + Bool_t fBufferRead; // set to be true if buffer is read for a given equipment + + AliTRDgeometry *fGeometry; //! TRD geometry + AliRawReader *fRawReader; //! raw reader + + AliTRDfeeParam *fTRDfeeParam; // pointer to the fee params + Int_t fCommonAdditive; + + // STATIC + + static Bool_t fgExtraSkip; // whether we should skip the leading 24 words + static Bool_t fgSkipCDH; // whether we should skip CDH (8 words) + static Bool_t fgWarnError; // no errors no warnings + static Bool_t fgCleanDataOnly; // release only clean events = no errors + static Bool_t fgDebugFlag; // allow debugging info + static Bool_t fgEnableMemoryReset; // allow memory reset + static Bool_t fgStackNumberChecker; // decide if we check stack number insanity - set false to cleanroom data + static Bool_t fgStackLinkNumberChecker; // decide if we check stack link number insanity - debuging purpose + static Bool_t fgSkipData; // decide if we skip corrupted data of given HC + static Int_t fgDumpHead; // number of words to dump (from the start of the buffer) on each Init + static Int_t fgEmptySignals[30]; // empty signals in case of ADC pointer = NULL + static Short_t fgMCMordering[16]; // mcm number odering for mcm header corruption check + static Short_t fgROBordering[16]; // mcm number odering for mcm header corruption check + static Int_t fgLastHC; // HC number indicator to check HC numbering + static Int_t fgLastROB; // ROB number indicator to check ROB numbering + static Int_t fgLastIndex; // variable to check mcm number odering + + static Bool_t fgDumpingEnable; // flag to dump MCM data words + + static Int_t fgDumpingSM; // sm number to dump MCM data words + static Int_t fgDumpingStack; // stack number to dump MCM data words + static Int_t fgDumpingLayer; // layer number to dump MCM data words + static Int_t fgDumpingROB; // rob number to dump MCM data words + static Int_t fgDumpingMCM; // mcm number to dump MCM data words + + // ----------------- DATA MEMBERS STOP + + enum ETRDzRawStreamError + { + kDecodeStackInfo = 1 // + , kMissingData = 2 // + , kLinkDataMissing = 3 // + , kHCdataMissing = 4 // + , kTrackletOverflow = 5 // + , kEOTrackeltsMissing = 6 // + , kWrongPadrow = 7 // + , kMCMheaderCorrupted = 8 // + , kWrongMCMorROB = 9 // + , kMCMeventMissmatch = 10 // + , kMCMADCMaskMissing = 11 // + , kHCHeaderCorrupt = 12 // + , kHCHeaderWrongStack = 13 // + , kHCHeaderWrongLayer = 14 // + , kHCHeaderWrongSide = 15 // + , kHCHeaderWrongSM = 16 // + , kHCHeaderWrongDet = 17 // + , kHCHeaderWrongROC = 18 // + , kHCWordMissing = 19 // + , kMCMdataMissing = 20 // + , kMCMoverflow = 21 // + , kADCdataMissing = 22 // + , kADCmaskMissmatch = 23 // + , kWrongPadcolumn = 24 // + }; + + ClassDef(AliTRDrawStream, 0) +}; //clas def end + +#endif diff --git a/TRD/AliTRDrawStreamBase.cxx b/TRD/AliTRDrawStreamBase.cxx index ced5191891c..e28b6c7ad9e 100644 --- a/TRD/AliTRDrawStreamBase.cxx +++ b/TRD/AliTRDrawStreamBase.cxx @@ -1,154 +1,153 @@ -/************************************************************************** - * 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: AliTRDrawStreamBase.cxx 23387 2008-01-17 17:25:16Z cblume $ */ - -/////////////////////////////////////////////////////////////////////////////// -// // -// This class defines 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) // -// // -/////////////////////////////////////////////////////////////////////////////// - -#include "AliTRDrawStream.h" -#include "AliTRDrawFastStream.h" - -#include "AliTRDrawStreamBase.h" - -//-------------------------------------------------------- -ClassImp(AliTRDrawStreamBase) - -Int_t AliTRDrawStreamBase::fgRawStreamVersion = AliTRDrawStreamBase::kTRDrealStream; -Int_t AliTRDrawStreamBase::fgCommonAdditive = 0; - -//_____________________________________________________________________________ -AliTRDrawStreamBase::AliTRDrawStreamBase() - : TObject() -{ - // - // this is just for API - // - ; -} - -//_____________________________________________________________________________ -AliTRDrawStreamBase::AliTRDrawStreamBase(AliRawReader */*rawReader*/) - : TObject() -{ - // - // this is just for API - // - ; -} - -//_____________________________________________________________________________ -AliTRDrawStreamBase::AliTRDrawStreamBase(const AliTRDrawStreamBase& /*st*/) - : TObject() -{ - // - // copy - // - TRD_NOIMP(); - ; -} - -//_____________________________________________________________________________ -AliTRDrawStreamBase::~AliTRDrawStreamBase() -{ - // - // destructor - // - ; -} - -//_____________________________________________________________________________ -AliTRDrawStreamBase & -AliTRDrawStreamBase::operator=(const AliTRDrawStreamBase &) -{ - // - // we are not using this functionality - // - TRD_NOIMP(); - return *this; -} - -//_____________________________________________________________________________ -AliTRDrawStreamBase *AliTRDrawStreamBase::GetRawStream() -{ - // - // Returns the selected raw stream implementation - // - - if (fgRawStreamVersion == kTRDrealStream) - return new AliTRDrawStream(); - - if (fgRawStreamVersion == kTRDsimStream) - return new AliTRDrawStream(); - - if (fgRawStreamVersion == kTRDfastStream) - return new AliTRDrawFastStream(); - - return new AliTRDrawStreamBase; -} - -//_____________________________________________________________________________ -AliTRDrawStreamBase *AliTRDrawStreamBase::GetRawStream(AliRawReader *reader) -{ - // - // Returns the selected raw stream implementation - // - - if (fgRawStreamVersion == kTRDrealStream) - return new AliTRDrawStream(reader); - - if (fgRawStreamVersion == kTRDsimStream) - return new AliTRDrawStream(reader); - - - if (fgRawStreamVersion == kTRDfastStream){ - return new AliTRDrawFastStream(reader);} - - return new AliTRDrawStreamBase; -} - -//_____________________________________________________________________________ -void AliTRDrawStreamBase::SetRawStreamVersion(const char *opt) -{ - // - // Sets the raw stream version - // - - fgRawStreamVersion = 0; - - if (strstr(opt, "sim" ) != 0 || strstr(opt, "SIM") != 0) - fgRawStreamVersion = kTRDsimStream; - - if (strstr(opt, "tb" ) != 0 || strstr(opt, "TB") != 0) - fgRawStreamVersion = kTRDrealStream; - - if (strstr(opt, "real" ) != 0 || strstr(opt, "REAL") != 0) - fgRawStreamVersion = kTRDrealStream; - - if (strstr(opt, "fast" ) != 0 || strstr(opt, "FAST") != 0) - fgRawStreamVersion = kTRDfastStream; - -} - +/************************************************************************** + * 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: AliTRDrawStreamBase.cxx 23387 2008-01-17 17:25:16Z cblume $ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This class defines 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) // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include "AliTRDrawStream.h" +#include "AliTRDrawFastStream.h" + +#include "AliTRDrawStreamBase.h" + +//-------------------------------------------------------- +ClassImp(AliTRDrawStreamBase) + +Int_t AliTRDrawStreamBase::fgRawStreamVersion = AliTRDrawStreamBase::kTRDrealStream; + +//_____________________________________________________________________________ +AliTRDrawStreamBase::AliTRDrawStreamBase() + : TObject() +{ + // + // this is just for API + // + ; +} + +//_____________________________________________________________________________ +AliTRDrawStreamBase::AliTRDrawStreamBase(AliRawReader */*rawReader*/) + : TObject() +{ + // + // this is just for API + // + ; +} + +//_____________________________________________________________________________ +AliTRDrawStreamBase::AliTRDrawStreamBase(const AliTRDrawStreamBase& /*st*/) + : TObject() +{ + // + // copy + // + TRD_NOIMP(); + ; +} + +//_____________________________________________________________________________ +AliTRDrawStreamBase::~AliTRDrawStreamBase() +{ + // + // destructor + // + ; +} + +//_____________________________________________________________________________ +AliTRDrawStreamBase & +AliTRDrawStreamBase::operator=(const AliTRDrawStreamBase &) +{ + // + // we are not using this functionality + // + TRD_NOIMP(); + return *this; +} + +//_____________________________________________________________________________ +AliTRDrawStreamBase *AliTRDrawStreamBase::GetRawStream() +{ + // + // Returns the selected raw stream implementation + // + + if (fgRawStreamVersion == kTRDrealStream) + return new AliTRDrawStream(); + + if (fgRawStreamVersion == kTRDsimStream) + return new AliTRDrawStream(); + + if (fgRawStreamVersion == kTRDfastStream) + return new AliTRDrawFastStream(); + + return new AliTRDrawStreamBase; +} + +//_____________________________________________________________________________ +AliTRDrawStreamBase *AliTRDrawStreamBase::GetRawStream(AliRawReader *reader) +{ + // + // Returns the selected raw stream implementation + // + + if (fgRawStreamVersion == kTRDrealStream) + return new AliTRDrawStream(reader); + + if (fgRawStreamVersion == kTRDsimStream) + return new AliTRDrawStream(reader); + + + if (fgRawStreamVersion == kTRDfastStream){ + return new AliTRDrawFastStream(reader);} + + return new AliTRDrawStreamBase; +} + +//_____________________________________________________________________________ +void AliTRDrawStreamBase::SetRawStreamVersion(const char *opt) +{ + // + // Sets the raw stream version + // + + fgRawStreamVersion = 0; + + if (strstr(opt, "sim" ) != 0 || strstr(opt, "SIM") != 0) + fgRawStreamVersion = kTRDsimStream; + + if (strstr(opt, "tb" ) != 0 || strstr(opt, "TB") != 0) + fgRawStreamVersion = kTRDrealStream; + + if (strstr(opt, "real" ) != 0 || strstr(opt, "REAL") != 0) + fgRawStreamVersion = kTRDrealStream; + + if (strstr(opt, "fast" ) != 0 || strstr(opt, "FAST") != 0) + fgRawStreamVersion = kTRDfastStream; + +} + diff --git a/TRD/AliTRDrawStreamBase.h b/TRD/AliTRDrawStreamBase.h index 78e3b115a81..45acaef07a1 100644 --- a/TRD/AliTRDrawStreamBase.h +++ b/TRD/AliTRDrawStreamBase.h @@ -1,139 +1,134 @@ -#ifndef ALITRDRAWSTREAMBASE_H -#define ALITRDRAWSTREAMBASE_H - -/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * - * See cxx source for full Copyright notice */ - -/* $Id: AliTRDrawStreamBase.h 23387 2008-01-17 17:25:16Z cblume $ */ - -/////////////////////////////////////////////////////////////////////////////// -// // -// This base class defines access to TRD digits in raw data. // -// // -/////////////////////////////////////////////////////////////////////////////// - -#include "TObject.h" -#include "AliLog.h" - -class AliRawReader; -class AliTRDdigitsManager; - -#define TRDMAXTBINS 63 -#define TRDMAXADC 21 -#define TRDMAXMCM 4 * 16 -#define MAXTRACKLETSPERHC 256 - -#define TRD_NOIMP() AliFatal("Not Implemented for this class. Use inherited."); - -class AliTRDrawStreamBase : public TObject -{ // class def begin - - public: - - AliTRDrawStreamBase(); - AliTRDrawStreamBase(AliRawReader *rawReader); - virtual ~AliTRDrawStreamBase(); - - AliTRDrawStreamBase(const AliTRDrawStreamBase& st); - AliTRDrawStreamBase &operator=(const AliTRDrawStreamBase &); - - //-------------------------------------------------------- - - enum STREAMTYPE - { - kTRDsimStream = 0, - kTRDrealStream = 1, - kTRDfastStream = 2 - }; - - enum { kDDLOffset = 0x400 }; // Offset for DDL numbers - - static AliTRDrawStreamBase *GetRawStream(); - static AliTRDrawStreamBase *GetRawStream(AliRawReader *reader); - - static void SetRawStreamVersion(Int_t iver) { fgRawStreamVersion = iver; } - static void SetRawStreamVersion(const char *opt); - - // this is a temporary solution!^M - // baseline should come with the HC header word 2 (count from 0!)^M - static void SetSubtractBaseline(Int_t baseline) {fgCommonAdditive = baseline;} - - virtual Bool_t Next() {TRD_NOIMP(); return 0;} - //virtual Int_t NextChamber(AliTRDdigitsManager */*man*/) {TRD_NOIMP(); return 0;} - //virtual Int_t NextChamber(AliTRDdigitsManager */*man*/, UInt_t **/*trackletContainer*/=NULL) {TRD_NOIMP(); return 0;} - virtual Int_t NextChamber(AliTRDdigitsManager */*man*/, UInt_t **/*trackletContainer*/=NULL, UShort_t **/*errorCodeContainer*/=NULL) {TRD_NOIMP(); return 0;} - virtual Bool_t Init() {TRD_NOIMP(); return -1;} - - virtual Bool_t SetRawVersion(Int_t /*fraw*/) {TRD_NOIMP(); return 0;} - - virtual Bool_t IsCurrentPadShared() const {TRD_NOIMP(); return 0;} - virtual void SetSharedPadReadout(Bool_t /*fv*/) {TRD_NOIMP();} - virtual Bool_t IsDataZeroSuppressed() const {TRD_NOIMP(); return 0;} - - virtual Bool_t SetReader(AliRawReader */*reader*/) {TRD_NOIMP(); return 0;} - - virtual Bool_t IsTrackletEnableBitSet() const {TRD_NOIMP(); return 0;} - virtual Bool_t IsStackActive(Int_t /*is*/) const {TRD_NOIMP(); return 0;} - virtual Int_t GetNofActiveStacks() const {TRD_NOIMP(); return 0;} - virtual UInt_t *GetSMstreamPosition() const {TRD_NOIMP(); return 0;} - - virtual Bool_t IsSMbufferClean() const {TRD_NOIMP(); return 0;} - - virtual Bool_t IsLinkActiveInStack(Int_t /*is*/, Int_t /*il*/) const {TRD_NOIMP(); return 0;} - virtual Int_t GetActiveLinksInStack(Int_t /*is*/) const {TRD_NOIMP(); return 0;} - - virtual Int_t GetSpecialRawVersion() const {TRD_NOIMP(); return 0;} - virtual Int_t GetMajorRawVersion() const {TRD_NOIMP(); return 0;} - virtual Int_t GetRawVersion() const {TRD_NOIMP(); return 0;} - virtual Int_t GetMinorRawVersion() const {TRD_NOIMP(); return 0;} - - virtual Int_t GetSM() const {TRD_NOIMP(); return 0;} - virtual Int_t GetLayer() const {TRD_NOIMP(); return 0;} - virtual Int_t GetStack() const {TRD_NOIMP(); return 0;} - virtual Int_t GetSide() const {TRD_NOIMP(); return 0;} - virtual Int_t GetDCS() const {TRD_NOIMP(); return 0;} - - virtual Int_t GetROC() const {TRD_NOIMP(); return 0;} - virtual Int_t GetNumberOfTimeBins() const {TRD_NOIMP(); return 0;} - virtual UInt_t GetBunchCrossCounter() const {TRD_NOIMP(); return 0;} - virtual UInt_t GetPreTriggerCounter() const {TRD_NOIMP(); return 0;} - virtual UInt_t GetPreTriggerPhase() const {TRD_NOIMP(); return 0;} - - virtual Int_t GetRow() const {TRD_NOIMP(); return 0;} - virtual Int_t GetCol() const {TRD_NOIMP(); return 0;} - virtual Int_t GetRowMax() const {TRD_NOIMP(); return 0;} - virtual Int_t GetColMax() const {TRD_NOIMP(); return 0;} - - // compatibility - virtual Int_t GetMaxRow() const {TRD_NOIMP(); return 0;} - virtual Int_t GetMaxCol() const {TRD_NOIMP(); return 0;} - - virtual Int_t GetDET() const {TRD_NOIMP(); return 0;} - virtual Int_t GetDet() const {TRD_NOIMP(); return 0;} - - virtual Int_t GetROB() const {TRD_NOIMP(); return 0;} - virtual Int_t GetMCM() const {TRD_NOIMP(); return 0;} - virtual Int_t GetEventNumber() const {TRD_NOIMP(); return 0;} - virtual Int_t IsMCMcorrupted() const {TRD_NOIMP(); return 0;} - - virtual Int_t *GetSignals() const {TRD_NOIMP(); return 0;} - virtual Int_t GetADC() const {TRD_NOIMP(); return 0;} - virtual Int_t GetTimeBin() const {TRD_NOIMP(); return 0;} - - virtual Int_t GetCommonAdditive() const {TRD_NOIMP(); return 0;} - - //---------------------------------------------------------- - - protected: - - static Int_t fgCommonAdditive; // baseline to be subtracted - - private: - - static Int_t fgRawStreamVersion; // Raw stream version number - - ClassDef(AliTRDrawStreamBase, 0) // TRD raw stream base class - -}; //clas def end - -#endif +#ifndef ALITRDRAWSTREAMBASE_H +#define ALITRDRAWSTREAMBASE_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id: AliTRDrawStreamBase.h 23387 2008-01-17 17:25:16Z cblume $ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// This base class defines access to TRD digits in raw data. // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include "TObject.h" +#include "AliLog.h" + +class AliRawReader; +class AliTRDdigitsManager; + +#define TRDMAXTBINS 63 +#define TRDMAXADC 21 +#define TRDMAXMCM 4 * 16 +#define MAXTRACKLETSPERHC 256 + +#define TRD_NOIMP() AliFatal("Not Implemented for this class. Use inherited."); + +class AliTRDrawStreamBase : public TObject +{ // class def begin + + public: + + AliTRDrawStreamBase(); + AliTRDrawStreamBase(AliRawReader *rawReader); + virtual ~AliTRDrawStreamBase(); + + AliTRDrawStreamBase(const AliTRDrawStreamBase& st); + AliTRDrawStreamBase &operator=(const AliTRDrawStreamBase &); + + //-------------------------------------------------------- + + enum STREAMTYPE + { + kTRDsimStream = 0, + kTRDrealStream = 1, + kTRDfastStream = 2 + }; + + enum { kDDLOffset = 0x400 }; // Offset for DDL numbers + + static AliTRDrawStreamBase *GetRawStream(); + static AliTRDrawStreamBase *GetRawStream(AliRawReader *reader); + + static void SetRawStreamVersion(Int_t iver) { fgRawStreamVersion = iver; } + static void SetRawStreamVersion(const char *opt); + + // this is a temporary solution!^M + // baseline should come with the HC header word 2 (count from 0!)^M + + virtual Bool_t Next() {TRD_NOIMP(); return 0;} + //virtual Int_t NextChamber(AliTRDdigitsManager */*man*/) {TRD_NOIMP(); return 0;} + //virtual Int_t NextChamber(AliTRDdigitsManager */*man*/, UInt_t **/*trackletContainer*/=NULL) {TRD_NOIMP(); return 0;} + virtual Int_t NextChamber(AliTRDdigitsManager */*man*/, UInt_t **/*trackletContainer*/=NULL, UShort_t **/*errorCodeContainer*/=NULL) {TRD_NOIMP(); return 0;} + virtual Bool_t Init() {TRD_NOIMP(); return -1;} + + virtual Bool_t SetRawVersion(Int_t /*fraw*/) {TRD_NOIMP(); return 0;} + + virtual Bool_t IsCurrentPadShared() const {TRD_NOIMP(); return 0;} + virtual void SetSharedPadReadout(Bool_t /*fv*/) {TRD_NOIMP();} + virtual Bool_t IsDataZeroSuppressed() const {TRD_NOIMP(); return 0;} + + virtual Bool_t SetReader(AliRawReader */*reader*/) {TRD_NOIMP(); return 0;} + + virtual Bool_t IsTrackletEnableBitSet() const {TRD_NOIMP(); return 0;} + virtual Bool_t IsStackActive(Int_t /*is*/) const {TRD_NOIMP(); return 0;} + virtual Int_t GetNofActiveStacks() const {TRD_NOIMP(); return 0;} + virtual UInt_t *GetSMstreamPosition() const {TRD_NOIMP(); return 0;} + + virtual Bool_t IsSMbufferClean() const {TRD_NOIMP(); return 0;} + + virtual Bool_t IsLinkActiveInStack(Int_t /*is*/, Int_t /*il*/) const {TRD_NOIMP(); return 0;} + virtual Int_t GetActiveLinksInStack(Int_t /*is*/) const {TRD_NOIMP(); return 0;} + + virtual Int_t GetSpecialRawVersion() const {TRD_NOIMP(); return 0;} + virtual Int_t GetMajorRawVersion() const {TRD_NOIMP(); return 0;} + virtual Int_t GetRawVersion() const {TRD_NOIMP(); return 0;} + virtual Int_t GetMinorRawVersion() const {TRD_NOIMP(); return 0;} + + virtual Int_t GetSM() const {TRD_NOIMP(); return 0;} + virtual Int_t GetLayer() const {TRD_NOIMP(); return 0;} + virtual Int_t GetStack() const {TRD_NOIMP(); return 0;} + virtual Int_t GetSide() const {TRD_NOIMP(); return 0;} + virtual Int_t GetDCS() const {TRD_NOIMP(); return 0;} + + virtual Int_t GetROC() const {TRD_NOIMP(); return 0;} + virtual Int_t GetNumberOfTimeBins() const {TRD_NOIMP(); return 0;} + virtual UInt_t GetBunchCrossCounter() const {TRD_NOIMP(); return 0;} + virtual UInt_t GetPreTriggerCounter() const {TRD_NOIMP(); return 0;} + virtual UInt_t GetPreTriggerPhase() const {TRD_NOIMP(); return 0;} + + virtual Int_t GetRow() const {TRD_NOIMP(); return 0;} + virtual Int_t GetCol() const {TRD_NOIMP(); return 0;} + virtual Int_t GetRowMax() const {TRD_NOIMP(); return 0;} + virtual Int_t GetColMax() const {TRD_NOIMP(); return 0;} + + // compatibility + virtual Int_t GetMaxRow() const {TRD_NOIMP(); return 0;} + virtual Int_t GetMaxCol() const {TRD_NOIMP(); return 0;} + + virtual Int_t GetDET() const {TRD_NOIMP(); return 0;} + virtual Int_t GetDet() const {TRD_NOIMP(); return 0;} + + virtual Int_t GetROB() const {TRD_NOIMP(); return 0;} + virtual Int_t GetMCM() const {TRD_NOIMP(); return 0;} + virtual Int_t GetEventNumber() const {TRD_NOIMP(); return 0;} + virtual Int_t IsMCMcorrupted() const {TRD_NOIMP(); return 0;} + + virtual Int_t *GetSignals() const {TRD_NOIMP(); return 0;} + virtual Int_t GetADC() const {TRD_NOIMP(); return 0;} + virtual Int_t GetTimeBin() const {TRD_NOIMP(); return 0;} + + virtual Int_t GetCommonAdditive() const {TRD_NOIMP(); return 0;} + + //---------------------------------------------------------- + + private: + + static Int_t fgRawStreamVersion; // Raw stream version number + + ClassDef(AliTRDrawStreamBase, 0) // TRD raw stream base class + +}; //clas def end + +#endif -- 2.43.0