X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TRD%2FAliTRDsegmentArrayBase.cxx;h=c8f9110c15d690f2ca077d9a19d8fbd3af3d6b04;hb=54d68e6950921908e0573b1577818b2a3614148c;hp=8ceb9e7a7b2a6bff779eaefecf4998f942ba22ff;hpb=b9d0a01d7a0723a09071b0b56200d72f59a9c2b6;p=u%2Fmrichter%2FAliRoot.git diff --git a/TRD/AliTRDsegmentArrayBase.cxx b/TRD/AliTRDsegmentArrayBase.cxx index 8ceb9e7a7b2..c8f9110c15d 100644 --- a/TRD/AliTRDsegmentArrayBase.cxx +++ b/TRD/AliTRDsegmentArrayBase.cxx @@ -13,60 +13,7 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* -$Log$ -Revision 1.12.6.1 2002/06/10 15:28:58 hristov -Merged with v3-08-02 - -Revision 1.13 2002/03/28 14:59:07 cblume -Coding conventions - -Revision 1.12 2002/02/12 16:06:45 cblume -Remove delete fTree - -Revision 1.11 2001/11/19 08:44:08 cblume -Fix bugs reported by Rene - -Revision 1.10 2001/08/30 09:31:22 hristov -The operator[] is replaced by At() or AddAt() in case of TObjArray. - -Revision 1.9 2001/07/27 13:03:15 hristov -Default Branch split level set to 99 - -Revision 1.8 2001/01/26 19:56:57 hristov -Major upgrade of AliRoot code - -Revision 1.7 2000/11/20 08:56:07 cblume -Cleanup of data arrays - -Revision 1.6 2000/11/01 14:53:21 cblume -Merge with TRD-develop - -Revision 1.1.4.3 2000/10/06 16:49:46 cblume -Made Getters const - -Revision 1.1.4.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.4.1 2000/05/08 14:55:03 cblume -Bug fixes - -Revision 1.1 2000/02/28 19:02:56 cblume -Add new TRD classes - -*/ +/* $Id$ */ /////////////////////////////////////////////////////////////////////////////// // // @@ -81,30 +28,39 @@ Add new TRD classes #include #include +#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(Text_t *classname, Int_t n) +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 . The class must inherit from @@ -112,13 +68,6 @@ AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n) // the array. // - fNSegment = 0; - fSegment = 0; - fTreeIndex = 0; - fTree = 0; - fClass = 0; - fBranch = 0; - SetClass(classname); if (MakeArray(n) == kFALSE) { @@ -130,12 +79,17 @@ AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n) //_____________________________________________________________________________ AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &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); } @@ -146,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; + } } @@ -170,7 +125,7 @@ AliTRDsegmentArrayBase &AliTRDsegmentArrayBase } //_____________________________________________________________________________ -void AliTRDsegmentArrayBase::Copy(TObject &a) +void AliTRDsegmentArrayBase::Copy(TObject &a) const { // // Copy function @@ -187,7 +142,7 @@ void AliTRDsegmentArrayBase::Copy(TObject &a) } //_____________________________________________________________________________ -Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *classname) +Bool_t AliTRDsegmentArrayBase::SetClass(const char *classname) { // // Sets the classname of the stored object @@ -206,21 +161,22 @@ Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *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; } @@ -231,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; + } } @@ -247,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; } @@ -265,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); @@ -302,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; + } } @@ -316,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); } @@ -335,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()))); @@ -377,30 +357,42 @@ AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index) // Load a segment with 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; @@ -413,20 +405,24 @@ AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index) // Load a segment at position 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; @@ -441,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(); @@ -455,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); @@ -468,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; } @@ -487,7 +492,11 @@ const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i) const // Returns a segment with the given index // - if ((i < 0) || (i >= fNSegment)) return 0; + if ((i < 0) || + (i >= fNSegment)) { + return 0; + } + return (AliTRDsegmentID *) fSegment->At(i); } @@ -499,8 +508,11 @@ const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const // Returns a segment with the given index // - if ((i < 0) || (i >= fNSegment)) return 0; - //PH return (AliTRDsegmentID *)((*fSegment)[i]); + if ((i < 0) || + (i >= fNSegment)) { + return 0; + } + return (AliTRDsegmentID *) fSegment->At(i); }