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.10 2001/08/30 09:31:22 hristov
19 The operator[] is replaced by At() or AddAt() in case of TObjArray.
21 Revision 1.9 2001/07/27 13:03:15 hristov
22 Default Branch split level set to 99
24 Revision 1.8 2001/01/26 19:56:57 hristov
25 Major upgrade of AliRoot code
27 Revision 1.7 2000/11/20 08:56:07 cblume
28 Cleanup of data arrays
30 Revision 1.6 2000/11/01 14:53:21 cblume
31 Merge with TRD-develop
33 Revision 1.1.4.3 2000/10/06 16:49:46 cblume
36 Revision 1.1.4.2 2000/10/04 16:34:58 cblume
37 Replace include files by forward declarations
39 Revision 1.5 2000/06/09 11:10:07 cblume
40 Compiler warnings and coding conventions, next round
42 Revision 1.4 2000/06/08 18:32:58 cblume
43 Make code compliant to coding conventions
45 Revision 1.3 2000/06/07 16:27:01 cblume
46 Try to remove compiler warnings on Sun and HP
48 Revision 1.2 2000/05/08 16:17:27 cblume
51 Revision 1.1.4.1 2000/05/08 14:55:03 cblume
54 Revision 1.1 2000/02/28 19:02:56 cblume
59 ///////////////////////////////////////////////////////////////////////////////
61 // Alice segment manager base class //
63 ///////////////////////////////////////////////////////////////////////////////
67 #include <TClonesArray.h>
68 #include <TDirectory.h>
72 #include "AliTRDarrayI.h"
73 #include "AliTRDsegmentID.h"
74 #include "AliTRDsegmentArrayBase.h"
76 ClassImp(AliTRDsegmentArrayBase)
78 //_____________________________________________________________________________
79 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase():TNamed()
82 // AliTRDsegmentArrayBase default constructor
94 //_____________________________________________________________________________
95 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n)
98 // Create an array of objects of <classname>. The class must inherit from
99 // AliTRDsegmentID. The second argument sets the number of entries in
112 if (MakeArray(n) == kFALSE) {
113 Error("AliTRDsegmentArrayBase","Cannot allocate %d segments in memory",n);
119 //_____________________________________________________________________________
120 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &a)
123 // AliTRDsegmentArrayBase copy constructor
126 ((AliTRDsegmentArrayBase &) a).Copy(*this);
130 //_____________________________________________________________________________
131 AliTRDsegmentArrayBase::~AliTRDsegmentArrayBase()
134 // AliTRDsegmentArrayBase destructor
142 if (fTree) delete fTree;
143 if (fTreeIndex) delete fTreeIndex;
147 //_____________________________________________________________________________
148 AliTRDsegmentArrayBase &AliTRDsegmentArrayBase
149 ::operator=(const AliTRDsegmentArrayBase &a)
152 // Assignment operator
155 if (this != &a) ((AliTRDsegmentArrayBase &) a).Copy(*this);
160 //_____________________________________________________________________________
161 void AliTRDsegmentArrayBase::Copy(TObject &a)
169 fSegment->Copy(*((AliTRDsegmentArrayBase &) a).fSegment);
170 fTreeIndex->Copy(*((AliTRDsegmentArrayBase &) a).fTreeIndex);
171 fClass->Copy(*((AliTRDsegmentArrayBase &) a).fClass);
173 ((AliTRDsegmentArrayBase &) a).fNSegment = fNSegment;
177 //_____________________________________________________________________________
178 Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *classname)
181 // Sets the classname of the stored object
197 if (!gROOT) ::Fatal("AliTRDsegmentArrayBase::AliTRDsegmentArrayBase"
198 ,"ROOT system not initialized");
200 fClass = gROOT->GetClass(classname);
202 Error("AliTRDsegmentArrayBase","%s is not a valid class name",classname);
205 if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
206 Error("AliTRDsegmentArrayBase"
207 ,"%s does not inherit from AliTRDsegmentID",classname);
215 //_____________________________________________________________________________
216 AliTRDsegmentID * AliTRDsegmentArrayBase::NewSegment()
219 // Create a new object according to the class information
222 if (fClass == 0) return 0;
224 AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New();
225 if (segment == 0) return 0;
231 //_____________________________________________________________________________
232 Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment)
235 // Add a segment to the array
238 if (segment == 0) return kFALSE;
239 if (fSegment == 0) return kFALSE;
240 if (fClass == 0) return kFALSE;
242 if (!(segment->IsA()->InheritsFrom(fClass))) {
243 Error("AliTRDsegmentArrayBase","added class %s is not of proper type",
244 segment->IsA()->GetName());
248 fSegment->AddAt(segment,segment->GetID());
249 fNSegment = fSegment->GetLast() + 1;
255 //_____________________________________________________________________________
256 AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index)
259 // Add a segment to the array
262 if (fSegment == 0) return 0;
263 if (fClass == 0) return 0;
265 AliTRDsegmentID *segment = NewSegment();
266 if (segment == 0) return 0;
268 fSegment->AddAt(segment,index);
269 segment->SetID(index);
270 fNSegment = fSegment->GetLast() + 1;
276 //_____________________________________________________________________________
277 Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n)
280 // Create an array of pointers to the segments
287 if (fTreeIndex) delete fTreeIndex;
289 fSegment = new TObjArray(n);
290 fTreeIndex = new AliTRDarrayI();
293 if ((fSegment) && (fTreeIndex))
300 //_____________________________________________________________________________
301 void AliTRDsegmentArrayBase::ClearSegment(Int_t index)
304 // Remove a segment from the active memory
307 //PH if ((*fSegment)[index]){
308 //PH delete (*fSegment)[index]; // because problem with deleting TClonesArray
309 //PH fSegment->RemoveAt(index);
311 if (fSegment->At(index)){
312 delete fSegment->RemoveAt(index);
317 //_____________________________________________________________________________
318 void AliTRDsegmentArrayBase::MakeTree(char *file)
321 // Create a tree for the segment
324 AliTRDsegmentID *psegment = NewSegment();
326 if (fTree) delete fTree;
327 fTree = new TTree("Segment Tree","Tree with segments");
329 fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000);
331 fBranch->SetFile(file);
337 //_____________________________________________________________________________
338 Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName)
341 // Connect a tree from current directory
350 fTree = (TTree*) gDirectory->Get(treeName);
351 if (fTree == 0) return kFALSE;
352 fBranch = fTree->GetBranch("Segment");
353 if (fBranch == 0) return kFALSE;
355 MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries())));
361 //_____________________________________________________________________________
362 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index)
365 // Load a segment with index <index> into the memory
368 if (fTreeIndex == 0) MakeDictionary(3000);
370 // First try to load dictionary
371 if (fTreeIndex == 0) return 0;
372 if (fBranch == 0) return 0;
373 if (index > fTreeIndex->fN) return 0;
374 //PH AliTRDsegmentID *s = (AliTRDsegmentID*) (*fSegment)[index];
375 AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index);
376 if (s == 0) s = NewSegment();
380 Int_t treeIndex = (*fTreeIndex)[index];
385 fBranch->SetAddress(&s);
386 fTree->GetEvent(treeIndex);
387 //PH (*fSegment)[index] = (TObject*) s;
388 fSegment->AddAt((TObject*) s, index);
397 //_____________________________________________________________________________
398 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index)
401 // Load a segment at position <index> in the tree into the memory
404 if (fBranch == 0) return 0;
405 if (index > fTree->GetEntries()) return 0;
407 AliTRDsegmentID *s = NewSegment();
409 fBranch->SetAddress(&s);
410 fTree->GetEvent(index);
415 Int_t nindex = s->GetID();
416 ClearSegment(nindex);
417 //PH (*fSegment)[nindex] = (TObject *) s;
418 fSegment->AddAt((TObject *) s, nindex);
424 //_____________________________________________________________________________
425 void AliTRDsegmentArrayBase::StoreSegment(Int_t index)
428 // Make a segment persistent
431 const AliTRDsegmentID *kSegment = (*this)[index];
432 if (kSegment == 0) return;
433 if (fTree == 0) MakeTree();
434 fBranch->SetAddress(&kSegment);
439 //_____________________________________________________________________________
440 Bool_t AliTRDsegmentArrayBase::MakeDictionary(Int_t size)
443 // Create an index table for the tree
446 if (size < 1) return kFALSE;
447 if (fTreeIndex) delete fTreeIndex;
449 fTreeIndex = new AliTRDarrayI();
450 fTreeIndex->Set(size);
452 AliTRDsegmentID segment;
453 AliTRDsegmentID *psegment = &segment;
455 fBranch->SetAddress(&psegment);
456 TBranch *brindix = fTree->GetBranch("fSegmentID");
458 Int_t nevent = (Int_t) fTree->GetEntries();
459 for (Int_t i = 0; i < nevent; i++){
460 brindix->GetEvent(i);
461 Int_t treeIndex = segment.GetID();
462 if (fTreeIndex->fN < treeIndex)
463 fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1);
464 (*fTreeIndex)[treeIndex] = i + 1;
471 //_____________________________________________________________________________
472 const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i)
475 // Returns a segment with the given index <i>
478 if ((i < 0) || (i >= fNSegment)) return 0;
479 return (AliTRDsegmentID *) fSegment->At(i);
483 //_____________________________________________________________________________
484 const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const
487 // Returns a segment with the given index <i>
490 if ((i < 0) || (i >= fNSegment)) return 0;
491 //PH return (AliTRDsegmentID *)((*fSegment)[i]);
492 return (AliTRDsegmentID *) fSegment->At(i);