+ Int_t RecoDet = fRawRec ? 0 : det;
+
+ if (fUseDictionaries == kFALSE)
+ {
+ return;
+ }
+
+ for (Int_t i = 0; i < kNDict; i++)
+ {
+ if (fDict[i]->At(RecoDet))
+ {
+ AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(RecoDet);
+ delete arr;
+ }
+ }
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::RemoveIndexes(Int_t det)
+{
+ //
+ // Clear memory
+ //
+
+ Int_t RecoDet = fRawRec ? 0 : det;
+
+ if (fSignalIndexes->At(RecoDet))
+ {
+ AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(RecoDet);
+ delete arr;
+ }
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::ClearIndexes(Int_t det)
+{
+ //
+ // Clear memory
+ //
+
+ Int_t RecoDet = fRawRec ? 0 : det;
+
+ ((AliTRDSignalIndex *) fSignalIndexes->At(RecoDet))->ClearAll();
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
+{
+ //
+ // Build the list of indices
+ //
+
+ Int_t nRows = 0;
+ Int_t nCols = 0;
+ Int_t nTbins = 0;
+
+ AliTRDgeometry geom;
+ AliTRDarrayADC *digits = 0x0;
+
+ if (fHasSDigits)
+ {
+ return kFALSE;
+ }
+ else
+ {
+ digits = (AliTRDarrayADC *) GetDigits(det);
+ }
+
+ // digits should be expanded by now!!!
+ if (digits->GetNtime() > 0)
+ {
+ digits->Expand();
+ nRows = digits->GetNrow();
+ nCols = digits->GetNcol();
+ nTbins = digits->GetNtime();
+
+ AliTRDSignalIndex *indexes = GetIndexes(det);
+ indexes->SetSM(geom.GetSector(det));
+ indexes->SetStack(geom.GetStack(det));
+ indexes->SetLayer(geom.GetLayer(det));
+ indexes->SetDetNumber(det);
+
+ if (indexes->IsAllocated() == kFALSE)
+ {
+ indexes->Allocate(nRows,nCols,nTbins);
+ }
+
+ for (Int_t ir = 0; ir < nRows; ir++)
+ {
+ for (Int_t ic = 0; ic < nCols; ic++)
+ {
+ for (Int_t it = 0; it < nTbins; it++)
+ {
+ Int_t isig = digits->GetDataBits(ir,ic,it);
+ if (isig > 0)
+ {
+ indexes->AddIndexRC(ir,ic);
+ }
+ } // tbins
+ } // cols
+ } // rows
+
+ } // if GetNtime
+ else
+ {
+ return kFALSE;
+ }
+
+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::LoadArrayDigits()
+{
+ //
+ // Loads the (s-)digits arrays for all detectors
+ //
+
+ if (!fTree)
+ {
+ AliError("Digits tree is not defined\n");
+ return kFALSE;
+ }
+
+ Bool_t status = kTRUE;
+
+ // Get the branch
+ TBranch *branch = fTree->GetBranch("TRDdigits");
+ if (!branch)
+ {
+ AliError("Branch TRDdigits is not defined\n");
+ return kFALSE;
+ }
+
+ // Loop through all detectors and read them from the tree
+ for (Int_t iDet = 0; iDet < fDets; iDet++)
+ {
+ if (fHasSDigits)
+ {
+ AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
+ if (!dataArray)
+ {
+ status = kFALSE;
+ break;
+ }
+ branch->SetAddress(&dataArray);
+ branch->GetEntry(iDet);
+ }
+ else
+ {
+ AliTRDarrayADC *dataArray = (AliTRDarrayADC *) fDigits->At(iDet);
+ if (!dataArray)
+ {
+ status = kFALSE;
+ break;
+ }
+ branch->SetAddress(&dataArray);
+ branch->GetEntry(iDet);
+ }
+ }
+
+ return status;
+
+}
+
+//________________________________________________________________________________________________
+Bool_t AliTRDdigitsManager::LoadArrayDict()
+{
+ //
+ // Loads dictionary arrays for all detectors
+ //
+
+ if (!fTree)
+ {
+ AliError("Digits tree is not defined\n");
+ return kFALSE;
+ }
+
+ Bool_t status = kTRUE;
+
+ for (Int_t iDict = 0; iDict < kNDict; iDict++)
+ {
+
+ // Get the branch
+ Char_t branchname[15];
+ sprintf(branchname,"TRDdictionary%d",iDict);
+ TBranch *branch = fTree->GetBranch(branchname);
+ if (!branch)
+ {
+ AliError(Form("Branch %s is not defined\n",branchname));
+ return kFALSE;
+ }
+
+ // Loop through all detectors and read them from the tree
+ for (Int_t iDet = 0; iDet < fDets; iDet++)
+ {
+ AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
+ if (!dataArray)
+ {
+ status = kFALSE;
+ break;
+ }
+ branch->SetAddress(&dataArray);
+ branch->GetEntry(iDet);
+ }
+
+ }
+
+ return status;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::LoadDigitsParam()
+{
+ //
+ // Loads the digits parameter object from the digits tree
+ //
+
+ if (!fTree)
+ {
+ AliError("Digits tree is not defined\n");
+ return kFALSE;
+ }
+
+ // Get the branch
+ TBranch *branch = fTree->GetBranch("TRDdigitsParam");
+ if (!branch)
+ {
+ AliError("Branch TRDdigitsParam is not defined\n");
+ return kFALSE;
+ }
+
+ // Read the parameter object
+ AliTRDdigitsParam *digitsParam = fDigitsParam;
+ if (!digitsParam)
+ {
+ return kFALSE;
+ }
+
+ branch->SetAddress(&digitsParam);
+ branch->GetEntry();
+
+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::StoreArrayDigits()
+{
+ //
+ // Stores the digit arrays for all detectors
+ //
+
+ if (!fTree)
+ {
+ AliError("Digits tree is not defined\n");
+ return kFALSE;
+ }
+
+ // Get the branch
+ TBranch *branch = fTree->GetBranch("TRDdigits");
+ if (!branch)
+ {
+ AliError("Branch TRDdigits is not defined\n");
+ return kFALSE;
+ }
+
+ // Loop through all detectors and fill them into the tree
+ Bool_t status = kTRUE;
+ for (Int_t iDet = 0; iDet < fDets; iDet++)
+ {
+ if (fHasSDigits)
+ {
+ const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
+ if (!kDataArray)
+ {
+ status = kFALSE;
+ break;
+ }
+ branch->SetAddress(&kDataArray);
+ branch->Fill();
+ }
+ else
+ {
+ const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) fDigits->At(iDet);
+ if (!kDataArray)
+ {
+ status = kFALSE;
+ break;
+ }
+ branch->SetAddress(&kDataArray);
+ branch->Fill();
+ }
+ }
+
+ return status;