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.9 2001/07/27 13:03:15 hristov
19 Default Branch split level set to 99
21 Revision 1.8 2001/01/26 19:56:57 hristov
22 Major upgrade of AliRoot code
24 Revision 1.7 2000/11/20 08:56:07 cblume
25 Cleanup of data arrays
27 Revision 1.6 2000/11/01 14:53:21 cblume
28 Merge with TRD-develop
30 Revision 1.1.4.3 2000/10/06 16:49:46 cblume
33 Revision 1.1.4.2 2000/10/04 16:34:58 cblume
34 Replace include files by forward declarations
36 Revision 1.5 2000/06/09 11:10:07 cblume
37 Compiler warnings and coding conventions, next round
39 Revision 1.4 2000/06/08 18:32:58 cblume
40 Make code compliant to coding conventions
42 Revision 1.3 2000/06/07 16:27:01 cblume
43 Try to remove compiler warnings on Sun and HP
45 Revision 1.2 2000/05/08 16:17:27 cblume
48 Revision 1.1.4.1 2000/05/08 14:55:03 cblume
51 Revision 1.1 2000/02/28 19:02:56 cblume
56 ///////////////////////////////////////////////////////////////////////////////
58 // Alice segment manager base class //
60 ///////////////////////////////////////////////////////////////////////////////
64 #include <TClonesArray.h>
65 #include <TDirectory.h>
69 #include "AliTRDarrayI.h"
70 #include "AliTRDsegmentID.h"
71 #include "AliTRDsegmentArrayBase.h"
73 ClassImp(AliTRDsegmentArrayBase)
75 //_____________________________________________________________________________
76 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase():TNamed()
79 // AliTRDsegmentArrayBase default constructor
91 //_____________________________________________________________________________
92 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n)
95 // Create an array of objects of <classname>. The class must inherit from
96 // AliTRDsegmentID. The second argument sets the number of entries in
109 if (MakeArray(n) == kFALSE) {
110 Error("AliTRDsegmentArrayBase","Cannot allocate %d segments in memory",n);
116 //_____________________________________________________________________________
117 AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &a)
120 // AliTRDsegmentArrayBase copy constructor
123 ((AliTRDsegmentArrayBase &) a).Copy(*this);
127 //_____________________________________________________________________________
128 AliTRDsegmentArrayBase::~AliTRDsegmentArrayBase()
131 // AliTRDsegmentArrayBase destructor
139 if (fTree) delete fTree;
140 if (fTreeIndex) delete fTreeIndex;
141 if (fClass) delete fClass;
145 //_____________________________________________________________________________
146 AliTRDsegmentArrayBase &AliTRDsegmentArrayBase
147 ::operator=(const AliTRDsegmentArrayBase &a)
150 // Assignment operator
153 if (this != &a) ((AliTRDsegmentArrayBase &) a).Copy(*this);
158 //_____________________________________________________________________________
159 void AliTRDsegmentArrayBase::Copy(TObject &a)
167 fSegment->Copy(*((AliTRDsegmentArrayBase &) a).fSegment);
168 fTreeIndex->Copy(*((AliTRDsegmentArrayBase &) a).fTreeIndex);
169 fClass->Copy(*((AliTRDsegmentArrayBase &) a).fClass);
171 ((AliTRDsegmentArrayBase &) a).fNSegment = fNSegment;
175 //_____________________________________________________________________________
176 Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *classname)
179 // Sets the classname of the stored object
199 if (!gROOT) ::Fatal("AliTRDsegmentArrayBase::AliTRDsegmentArrayBase"
200 ,"ROOT system not initialized");
202 fClass = gROOT->GetClass(classname);
204 Error("AliTRDsegmentArrayBase","%s is not a valid class name",classname);
207 if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
208 Error("AliTRDsegmentArrayBase"
209 ,"%s does not inherit from AliTRDsegmentID",classname);
217 //_____________________________________________________________________________
218 AliTRDsegmentID * AliTRDsegmentArrayBase::NewSegment()
221 // Create a new object according to the class information
224 if (fClass == 0) return 0;
226 AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New();
227 if (segment == 0) return 0;
233 //_____________________________________________________________________________
234 Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment)
237 // Add a segment to the array
240 if (segment == 0) return kFALSE;
241 if (fSegment == 0) return kFALSE;
242 if (fClass == 0) return kFALSE;
244 if (!(segment->IsA()->InheritsFrom(fClass))) {
245 Error("AliTRDsegmentArrayBase","added class %s is not of proper type",
246 segment->IsA()->GetName());
250 fSegment->AddAt(segment,segment->GetID());
251 fNSegment = fSegment->GetLast() + 1;
257 //_____________________________________________________________________________
258 AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index)
261 // Add a segment to the array
264 if (fSegment == 0) return 0;
265 if (fClass == 0) return 0;
267 AliTRDsegmentID *segment = NewSegment();
268 if (segment == 0) return 0;
270 fSegment->AddAt(segment,index);
271 segment->SetID(index);
272 fNSegment = fSegment->GetLast() + 1;
278 //_____________________________________________________________________________
279 Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n)
282 // Create an array of pointers to the segments
289 if (fTreeIndex) delete fTreeIndex;
291 fSegment = new TObjArray(n);
292 fTreeIndex = new AliTRDarrayI();
295 if ((fSegment) && (fTreeIndex))
302 //_____________________________________________________________________________
303 void AliTRDsegmentArrayBase::ClearSegment(Int_t index)
306 // Remove a segment from the active memory
309 //PH if ((*fSegment)[index]){
310 //PH delete (*fSegment)[index]; // because problem with deleting TClonesArray
311 //PH fSegment->RemoveAt(index);
313 if (fSegment->At(index)){
314 delete fSegment->RemoveAt(index);
319 //_____________________________________________________________________________
320 void AliTRDsegmentArrayBase::MakeTree(char *file)
323 // Create a tree for the segment
326 AliTRDsegmentID *psegment = NewSegment();
328 if (fTree) delete fTree;
329 fTree = new TTree("Segment Tree","Tree with segments");
331 fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000);
333 fBranch->SetFile(file);
339 //_____________________________________________________________________________
340 Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName)
343 // Connect a tree from current directory
352 fTree = (TTree*) gDirectory->Get(treeName);
353 if (fTree == 0) return kFALSE;
354 fBranch = fTree->GetBranch("Segment");
355 if (fBranch == 0) return kFALSE;
357 MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries())));
363 //_____________________________________________________________________________
364 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index)
367 // Load a segment with index <index> into the memory
370 if (fTreeIndex == 0) MakeDictionary(3000);
372 // First try to load dictionary
373 if (fTreeIndex == 0) return 0;
374 if (fBranch == 0) return 0;
375 if (index > fTreeIndex->fN) return 0;
376 //PH AliTRDsegmentID *s = (AliTRDsegmentID*) (*fSegment)[index];
377 AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index);
378 if (s == 0) s = NewSegment();
382 Int_t treeIndex = (*fTreeIndex)[index];
387 fBranch->SetAddress(&s);
388 fTree->GetEvent(treeIndex);
389 //PH (*fSegment)[index] = (TObject*) s;
390 fSegment->AddAt((TObject*) s, index);
399 //_____________________________________________________________________________
400 AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index)
403 // Load a segment at position <index> in the tree into the memory
406 if (fBranch == 0) return 0;
407 if (index > fTree->GetEntries()) return 0;
409 AliTRDsegmentID *s = NewSegment();
411 fBranch->SetAddress(&s);
412 fTree->GetEvent(index);
417 Int_t nindex = s->GetID();
418 ClearSegment(nindex);
419 //PH (*fSegment)[nindex] = (TObject *) s;
420 fSegment->AddAt((TObject *) s, nindex);
426 //_____________________________________________________________________________
427 void AliTRDsegmentArrayBase::StoreSegment(Int_t index)
430 // Make a segment persistent
433 const AliTRDsegmentID *kSegment = (*this)[index];
434 if (kSegment == 0) return;
435 if (fTree == 0) MakeTree();
436 fBranch->SetAddress(&kSegment);
441 //_____________________________________________________________________________
442 Bool_t AliTRDsegmentArrayBase::MakeDictionary(Int_t size)
445 // Create an index table for the tree
448 if (size < 1) return kFALSE;
449 if (fTreeIndex) delete fTreeIndex;
451 fTreeIndex = new AliTRDarrayI();
452 fTreeIndex->Set(size);
454 AliTRDsegmentID segment;
455 AliTRDsegmentID *psegment = &segment;
457 fBranch->SetAddress(&psegment);
458 TBranch *brindix = fTree->GetBranch("fSegmentID");
460 Int_t nevent = (Int_t) fTree->GetEntries();
461 for (Int_t i = 0; i < nevent; i++){
462 brindix->GetEvent(i);
463 Int_t treeIndex = segment.GetID();
464 if (fTreeIndex->fN < treeIndex)
465 fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1);
466 (*fTreeIndex)[treeIndex] = i + 1;
473 //_____________________________________________________________________________
474 const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i)
477 // Returns a segment with the given index <i>
480 if ((i < 0) || (i >= fNSegment)) return 0;
481 return (AliTRDsegmentID *) fSegment->At(i);
485 //_____________________________________________________________________________
486 const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const
489 // Returns a segment with the given index <i>
492 if ((i < 0) || (i >= fNSegment)) return 0;
493 //PH return (AliTRDsegmentID *)((*fSegment)[i]);
494 return (AliTRDsegmentID *) fSegment->At(i);