]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDsegmentArrayBase.cxx
Field conversion factor added.
[u/mrichter/AliRoot.git] / TRD / AliTRDsegmentArrayBase.cxx
CommitLineData
f7336fa3 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
b9d0a01d 18Revision 1.12.6.1 2002/06/10 15:28:58 hristov
19Merged with v3-08-02
20
21Revision 1.13 2002/03/28 14:59:07 cblume
22Coding conventions
23
0a29d0f1 24Revision 1.12 2002/02/12 16:06:45 cblume
25Remove delete fTree
26
cb2116ca 27Revision 1.11 2001/11/19 08:44:08 cblume
28Fix bugs reported by Rene
29
a1c3aded 30Revision 1.10 2001/08/30 09:31:22 hristov
31The operator[] is replaced by At() or AddAt() in case of TObjArray.
32
350743f0 33Revision 1.9 2001/07/27 13:03:15 hristov
34Default Branch split level set to 99
35
d0f40f23 36Revision 1.8 2001/01/26 19:56:57 hristov
37Major upgrade of AliRoot code
38
2ab0c725 39Revision 1.7 2000/11/20 08:56:07 cblume
40Cleanup of data arrays
41
fa6b9ac3 42Revision 1.6 2000/11/01 14:53:21 cblume
43Merge with TRD-develop
44
793ff80c 45Revision 1.1.4.3 2000/10/06 16:49:46 cblume
46Made Getters const
47
48Revision 1.1.4.2 2000/10/04 16:34:58 cblume
49Replace include files by forward declarations
50
51Revision 1.5 2000/06/09 11:10:07 cblume
52Compiler warnings and coding conventions, next round
53
dd9a6ee3 54Revision 1.4 2000/06/08 18:32:58 cblume
55Make code compliant to coding conventions
56
8230f242 57Revision 1.3 2000/06/07 16:27:01 cblume
58Try to remove compiler warnings on Sun and HP
59
9d0b222b 60Revision 1.2 2000/05/08 16:17:27 cblume
61Merge TRD-develop
62
6f1e466d 63Revision 1.1.4.1 2000/05/08 14:55:03 cblume
64Bug fixes
65
66Revision 1.1 2000/02/28 19:02:56 cblume
67Add new TRD classes
68
f7336fa3 69*/
70
71///////////////////////////////////////////////////////////////////////////////
72// //
8230f242 73// Alice segment manager base class //
f7336fa3 74// //
75///////////////////////////////////////////////////////////////////////////////
76
793ff80c 77#include <TROOT.h>
f7336fa3 78#include <TTree.h>
793ff80c 79#include <TClonesArray.h>
80#include <TDirectory.h>
81#include <TError.h>
82#include <TClass.h>
f7336fa3 83
793ff80c 84#include "AliTRDarrayI.h"
f7336fa3 85#include "AliTRDsegmentID.h"
86#include "AliTRDsegmentArrayBase.h"
87
f7336fa3 88ClassImp(AliTRDsegmentArrayBase)
89
6f1e466d 90//_____________________________________________________________________________
8230f242 91AliTRDsegmentArrayBase::AliTRDsegmentArrayBase():TNamed()
f7336fa3 92{
93 //
8230f242 94 // AliTRDsegmentArrayBase default constructor
f7336fa3 95 //
6f1e466d 96
97 fNSegment = 0;
98 fSegment = 0;
f7336fa3 99 fTreeIndex = 0;
6f1e466d 100 fTree = 0;
101 fClass = 0;
793ff80c 102 fBranch = 0;
6f1e466d 103
f7336fa3 104}
105
6f1e466d 106//_____________________________________________________________________________
f7336fa3 107AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n)
108{
109 //
8230f242 110 // Create an array of objects of <classname>. The class must inherit from
111 // AliTRDsegmentID. The second argument sets the number of entries in
f7336fa3 112 // the array.
8230f242 113 //
114
115 fNSegment = 0;
116 fSegment = 0;
f7336fa3 117 fTreeIndex = 0;
8230f242 118 fTree = 0;
119 fClass = 0;
793ff80c 120 fBranch = 0;
8230f242 121
f7336fa3 122 SetClass(classname);
8230f242 123
124 if (MakeArray(n) == kFALSE) {
cb2116ca 125 Error("AliTRDsegmentArrayBase","Cannot allocate %d segments in memory",n);
126 return;
8230f242 127 }
128
129}
130
131//_____________________________________________________________________________
dd9a6ee3 132AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &a)
8230f242 133{
134 //
135 // AliTRDsegmentArrayBase copy constructor
136 //
137
dd9a6ee3 138 ((AliTRDsegmentArrayBase &) a).Copy(*this);
8230f242 139
140}
141
142//_____________________________________________________________________________
143AliTRDsegmentArrayBase::~AliTRDsegmentArrayBase()
144{
145 //
146 // AliTRDsegmentArrayBase destructor
147 //
148
149 if (fNSegment){
150 fSegment->Delete();
151 delete fSegment;
152 }
153
cb2116ca 154 //if (fTree) delete fTree;
8230f242 155 if (fTreeIndex) delete fTreeIndex;
8230f242 156
157}
158
159//_____________________________________________________________________________
dd9a6ee3 160AliTRDsegmentArrayBase &AliTRDsegmentArrayBase
161 ::operator=(const AliTRDsegmentArrayBase &a)
162{
163 //
164 // Assignment operator
165 //
166
167 if (this != &a) ((AliTRDsegmentArrayBase &) a).Copy(*this);
168 return *this;
169
170}
171
172//_____________________________________________________________________________
173void AliTRDsegmentArrayBase::Copy(TObject &a)
8230f242 174{
175 //
176 // Copy function
177 //
178
179 TNamed::Copy(a);
180
dd9a6ee3 181 fSegment->Copy(*((AliTRDsegmentArrayBase &) a).fSegment);
182 fTreeIndex->Copy(*((AliTRDsegmentArrayBase &) a).fTreeIndex);
183 fClass->Copy(*((AliTRDsegmentArrayBase &) a).fClass);
8230f242 184
dd9a6ee3 185 ((AliTRDsegmentArrayBase &) a).fNSegment = fNSegment;
8230f242 186
f7336fa3 187}
188
6f1e466d 189//_____________________________________________________________________________
8230f242 190Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *classname)
f7336fa3 191{
192 //
8230f242 193 // Sets the classname of the stored object
194 //
195
8230f242 196 if (fTree != 0) {
f7336fa3 197 delete fTree;
8230f242 198 fTree = 0;
199 fBranch = 0;
f7336fa3 200 delete fTreeIndex;
201 fTreeIndex = 0;
202 }
203 if (fSegment != 0) {
204 fSegment->Delete();
205 delete fSegment;
8230f242 206 fSegment = 0;
f7336fa3 207 }
8230f242 208
209 if (!gROOT) ::Fatal("AliTRDsegmentArrayBase::AliTRDsegmentArrayBase"
210 ,"ROOT system not initialized");
f7336fa3 211
212 fClass = gROOT->GetClass(classname);
213 if (!fClass) {
8230f242 214 Error("AliTRDsegmentArrayBase","%s is not a valid class name",classname);
215 return kFALSE;
f7336fa3 216 }
217 if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) {
8230f242 218 Error("AliTRDsegmentArrayBase"
219 ,"%s does not inherit from AliTRDsegmentID",classname);
220 return kFALSE;
221 }
222
f7336fa3 223 return kTRUE;
f7336fa3 224
f7336fa3 225}
226
6f1e466d 227//_____________________________________________________________________________
cb2116ca 228AliTRDsegmentID *AliTRDsegmentArrayBase::NewSegment()
f7336fa3 229{
230 //
8230f242 231 // Create a new object according to the class information
232 //
233
234 if (fClass == 0) return 0;
235
236 AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New();
f7336fa3 237 if (segment == 0) return 0;
8230f242 238
f7336fa3 239 return segment;
8230f242 240
f7336fa3 241}
242
6f1e466d 243//_____________________________________________________________________________
f7336fa3 244Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment)
245{
246 //
8230f242 247 // Add a segment to the array
f7336fa3 248 //
8230f242 249
250 if (segment == 0) return kFALSE;
251 if (fSegment == 0) return kFALSE;
252 if (fClass == 0) return kFALSE;
253
254 if (!(segment->IsA()->InheritsFrom(fClass))) {
255 Error("AliTRDsegmentArrayBase","added class %s is not of proper type",
f7336fa3 256 segment->IsA()->GetName());
8230f242 257 return kFALSE;
f7336fa3 258 }
8230f242 259
f7336fa3 260 fSegment->AddAt(segment,segment->GetID());
8230f242 261 fNSegment = fSegment->GetLast() + 1;
262
f7336fa3 263 return kTRUE;
8230f242 264
f7336fa3 265}
266
6f1e466d 267//_____________________________________________________________________________
f7336fa3 268AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index)
269{
270 //
8230f242 271 // Add a segment to the array
f7336fa3 272 //
8230f242 273
274 if (fSegment == 0) return 0;
275 if (fClass == 0) return 0;
276
277 AliTRDsegmentID *segment = NewSegment();
278 if (segment == 0) return 0;
279
f7336fa3 280 fSegment->AddAt(segment,index);
281 segment->SetID(index);
8230f242 282 fNSegment = fSegment->GetLast() + 1;
283
f7336fa3 284 return segment;
8230f242 285
f7336fa3 286}
287
6f1e466d 288//_____________________________________________________________________________
f7336fa3 289Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n)
290{
291 //
8230f242 292 // Create an array of pointers to the segments
f7336fa3 293 //
8230f242 294
f7336fa3 295 if (fSegment) {
296 fSegment->Delete();
297 delete fSegment;
298 }
8230f242 299 if (fTreeIndex) delete fTreeIndex;
300
301 fSegment = new TObjArray(n);
fa6b9ac3 302 fTreeIndex = new AliTRDarrayI();
f7336fa3 303 fTreeIndex->Set(n);
8230f242 304 fNSegment = n;
305 if ((fSegment) && (fTreeIndex))
306 return kTRUE;
307 else
308 return kFALSE;
309
f7336fa3 310}
311
6f1e466d 312//_____________________________________________________________________________
f7336fa3 313void AliTRDsegmentArrayBase::ClearSegment(Int_t index)
314{
315 //
8230f242 316 // Remove a segment from the active memory
f7336fa3 317 //
8230f242 318
350743f0 319 //PH if ((*fSegment)[index]){
320 //PH delete (*fSegment)[index]; // because problem with deleting TClonesArray
321 //PH fSegment->RemoveAt(index);
322 //PH }
323 if (fSegment->At(index)){
324 delete fSegment->RemoveAt(index);
f7336fa3 325 }
8230f242 326
f7336fa3 327}
328
6f1e466d 329//_____________________________________________________________________________
2ab0c725 330void AliTRDsegmentArrayBase::MakeTree(char *file)
f7336fa3 331{
8230f242 332 //
333 // Create a tree for the segment
334 //
335
336 AliTRDsegmentID *psegment = NewSegment();
337
f7336fa3 338 if (fTree) delete fTree;
8230f242 339 fTree = new TTree("Segment Tree","Tree with segments");
340
d0f40f23 341 fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000);
2ab0c725 342 if (file)
343 fBranch->SetFile(file);
8230f242 344
f7336fa3 345 delete psegment;
8230f242 346
f7336fa3 347}
348
6f1e466d 349//_____________________________________________________________________________
f7336fa3 350Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName)
351{
8230f242 352 //
353 // Connect a tree from current directory
354 //
355
f7336fa3 356 if (fTree){
357 delete fTree;
8230f242 358 fTree = 0;
f7336fa3 359 fBranch = 0;
360 }
8230f242 361
362 fTree = (TTree*) gDirectory->Get(treeName);
363 if (fTree == 0) return kFALSE;
f7336fa3 364 fBranch = fTree->GetBranch("Segment");
8230f242 365 if (fBranch == 0) return kFALSE;
366
f7336fa3 367 MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries())));
8230f242 368
f7336fa3 369 return kTRUE;
8230f242 370
f7336fa3 371}
372
6f1e466d 373//_____________________________________________________________________________
f7336fa3 374AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index)
375{
376 //
8230f242 377 // Load a segment with index <index> into the memory
f7336fa3 378 //
8230f242 379
380 if (fTreeIndex == 0) MakeDictionary(3000);
381
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;
350743f0 386 //PH AliTRDsegmentID *s = (AliTRDsegmentID*) (*fSegment)[index];
387 AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index);
8230f242 388 if (s == 0) s = NewSegment();
f7336fa3 389 s->SetID(index);
f7336fa3 390
8230f242 391 if (s != 0) {
392 Int_t treeIndex = (*fTreeIndex)[index];
393 if (treeIndex < 1)
394 return 0;
395 else
396 treeIndex--;
f7336fa3 397 fBranch->SetAddress(&s);
398 fTree->GetEvent(treeIndex);
350743f0 399 //PH (*fSegment)[index] = (TObject*) s;
400 fSegment->AddAt((TObject*) s, index);
f7336fa3 401 }
402 else
403 return 0;
8230f242 404
f7336fa3 405 return s;
8230f242 406
f7336fa3 407}
6f1e466d 408
409//_____________________________________________________________________________
f7336fa3 410AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index)
411{
412 //
8230f242 413 // Load a segment at position <index> in the tree into the memory
f7336fa3 414 //
8230f242 415
416 if (fBranch == 0) return 0;
417 if (index > fTree->GetEntries()) return 0;
418
419 AliTRDsegmentID *s = NewSegment();
f7336fa3 420 if (s) {
421 fBranch->SetAddress(&s);
422 fTree->GetEvent(index);
423 }
424 else
425 return 0;
8230f242 426
f7336fa3 427 Int_t nindex = s->GetID();
428 ClearSegment(nindex);
350743f0 429 //PH (*fSegment)[nindex] = (TObject *) s;
430 fSegment->AddAt((TObject *) s, nindex);
8230f242 431
f7336fa3 432 return s;
8230f242 433
f7336fa3 434}
435
8230f242 436//_____________________________________________________________________________
f7336fa3 437void AliTRDsegmentArrayBase::StoreSegment(Int_t index)
438{
439 //
8230f242 440 // Make a segment persistent
f7336fa3 441 //
8230f242 442
443 const AliTRDsegmentID *kSegment = (*this)[index];
444 if (kSegment == 0) return;
445 if (fTree == 0) MakeTree();
446 fBranch->SetAddress(&kSegment);
f7336fa3 447 fTree->Fill();
8230f242 448
f7336fa3 449}
450
6f1e466d 451//_____________________________________________________________________________
f7336fa3 452Bool_t AliTRDsegmentArrayBase::MakeDictionary(Int_t size)
453{
454 //
8230f242 455 // Create an index table for the tree
f7336fa3 456 //
8230f242 457
458 if (size < 1) return kFALSE;
f7336fa3 459 if (fTreeIndex) delete fTreeIndex;
8230f242 460
f7336fa3 461 fTreeIndex = new AliTRDarrayI();
462 fTreeIndex->Set(size);
463
8230f242 464 AliTRDsegmentID segment;
465 AliTRDsegmentID *psegment = &segment;
466
f7336fa3 467 fBranch->SetAddress(&psegment);
8230f242 468 TBranch *brindix = fTree->GetBranch("fSegmentID");
469
470 Int_t nevent = (Int_t) fTree->GetEntries();
471 for (Int_t i = 0; i < nevent; i++){
f7336fa3 472 brindix->GetEvent(i);
8230f242 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;
f7336fa3 477 }
8230f242 478
f7336fa3 479 return kTRUE;
8230f242 480
f7336fa3 481}
9d0b222b 482
483//_____________________________________________________________________________
0a29d0f1 484const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i) const
9d0b222b 485{
486 //
8230f242 487 // Returns a segment with the given index <i>
9d0b222b 488 //
8230f242 489
490 if ((i < 0) || (i >= fNSegment)) return 0;
491 return (AliTRDsegmentID *) fSegment->At(i);
492
9d0b222b 493}
494
495//_____________________________________________________________________________
793ff80c 496const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const
9d0b222b 497{
498 //
8230f242 499 // Returns a segment with the given index <i>
9d0b222b 500 //
8230f242 501
502 if ((i < 0) || (i >= fNSegment)) return 0;
350743f0 503 //PH return (AliTRDsegmentID *)((*fSegment)[i]);
504 return (AliTRDsegmentID *) fSegment->At(i);
8230f242 505
9d0b222b 506}