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