]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDsegmentArrayBase.cxx
Adding include files where needed for latest ROOT
[u/mrichter/AliRoot.git] / TRD / AliTRDsegmentArrayBase.cxx
index cc52a5c21cb89008f1986f2f5de7135f60108847..c8f9110c15d690f2ca077d9a19d8fbd3af3d6b04 100644 (file)
 #include <TError.h>
 #include <TClass.h>
 
+#include "AliLog.h"
+
+#include "AliTRDsegmentArrayBase.h"
 #include "AliTRDarrayI.h"
 #include "AliTRDsegmentID.h"
-#include "AliTRDsegmentArrayBase.h"
 
 ClassImp(AliTRDsegmentArrayBase)
   
 //_____________________________________________________________________________
-AliTRDsegmentArrayBase::AliTRDsegmentArrayBase():TNamed()
+AliTRDsegmentArrayBase::AliTRDsegmentArrayBase()
+  :TNamed()
+  ,fSegment(0) 
+  ,fTreeIndex(0)
+  ,fNSegment(0)
+  ,fTree(0)
+  ,fBranch(0)
+  ,fClass(0)
 {
   //
   // AliTRDsegmentArrayBase default constructor
   //
 
-  fNSegment  = 0;
-  fSegment   = 0; 
-  fTreeIndex = 0;
-  fTree      = 0;
-  fClass     = 0;
-  fBranch    = 0;
-
 }
 
 //_____________________________________________________________________________
 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const char *classname, Int_t n)
+  :TNamed()
+  ,fSegment(0) 
+  ,fTreeIndex(0)
+  ,fNSegment(0)
+  ,fTree(0)
+  ,fBranch(0)
+  ,fClass(0)
 {
   //
   //  Create an array of objects of <classname>. The class must inherit from
@@ -59,13 +68,6 @@ AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const char *classname, Int_t n)
   //  the array.
   //
 
-  fNSegment  = 0;
-  fSegment   = 0; 
-  fTreeIndex = 0;
-  fTree      = 0;
-  fClass     = 0;
-  fBranch    = 0;
-
   SetClass(classname);
 
   if (MakeArray(n) == kFALSE) {
@@ -77,13 +79,17 @@ AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const char *classname, Int_t n)
 
 //_____________________________________________________________________________
 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &a)
-:TNamed(a)
+  :TNamed(a)
+  ,fSegment(a.fSegment) 
+  ,fTreeIndex(a.fTreeIndex)
+  ,fNSegment(a.fNSegment)
+  ,fTree(a.fTree)
+  ,fBranch(a.fBranch)
+  ,fClass(a.fClass)
 {
   //
   // AliTRDsegmentArrayBase copy constructor
   //
-  
-  ((AliTRDsegmentArrayBase &) a).Copy(*this);
 
 }
 
@@ -94,13 +100,14 @@ AliTRDsegmentArrayBase::~AliTRDsegmentArrayBase()
   // AliTRDsegmentArrayBase destructor
   //
 
-  if (fNSegment){
+  if (fNSegment) {
     fSegment->Delete();
     delete fSegment;
   }
 
-  //if (fTree)      delete fTree;
-  if (fTreeIndex) delete fTreeIndex;
+  if (fTreeIndex) {
+    delete fTreeIndex;
+  }
 
 }
 
@@ -118,7 +125,7 @@ AliTRDsegmentArrayBase &AliTRDsegmentArrayBase
 }
 
 //_____________________________________________________________________________
-void AliTRDsegmentArrayBase::Copy(TObject &a)
+void AliTRDsegmentArrayBase::Copy(TObject &a) const
 {
   //
   // Copy function
@@ -154,21 +161,22 @@ Bool_t AliTRDsegmentArrayBase::SetClass(const char *classname)
     fSegment   = 0;
   }
 
-  if (!gROOT) ::Fatal("AliTRDsegmentArrayBase::AliTRDsegmentArrayBase"
-                     ,"ROOT system not initialized");
-   
-   fClass = gROOT->GetClass(classname);
-   if (!fClass) {
-     Error("AliTRDsegmentArrayBase","%s is not a valid class name",classname);
-     return kFALSE;
-   }
-   if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
-     Error("AliTRDsegmentArrayBase"
-          ,"%s does not inherit from AliTRDsegmentID",classname);
-     return kFALSE;
-   }
+  if (!gROOT) {
+    AliFatal("ROOT system not initialized");
+    exit(1);
+  }   
+
+  fClass = gROOT->GetClass(classname);
+  if (!fClass) {
+    AliError(Form("%s is not a valid class name",classname));
+    return kFALSE;
+  }
+  if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
+    AliError(Form("%s does not inherit from AliTRDsegmentID",classname));
+    return kFALSE;
+  }
   
-   return kTRUE;
+  return kTRUE;
 
 }
 
@@ -179,12 +187,18 @@ AliTRDsegmentID *AliTRDsegmentArrayBase::NewSegment()
   // Create a new object according to the class information
   //
 
-  if (fClass  == 0) return 0;
+  if (fClass  == 0) {
+    return 0;
+  }
 
   AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New();
-  if (segment == 0) return 0;
 
-  return segment;
+  if (segment == 0) {
+    return 0;
+  }
+  else {
+    return segment;
+  }
 
 }
 
@@ -195,13 +209,19 @@ Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment)
   // Add a segment to the array
   //
 
-  if (segment  == 0) return kFALSE;
-  if (fSegment == 0) return kFALSE;
-  if (fClass   == 0) return kFALSE;
+  if (segment  == 0) {
+    return kFALSE;
+  }
+  if (fSegment == 0) {
+    return kFALSE;
+  }
+  if (fClass   == 0) {
+    return kFALSE;
+  }
 
   if (!(segment->IsA()->InheritsFrom(fClass))) {
-    Error("AliTRDsegmentArrayBase","added class %s is not of proper type",
-         segment->IsA()->GetName());
+    AliError(Form("added class %s is not of proper type"
+                 ,segment->IsA()->GetName()));
     return kFALSE;
   }
 
@@ -213,17 +233,23 @@ Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment)
 }
 
 //_____________________________________________________________________________
-AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index)
+AliTRDsegmentID *AliTRDsegmentArrayBase::AddSegment(Int_t index)
 {
   //
   // Add a segment to the array
   //
 
-  if (fSegment == 0) return 0;
-  if (fClass   == 0) return 0;
+  if (fSegment == 0) {
+    return 0;
+  }
+  if (fClass   == 0) {
+    return 0;
+  }
 
   AliTRDsegmentID *segment = NewSegment();
-  if (segment  == 0) return 0;
+  if (segment  == 0) {
+    return 0;
+  }
 
   fSegment->AddAt(segment,index);
   segment->SetID(index);
@@ -250,10 +276,12 @@ Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n)
   fTreeIndex = new AliTRDarrayI();
   fTreeIndex->Set(n);
   fNSegment  = n;
-  if ((fSegment) && (fTreeIndex)) 
+  if ((fSegment) && (fTreeIndex)) {
     return kTRUE;
-  else 
+  }
+  else { 
     return kFALSE;
+  }
                  
 }
 
@@ -264,11 +292,7 @@ void AliTRDsegmentArrayBase::ClearSegment(Int_t index)
   // Remove a segment from the active memory    
   //
 
-  //PH  if ((*fSegment)[index]){
-  //PH    delete (*fSegment)[index]; // because problem with deleting TClonesArray
-  //PH    fSegment->RemoveAt(index);
-  //PH  }
-  if (fSegment->At(index)){
+  if (fSegment->At(index)) {
     delete fSegment->RemoveAt(index);
   }
 
@@ -283,34 +307,42 @@ void AliTRDsegmentArrayBase::MakeTree(char *file)
 
   AliTRDsegmentID *psegment = NewSegment();  
 
-  if (fTree) delete fTree;
-  fTree   = new TTree("Segment Tree","Tree with segments");
+  if (fTree) {
+    delete fTree;
+  }
 
+  fTree   = new TTree("Segment Tree","Tree with segments");
   fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000);
-  if (file) 
-      fBranch->SetFile(file);      
+
+  if (file) {
+    fBranch->SetFile(file);      
+  }
 
   delete psegment;
 
 }              
 
 //_____________________________________________________________________________
-Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName)
+Bool_t AliTRDsegmentArrayBase::ConnectTree(const char *treeName)
 {
   //
   // Connect a tree from current directory  
   //
 
-  if (fTree){
+  if (fTree) {
     delete fTree;
     fTree   = 0;
     fBranch = 0;
   }
 
-  fTree   = (TTree*) gDirectory->Get(treeName);
-  if (fTree   == 0) return kFALSE;
+  fTree = (TTree *) gDirectory->Get(treeName);
+  if (fTree   == 0) {
+    return kFALSE;
+  }
   fBranch = fTree->GetBranch("Segment");
-  if (fBranch == 0) return kFALSE;
+  if (fBranch == 0) {
+    return kFALSE;
+  }
 
   MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries())));
 
@@ -325,30 +357,42 @@ AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index)
   // Load a segment with index <index> into the memory
   //
 
-  if (fTreeIndex == 0) MakeDictionary(3000);
+  if (fTreeIndex == 0) {
+    MakeDictionary(3000);
+  }
 
   // First try to load dictionary 
-  if (fTreeIndex == 0)        return 0;
-  if (fBranch    == 0)        return 0;
-  if (index > fTreeIndex->fN) return 0;
-  //PH  AliTRDsegmentID *s = (AliTRDsegmentID*) (*fSegment)[index];
-  AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index);
-  if (s == 0) s = NewSegment();
+  if (fTreeIndex == 0) {
+    return 0;
+  }
+  if (fBranch    == 0) {
+    return 0;
+  }
+  if (index > fTreeIndex->fN) {
+    return 0;
+  }
+
+  AliTRDsegmentID *s = (AliTRDsegmentID *) fSegment->At(index);
+  if (s == 0) {
+    s = NewSegment();
+  }
   s->SetID(index);
   
   if (s != 0) {
     Int_t treeIndex = (*fTreeIndex)[index];
-    if (treeIndex < 1) 
+    if (treeIndex < 1) {
       return 0;
-    else 
-      treeIndex--;   
+    }
+    else { 
+      treeIndex--;
+    }   
     fBranch->SetAddress(&s);
     fTree->GetEvent(treeIndex);
-    //PH    (*fSegment)[index] = (TObject*) s;
     fSegment->AddAt((TObject*) s, index);
   }
-  else 
+  else 
     return 0;
+  }
 
   return s;
 
@@ -361,20 +405,24 @@ AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index)
   // Load a segment at position <index> in the tree into the memory
   //
 
-  if (fBranch == 0)                return 0;
-  if (index > fTree->GetEntries()) return 0;
+  if (fBranch == 0) {
+    return 0;
+  }
+  if (index > fTree->GetEntries()) {
+    return 0;
+  }
 
   AliTRDsegmentID *s = NewSegment();  
   if (s) {
     fBranch->SetAddress(&s);
     fTree->GetEvent(index);
   }
-  else 
+  else {
     return 0;
+  }
 
   Int_t nindex = s->GetID();
   ClearSegment(nindex);
-  //PH  (*fSegment)[nindex] = (TObject *) s;
   fSegment->AddAt((TObject *) s, nindex);
 
   return s;
@@ -389,8 +437,12 @@ void AliTRDsegmentArrayBase::StoreSegment(Int_t index)
   //
 
   const AliTRDsegmentID *kSegment = (*this)[index];
-  if (kSegment == 0) return;
-  if (fTree    == 0) MakeTree();
+  if (kSegment == 0) {
+    return;
+  }
+  if (fTree    == 0) {
+    MakeTree();
+  }
   fBranch->SetAddress(&kSegment);
   fTree->Fill();
 
@@ -403,8 +455,12 @@ Bool_t  AliTRDsegmentArrayBase::MakeDictionary(Int_t size)
   // Create an index table for the tree
   //  
 
-  if (size < 1)   return kFALSE;
-  if (fTreeIndex) delete fTreeIndex;
+  if (size < 1) {
+    return kFALSE;
+  }
+  if (fTreeIndex) {
+    delete fTreeIndex;
+  }
 
   fTreeIndex = new AliTRDarrayI(); 
   fTreeIndex->Set(size);
@@ -416,11 +472,12 @@ Bool_t  AliTRDsegmentArrayBase::MakeDictionary(Int_t size)
   TBranch *brindix = fTree->GetBranch("fSegmentID");
 
   Int_t nevent = (Int_t) fTree->GetEntries();  
-  for (Int_t i = 0; i < nevent; i++){
+  for (Int_t i = 0; i < nevent; i++) {
     brindix->GetEvent(i);
     Int_t treeIndex = segment.GetID();
-    if (fTreeIndex->fN < treeIndex) 
+    if (fTreeIndex->fN < treeIndex) {
       fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1);
+    }
     (*fTreeIndex)[treeIndex] = i + 1; 
   }
 
@@ -435,7 +492,11 @@ const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i) const
   // Returns a segment with the given index <i>
   //
 
-  if ((i < 0) || (i >= fNSegment)) return 0; 
+  if ((i <          0) || 
+      (i >= fNSegment)) {
+    return 0; 
+  }
+
   return (AliTRDsegmentID *) fSegment->At(i);
 
 }
@@ -447,8 +508,11 @@ const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const
   // Returns a segment with the given index <i>
   //
 
-  if ((i < 0) || (i >= fNSegment)) return 0; 
-  //PH  return (AliTRDsegmentID *)((*fSegment)[i]);
+  if ((i <          0) || 
+      (i >= fNSegment)) {
+    return 0; 
+  }
+
   return (AliTRDsegmentID *) fSegment->At(i);
 
 }