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.11 2001/11/19 08:44:08 cblume
19 Fix bugs reported by Rene
21 Revision 1.10 2001/08/30 09:31:22 hristov
22 The operator[] is replaced by At() or AddAt() in case of TObjArray.
24 Revision 1.9 2001/07/27 13:03:15 hristov
25 Default Branch split level set to 99
27 Revision 1.8 2001/01/26 19:56:57 hristov
28 Major upgrade of AliRoot code
30 Revision 1.7 2000/11/20 08:56:07 cblume
31 Cleanup of data arrays
33 Revision 1.6 2000/11/01 14:53:21 cblume
34 Merge with TRD-develop
36 Revision 1.1.4.3 2000/10/06 16:49:46 cblume
39 Revision 1.1.4.2 2000/10/04 16:34:58 cblume
40 Replace include files by forward declarations
42 Revision 1.5 2000/06/09 11:10:07 cblume
43 Compiler warnings and coding conventions, next round
45 Revision 1.4 2000/06/08 18:32:58 cblume
46 Make code compliant to coding conventions
48 Revision 1.3 2000/06/07 16:27:01 cblume
49 Try to remove compiler warnings on Sun and HP
51 Revision 1.2 2000/05/08 16:17:27 cblume
54 Revision 1.1.4.1 2000/05/08 14:55:03 cblume
57 Revision 1.1 2000/02/28 19:02:56 cblume
62 ///////////////////////////////////////////////////////////////////////////////
64 // Alice segment manager base class //
66 ///////////////////////////////////////////////////////////////////////////////
70 #include <TClonesArray.h>
71 #include <TDirectory.h>
75 #include "AliTRDarrayI.h"
76 #include "AliTRDsegmentID.h"
77 #include "AliTRDsegmentArrayBase.h"
79 ClassImp(AliTRDsegmentArrayBase)
81 //_____________________________________________________________________________
82 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase():TNamed()
85 // AliTRDsegmentArrayBase default constructor
97 //_____________________________________________________________________________
98 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n)
101 // Create an array of objects of <classname>. The class must inherit from
102 // AliTRDsegmentID. The second argument sets the number of entries in
115 if (MakeArray(n) == kFALSE) {
116 Error("AliTRDsegmentArrayBase","Cannot allocate %d segments in memory",n);
122 //_____________________________________________________________________________
123 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &a)
126 // AliTRDsegmentArrayBase copy constructor
129 ((AliTRDsegmentArrayBase &) a).Copy(*this);
133 //_____________________________________________________________________________
134 AliTRDsegmentArrayBase::~AliTRDsegmentArrayBase()
137 // AliTRDsegmentArrayBase destructor
145 //if (fTree) delete fTree;
146 if (fTreeIndex) delete fTreeIndex;
150 //_____________________________________________________________________________
151 AliTRDsegmentArrayBase &AliTRDsegmentArrayBase
152 ::operator=(const AliTRDsegmentArrayBase &a)
155 // Assignment operator
158 if (this != &a) ((AliTRDsegmentArrayBase &) a).Copy(*this);
163 //_____________________________________________________________________________
164 void AliTRDsegmentArrayBase::Copy(TObject &a)
172 fSegment->Copy(*((AliTRDsegmentArrayBase &) a).fSegment);
173 fTreeIndex->Copy(*((AliTRDsegmentArrayBase &) a).fTreeIndex);
174 fClass->Copy(*((AliTRDsegmentArrayBase &) a).fClass);
176 ((AliTRDsegmentArrayBase &) a).fNSegment = fNSegment;
180 //_____________________________________________________________________________
181 Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *classname)
184 // Sets the classname of the stored object
200 if (!gROOT) ::Fatal("AliTRDsegmentArrayBase::AliTRDsegmentArrayBase"
201 ,"ROOT system not initialized");
203 fClass = gROOT->GetClass(classname);
205 Error("AliTRDsegmentArrayBase","%s is not a valid class name",classname);
208 if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
209 Error("AliTRDsegmentArrayBase"
210 ,"%s does not inherit from AliTRDsegmentID",classname);
218 //_____________________________________________________________________________
219 AliTRDsegmentID *AliTRDsegmentArrayBase::NewSegment()
222 // Create a new object according to the class information
225 if (fClass == 0) return 0;
227 AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New();
228 if (segment == 0) return 0;
234 //_____________________________________________________________________________
235 Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment)
238 // Add a segment to the array
241 if (segment == 0) return kFALSE;
242 if (fSegment == 0) return kFALSE;
243 if (fClass == 0) return kFALSE;
245 if (!(segment->IsA()->InheritsFrom(fClass))) {
246 Error("AliTRDsegmentArrayBase","added class %s is not of proper type",
247 segment->IsA()->GetName());
251 fSegment->AddAt(segment,segment->GetID());
252 fNSegment = fSegment->GetLast() + 1;
258 //_____________________________________________________________________________
259 AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index)
262 // Add a segment to the array
265 if (fSegment == 0) return 0;
266 if (fClass == 0) return 0;
268 AliTRDsegmentID *segment = NewSegment();
269 if (segment == 0) return 0;
271 fSegment->AddAt(segment,index);
272 segment->SetID(index);
273 fNSegment = fSegment->GetLast() + 1;
279 //_____________________________________________________________________________
280 Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n)
283 // Create an array of pointers to the segments
290 if (fTreeIndex) delete fTreeIndex;
292 fSegment = new TObjArray(n);
293 fTreeIndex = new AliTRDarrayI();
296 if ((fSegment) && (fTreeIndex))
303 //_____________________________________________________________________________
304 void AliTRDsegmentArrayBase::ClearSegment(Int_t index)
307 // Remove a segment from the active memory
310 //PH if ((*fSegment)[index]){
311 //PH delete (*fSegment)[index]; // because problem with deleting TClonesArray
312 //PH fSegment->RemoveAt(index);
314 if (fSegment->At(index)){
315 delete fSegment->RemoveAt(index);
320 //_____________________________________________________________________________
321 void AliTRDsegmentArrayBase::MakeTree(char *file)
324 // Create a tree for the segment
327 AliTRDsegmentID *psegment = NewSegment();
329 if (fTree) delete fTree;
330 fTree = new TTree("Segment Tree","Tree with segments");
332 fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000);
334 fBranch->SetFile(file);
340 //_____________________________________________________________________________
341 Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName)
344 // Connect a tree from current directory
353 fTree = (TTree*) gDirectory->Get(treeName);
354 if (fTree == 0) return kFALSE;
355 fBranch = fTree->GetBranch("Segment");
356 if (fBranch == 0) return kFALSE;
358 MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries())));
364 //_____________________________________________________________________________
365 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index)
368 // Load a segment with index <index> into the memory
371 if (fTreeIndex == 0) MakeDictionary(3000);
373 // First try to load dictionary
374 if (fTreeIndex == 0) return 0;
375 if (fBranch == 0) return 0;
376 if (index > fTreeIndex->fN) return 0;
377 //PH AliTRDsegmentID *s = (AliTRDsegmentID*) (*fSegment)[index];
378 AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index);
379 if (s == 0) s = NewSegment();
383 Int_t treeIndex = (*fTreeIndex)[index];
388 fBranch->SetAddress(&s);
389 fTree->GetEvent(treeIndex);
390 //PH (*fSegment)[index] = (TObject*) s;
391 fSegment->AddAt((TObject*) s, index);
400 //_____________________________________________________________________________
401 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index)
404 // Load a segment at position <index> in the tree into the memory
407 if (fBranch == 0) return 0;
408 if (index > fTree->GetEntries()) return 0;
410 AliTRDsegmentID *s = NewSegment();
412 fBranch->SetAddress(&s);
413 fTree->GetEvent(index);
418 Int_t nindex = s->GetID();
419 ClearSegment(nindex);
420 //PH (*fSegment)[nindex] = (TObject *) s;
421 fSegment->AddAt((TObject *) s, nindex);
427 //_____________________________________________________________________________
428 void AliTRDsegmentArrayBase::StoreSegment(Int_t index)
431 // Make a segment persistent
434 const AliTRDsegmentID *kSegment = (*this)[index];
435 if (kSegment == 0) return;
436 if (fTree == 0) MakeTree();
437 fBranch->SetAddress(&kSegment);
442 //_____________________________________________________________________________
443 Bool_t AliTRDsegmentArrayBase::MakeDictionary(Int_t size)
446 // Create an index table for the tree
449 if (size < 1) return kFALSE;
450 if (fTreeIndex) delete fTreeIndex;
452 fTreeIndex = new AliTRDarrayI();
453 fTreeIndex->Set(size);
455 AliTRDsegmentID segment;
456 AliTRDsegmentID *psegment = &segment;
458 fBranch->SetAddress(&psegment);
459 TBranch *brindix = fTree->GetBranch("fSegmentID");
461 Int_t nevent = (Int_t) fTree->GetEntries();
462 for (Int_t i = 0; i < nevent; i++){
463 brindix->GetEvent(i);
464 Int_t treeIndex = segment.GetID();
465 if (fTreeIndex->fN < treeIndex)
466 fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1);
467 (*fTreeIndex)[treeIndex] = i + 1;
474 //_____________________________________________________________________________
475 const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i)
478 // Returns a segment with the given index <i>
481 if ((i < 0) || (i >= fNSegment)) return 0;
482 return (AliTRDsegmentID *) fSegment->At(i);
486 //_____________________________________________________________________________
487 const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const
490 // Returns a segment with the given index <i>
493 if ((i < 0) || (i >= fNSegment)) return 0;
494 //PH return (AliTRDsegmentID *)((*fSegment)[i]);
495 return (AliTRDsegmentID *) fSegment->At(i);