X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TRD%2FAliTRDsegmentArray.cxx;h=bbc48a430282e14247959516c503dd6075e392c5;hb=42a6828281ba79bc6c9e2dd568055bae0179ac11;hp=d2fb55ff670257221d1948bdb36226f8c5b413e6;hpb=793ff80c55ff5c109e52679681ffde680cc9ff22;p=u%2Fmrichter%2FAliRoot.git diff --git a/TRD/AliTRDsegmentArray.cxx b/TRD/AliTRDsegmentArray.cxx index d2fb55ff670..bbc48a43028 100644 --- a/TRD/AliTRDsegmentArray.cxx +++ b/TRD/AliTRDsegmentArray.cxx @@ -13,52 +13,41 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* -$Log$ -Revision 1.1.4.3 2000/10/06 16:49:46 cblume -Made Getters const +/* $Id$ */ -Revision 1.1.4.2 2000/10/04 16:34:58 cblume -Replace include files by forward declarations - -Revision 1.5 2000/10/02 21:28:19 fca -Removal of useless dependecies via forward declarations - -Revision 1.4 2000/06/27 13:08:50 cblume -Changed to Copy(TObject &A) to appease the HP-compiler - -Revision 1.3 2000/06/08 18:32:58 cblume -Make code compliant to coding conventions - -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:32 cblume -Add new TRD classes - -*/ - -/////////////////////////////////////////////////////////////////////////////// -// // -// Alice segment manager class // -// // -/////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +// // +// Alice segment manager class // +// // +//////////////////////////////////////////////////////////////////////////// +#include +#include #include +#include +#include +#include +#include -#include "AliRun.h" +#include "AliLog.h" -#include "AliTRD.h" #include "AliTRDgeometry.h" #include "AliTRDsegmentArray.h" +#include "AliTRDsegmentID.h" +#include "AliTRDdataArray.h" +#include "AliTRDarrayI.h" ClassImp(AliTRDsegmentArray) //_____________________________________________________________________________ -AliTRDsegmentArray::AliTRDsegmentArray():AliTRDsegmentArrayBase() +AliTRDsegmentArray::AliTRDsegmentArray() + :TNamed() + ,fSegment(0) + ,fTreeIndex(0) + ,fNSegment(0) + ,fTree(0) + ,fBranch(0) + ,fClass(0) { // // Default constructor @@ -67,15 +56,30 @@ AliTRDsegmentArray::AliTRDsegmentArray():AliTRDsegmentArrayBase() } //_____________________________________________________________________________ -AliTRDsegmentArray::AliTRDsegmentArray(Text_t *classname, Int_t n) - :AliTRDsegmentArrayBase(classname,n) +AliTRDsegmentArray::AliTRDsegmentArray(const char *classname, Int_t n) + :TNamed() + ,fSegment(0) + ,fTreeIndex(0) + ,fNSegment(0) + ,fTree(0) + ,fBranch(0) + ,fClass(0) { // - // Constructor creating an array of AliTRDdataArray of size + // Create an array of objects of . The class must inherit from + // AliTRDsegmentID. The second argument sets the number of entries in + // the array. // AliTRDdataArray *dataArray; + SetClass(classname); + + if (MakeArray(n) == kFALSE) { + AliError(Form("Cannot allocate %d segments in memory",n)); + return; + } + for (Int_t i = 0; i < n; i++) { dataArray = (AliTRDdataArray *) AddSegment(i); } @@ -84,6 +88,13 @@ AliTRDsegmentArray::AliTRDsegmentArray(Text_t *classname, Int_t n) //_____________________________________________________________________________ AliTRDsegmentArray::AliTRDsegmentArray(AliTRDsegmentArray &a) + :TNamed(a) + ,fSegment(a.fSegment) + ,fTreeIndex(a.fTreeIndex) + ,fNSegment(a.fNSegment) + ,fTree(a.fTree) + ,fBranch(a.fBranch) + ,fClass(a.fClass) { // // AliTRDsegmentArray copy constructor @@ -99,16 +110,423 @@ AliTRDsegmentArray::~AliTRDsegmentArray() // // AliTRDsegmentArray destructor // + + // Needed ???? + //Delete(); + + if (fNSegment) { + fSegment->Delete(); + delete fSegment; + } + + if (fTreeIndex) { + delete fTreeIndex; + } + +} + +//_____________________________________________________________________________ +AliTRDsegmentArray &AliTRDsegmentArray::operator=(const AliTRDsegmentArray &a) +{ + // + // Assignment operator + // + + if (this != &a) ((AliTRDsegmentArray &) a).Copy(*this); + return *this; + } //_____________________________________________________________________________ -void AliTRDsegmentArray::Copy(TObject &a) +void AliTRDsegmentArray::Copy(TObject &a) const { // // Copy function // - AliTRDsegmentArrayBase::Copy(a); + TNamed::Copy(a); + + fSegment->Copy(*((AliTRDsegmentArray &) a).fSegment); + fTreeIndex->Copy(*((AliTRDsegmentArray &) a).fTreeIndex); + fClass->Copy(*((AliTRDsegmentArray &) a).fClass); + + ((AliTRDsegmentArray &) a).fNSegment = fNSegment; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::SetClass(const Char_t *classname) +{ + // + // Sets the classname of the stored object + // + + if (fTree != 0) { + delete fTree; + fTree = 0; + fBranch = 0; + delete fTreeIndex; + fTreeIndex = 0; + } + if (fSegment != 0) { + fSegment->Delete(); + delete fSegment; + fSegment = 0; + } + + 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; + +} + +//_____________________________________________________________________________ +AliTRDsegmentID *AliTRDsegmentArray::NewSegment() +{ + // + // Create a new object according to the class information + // + + if (fClass == 0) { + return 0; + } + + AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New(); + + if (segment == 0) { + return 0; + } + else { + return segment; + } + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::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->IsA()->InheritsFrom(fClass))) { + AliError(Form("added class %s is not of proper type" + ,segment->IsA()->GetName())); + return kFALSE; + } + + fSegment->AddAt(segment,segment->GetID()); + fNSegment = fSegment->GetLast() + 1; + + return kTRUE; + +} + +//_____________________________________________________________________________ +AliTRDsegmentID *AliTRDsegmentArray::AddSegment(Int_t index) +{ + // + // Add a segment to the array + // + + if (fSegment == 0) { + return 0; + } + if (fClass == 0) { + return 0; + } + + AliTRDsegmentID *segment = NewSegment(); + if (segment == 0) { + return 0; + } + + fSegment->AddAt(segment,index); + segment->SetID(index); + fNSegment = fSegment->GetLast() + 1; + + return segment; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::MakeArray(Int_t n) +{ + // + // Create an array of pointers to the segments + // + + if (fSegment) { + fSegment->Delete(); + delete fSegment; + } + if (fTreeIndex) delete fTreeIndex; + + fSegment = new TObjArray(n); + fTreeIndex = new AliTRDarrayI(); + fTreeIndex->Set(n); + fNSegment = n; + if ((fSegment) && (fTreeIndex)) { + return kTRUE; + } + else { + return kFALSE; + } + +} + +//_____________________________________________________________________________ +void AliTRDsegmentArray::ClearSegment(Int_t index) +{ + // + // Remove a segment from the active memory + // + + if (fSegment->At(index)) { + fClass->Destructor(fSegment->RemoveAt(index)); + } + +} + +//_____________________________________________________________________________ +void AliTRDsegmentArray::MakeTree(char *file) +{ + // + // Create a tree for the segment + // + + AliTRDsegmentID *psegment = NewSegment(); + + 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); + } + + delete psegment; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::ConnectTree(const char *treeName) +{ + // + // Connect a tree from current directory + // + + if (fTree) { + delete fTree; + fTree = 0; + fBranch = 0; + } + + fTree = (TTree *) gDirectory->Get(treeName); + if (fTree == 0) { + return kFALSE; + } + fBranch = fTree->GetBranch("Segment"); + if (fBranch == 0) { + return kFALSE; + } + + MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries()))); + + return kTRUE; + +} + +//_____________________________________________________________________________ +AliTRDsegmentID *AliTRDsegmentArray::LoadSegment(Int_t index) +{ + // + // Load a segment with index into the memory + // + + 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; + } + + 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) { + return 0; + } + else { + treeIndex--; + } + fBranch->SetAddress(&s); + fTree->GetEvent(treeIndex); + fSegment->AddAt((TObject*) s, index); + } + else { + return 0; + } + + return s; + +} + +//_____________________________________________________________________________ +AliTRDsegmentID *AliTRDsegmentArray::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; + } + + AliTRDsegmentID *s = NewSegment(); + if (s) { + fBranch->SetAddress(&s); + fTree->GetEvent(index); + } + else { + return 0; + } + + Int_t nindex = s->GetID(); + ClearSegment(nindex); + fSegment->AddAt((TObject *) s, nindex); + + return s; + +} + +//_____________________________________________________________________________ +void AliTRDsegmentArray::StoreSegment(Int_t index) +{ + // + // Make a segment persistent + // + + const AliTRDsegmentID *kSegment = (*this)[index]; + if (kSegment == 0) { + return; + } + if (fTree == 0) { + MakeTree(); + } + fBranch->SetAddress(&kSegment); + fTree->Fill(); + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::MakeDictionary(Int_t size) +{ + // + // Create an index table for the tree + // + + if (size < 1) { + return kFALSE; + } + if (fTreeIndex) { + delete fTreeIndex; + } + + fTreeIndex = new AliTRDarrayI(); + fTreeIndex->Set(size); + + AliTRDsegmentID segment; + AliTRDsegmentID *psegment = &segment; + + fBranch->SetAddress(&psegment); + TBranch *brindix = fTree->GetBranch("fSegmentID"); + + Int_t nevent = (Int_t) fTree->GetEntries(); + for (Int_t i = 0; i < nevent; i++) { + brindix->GetEvent(i); + Int_t treeIndex = segment.GetID(); + if (fTreeIndex->fN < treeIndex) { + fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1); + } + (*fTreeIndex)[treeIndex] = i + 1; + } + + return kTRUE; + +} + +//_____________________________________________________________________________ +const AliTRDsegmentID * AliTRDsegmentArray::operator[](Int_t i) const +{ + // + // Returns a segment with the given index + // + + if ((i < 0) || + (i >= fNSegment)) { + return 0; + } + + return (AliTRDsegmentID *) fSegment->At(i); + +} + +//_____________________________________________________________________________ +const AliTRDsegmentID *AliTRDsegmentArray::At(Int_t i) const +{ + // + // Returns a segment with the given index + // + + if ((i < 0) || + (i >= fNSegment)) { + return 0; + } + + return (AliTRDsegmentID *) fSegment->At(i); } @@ -126,20 +544,26 @@ void AliTRDsegmentArray::Delete() } //_____________________________________________________________________________ -Bool_t AliTRDsegmentArray::LoadArray(const Char_t *branchname) +Bool_t AliTRDsegmentArray::LoadArray(const Char_t *branchname, TTree *tree) { // // Loads all segments of the array from the branch of - // the digits tree + // the digits tree // - // Connect the digits tree - fTree = gAlice->TreeD(); - if (!fTree) return kFALSE; + fTree = tree; + + if (!fTree) { + AliError("Digits tree is not defined\n"); + return kFALSE; + } // Get the branch fBranch = fTree->GetBranch(branchname); - if (!fBranch) return kFALSE; + if (!fBranch) { + AliError(Form("Branch %s is not defined\n",branchname)); + return kFALSE; + } // Loop through all segments and read them from the tree Bool_t status = kTRUE; @@ -158,26 +582,32 @@ Bool_t AliTRDsegmentArray::LoadArray(const Char_t *branchname) } //_____________________________________________________________________________ -Bool_t AliTRDsegmentArray::StoreArray(const Char_t *branchname) +Bool_t AliTRDsegmentArray::StoreArray(const Char_t *branchname, TTree *tree) { // // Stores all segments of the array in the branch of - // the digits tree + // the digits tree // - // Connect the digits tree - fTree = gAlice->TreeD(); - if (!fTree) return kFALSE; + fTree = tree; + + if (!fTree) { + AliError("Digits tree is not defined\n"); + return kFALSE; + } // Get the branch fBranch = fTree->GetBranch(branchname); - if (!fBranch) return kFALSE; + if (!fBranch) { + AliError(Form("Branch %s is not defined\n",branchname)); + return kFALSE; + } // Loop through all segments and fill them into the tree Bool_t status = kTRUE; for (Int_t iSegment = 0; iSegment < fNSegment; iSegment++) { const AliTRDdataArray *kDataArray = - (AliTRDdataArray *) AliTRDsegmentArrayBase::At(iSegment); + (AliTRDdataArray *) AliTRDsegmentArray::At(iSegment); if (!kDataArray) { status = kFALSE; break; @@ -197,31 +627,20 @@ AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t det) const // Returns the data array for a given detector // - return ((AliTRDdataArray *) AliTRDsegmentArrayBase::At(det)); + return ((AliTRDdataArray *) AliTRDsegmentArray::At(det)); } //_____________________________________________________________________________ AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t pla - , Int_t cha, Int_t sec) const + , Int_t cha + , Int_t sec) const { // // Returns the data array for a given detector // - if (gAlice) { - - AliTRDgeometry *geo = ((AliTRD*) gAlice->GetDetector("TRD"))->GetGeometry(); - Int_t det = geo->GetDetector(pla,cha,sec); - return GetDataArray(det); - - } - else { - - printf("AliTRDsegmentArray::GetDigits -- "); - printf("gAlice is not defined\n"); - return NULL; - - } + Int_t det = AliTRDgeometry::GetDetector(pla,cha,sec); + return GetDataArray(det); }