Added const where it made sense
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGetter.cxx
CommitLineData
ffa6d63b 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/* $Id: */
17
18/* $Log:
19*/
20
21//_________________________________________________________________________
22// A singleton. This class should be used in the analysis stage to get
23// reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
24// instead of directly reading them from galice.root file. This container
25// ensures, that one reads Digits, made of these particular digits, RecPoints,
26// made of these particular RecPoints, TrackSegments and RecParticles.
27// This becomes non trivial if there are several identical branches, produced with
28// different set of parameters. Currently This class only Retrieves Hits, Digits, and SDigits.
29//
30// An example of how to use (see also class AliEMCALAnalyser):
31// AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
32// ................
33// please->GetEvent(event) ; // reads new event from galice.root
34//
35//*-- Author: Sahal Yacoob (LBL)
36// based on : AliPHOSGetter
37//////////////////////////////////////////////////////////////////////////////
38
39
40// --- ROOT system ---
41
42#include "TFile.h"
43#include "TTree.h"
44#include "TROOT.h"
45#include "TObjString.h"
46#include "TFolder.h"
47
48// --- Standard library ---
49#include <iostream.h>
50
51// --- AliRoot header files ---
52
53#include "AliRun.h"
54#include "AliConfig.h"
55#include "AliEMCALGetter.h"
56#include "AliEMCALv1.h"
57#include "AliEMCALDigitizer.h"
58#include "AliEMCALSDigitizer.h"
59#include "AliEMCALGeometry.h"
60
61ClassImp(AliEMCALGetter)
62
63 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
64
65//____________________________________________________________________________
66AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* branchTitle )
67{
68 //Initialize all lists
69
70 fHeaderFile = headerFile ;
71 fBranchTitle = branchTitle ;
72 fSDigitsTitle = branchTitle ;
73 fDigitsTitle = branchTitle ;
74
75 fPrimaries = new TObjArray(1) ;
76 fModuleFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Configuration/Modules"));
77 fHitsFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/Hits"));
78 fSDigitsFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/SDigits"));
79 fDigitsFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/Data"));
80 fTasksFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ;
81
82 if ( fHeaderFile != "aliroot" ) { // to call the getter without a file
83
84 //open headers file
85 TFile * file = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
86
87 if(file == 0){ //if file was not opened yet, read gAlice
88 if(fHeaderFile.Contains("rfio")) // if we read file using HPSS
89 file = TFile::Open(fHeaderFile.Data(),"update") ;
90 else
91 file = new TFile(fHeaderFile.Data(),"update") ;
92
93 if (!file->IsOpen()) {
94 cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot open " << fHeaderFile.Data() << endl ;
95 abort() ;
96 }
97
98 gAlice = static_cast<AliRun *>(file->Get("gAlice")) ;
99
100 if (!gAlice) {
101 cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ;
102 abort() ;
103 }
104 if (!EMCAL()) {
105 cout << "INFO: AliEMCALGetter -> Posting EMCAL to Folders" << endl ;
106 AliConfig * conf = AliConfig::Instance() ;
107 conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("EMCAL"))) ;
108 conf->Add(static_cast<AliModule*>(gAlice->GetDetector("EMCAL"))) ;
109 }
110 }
111
112 }
113}
114//____________________________________________________________________________
115AliEMCALGetter::~AliEMCALGetter(){
116
117}
118
119//____________________________________________________________________________
120void AliEMCALGetter::CreateWhiteBoard() const
121{
122
123}
124
125//____________________________________________________________________________
126AliEMCALGetter * AliEMCALGetter::GetInstance()
127{
128 // Returns the pointer of the unique instance already defined
129
130 AliEMCALGetter * rv = 0 ;
131 if ( fgObjGetter )
132 rv = fgObjGetter ;
133 else
134 cout << "AliEMCALGetter::GetInstance ERROR: not yet initialized" << endl ;
135
136 return rv ;
137}
138
139//____________________________________________________________________________
140AliEMCALGetter * AliEMCALGetter::GetInstance(const char* headerFile,
141 const char* branchTitle)
142{
143 // Creates and returns the pointer of the unique instance
144 // Must be called only when the environment has changed
145
146 if ( fgObjGetter )
147 if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0) &&
148 (fgObjGetter->fHeaderFile.CompareTo(headerFile)==0))
149 return fgObjGetter ;
150 else
151 fgObjGetter->~AliEMCALGetter() ; // delete it if already exists another version
152
153 fgObjGetter = new AliEMCALGetter(headerFile,branchTitle) ;
154
155 // Posts a few item to the white board (folders)
156 // fgObjGetter->CreateWhiteBoard() ;
157
158 return fgObjGetter ;
159
160}
161
162//____________________________________________________________________________
163const AliEMCALv0 * AliEMCALGetter::EMCAL()
164{
165 // returns the EMCAL object
166 //AliEMCALv0 * emcal = dynamic_cast<AliEMCALv0 *>(gAlice->GetDetector("EMCAL")) ;
167 AliEMCALv0 * emcal = dynamic_cast<AliEMCALv1 *>(fModuleFolder->FindObject("EMCAL")) ;
168 if (!emcal)
169 cout << "WARNING: AliEMCALGetter::EMCAL -> EMCAL module not found in Folders" << endl ;
170 return emcal ;
171}
172
173//____________________________________________________________________________
174const AliEMCALGeometry * AliEMCALGetter::EMCALGeometry()
175{
176 AliEMCALGeometry * rv = 0 ;
177 if (EMCAL() )
178 rv = EMCAL()->GetGeometry() ;
179 return rv ;
180}
181
182//____________________________________________________________________________
183Bool_t AliEMCALGetter::PostHits(void) const
184{ //------- Hits ----------------------
185
186 // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
187
188 TFolder * emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
189 if ( !emcalFolder ) {
190 cout << "WARNING: AliEMCALGetter::Post H -> Folder //" << fHitsFolder << "/EMCAL/ not found!" << endl;
191 cout << "INFO: AliEMCALGetter::Post H -> Adding Folder //" << fHitsFolder << "/EMCAL/" << endl;
192 emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ;
193 }
194 TClonesArray *hits= new TClonesArray("AliEMCALHit",1000) ;
195 hits->SetName("Hits") ;
196 emcalFolder->Add(hits) ;
197
198 return kTRUE;
199}
200
201//____________________________________________________________________________
202void * AliEMCALGetter::HitsRef(void) const
203{ //------- Hits ----------------------
204
205
206 // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
207 if ( !fHitsFolder ) {
208 cerr << "ERROR: AliEMCALGetter::Post H -> Folder //" << fHitsFolder << " not found!" << endl;
209 return 0;
210 }
211
212 TFolder * emcalFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
213 if ( !emcalFolder ) {
214 cerr << "ERROR: AliEMCALGetter::Post HRef -> Folder //" << fHitsFolder << "/EMCAL/ not found!" << endl;
215 return 0;
216 }
217
218 TObject * h = emcalFolder->FindObject("Hits") ;
219 if(!h) {
220 cerr << "ERROR: AliEMCALGetter::HRef -> " << emcalFolder->GetName() << "/Hits not found !" << endl ;
221 return 0 ;
222 }
223 else
224 return static_cast<void *>(emcalFolder->GetListOfFolders()->GetObjectRef(h)) ;
225}
226
227//____________________________________________________________________________
228Bool_t AliEMCALGetter::PostSDigits(const char * name, const char * headerFile) const
229{ //---------- SDigits -------------------------
230
231
232 // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
233 // because you can have sdigits from several hit files for mixing
234
235 TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
236 if ( !emcalFolder ) {
237 cout << "WARNING: AliEMCALGetter::Post S -> Folder //" << fSDigitsFolder << "/EMCAL/ not found!" << endl;
238 cout << "INFO: AliEMCALGetter::Post S -> Adding Folder //" << fHitsFolder << "/EMCAL/" << endl;
239 emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ;
240 }
241 TString subdir(headerFile) ;
242 TFolder * emcalSubFolder = dynamic_cast<TFolder*>(emcalFolder->FindObject(subdir)) ;
243 if ( !emcalSubFolder )
244 emcalSubFolder = emcalFolder->AddFolder(subdir, "");
245
246 TObject * sd = emcalSubFolder->FindObject(name);
247 if ( sd ) {
248 cerr <<"INFO: AliEMCALGetter::Post S -> Folder " << subdir
249 << " already exists!" << endl ;
250 }else{
251 TClonesArray * sdigits = new TClonesArray("AliEMCALDigit",1000) ;
252 sdigits->SetName(name) ;
253 emcalSubFolder->Add(sdigits) ;
254 }
255
256 return kTRUE;
257}
258//____________________________________________________________________________
259void * AliEMCALGetter::SDigitsRef(const char * name, const char * file) const
260{ //------- SDigits ----------------------
261
262 // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/filename/SDigits
263
264 if ( !fSDigitsFolder ) {
265 cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //" << fSDigitsFolder << " not found!" << endl;
266 return 0;
267 }
268
269 TFolder * emcalFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
270 if ( !emcalFolder ) {
271 cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //" << fSDigitsFolder << "/EMCAL/ not found!" << endl;
272 return 0;
273 }
274
275 TFolder * emcalSubFolder = 0 ;
276 if(file)
277 emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(file)) ;
278 else
279 emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(fHeaderFile)) ;
280
281 if(!emcalSubFolder) {
282 cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //Folders/RunMC/Event/Data/EMCAL/" << file << "not found!" << endl;
283 return 0;
284 }
285
286 TObject * dis = emcalSubFolder->FindObject(name) ;
287 if(!dis)
288 return 0 ;
289 else
290 return static_cast<void *>(emcalSubFolder->GetListOfFolders()->GetObjectRef(dis)) ;
291
292}
293
294//____________________________________________________________________________
295Bool_t AliEMCALGetter::PostSDigitizer(AliEMCALSDigitizer * sdigitizer) const
296{ //---------- SDigitizer -------------------------
297
298 // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
299
300
301 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
302
303 if ( !sd ) {
304 cerr << "ERROR: AliEMCALGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
305 return kFALSE ;
306 }
307 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
308 if ( !emcal ) {
309 cout <<"WARNING: AliEMCALGetter::Post Ser ->//" << fTasksFolder << "/SDigitizer/EMCAL/ not found!" << endl;
310 cout <<"INFO: AliEMCALGetter::Post Ser -> Adding //" << fTasksFolder << "/SDigitizer/EMCAL/" << endl;
311 emcal = new TTask("EMCAL", "") ;
312 sd->Add(emcal) ;
313 }
314 AliEMCALSDigitizer * emcalsd = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdigitizer->GetName() ));
315 if (emcalsd) {
316 cout << "INFO: AliEMCALGetter::Post Ser -> Task " << sdigitizer->GetName() << " already exists" << endl ;
317 emcal->GetListOfTasks()->Remove(emcalsd) ;
318 }
319 emcal->Add(sdigitizer) ;
320 return kTRUE;
321
322}
323
324//____________________________________________________________________________
325void * AliEMCALGetter::SDigitizerRef(const char * name) const
326{
327
328 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
329 if ( !sd ) {
330 cerr << "ERROR: AliEMCALGetter::Post SerRef -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
331 abort();
332 }
333
334 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
335 if ( !emcal ) {
336 cerr <<"ERROR: AliEMCALGetter::Post SerRef -> //" << fTasksFolder << "/SDigitizer/EMCAL not found!" << endl;
337 abort();
338 }
339
340 TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ;
341
342 return static_cast<void *>(emcal->GetListOfTasks()->GetObjectRef(task)) ;
343
344}
345
346//____________________________________________________________________________
347Bool_t AliEMCALGetter::PostSDigitizer(const char * name, const char * file) const
348{ //---------- SDigitizer -------------------------
349
350 // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
351
352
353 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
354 if ( !sd ) {
355 cerr << "ERROR: AliEMCALGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
356 return kFALSE ;
357 }
358
359 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
360 if ( !emcal ) {
361 cout <<"WARNING: AliEMCALGetter::Post Ser -> //" << fTasksFolder << "/SDigitizer/EMCAL/ not found!" << endl;
362 cout <<"INFO: AliEMCALGetter::Post Ser -> Adding //" << fTasksFolder << "/SDigitizer/EMCAL" << endl;
363 emcal = new TTask("EMCAL", "") ;
364 sd->Add(emcal) ;
365 }
366
367 TString sdname(name) ;
368 sdname.Append(":") ;
369 sdname.Append(file);
370 AliEMCALSDigitizer * emcalsd = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdname ));
371 if (!emcalsd) {
372 emcalsd = new AliEMCALSDigitizer() ;
373 //Note, we can not call constructor with parameters: it will call Getter and scrud up everething
374 emcalsd->SetName(sdname) ;
375 emcalsd->SetTitle(file) ;
376 emcal->Add(emcalsd) ;
377 }
378 return kTRUE;
379
380}
381
382//____________________________________________________________________________
383Bool_t AliEMCALGetter::PostDigits(const char * name) const
384{ //---------- Digits -------------------------
385
386 // the hierarchy is //Folders/Run/Event/Data/EMCAL/SDigits/name
387
388 TFolder * emcalFolder = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
389
390 if ( !emcalFolder ) {
391 cout << "WARNING: AliEMCALGetter::Post D -> Folder //" << fDigitsFolder << "/EMCAL/ not found!" << endl;
392 cout << "INFO: AliEMCALGetter::Post D -> Adding Folder //" << fDigitsFolder << "/EMCAL/" << endl;
393 emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;
394 }
395
396 TObject* dig = emcalFolder->FindObject( name ) ;
397 if ( !dig ) {
398 TClonesArray * digits = new TClonesArray("AliEMCALDigit",1000) ;
399 digits->SetName(name) ;
400 emcalFolder->Add(digits) ;
401 }
402 return kTRUE;
403}
404
405//____________________________________________________________________________
406void * AliEMCALGetter::DigitsRef(const char * name) const
407{ //------- Digits ----------------------
408
409 // the hierarchy is //Folders/Run/Event/Data/EMCAL/Digits/name
410
411 if ( !fDigitsFolder ) {
412 cerr << "ERROR: AliEMCALGetter::Post DRef -> Folder //" << fDigitsFolder << " not found!" << endl;
413 return 0;
414 }
415
416 TFolder * emcalFolder = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
417 if ( !emcalFolder ) {
418 cerr << "ERROR: AliEMCALGetter::DRef -> Folder //" << fDigitsFolder << "/EMCAL/ not found!" << endl;
419 return 0;
420 }
421
422 TObject * d = emcalFolder->FindObject(name) ;
423 if(!d)
424 return 0 ;
425 else
426 return static_cast<void *>(emcalFolder->GetListOfFolders()->GetObjectRef(d)) ;
427
428}
429
430//____________________________________________________________________________
431Bool_t AliEMCALGetter::PostDigitizer(AliEMCALDigitizer * digitizer) const
432{ //---------- Digitizer -------------------------
433
434 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
435
436 if ( !sd ) {
437 cerr << "ERROR: AliEMCALGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
438 return kFALSE ;
439 }
440 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
441 if ( !emcal ) {
442 cout <<"WARNING: AliEMCALGetter::Post Der -> //" << fTasksFolder << "/Digitizer/EMCAL not found!" << endl;
443 cout <<"INFO: AliEMCALGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
444 emcal = new TTask("EMCAL", "") ;
445 sd->Add(emcal) ;
446 }
447
448 AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(digitizer->GetName())) ;
449 if (emcald) {
450 emcald->Delete() ;
451 emcal->GetListOfTasks()->Remove(emcald) ;
452 }
453 emcal->Add(digitizer) ;
454 return kTRUE;
455}
456
457//____________________________________________________________________________
458Bool_t AliEMCALGetter::PostDigitizer(const char * name) const
459{ //---------- Digitizer -------------------------
460
461 // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
462
463 TTask * d = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
464 if ( !d ) {
465 cerr << "ERROR: AliEMCALGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
466 return kFALSE ;
467 }
468
469 TTask * emcal = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("EMCAL")) ;
470 if ( !emcal ) {
471 cout <<"WARNING: AliEMCALGetter::Post Der -> //" << fTasksFolder << "/Digitizer/EMCAL not found!" << endl;
472 cout <<"INFO: AliEMCALGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
473 emcal = new TTask("EMCAL", "") ;
474 d->Add(emcal) ;
475}
476
477 AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(name)) ;
478 if (!emcald) {
479 emcald = new AliEMCALDigitizer() ;
480 emcald->SetName(fDigitsTitle) ;
481 emcald->SetTitle(fHeaderFile) ;
482 emcal->Add(emcald) ;
483 }
484 return kTRUE;
485}
486
487//____________________________________________________________________________
488void * AliEMCALGetter::DigitizerRef(const char * name) const
489{
490 TTask * sd = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
491 if ( !sd ) {
492 cerr << "ERROR: AliEMCALGetter::Post DerRef -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
493 abort();
494 }
495
496 TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ;
497 if ( !emcal ) {
498 cerr <<"ERROR: AliEMCALGetter::Post DerRef -> //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
499 abort();
500 }
501
502 TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ;
503
504 return static_cast<void *>(emcal->GetListOfTasks()->GetObjectRef(task)) ;
505
506}
507
508//____________________________________________________________________________
509const TParticle * AliEMCALGetter::Primary(Int_t index) const
510{
511 // Return primary particle numbered by <index>
512
513 if(index < 0)
514 return 0 ;
515
516 Int_t primaryIndex = index % 10000000 ;
517 Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.) ;
518
519 if ( primaryList > 0 ) {
520 cout << " Getter does not support currently Mixing of primary " << endl ;
521 cout << " can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
522 return 0;
523 }
524
525 return gAlice->Particle(primaryIndex) ;
526
527}
528
529//____________________________________________________________________________
530void AliEMCALGetter::ReadTreeD()
531{
532 // Read the digit tree gAlice->TreeD()
533 if(gAlice->TreeD()== 0){
534 cerr << "ERROR: AliEMCALGetter::ReadTreeD: can not read TreeD " << endl ;
535 return ;
536 }
537 cout << "hello" << endl;
538 TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeD()->GetListOfBranches()) ;
539 TIter next(lob) ;
540 TBranch * branch = 0 ;
541 TBranch * digitsbranch = 0 ;
542 TBranch * digitizerbranch = 0 ;
543 Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ;
544
545 while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !digitizerfound) ) {
546 if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
547 digitsbranch = branch ;
548 emcalfound = kTRUE ;
549 }
550 else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
551 digitizerbranch = branch ;
552 digitizerfound = kTRUE ;
553 }
554 }
555
556 if ( !emcalfound || !digitizerfound ) {
557 cout << "WARNING: AliEMCALGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name "
558 << fDigitsTitle << endl ;
559 return ;
560 }
561
562 //read digits
563 if(!Digits(fDigitsTitle) )
564 PostDigits(fDigitsTitle);
565 digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
566 digitsbranch->GetEntry(0) ;
567
568
569 // read the Digitizer
570 if(!Digitizer(fDigitsTitle))
571 PostDigitizer(fDigitsTitle) ;
572 digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
573 digitizerbranch->GetEntry(0) ;
574
575
576}
577
578//____________________________________________________________________________
579void AliEMCALGetter::ReadTreeH()
580{
581 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
582
583 if(gAlice->TreeH()== 0){
584 cerr << "ERROR: AliEMCALGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
585 return ;
586 }
587
588 TBranch * hitsbranch = static_cast<TBranch*>(gAlice->TreeH()->GetBranch("EMCAL")) ;
589 if ( !hitsbranch ) {
590 cout << "WARNING: AliEMCALGetter::ReadTreeH -> Cannot find branch EMCAL" << endl ;
591 return ;
592 }
593 if(!Hits())
594 PostHits() ;
595
596 hitsbranch->SetAddress(HitsRef()) ;
597
598 hitsbranch->GetEntry(0) ;
599
600}
601
602//____________________________________________________________________________
603void AliEMCALGetter::Track(Int_t itrack)
604{
605 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
606
607 if(gAlice->TreeH()== 0){
608 cerr << "ERROR: AliEMCALGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
609 return ;
610 }
611
612 TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
613 if ( !hitsbranch ) {
614 cout << "WARNING: AliEMCALGetter::ReadTreeH -> Cannot find branch EMCAL" << endl ;
615 return ;
616 }
617 if(!Hits())
618 PostHits() ;
619 hitsbranch->SetAddress(HitsRef()) ;
620 hitsbranch->GetEntry(itrack) ;
621
622
623}
624//____________________________________________________________________________
625void AliEMCALGetter::ReadTreeS(Int_t event)
626{
627 // Read the summable digits tree gAlice->TreeS()
628
629 // loop over all opened files and read their SDigits to the White Board
630 TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
631 if (!emcalF)
632 emcalF = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ;
633 TCollection * folderslist = emcalF->GetListOfFolders() ;
634
635 //Add current file to list if it is not there yet
636 if ( (fHeaderFile != "aliroot") && ( !folderslist->Contains(fHeaderFile) ) ){
637 emcalF->AddFolder(fHeaderFile, "");
638 }
639
640 TIter next(folderslist) ;
641 TFolder * folder = 0 ;
642 TFile * file;
643 TTree * treeS = 0;
644 while ( (folder = static_cast<TFolder*>(next())) ) {
645 if(fHeaderFile.CompareTo(folder->GetName()) == 0 )
646 {treeS=gAlice->TreeS() ;
647 cout << "ReadTreeS "<< gAlice->TreeS() <<endl ;}
648 else{
649 cout << " AliEMCALGetter::ReadTreeS 2 " << folder->GetName() << endl ;
650 file = static_cast<TFile*>(gROOT->GetFile(folder->GetName()));
651 file->cd() ;
652
653 // Get SDigits Tree header from file
654 TString treeName("TreeS") ;
655 treeName += event ;
656 treeS = dynamic_cast<TTree*>(gDirectory->Get(treeName.Data()));
657 }
658 if(treeS==0){
659 cerr << "ERROR: AliEMCALGetter::ReadTreeS There is no SDigit Tree" << endl;
660 return ;
661 }
662
663 //set address of the SDigits and SDigitizer
664 TBranch * sdigitsBranch = 0;
665 TBranch * sdigitizerBranch = 0;
666 TBranch * branch = 0 ;
667 TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
668 TIter next(lob) ;
669 Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ;
670
671 while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !sdigitizerfound) ) {
672
673 if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
674 emcalfound = kTRUE ;
675 sdigitsBranch = branch ;
676 cout << "sdigitsbranch found = " << branch << endl ;
677 }
678
679 else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
680 sdigitizerfound = kTRUE ;
681 sdigitizerBranch = branch ;
682 cout << "sdigitizerbranch found = " << branch << endl ;
683 }
684 }
685 if ( !emcalfound || !sdigitizerfound ) {
686 cout << "WARNING: AliEMCALDigitizer::ReadSDigits -> Digits and/or Digitizer branch with name " << GetName()
687 << " not found" << endl ;
688 return ;
689 }
690
691 if ( !folder->FindObject(fSDigitsTitle) )
692 { PostSDigits(fSDigitsTitle,folder->GetName()) ;
693 cout << "Posting SDigits " << endl << endl ;}
694 sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
695
696 sdigitsBranch->GetEntry(0) ;
697
698 TString sdname(fSDigitsTitle) ;
699 cout << sdname << endl ;
700 sdname+=":" ;
701 sdname+=folder->GetName() ;
702 if(!SDigitizer(sdname) )
703 PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
704 sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
705 sdigitizerBranch->GetEntry(0) ;
706
707 }
708
709 // After SDigits have been read from all files, return to the first one
710
711 next.Reset();
712 folder = static_cast<TFolder*>(next());
713 if(folder){
714 file = static_cast<TFile*>(gROOT->GetFile(folder->GetName()));
715 file ->cd() ;
716 }
717
718}
719//____________________________________________________________________________
720void AliEMCALGetter::ReadTreeS(TTree * treeS, Int_t input)
721{ // Read the summable digits fron treeS()
722
723
724 TString filename("mergefile") ;
725 filename+= input ;
726
727 TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
728 if ( !emcalFolder ) {
729 emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ;
730 }
731 TFolder * folder=(TFolder*)emcalFolder->FindObject(filename) ;
732 //set address of the SDigits and SDigitizer
733 TBranch * sdigitsBranch = 0;
734 TBranch * sdigitizerBranch = 0;
735 TBranch * branch = 0 ;
736 TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
737 TIter next(lob) ;
738 Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ;
739
740 while ( (branch = (TBranch*)next()) && (!emcalfound || !sdigitizerfound) ) {
741 if ( strcmp(branch->GetName(), "EMCAL")==0) {
742 emcalfound = kTRUE ;
743 sdigitsBranch = branch ;
744 }
745
746 else if ( strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) {
747 sdigitizerfound = kTRUE ;
748 sdigitizerBranch = branch ;
749 }
750 }
751 if ( !emcalfound || !sdigitizerfound ) {
752 cout << "WARNING: AliEMCALGetter::ReadTreeS -> Digits and/or Digitizer branch not found" << endl ;
753 return ;
754 }
755
756 if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
757 PostSDigits(sdigitsBranch->GetTitle(),filename) ;
758
759 sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
760
761 TString sdname(sdigitsBranch->GetTitle()) ;
762 sdname+=":" ;
763 sdname+=filename ;
764 if(!SDigitizer(sdigitsBranch->GetTitle()) )
765 PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
766 sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
767
768 sdigitsBranch->GetEntry(0) ;
769 sdigitizerBranch->GetEntry(0) ;
770
771}
772
773
774//____________________________________________________________________________
775void AliEMCALGetter::ReadPrimaries()
776{
777 // Reads specific branches of primaries
778
779 fNPrimaries = gAlice->GetNtrack();
780
781 // //Check, is it necessary to open new files
782 // TArrayI* events = fDigitizer->GetCurrentEvents() ;
783 // TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
784// Int_t input ;
785// for(input = 0; input < filenames->GetEntriesFast(); input++){
786
787// TObjString * filename = (TObjString *) filenames->At(input) ;
788
789// //Test, if this file already open
790// TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
791// if(file == 0)
792// file = new TFile( filename->GetString()) ;
793// file->cd() ;
794
795// // Get Kine Tree from file
796// // char treeName[20];
797// // sprintf(treeName,"TreeK%d",events->At(input));
798// // TTree * treeK = (TTree*)gDirectory->Get(treeName);
799// // if (treeK)
800// // treeK->SetBranchAddress("Particles", &fParticleBuffer);
801// // else
802// // cout << "AliEMCALGetter: cannot find Kine Tree for event:" << events->At(input) << endl;
803
804// // // Create the particle stack
805// // if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
806// // // Build the pointer list
807// // if(fParticleMap) { <----
808// // fParticleMap->Clear();
809// // fParticleMap->Expand(treeK->GetEntries());
810// // } else
811// // fParticleMap = new TObjArray(treeK->GetEntries());
812
813// // From gAlice->Particle(i)
814
815
816// // if(!(*fParticleMap)[i]) {
817// // Int_t nentries = fParticles->GetEntries();
818
819// // // algorithmic way of getting entry index
820// // // (primary particles are filled after secondaries)
821// // Int_t entry;
822// // if (i<fHeader.GetNprimary())
823// // entry = i+fHeader.GetNsecondary();
824// // else
825// // entry = i-fHeader.GetNprimary();
826
827// // // only check the algorithmic way and give
828// // // the fatal error if it is wrong
829// // if (entry != fParticleFileMap[i]) {
830// // Fatal("Particle",
831// // "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
832// // entry, fParticleFileMap[i]);
833// // }
834
835// // fTreeK->GetEntry(fParticleFileMap[i]);
836// // new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
837// // fParticleMap->AddAt((*fParticles)[nentries],i);
838// // }
839// // return (TParticle *) (*fParticleMap)[i];
840
841
842
843// }
844
845
846// //scan over opened files and read corresponding TreeK##
847
848 return ;
849}
850//____________________________________________________________________________
851void AliEMCALGetter::Event(const Int_t event, const char* opt)
852{
853 // Reads the content of all Tree's S, D and R
854
855 if (event >= gAlice->TreeE()->GetEntries() ) {
856 cerr << "ERROR: AliEMCALGetter::Event -> " << event << " not found in TreeE!" << endl ;
857 return ;
858 }
859 gAlice->GetEvent(event) ;
860
861 if(strstr(opt,"H") )
862 {cout<<"Reading TreeH" << endl ;
863 ReadTreeH() ;}
864
865 if(strstr(opt,"S") )
866 { cout << "Reading TreeS" << endl ;
867 ReadTreeS(event) ;}
868
869 if( strstr(opt,"D") )
870 ReadTreeD() ;
871
872 if( strstr(opt,"R") )
873// ReadTreeR() ;
874
875 if( strstr(opt,"Q") )
876// ReadTreeQA() ;
877
878 if( strstr(opt,"P") )
879 ReadPrimaries() ;
880
881}
882
883//____________________________________________________________________________
884const TObject * AliEMCALGetter::ReturnO(TString what, TString name, TString file) const
885{
886 // get the object named "what" from the folder
887 // folders are named like //Folders
888
889 if ( file.IsNull() )
890 file = fHeaderFile ;
891
892 TFolder * folder = 0 ;
893 TObject * emcalO = 0 ;
894
895 // if ( name.IsNull() ) {
896 if ( what.CompareTo("Hits") == 0 ) {
897 folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
898 if (folder)
899 emcalO = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;
900 }
901 else if ( what.CompareTo("SDigits") == 0 ) {
902 TString path = "EMCAL/" + file ;
903 folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ;
904 if (folder) {
905 cout << "folder found" << endl ;
906 if (name.IsNull())
907 name = fSDigitsTitle ;
908 emcalO = dynamic_cast<TObject *>(folder->FindObject(name)) ;
909 }
910 }
911 else if ( what.CompareTo("Digits") == 0 ){
912 folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("EMCAL")) ;
913 if (folder) {
914 if (name.IsNull())
915 name = fDigitsTitle ;
916 emcalO = dynamic_cast<TObject *>(folder->FindObject(name)) ;
917 }
918 }
919 if (!emcalO) {
920 cerr << "ERROR : AliEMCALGetter::ReturnO -> Object " << what << " not found in " << folder->GetName() << endl ;
921 return 0 ;
922 }
923 return emcalO ;
924}
925
926//____________________________________________________________________________
927const TTask * AliEMCALGetter::ReturnT(TString what, TString name) const
928{
929 // get the TTask named "what" from the folder
930 // folders are named like //Folders/Tasks/what/EMCAL/name
931
932 TString search(what) ;
933
934 TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ;
935
936 if (!tasks) {
937 cerr << "ERROR: AliEMCALGetter::ReturnT -> Task " << what << " not found!" << endl ;
938 return 0 ;
939 }
940
941 TTask * emcalT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ;
942 if (!emcalT) {
943 cerr << "ERROR: AliEMCALGetter::ReturnT -> Task " << what << "/EMCAL not found!" << endl ;
944 return 0 ;
945 }
946
947 TList * list = emcalT->GetListOfTasks() ;
948
949 if (what.CompareTo("SDigitizer") == 0) {
950 if ( name.IsNull() )
951 name = fSDigitsTitle ;
952 } else if (what.CompareTo("Digitizer") == 0){
953 if ( name.IsNull() )
954 name = fDigitsTitle ;
955 }
956
957 TIter it(list) ;
958 TTask * task = 0 ;
959 while((task = static_cast<TTask *>(it.Next()) )){
960 TString taskname(task->GetName()) ;
961 if(taskname.BeginsWith(name))
962 return task ;
963 }
964
965 cout << "WARNING: AliEMCALGetter::ReturnT -> Task " << search << "/" << name << " not found!" << endl ;
966 return 0 ;
967}