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 2002/02/12 16:06:45 cblume
21 Revision 1.11 2001/11/19 08:44:08 cblume
22 Fix bugs reported by Rene
24 Revision 1.10 2001/08/30 09:31:22 hristov
25 The operator[] is replaced by At() or AddAt() in case of TObjArray.
27 Revision 1.9 2001/07/27 13:03:15 hristov
28 Default Branch split level set to 99
30 Revision 1.8 2001/01/26 19:56:57 hristov
31 Major upgrade of AliRoot code
33 Revision 1.7 2000/11/20 08:56:07 cblume
34 Cleanup of data arrays
36 Revision 1.6 2000/11/01 14:53:21 cblume
37 Merge with TRD-develop
39 Revision 1.1.4.3 2000/10/06 16:49:46 cblume
42 Revision 1.1.4.2 2000/10/04 16:34:58 cblume
43 Replace include files by forward declarations
45 Revision 1.5 2000/06/09 11:10:07 cblume
46 Compiler warnings and coding conventions, next round
48 Revision 1.4 2000/06/08 18:32:58 cblume
49 Make code compliant to coding conventions
51 Revision 1.3 2000/06/07 16:27:01 cblume
52 Try to remove compiler warnings on Sun and HP
54 Revision 1.2 2000/05/08 16:17:27 cblume
57 Revision 1.1.4.1 2000/05/08 14:55:03 cblume
60 Revision 1.1 2000/02/28 19:02:56 cblume
65 ///////////////////////////////////////////////////////////////////////////////
67 // Alice segment manager base class //
69 ///////////////////////////////////////////////////////////////////////////////
73 #include <TClonesArray.h>
74 #include <TDirectory.h>
78 #include "AliTRDarrayI.h"
79 #include "AliTRDsegmentID.h"
80 #include "AliTRDsegmentArrayBase.h"
82 ClassImp(AliTRDsegmentArrayBase)
84 //_____________________________________________________________________________
85 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase():TNamed()
88 // AliTRDsegmentArrayBase default constructor
100 //_____________________________________________________________________________
101 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n)
104 // Create an array of objects of <classname>. The class must inherit from
105 // AliTRDsegmentID. The second argument sets the number of entries in
118 if (MakeArray(n) == kFALSE) {
119 Error("AliTRDsegmentArrayBase","Cannot allocate %d segments in memory",n);
125 //_____________________________________________________________________________
126 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &a)
129 // AliTRDsegmentArrayBase copy constructor
132 ((AliTRDsegmentArrayBase &) a).Copy(*this);
136 //_____________________________________________________________________________
137 AliTRDsegmentArrayBase::~AliTRDsegmentArrayBase()
140 // AliTRDsegmentArrayBase destructor
148 //if (fTree) delete fTree;
149 if (fTreeIndex) delete fTreeIndex;
153 //_____________________________________________________________________________
154 AliTRDsegmentArrayBase &AliTRDsegmentArrayBase
155 ::operator=(const AliTRDsegmentArrayBase &a)
158 // Assignment operator
161 if (this != &a) ((AliTRDsegmentArrayBase &) a).Copy(*this);
166 //_____________________________________________________________________________
167 void AliTRDsegmentArrayBase::Copy(TObject &a)
175 fSegment->Copy(*((AliTRDsegmentArrayBase &) a).fSegment);
176 fTreeIndex->Copy(*((AliTRDsegmentArrayBase &) a).fTreeIndex);
177 fClass->Copy(*((AliTRDsegmentArrayBase &) a).fClass);
179 ((AliTRDsegmentArrayBase &) a).fNSegment = fNSegment;
183 //_____________________________________________________________________________
184 Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *classname)
187 // Sets the classname of the stored object
203 if (!gROOT) ::Fatal("AliTRDsegmentArrayBase::AliTRDsegmentArrayBase"
204 ,"ROOT system not initialized");
206 fClass = gROOT->GetClass(classname);
208 Error("AliTRDsegmentArrayBase","%s is not a valid class name",classname);
211 if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
212 Error("AliTRDsegmentArrayBase"
213 ,"%s does not inherit from AliTRDsegmentID",classname);
221 //_____________________________________________________________________________
222 AliTRDsegmentID *AliTRDsegmentArrayBase::NewSegment()
225 // Create a new object according to the class information
228 if (fClass == 0) return 0;
230 AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New();
231 if (segment == 0) return 0;
237 //_____________________________________________________________________________
238 Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment)
241 // Add a segment to the array
244 if (segment == 0) return kFALSE;
245 if (fSegment == 0) return kFALSE;
246 if (fClass == 0) return kFALSE;
248 if (!(segment->IsA()->InheritsFrom(fClass))) {
249 Error("AliTRDsegmentArrayBase","added class %s is not of proper type",
250 segment->IsA()->GetName());
254 fSegment->AddAt(segment,segment->GetID());
255 fNSegment = fSegment->GetLast() + 1;
261 //_____________________________________________________________________________
262 AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index)
265 // Add a segment to the array
268 if (fSegment == 0) return 0;
269 if (fClass == 0) return 0;
271 AliTRDsegmentID *segment = NewSegment();
272 if (segment == 0) return 0;
274 fSegment->AddAt(segment,index);
275 segment->SetID(index);
276 fNSegment = fSegment->GetLast() + 1;
282 //_____________________________________________________________________________
283 Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n)
286 // Create an array of pointers to the segments
293 if (fTreeIndex) delete fTreeIndex;
295 fSegment = new TObjArray(n);
296 fTreeIndex = new AliTRDarrayI();
299 if ((fSegment) && (fTreeIndex))
306 //_____________________________________________________________________________
307 void AliTRDsegmentArrayBase::ClearSegment(Int_t index)
310 // Remove a segment from the active memory
313 //PH if ((*fSegment)[index]){
314 //PH delete (*fSegment)[index]; // because problem with deleting TClonesArray
315 //PH fSegment->RemoveAt(index);
317 if (fSegment->At(index)){
318 delete fSegment->RemoveAt(index);
323 //_____________________________________________________________________________
324 void AliTRDsegmentArrayBase::MakeTree(char *file)
327 // Create a tree for the segment
330 AliTRDsegmentID *psegment = NewSegment();
332 if (fTree) delete fTree;
333 fTree = new TTree("Segment Tree","Tree with segments");
335 fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000);
337 fBranch->SetFile(file);
343 //_____________________________________________________________________________
344 Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName)
347 // Connect a tree from current directory
356 fTree = (TTree*) gDirectory->Get(treeName);
357 if (fTree == 0) return kFALSE;
358 fBranch = fTree->GetBranch("Segment");
359 if (fBranch == 0) return kFALSE;
361 MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries())));
367 //_____________________________________________________________________________
368 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index)
371 // Load a segment with index <index> into the memory
374 if (fTreeIndex == 0) MakeDictionary(3000);
376 // First try to load dictionary
377 if (fTreeIndex == 0) return 0;
378 if (fBranch == 0) return 0;
379 if (index > fTreeIndex->fN) return 0;
380 //PH AliTRDsegmentID *s = (AliTRDsegmentID*) (*fSegment)[index];
381 AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index);
382 if (s == 0) s = NewSegment();
386 Int_t treeIndex = (*fTreeIndex)[index];
391 fBranch->SetAddress(&s);
392 fTree->GetEvent(treeIndex);
393 //PH (*fSegment)[index] = (TObject*) s;
394 fSegment->AddAt((TObject*) s, index);
403 //_____________________________________________________________________________
404 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index)
407 // Load a segment at position <index> in the tree into the memory
410 if (fBranch == 0) return 0;
411 if (index > fTree->GetEntries()) return 0;
413 AliTRDsegmentID *s = NewSegment();
415 fBranch->SetAddress(&s);
416 fTree->GetEvent(index);
421 Int_t nindex = s->GetID();
422 ClearSegment(nindex);
423 //PH (*fSegment)[nindex] = (TObject *) s;
424 fSegment->AddAt((TObject *) s, nindex);
430 //_____________________________________________________________________________
431 void AliTRDsegmentArrayBase::StoreSegment(Int_t index)
434 // Make a segment persistent
437 const AliTRDsegmentID *kSegment = (*this)[index];
438 if (kSegment == 0) return;
439 if (fTree == 0) MakeTree();
440 fBranch->SetAddress(&kSegment);
445 //_____________________________________________________________________________
446 Bool_t AliTRDsegmentArrayBase::MakeDictionary(Int_t size)
449 // Create an index table for the tree
452 if (size < 1) return kFALSE;
453 if (fTreeIndex) delete fTreeIndex;
455 fTreeIndex = new AliTRDarrayI();
456 fTreeIndex->Set(size);
458 AliTRDsegmentID segment;
459 AliTRDsegmentID *psegment = &segment;
461 fBranch->SetAddress(&psegment);
462 TBranch *brindix = fTree->GetBranch("fSegmentID");
464 Int_t nevent = (Int_t) fTree->GetEntries();
465 for (Int_t i = 0; i < nevent; i++){
466 brindix->GetEvent(i);
467 Int_t treeIndex = segment.GetID();
468 if (fTreeIndex->fN < treeIndex)
469 fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1);
470 (*fTreeIndex)[treeIndex] = i + 1;
477 //_____________________________________________________________________________
478 const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i) const
481 // Returns a segment with the given index <i>
484 if ((i < 0) || (i >= fNSegment)) return 0;
485 return (AliTRDsegmentID *) fSegment->At(i);
489 //_____________________________________________________________________________
490 const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const
493 // Returns a segment with the given index <i>
496 if ((i < 0) || (i >= fNSegment)) return 0;
497 //PH return (AliTRDsegmentID *)((*fSegment)[i]);
498 return (AliTRDsegmentID *) fSegment->At(i);