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 Revision 1.12.6.1 2002/06/10 15:28:58 hristov
21 Revision 1.13 2002/03/28 14:59:07 cblume
24 Revision 1.12 2002/02/12 16:06:45 cblume
27 Revision 1.11 2001/11/19 08:44:08 cblume
28 Fix bugs reported by Rene
30 Revision 1.10 2001/08/30 09:31:22 hristov
31 The operator[] is replaced by At() or AddAt() in case of TObjArray.
33 Revision 1.9 2001/07/27 13:03:15 hristov
34 Default Branch split level set to 99
36 Revision 1.8 2001/01/26 19:56:57 hristov
37 Major upgrade of AliRoot code
39 Revision 1.7 2000/11/20 08:56:07 cblume
40 Cleanup of data arrays
42 Revision 1.6 2000/11/01 14:53:21 cblume
43 Merge with TRD-develop
45 Revision 1.1.4.3 2000/10/06 16:49:46 cblume
48 Revision 1.1.4.2 2000/10/04 16:34:58 cblume
49 Replace include files by forward declarations
51 Revision 1.5 2000/06/09 11:10:07 cblume
52 Compiler warnings and coding conventions, next round
54 Revision 1.4 2000/06/08 18:32:58 cblume
55 Make code compliant to coding conventions
57 Revision 1.3 2000/06/07 16:27:01 cblume
58 Try to remove compiler warnings on Sun and HP
60 Revision 1.2 2000/05/08 16:17:27 cblume
63 Revision 1.1.4.1 2000/05/08 14:55:03 cblume
66 Revision 1.1 2000/02/28 19:02:56 cblume
71 ///////////////////////////////////////////////////////////////////////////////
73 // Alice segment manager base class //
75 ///////////////////////////////////////////////////////////////////////////////
79 #include <TClonesArray.h>
80 #include <TDirectory.h>
84 #include "AliTRDarrayI.h"
85 #include "AliTRDsegmentID.h"
86 #include "AliTRDsegmentArrayBase.h"
88 ClassImp(AliTRDsegmentArrayBase)
90 //_____________________________________________________________________________
91 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase():TNamed()
94 // AliTRDsegmentArrayBase default constructor
106 //_____________________________________________________________________________
107 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n)
110 // Create an array of objects of <classname>. The class must inherit from
111 // AliTRDsegmentID. The second argument sets the number of entries in
124 if (MakeArray(n) == kFALSE) {
125 Error("AliTRDsegmentArrayBase","Cannot allocate %d segments in memory",n);
131 //_____________________________________________________________________________
132 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &a)
135 // AliTRDsegmentArrayBase copy constructor
138 ((AliTRDsegmentArrayBase &) a).Copy(*this);
142 //_____________________________________________________________________________
143 AliTRDsegmentArrayBase::~AliTRDsegmentArrayBase()
146 // AliTRDsegmentArrayBase destructor
154 //if (fTree) delete fTree;
155 if (fTreeIndex) delete fTreeIndex;
159 //_____________________________________________________________________________
160 AliTRDsegmentArrayBase &AliTRDsegmentArrayBase
161 ::operator=(const AliTRDsegmentArrayBase &a)
164 // Assignment operator
167 if (this != &a) ((AliTRDsegmentArrayBase &) a).Copy(*this);
172 //_____________________________________________________________________________
173 void AliTRDsegmentArrayBase::Copy(TObject &a)
181 fSegment->Copy(*((AliTRDsegmentArrayBase &) a).fSegment);
182 fTreeIndex->Copy(*((AliTRDsegmentArrayBase &) a).fTreeIndex);
183 fClass->Copy(*((AliTRDsegmentArrayBase &) a).fClass);
185 ((AliTRDsegmentArrayBase &) a).fNSegment = fNSegment;
189 //_____________________________________________________________________________
190 Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *classname)
193 // Sets the classname of the stored object
209 if (!gROOT) ::Fatal("AliTRDsegmentArrayBase::AliTRDsegmentArrayBase"
210 ,"ROOT system not initialized");
212 fClass = gROOT->GetClass(classname);
214 Error("AliTRDsegmentArrayBase","%s is not a valid class name",classname);
217 if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
218 Error("AliTRDsegmentArrayBase"
219 ,"%s does not inherit from AliTRDsegmentID",classname);
227 //_____________________________________________________________________________
228 AliTRDsegmentID *AliTRDsegmentArrayBase::NewSegment()
231 // Create a new object according to the class information
234 if (fClass == 0) return 0;
236 AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New();
237 if (segment == 0) return 0;
243 //_____________________________________________________________________________
244 Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment)
247 // Add a segment to the array
250 if (segment == 0) return kFALSE;
251 if (fSegment == 0) return kFALSE;
252 if (fClass == 0) return kFALSE;
254 if (!(segment->IsA()->InheritsFrom(fClass))) {
255 Error("AliTRDsegmentArrayBase","added class %s is not of proper type",
256 segment->IsA()->GetName());
260 fSegment->AddAt(segment,segment->GetID());
261 fNSegment = fSegment->GetLast() + 1;
267 //_____________________________________________________________________________
268 AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index)
271 // Add a segment to the array
274 if (fSegment == 0) return 0;
275 if (fClass == 0) return 0;
277 AliTRDsegmentID *segment = NewSegment();
278 if (segment == 0) return 0;
280 fSegment->AddAt(segment,index);
281 segment->SetID(index);
282 fNSegment = fSegment->GetLast() + 1;
288 //_____________________________________________________________________________
289 Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n)
292 // Create an array of pointers to the segments
299 if (fTreeIndex) delete fTreeIndex;
301 fSegment = new TObjArray(n);
302 fTreeIndex = new AliTRDarrayI();
305 if ((fSegment) && (fTreeIndex))
312 //_____________________________________________________________________________
313 void AliTRDsegmentArrayBase::ClearSegment(Int_t index)
316 // Remove a segment from the active memory
319 //PH if ((*fSegment)[index]){
320 //PH delete (*fSegment)[index]; // because problem with deleting TClonesArray
321 //PH fSegment->RemoveAt(index);
323 if (fSegment->At(index)){
324 delete fSegment->RemoveAt(index);
329 //_____________________________________________________________________________
330 void AliTRDsegmentArrayBase::MakeTree(char *file)
333 // Create a tree for the segment
336 AliTRDsegmentID *psegment = NewSegment();
338 if (fTree) delete fTree;
339 fTree = new TTree("Segment Tree","Tree with segments");
341 fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000);
343 fBranch->SetFile(file);
349 //_____________________________________________________________________________
350 Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName)
353 // Connect a tree from current directory
362 fTree = (TTree*) gDirectory->Get(treeName);
363 if (fTree == 0) return kFALSE;
364 fBranch = fTree->GetBranch("Segment");
365 if (fBranch == 0) return kFALSE;
367 MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries())));
373 //_____________________________________________________________________________
374 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index)
377 // Load a segment with index <index> into the memory
380 if (fTreeIndex == 0) MakeDictionary(3000);
382 // First try to load dictionary
383 if (fTreeIndex == 0) return 0;
384 if (fBranch == 0) return 0;
385 if (index > fTreeIndex->fN) return 0;
386 //PH AliTRDsegmentID *s = (AliTRDsegmentID*) (*fSegment)[index];
387 AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index);
388 if (s == 0) s = NewSegment();
392 Int_t treeIndex = (*fTreeIndex)[index];
397 fBranch->SetAddress(&s);
398 fTree->GetEvent(treeIndex);
399 //PH (*fSegment)[index] = (TObject*) s;
400 fSegment->AddAt((TObject*) s, index);
409 //_____________________________________________________________________________
410 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index)
413 // Load a segment at position <index> in the tree into the memory
416 if (fBranch == 0) return 0;
417 if (index > fTree->GetEntries()) return 0;
419 AliTRDsegmentID *s = NewSegment();
421 fBranch->SetAddress(&s);
422 fTree->GetEvent(index);
427 Int_t nindex = s->GetID();
428 ClearSegment(nindex);
429 //PH (*fSegment)[nindex] = (TObject *) s;
430 fSegment->AddAt((TObject *) s, nindex);
436 //_____________________________________________________________________________
437 void AliTRDsegmentArrayBase::StoreSegment(Int_t index)
440 // Make a segment persistent
443 const AliTRDsegmentID *kSegment = (*this)[index];
444 if (kSegment == 0) return;
445 if (fTree == 0) MakeTree();
446 fBranch->SetAddress(&kSegment);
451 //_____________________________________________________________________________
452 Bool_t AliTRDsegmentArrayBase::MakeDictionary(Int_t size)
455 // Create an index table for the tree
458 if (size < 1) return kFALSE;
459 if (fTreeIndex) delete fTreeIndex;
461 fTreeIndex = new AliTRDarrayI();
462 fTreeIndex->Set(size);
464 AliTRDsegmentID segment;
465 AliTRDsegmentID *psegment = &segment;
467 fBranch->SetAddress(&psegment);
468 TBranch *brindix = fTree->GetBranch("fSegmentID");
470 Int_t nevent = (Int_t) fTree->GetEntries();
471 for (Int_t i = 0; i < nevent; i++){
472 brindix->GetEvent(i);
473 Int_t treeIndex = segment.GetID();
474 if (fTreeIndex->fN < treeIndex)
475 fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1);
476 (*fTreeIndex)[treeIndex] = i + 1;
483 //_____________________________________________________________________________
484 const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i) const
487 // Returns a segment with the given index <i>
490 if ((i < 0) || (i >= fNSegment)) return 0;
491 return (AliTRDsegmentID *) fSegment->At(i);
495 //_____________________________________________________________________________
496 const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const
499 // Returns a segment with the given index <i>
502 if ((i < 0) || (i >= fNSegment)) return 0;
503 //PH return (AliTRDsegmentID *)((*fSegment)[i]);
504 return (AliTRDsegmentID *) fSegment->At(i);