]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdigitsManager.cxx
Put 0.1 as minimal value of the gas gain (Raphaelle)
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
index 606d2a9ed6a578c76a5cfef1ec84b82d8faef97e..048ee25067965450564648d1fc664ae3005156f5 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.5  2000/06/09 11:10:07  cblume
-Compiler warnings and coding conventions, next round
-
-Revision 1.4  2000/06/08 18:32:58  cblume
-Make code compliant to coding conventions
-
-Revision 1.3  2000/06/07 16:27:01  cblume
-Try to remove compiler warnings on Sun and HP
-
-Revision 1.2  2000/05/08 16:17:27  cblume
-Merge TRD-develop
-
-Revision 1.1.2.1  2000/05/08 14:44:01  cblume
-Add new class AliTRDdigitsManager
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
 //  Manages the digits and the track dictionary in the form of               //
-//  AliTRDdataArray objects.                                                 //
+//  TObjArray objects                                                        //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <TTree.h>
+#include <TTree.h>                                                              
 
-#include "AliRun.h"
+#include "AliLog.h"
 
 #include "AliTRDdigitsManager.h"
-#include "AliTRDconst.h"
+#include "AliTRDarrayDictionary.h"
+#include "AliTRDarrayADC.h"
+#include "AliTRDarraySignal.h"
+#include "AliTRDdigit.h"
+#include "AliTRDdigitsParam.h"
+#include "AliTRDSimParam.h"
+#include "AliTRDgeometry.h"
+#include "AliTRDSignalIndex.h"
 
 ClassImp(AliTRDdigitsManager)
 
 //_____________________________________________________________________________
-AliTRDdigitsManager::AliTRDdigitsManager():TObject()
+
+  // Number of track dictionary arrays
+  const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
+
+//_____________________________________________________________________________
+AliTRDdigitsManager::AliTRDdigitsManager(Bool_t rawRec)
+  :TObject()
+  ,fEvent(0)
+  ,fTree(0)
+  ,fDigits(0) 
+  ,fHasSDigits(0)
+  ,fSignalIndexes(NULL)
+  ,fUseDictionaries(kTRUE)
+  ,fDets(AliTRDgeometry::Ndet())
+  ,fRawRec(rawRec)
+  ,fDigitsParam(0)
 {
   //
   // Default constructor
   //
+  
+  if (fRawRec)
+    {
+      fDets   = 1;
+      fRawRec = kTRUE;
+    }
 
-  fIsRaw = kFALSE;
-
-  fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",kNdet);
-
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI",kNdet);
-  }
-
+  for (Int_t iDict = 0; iDict < kNDict; iDict++) 
+    {
+      fDict[iDict] = NULL;
+    }
+  
 }
 
 //_____________________________________________________________________________
 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
+  :TObject(m)
+  ,fEvent(m.fEvent)
+  ,fTree(0)
+  ,fDigits(0) 
+  ,fHasSDigits(m.fHasSDigits)
+  ,fSignalIndexes(NULL)
+  ,fUseDictionaries(kTRUE)
+  ,fDets(m.fDets)
+  ,fRawRec(m.fRawRec)
+  ,fDigitsParam(NULL)
 {
   //
   // AliTRDdigitsManager copy constructor
   //
 
-  ((AliTRDdigitsManager &) m).Copy(*this);
+  for (Int_t iDict = 0; iDict < kNDict; iDict++) 
+    {
+      fDict[iDict] = NULL;
+    }
 
 }
 
@@ -83,106 +104,323 @@ AliTRDdigitsManager::~AliTRDdigitsManager()
   // AliTRDdigitsManager destructor
   //
 
-  if (fDigits) {
-    fDigits->Delete();
-    delete fDigits;
-  }
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    fDictionary[iDict]->Delete();
-    delete fDictionary[iDict];
-  }
+  if (fDigits) 
+    {
+      fDigits->Delete();
+      delete fDigits;
+      fDigits = NULL;
+    }
+
+  for (Int_t iDict = 0; iDict < kNDict; iDict++) 
+    {
+      if(fDict[iDict])
+       {
+         fDict[iDict]->Delete();
+         delete fDict[iDict];
+         fDict[iDict] = NULL;
+       }
+    }
+
+  if (fSignalIndexes) 
+    {
+      fSignalIndexes->Delete();
+      delete fSignalIndexes;
+      fSignalIndexes = NULL;
+    }
+
+  if (fDigitsParam)
+    {
+      delete fDigitsParam;
+      fDigitsParam = NULL;
+    }
+
+}
+
+//_____________________________________________________________________________
+AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
+{
+  //
+  // Assignment operator
+  //
+
+  if (this != &m) 
+    {
+      ((AliTRDdigitsManager &) m).Copy(*this);
+    }
+
+  return *this;
 
 }
 
 //_____________________________________________________________________________
-void AliTRDdigitsManager::Copy(TObject &m)
+void AliTRDdigitsManager::Copy(TObject &m) const
 {
   //
   // Copy function
   //
 
-  ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
+  ((AliTRDdigitsManager &) m).fEvent           = fEvent;
+  ((AliTRDdigitsManager &) m).fHasSDigits      = fHasSDigits;
+  ((AliTRDdigitsManager &) m).fDigits          = NULL;
+  for(Int_t i = 0; i < kNDict; i++)
+    {
+      ((AliTRDdigitsManager &) m).fDict[i]  = NULL;
+    }
+  ((AliTRDdigitsManager &) m).fSignalIndexes   = NULL;
+  ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
+  ((AliTRDdigitsManager &) m).fDets            = fDets;
+  ((AliTRDdigitsManager &) m).fRawRec          = fRawRec;
+  ((AliTRDdigitsManager &) m).fDigitsParam     = NULL;
 
   TObject::Copy(m);
 
 }
 
 //_____________________________________________________________________________
-void AliTRDdigitsManager::SetRaw()
+void AliTRDdigitsManager::CreateArrays()
 {
+  //
+  // Create the data arrays
+  //
 
-  fIsRaw = kTRUE;
+  if (fHasSDigits) 
+    {
+      if (fDigits)                                        
+       {                                                   
+         fDigits->Delete();                                
+         delete fDigits;                                   
+       }                                                    
+      fDigits = new TObjArray(fDets);
+      for (Int_t index = 0; index < fDets; index++) 
+       {
+         fDigits->AddAt(new AliTRDarraySignal(),index);
+       }
+    }
+  else 
+    {
+      if (fDigits)                                          
+       {                                                    
+         fDigits->Delete();                                
+         delete fDigits;                                   
+       }                                                   
+      fDigits = new TObjArray(fDets);    
+      for (Int_t index = 0; index < fDets; index++) 
+       {
+         fDigits->AddAt(new AliTRDarrayADC(),index);
+       }
+    }
 
-  fDigits->SetBit(kRawDigit);
+  if (fUseDictionaries) 
+    {
+      for (Int_t iDict = 0; iDict < kNDict; iDict++)
+       {
+         if (fDict[iDict])                                   
+           {
+             fDict[iDict]->Delete();                                
+             delete fDict[iDict];                                    
+           }
+         fDict[iDict] = new TObjArray(fDets);
+         for (Int_t index = 0; index < fDets; index++) 
+           {
+             fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
+           }
+       }
+    }
   
+  if (fSignalIndexes)
+    {
+      fSignalIndexes->Delete();
+      delete fSignalIndexes;
+    }
+  fSignalIndexes = new TObjArray(fDets);
+  for (Int_t i = 0; i < fDets; i++)
+    {
+      fSignalIndexes->AddLast(new AliTRDSignalIndex());
+    }
+
+  if (fDigitsParam)
+    {
+      delete fDigitsParam;
+    }
+  fDigitsParam = new AliTRDdigitsParam();
+
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdigitsManager::MakeBranch()
+void AliTRDdigitsManager::ClearArrays(Int_t det)
 {
   //
-  // Creates the branches for the digits and the dictionary in the digits tree
+  // Reset the data arrays
   //
 
-  Int_t buffersize = 64000;
+  Int_t recoDet = fRawRec ? 0 : det;
 
-  Bool_t status = kTRUE;
+  if (fHasSDigits)
+    {
+      ((AliTRDarraySignal*)fDigits->At(recoDet))->Reset();
+    }
+  else
+    {
+      ((AliTRDarrayADC*)fDigits->At(recoDet))->ConditionalReset((AliTRDSignalIndex*)fSignalIndexes->At(recoDet));
+    }
 
-  if (gAlice->TreeD()) {
-
-    // Make the branch for the digits
-    if (fDigits) {
-      const AliTRDdataArrayI *kDigits = 
-           (AliTRDdataArrayI *) fDigits->At(0);
-      if (kDigits) {
-        gAlice->TreeD()->Branch("TRDdigits",kDigits->IsA()->GetName()
-                                           ,&kDigits,buffersize,1);
-        printf("AliTRDdigitsManager::MakeBranch -- ");
-        printf("Making branch TRDdigits\n");
-      }
-      else {
-        status = kFALSE;
-      }
-    }
-    else {
-      status = kFALSE;
+  if (fUseDictionaries) 
+    {
+      for (Int_t iDict = 0; iDict < kNDict; iDict++)
+       {
+         ((AliTRDarrayDictionary*)fDict[iDict]->At(recoDet))->Reset();
+       }
     }
+  
+  ((AliTRDSignalIndex*)fSignalIndexes->At(recoDet))->ResetContent();
 
-    // Make the branches for the dictionaries
-    for (Int_t iDict = 0; iDict < kNDict; iDict++) {
+}
 
-      Char_t branchname[15];
-      sprintf(branchname,"TRDdictionary%d",iDict);
-      if (fDictionary[iDict]) {
-        const AliTRDdataArrayI *kDictionary = 
-             (AliTRDdataArrayI *) fDictionary[iDict]->At(0);
-        if (kDictionary) {
-          gAlice->TreeD()->Branch(branchname,kDictionary->IsA()->GetName()
-                                            ,&kDictionary,buffersize,1);
-          printf("AliTRDdigitsManager::MakeBranch -- ");
-          printf("Making branch %s\n",branchname);
+//_____________________________________________________________________________
+Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
+{
+  //
+  // Returns the amplitude of a digit
+  //
+
+  if (!GetDigits(det)) return 0;
+  
+  return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
+
+}
+
+//_____________________________________________________________________________
+UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
+{
+  //
+  // Returns the pad status for the requested pad
+  //
+       
+  if (!GetDigits(det)) return 0;
+
+  return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)  
+{
+  //
+  // Creates the tree and branches for the digits and the dictionary
+  //
+
+  Int_t  buffersize = 64000;
+  Bool_t status     = kTRUE;
+
+  if (tree) 
+    {
+      fTree = tree;
+    }
+
+  // Make the branch for the digits
+  if (fDigits) 
+    {
+      if (fHasSDigits)
+       {
+         const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0); 
+         if (kDigits) 
+           {
+             if (!fTree) return kFALSE;
+             AliDebug(1,"Making branch for SDigits!\n");
+             TBranch *branch = fTree->GetBranch("TRDdigits");
+             if (!branch)
+               {
+                  fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
+               }
+             AliDebug(1,"Making branch TRDdigits\n");
+           }
+         else 
+           {
+             status = kFALSE;
+           }
        }
-        else {
-          status = kFALSE;
+
+      if (!fHasSDigits)
+       {
+         const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
+         if (kDigits) 
+           {
+             if (!fTree) return kFALSE;
+             AliDebug(1,"Making branch for Digits!\n");
+             TBranch *branch = fTree->GetBranch("TRDdigits");
+             if (!branch) 
+               {
+                  fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
+               }
+             AliDebug(1,"Making branch TRDdigits\n");        
+           }
+         else 
+           {
+             status = kFALSE;
+           }
        }
-      }
-      else {
-        status = kFALSE;
-      }
+
     }
+  else
+    {
 
-  }
-  else {
-    status = kFALSE;
-  }
+      status = kFALSE;
+
+    }
+  
+  if (fUseDictionaries) 
+    {
+      // Make the branches for the dictionaries
+      for (Int_t iDict = 0; iDict < kNDict; iDict++) 
+       {
+          const Int_t kBranchname = 15;
+         Char_t branchname[kBranchname];
+         snprintf(branchname,kBranchname,"TRDdictionary%d",iDict); 
+         if (fDict[iDict]) 
+           {
+             const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
+             if (kDictionary) 
+               {
+                 if (!fTree) return kFALSE;
+                 AliDebug(2,"Making branch for dictionary!\n");
+                 TBranch *branch = fTree->GetBranch(branchname);
+                 if (!branch) 
+                   {
+                      fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
+                   }
+                 AliDebug(1,Form("Making branch %s\n",branchname));
+               }
+             else 
+               {
+                 status = kFALSE;
+               }
+           }
+         else 
+           {
+             status = kFALSE;
+           }
+       }
+    }
+
+  if (fDigitsParam)
+    {
+      const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
+      if (!fTree) return kFALSE;
+      TBranch *branch = fTree->GetBranch("TRDdigitsParam");
+      if (!branch) 
+       {
+          fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
+       }
+      AliDebug(1,"Making branch AliTRDdigitsParam\n");
+    }
 
   return status;
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdigitsManager::ReadDigits()
+Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
 {
   //
   // Reads the digit information from the input file
@@ -190,22 +428,42 @@ Bool_t AliTRDdigitsManager::ReadDigits()
 
   Bool_t status = kTRUE;
 
-  status = fDigits->LoadArray("TRDdigits");
+  if (tree) 
+    {
+      fTree = tree;
+    }
+
+  if (!fDigits) 
+    {
+      AliDebug(1,"Create the data arrays.\n");
+      CreateArrays();
+    }
 
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    Char_t branchname[15];
-    sprintf(branchname,"TRDdictionary%d",iDict);
-    status = fDictionary[iDict]->LoadArray(branchname);
-  }  
+  status = LoadArrayDigits();
 
-  if (fDigits->TestBit(kRawDigit)) {
-    fIsRaw = kTRUE;
-  }
-  else {
-    fIsRaw = kFALSE;
+  if (fUseDictionaries) 
+    {
+      status = LoadArrayDict();
+      if (status == kFALSE) 
+       {
+         fUseDictionaries = kFALSE;
+         AliWarning("Unable to load dict arrays. Will not use them.\n");
+       }
+    }  
+
+  if (!LoadDigitsParam()) {
+    AliWarning("Could not read digits parameter.");
+    if (fDigitsParam) {
+      delete fDigitsParam;
+    }
+    AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
+                  ,AliTRDSimParam::Instance()->GetNTimeBins()));
+    fDigitsParam = new AliTRDdigitsParam();
+    fDigitsParam->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
+    fDigitsParam->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
   }
 
-  return kTRUE;
+  return status;
 
 }
 
@@ -213,43 +471,48 @@ Bool_t AliTRDdigitsManager::ReadDigits()
 Bool_t AliTRDdigitsManager::WriteDigits()
 {
   //
-  // Writes out the TRD-digits and the dictionaries
+  // Writes out the TRD-digits, the dictionaries and the digitsPaam
   //
 
-  // Create the branches
-  if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) { 
-    if (!MakeBranch()) return kFALSE;
-  }
+  if (!StoreArrayDigits())
+    {
+      AliError("Error while storing digits\n");
+      return kFALSE;
+    }
 
-  // Store the contents of the segment array in the tree
-  if (!fDigits->StoreArray("TRDdigits")) {
-    printf("AliTRDdigitsManager::WriteDigits -- ");
-    printf("Error while storing digits in branch TRDdigits\n");
-    return kFALSE;
-  }
-  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
-    Char_t branchname[15];
-    sprintf(branchname,"TRDdictionary%d",iDict);
-    if (!fDictionary[iDict]->StoreArray(branchname)) {
-      printf("AliTRDdigitsManager::WriteDigits -- ");
-      printf("Error while storing dictionary in branch %s\n",branchname);
+  if (fUseDictionaries) 
+    {
+      if (!StoreArrayDict())
+       {
+         AliError("Error while storing dictionaries in branch\n");
+         return kFALSE;
+       }
+    }
+
+  if (!StoreDigitsParam())
+    {
+      AliError("Error while storing digitsParam\n");
       return kFALSE;
     }
-  }
+  
+  // Write the new tree to the output file
+  fTree->AutoSave();
 
   return kTRUE;
 
 }
 
 //_____________________________________________________________________________
-AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
-                                         , Int_t time, Int_t det)
+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 digits[4]; 
   Int_t amp[1];
 
   digits[0] = det;
@@ -257,79 +520,557 @@ AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
   digits[2] = col;
   digits[3] = time;
 
-  amp[0]    = GetDigits(det)->GetData(row,col,time);
+  amp[0]    = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
   
-  return (new AliTRDdigit(fIsRaw,digits,amp));
+  return (new AliTRDdigit(digits,amp));
 
 }
 
 //_____________________________________________________________________________
 Int_t AliTRDdigitsManager::GetTrack(Int_t track
-                                  , Int_t row, Int_t col, Int_t time
-                                  , Int_t det)
+                                  , 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)) {
-    TObject::Error("GetTracks"
-                  ,"track %d out of bounds (size: %d, this: 0x%08x)"
-                  ,track,kNDict,this);
-    return -1;
-  }
+  if ((track < 0) || (track >= kNDict)) 
+    {
+      AliError(Form("track %d out of bounds (size: %d, this: 0x%p)",track,kNDict,this));
+      return -1;
+    }
 
-  // Array contains index+1 to allow data compression
-  return (GetDictionary(det,track)->GetData(row,col,time) - 1);
+  if (fUseDictionaries == kFALSE) 
+    {
+      return -1;
+    }
+
+  // Array contains index+1 to allow data compression--->Changed
+  return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
 
 }
 
-//_____________________________________________________________________________
-AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) 
+//________________________________________________________________________________
+AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
 {
   //
   // Returns the digits array for one detector
   //
 
-  return (AliTRDdataArrayI *) fDigits->At(det);
+  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;
+    }
 
 }
 
 //_____________________________________________________________________________
-AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) 
+AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
+                                                        , Int_t i) const
 {
   //
   // Returns the dictionary for one detector
   //
 
-  return (AliTRDdataArrayI *) fDictionary[i]->At(det);
+  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, AliTRDdigit *Digit)
+Int_t AliTRDdigitsManager::GetTrack(Int_t track, 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();
+  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);
 
 }
 
 //_____________________________________________________________________________
-AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
+AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det) 
 {
+  // 
+  // Returns indexes of active pads
   //
-  // Assignment operator
+
+  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
   //
 
-  if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
-  return *this;
+  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;
+
+}
+