+
+//_____________________________________________________________________________
+AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
+ , Int_t col
+ , Int_t time
+ , Int_t det) const
+{
+ //
+ // Creates a single digit object
+ //
+
+ Int_t digits[4];
+ Int_t amp[1];
+
+ digits[0] = det;
+ digits[1] = row;
+ digits[2] = col;
+ digits[3] = time;
+
+ amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
+
+ return (new AliTRDdigit(digits,amp));
+
+}
+
+//_____________________________________________________________________________
+Int_t AliTRDdigitsManager::GetTrack(Int_t track
+ , Int_t row
+ , Int_t col
+ , Int_t time
+ , Int_t det) const
+{
+ //
+ // Returns the MC-track numbers from the dictionary.
+ //
+
+ if ((track < 0) || (track >= kNDict))
+ {
+ AliError(Form("track %d out of bounds (size: %d, this: 0x%p)",track,kNDict,this));
+ return -1;
+ }
+
+ if (fUseDictionaries == kFALSE)
+ {
+ return -1;
+ }
+
+ // Array contains index+1 to allow data compression--->Changed
+ return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
+
+}
+
+//________________________________________________________________________________
+AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
+{
+ //
+ // Returns the digits array for one detector
+ //
+
+ Int_t recoDet = fRawRec ? 0 : det;
+
+ if (!fDigits)
+ {
+ return 0x0;
+ }
+
+ if (!fHasSDigits)
+ {
+ ((AliTRDarrayADC *) fDigits->At(recoDet))->SetNdet(det);
+ return (AliTRDarrayADC *) fDigits->At(recoDet);
+ }
+ else
+ {
+ AliDebug(2,"ERROR IN DATA TYPE!!!!");
+ return 0x0;
+ }
+
+}
+
+//_____________________________________________________________________________
+AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
+{
+ //
+ // Returns the sdigits array for one detector
+ //
+
+ Int_t recoDet = fRawRec ? 0 : det;
+
+ if (!fDigits)
+ {
+ // AliDebug(1,"NO FDIGITS!");
+ return 0x0;
+ }
+
+ if (fHasSDigits)
+ {
+ ((AliTRDarraySignal *) fDigits->At(recoDet))->SetNdet(det);
+ return (AliTRDarraySignal *) fDigits->At(recoDet);
+ }
+ else
+ {
+ AliDebug(2,"ERROR IN DATA TYPE!!!!");
+ return 0x0;
+ }
+
+}
+
+//_____________________________________________________________________________
+AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
+ , Int_t i) const
+{
+ //
+ // Returns the dictionary for one detector
+ //
+
+ Int_t recoDet = fRawRec ? 0 : det;
+
+ if (fUseDictionaries == kFALSE)
+ {
+ return 0x0;
+ }
+
+ ((AliTRDarrayDictionary *) fDigits->At(recoDet))->SetNdet(det);
+ return (AliTRDarrayDictionary *) fDict[i]->At(recoDet);
+
+}
+
+//_____________________________________________________________________________
+Int_t AliTRDdigitsManager::GetTrack(Int_t track, const AliTRDdigit * const digit) const
+{
+ //
+ // Returns the MC-track numbers from the dictionary for a given digit
+ //
+
+ Int_t row = digit->GetRow();
+ Int_t col = digit->GetCol();
+ Int_t time = digit->GetTime();
+ Int_t det = digit->GetDetector();
+
+ return GetTrack(track,row,col,time,det);
+
+}
+
+//_____________________________________________________________________________
+AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
+{
+ //
+ // Returns indexes of active pads
+ //
+
+ Int_t recoDet = fRawRec ? 0 : det;
+
+ return (AliTRDSignalIndex *) fSignalIndexes->At(recoDet);
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::RemoveDigits(Int_t det)
+{
+ //
+ // Clear memory at det for Digits
+ //
+
+ Int_t recoDet = fRawRec ? 0 : det;
+
+ if (fDigits->At(recoDet))
+ {
+ if (fHasSDigits)
+ {
+ AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(recoDet);
+ delete arr;
+ }
+ else
+ {
+ AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(recoDet);
+ delete arr;
+ }
+ }
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
+{
+ //
+ // Clear memory
+ //
+
+ 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];
+ snprintf(branchname,15,"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;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::StoreArrayDict()
+{
+ //
+ // Stores the 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];
+ snprintf(branchname,15,"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 fill them into the tree
+ for (Int_t iDet = 0; iDet < fDets; iDet++)
+ {
+ const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
+ if (!kDataArray)
+ {
+ status = kFALSE;
+ break;
+ }
+ branch->SetAddress(&kDataArray);
+ branch->Fill();
+ }
+
+ }
+
+ return status;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::StoreDigitsParam()
+{
+ //
+ // Stores 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;
+ }
+
+ // Fill the digits object in the tree
+ const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
+ if (!kDigitsParam)
+ {
+ return kFALSE;
+ }
+ branch->SetAddress(&kDigitsParam);
+ branch->Fill();
+
+ return kTRUE;
+
+}
+