#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
// the array.
//
- fNSegment = 0;
- fSegment = 0;
- fTreeIndex = 0;
- fTree = 0;
- fClass = 0;
- fBranch = 0;
-
SetClass(classname);
if (MakeArray(n) == kFALSE) {
//_____________________________________________________________________________
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);
}
// AliTRDsegmentArrayBase destructor
//
- if (fNSegment){
+ if (fNSegment) {
fSegment->Delete();
delete fSegment;
}
- //if (fTree) delete fTree;
- if (fTreeIndex) delete fTreeIndex;
+ if (fTreeIndex) {
+ delete fTreeIndex;
+ }
}
}
//_____________________________________________________________________________
-void AliTRDsegmentArrayBase::Copy(TObject &a)
+void AliTRDsegmentArrayBase::Copy(TObject &a) const
{
//
// Copy function
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;
}
// 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;
+ }
}
// 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;
}
}
//_____________________________________________________________________________
-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);
fTreeIndex = new AliTRDarrayI();
fTreeIndex->Set(n);
fNSegment = n;
- if ((fSegment) && (fTreeIndex))
+ if ((fSegment) && (fTreeIndex)) {
return kTRUE;
- else
+ }
+ else {
return kFALSE;
+ }
}
// 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);
}
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())));
// 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;
// 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;
//
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();
// 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);
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;
}
// 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);
}
// 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);
}