1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // Alice segment manager class //
22 ////////////////////////////////////////////////////////////////////////////
26 #include <TClonesArray.h>
27 #include <TDirectory.h>
33 #include "AliTRDgeometry.h"
34 #include "AliTRDsegmentArray.h"
35 #include "AliTRDsegmentID.h"
36 #include "AliTRDdataArray.h"
37 #include "AliTRDarrayI.h"
39 ClassImp(AliTRDsegmentArray)
41 //_____________________________________________________________________________
42 AliTRDsegmentArray::AliTRDsegmentArray()
52 // Default constructor
57 //_____________________________________________________________________________
58 AliTRDsegmentArray::AliTRDsegmentArray(const char *classname, Int_t n)
68 // Create an array of objects of <classname>. The class must inherit from
69 // AliTRDsegmentID. The second argument sets the number of entries in
73 AliTRDdataArray *dataArray;
77 if (MakeArray(n) == kFALSE) {
78 AliError(Form("Cannot allocate %d segments in memory",n));
82 for (Int_t i = 0; i < n; i++) {
83 dataArray = (AliTRDdataArray *) AddSegment(i);
88 //_____________________________________________________________________________
89 AliTRDsegmentArray::AliTRDsegmentArray(AliTRDsegmentArray &a)
92 ,fTreeIndex(a.fTreeIndex)
93 ,fNSegment(a.fNSegment)
99 // AliTRDsegmentArray copy constructor
106 //_____________________________________________________________________________
107 AliTRDsegmentArray::~AliTRDsegmentArray()
110 // AliTRDsegmentArray destructor
126 //_____________________________________________________________________________
127 AliTRDsegmentArray &AliTRDsegmentArray::operator=(const AliTRDsegmentArray &a)
130 // Assignment operator
133 if (this != &a) ((AliTRDsegmentArray &) a).Copy(*this);
138 //_____________________________________________________________________________
139 void AliTRDsegmentArray::Copy(TObject &a) const
147 fSegment->Copy(*((AliTRDsegmentArray &) a).fSegment);
148 fTreeIndex->Copy(*((AliTRDsegmentArray &) a).fTreeIndex);
149 fClass->Copy(*((AliTRDsegmentArray &) a).fClass);
151 ((AliTRDsegmentArray &) a).fNSegment = fNSegment;
155 //_____________________________________________________________________________
156 Bool_t AliTRDsegmentArray::SetClass(const Char_t *classname)
159 // Sets the classname of the stored object
176 AliFatal("ROOT system not initialized");
180 fClass = gROOT->GetClass(classname);
182 AliError(Form("%s is not a valid class name",classname));
185 if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
186 AliError(Form("%s does not inherit from AliTRDsegmentID",classname));
194 //_____________________________________________________________________________
195 AliTRDsegmentID *AliTRDsegmentArray::NewSegment()
198 // Create a new object according to the class information
205 AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New();
216 //_____________________________________________________________________________
217 Bool_t AliTRDsegmentArray::AddSegment(AliTRDsegmentID *segment)
220 // Add a segment to the array
233 if (!(segment->IsA()->InheritsFrom(fClass))) {
234 AliError(Form("added class %s is not of proper type"
235 ,segment->IsA()->GetName()));
239 fSegment->AddAt(segment,segment->GetID());
240 fNSegment = fSegment->GetLast() + 1;
246 //_____________________________________________________________________________
247 AliTRDsegmentID *AliTRDsegmentArray::AddSegment(Int_t index)
250 // Add a segment to the array
260 AliTRDsegmentID *segment = NewSegment();
265 fSegment->AddAt(segment,index);
266 segment->SetID(index);
267 fNSegment = fSegment->GetLast() + 1;
273 //_____________________________________________________________________________
274 Bool_t AliTRDsegmentArray::MakeArray(Int_t n)
277 // Create an array of pointers to the segments
284 if (fTreeIndex) delete fTreeIndex;
286 fSegment = new TObjArray(n);
287 fTreeIndex = new AliTRDarrayI();
290 if ((fSegment) && (fTreeIndex)) {
299 //_____________________________________________________________________________
300 void AliTRDsegmentArray::ClearSegment(Int_t index)
303 // Remove a segment from the active memory
306 if (fSegment->At(index)) {
307 delete fSegment->RemoveAt(index);
312 //_____________________________________________________________________________
313 void AliTRDsegmentArray::MakeTree(char *file)
316 // Create a tree for the segment
319 AliTRDsegmentID *psegment = NewSegment();
325 fTree = new TTree("Segment Tree","Tree with segments");
326 fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000);
329 fBranch->SetFile(file);
336 //_____________________________________________________________________________
337 Bool_t AliTRDsegmentArray::ConnectTree(const char *treeName)
340 // Connect a tree from current directory
349 fTree = (TTree *) gDirectory->Get(treeName);
353 fBranch = fTree->GetBranch("Segment");
358 MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries())));
364 //_____________________________________________________________________________
365 AliTRDsegmentID *AliTRDsegmentArray::LoadSegment(Int_t index)
368 // Load a segment with index <index> into the memory
371 if (fTreeIndex == 0) {
372 MakeDictionary(3000);
375 // First try to load dictionary
376 if (fTreeIndex == 0) {
382 if (index > fTreeIndex->fN) {
386 AliTRDsegmentID *s = (AliTRDsegmentID *) fSegment->At(index);
393 Int_t treeIndex = (*fTreeIndex)[index];
400 fBranch->SetAddress(&s);
401 fTree->GetEvent(treeIndex);
402 fSegment->AddAt((TObject*) s, index);
412 //_____________________________________________________________________________
413 AliTRDsegmentID *AliTRDsegmentArray::LoadEntry(Int_t index)
416 // Load a segment at position <index> in the tree into the memory
422 if (index > fTree->GetEntries()) {
426 AliTRDsegmentID *s = NewSegment();
428 fBranch->SetAddress(&s);
429 fTree->GetEvent(index);
435 Int_t nindex = s->GetID();
436 ClearSegment(nindex);
437 fSegment->AddAt((TObject *) s, nindex);
443 //_____________________________________________________________________________
444 void AliTRDsegmentArray::StoreSegment(Int_t index)
447 // Make a segment persistent
450 const AliTRDsegmentID *kSegment = (*this)[index];
457 fBranch->SetAddress(&kSegment);
462 //_____________________________________________________________________________
463 Bool_t AliTRDsegmentArray::MakeDictionary(Int_t size)
466 // Create an index table for the tree
476 fTreeIndex = new AliTRDarrayI();
477 fTreeIndex->Set(size);
479 AliTRDsegmentID segment;
480 AliTRDsegmentID *psegment = &segment;
482 fBranch->SetAddress(&psegment);
483 TBranch *brindix = fTree->GetBranch("fSegmentID");
485 Int_t nevent = (Int_t) fTree->GetEntries();
486 for (Int_t i = 0; i < nevent; i++) {
487 brindix->GetEvent(i);
488 Int_t treeIndex = segment.GetID();
489 if (fTreeIndex->fN < treeIndex) {
490 fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1);
492 (*fTreeIndex)[treeIndex] = i + 1;
499 //_____________________________________________________________________________
500 const AliTRDsegmentID * AliTRDsegmentArray::operator[](Int_t i) const
503 // Returns a segment with the given index <i>
511 return (AliTRDsegmentID *) fSegment->At(i);
515 //_____________________________________________________________________________
516 const AliTRDsegmentID *AliTRDsegmentArray::At(Int_t i) const
519 // Returns a segment with the given index <i>
527 return (AliTRDsegmentID *) fSegment->At(i);
531 //_____________________________________________________________________________
532 void AliTRDsegmentArray::Delete()
535 // Deletes all detector segments from the array
538 for (Int_t iDet = 0; iDet < fNSegment; iDet++) {
544 //_____________________________________________________________________________
545 Bool_t AliTRDsegmentArray::LoadArray(const Char_t *branchname, TTree *tree)
548 // Loads all segments of the array from the branch <branchname> of
549 // the digits tree <tree>
555 AliError("Digits tree is not defined\n");
560 fBranch = fTree->GetBranch(branchname);
562 AliError(Form("Branch %s is not defined\n",branchname));
566 // Loop through all segments and read them from the tree
567 Bool_t status = kTRUE;
568 for (Int_t iSegment = 0; iSegment < fNSegment; iSegment++) {
569 AliTRDdataArray *dataArray = (AliTRDdataArray *) fSegment->At(iSegment);
574 fBranch->SetAddress(&dataArray);
575 fBranch->GetEntry(iSegment);
582 //_____________________________________________________________________________
583 Bool_t AliTRDsegmentArray::StoreArray(const Char_t *branchname, TTree *tree)
586 // Stores all segments of the array in the branch <branchname> of
587 // the digits tree <tree>
593 AliError("Digits tree is not defined\n");
598 fBranch = fTree->GetBranch(branchname);
600 AliError(Form("Branch %s is not defined\n",branchname));
604 // Loop through all segments and fill them into the tree
605 Bool_t status = kTRUE;
606 for (Int_t iSegment = 0; iSegment < fNSegment; iSegment++) {
607 const AliTRDdataArray *kDataArray =
608 (AliTRDdataArray *) AliTRDsegmentArray::At(iSegment);
613 fBranch->SetAddress(&kDataArray);
621 //_____________________________________________________________________________
622 AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t det) const
625 // Returns the data array for a given detector
628 return ((AliTRDdataArray *) AliTRDsegmentArray::At(det));
632 //_____________________________________________________________________________
633 AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t pla
638 // Returns the data array for a given detector
641 Int_t det = AliTRDgeometry::GetDetector(pla,cha,sec);
642 return GetDataArray(det);