]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSIndexToObject.cxx
new design: singleton to be used instead od AliPHOS object during analysis; contains...
[u/mrichter/AliRoot.git] / PHOS / AliPHOSIndexToObject.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id:  */
17
18 //_________________________________________________________________________
19 //  A singleton 
20 //                  
21 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
22 //////////////////////////////////////////////////////////////////////////////
23
24
25 // --- ROOT system ---
26
27 #include "TFile.h"
28 #include "TTree.h"
29 #include "TROOT.h"
30 #include "TObjString.h"
31
32 // --- Standard library ---
33 #include <iostream.h>
34
35 // --- AliRoot header files ---
36
37 #include "AliRun.h"
38 #include "AliPHOSIndexToObject.h"
39 #include "AliPHOSDigitizer.h"
40 #include "AliPHOSClusterizer.h"
41 #include "AliPHOSTrackSegmentMaker.h"
42 #include "AliPHOSPID.h" 
43
44 ClassImp(AliPHOSIndexToObject)
45   
46   AliPHOSIndexToObject * AliPHOSIndexToObject::fgObjGetter = 0 ; 
47
48 //____________________________________________________________________________ 
49 AliPHOSIndexToObject::AliPHOSIndexToObject(char* headerFile,char* branch,char* branchTitle )
50 {
51   //Initiate all lists
52   fEvent = 0 ;
53
54   fDigits = new TClonesArray("AliPHOSDigit",100) ;
55   fEmcRecPoints = new TObjArray(100) ;
56   fCpvRecPoints = new TObjArray(100) ;
57   fTS = new TClonesArray("AliPHOSTrackSegment",100) ;
58   fRecParticles = new TClonesArray("AliPHOSRecParticle",100) ;
59   fPrimaries = new TObjArray(1) ;
60
61   fDigitizer = 0 ;
62   fClusterizer = 0 ;
63   fTSMaker = 0 ;
64   fPID = 0 ;
65
66   //open headers file
67   fHeaderFile = headerFile ;
68   TFile * file = (TFile*) gROOT->GetFile(fHeaderFile.Data() ) ;
69
70   if(file == 0){
71     file = new TFile(fHeaderFile.Data(),"update") ;
72     gAlice = (AliRun *) file->Get("gAlice") ;
73   }
74
75   fMaxEvent = (Int_t) gAlice->TreeE()->GetEntries() ;
76
77   char * dummyfile = 0 ;
78
79   gAlice->GetEvent(fEvent) ;
80
81   Bool_t isRead = kFALSE;
82   //now read branches 
83   if((strcmp(branch,"PHOSRP")==0) || (strcmp(branch,"PHOSPID")==0)){
84     ReadRecParticles(branchTitle) ;  //first read RecPartcles and branche TS from which they are made
85     ReadTS(dummyfile);              //read TS from which made RecParticles above
86     ReadRecPoints(dummyfile) ;     //RecPoints from which TS above made
87     ReadDigits(dummyfile) ;         //digits. from whic RecPoints made
88     isRead= kTRUE ;
89   }
90   
91   if((strcmp(branch,"PHOSTS")==0) || (strcmp(branch,"PHOSTSMaker")==0)){
92     ReadTS(branchTitle);            //read TS and branch of RecPoints from which they are made
93     ReadRecPoints(dummyfile) ;     //recpoints abd branch of digits
94     ReadDigits(dummyfile) ;       //digits and branch of Primaries
95     ReadRecParticles(dummyfile) ;  //posiible completion of TS
96     isRead= kTRUE ;
97   }
98
99   if((strcmp(branch,"PHOSEmcRP")==0)|| (strcmp(branch,"PHOSCpvRP")==0) || 
100      (strcmp(branch,"PHOSClusterizer")==0)){
101     ReadRecPoints(branchTitle) ;    //RecPoints and Digits branch filename
102     ReadDigits(dummyfile) ;        //digits and primary file name
103     ReadTS(dummyfile);             //possible completion of RecPoints
104     ReadRecParticles(dummyfile) ;  //possible completion of TS
105     isRead= kTRUE ;
106   }
107
108   if((strcmp(branch,"PHOS")==0) || (strcmp(branch,"PHOSDigitizer")==0)){
109     ReadDigits(branchTitle) ;
110     ReadRecPoints(dummyfile) ;
111     ReadTS(dummyfile);
112     ReadRecParticles(dummyfile) ;
113     isRead= kTRUE ;
114   }
115
116   if(!isRead){
117     cout << "AliPHOSIndexToObject: wrong branch name specified: " << branch << endl ;
118     cout << "   avalilable names are `PHOSRP', `PHOSPID'"<<endl ;
119     cout << "                        `PHOSTS', `PHOSTSMaker'"<<endl ;
120     cout << "                        `PHOSEmcRP', `PHOSCpvRP', `PHOSClusterizer'"<< endl ;
121     cout << "                        `PHOS' and `PHOSDigitizer'"<< endl ;
122   }
123   ReadPrimaries() ; // should be called when digits are already read 
124
125 }
126 //____________________________________________________________________________ 
127 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance()
128 {
129   // Returns the pointer of the unique instance already defined
130   
131   AliPHOSIndexToObject * rv = 0 ;
132   if ( fgObjGetter )
133     rv = fgObjGetter ;
134   else
135     cout << "AliPHOSIndexToObject::GetInstance ERROR: not yet initialized" << endl ;
136
137   return rv ;
138 }
139
140 //____________________________________________________________________________ 
141 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance(char* headerFile,char* branch,char* branchTitle)
142 {
143   // Creates and returns the pointer of the unique instance
144   // Must be called only when the environment has changed 
145
146   if ( fgObjGetter )      // delete it if already exists
147     delete fgObjGetter ; 
148
149   fgObjGetter = new AliPHOSIndexToObject(headerFile,branch,branchTitle) ; 
150   
151   return fgObjGetter ; 
152   
153 }
154
155 //____________________________________________________________________________ 
156 TParticle * AliPHOSIndexToObject::GimePrimary(Int_t index)
157 {
158   
159   
160   Int_t primaryList = (Int_t) (TMath::Ceil(index/10000000.) ) - 1 ;
161   Int_t primaryIndex = index - primaryList*10000000 ; 
162   
163   if ( primaryList > 0  ) {
164     cout << " IndexToObject does not support currently Mixing of primary " << endl ;
165     cout << "   can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
166     return 0;
167   }
168   
169   return gAlice->Particle(primaryIndex) ;
170   
171 }
172
173 //____________________________________________________________________________ 
174 Bool_t AliPHOSIndexToObject::ReadRecParticles(char * branchTitle){
175
176   if(gAlice->TreeR()==0)
177     return kFALSE ;
178   
179   if(fPID) // already read
180     branchTitle = fPID->GetRecParticlesBranch() ;
181
182
183   if(branchTitle){ // we should read a specific branch
184     TBranch * pidBranch = 0;
185     TBranch * rpBranch = 0;
186     
187     TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
188     Int_t ibranch;
189     Bool_t pidNotFound = kTRUE ;
190     Bool_t rpNotFound = kTRUE ;
191     
192     for(ibranch = 0;(ibranch <branches->GetEntries())&&(pidNotFound||rpNotFound);ibranch++){
193
194       if(pidNotFound){
195         pidBranch=(TBranch *) branches->At(ibranch) ;
196         if( (strcmp(branchTitle,pidBranch->GetTitle())==0 ) &&
197             (strcmp(pidBranch->GetName(),"AliPHOSPID") == 0) )
198           pidNotFound = kFALSE ;
199       }
200       if(rpNotFound){
201         rpBranch=(TBranch *) branches->At(ibranch) ;
202         if( (strcmp(branchTitle,rpBranch->GetTitle())==0 ) &&
203             (strcmp(rpBranch->GetName(),"PHOSRP") == 0) )
204           rpNotFound = kFALSE ;
205       }
206     }
207     
208     if(pidNotFound ||rpNotFound ){
209       cout << "AliPHOSIndexToObject error" << endl ;
210       cout << "     Can't find Branch with PID and RecParticles " ;
211       return kFALSE ;
212     }
213     
214     pidBranch->SetAddress(&fPID) ;
215     rpBranch->SetAddress(&fRecParticles) ;
216     gAlice->TreeR()->GetEvent(0) ;    
217   }
218   else{ //we Should read any branch and print warning if there are other possibilities
219     if(fTSMaker){//if TrackSegments already read, we should read RecParticles Made from it
220       TBranch * pidBranch = 0;
221       TBranch * rpBranch = 0;
222     
223       TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
224
225       Int_t branchRead = 0;
226       Bool_t allNotFound = kTRUE ;
227       while(allNotFound){
228         Bool_t pidNotFound = kTRUE ;
229         Bool_t rpNotFound = kTRUE ;
230         Int_t ibranch ;
231         for(ibranch = branchRead;(ibranch <branches->GetEntries() )&& pidNotFound;ibranch++){
232           pidBranch=(TBranch *) branches->At(ibranch) ;
233           if(strcmp(pidBranch->GetName(),"AliPHOSPID") == 0) 
234             pidNotFound = kFALSE ;
235         }
236         branchRead = ibranch +1 ; 
237         for(ibranch = 0 ;(ibranch <branches->GetEntries() )&& rpNotFound;ibranch++){
238           rpBranch=(TBranch *) branches->At(ibranch) ;
239           if( (strcmp(pidBranch->GetTitle(),rpBranch->GetTitle())==0 ) &&
240               (strcmp(rpBranch->GetName(),"PHOSRP") == 0) )
241             rpNotFound = kFALSE ;
242         }
243         
244         if(pidNotFound ||rpNotFound ){
245           cout << "AliPHOSIndexToObject error" << endl ;
246           cout << "     Can't find Branch with PID and RecParticles " ;
247           return kFALSE ;
248         }
249     
250         pidBranch->SetAddress(&fPID) ;
251         rpBranch->SetAddress(&fRecParticles) ;
252         gAlice->TreeR()->GetEvent(0) ;    
253         
254         if(strcmp(fTSMaker->GetTrackSegmentsBranch(),fPID->GetTrackSegmentsBranch()) == 0)
255           allNotFound = kFALSE ;
256       }
257     }
258     else{//we read any (first) recparticles
259       TBranch * pidBranch = 0;
260       TBranch * rpBranch = 0;
261       TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
262
263       Bool_t pidNotFound = kTRUE ;
264       Bool_t rpNotFound = kTRUE ;
265       Int_t ibranch ;
266       for(ibranch = 0;(ibranch <branches->GetEntries() )&& pidNotFound;ibranch++){
267         pidBranch=(TBranch *) branches->At(ibranch) ;
268         if(strcmp(pidBranch->GetName(),"AliPHOSPID") == 0) 
269           pidNotFound = kFALSE ;
270       }
271       for(ibranch = 0 ;(ibranch <branches->GetEntries() )&& rpNotFound;ibranch++){
272         rpBranch=(TBranch *) branches->At(ibranch) ;
273         if( (strcmp(pidBranch->GetTitle(),rpBranch->GetTitle())==0 ) &&
274             (strcmp(rpBranch->GetName(),"PHOSRP") == 0) )
275           rpNotFound = kFALSE ;
276       }
277       
278       if(pidNotFound ||rpNotFound ){
279         cout << "AliPHOSIndexToObject worning: " << endl ;
280         cout << "     Can't find Branch with PID and RecParticles " << endl;
281         return kFALSE ;
282       }
283       
284       pidBranch->SetAddress(&fPID) ;
285       rpBranch->SetAddress(&fRecParticles) ;
286       gAlice->TreeR()->GetEvent(0) ;    
287       
288     }
289   }
290   return kTRUE ;
291 }
292 //____________________________________________________________________________ 
293 Bool_t AliPHOSIndexToObject::ReadTS(char * branchTitle){
294
295   if(gAlice->TreeR()==0)
296     return kFALSE ;
297
298   if(fPID)//if RecParticles already read, we should read TS from which they are made
299     branchTitle= fPID->GetTrackSegmentsBranch() ;
300   
301   if(branchTitle){   // we should read a specific branch
302     
303     TBranch * tsMakerBranch = 0;
304     TBranch * tsBranch = 0;
305     
306     TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
307     Int_t ibranch;
308     Bool_t tsMakerNotFound = kTRUE ;
309     Bool_t tsNotFound = kTRUE ;
310     
311     for(ibranch = 0;(ibranch <branches->GetEntries())&&(tsMakerNotFound||tsNotFound);ibranch++){
312       if(tsMakerNotFound){
313         tsMakerBranch=(TBranch *) branches->At(ibranch) ;
314         if( strcmp(branchTitle,tsMakerBranch->GetTitle())==0 )
315           if( strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0) 
316             tsMakerNotFound = kFALSE ;
317       }
318       if(tsNotFound){
319         tsBranch=(TBranch *) branches->At(ibranch) ;
320         if( strcmp(branchTitle,tsBranch->GetTitle())==0 )
321           if( strcmp(tsBranch->GetName(),"PHOSTS") == 0) 
322             tsNotFound = kFALSE ;
323       }
324     }
325     
326     if(tsMakerNotFound ||tsNotFound ){
327       cout << "AliPHOSIndexToObject error" << endl ;
328       cout << "       Can't find Branch with TrackSegmentMaker and TrackSegments " ;
329       cout << "       Do nothing" <<endl  ;
330       return kFALSE ;
331     }
332     
333     tsMakerBranch->SetAddress(&fTSMaker) ;
334     tsBranch->SetAddress(&fTS) ;
335     gAlice->TreeR()->GetEvent(0) ;
336     
337   }
338   else{ 
339     if(fClusterizer){//Clusterizer aready read, 
340                      //we should read TrackSegments made from these RecPoints
341
342       Int_t branchRead = 0 ; 
343       TBranch * tsMakerBranch = 0;
344       TBranch * tsBranch = 0;
345     
346       TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
347       Int_t ibranch;
348       Bool_t allNotFound = kTRUE ;
349       while(allNotFound){
350         Bool_t tsMakerNotFound = kTRUE ;
351         Bool_t tsNotFound = kTRUE ;
352         
353         for(ibranch = branchRead;(ibranch <branches->GetEntries())&&(tsMakerNotFound);ibranch++){
354           tsMakerBranch=(TBranch *) branches->At(ibranch) ;
355           if( strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0) 
356             tsMakerNotFound = kFALSE ;
357         }
358         branchRead = ibranch++ ;
359         for(ibranch = 0 ;(ibranch <branches->GetEntries())&&(tsNotFound);ibranch++){
360           tsBranch=(TBranch *) branches->At(ibranch) ;
361           if( (strcmp(tsBranch->GetName(),"PHOSTS") == 0) && 
362               (strcmp(tsBranch->GetName(),tsMakerBranch->GetTitle())==0))
363             tsNotFound = kFALSE ;
364         }
365         
366         branchRead = ibranch++ ;
367         
368         if(tsMakerNotFound ||tsNotFound ){
369           cout << "AliPHOSIndexToObject error" << endl ;
370           cout << "       Can't find Branch with TrackSegmentMaker and TrackSegments " ;
371           cout << "       Do nothing" <<endl  ;
372           return kFALSE ;
373         }
374         
375         tsMakerBranch->SetAddress(&fTSMaker) ;
376         tsBranch->SetAddress(&fTS) ;
377         gAlice->TreeR()->GetEvent(0) ;
378         
379         if(strcmp(fTSMaker->GetRecPointsBranch(),fClusterizer->GetRecPointsBranch()) == 0)
380           allNotFound = kFALSE ;
381       }
382       
383     }
384     else{//Neither Title,neither fPID, neither fClusterizer: we read any (first) occurence
385       TBranch * tsMakerBranch = 0;
386       TBranch * tsBranch = 0;    
387       TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
388       Bool_t tsMakerNotFound = kTRUE ;
389       Bool_t tsNotFound = kTRUE ;
390       Int_t ibranch ;
391       for(ibranch =  0;(ibranch <branches->GetEntries())&& tsMakerNotFound;ibranch++){
392         tsMakerBranch=(TBranch *) branches->At(ibranch) ;
393         if( strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0) 
394           tsMakerNotFound = kFALSE ;
395       }
396       for(ibranch = 0 ;(ibranch <branches->GetEntries())&&(tsNotFound);ibranch++){
397         tsBranch=(TBranch *) branches->At(ibranch) ;
398         if( (strcmp(tsBranch->GetName(),"PHOSTS") == 0) && 
399             (strcmp(tsBranch->GetName(),tsMakerBranch->GetTitle())==0))
400           tsNotFound = kFALSE ;
401       } 
402       if(tsMakerNotFound ||tsNotFound ){
403         cout << "AliPHOSIndexToObject error" << endl ;
404         cout << "       Can't find Branch with TrackSegmentMaker and TrackSegments " ;
405         cout << "       Do nothing" <<endl  ;
406         return kFALSE ;
407       }
408       
409       tsMakerBranch->SetAddress(&fTSMaker) ;
410       tsBranch->SetAddress(&fTS) ;
411       gAlice->TreeR()->GetEvent(0) ;     
412     }
413   }
414
415   return kTRUE ;  
416 }
417 //____________________________________________________________________________ 
418 Bool_t AliPHOSIndexToObject::ReadRecPoints(char * branchTitle){
419   
420   if(gAlice->TreeR() == 0)
421     return kFALSE ;
422
423   if(fTSMaker) //if TrackSegment maker already read, read corresponding branches
424     branchTitle = fTSMaker->GetRecPointsBranch() ;
425
426   if(branchTitle){ // we should read a specific branch
427     TBranch * emcBranch = 0;
428     TBranch * cpvBranch = 0;
429     TBranch * clusterizerBranch = 0;
430     
431     TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
432     Int_t ibranch;
433     Bool_t emcNotFound = kTRUE ;
434     Bool_t cpvNotFound = kTRUE ;  
435     Bool_t clusterizerNotFound = kTRUE ;
436     
437     for(ibranch = 0;((ibranch < branches->GetEntries())&&(emcNotFound ||cpvNotFound || clusterizerNotFound)) ;ibranch++){
438       if(emcNotFound){
439         emcBranch=(TBranch *) branches->At(ibranch) ;
440         if( (strcmp(emcBranch->GetTitle(),branchTitle) == 0) && 
441             (strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0) )
442           emcNotFound = kFALSE ;
443       }
444       if(cpvNotFound){
445         cpvBranch=(TBranch *) branches->At(ibranch) ;
446         if( (strcmp(cpvBranch->GetTitle(),branchTitle) == 0) &&
447             (strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0) )
448           cpvNotFound = kFALSE ;
449       }
450       if(clusterizerNotFound){
451         clusterizerBranch = (TBranch *) branches->At(ibranch) ;
452         if( (strcmp(clusterizerBranch->GetTitle(),branchTitle) == 0) &&
453             (strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0) )
454           clusterizerNotFound = kFALSE ;
455       }
456       
457     }
458     
459     if(clusterizerNotFound || emcNotFound || cpvNotFound){
460       cout << "AliPHOSIndexToObject error" << endl ;
461       cout << "       Can't find Branch with RecPoints or Clusterizer " << endl ;
462       return kFALSE ;
463     }
464     
465     emcBranch->SetAddress(&fEmcRecPoints) ;
466     cpvBranch->SetAddress(&fCpvRecPoints) ;
467     clusterizerBranch->SetAddress(&fClusterizer) ;
468     gAlice->TreeR()->GetEvent(0) ;
469   }
470   else{ //no specific branch
471     if(fDigitizer){//Digitizer aready read, 
472                    //we should read RecPoints made from these Digits
473       TBranch * emcBranch = 0;
474       TBranch * cpvBranch = 0;
475       TBranch * clusterizerBranch = 0;
476       
477       TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
478       Int_t branchRead = 0;
479       Bool_t allNotFound = kTRUE ;
480       while(allNotFound){
481         Bool_t emcNotFound = kTRUE ;
482         Bool_t cpvNotFound = kTRUE ;  
483         Bool_t clusterizerNotFound = kTRUE ;
484         Int_t ibranch ;
485         for(ibranch = branchRead;ibranch < branches->GetEntries();ibranch++){
486           emcBranch=(TBranch *) branches->At(ibranch) ;
487           if( strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0)
488             emcNotFound = kFALSE ;
489         }
490         branchRead = ibranch + 1 ;
491         for(ibranch =  0 ;ibranch < branches->GetEntries();ibranch++){
492           cpvBranch=(TBranch *) branches->At(ibranch) ;
493           if( (strcmp(cpvBranch->GetTitle(),emcBranch->GetTitle()) == 0) &&
494               (strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0) )
495             cpvNotFound = kFALSE ;
496         }
497         for(ibranch = 0 ;ibranch < branches->GetEntries();ibranch++){
498           clusterizerBranch = (TBranch *) branches->At(ibranch) ;
499           if( (strcmp(clusterizerBranch->GetTitle(),emcBranch->GetTitle()) == 0) &&
500               (strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0) )
501             clusterizerNotFound = kFALSE ;
502         }
503         
504         if(clusterizerNotFound || emcNotFound || cpvNotFound){
505           cout << "AliPHOSIndexToObject error" << endl ;
506           cout << "       Can't find Branch with RecPoints or Clusterizer " << endl ;
507           return kFALSE ;
508         }
509     
510         emcBranch->SetAddress(&fEmcRecPoints) ;
511         cpvBranch->SetAddress(&fCpvRecPoints) ;
512         clusterizerBranch->SetAddress(&fClusterizer) ;
513         gAlice->TreeR()->GetEvent(0) ;
514         
515         if(strcmp(fClusterizer->GetDigitsBranch(),fDigitizer->GetDigitsBranch())== 0)
516           allNotFound = kFALSE ;
517       }
518     }
519     else{//Neither Title, Neither TSMaker, Neither Digits: we read any (first) RecPoints
520       TBranch * emcBranch = 0;
521       TBranch * cpvBranch = 0;
522       TBranch * clusterizerBranch = 0;
523       TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
524       Bool_t emcNotFound = kTRUE ;
525       Bool_t cpvNotFound = kTRUE ;  
526       Bool_t clusterizerNotFound = kTRUE ;
527       Int_t ibranch ;
528       for(ibranch = 0 ;ibranch < branches->GetEntries();ibranch++){
529         emcBranch=(TBranch *) branches->At(ibranch) ;
530         if( strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0)
531           emcNotFound = kFALSE ;
532       }
533       for(ibranch = 0 ;ibranch < branches->GetEntries();ibranch++){
534         cpvBranch=(TBranch *) branches->At(ibranch) ;
535         if( (strcmp(cpvBranch->GetTitle(),emcBranch->GetTitle()) == 0) &&
536             (strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0) )
537           cpvNotFound = kFALSE ;
538       }
539       for(ibranch = 0;ibranch < branches->GetEntries();ibranch++){
540         clusterizerBranch = (TBranch *) branches->At(ibranch) ;
541         if( (strcmp(clusterizerBranch->GetTitle(),emcBranch->GetTitle()) == 0) &&
542             (strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0) )
543           clusterizerNotFound = kFALSE ;
544       }
545       
546       if(clusterizerNotFound || emcNotFound || cpvNotFound){
547         cout << "AliPHOSIndexToObject error" << endl ;
548         cout << "       Can't find Branch with RecPoints or Clusterizer " << endl ;
549         return kFALSE ;
550       }
551       
552       emcBranch->SetAddress(&fEmcRecPoints) ;
553       cpvBranch->SetAddress(&fCpvRecPoints) ;
554       clusterizerBranch->SetAddress(&fClusterizer) ;
555       gAlice->TreeR()->GetEvent(0) ;
556     }
557   }
558
559   return kTRUE ;
560 }
561 //____________________________________________________________________________ 
562 Bool_t AliPHOSIndexToObject::ReadDigits(char * branchTitle){
563
564   if(gAlice->TreeD()== 0)
565     return kFALSE ;
566   
567   //if RecPoints are already read, we should read Digits from which they are made
568   if(fClusterizer)
569     branchTitle = fClusterizer->GetDigitsBranch() ;
570   
571   if(branchTitle){ // we should read a specific branch
572     TBranch * digitsBranch = 0;
573     TBranch * digitizerBranch = 0;
574
575     TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
576     Int_t ibranch;
577     Bool_t phosNotFound = kTRUE ;
578     Bool_t digitizerNotFound = kTRUE ;
579     
580     for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
581       
582       if(phosNotFound){
583         digitsBranch=(TBranch *) branches->At(ibranch) ;
584         if( (strcmp(digitsBranch->GetTitle(),branchTitle)==0 ) &&
585             (strcmp(digitsBranch->GetName(),"PHOS") == 0) )
586           phosNotFound = kFALSE ;
587       }
588       if(digitizerNotFound){
589         digitizerBranch = (TBranch *) branches->At(ibranch) ;
590         if( (strcmp(digitizerBranch->GetTitle(),branchTitle) == 0) && 
591             (strcmp(digitizerBranch->GetName(),"AliPHOSDigitizer") == 0) )
592           digitizerNotFound = kFALSE ;
593       } 
594     }
595     
596     if(digitizerNotFound || phosNotFound){
597       cout << "AliPHOSIndexToObject error: " << endl ;
598       cout << "       Can't find Branch with Digits or Digitizer "<< endl ; ;
599       return kFALSE ;
600     }
601     
602     digitsBranch->SetAddress(&fDigits) ;
603     digitizerBranch->SetAddress(&fDigitizer) ;
604   
605     gAlice->TreeD()->GetEvent(0) ;
606   }
607   else{ //we should read any branch and print warning if there are other possibilities
608     TBranch * digitsBranch = 0;
609     TBranch * digitizerBranch = 0;
610     
611     TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
612     Int_t ibranch;
613     Bool_t phosNotFound = kTRUE ;
614     Bool_t digitizerNotFound = kTRUE ;
615     
616     for(ibranch = 0;(ibranch <branches->GetEntries())&& phosNotFound ;ibranch++){
617       digitsBranch=(TBranch *) branches->At(ibranch) ;
618       if(strcmp(digitsBranch->GetName(),"PHOS") == 0) 
619         phosNotFound = kFALSE ;
620     }
621     for(ibranch = 0;(ibranch <branches->GetEntries())&& digitizerNotFound ;ibranch++){
622       digitizerBranch = (TBranch *) branches->At(ibranch) ;
623       if( (strcmp(digitizerBranch->GetTitle(),digitsBranch->GetTitle()) == 0) && 
624           (strcmp(digitizerBranch->GetName(),"AliPHOSDigitizer") == 0) )
625         digitizerNotFound = kFALSE ;
626     } 
627     
628     if(digitizerNotFound || phosNotFound){
629       cout << "AliPHOSIndexToObject error: " << endl ;
630       cout << "       Can't find Branch with Digits or Digitizer "<< endl ; ;
631       return kFALSE ;
632     }
633     
634     digitsBranch->SetAddress(&fDigits) ;
635     digitizerBranch->SetAddress(&fDigitizer) ;
636     
637     gAlice->TreeD()->GetEvent(0) ;
638     
639   }
640
641   return kTRUE ;
642 }
643 //____________________________________________________________________________ 
644 Bool_t AliPHOSIndexToObject::ReadPrimaries(){
645   //read specific branches of primaries
646
647 //   //Check, is it necessary to open new files
648 //   TArrayI* events = fDigitizer->GetCurrentEvents() ; 
649 //   TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
650 //   Int_t input ;
651 //   for(input = 0; input < filenames->GetEntriesFast(); input++){
652
653 //     TObjString * filename = (TObjString *) filenames->At(input) ;
654
655 //     //Test, if this file already open
656 //     TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
657 //     if(file == 0)
658 //       file = new TFile( filename->GetString()) ;
659 //     file->cd() ;
660     
661 //     // Get Kine Tree from file
662 // //     char treeName[20];
663 // //     sprintf(treeName,"TreeK%d",events->At(input));
664 // //     TTree * treeK = (TTree*)gDirectory->Get(treeName);
665 // //     if (treeK) 
666 // //       treeK->SetBranchAddress("Particles", &fParticleBuffer);
667 // //     else    
668 // //       cout << "AliPHOSIndexToObject: cannot find Kine Tree for event:" << events->At(input) << endl;
669
670 // //     // Create the particle stack
671 // //     if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
672 // //     // Build the pointer list
673 // //     if(fParticleMap) {     <----
674 // //       fParticleMap->Clear();
675 // //       fParticleMap->Expand(treeK->GetEntries());
676 // //     } else
677 // //       fParticleMap = new TObjArray(treeK->GetEntries());
678     
679 //     // From gAlice->Particle(i) 
680
681
682 // //   if(!(*fParticleMap)[i]) {
683 // //     Int_t nentries = fParticles->GetEntries();
684     
685 // //     // algorithmic way of getting entry index
686 // //     // (primary particles are filled after secondaries)
687 // //     Int_t entry;
688 // //     if (i<fHeader.GetNprimary())
689 // //       entry = i+fHeader.GetNsecondary();
690 // //     else 
691 // //       entry = i-fHeader.GetNprimary();
692       
693 // //     // only check the algorithmic way and give
694 // //     // the fatal error if it is wrong
695 // //     if (entry != fParticleFileMap[i]) {
696 // //       Fatal("Particle",
697 // //         "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
698 // //   entry, fParticleFileMap[i]); 
699 // //     }  
700       
701 // //     fTreeK->GetEntry(fParticleFileMap[i]);
702 // //     new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
703 // //     fParticleMap->AddAt((*fParticles)[nentries],i);
704 // //   }
705 // //   return (TParticle *) (*fParticleMap)[i];
706
707    
708     
709 //   }
710
711
712 //   //scan over opened files and read corresponding TreeK##
713
714   return kTRUE ;
715 }
716 //____________________________________________________________________________ 
717 void AliPHOSIndexToObject::GetEvent(Int_t event){
718   if(event == fEvent) // do nothing
719     return ;
720     
721   fEvent = event ;
722   gAlice->GetEvent(fEvent) ;
723   
724   ReadRecParticles(fPID->GetRecParticlesBranch()) ;
725   ReadTS(fTSMaker->GetTrackSegmentsBranch()) ;
726   ReadRecPoints(fClusterizer->GetRecPointsBranch()) ;
727   ReadDigits(fDigitizer->GetDigitsBranch()) ;
728   ReadPrimaries() ;
729 }
730