]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGetter.cxx
97ece73256b2c3f6e35a0ebdbf14ad73b05cf091
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGetter.cxx
1 /**************************************************************************
2
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4
5  *                                                                        *
6
7  * Author: The ALICE Off-line Project.                                    *
8
9  * Contributors are mentioned in the code where appropriate.              *
10
11  *                                                                        *
12
13  * Permission to use, copy, modify and distribute this software and its   *
14
15  * documentation strictly for non-commercial purposes is hereby granted   *
16
17  * without fee, provided that the above copyright notice appears in all   *
18
19  * copies and that both the copyright notice and this permission notice   *
20
21  * appear in the supporting documentation. The authors make no claims     *
22
23  * about the suitability of this software for any purpose. It is          *
24
25  * provided "as is" without express or implied warranty.                  *
26
27  **************************************************************************/
28
29
30
31 /* $Id:  */
32
33
34
35 /* $Log:
36
37    29.05.2001 Yuri Kharlov:
38
39               Everywhere reading the treese TTree->GetEvent(i)
40
41               is replaced by reading the branches TBranch->GetEntry(0)
42
43 */
44
45 /* $Log:
46
47    08.2002 Dmitri Peressounko:
48
49
50
51 */
52
53
54
55 //_________________________________________________________________________
56
57 //  A singleton. This class should be used in the analysis stage to get 
58
59 //  reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
60
61 //  instead of directly reading them from galice.root file. This container 
62
63 //  ensures, that one reads Digits, made of these particular digits, RecPoints, 
64
65 //  made of these particular RecPoints, TrackSegments and RecParticles. 
66
67 //  This becomes non trivial if there are several identical branches, produced with
68
69 //  different set of parameters. 
70
71 //
72
73 //  An example of how to use (see also class AliEMCALAnalyser):
74
75 //  AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
76
77 //  for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
78
79 //     AliEMCALRecParticle * part = gime->RecParticle(1) ;
80
81 //     ................
82
83 //  please->GetEvent(event) ;    // reads new event from galice.root
84
85 //                  
86
87 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
88
89 //*--         Completely redesigned by Dmitri Peressounko March 2001  
90
91 //
92
93 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
94
95 //*--         systematic usage of TFolders without changing the interface     
96
97 //*-- YS August 2002 : clone PHOS as closely as possible and intoduction
98
99 //                     of new  IO (à la PHOS)
100
101 //////////////////////////////////////////////////////////////////////////////
102
103
104
105 // --- ROOT system ---
106
107 #include "TFile.h"
108
109 #include "TTree.h"
110
111 #include "TROOT.h"
112
113 #include "TObjString.h"
114
115 #include "TFolder.h"
116
117 #include "TParticle.h"
118
119
120
121 // --- Standard library ---
122
123 #include <iostream.h>
124
125
126
127 // --- AliRoot header files ---
128
129 #include "AliRun.h"
130
131 #include "AliConfig.h"
132
133 #include "AliEMCALGetter.h"
134
135 #include "AliEMCAL.h"
136
137 #include "AliEMCALDigitizer.h"
138
139 #include "AliEMCALSDigitizer.h"
140
141 #include "AliEMCALClusterizerv1.h"
142
143 //#include "AliEMCALTrackSegmentMakerv1.h"
144
145 //#include "AliEMCALTrackSegment.h"
146
147 //#include "AliEMCALPIDv1.h" 
148
149 #include "AliEMCALGeometry.h"
150
151
152
153 ClassImp(AliEMCALGetter)
154
155   
156
157   AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ; 
158
159   TFile * AliEMCALGetter::fFile = 0 ; 
160
161
162
163 //____________________________________________________________________________ 
164
165 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* branchTitle, const Bool_t toSplit)
166
167 {
168
169   // This is the ctor called by GetInstance and the only one that can be used 
170
171   
172
173   if ( fHeaderFile.Contains("_") ) {
174
175     cerr << "AliEMCALGetter::AliEMCALGetter -> Invalid file name (_ not allowed) " << fHeaderFile.Data() << endl ;
176
177     abort() ; 
178
179   }
180
181   
182
183   //Initialize  all data
184
185
186
187   fFailed = kFALSE ;   
188
189   fDebug  = 0 ; 
190
191   fAlice  = 0 ; 
192
193
194
195   fToSplit    = toSplit ;
196
197   fHeaderFile = headerFile ; 
198
199
200
201   fPrimaries = new TObjArray(1) ;
202
203
204
205   fModuleFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Configuration/Modules")); 
206
207   fPrimariesFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data")); 
208
209   fHitsFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/Hits")); 
210
211   fSDigitsFolder   = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/SDigits")); 
212
213   fDigitsFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/Data")); 
214
215   fRecoFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/RecData")); 
216
217   //fQAFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Conditions/QA")); 
218
219   fTasksFolder     = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ; 
220
221
222
223   //Set titles to branches and create PHOS specific folders
224
225   SetTitle(branchTitle) ;
226
227   
228
229   if ( fHeaderFile != "aliroot"  ) { // to call the getter without a file
230
231     //open headers file
232
233     fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
234
235   
236
237     if(!fFile){    //if file was not opened yet, read gAlice
238
239       fFile = TFile::Open(fHeaderFile.Data(), "update") ;   
240
241       if (!fFile->IsOpen()) {
242
243         cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot open " << fHeaderFile.Data() << endl ; 
244
245         fFailed = kTRUE ;
246
247         return ;  
248
249       }
250
251       gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
252
253     }
254
255   }
256
257   
258
259   if (!gAlice) {
260
261     cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ; 
262
263     fFailed = kTRUE ;
264
265     return ; 
266
267   }
268
269   if (!EMCAL()) {
270
271     if (fDebug)
272
273       cout << "INFO: AliEMCALGetter -> Posting EMCAL to Folders" << endl ; 
274
275     if (gAlice->GetDetector("EMCAL")) {
276
277       AliConfig * conf = AliConfig::Instance() ;
278
279       conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("EMCAL"))) ; 
280
281       conf->Add(static_cast<AliModule*>(gAlice->GetDetector("EMCAL"))) ;
282
283     }
284
285     else 
286
287       cerr << "ERROR: AliEMCALGetter -> detector EMCAL not found" << endl ;
288
289   }
290
291   
292
293   fDebug=0;
294
295 }
296
297
298
299 //____________________________________________________________________________ 
300
301 AliEMCALGetter::~AliEMCALGetter()
302
303 {
304
305   if (fPrimaries) {
306
307     fPrimaries->Delete() ; 
308
309     delete fPrimaries ; 
310
311   }
312
313
314
315   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
316
317   TCollection * folderslist = emcalF->GetListOfFolders() ; 
318
319   TIter next(folderslist) ; 
320
321   TFolder * folder = 0 ; 
322
323   while ( (folder = static_cast<TFolder*>(next())) ) 
324
325     emcalF->Remove(folder) ; 
326
327
328
329   if (fFile) { 
330
331     fFile->Close() ;  
332
333     delete fFile ; 
334
335     fFile = 0 ;
336
337   }
338
339   fgObjGetter = 0 ; 
340
341
342
343 }
344
345
346
347 //____________________________________________________________________________ 
348
349 void AliEMCALGetter::CloseFile()
350
351 {
352
353   delete gAlice ;  
354
355   gAlice = 0 ; 
356
357   delete fAlice ; 
358
359   fAlice = 0 ; 
360
361 }
362
363
364
365 //____________________________________________________________________________ 
366
367 const TFolder * AliEMCALGetter::Folder(const TString what) const {
368
369
370
371   // returns the EMCAL folder required by what
372
373   // what = hits, sdigits, digits
374
375
376
377   if ( what == "hits" ) 
378
379     return dynamic_cast<const TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
380
381   else if ( what == "sdigits" ) 
382
383     return  dynamic_cast<const TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ; 
384
385   else if ( what == "digits" ) 
386
387     return  dynamic_cast<const TFolder *>(fDigitsFolder->FindObject("EMCAL")) ; 
388
389   else {
390
391     cerr << "ERROR: AliEMCALGetter::GetFolder -> " << what.Data() << " illegal option (hits, sdigits, digits) " << endl ; 
392
393     return 0 ; 
394
395   }
396
397 }
398
399
400
401 //____________________________________________________________________________ 
402
403 AliEMCALGetter * AliEMCALGetter::GetInstance()
404
405 {
406
407   // Returns the pointer of the unique instance already defined
408
409   
410
411   if ( fgObjGetter ) {
412
413     return fgObjGetter ;
414
415   }
416
417   else {
418
419     // cout << "AliEMCALGetter::GetInstance ERROR: not yet initialized" << endl ;
420
421     return 0 ;
422
423   }
424
425 }
426
427
428
429 //____________________________________________________________________________ 
430
431 AliEMCALGetter * AliEMCALGetter::GetInstance(const char* headerFile,
432
433                                              const char* branchTitle,
434
435                                              const Bool_t toSplit)
436
437 {
438
439   // Creates and returns the pointer of the unique instance
440
441   // Must be called only when the environment has changed 
442
443
444
445   if(!fgObjGetter){
446
447     fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
448
449     if(fgObjGetter->fFailed)
450
451       return 0;
452
453     else
454
455       return fgObjGetter ;
456
457   }
458
459
460
461   //First checks, if header file already opened
462
463   if(!fgObjGetter->fFile){
464
465      fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
466
467     if(fgObjGetter->fFailed)
468
469       return 0;
470
471     else
472
473       return fgObjGetter ;
474
475   }
476
477  
478
479   if(fgObjGetter->fHeaderFile.CompareTo(headerFile)==0){ //Opened the same header file   
480
481     if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0)&&   //Open the same branch title
482
483        (toSplit==fgObjGetter->fToSplit)){                          //Nothing should be cleaned
484
485       return fgObjGetter ;
486
487     }
488
489     else{ //Clean all data and AliEMCAL...zers
490
491       if(fgObjGetter->fToSplit)
492
493         fgObjGetter->CloseSplitFiles() ;          
494
495       fgObjGetter->CleanWhiteBoard() ;
496
497       fgObjGetter->fToSplit = toSplit ;
498
499       fgObjGetter->SetTitle(branchTitle) ;
500
501       return fgObjGetter ;
502
503     }
504
505   }
506
507   else{  //Close already opened files, clean memory and open new header file
508
509     if(gAlice)
510
511       delete gAlice ;
512
513     gAlice= 0;
514
515     if(fgObjGetter->fFile){
516
517       fgObjGetter->fFile->Close() ;
518
519       fgObjGetter->fFile=0;
520
521     }
522
523     if(fgObjGetter->fToSplit)
524
525       fgObjGetter->CloseSplitFiles() ;
526
527     fgObjGetter->CleanWhiteBoard() ;    
528
529     fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
530
531     return fgObjGetter ; 
532
533   }
534
535   return fgObjGetter ; 
536
537   
538
539 }
540
541
542
543 //____________________________________________________________________________ 
544
545 const Bool_t AliEMCALGetter::BranchExists(const TString recName) const
546
547 {
548
549   //Looks in the tree Tree"name" if branch with current name olready exists
550
551   
552
553   TString filename("") ;
554
555   TString name, dataname, zername;
556
557   if(recName == "SDigits"){
558
559     filename=fSDigitsFileName ;
560
561     name = "TreeS0" ;
562
563     dataname = "PHOS" ;
564
565     zername = "AliPHOSSDigitizer" ;
566
567   }
568
569   else
570
571     if(recName == "Digits"){
572
573       filename=fDigitsFileName ;
574
575       name = "TreeD0" ;
576
577       dataname = "PHOS" ;
578
579       zername = "AliPHOSDigitizer" ;
580
581     }
582
583     else
584
585       if(recName =="RecPoints"){
586
587         filename=fRecPointsFileName ;
588
589         name = "TreeR0" ;
590
591         dataname = "PHOSEmcRP" ;
592
593         zername = "AliPHOSClusterizer" ;
594
595       }
596
597       else
598
599         if(recName == "TrackSegments"){
600
601           filename=fTrackSegmentsFileName ;
602
603           name = "TreeR0" ;
604
605           dataname = "PHOSTS" ;
606
607           zername = "AliPHOSTrackSegmentMaker" ;
608
609         }        
610
611         else
612
613           if(recName == "RecParticles"){
614
615             filename= fRecParticlesFileName ;
616
617             name = "TreeR0" ;
618
619             dataname = "PHOSRP" ;
620
621             zername = "AliPHOSPID" ;
622
623           }
624
625           else
626
627             return kFALSE ;
628
629   
630
631   TFile * file ;
632
633   TTree * tree ;
634
635   if(fToSplit){
636
637     file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
638
639     if(!file)
640
641       file = TFile::Open(fSDigitsFileName.Data(),"update");
642
643   }
644
645   else
646
647     file = fFile ;
648
649   
650
651   tree = (TTree *)file->Get(name.Data()) ;
652
653   
654
655   if(!tree ) 
656
657     return kFALSE ;
658
659
660
661   TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
662
663   TIter next(lob) ; 
664
665   TBranch * branch = 0 ;  
666
667   TString titleName(fBranchTitle);
668
669   titleName+=":";
670
671   while ((branch = (static_cast<TBranch*>(next())))) {
672
673     TString branchName(branch->GetName() ) ; 
674
675     TString branchTitle(branch->GetTitle() ) ;  
676
677     if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){  
678
679       cerr << "WARNING: AliEMCALGetter::BranchExists -> branch " << dataname.Data() << " with title " << fBranchTitle << " already exits in "
680
681            << name.Data() << endl;
682
683       return kTRUE ;
684
685     }
686
687     if ( branchName.BeginsWith(zername) &&  branchTitle.BeginsWith(titleName) ){
688
689       cerr << "WARNING: AliEMCALGetter::BranchExists -> branch AliEMCAL... with title " << branch->GetTitle() << " already exits in "
690
691            << name.Data() << endl;     
692
693       return kTRUE ; 
694
695     }
696
697   }
698
699     //We can't delete three if gAlice points to it... To be redisigned somehow???!!!
700
701   if(!fToSplit){
702
703     if(name.Contains("TreeS"))
704
705       if(tree!=gAlice->TreeS())
706
707         tree->Delete();
708
709     if(name.Contains("TreeD"))
710
711       if(tree!=gAlice->TreeD())
712
713         tree->Delete();
714
715     if(name.Contains("TreeR"))
716
717       if(tree!=gAlice->TreeR())
718
719         tree->Delete();    
720
721   }
722
723   return kFALSE ;
724
725   
726
727 }
728
729
730
731 //____________________________________________________________________________ 
732
733 void AliEMCALGetter::ListBranches(Int_t event) const  
734
735 {
736
737   
738
739   TBranch * branch = 0 ; 
740
741   if (gAlice->GetEvent(event) == -1)
742
743     return ; 
744
745
746
747   TTree * t =  gAlice->TreeH() ; 
748
749   if(t){
750
751     cout << "INFO: AliEMCALGetter::ListBranches -> ****** Hits    : " << endl ; 
752
753     TObjArray * lob = t->GetListOfBranches() ;
754
755     TIter next(lob) ; 
756
757     while ( (branch = static_cast<TBranch*>(next())) )
758
759       cout << "             " << branch->GetName() << endl ; 
760
761   } else 
762
763     cerr << "WARNING::AliEMCALGetter::ListBranches -> TreeH not found for event " << event << endl ;  
764
765   
766
767   
768
769   t = gAlice->TreeS() ;
770
771   if(t){
772
773     cout << "INFO: AliEMCALGetter::ListBranches -> ****** SDigits : " << endl ; 
774
775     TObjArray * lob = t->GetListOfBranches() ;
776
777     TIter next(lob) ; 
778
779     while ( (branch = static_cast<TBranch*>(next())) )
780
781       cout << "             " << branch->GetName() << " " << branch->GetTitle() << endl ; 
782
783   } else 
784
785     cerr << "WARNING::AliEMCALGetter::ListBranches -> TreeS not found for event " << event << endl ;  
786
787     
788
789   t = gAlice->TreeD() ;
790
791   if(t){
792
793     cout << "INFO: AliEMCALGetter::ListBranches -> ****** Digits  : " << endl ; 
794
795     TObjArray * lob = t->GetListOfBranches() ;
796
797     TIter next(lob) ; 
798
799     while ( (branch = static_cast<TBranch*>(next())) )
800
801       cout << "             " << branch->GetName() << " " << branch->GetTitle() << endl ; 
802
803   } else 
804
805     cerr << "WARNING::AliEMCALGetter::ListBranches -> TreeD not found for event " << event << endl ;  
806
807   
808
809
810
811   t = gAlice->TreeR() ;
812
813   if(t){
814
815     cout << "INFO: AliEMCALGetter::ListBranches -> ****** Recon   : " << endl ; 
816
817     TObjArray * lob = t->GetListOfBranches() ;
818
819     TIter next(lob) ; 
820
821     while ( (branch = static_cast<TBranch*>(next())) )
822
823       cout << "             " << branch->GetName() << " " << branch->GetTitle() << endl ; 
824
825   } else 
826
827     cerr << "WARNING::AliEMCALGetter::ListBranches -> TreeR not found for event " << event << endl ;  
828
829   
830
831 }
832
833
834
835 //____________________________________________________________________________ 
836
837 void AliEMCALGetter::NewBranch(TString name, Int_t event)  
838
839 {
840
841   fBranchTitle = fSDigitsTitle = fDigitsTitle = fRecPointsTitle = fTrackSegmentsTitle = fRecParticlesTitle =  name ; 
842
843   Event(event) ; 
844
845 }
846
847
848
849 //____________________________________________________________________________ 
850
851 Bool_t AliEMCALGetter::NewFile(TString name)  
852
853 {
854
855   fHeaderFile = name ; 
856
857   fFile->Close() ; 
858
859   fFailed = kFALSE; 
860
861
862
863   fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
864
865   if(!fFile) {    //if file was not opened yet, read gAlice
866
867     fFile = TFile::Open(fHeaderFile.Data(),"update") ;
868
869     if (!fFile->IsOpen()) {
870
871       cerr << "ERROR : AliEMCALGetter::NewFile -> Cannot open " << fHeaderFile.Data() << endl ; 
872
873       fFailed = kTRUE ;
874
875       return fFailed ;  
876
877     }
878
879     gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
880
881   } 
882
883   
884
885   if (!gAlice) {
886
887     cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ; 
888
889     fFailed = kTRUE ;
890
891     return fFailed ; 
892
893   }
894
895   return fFailed ; 
896
897 }
898
899
900
901 //____________________________________________________________________________ 
902
903 const AliEMCAL * AliEMCALGetter::EMCAL() 
904
905 {
906
907   // returns the EMCAL object 
908
909   AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(fModuleFolder->FindObject("EMCAL")) ;  
910
911   if (!emcal) 
912
913     if (fDebug)
914
915       cout << "WARNING: AliEMCALGetter::EMCAL -> EMCAL module not found in Folders" << endl ; 
916
917   return emcal ; 
918
919 }  
920
921
922
923 //____________________________________________________________________________ 
924
925 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() 
926
927 {
928
929   AliEMCALGeometry * rv = 0 ; 
930
931   if (EMCAL() )
932
933     rv =  EMCAL()->GetGeometry() ;
934
935   return rv ; 
936
937
938
939
940
941 //____________________________________________________________________________ 
942
943 const Bool_t AliEMCALGetter::PostPrimaries(void) const 
944
945 {  //------- Primaries ----------------------
946
947
948
949   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
950
951   
952
953   TFolder * primariesFolder = dynamic_cast<TFolder*>(fPrimariesFolder->FindObject("Primaries")) ; 
954
955   if ( !primariesFolder ) {
956
957     if (fDebug) {
958
959       cout << "WARNING: AliEMCALGetter::Post Primaries -> Folder //" << fPrimariesFolder->GetName() << "/Primaries/ not found!" << endl;
960
961       cout << "INFO:    AliEMCALGetter::Post Primaries -> Adding Folder //" << fPrimariesFolder->GetName() << "/Primaries/"  << endl;
962
963     }
964
965     primariesFolder = fPrimariesFolder->AddFolder("Primaries", "Primaries particles from TreeK") ; 
966
967   }    
968
969   TClonesArray *primaries=  new TClonesArray("TParticle",1000) ;
970
971   primaries->SetName("Primaries") ;
972
973   primariesFolder->Add(primaries) ; 
974
975   
976
977   return kTRUE;
978
979
980
981
982
983 //____________________________________________________________________________ 
984
985 TObject** AliEMCALGetter::PrimariesRef(void) const 
986
987 {  //------- Primaries ----------------------
988
989
990
991   
992
993   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
994
995   if ( !fPrimariesFolder ) {
996
997     cerr << "ERROR: AliEMCALGetter::PrimariesRef -> Folder //" << fPrimariesFolder << " not found!" << endl;
998
999     abort() ;
1000
1001   }    
1002
1003  
1004
1005   TFolder * primariesFolder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ;
1006
1007   if ( !primariesFolder ) {
1008
1009     cerr << "ERROR: AliEMCALGetter::PrimariesRef -> Folder //" << fPrimariesFolder << "/Primaries/ not found!" << endl;  
1010
1011     abort() ;
1012
1013   }
1014
1015  
1016
1017   TObject * p = primariesFolder->FindObject("Primaries") ;
1018
1019   if(!p) {
1020
1021     cerr << "ERROR: AliEMCALGetter::PrimariesRef -> " << primariesFolder->GetName() << "/Primaries not found !" << endl ; 
1022
1023     abort() ;
1024
1025   }
1026
1027   else
1028
1029     return primariesFolder->GetListOfFolders()->GetObjectRef(p) ;
1030
1031 }
1032
1033
1034
1035 //____________________________________________________________________________ 
1036
1037 const Bool_t AliEMCALGetter::PostHits(void) const 
1038
1039 {  //------- Hits ----------------------
1040
1041
1042
1043   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
1044
1045   
1046
1047   TFolder * emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
1048
1049   if ( !emcalFolder ) {
1050
1051     if (fDebug) {
1052
1053       cout << "WARNING: AliEMCALGetter::Post H -> Folder //" << fHitsFolder << "/EMCAL/ not found!" << endl;
1054
1055       cout << "INFO:    AliEMCALGetter::Post H -> Adding Folder //" << fHitsFolder << "/EMCAL/"  << endl;
1056
1057     }
1058
1059     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
1060
1061   }    
1062
1063   TClonesArray *hits=  new TClonesArray("AliEMCALHit",1000) ;
1064
1065   hits->SetName("Hits") ;
1066
1067   emcalFolder->Add(hits) ; 
1068
1069   
1070
1071   return kTRUE;
1072
1073
1074
1075
1076
1077 //____________________________________________________________________________ 
1078
1079 TObject ** AliEMCALGetter::HitsRef(void) const 
1080
1081 {  //------- Hits ----------------------
1082
1083
1084
1085   
1086
1087   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
1088
1089   if ( !fHitsFolder ) {
1090
1091     cerr << "ERROR: AliEMCALGetter::Post H -> Folder //" << fHitsFolder << " not found!" << endl;
1092
1093     return 0;
1094
1095   }    
1096
1097  
1098
1099   TFolder * emcalFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
1100
1101   if ( !emcalFolder ) {
1102
1103     cerr << "ERROR: AliEMCALGetter::Post HRef -> Folder //" << fHitsFolder << "/EMCAL/ not found!" << endl;  
1104
1105     return 0;
1106
1107   }
1108
1109  
1110
1111   TObject * h = emcalFolder->FindObject("Hits") ;
1112
1113   if(!h) {
1114
1115     cerr << "ERROR: AliEMCALGetter::HRef -> " << emcalFolder->GetName() << "/Hits not found !" << endl ; 
1116
1117     return 0 ;
1118
1119   }
1120
1121   else
1122
1123     return emcalFolder->GetListOfFolders()->GetObjectRef(h) ;
1124
1125 }
1126
1127
1128
1129 //____________________________________________________________________________ 
1130
1131 const Bool_t AliEMCALGetter::PostSDigits(const char * name, const char * headerFile) const 
1132
1133 {  //---------- SDigits -------------------------
1134
1135
1136
1137   
1138
1139   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
1140
1141   // because you can have sdigits from several hit files for mixing
1142
1143   
1144
1145   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
1146
1147   if ( !emcalFolder ) {
1148
1149     if (fDebug) {
1150
1151       cout << "WARNING: AliEMCALGetter::Post S -> Folder //" << fSDigitsFolder << "/EMCAL/ not found!" << endl;
1152
1153       cout << "INFO:    AliEMCALGetter::Post S -> Adding Folder //" << fHitsFolder << "/EMCAL/" << endl;
1154
1155     }
1156
1157     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1158
1159   }    
1160
1161
1162
1163   TString subdir(headerFile) ;
1164
1165   subdir.ReplaceAll("/", "_") ; 
1166
1167   TFolder * emcalSubFolder = dynamic_cast<TFolder*>(emcalFolder->FindObject(subdir)) ; 
1168
1169   if ( !emcalSubFolder ) 
1170
1171     emcalSubFolder = emcalFolder->AddFolder(subdir, ""); 
1172
1173
1174
1175   
1176
1177   TObject * sd  = emcalSubFolder->FindObject(name); 
1178
1179   if ( !sd ) {
1180
1181     TClonesArray * sdigits = new TClonesArray("AliEMCALDigit",1) ;
1182
1183     sdigits->SetName(name) ;
1184
1185     emcalSubFolder->Add(sdigits) ;
1186
1187   }
1188
1189   
1190
1191   return kTRUE;
1192
1193
1194
1195 //____________________________________________________________________________ 
1196
1197 TObject ** AliEMCALGetter::SDigitsRef(const char * name, const char * file) const 
1198
1199 {  //------- SDigits ----------------------
1200
1201   
1202
1203   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/filename/SDigits
1204
1205
1206
1207   if ( !fSDigitsFolder ) {
1208
1209     cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //" << fSDigitsFolder << " not found!" << endl;
1210
1211     abort() ;
1212
1213   }    
1214
1215  
1216
1217   TFolder * emcalFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
1218
1219   if ( !emcalFolder ) {
1220
1221     cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //" << fSDigitsFolder << "/EMCAL/ not found!" << endl;
1222
1223     abort() ;
1224
1225   }
1226
1227
1228
1229   TFolder * emcalSubFolder = 0 ;
1230
1231   if(file)
1232
1233     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(file)) ;
1234
1235   else
1236
1237     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(fHeaderFile)) ;
1238
1239   
1240
1241   if(!emcalSubFolder) {
1242
1243     cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //Folders/RunMC/Event/Data/EMCAL/" << file << "not found!" << endl;
1244
1245     abort() ;
1246
1247   }
1248
1249
1250
1251   TObject * dis = emcalSubFolder->FindObject(name) ;
1252
1253   if(!dis) {
1254
1255     cerr << "ERROR: AliEMCALGetter::DigitesSRef -> object " << name << " not found! " << endl ; 
1256
1257     abort() ;
1258
1259   }
1260
1261   else
1262
1263     return emcalSubFolder->GetListOfFolders()->GetObjectRef(dis) ;
1264
1265
1266
1267 }
1268
1269
1270
1271 //____________________________________________________________________________ 
1272
1273 const Bool_t AliEMCALGetter::PostSDigitizer(AliEMCALSDigitizer * sdigitizer) const 
1274
1275 {  //---------- SDigitizer -------------------------
1276
1277     
1278
1279   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
1280
1281
1282
1283
1284
1285   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
1286
1287
1288
1289   if ( !sd ) {
1290
1291     cerr << "ERROR: AliEMCALGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
1292
1293     return kFALSE ;
1294
1295   }        
1296
1297   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
1298
1299   if ( !emcal )  {
1300
1301     if (fDebug) {
1302
1303       cout <<"WARNING: AliEMCALGetter::Post Ser ->//" << fTasksFolder << "/SDigitizer/EMCAL/ not found!" << endl;  
1304
1305       cout <<"INFO: AliEMCALGetter::Post Ser -> Adding //" << fTasksFolder << "/SDigitizer/EMCAL/" << endl;
1306
1307     }
1308
1309     emcal = new TTask("EMCAL", "") ; 
1310
1311     sd->Add(emcal) ; 
1312
1313   } 
1314
1315   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdigitizer->GetName() )); 
1316
1317   if (emcalsd) { 
1318
1319     if (fDebug)
1320
1321       cout << "INFO: AliEMCALGetter::Post Ser -> Task " << sdigitizer->GetName() << " already exists" << endl ; 
1322
1323     emcal->GetListOfTasks()->Remove(emcalsd) ;
1324
1325   }
1326
1327   emcal->Add(sdigitizer) ;      
1328
1329   return kTRUE; 
1330
1331   
1332
1333 }
1334
1335
1336
1337 //____________________________________________________________________________ 
1338
1339 TObject ** AliEMCALGetter::SDigitizerRef(const char * name) const 
1340
1341 {  
1342
1343
1344
1345   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
1346
1347   if ( !sd ) {
1348
1349     cerr << "ERROR: AliEMCALGetter::Post SerRef -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
1350
1351     abort();
1352
1353   }        
1354
1355
1356
1357   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
1358
1359   if ( !emcal )  {
1360
1361     cerr <<"ERROR: AliEMCALGetter::Post SerRef ->  //" << fTasksFolder << "/SDigitizer/EMCAL not found!" << endl;
1362
1363     abort();
1364
1365   }        
1366
1367
1368
1369   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
1370
1371
1372
1373   return emcal->GetListOfTasks()->GetObjectRef(task) ;
1374
1375
1376
1377 }
1378
1379
1380
1381 //____________________________________________________________________________ 
1382
1383 const Bool_t AliEMCALGetter::PostSDigitizer(const char * name, const char * file) const 
1384
1385 {  //---------- SDigitizer -------------------------
1386
1387   
1388
1389  // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
1390
1391
1392
1393   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
1394
1395   if ( !sd ) {
1396
1397     cerr << "ERROR: AliEMCALGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
1398
1399     return kFALSE ;
1400
1401   }        
1402
1403
1404
1405   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
1406
1407   if ( !emcal )  {
1408
1409     if (fDebug) {
1410
1411       cout <<"WARNING: AliEMCALGetter::Post Ser ->  //" << fTasksFolder << "/SDigitizer/EMCAL/ not found!" << endl;
1412
1413       cout <<"INFO: AliEMCALGetter::Post Ser -> Adding  //" << fTasksFolder << "/SDigitizer/EMCAL" << endl;
1414
1415     }
1416
1417     emcal = new TTask("EMCAL", "") ; 
1418
1419     sd->Add(emcal) ; 
1420
1421   } 
1422
1423
1424
1425   TString sdname(name) ;
1426
1427   sdname.Append(":") ;
1428
1429   sdname.Append(file);
1430
1431   sdname.ReplaceAll("/","_") ; 
1432
1433   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdname )); 
1434
1435   if (!emcalsd) {
1436
1437     emcalsd = new AliEMCALSDigitizer() ;  
1438
1439     //Note, we can not call constructor with parameters: it will call Getter and screw up everething
1440
1441     emcalsd->SetName(sdname) ;
1442
1443     emcalsd->SetTitle(file) ;
1444
1445     emcal->Add(emcalsd) ;       
1446
1447   }
1448
1449   return kTRUE; 
1450
1451   
1452
1453 }
1454
1455
1456
1457 //____________________________________________________________________________ 
1458
1459 const Bool_t AliEMCALGetter::PostDigits(const char * name) const 
1460
1461 {  //---------- Digits -------------------------
1462
1463
1464
1465   // the hierarchy is //Folders/Run/Event/Data/EMCAL/SDigits/name
1466
1467
1468
1469   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
1470
1471
1472
1473   if ( !emcalFolder ) {
1474
1475     if (fDebug) {
1476
1477       cout << "WARNING: AliEMCALGetter::Post D -> Folder //" << fDigitsFolder << "/EMCAL/ not found!" << endl;
1478
1479       cout << "INFO:    AliEMCALGetter::Post D -> Adding Folder //" << fDigitsFolder << "/EMCAL/" << endl;
1480
1481     }
1482
1483     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
1484
1485   }    
1486
1487  
1488
1489   TObject*  dig = emcalFolder->FindObject( name ) ;
1490
1491   if ( !dig ) {
1492
1493     TClonesArray * digits = new TClonesArray("AliEMCALDigit",1000) ;
1494
1495     digits->SetName(name) ;
1496
1497     emcalFolder->Add(digits) ;  
1498
1499   }
1500
1501   return kTRUE; 
1502
1503 }
1504
1505
1506
1507 //____________________________________________________________________________ 
1508
1509 TObject ** AliEMCALGetter::DigitsRef(const char * name) const 
1510
1511 { //------- Digits ----------------------
1512
1513   
1514
1515   // the hierarchy is //Folders/Run/Event/Data/EMCAL/Digits/name
1516
1517
1518
1519   if ( !fDigitsFolder ) {
1520
1521     cerr << "ERROR: AliEMCALGetter::Post DRef -> Folder //" << fDigitsFolder << " not found!" << endl;
1522
1523     abort() ;
1524
1525   }    
1526
1527   
1528
1529   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ; 
1530
1531   if ( !emcalFolder ) {
1532
1533     cerr << "ERROR: AliEMCALGetter::DRef -> Folder //" << fDigitsFolder << "/EMCAL/ not found!" << endl;
1534
1535     abort() ;
1536
1537   }    
1538
1539
1540
1541   TObject * d = emcalFolder->FindObject(name) ;
1542
1543   if(!d) {
1544
1545     cerr << "ERROR: AliEMCALGetter::DigitsRef -> object " << name << " not found! " << endl ; 
1546
1547     abort() ;
1548
1549   }   
1550
1551   else
1552
1553     return emcalFolder->GetListOfFolders()->GetObjectRef(d) ;
1554
1555
1556
1557 }
1558
1559
1560
1561 //____________________________________________________________________________ 
1562
1563 const Bool_t AliEMCALGetter::PostDigitizer(AliEMCALDigitizer * digitizer) const 
1564
1565 {  //---------- Digitizer -------------------------
1566
1567   
1568
1569   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
1570
1571
1572
1573   if ( !sd ) {
1574
1575     cerr << "ERROR: AliEMCALGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
1576
1577     return kFALSE ;
1578
1579   }        
1580
1581   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
1582
1583   if ( !emcal )  {
1584
1585     if (fDebug) {
1586
1587       cout <<"WARNING: AliEMCALGetter::Post Der ->  //" << fTasksFolder << "/Digitizer/EMCAL not found!" << endl;
1588
1589       cout <<"INFO: AliEMCALGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/EMCAL" << endl; 
1590
1591     }
1592
1593     emcal = new TTask("EMCAL", "") ; 
1594
1595     sd->Add(emcal) ; 
1596
1597   } 
1598
1599
1600
1601     AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(digitizer->GetName())) ; 
1602
1603     if (emcald) { 
1604
1605       emcald->Delete() ;
1606
1607       emcal->GetListOfTasks()->Remove(emcald) ;
1608
1609     }
1610
1611     emcal->Add(digitizer) ; 
1612
1613     return kTRUE; 
1614
1615 }  
1616
1617
1618
1619 //____________________________________________________________________________ 
1620
1621 const Bool_t AliEMCALGetter::PostDigitizer(const char * name) const 
1622
1623 {  //---------- Digitizer -------------------------
1624
1625   
1626
1627  // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
1628
1629
1630
1631   TTask * d  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
1632
1633   if ( !d ) {
1634
1635     cerr << "ERROR: AliEMCALGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
1636
1637     return kFALSE ;
1638
1639   }        
1640
1641
1642
1643   TTask * emcal = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("EMCAL")) ; 
1644
1645   if ( !emcal )  {
1646
1647     if (fDebug) {
1648
1649       cout <<"WARNING: AliEMCALGetter::Post Der -> //" << fTasksFolder << "/Digitizer/EMCAL not found!" << endl; 
1650
1651       cout <<"INFO: AliEMCALGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
1652
1653     }
1654
1655     emcal = new TTask("EMCAL", "") ; 
1656
1657     d->Add(emcal) ; 
1658
1659
1660
1661
1662
1663   AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(name)) ; 
1664
1665   if (!emcald) { 
1666
1667     emcald = new AliEMCALDigitizer() ;
1668
1669     emcald->SetName(fDigitsTitle) ;
1670
1671     emcald->SetTitle(fHeaderFile) ;
1672
1673     emcal->Add(emcald) ;
1674
1675   }
1676
1677   return kTRUE;  
1678
1679 }
1680
1681
1682
1683 //____________________________________________________________________________ 
1684
1685 TObject ** AliEMCALGetter::DigitizerRef(const char * name) const 
1686
1687 {  
1688
1689   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
1690
1691   if ( !sd ) {
1692
1693     cerr << "ERROR: AliEMCALGetter::Post DerRef -> Task //" << fTasksFolder->GetName() << "/Digitizer not found!" << endl;
1694
1695     abort();
1696
1697   }        
1698
1699
1700
1701   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
1702
1703   if ( !emcal )  {
1704
1705     cerr <<"ERROR: AliEMCALGetter::Post DerRef ->  //" << fTasksFolder->GetName() << "/Digitizer/EMCAL" << endl;
1706
1707     abort();
1708
1709   }        
1710
1711
1712
1713   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
1714
1715
1716
1717   return emcal->GetListOfTasks()->GetObjectRef(task) ;
1718
1719
1720
1721 }
1722
1723  
1724
1725 //____________________________________________________________________________ 
1726
1727 const Bool_t AliEMCALGetter::PostRecPoints(const char * name) const 
1728
1729 { // -------------- RecPoints -------------------------------------------
1730
1731   
1732
1733   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
1734
1735   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShowerRecPoints/name
1736
1737
1738
1739   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
1740
1741   
1742
1743   if ( !emcalFolder ) {
1744
1745     if (fDebug) {
1746
1747       cout << "WARNING: AliEMCALGetter::Post RPo -> Folder //" << fRecoFolder << "/EMCAL/ not found!" << endl;
1748
1749       cout << "INFO:    AliEMCALGetter::Post Rpo -> Adding Folder //" << fRecoFolder << "/EMCAL/" << endl;
1750
1751     }
1752
1753     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
1754
1755   }    
1756
1757   
1758
1759   // Tower RecPoints 
1760
1761   TFolder * emcalRPoTowerFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("TowerRecPoints")) ;
1762
1763   if ( !emcalRPoTowerFolder ) {
1764
1765     if (fDebug) {
1766
1767       cout << "WARNING: AliEMCALGetter::Post RPo -> Folder //" << fRecoFolder << "/EMCAL/TowerRecPoints/ not found!" << endl;
1768
1769       cout << "INFO:    AliEMCALGetter::Post Rpo -> Adding Folder //" << fRecoFolder << "/EMCAL/TowerRecPoints not found!" << endl;
1770
1771     }
1772
1773     emcalRPoTowerFolder = emcalFolder->AddFolder("TowerRecPoints", "Tower RecPoints from EMCAL") ;  
1774
1775   }    
1776
1777   
1778
1779   TObject * erp = emcalFolder->FindObject( name ) ;
1780
1781   if ( !erp )   {
1782
1783     TObjArray * towerrp = new TObjArray(100) ;
1784
1785     towerrp->SetName(name) ;
1786
1787     emcalRPoTowerFolder->Add(towerrp) ;  
1788
1789   }
1790
1791
1792
1793   // Pre Shower RecPoints 
1794
1795   TFolder * emcalRPoPreShoFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("PreShowerRecPoints")) ;
1796
1797   if ( !emcalRPoPreShoFolder ) {
1798
1799     if (fDebug) {
1800
1801       cout << "WARNING: AliEMCALGetter::Post RPo -> Folder //" << fRecoFolder << "/EMCAL/PreShowerRecPoints/ not found!" << endl;
1802
1803       cout << "INFO:    AliEMCALGetter::Post Rpo -> Adding Folder //" << fRecoFolder << "/EMCAL/PreShowerRecPoints/" << endl;
1804
1805     }
1806
1807     emcalRPoPreShoFolder = emcalFolder->AddFolder("PreShowerRecPoints", "PreSho RecPoints from EMCAL") ;  
1808
1809   }    
1810
1811   
1812
1813   TObject * crp =  emcalRPoPreShoFolder->FindObject( name ) ;
1814
1815   if ( !crp )   {
1816
1817     TObjArray * preshorp = new TObjArray(100) ;
1818
1819     preshorp->SetName(name) ;
1820
1821     emcalRPoPreShoFolder->Add(preshorp) ;  
1822
1823   }
1824
1825   return kTRUE; 
1826
1827 }
1828
1829
1830
1831 //____________________________________________________________________________ 
1832
1833 TObject ** AliEMCALGetter::TowerRecPointsRef(const char * name) const 
1834
1835 { // -------------- RecPoints -------------------------------------------
1836
1837   
1838
1839   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
1840
1841    
1842
1843   if ( !fRecoFolder ) {
1844
1845     cerr << "ERROR: AliEMCALGetter::TowerRecPointsRef -> Folder //" << fRecoFolder << " not found!" << endl;
1846
1847     abort() ; 
1848
1849   }    
1850
1851
1852
1853   TFolder * towerFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
1854
1855   if ( !towerFolder ) {
1856
1857     cerr << "ERROR: AliEMCALGetter::TowerRecPointsRef -> Folder //" << fRecoFolder << "/EMCAL/TowerRecPoints/ not found!" << endl;
1858
1859     abort() ;
1860
1861   }    
1862
1863
1864
1865
1866
1867   TObject * trp = towerFolder->FindObject(name ) ;
1868
1869   if ( !trp )   {
1870
1871     cerr << "ERROR: AliEMCALGetter::TowerRecPointsRef -> Object " << name << " not found!" << endl  ;
1872
1873     abort() ; 
1874
1875   }
1876
1877   return towerFolder->GetListOfFolders()->GetObjectRef(trp) ;
1878
1879
1880
1881
1882
1883
1884
1885 //____________________________________________________________________________ 
1886
1887 TObject ** AliEMCALGetter::PreShowerRecPointsRef(const char * name) const 
1888
1889 { // -------------- RecPoints -------------------------------------------
1890
1891   
1892
1893   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShowerRecPoints/name
1894
1895    
1896
1897   if ( !fRecoFolder ) {
1898
1899     cerr << "ERROR: AliEMCALGetter::PreShowerRecPointsRef -> Folder //" << fRecoFolder << " not found!" << endl;
1900
1901     abort() ; 
1902
1903   }    
1904
1905
1906
1907   TFolder * preshoFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ; 
1908
1909   if ( !preshoFolder ) {
1910
1911     cerr << "ERROR: AliEMCALGetter::PreShowerRecPointsRef -> Folder //" << fRecoFolder << "/EMCAL/PreShowerRecPoints/" << endl;
1912
1913     abort() ;
1914
1915   }    
1916
1917
1918
1919   TObject * prp = preshoFolder->FindObject(name ) ;
1920
1921   if ( !prp )   {
1922
1923     cerr << "ERROR: AliEMCALGetter::PreShowerRecPointsRef -> Object " << name << " not found! " << endl ; 
1924
1925     abort() ;
1926
1927   }
1928
1929   return preshoFolder->GetListOfFolders()->GetObjectRef(prp) ;
1930
1931
1932
1933
1934
1935
1936
1937 //____________________________________________________________________________ 
1938
1939 const Bool_t AliEMCALGetter::PostClusterizer(AliEMCALClusterizer * clu) const 
1940
1941 { // ------------------ AliEMCALClusterizer ------------------------
1942
1943   
1944
1945   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1946
1947
1948
1949   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1950
1951
1952
1953   if ( !tasks ) {
1954
1955     cerr << "ERROR: AliEMCALGetter::Post Rer -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
1956
1957     return kFALSE ;
1958
1959   }        
1960
1961         
1962
1963   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1964
1965   if ( !emcal )  {
1966
1967     if (fDebug) {
1968
1969       cout <<"WARNING: AliEMCALGetter::Post Rer -> //" << fTasksFolder << "/ReconstructionerEMCAL not found!" << endl; 
1970
1971       cout <<"INFO: AliEMCALGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl; 
1972
1973     }
1974
1975     emcal = new TTask("EMCAL", "") ; 
1976
1977     tasks->Add(emcal) ; 
1978
1979   } 
1980
1981
1982
1983   AliEMCALClusterizerv1 * emcalcl = dynamic_cast<AliEMCALClusterizerv1*>(emcal->GetListOfTasks()->FindObject(clu->GetName())) ; 
1984
1985   if (emcalcl) { 
1986
1987     if (fDebug)
1988
1989       cout << "INFO: AliEMCALGetter::Post Rer -> Task " << clu->GetName() << " already exists" << endl ; 
1990
1991     emcalcl->Delete() ; 
1992
1993     emcal->GetListOfTasks()->Remove(emcalcl) ;
1994
1995   }
1996
1997   emcal->Add(clu) ;      
1998
1999   return kTRUE; 
2000
2001
2002
2003
2004
2005 //____________________________________________________________________________ 
2006
2007 TObject ** AliEMCALGetter::ClusterizerRef(const char * name) const 
2008
2009 { // ------------------ AliEMCALClusterizer ------------------------
2010
2011   
2012
2013   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
2014
2015
2016
2017   if ( !tasks ) {
2018
2019     cerr << "ERROR: AliEMCALGetter::Post RerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
2020
2021     abort() ;
2022
2023   }        
2024
2025         
2026
2027   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2028
2029   if ( !emcal )  {
2030
2031     cerr <<"WARNING: AliEMCALGetter::Post RerRef -> //" << fTasksFolder->GetName() << "/Reconstructioner/EMCAL" << endl; 
2032
2033     abort() ; 
2034
2035   }   
2036
2037
2038
2039   TList * l = emcal->GetListOfTasks() ; 
2040
2041   TIter it(l) ;
2042
2043   TTask * task ;
2044
2045   TTask * clu = 0 ;
2046
2047   TString cluname(name) ;
2048
2049   cluname+=":clu-" ;
2050
2051   while((task = static_cast<TTask *>(it.Next()) )){
2052
2053     TString taskname(task->GetName()) ;
2054
2055     if(taskname.BeginsWith(cluname)){
2056
2057       clu = task ;
2058
2059       break ;
2060
2061     }
2062
2063   }
2064
2065
2066
2067   if(clu) 
2068
2069     return l->GetObjectRef(clu) ;
2070
2071   else {
2072
2073     cerr << "ERROR: AliEMCALGetter::Post RerRef -> task " << task->GetName() << " not found! " << endl ; 
2074
2075     abort() ;
2076
2077   }
2078
2079 }
2080
2081
2082
2083 //____________________________________________________________________________ 
2084
2085 const Bool_t AliEMCALGetter::PostClusterizer(const char * name) const 
2086
2087 { // ------------------ AliEMCALClusterizer ------------------------
2088
2089
2090
2091   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
2092
2093   
2094
2095   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
2096
2097
2098
2099   if ( !tasks ) {
2100
2101     cerr << "ERROR: AliEMCALGetter::Post Rer -> Task//" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl; 
2102
2103     return kFALSE ;
2104
2105   }        
2106
2107   
2108
2109   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2110
2111   if ( !emcal )  {
2112
2113     if (fDebug) {
2114
2115       cout <<"WARNING: AliEMCALGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/EMCAL not found!" << endl;
2116
2117       cout <<"INFO: AliEMCALGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl;
2118
2119     }
2120
2121     emcal = new TTask("EMCAL", "") ; 
2122
2123     tasks->Add(emcal) ; 
2124
2125   } 
2126
2127
2128
2129   TList * l = emcal->GetListOfTasks() ;   
2130
2131   TIter it(l) ;
2132
2133   TString clun(name) ;
2134
2135   clun+=":clu" ; 
2136
2137   TTask * task ;
2138
2139   while((task = static_cast<TTask *>(it.Next()) )){
2140
2141     TString taskname(task->GetName()) ;
2142
2143     if(taskname.BeginsWith(clun))
2144
2145       return kTRUE ;
2146
2147   }
2148
2149
2150
2151   AliEMCALClusterizerv1 * emcalcl = new AliEMCALClusterizerv1() ;
2152
2153   clun+="-v1" ; 
2154
2155   emcalcl->SetName(clun) ;
2156
2157   emcalcl->SetTitle(fHeaderFile) ; 
2158
2159   emcal->Add(emcalcl) ;
2160
2161   return kTRUE; 
2162
2163   
2164
2165 }
2166
2167
2168
2169 //____________________________________________________________________________ 
2170
2171 /*const Bool_t AliEMCALGetter::PostTrackSegments(const char * name) const 
2172
2173 { // ---------------TrackSegments -----------------------------------
2174
2175   
2176
2177   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
2178
2179
2180
2181   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
2182
2183   
2184
2185   if ( !emcalFolder ) {
2186
2187     if (fDebug) {
2188
2189       cout << "WARNING: AliEMCALGetter::Post TS -> Folder //" << fRecoFolder << "/EMCAL/ not found!" << endl;
2190
2191       cout << "INFO:    AliEMCALGetter::Post TS -> Adding Folder //" << fRecoFolder << "/EMCAL" << endl;
2192
2193     }
2194
2195     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
2196
2197   }    
2198
2199
2200
2201   TFolder * emcalTSFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("TrackSegments")) ;
2202
2203   if ( !emcalTSFolder ) {
2204
2205     if (fDebug) {
2206
2207       cout << "WARNING: AliEMCALGetter::Post TS -> Folder//" << fRecoFolder << "/EMCAL/TrackSegments/ not found!" << endl; 
2208
2209       cout << "INFO:    AliEMCALGetter::Post TS -> Adding Folder //" << fRecoFolder << "/EMCAL/TrackSegments/" << endl; 
2210
2211     }
2212
2213     emcalTSFolder = emcalFolder->AddFolder("TrackSegments", "TrackSegments from EMCAL") ;  
2214
2215   }    
2216
2217   
2218
2219   TObject * tss =  emcalTSFolder->FindObject( name ) ;
2220
2221   if (!tss) {
2222
2223     TClonesArray * ts = new TClonesArray("AliEMCALTrackSegment",100) ;
2224
2225     ts->SetName(name) ;
2226
2227     emcalTSFolder->Add(ts) ;  
2228
2229   }
2230
2231   return kTRUE; 
2232
2233
2234
2235
2236
2237 //____________________________________________________________________________ 
2238
2239 TObject ** AliEMCALGetter::TrackSegmentsRef(const char * name) const 
2240
2241 { // ---------------TrackSegments -----------------------------------
2242
2243   
2244
2245   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
2246
2247
2248
2249  if ( !fRecoFolder ) {
2250
2251     cerr << "ERROR: AliEMCALGetter::TrackSegmentsRef -> Folder //" << fRecoFolder << "not found!" << endl;
2252
2253     abort() ; 
2254
2255   }    
2256
2257
2258
2259   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ; 
2260
2261   if ( !emcalFolder ) {
2262
2263     cerr << "ERROR: AliEMCALGetter::TrackSegmentsRef -> Folder //" << fRecoFolder << "/EMCAL/TrackSegments/ not found!" << endl;
2264
2265     abort();
2266
2267   }    
2268
2269   
2270
2271   TObject * tss =  emcalFolder->FindObject(name) ;
2272
2273   if (!tss) {
2274
2275     cerr << "ERROR: AliEMCALGetter::TrackSegmentsRef -> object " << name << " not found! " << endl ;  
2276
2277     abort() ;  
2278
2279   }
2280
2281   return emcalFolder->GetListOfFolders()->GetObjectRef(tss) ;
2282
2283
2284
2285
2286
2287 //____________________________________________________________________________ 
2288
2289 const Bool_t AliEMCALGetter::PostTrackSegmentMaker(AliEMCALTrackSegmentMaker * tsmaker) const 
2290
2291 { //------------Track Segment Maker ------------------------------
2292
2293   
2294
2295   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
2296
2297
2298
2299   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
2300
2301
2302
2303   if ( !tasks ) {
2304
2305     cerr << "ERROR: AliEMCALGetter::Post Ter -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
2306
2307     return kFALSE ;
2308
2309   }        
2310
2311         
2312
2313   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2314
2315   if ( !emcal )  {
2316
2317     if (fDebug) {
2318
2319       cout <<"WARNING: AliEMCALGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/EMCAL not found!" << endl; 
2320
2321       cout <<"INFO: AliEMCALGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl;
2322
2323     }
2324
2325     emcal = new TTask("EMCAL", "") ; 
2326
2327     tasks->Add(emcal) ; 
2328
2329   } 
2330
2331
2332
2333   AliEMCALTrackSegmentMaker * emcalts = 
2334
2335     dynamic_cast<AliEMCALTrackSegmentMaker*>(emcal->GetListOfTasks()->FindObject(tsmaker->GetName())) ; 
2336
2337   if (emcalts) { 
2338
2339     emcalts->Delete() ;
2340
2341     emcal->GetListOfTasks()->Remove(emcalts) ;
2342
2343   }
2344
2345   emcal->Add(tsmaker) ;      
2346
2347   return kTRUE; 
2348
2349   
2350
2351
2352
2353 //____________________________________________________________________________ 
2354
2355 const Bool_t AliEMCALGetter::PostTrackSegmentMaker(const char * name) const 
2356
2357 { //------------Track Segment Maker ------------------------------
2358
2359   
2360
2361   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
2362
2363
2364
2365   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
2366
2367   
2368
2369   if ( !tasks ) {
2370
2371     cerr << "ERROR: AliEMCALGetter::Post Ter -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
2372
2373     return kFALSE ;
2374
2375   }        
2376
2377   
2378
2379   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2380
2381   if ( !emcal )  {
2382
2383     if (fDebug) {
2384
2385       cout <<"WARNING: AliEMCALGetter::Post Ter -> //" << fTasksFolder->GetName() << "/Reconstructioner/EMCAL not found!" << endl; 
2386
2387       cout <<"INFO: AliEMCALGetter::Post Ter -> Adding //" << fTasksFolder->GetName() << "/Reconstructioner/EMCAL" << endl;
2388
2389     }
2390
2391     emcal = new TTask("EMCAL", "") ; 
2392
2393     tasks->Add(emcal) ; 
2394
2395   } 
2396
2397
2398
2399   TList * l = emcal->GetListOfTasks() ;   
2400
2401   TIter it(l) ;
2402
2403   TString tsn(name);
2404
2405   tsn+=":tsm" ; 
2406
2407   TTask * task ;
2408
2409   while((task = static_cast<TTask *>(it.Next()) )){
2410
2411     TString taskname(task->GetName()) ;
2412
2413     if(taskname.BeginsWith(tsn))
2414
2415       return kTRUE ;
2416
2417   }
2418
2419   
2420
2421   AliEMCALTrackSegmentMakerv1 * emcalts = new AliEMCALTrackSegmentMakerv1() ;
2422
2423   tsn+="-v1" ;
2424
2425   emcalts->SetName(tsn) ;
2426
2427   emcalts->SetTitle(fHeaderFile) ;
2428
2429   emcal->Add(emcalts) ;      
2430
2431   return kTRUE; 
2432
2433   
2434
2435
2436
2437   
2438
2439   
2440
2441
2442
2443
2444
2445 //____________________________________________________________________________ 
2446
2447 TObject ** AliEMCALGetter::TSMakerRef(const char * name) const 
2448
2449 { //------------Track Segment Maker ------------------------------
2450
2451   
2452
2453   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
2454
2455
2456
2457   if ( !tasks ) {
2458
2459     cerr << "ERROR: AliEMCALGetter::TSLakerRef TerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
2460
2461     abort() ;
2462
2463   }        
2464
2465         
2466
2467   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2468
2469   if ( !emcal )  {
2470
2471     cerr <<"WARNING: AliEMCALGetter::TSMakerRef TerRef -> //" << fTasksFolder->GetName() << "/Reconstructioner/EMCAL not found!" << endl; 
2472
2473     abort() ; 
2474
2475   }   
2476
2477
2478
2479   TList * l = emcal->GetListOfTasks() ; 
2480
2481   TIter it(l) ;
2482
2483   TTask * task ;
2484
2485   TTask * tsm = 0 ;
2486
2487   TString tsmname(name) ;
2488
2489   tsmname+=":tsm-" ;
2490
2491   while((task = static_cast<TTask *>(it.Next()) )){
2492
2493     TString taskname(task->GetName()) ;
2494
2495     if(taskname.BeginsWith(tsmname)){
2496
2497       tsm = task ;
2498
2499       break ;
2500
2501     }
2502
2503   }
2504
2505   
2506
2507   if(tsm) 
2508
2509     return l->GetObjectRef(tsm) ;
2510
2511   else {
2512
2513     cerr << "ERROR: AliEMCALGetter::TSLakerRef -> task " << task->GetName() << " not found! " << endl ; 
2514
2515     abort() ;
2516
2517   }
2518
2519
2520
2521
2522
2523 //____________________________________________________________________________ 
2524
2525 const Bool_t AliEMCALGetter::PostRecParticles(const char * name) const 
2526
2527 {  // -------------------- RecParticles ------------------------
2528
2529   
2530
2531   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
2532
2533
2534
2535   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
2536
2537   
2538
2539   if ( !emcalFolder ) {
2540
2541     if (fDebug) {
2542
2543       cout << "WARNING: AliEMCALGetter::Post RPa -> Folder //" << fRecoFolder << "/EMCAL/ not found!" << endl;
2544
2545       cout << "INFO:    AliEMCALGetter::Post Rpa -> Adding Folder //" << fRecoFolder << "/EMCAL/" << endl;
2546
2547     }
2548
2549     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
2550
2551   }    
2552
2553
2554
2555  TFolder * emcalRPaFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("RecParticles")) ;
2556
2557   if ( !emcalRPaFolder ) {
2558
2559     if (fDebug) {
2560
2561       cout << "WARNING: AliEMCALGetter::Post RPa -> Folder //" << fRecoFolder << "/EMCAL/RecParticles/ not found!" << endl;
2562
2563       cout << "INFO:    AliEMCALGetter::Post RPa -> Adding Folder //" << fRecoFolder << "/EMCAL/RecParticles/" << endl;
2564
2565     }
2566
2567     emcalRPaFolder = emcalFolder->AddFolder("RecParticles", "RecParticles from EMCAL") ;  
2568
2569   } 
2570
2571
2572
2573   TObject * rps = emcalRPaFolder->FindObject( name )  ;
2574
2575   if ( !rps ) {
2576
2577     TClonesArray * rp = new TClonesArray("AliEMCALRecParticle",100) ;
2578
2579     rp->SetName(name) ;    
2580
2581     emcalRPaFolder->Add(rp) ;  
2582
2583   }
2584
2585   return kTRUE; 
2586
2587
2588
2589
2590
2591 //____________________________________________________________________________ 
2592
2593 TObject ** AliEMCALGetter::RecParticlesRef(const char * name) const 
2594
2595 { // ---------------RecParticles -----------------------------------
2596
2597   
2598
2599   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
2600
2601
2602
2603  if ( !fRecoFolder ) {
2604
2605     cerr << "ERROR: AliEMCALGetter::RecParticlesRef -> Folder//" << fRecoFolder << " not found!" << endl; 
2606
2607     abort() ; 
2608
2609   }    
2610
2611
2612
2613   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ; 
2614
2615   if ( !emcalFolder ) {
2616
2617     cerr << "ERROR: AliEMCALGetter::RecParticlesRef -> Folder //" << fRecoFolder << "/EMCAL/RecParticles/ not found!" << endl;
2618
2619     abort() ;
2620
2621   }    
2622
2623
2624
2625   TObject * tss =  emcalFolder->FindObject(name) ;
2626
2627   if (!tss) {
2628
2629     cerr << "ERROR: AliEMCALGetter::RecParticlesRef -> object " << name << " not found! " << endl ; 
2630
2631     abort() ;  
2632
2633   }
2634
2635   return emcalFolder->GetListOfFolders()->GetObjectRef(tss) ;
2636
2637 }
2638
2639
2640
2641 //____________________________________________________________________________ 
2642
2643 const Bool_t AliEMCALGetter::PostPID(AliEMCALPID * pid) const 
2644
2645 {      // ------------AliEMCAL PID -----------------------------
2646
2647
2648
2649   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
2650
2651
2652
2653   if ( !tasks ) {
2654
2655     cerr << "ERROR: AliEMCALGetter::Post Per -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
2656
2657     return kFALSE ;
2658
2659   }        
2660
2661   
2662
2663   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2664
2665   if ( !emcal )  {
2666
2667     if (fDebug) {
2668
2669       cout <<"WARNING: AliEMCALGetter::Post Per -> //" << fTasksFolder->GetName() << "/Reconstructioner/EMCAL not found!" << endl; 
2670
2671       cout <<"INFO: AliEMCALGetter::Post Per -> Adding //" << fTasksFolder->GetName() << "/Reconstructioner/EMCAL" << endl;
2672
2673     }
2674
2675     emcal = new TTask("EMCAL", "") ; 
2676
2677     tasks->Add(emcal) ; 
2678
2679   } 
2680
2681
2682
2683   AliEMCALPID * emcalpid = dynamic_cast<AliEMCALPID*>(emcal->GetListOfTasks()->FindObject(pid->GetName())) ; 
2684
2685   if (emcalpid) { 
2686
2687     if (fDebug)
2688
2689       cout << "INFO: AliEMCALGetter::Post Per -> Task " << pid->GetName()
2690
2691            << " already exists" << endl ; 
2692
2693     emcal->GetListOfTasks()->Remove(emcalpid) ;
2694
2695   }
2696
2697   
2698
2699   emcal->Add(pid) ;      
2700
2701   return kTRUE; 
2702
2703
2704
2705
2706
2707 //____________________________________________________________________________ 
2708
2709 const Bool_t AliEMCALGetter::PostPID(const char * name) const 
2710
2711 {     
2712
2713   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
2714
2715   
2716
2717   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
2718
2719
2720
2721   if ( !tasks ) {
2722
2723     cerr << "ERROR: AliEMCALGetter::Post Per -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
2724
2725     return kFALSE ;
2726
2727   }        
2728
2729   
2730
2731   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2732
2733   if ( !emcal )  {
2734
2735     if (fDebug) {
2736
2737       cout <<"WARNING: AliEMCALGetter::Post Per -> //" << fTasksFolder->GetName() << "/Reconstructioner/EMCAL not found!" << endl; 
2738
2739       cout <<"INFO: AliEMCALGetter::Post Per -> Adding //" << fTasksFolder->GetName() << "/Reconstructioner/EMCAL" << endl;
2740
2741     }
2742
2743     emcal = new TTask("EMCAL", "") ; 
2744
2745     tasks->Add(emcal) ; 
2746
2747   } 
2748
2749
2750
2751   TList * l = emcal->GetListOfTasks() ;   
2752
2753   TIter it(l) ;
2754
2755   TString pidname(name) ;
2756
2757   pidname+=":pid" ; 
2758
2759   TTask * task ;
2760
2761   while((task = static_cast<TTask *>(it.Next()) )){
2762
2763     TString taskname(task->GetName()) ;
2764
2765     if(taskname.BeginsWith(pidname))
2766
2767       return kTRUE ;
2768
2769   }
2770
2771  
2772
2773   AliEMCALPIDv1 * emcalpid = new AliEMCALPIDv1() ;
2774
2775   pidname+="-v1" ;
2776
2777   emcalpid->SetName(pidname) ;
2778
2779   emcalpid->SetTitle(fHeaderFile) ;
2780
2781   emcal->Add(emcalpid) ;      
2782
2783   
2784
2785   return kTRUE; 
2786
2787
2788
2789
2790
2791 //____________________________________________________________________________ 
2792
2793 TObject ** AliEMCALGetter::PIDRef(const char * name) const 
2794
2795 { //------------PID ------------------------------
2796
2797
2798
2799   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
2800
2801
2802
2803   if ( !tasks ) {
2804
2805     cerr << "ERROR: AliEMCALGetter::PIDRef PerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
2806
2807     abort() ;
2808
2809   }        
2810
2811         
2812
2813   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2814
2815   if ( !emcal )  {
2816
2817     cerr <<"WARNING: AliEMCALGetter::PIDRef PerRef -> //" << fTasksFolder->GetName() << "/ReconstructionerEMCAL not found!" << endl; 
2818
2819     abort() ; 
2820
2821   }   
2822
2823   
2824
2825   TList * l = emcal->GetListOfTasks() ; 
2826
2827   TIter it(l) ;
2828
2829   TTask * task ;
2830
2831   TTask * pid = 0 ;
2832
2833   TString pidname(name) ;
2834
2835   pidname+=":pid-" ;
2836
2837   while((task = static_cast<TTask *>(it.Next()) )){
2838
2839     TString taskname(task->GetName()) ;
2840
2841     if(taskname.BeginsWith(pidname)){
2842
2843       pid = task ;
2844
2845       break ;
2846
2847     }
2848
2849   }
2850
2851   
2852
2853   if(pid) 
2854
2855     return l->GetObjectRef(pid) ;
2856
2857   else {
2858
2859     cerr << "ERROR: AliEMCALGetter::PIDRef -> task " << task->GetName() << " not found! " << endl ;  
2860
2861     abort() ;
2862
2863   }
2864
2865
2866
2867
2868
2869
2870
2871 //____________________________________________________________________________ 
2872
2873 const Bool_t AliEMCALGetter::PostQA(void) const 
2874
2875 { // ------------------ QA ---------------------------------
2876
2877
2878
2879   // the hierarchy is //Folders/Run/Conditions/QA/EMCAL/alarmsName
2880
2881
2882
2883   TFolder * emcalFolder = dynamic_cast<TFolder*>(fQAFolder->FindObject("EMCAL")) ; 
2884
2885   if ( !emcalFolder ) {
2886
2887     if (fDebug) {
2888
2889       cout << "WARNING: AliEMCALGetter::Post Q -> Folder //" << fQAFolder << "/EMCAL/ not found!" << endl;
2890
2891       cout << "INFO:    AliEMCALGetter::Post Q -> Adding Folder //" << fQAFolder << "/EMCAL/" << endl;
2892
2893     }
2894
2895     emcalFolder = fQAFolder->AddFolder("EMCAL", "QA from EMCAL") ; 
2896
2897   }      
2898
2899
2900
2901   return kTRUE;
2902
2903 }
2904
2905
2906
2907 //____________________________________________________________________________ 
2908
2909 TObject ** AliEMCALGetter::AlarmsRef(void) const 
2910
2911 {  //------- Alarms ----------------------
2912
2913
2914
2915   
2916
2917   // the hierarchy is //Folders/Run/Conditions/QA/EMCAL
2918
2919   if ( !fQAFolder ) {
2920
2921     cerr << "ERROR: AliEMCALGetter::AlarmsRef QRef -> Folder //" << fQAFolder << " not found!" << endl;
2922
2923     abort() ;
2924
2925   }    
2926
2927  
2928
2929   TFolder * emcalFolder = dynamic_cast<TFolder *>(fQAFolder->FindObject("EMCAL")) ;
2930
2931   if ( !emcalFolder ) {
2932
2933     cerr << "ERROR: AliEMCALGetter::AlarmsRef QRef -> Folder //" << fQAFolder << "/EMCAL/ not found!" << endl;
2934
2935     abort() ;
2936
2937   }
2938
2939    
2940
2941   return fQAFolder->GetListOfFolders()->GetObjectRef(emcalFolder) ;
2942
2943 }
2944
2945 */
2946
2947
2948
2949 //____________________________________________________________________________ 
2950
2951 TTree * AliEMCALGetter::TreeK(TString filename)  
2952
2953 {
2954
2955
2956
2957   // returns TreeK from file filename
2958
2959   // usefull in case of split file
2960
2961
2962
2963   if ( filename.IsNull() ) 
2964
2965     filename = fHeaderFile ; 
2966
2967
2968
2969   TFile * file = 0 ; 
2970
2971   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
2972
2973   if (file && (filename != fHeaderFile) ) {  // file already open 
2974
2975     file->Close() ; 
2976
2977     delete fAlice ; 
2978
2979   }    
2980
2981   file = TFile::Open(filename.Data(), "read") ; 
2982
2983   fAlice = static_cast<AliRun *>(file->Get("gAlice")) ; 
2984
2985   TString treeName("TreeK") ; 
2986
2987   treeName += EventNumber()  ; 
2988
2989   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
2990
2991   if (!tree && fDebug)  
2992
2993     cout << "WARNING: AliEMCALGetter::TreeK -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
2994
2995   
2996
2997   return tree ;                       
2998
2999 }
3000
3001
3002
3003 //____________________________________________________________________________ 
3004
3005 TTree * AliEMCALGetter::TreeH(TString filename)  
3006
3007 {
3008
3009
3010
3011   // returns TreeH from file filename
3012
3013   // usefull in case of split file
3014
3015
3016
3017   if ( filename.IsNull() ) 
3018
3019     filename = fHeaderFile ; 
3020
3021
3022
3023   TFile * file = 0 ; 
3024
3025   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
3026
3027   if (!file) { // file not open yet
3028
3029     file = TFile::Open(filename.Data(), "read") ; 
3030
3031   }
3032
3033   TString treeName("TreeH") ; 
3034
3035   treeName += EventNumber()  ; 
3036
3037   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
3038
3039   if (!tree && fDebug)  
3040
3041     cout << "WARNING: AliEMCALGetter::TreeH -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
3042
3043   
3044
3045   return tree ;                       
3046
3047 }
3048
3049
3050
3051 //____________________________________________________________________________ 
3052
3053 TTree * AliEMCALGetter::TreeS(TString filename)  
3054
3055 {
3056
3057
3058
3059   // returns TreeS from file filename
3060
3061   // usefull in case of split file
3062
3063
3064
3065   if ( filename.IsNull() ) 
3066
3067     filename = fHeaderFile ; 
3068
3069
3070
3071   TFile * file = 0 ; 
3072
3073   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
3074
3075   if (!file) { // file not open yet
3076
3077     file = TFile::Open(filename.Data(), "read") ; 
3078
3079   }
3080
3081   TString treeName("TreeS") ; 
3082
3083   treeName += EventNumber()  ; 
3084
3085   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
3086
3087   if (!tree && fDebug)  
3088
3089     cout << "WARNING: AliEMCALGetter::TreeS -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
3090
3091   
3092
3093   return tree ;                       
3094
3095 }
3096
3097
3098
3099 //____________________________________________________________________________ 
3100
3101 TTree * AliEMCALGetter::TreeD(TString filename)  
3102
3103 {
3104
3105
3106
3107   // returns TreeD from file filename
3108
3109   // usefull in case of split file
3110
3111
3112
3113   if ( filename.IsNull() ) 
3114
3115     filename = fHeaderFile ; 
3116
3117
3118
3119   TFile * file = 0 ; 
3120
3121   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
3122
3123   if (!file) { // file not open yet
3124
3125     file = TFile::Open(filename.Data(), "read") ; 
3126
3127   }
3128
3129   TString treeName("TreeD") ; 
3130
3131   treeName += EventNumber()  ; 
3132
3133   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
3134
3135   if (!tree && fDebug)  
3136
3137     cout << "WARNING: AliEMCALGetter::TreeD -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
3138
3139   
3140
3141   return tree ;                       
3142
3143 }
3144
3145
3146
3147 //____________________________________________________________________________ 
3148
3149 const TParticle * AliEMCALGetter::Primary(Int_t index) const
3150
3151 {
3152
3153   // Return primary particle numbered by <index>
3154
3155   
3156
3157   if(index < 0) 
3158
3159     return 0 ;
3160
3161   TParticle *  p = 0 ;
3162
3163   if (fAlice) 
3164
3165     p = fAlice->Particle(index) ; 
3166
3167   else 
3168
3169     p = gAlice->Particle(index) ; 
3170
3171   
3172
3173   return p ; 
3174
3175       
3176
3177 }
3178
3179
3180
3181 //____________________________________________________________________________ 
3182
3183 const TParticle * AliEMCALGetter::Secondary(TParticle* p, Int_t index) const
3184
3185 {
3186
3187   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
3188
3189
3190
3191   if(index <= 0) 
3192
3193     return 0 ;
3194
3195   if(index > 2)
3196
3197     return 0 ;
3198
3199
3200
3201   if(p) {
3202
3203   Int_t daughterIndex = p->GetDaughter(index-1) ; 
3204
3205   return  gAlice->Particle(daughterIndex) ; 
3206
3207   }
3208
3209   else
3210
3211     return 0 ;
3212
3213 }
3214
3215
3216
3217 //____________________________________________________________________________ 
3218
3219 Int_t AliEMCALGetter::ReadTreeD(const Int_t event)
3220
3221 {
3222
3223   // Read the digit tree gAlice->TreeD()  
3224
3225   
3226
3227   TTree * treeD ;
3228
3229   if(fToSplit){
3230
3231     TFile * file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName)); 
3232
3233     if(!file) 
3234
3235       file = TFile::Open(fDigitsFileName) ;      
3236
3237     // Get Digits Tree header from file
3238
3239     TString treeName("TreeD") ;
3240
3241     treeName += event ; 
3242
3243     treeD = dynamic_cast<TTree*>(file->Get(treeName.Data()));
3244
3245     if(!treeD){ // TreeD not found in header file
3246
3247       if (fDebug)
3248
3249         cout << "WARNING: AliEMCALGetter::ReadTreeD -> Cannot find TreeD in " << fDigitsFileName.Data() << endl;
3250
3251       return 1;
3252
3253     }
3254
3255   }
3256
3257   else
3258
3259     treeD = gAlice->TreeD() ;
3260
3261   
3262
3263   TObjArray * lob = static_cast<TObjArray*>(treeD->GetListOfBranches()) ;
3264
3265   TIter next(lob) ; 
3266
3267   TBranch * branch = 0 ; 
3268
3269   TBranch * digitsbranch = 0 ; 
3270
3271   TBranch * digitizerbranch = 0 ; 
3272
3273   Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ; 
3274
3275   
3276
3277   while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !digitizerfound) ) {
3278
3279     if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
3280
3281       digitsbranch = branch ; 
3282
3283       emcalfound = kTRUE ;
3284
3285     }
3286
3287     else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
3288
3289       digitizerbranch = branch ; 
3290
3291       digitizerfound = kTRUE ; 
3292
3293     }
3294
3295   }
3296
3297
3298
3299   if ( !emcalfound || !digitizerfound ) {
3300
3301     if (fDebug)
3302
3303       cout << "WARNING: AliEMCALGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name " 
3304
3305            << fDigitsTitle << endl ;
3306
3307     return 2; 
3308
3309   }   
3310
3311  
3312
3313   //read digits
3314
3315   if(!Digits(fDigitsTitle) ) 
3316
3317     PostDigits(fDigitsTitle);
3318
3319   digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
3320
3321   digitsbranch->GetEntry(0) ;
3322
3323   
3324
3325   
3326
3327   // read  the Digitizer
3328
3329   RemoveTask("D", fDigitsTitle) ; // I do not understand why I need that 
3330
3331   if(!Digitizer(fDigitsTitle))
3332
3333     PostDigitizer(fDigitsTitle) ;
3334
3335   digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
3336
3337   digitizerbranch->GetEntry(0) ;
3338
3339  
3340
3341   lob  ->Delete();
3342
3343   if(gAlice->TreeD()!=treeD)
3344
3345     treeD->Delete();
3346
3347   return 0 ; 
3348
3349 }
3350
3351
3352
3353 //____________________________________________________________________________ 
3354
3355 Int_t AliEMCALGetter::ReadTreeH()
3356
3357 {
3358
3359   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
3360
3361
3362
3363   TTree * treeH = gAlice->TreeH() ;
3364
3365   
3366
3367   if(!treeH) {// TreeH not found in header file
3368
3369     
3370
3371     if (fDebug) 
3372
3373       cout <<   "WARNING: AliEMCALGetter::ReadTreeH -> Cannot find TreeH in " << fHeaderFile << endl ;
3374
3375     
3376
3377     TString searchFileName("EMCAL.HITS") ; 
3378
3379     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
3380
3381       searchFileName+="." ;
3382
3383       searchFileName += fBranchTitle ;
3384
3385     }
3386
3387     searchFileName+=".root" ;
3388
3389     
3390
3391     if ( (treeH = TreeH(searchFileName)) ) { //found TreeH in the file which contains the hits
3392
3393       if (fDebug) 
3394
3395         cout << "INFO: AliEMCALGetter::ReadTreeH -> TreeH found in " << searchFileName.Data() << endl ; 
3396
3397       
3398
3399     } else {
3400
3401       cerr << "ERROR: AliEMCALGetter::ReadTreeH -> TreeH not found " << endl ; 
3402
3403       return 1;
3404
3405     }  
3406
3407   }
3408
3409   
3410
3411   TBranch * hitsbranch = static_cast<TBranch*>(gAlice->TreeH()->GetBranch("EMCAL")) ;
3412
3413   if ( !hitsbranch ) {
3414
3415     if (fDebug)
3416
3417       cout << "WARNING:  AliEMCALGetter::ReadTreeH -> Cannot find branch EMCAL" << endl ; 
3418
3419     return 2;
3420
3421   }
3422
3423   if(!Hits())
3424
3425     PostHits() ;
3426
3427  
3428
3429   if (hitsbranch->GetEntries() > 1 ) {
3430
3431     (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
3432
3433     TClonesArray * tempo =  new TClonesArray("AliEMCALHit",1000) ;
3434
3435     TClonesArray * hits = dynamic_cast<TClonesArray*>(*HitsRef()) ; 
3436
3437     hitsbranch->SetAddress(&tempo) ;
3438
3439     Int_t index = 0 ; 
3440
3441     Int_t i = 0 ;
3442
3443     for (i = 0 ; i < hitsbranch->GetEntries() ; i++) {
3444
3445       hitsbranch->GetEntry(i) ;
3446
3447       Int_t j = 0 ; 
3448
3449       for ( j = 0 ; j < tempo->GetEntries() ; j++) { 
3450
3451         const AliEMCALHit * hit = static_cast<const AliEMCALHit *>(tempo->At(j)) ; 
3452
3453         new((*hits)[index]) AliEMCALHit( *hit ) ;
3454
3455         index++ ; 
3456
3457       }
3458
3459     }
3460
3461     delete tempo ; 
3462
3463   }
3464
3465   else {
3466
3467   (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
3468
3469   hitsbranch->SetAddress(HitsRef()) ;
3470
3471   hitsbranch->GetEntry(0) ;
3472
3473   }
3474
3475   return 0 ; 
3476
3477 }
3478
3479
3480
3481 //____________________________________________________________________________ 
3482
3483 void AliEMCALGetter::Track(const Int_t itrack)
3484
3485 {
3486
3487   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
3488
3489
3490
3491   if(gAlice->TreeH()== 0){
3492
3493     cerr <<   "ERROR: AliEMCALGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
3494
3495     return ;
3496
3497   }
3498
3499   
3500
3501   TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
3502
3503   if ( !hitsbranch ) {
3504
3505     if (fDebug)
3506
3507       cout << "WARNING:  AliEMCALGetter::ReadTreeH -> Cannot find branch EMCAL" << endl ; 
3508
3509     return ;
3510
3511   }  
3512
3513   if(!Hits())
3514
3515     PostHits() ;
3516
3517
3518
3519   (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
3520
3521   hitsbranch->SetAddress(HitsRef()) ;
3522
3523   hitsbranch->GetEntry(itrack) ;
3524
3525   
3526
3527 }
3528
3529
3530
3531 //____________________________________________________________________________ 
3532
3533 void AliEMCALGetter::ReadTreeQA()
3534
3535 {
3536
3537   if (fDebug)
3538
3539     cout << "WARNING : " << ClassName() << "::ReadTreeQA -> not implemented" << endl ; 
3540
3541   // Read the digit tree gAlice->TreeQA()
3542
3543   // so far only EMCAL knows about this Tree  
3544
3545
3546
3547 //   if(EMCAL()->TreeQA()== 0){
3548
3549 //     cerr <<   "ERROR: AliEMCALGetter::ReadTreeQA: can not read TreeQA " << endl ;
3550
3551 //     return ;
3552
3553 //   }
3554
3555   
3556
3557 //   TBranch * qabranch = EMCAL()->TreeQA()->GetBranch("EMCAL") ; 
3558
3559 //   if (!qabranch) { 
3560
3561 //     if (fDebug)
3562
3563 //       cout << "WARNING: AliEMCALGetter::ReadTreeQA -> Cannot find QA Alarms for EMCAL" << endl ;
3564
3565 //     return ; 
3566
3567 //   }   
3568
3569   
3570
3571 //   if(!Alarms())
3572
3573 //     PostQA() ; 
3574
3575
3576
3577 //   qabranch->SetAddress(AlarmsRef()) ;
3578
3579
3580
3581 //   qabranch->GetEntry(0) ;
3582
3583  
3584
3585 //   PostQA("EMCAL") ; 
3586
3587 //   TFolder * alarmsF = Alarms() ; 
3588
3589 //   alarmsF->Clear() ; 
3590
3591 //   qabranch->SetAddress(&alarmsF) ;
3592
3593 //   qabranch->GetEntry(0) ;
3594
3595   
3596
3597 }
3598
3599   
3600
3601 //____________________________________________________________________________ 
3602
3603 Int_t AliEMCALGetter::ReadTreeR(const Int_t event)
3604
3605 {
3606
3607   // Read the reconstrunction tree gAlice->TreeR()
3608
3609   // A particularity has been introduced here :
3610
3611   //  if gime->Event(ievent,"R") is called branches with the current title are read, the current title
3612
3613   //   being for example give in AliPHOSPID(fileName, title)
3614
3615   //  if gime(Event(ievent, "RA") is called the title of the branches is not checked anymore, "A" stands for any
3616
3617   // This is a feature needed by PID to be able to reconstruct several times particles (each time a ther title is given)
3618
3619   // from a given set of TrackSegments (with a given name)
3620
3621   // This is why any is NOT used to read the branch of RecParticles
3622
3623   // any migh have become obsolete : to be checked
3624
3625   // See AliEMCALPIDv1    
3626
3627
3628
3629  TTree * treeR ;
3630
3631   if(fToSplit){
3632
3633     TFile * file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName)); 
3634
3635     if(!file) 
3636
3637       file = TFile::Open(fRecPointsFileName) ;      
3638
3639     // Get Digits Tree header from file
3640
3641     TString treeName("TreeR") ;
3642
3643     treeName += event ; 
3644
3645     treeR = dynamic_cast<TTree*>(file->Get(treeName.Data()));
3646
3647     if(!treeR){ // TreeR not found in header file
3648
3649       if (fDebug)
3650
3651         cout << "WARNING: AliEMCALGetter::ReadTreeD -> Cannot find TreeR in " << fRecPointsFileName.Data() << endl;
3652
3653       return 1;
3654
3655     }
3656
3657   }
3658
3659   else
3660
3661     treeR = gAlice->TreeR() ;
3662
3663   
3664
3665   // RecPoints 
3666
3667   TObjArray * lob = static_cast<TObjArray*>(treeR->GetListOfBranches()) ;
3668
3669   TIter next(lob) ; 
3670
3671   TBranch * branch = 0 ; 
3672
3673   TBranch * towerbranch = 0 ; 
3674
3675   TBranch * preshowerbranch = 0 ; 
3676
3677   TBranch * clusterizerbranch = 0 ; 
3678
3679   Bool_t emcalTowerRPfound = kFALSE, emcalPreShoRPfound = kFALSE, clusterizerfound = kFALSE ; 
3680
3681
3682
3683   
3684
3685   while ( (branch = static_cast<TBranch*>(next())) && (!emcalTowerRPfound || !emcalPreShoRPfound || !clusterizerfound) ) {
3686
3687     if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 ) {
3688
3689       if ( strcmp(branch->GetName(), "EMCALTowerRP")==0) {
3690
3691         towerbranch = branch ; 
3692
3693         emcalTowerRPfound = kTRUE ;
3694
3695       }
3696
3697       else if ( strcmp(branch->GetName(), "EMCALPreShoRP")==0) {
3698
3699         preshowerbranch = branch ; 
3700
3701         emcalPreShoRPfound = kTRUE ;
3702
3703       }
3704
3705       else if(strcmp(branch->GetName(), "AliEMCALClusterizer")==0){
3706
3707         clusterizerbranch = branch ; 
3708
3709         clusterizerfound = kTRUE ; 
3710
3711       }
3712
3713     }
3714
3715   }
3716
3717
3718
3719   if ( !emcalTowerRPfound || !emcalPreShoRPfound || !clusterizerfound) {
3720
3721     if (fDebug)
3722
3723       cout << "WARNING: AliEMCALGetter::ReadTreeR -> Cannot find RecPoints and/or Clusterizer with name " 
3724
3725            << fRecPointsTitle << endl ;
3726
3727  
3728
3729   } else { 
3730
3731     if(!TowerRecPoints(fRecPointsTitle) ) 
3732
3733       PostRecPoints(fRecPointsTitle) ;
3734
3735     
3736
3737     towerbranch->SetAddress(TowerRecPointsRef(fRecPointsTitle)) ;
3738
3739     towerbranch->GetEntry(0) ;
3740
3741
3742
3743     preshowerbranch->SetAddress(PreShowerRecPointsRef(fRecPointsTitle)) ; 
3744
3745     preshowerbranch->GetEntry(0) ;  
3746
3747     
3748
3749     if(!Clusterizer(fRecPointsTitle) )
3750
3751       PostClusterizer(fRecPointsTitle) ;
3752
3753     
3754
3755     clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
3756
3757     clusterizerbranch->GetEntry(0) ;
3758
3759   }
3760
3761   
3762
3763 //   //------------------- TrackSegments ---------------------
3764
3765 //   next.Reset() ; 
3766
3767 //   TBranch * tsbranch = 0 ; 
3768
3769 //   TBranch * tsmakerbranch = 0 ; 
3770
3771 //   Bool_t emcaltsfound = kFALSE, tsmakerfound = kFALSE ; 
3772
3773 //   while ( (branch = static_cast<TBranch*>(next())) && (!emcaltsfound || !tsmakerfound) ) {
3774
3775 //     if(strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0 )  {
3776
3777 //       if ( strcmp(branch->GetName(), "EMCALTS")==0){
3778
3779 //      tsbranch = branch ; 
3780
3781 //      emcaltsfound = kTRUE ;
3782
3783 //       }
3784
3785 //       else if(strcmp(branch->GetName(), "AliEMCALTrackSegmentMaker")==0) {
3786
3787 //      tsmakerbranch = branch ; 
3788
3789 //      tsmakerfound  = kTRUE ; 
3790
3791 //       }
3792
3793 //     }
3794
3795 //   }
3796
3797
3798
3799 //   if ( !emcaltsfound || !tsmakerfound ) {
3800
3801 //     if (fDebug)
3802
3803 //       cout << "WARNING: AliEMCALGetter::ReadTreeR -> Cannot find TrackSegments and/or TrackSegmentMaker with name "
3804
3805 //         << fTrackSegmentsTitle << endl ;
3806
3807 //   } else { 
3808
3809 //     // Read and Post the TrackSegments
3810
3811 //     if(!TrackSegments(fTrackSegmentsTitle))
3812
3813 //       PostTrackSegments(fTrackSegmentsTitle) ;
3814
3815 //     tsbranch->SetAddress(TrackSegmentsRef(fTrackSegmentsTitle)) ;
3816
3817 //     tsbranch->GetEntry(0) ;
3818
3819
3820
3821 //     // Read and Post the TrackSegment Maker
3822
3823 //     if(!TrackSegmentMaker(fTrackSegmentsTitle))
3824
3825 //       PostTrackSegmentMaker(fTrackSegmentsTitle) ;
3826
3827 //     tsmakerbranch->SetAddress(TSMakerRef(fTrackSegmentsTitle)) ;
3828
3829 //     tsmakerbranch->GetEntry(0) ;
3830
3831 //  }
3832
3833   
3834
3835   
3836
3837 //   //------------ RecParticles ----------------------------
3838
3839 //   next.Reset() ; 
3840
3841 //   TBranch * rpabranch = 0 ; 
3842
3843 //   TBranch * pidbranch = 0 ; 
3844
3845 //   Bool_t emcalrpafound = kFALSE, pidfound = kFALSE ; 
3846
3847   
3848
3849 //   while ( (branch = static_cast<TBranch*>(next())) && (!emcalrpafound || !pidfound) ) 
3850
3851 //     if(strcmp(branch->GetTitle(), fRecParticlesTitle)==0) {   
3852
3853 //       if ( strcmp(branch->GetName(), "EMCALRP")==0) {   
3854
3855 //      rpabranch = branch ; 
3856
3857 //      emcalrpafound = kTRUE ;
3858
3859 //       }
3860
3861 //       else if (strcmp(branch->GetName(), "AliEMCALPID")==0) {
3862
3863 //      pidbranch = branch ; 
3864
3865 //      pidfound  = kTRUE ; 
3866
3867 //       }
3868
3869 //     }
3870
3871   
3872
3873 //   if ( !emcalrpafound || !pidfound ) {
3874
3875 //     if (fDebug)
3876
3877 //       cout << "WARNING: AliEMCALGetter::ReadTreeR -> Cannot find RecParticles and/or PID with name " 
3878
3879 //         << fRecParticlesTitle << endl ; 
3880
3881 //   } else { 
3882
3883 //     // Read and Post the RecParticles
3884
3885 //     if(!RecParticles(fRecParticlesTitle)) 
3886
3887 //       PostRecParticles(fRecParticlesTitle) ;
3888
3889 //     rpabranch->SetAddress(RecParticlesRef(fRecParticlesTitle)) ;
3890
3891 //     rpabranch->GetEntry(0) ;
3892
3893 //     // Read and Post the PID
3894
3895 //     if(!PID(fRecParticlesTitle))
3896
3897 //       PostPID(fRecParticlesTitle) ;
3898
3899 //     pidbranch->SetAddress(PIDRef(fRecParticlesTitle)) ;
3900
3901 //     pidbranch->GetEntry(0) ;
3902
3903 //   }
3904
3905
3906
3907   if(gAlice->TreeR()!=treeR)
3908
3909     treeR->Delete();
3910
3911   return 0 ; 
3912
3913 }
3914
3915
3916
3917 //____________________________________________________________________________ 
3918
3919 Int_t AliEMCALGetter::ReadTreeS(Int_t event)
3920
3921 {
3922
3923   // Reads the SDigits treeS from all files  
3924
3925   // Files, which should be opened are listed in emcalF
3926
3927   // So, first get list of files
3928
3929   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
3930
3931   if (!emcalF) 
3932
3933     emcalF = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
3934
3935   TCollection * folderslist = emcalF->GetListOfFolders() ; 
3936
3937   
3938
3939   // Now iterate over the list of files and read TreeS into Whiteboard
3940
3941   TIter next(folderslist) ; 
3942
3943   TFolder * folder = 0 ; 
3944
3945   TFile * file; 
3946
3947   TTree * treeS = 0;
3948
3949   while ( (folder = static_cast<TFolder*>(next())) ) {
3950
3951     TString fileName("") ;
3952
3953     if(fToSplit)
3954
3955       fileName = folder->GetTitle() ;
3956
3957     else
3958
3959       fileName = folder->GetName() ; 
3960
3961     fileName.ReplaceAll("_","/") ; 
3962
3963     file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
3964
3965     if(!file) 
3966
3967       file = TFile::Open(fileName) ;      
3968
3969     // Get SDigits Tree header from file
3970
3971     TString treeName("TreeS") ;
3972
3973     treeName += event ; 
3974
3975     treeS = dynamic_cast<TTree*>(file->Get(treeName.Data()));
3976
3977
3978
3979     if(!treeS){ // TreeS not found in header file
3980
3981       if (fDebug)
3982
3983         cout << "WARNING: AliEMCALGetter::ReadTreeS -> Cannot find TreeS in " << fileName.Data() << endl;
3984
3985       return 1;
3986
3987     }
3988
3989     
3990
3991     //set address of the SDigits and SDigitizer
3992
3993     TBranch   * sdigitsBranch    = 0;
3994
3995     TBranch   * sdigitizerBranch = 0;
3996
3997     TBranch   * branch           = 0 ;  
3998
3999     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
4000
4001     TIter next(lob) ; 
4002
4003     Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
4004
4005
4006
4007     while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !sdigitizerfound) ) {
4008
4009       if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
4010
4011         emcalfound = kTRUE ;
4012
4013         sdigitsBranch = branch ; 
4014
4015       }
4016
4017       
4018
4019       else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && 
4020
4021                 (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
4022
4023         sdigitizerfound = kTRUE ; 
4024
4025         sdigitizerBranch = branch ;
4026
4027       }
4028
4029     }
4030
4031     if ( !emcalfound || !sdigitizerfound ) {
4032
4033       if (fDebug)
4034
4035         cout << "WARNING: AliEMCALDigitizer::ReadSDigits -> Digits and/or Digitizer branch with name " << GetName() 
4036
4037              << " not found" << endl ;
4038
4039       return 2; 
4040
4041     }   
4042
4043     
4044
4045     if ( !folder->FindObject(fSDigitsTitle) )  
4046
4047       PostSDigits(fSDigitsTitle,folder->GetName()) ;
4048
4049
4050
4051     ((TClonesArray*) (*SDigitsRef(fSDigitsTitle,folder->GetName())))->Clear() ;
4052
4053     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
4054
4055     sdigitsBranch->GetEntry(0) ;
4056
4057     
4058
4059     TString sdname(fSDigitsTitle) ;
4060
4061     sdname+=":" ;
4062
4063     sdname+=folder->GetName() ;
4064
4065     if(!SDigitizer(sdname) ) 
4066
4067       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
4068
4069     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
4070
4071     sdigitizerBranch->GetEntry(0) ; 
4072
4073     if(gAlice->TreeS()!=treeS)
4074
4075       treeS->Delete();
4076
4077   }    
4078
4079    return 0 ;  
4080
4081 }
4082
4083
4084
4085 //____________________________________________________________________________ 
4086
4087 void AliEMCALGetter::ReadTreeS(TTree * treeS, Int_t input)
4088
4089 {  // Read the summable digits fron treeS()  
4090
4091
4092
4093
4094
4095   TString filename("mergefile") ;
4096
4097   filename+= input ;
4098
4099
4100
4101   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ; 
4102
4103   if ( !emcalFolder ) { 
4104
4105    emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
4106
4107   } 
4108
4109   TFolder * folder=(TFolder*)emcalFolder->FindObject(filename) ;
4110
4111   //set address of the SDigits and SDigitizer
4112
4113   TBranch   * sdigitsBranch    = 0;
4114
4115   TBranch   * sdigitizerBranch = 0;
4116
4117   TBranch   * branch           = 0 ;  
4118
4119   TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
4120
4121   TIter next(lob) ; 
4122
4123   Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
4124
4125   
4126
4127   while ( (branch = (TBranch*)next()) && (!emcalfound || !sdigitizerfound) ) {
4128
4129     if ( strcmp(branch->GetName(), "EMCAL")==0) {
4130
4131       emcalfound = kTRUE ;
4132
4133       sdigitsBranch = branch ; 
4134
4135     }
4136
4137     
4138
4139     else if ( strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) {
4140
4141       sdigitizerfound = kTRUE ; 
4142
4143       sdigitizerBranch = branch ;
4144
4145     }
4146
4147   }
4148
4149   if ( !emcalfound || !sdigitizerfound ) {
4150
4151     if (fDebug)
4152
4153       cout << "WARNING: AliEMCALGetter::ReadTreeS -> Digits and/or Digitizer branch not found" << endl ;
4154
4155     return ; 
4156
4157   }   
4158
4159   
4160
4161   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
4162
4163     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
4164
4165
4166
4167   sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
4168
4169   sdigitsBranch->GetEntry(0) ;
4170
4171   
4172
4173   TString sdname(sdigitsBranch->GetTitle()) ;
4174
4175   sdname+=":" ;
4176
4177   sdname+=filename ;
4178
4179
4180
4181   if(!SDigitizer(sdigitsBranch->GetTitle()) )
4182
4183     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
4184
4185   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
4186
4187   sdigitizerBranch->GetEntry(0) ;
4188
4189   if(gAlice->TreeS()!=treeS)
4190
4191     treeS->Delete();
4192
4193 }    
4194
4195
4196
4197
4198
4199 //____________________________________________________________________________ 
4200
4201 void AliEMCALGetter::ReadPrimaries()
4202
4203 {
4204
4205   // Reads specific branches of primaries
4206
4207   
4208
4209   TClonesArray * ar = 0  ; 
4210
4211   if(! (ar = Primaries()) ) { 
4212
4213     PostPrimaries() ;
4214
4215     ar = Primaries() ; 
4216
4217   }
4218
4219   ar->Delete() ; 
4220
4221   
4222
4223   if (TreeK(fHeaderFile)) { // treeK found in header file
4224
4225     if (fDebug) 
4226
4227       cout << "INFO: AliEMCALGetter::ReadPrimaries -> TreeK found in " << fHeaderFile.Data() << endl ; 
4228
4229     fNPrimaries = gAlice->GetNtrack() ; 
4230
4231     fAlice = 0 ; 
4232
4233
4234
4235   } else { // treeK not found in header file
4236
4237
4238
4239     cerr << "ERROR: AliEMCALGetter::ReadPrimaries -> TreeK not  found " << endl ; 
4240
4241     return ;
4242
4243     
4244
4245   }
4246
4247   Int_t index = 0 ; 
4248
4249   for (index = 0 ; index < fNPrimaries; index++) { 
4250
4251     new ((*ar)[index]) TParticle(*(Primary(index)));
4252
4253   }
4254
4255 }
4256
4257
4258
4259 //____________________________________________________________________________ 
4260
4261 void AliEMCALGetter::Event(const Int_t event, const char* opt)
4262
4263 {
4264
4265   // Reads the content of all Tree's S, D and R
4266
4267   
4268
4269   if (event >= gAlice->TreeE()->GetEntries() ) {
4270
4271     cerr << "ERROR: AliEMCALGetter::Event -> " << event << " not found in TreeE!" << endl ; 
4272
4273     return ; 
4274
4275   }
4276
4277
4278
4279   Bool_t any = kFALSE ; 
4280
4281   if (strstr(opt,"A") ) // do not check the title of the branches
4282
4283     any = kTRUE; 
4284
4285
4286
4287   gAlice->GetEvent(event) ; 
4288
4289
4290
4291   if( strstr(opt,"R") )
4292
4293     ReadTreeR(event) ;
4294
4295
4296
4297   if( strstr(opt,"D") )
4298
4299     ReadTreeD(event) ;
4300
4301
4302
4303   if(strstr(opt,"S") )
4304
4305     ReadTreeS(event) ;
4306
4307
4308
4309   if(strstr(opt,"H") )
4310
4311     ReadTreeH() ;
4312
4313    
4314
4315   if( strstr(opt,"Q") )
4316
4317     ReadTreeQA() ;
4318
4319  
4320
4321   if( strstr(opt,"P") || (strcmp(opt,"")==0) )
4322
4323     ReadPrimaries() ;
4324
4325   
4326
4327 }
4328
4329
4330
4331 //____________________________________________________________________________ 
4332
4333 TObject * AliEMCALGetter::ReturnO(TString what, TString name, TString file) const 
4334
4335 {
4336
4337   // get the object named "what" from the folder
4338
4339   // folders are named like //Folders
4340
4341
4342
4343   if ( file.IsNull() ) 
4344
4345     file = fHeaderFile ; 
4346
4347
4348
4349   TFolder * folder = 0 ;
4350
4351   TObject * emcalO  = 0 ; 
4352
4353
4354
4355   if ( what.CompareTo("Primaries") == 0 ) {
4356
4357     folder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ; 
4358
4359     if (folder) 
4360
4361       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Primaries")) ;  
4362
4363     else 
4364
4365       return 0 ; 
4366
4367   }
4368
4369   else if ( what.CompareTo("Hits") == 0 ) {
4370
4371     folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
4372
4373     if (folder) 
4374
4375       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;  
4376
4377   }
4378
4379   else if ( what.CompareTo("SDigits") == 0 ) { 
4380
4381     file.ReplaceAll("/","_") ; 
4382
4383     TString path = "EMCAL/" + file  ; 
4384
4385     folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ; 
4386
4387     if (folder) { 
4388
4389       if (name.IsNull())
4390
4391         name = fSDigitsTitle ; 
4392
4393       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
4394
4395     }
4396
4397   }
4398
4399   else if ( what.CompareTo("Digits") == 0 ){
4400
4401     folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("EMCAL")) ; 
4402
4403     if (folder) { 
4404
4405       if (name.IsNull())
4406
4407         name = fDigitsTitle ; 
4408
4409       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
4410
4411     } 
4412
4413   }
4414
4415   else if ( what.CompareTo("TowerRecPoints") == 0 ) {
4416
4417     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
4418
4419     if (folder) { 
4420
4421       if (name.IsNull())
4422
4423         name = fRecPointsTitle ; 
4424
4425       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
4426
4427     } 
4428
4429   }
4430
4431   else if ( what.CompareTo("PreShowerRecPoints") == 0 ) {
4432
4433     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ; 
4434
4435     if (folder) { 
4436
4437       if (name.IsNull())
4438
4439         name = fRecPointsTitle ; 
4440
4441       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
4442
4443     }   
4444
4445   }
4446
4447   /*
4448
4449   else if ( what.CompareTo("TrackSegments") == 0 ) {
4450
4451     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ; 
4452
4453     if (folder) { 
4454
4455       if (name.IsNull())
4456
4457         name = fTrackSegmentsTitle ; 
4458
4459       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
4460
4461     }   
4462
4463   }
4464
4465   else if ( what.CompareTo("RecParticles") == 0 ) {
4466
4467     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/RecParticles")) ; 
4468
4469    if (folder) { 
4470
4471       if (name.IsNull())
4472
4473         name = fRecParticlesTitle ; 
4474
4475       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
4476
4477     }   
4478
4479  }
4480
4481   else if ( what.CompareTo("Alarms") == 0 ){ 
4482
4483     if (name.IsNull() ) 
4484
4485       emcalO = dynamic_cast<TObject *>(fQAFolder->FindObject("EMCAL")) ;  
4486
4487     else {
4488
4489       folder = dynamic_cast<TFolder *>(fQAFolder->FindObject("EMCAL")) ; 
4490
4491       if (!folder) 
4492
4493         emcalO = 0 ; 
4494
4495       else 
4496
4497         emcalO = dynamic_cast<TObject *>(folder->FindObject(name)) ;  
4498
4499     }
4500
4501   }
4502
4503 */
4504
4505   if (!emcalO) {
4506
4507     if(fDebug)
4508
4509       cout << "WARNING : AliEMCALGetter::ReturnO -> Object " << what << " not found in " << folder->GetName() << endl ; 
4510
4511     return 0 ;
4512
4513   }
4514
4515
4516
4517   return emcalO ;
4518
4519 }
4520
4521   
4522
4523 //____________________________________________________________________________ 
4524
4525 const TTask * AliEMCALGetter::ReturnT(TString what, TString name) const 
4526
4527 {
4528
4529   // get the TTask named "what" from the folder
4530
4531   // folders are named like //Folders/Tasks/what/EMCAL/name
4532
4533
4534
4535   TString search(what) ; 
4536
4537   if ( what.CompareTo("Clusterizer") == 0 ) 
4538
4539     search = "Reconstructioner" ; 
4540
4541   else if ( what.CompareTo("TrackSegmentMaker") == 0 ) 
4542
4543     search = "Reconstructioner" ; 
4544
4545   else if ( what.CompareTo("PID") == 0 ) 
4546
4547     search = "Reconstructioner" ; 
4548
4549   else if ( what.CompareTo("QATasks") == 0 ) 
4550
4551     search = "QA" ; 
4552
4553   
4554
4555   TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ; 
4556
4557
4558
4559   if (!tasks) {
4560
4561     cerr << "ERROR: AliEMCALGetter::ReturnT -> Task " << what << " not found!" << endl ;  
4562
4563     return 0 ; 
4564
4565   }
4566
4567
4568
4569   TTask * emcalT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
4570
4571   if (!emcalT) { 
4572
4573     cerr << "ERROR: AliEMCALGetter::ReturnT -> Task " << what << "/EMCAL not found!" << endl ;  
4574
4575     return 0 ; 
4576
4577   }
4578
4579   
4580
4581   TList * list = emcalT->GetListOfTasks() ; 
4582
4583  
4584
4585   if (what.CompareTo("SDigitizer") == 0) {  
4586
4587     if ( name.IsNull() )
4588
4589       name =  fSDigitsTitle ; 
4590
4591   } else  if (what.CompareTo("Digitizer") == 0){ 
4592
4593     if ( name.IsNull() )
4594
4595       name =  fDigitsTitle ;
4596
4597   } else  if (what.CompareTo("Clusterizer") == 0){ 
4598
4599     if ( name.IsNull() )
4600
4601       name =  fRecPointsTitle ;
4602
4603     name.Append(":clu") ;
4604
4605   }
4606
4607  //  else  if (what.CompareTo("TrackSegmentMaker") == 0){ 
4608
4609 //     if ( name.IsNull() )
4610
4611 //       name =  fTrackSegmentsTitle ;
4612
4613 //     name.Append(":tsm") ;
4614
4615 //   }
4616
4617 //   else  if (what.CompareTo("PID") == 0){ 
4618
4619 //     if ( name.IsNull() )
4620
4621 //       name =  fRecParticlesTitle ;
4622
4623 //     name.Append(":pid") ;
4624
4625 //   }
4626
4627 //   else  if (what.CompareTo("QATasks") == 0){ 
4628
4629 //     if ( name.IsNull() )
4630
4631 //       return emcalT ;
4632
4633 //   }
4634
4635   
4636
4637   TIter it(list) ;
4638
4639   TTask * task = 0 ; 
4640
4641   while((task = static_cast<TTask *>(it.Next()) )){
4642
4643     TString taskname(task->GetName()) ;
4644
4645     if(taskname.BeginsWith(name)){
4646
4647     return task ;}
4648
4649   }
4650
4651   
4652
4653   if(fDebug)
4654
4655     cout << "WARNING: AliEMCALGetter::ReturnT -> Task " << search << "/" << name << " not found!" << endl ; 
4656
4657   return 0 ;
4658
4659 }
4660
4661
4662
4663 //____________________________________________________________________________ 
4664
4665 void AliEMCALGetter::RemoveTask(TString opt, TString name) const 
4666
4667 {
4668
4669   // remove a task from the folder
4670
4671   // path is fTasksFolder/SDigitizer/EMCAL/name
4672
4673
4674
4675   TTask * task  = 0 ; 
4676
4677   TTask * emcal = 0 ; 
4678
4679   TList * lofTasks = 0 ; 
4680
4681
4682
4683   if (opt == "S") { // SDigitizer
4684
4685     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
4686
4687     if (!task) 
4688
4689       return ; 
4690
4691   } 
4692
4693   else if (opt == "D") { // Digitizer
4694
4695     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
4696
4697     if (!task) 
4698
4699       return ; 
4700
4701   }
4702
4703   else if (opt == "C") { // Clusterizer
4704
4705     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
4706
4707     if (!task) 
4708
4709       return ; 
4710
4711   }
4712
4713   else {
4714
4715     cerr << "WARNING: AliEMCALGetter::RemoveTask -> Unknown option " << opt.Data() << endl ; 
4716
4717     return ; 
4718
4719   }    
4720
4721   emcal =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
4722
4723   if (!emcal)
4724
4725     return ; 
4726
4727   lofTasks = emcal->GetListOfTasks() ;
4728
4729   if (!lofTasks) 
4730
4731     return ; 
4732
4733   TObject * obj = lofTasks->FindObject(name) ; 
4734
4735   if (obj) 
4736
4737     lofTasks->Remove(obj) ;
4738
4739
4740
4741 }
4742
4743   
4744
4745 //____________________________________________________________________________ 
4746
4747 void AliEMCALGetter::RemoveObjects(TString opt, TString name) const 
4748
4749 {
4750
4751   // remove SDigits from the folder
4752
4753   // path is fSDigitsFolder/fHeaderFileName/name
4754
4755
4756
4757   TFolder * emcal     = 0 ; 
4758
4759   TFolder * emcalmain = 0 ; 
4760
4761
4762
4763   if (opt == "H") { // Hits
4764
4765     emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
4766
4767     if (!emcal) 
4768
4769       return ;
4770
4771     name = "Hits" ; 
4772
4773   }
4774
4775   
4776
4777   else if ( opt == "S") { // SDigits
4778
4779     emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
4780
4781     if (!emcalmain) 
4782
4783       return ;
4784
4785     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
4786
4787     if (!emcal) 
4788
4789       return ;
4790
4791   }
4792
4793
4794
4795   else if (opt == "D") { // Digits
4796
4797     emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
4798
4799     if (!emcal) 
4800
4801       return ;
4802
4803   }
4804
4805
4806
4807   else if (opt == "RT") { // Tower RecPoints
4808
4809     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
4810
4811     if (!emcal) 
4812
4813       return ;
4814
4815   }
4816
4817
4818
4819   else if (opt == "RP") { // Preshower RecPoints
4820
4821     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
4822
4823     if (!emcal) 
4824
4825       return ;
4826
4827   }
4828
4829
4830
4831   else if (opt == "T") { // TrackSegments
4832
4833     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
4834
4835     if (!emcal) 
4836
4837       return ;
4838
4839   }
4840
4841
4842
4843   else if (opt == "P") { // RecParticles
4844
4845     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
4846
4847     if (!emcal) 
4848
4849       return ;
4850
4851   }
4852
4853   
4854
4855   else {
4856
4857     cerr << "WARNING: AliEMCALGetter::RemoveObjects -> Unknown option " << opt.Data() << endl ; 
4858
4859     return ; 
4860
4861   }
4862
4863   
4864
4865   TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject(name)) ; 
4866
4867   if (ar) { 
4868
4869     emcal->Remove(ar) ;
4870
4871     ar->Delete() ; 
4872
4873     delete ar ; 
4874
4875   }
4876
4877
4878
4879   if (opt == "S") 
4880
4881     emcalmain->Remove(emcal) ; 
4882
4883   
4884
4885 }
4886
4887
4888
4889 //____________________________________________________________________________ 
4890
4891 void AliEMCALGetter::RemoveSDigits() const 
4892
4893 {
4894
4895   TFolder * emcal= dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
4896
4897   if (!emcal) 
4898
4899     return ;
4900
4901   
4902
4903   emcal->SetOwner() ; 
4904
4905   emcal->Clear() ; 
4906
4907 }
4908
4909
4910
4911 //____________________________________________________________________________ 
4912
4913 void AliEMCALGetter::CleanWhiteBoard(void){
4914
4915
4916
4917   TFolder * emcalmain = 0 ; 
4918
4919   TFolder * emcal ;
4920
4921   TObjArray * ar ;
4922
4923   TList * lofTasks = 0 ; 
4924
4925   TTask * task = 0 ; 
4926
4927   TTask * emcalt = 0 ; 
4928
4929   
4930
4931   // Hits  
4932
4933   emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
4934
4935   if (emcal){  
4936
4937     TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject("Hits")) ; 
4938
4939     if (ar) { 
4940
4941       emcal->Remove(ar) ;
4942
4943       ar->Delete() ; 
4944
4945       delete ar ; 
4946
4947     }
4948
4949   }
4950
4951   
4952
4953   // SDigits
4954
4955   emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
4956
4957   if (emcalmain){ 
4958
4959     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
4960
4961     if (emcal) {
4962
4963       ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fSDigitsTitle)) ; 
4964
4965       if (ar) { 
4966
4967         emcal->Remove(ar) ;
4968
4969         ar->Delete() ; 
4970
4971         delete ar ; 
4972
4973       }
4974
4975     }
4976
4977     emcalmain->Remove(emcal) ; 
4978
4979   }
4980
4981
4982
4983   
4984
4985   // Digits
4986
4987   emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
4988
4989   if (emcal){ 
4990
4991     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fDigitsTitle)) ; 
4992
4993     if (ar) { 
4994
4995       emcal->Remove(ar) ;
4996
4997       ar->Delete() ; 
4998
4999       delete ar ; 
5000
5001     }
5002
5003   }
5004
5005
5006
5007
5008
5009   // TowerRecPoints
5010
5011   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
5012
5013   if (emcal){ 
5014
5015     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
5016
5017     if (ar) { 
5018
5019       emcal->Remove(ar) ;
5020
5021       ar->Delete() ; 
5022
5023       delete ar ; 
5024
5025     }
5026
5027   }
5028
5029
5030
5031   
5032
5033   // PreShowerRecPoints
5034
5035   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
5036
5037   if (emcal){ 
5038
5039     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
5040
5041     if (ar) { 
5042
5043       emcal->Remove(ar) ;
5044
5045       ar->Delete() ; 
5046
5047       delete ar ; 
5048
5049     }
5050
5051   }  
5052
5053
5054
5055   
5056
5057   // TrackSegments
5058
5059   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
5060
5061   if (emcal) { 
5062
5063     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fTrackSegmentsTitle)) ; 
5064
5065     if (ar) { 
5066
5067       emcal->Remove(ar) ;
5068
5069       ar->Delete() ; 
5070
5071       delete ar ; 
5072
5073     }
5074
5075   }
5076
5077   
5078
5079
5080
5081
5082
5083   // RecParticles
5084
5085   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
5086
5087   if (emcal){ 
5088
5089     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecParticlesTitle)) ; 
5090
5091     if (ar) { 
5092
5093       emcal->Remove(ar) ;
5094
5095       ar->Delete() ; 
5096
5097       delete ar ; 
5098
5099     }
5100
5101   }
5102
5103
5104
5105
5106
5107   //---- Now Tasks ----------- 
5108
5109
5110
5111   TObject * obj ;
5112
5113   TString sdname(fSDigitsTitle);
5114
5115   
5116
5117   // Digitizer
5118
5119   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
5120
5121   if (task){ 
5122
5123     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
5124
5125     if (emcalt){
5126
5127       lofTasks = emcalt->GetListOfTasks() ;
5128
5129       if (lofTasks){ 
5130
5131         obj = lofTasks->FindObject(sdname.Data()) ; 
5132
5133         if (obj) 
5134
5135           lofTasks->Remove(obj) ;
5136
5137       }
5138
5139     }      
5140
5141   }
5142
5143   
5144
5145
5146
5147   sdname.Append(":") ;
5148
5149   // Clusterizer, TrackSegmentMaker, PID
5150
5151   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
5152
5153   if (task){ 
5154
5155     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
5156
5157     if (emcalt){
5158
5159       lofTasks = emcalt->GetListOfTasks() ;
5160
5161       TIter next(lofTasks);
5162
5163       while((obj=next())){ 
5164
5165         TString oname(obj->GetName()) ;
5166
5167         if (oname.BeginsWith(sdname)){ 
5168
5169           lofTasks->Remove(obj) ;
5170
5171         }
5172
5173       }
5174
5175     }  
5176
5177   }
5178
5179
5180
5181
5182
5183   // SDigitizer
5184
5185   sdname.Append(fHeaderFile) ;
5186
5187   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
5188
5189   if (task) {
5190
5191     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
5192
5193     if (emcalt){
5194
5195       lofTasks = emcalt->GetListOfTasks() ;
5196
5197       if (lofTasks){ 
5198
5199         obj = lofTasks->FindObject(sdname.Data()) ; 
5200
5201         if (obj) 
5202
5203           lofTasks->Remove(obj) ;
5204
5205       }
5206
5207     }
5208
5209   }  
5210
5211
5212
5213 }
5214
5215 //____________________________________________________________________________ 
5216
5217 void AliEMCALGetter::SetTitle(const char * branchTitle ) 
5218
5219 {
5220
5221   fBranchTitle        = branchTitle ;
5222
5223   fSDigitsTitle       = branchTitle ; 
5224
5225   fDigitsTitle        = branchTitle ; 
5226
5227   fRecPointsTitle     = branchTitle ; 
5228
5229   fRecParticlesTitle  = branchTitle ; 
5230
5231   fTrackSegmentsTitle = branchTitle ; 
5232
5233   if(fToSplit){
5234
5235     //First - extract full path if necessary
5236
5237     TString sFileName(fHeaderFile) ;
5238
5239     Ssiz_t islash = sFileName.Last('/') ;
5240
5241     if(islash<sFileName.Length())
5242
5243       sFileName.Remove(islash+1,sFileName.Length()) ;
5244
5245     else
5246
5247       sFileName="" ;
5248
5249     //Now construct file names
5250
5251     fSDigitsFileName       = sFileName ;
5252
5253     fDigitsFileName        = sFileName ; 
5254
5255     fRecPointsFileName     = sFileName ; 
5256
5257     fRecParticlesFileName  = sFileName ; 
5258
5259     fTrackSegmentsFileName = sFileName ; 
5260
5261     fSDigitsFileName      += "EMCAL.SDigits." ;
5262
5263     fDigitsFileName       += "EMCAL.Digits." ; 
5264
5265     fRecPointsFileName    += "EMCAL.RecData." ; 
5266
5267     fTrackSegmentsFileName+= "EMCAL.RecData." ; 
5268
5269     fRecParticlesFileName += "EMCAL.RecData." ; 
5270
5271     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
5272
5273       fSDigitsFileName      += fBranchTitle ;
5274
5275       fSDigitsFileName      += "." ;
5276
5277       fDigitsFileName       += fBranchTitle ; 
5278
5279       fDigitsFileName       += "." ; 
5280
5281       fRecPointsFileName    += fBranchTitle ; 
5282
5283       fRecPointsFileName    += "." ; 
5284
5285       fRecParticlesFileName += fBranchTitle ; 
5286
5287       fRecParticlesFileName += "." ; 
5288
5289       fTrackSegmentsFileName+= fBranchTitle ; 
5290
5291       fTrackSegmentsFileName+= "." ; 
5292
5293     }
5294
5295     fSDigitsFileName      += "root" ;
5296
5297     fDigitsFileName       += "root" ; 
5298
5299     fRecPointsFileName    += "root" ; 
5300
5301     fRecParticlesFileName += "root" ; 
5302
5303     fTrackSegmentsFileName+= "root" ; 
5304
5305   }else{
5306
5307     fSDigitsFileName       = "" ; 
5308
5309     fDigitsFileName        = "" ; 
5310
5311     fRecPointsFileName     = "" ; 
5312
5313     fRecParticlesFileName  = "" ; 
5314
5315     fTrackSegmentsFileName = "" ; 
5316
5317   }
5318
5319   TFolder * emcalFolder ; 
5320
5321   emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
5322
5323   if ( !emcalFolder ) 
5324
5325     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
5326
5327
5328
5329   emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
5330
5331   if ( !emcalFolder ) 
5332
5333     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
5334
5335   
5336
5337   //Make folder for SDigits
5338
5339   TString subdir(fHeaderFile) ;
5340
5341   subdir.ReplaceAll("/","_") ;
5342
5343   emcalFolder->AddFolder(subdir, fSDigitsFileName.Data());
5344
5345
5346
5347
5348
5349   emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
5350
5351   if ( !emcalFolder ) 
5352
5353     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
5354
5355
5356
5357   emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
5358
5359   if ( !emcalFolder )
5360
5361     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
5362
5363   
5364
5365
5366
5367 }
5368
5369 //____________________________________________________________________________ 
5370
5371 void AliEMCALGetter::CloseSplitFiles(void){
5372
5373   TFile * file ;
5374
5375   file = static_cast<TFile*>(gROOT->GetFile(fSDigitsFileName.Data() ) ) ;
5376
5377   if(file)
5378
5379     file->Close() ;
5380
5381   file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName.Data() ) ) ;
5382
5383   if(file)
5384
5385     file->Close() ;
5386
5387   file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName.Data() ) ) ;
5388
5389   if(file)
5390
5391     file->Close() ;
5392
5393   file = static_cast<TFile*>(gROOT->GetFile(fTrackSegmentsFileName.Data() ) ) ;
5394
5395   if(file)
5396
5397     file->Close() ;
5398
5399   file = static_cast<TFile*>(gROOT->GetFile(fRecParticlesFileName.Data() ) ) ;
5400
5401   if(file)
5402
5403     file->Close() ;
5404
5405
5406
5407 }
5408