]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdigitsManager.cxx
Add the number of local boards
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
index d0c39248f0ff94cf7a6f62903876743346a765da..3e8fe6b7d423961129f88c012d0aa94960ac466a 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.13  2001/11/06 17:19:41  cblume
-Add detailed geometry and simple simulator
-
-Revision 1.12  2001/05/16 14:57:28  alibrary
-New files for folders and Stack
-
-Revision 1.11  2001/03/13 09:30:35  cblume
-Update of digitization. Moved digit branch definition to AliTRD
-
-Revision 1.10  2001/01/26 19:56:57  hristov
-Major upgrade of AliRoot code
-
-Revision 1.9  2000/11/02 09:25:53  cblume
-Change also the dictionary to AliTRDdataArray
-
-Revision 1.8  2000/11/01 15:20:13  cblume
-Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch()
-
-Revision 1.7  2000/11/01 14:53:20  cblume
-Merge with TRD-develop
-
-Revision 1.1.2.5  2000/10/17 02:27:34  cblume
-Get rid of global constants
-
-Revision 1.1.2.4  2000/10/15 23:40:01  cblume
-Remove AliTRDconst
-
-Revision 1.1.2.3  2000/10/06 16:49:46  cblume
-Made Getters const
-
-Revision 1.1.2.2  2000/10/04 16:34:58  cblume
-Replace include files by forward declarations
-
-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$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -72,20 +22,20 @@ Add new class AliTRDdigitsManager
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <iostream.h>
+#include <Riostream.h>
  
 #include <TROOT.h>
 #include <TTree.h>                                                              
 #include <TFile.h>
 
 #include "AliRun.h"
+#include "AliLog.h"
 
 #include "AliTRDdigitsManager.h"
 #include "AliTRDsegmentArray.h"
 #include "AliTRDdataArrayI.h"
 #include "AliTRDdigit.h"
 #include "AliTRDgeometry.h"
-#include "AliTRD.h"
 
 ClassImp(AliTRDdigitsManager)
 
@@ -95,20 +45,18 @@ ClassImp(AliTRDdigitsManager)
   const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
 
 //_____________________________________________________________________________
-AliTRDdigitsManager::AliTRDdigitsManager():TObject()
+AliTRDdigitsManager::AliTRDdigitsManager()
+  :TObject()
+  ,fEvent(0)
+  ,fTree(0)
+  ,fDigits(0)
+  ,fIsRaw(0)
+  ,fSDigits(0)
 {
   //
   // Default constructor
   //
 
-  fIsRaw   = kFALSE;
-  fEvent   = 0;
-  fVerbose = 0;
-  fSDigits = 0;
-
-  fFile    = NULL;
-  fTree    = NULL;
-  fDigits  = NULL;
   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
     fDictionary[iDict] = NULL;
   }
@@ -117,13 +65,17 @@ AliTRDdigitsManager::AliTRDdigitsManager():TObject()
 
 //_____________________________________________________________________________
 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
+  :TObject(m)
+  ,fEvent(m.fEvent)
+  ,fTree(0)
+  ,fDigits(0)
+  ,fIsRaw(m.fIsRaw)
+  ,fSDigits(m.fSDigits)
 {
   //
   // AliTRDdigitsManager copy constructor
   //
 
-  ((AliTRDdigitsManager &) m).Copy(*this);
-
 }
 
 //_____________________________________________________________________________
@@ -133,17 +85,6 @@ AliTRDdigitsManager::~AliTRDdigitsManager()
   // AliTRDdigitsManager destructor
   //
 
-  if (fFile) {
-    fFile->Close();
-    delete fFile;
-    fFile = NULL;
-  }
-
-  if (fTree) {
-    delete fTree;
-    fTree = NULL;
-  }
-
   if (fDigits) {
     fDigits->Delete();
     delete fDigits;
@@ -159,7 +100,19 @@ AliTRDdigitsManager::~AliTRDdigitsManager()
 }
 
 //_____________________________________________________________________________
-void AliTRDdigitsManager::Copy(TObject &m)
+AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
+{
+  //
+  // Assignment operator
+  //
+
+  if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
+  return *this;
+
+}
+
+//_____________________________________________________________________________
+void AliTRDdigitsManager::Copy(TObject &m) const
 {
   //
   // Copy function
@@ -167,7 +120,6 @@ void AliTRDdigitsManager::Copy(TObject &m)
 
   ((AliTRDdigitsManager &) m).fIsRaw   = fIsRaw;
   ((AliTRDdigitsManager &) m).fEvent   = fEvent;
-  ((AliTRDdigitsManager &) m).fVerbose = fVerbose;
   ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
 
   TObject::Copy(m);
@@ -188,15 +140,39 @@ void AliTRDdigitsManager::CreateArrays()
                                                ,AliTRDgeometry::Ndet());
   }
 
+}
+//_____________________________________________________________________________
+void AliTRDdigitsManager::ResetArrays()
+{
+  //
+  // Reset the data arrays
+  //
+
+  if (fDigits) {
+    delete fDigits;
+  }
+  fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
+
+  for (Int_t iDict = 0; iDict < kNDict; iDict++) {
+    if (fDictionary[iDict]) {  
+      delete fDictionary[iDict];
+    }
+    fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
+                                               ,AliTRDgeometry::Ndet());
+  }
+
 }
 
 //_____________________________________________________________________________
 void AliTRDdigitsManager::SetRaw()
 {
+  //
+  // Switch on the raw digits flag
+  //
 
   fIsRaw = kTRUE;
-
-  fDigits->SetBit(AliTRDdigit::RawDigit());
+  if (fDigits)
+    fDigits->SetBit(AliTRDdigit::RawDigit());
   
 }
 
@@ -208,39 +184,13 @@ Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
   // Returns the amplitude of a digit
   //
 
+  if (!GetDigits(det)) return 0;
   return ((Short_t) GetDigits(det)->GetData(row,col,time));
 
 }
  
 //_____________________________________________________________________________
-Bool_t AliTRDdigitsManager::Open(const Char_t *name)
-{
-  //
-  // Opens the file for the TRD digits
-  //
-
-  fFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
-  if (!fFile) {
-    if (fVerbose > 0) {
-      printf("AliTRDdigitsManager::Open -- ");
-      printf("Open the AliROOT-file %s.\n",name);
-    }
-    fFile = new TFile(name,"UPDATE");
-    if (!fFile) return kFALSE;
-  }
-  else {
-    if (fVerbose > 0) {
-      printf("AliTRDdigitsManager::Open -- ");
-      printf("%s is already open.\n",name);
-    }
-  }
-
-  return kTRUE;
-
-}
-
-//_____________________________________________________________________________
-Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
+Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
 {
   //
   // Creates the tree and branches for the digits and the dictionary
@@ -250,34 +200,19 @@ Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
 
   Bool_t status = kTRUE;
 
-  AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD") ;
-
-  // Create the TRD digits tree
-  Char_t treeName[12];
-  if (fSDigits) {
-    sprintf(treeName,"TreeS%d_TRD",fEvent);
-    fTree = new TTree(treeName,"TRD SDigits");
-  }
-  else {
-    sprintf(treeName,"TreeD%d_TRD",fEvent);
-    fTree = new TTree(treeName,"TRD Digits");
-  }
-
-  if (fVerbose > 0) {
-    printf("AliTRDdigitsManager::MakeBranch -- ");
-    printf("Creating tree %s\n",treeName);
+  if (tree) {
+    fTree = tree;
   }
 
   // Make the branch for the digits
   if (fDigits) {
     const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
     if (kDigits) {
-      trd->MakeBranchInTree(fTree,"TRDdigits",kDigits->IsA()->GetName()
-                                 ,&kDigits,buffersize,99,file);
-      if (fVerbose > 0) {
-        printf("AliTRDdigitsManager::MakeBranch -- ");
-        printf("Making branch TRDdigits\n");
-      }
+      if (!fTree) return kFALSE;
+      TBranch* branch = fTree->GetBranch("TRDdigits");
+      if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName(),
+                                 &kDigits,buffersize,99);
+      AliDebug(1,"Making branch TRDdigits\n");
     }
     else {
       status = kFALSE;
@@ -295,12 +230,11 @@ Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
       const AliTRDdataArray *kDictionary = 
               (AliTRDdataArray *) fDictionary[iDict]->At(0);
       if (kDictionary) {
-        trd->MakeBranchInTree(fTree,branchname,kDictionary->IsA()->GetName()
-                             ,&kDictionary,buffersize,99,file);
-        if (fVerbose > 0) {
-          printf("AliTRDdigitsManager::MakeBranch -- ");
-          printf("Making branch %s\n",branchname);
-       }
+       if (!fTree) return kFALSE;
+       TBranch* branch = fTree->GetBranch(branchname);
+       if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName(),
+                                  &kDictionary,buffersize,99);
+        AliDebug(1,Form("Making branch %s\n",branchname));
       }
       else {
         status = kFALSE;
@@ -316,7 +250,7 @@ Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDdigitsManager::ReadDigits()
+Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
 {
   //
   // Reads the digit information from the input file
@@ -324,33 +258,14 @@ Bool_t AliTRDdigitsManager::ReadDigits()
 
   Bool_t status = kTRUE;
 
-  // Get the digits tree
-  Char_t treeName[12];
-  if (fSDigits) {
-    sprintf(treeName,"TreeS%d_TRD",fEvent);
-  }
-  else {
-    sprintf(treeName,"TreeD%d_TRD",fEvent);
-  }
-  if (fFile) {
-    fTree = (TTree *) fFile->Get(treeName);
-  }
-  else {
-    fTree = (TTree *) gDirectory->Get(treeName);
-  }
-  if (!fTree) {
-    if (fVerbose > 0) {
-      printf("AliTRDdigitsManager::ReadDigits -- ");
-      printf("Could not find tree %s.\n",treeName);
-    }
-    return kFALSE;
+  if (tree) {
+
+    fTree = tree;
+
   }
 
   if (!fDigits) {
-    if (fVerbose > 0) {
-      printf("AliTRDdigitsManager::ReadDigits -- ");
-      printf("Create the data arrays.\n");
-    }
+    AliDebug(1,"Create the data arrays.\n");
     CreateArrays();
   }
 
@@ -382,22 +297,20 @@ Bool_t AliTRDdigitsManager::WriteDigits()
 
   // Store the contents of the segment array in the tree
   if (!fDigits->StoreArray("TRDdigits",fTree)) {
-    printf("AliTRDdigitsManager::WriteDigits -- ");
-    printf("Error while storing digits in branch TRDdigits\n");
+    AliError("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,fTree)) {
-      printf("AliTRDdigitsManager::WriteDigits -- ");
-      printf("Error while storing dictionary in branch %s\n",branchname);
+      AliError(Form("Error while storing dictionary in branch %s\n",branchname));
       return kFALSE;
     }
   }
 
   // Write the new tree to the output file
-  fTree->Write();
+  fTree->AutoSave();  // Modification by Jiri
 
   return kTRUE;
 
@@ -435,9 +348,8 @@ Int_t AliTRDdigitsManager::GetTrack(Int_t track
   //
 
   if ((track < 0) || (track >= kNDict)) {
-    TObject::Error("GetTracks"
-                  ,"track %d out of bounds (size: %d, this: 0x%08x)"
-                  ,track,kNDict,this);
+    AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)"
+                 ,track,kNDict,this));
     return -1;
   }
 
@@ -453,6 +365,7 @@ AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
   // Returns the digits array for one detector
   //
 
+  if (!fDigits) return 0x0;
   return (AliTRDdataArrayI *) fDigits->At(det);
 
 }
@@ -483,15 +396,3 @@ Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
   return GetTrack(track,row,col,time,det);
 
 }
-
-//_____________________________________________________________________________
-AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
-{
-  //
-  // Assignment operator
-  //
-
-  if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
-  return *this;
-
-}