]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSIndexToObject.cxx
72c2c919d60ed762f1f50096c9e3824ff4b7b95d
[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 that retrieves objets from an array stored in a Tree on a disk file
20 //    1. AliPHOSDigit from TreeD     
21 //                  
22 //*-- Author: Yves Schutz (SUBATECH)
23 //////////////////////////////////////////////////////////////////////////////
24
25 #include <iostream.h>
26
27 // --- ROOT system ---
28
29 #include "TTree.h"
30
31 // --- Standard library ---
32
33 // --- AliRoot header files ---
34
35 #include "AliPHOSIndexToObject.h"
36
37 ClassImp(AliPHOSIndexToObject)
38   
39   AliPHOSIndexToObject * AliPHOSIndexToObject::fgObjGetter = 0 ; 
40
41 //____________________________________________________________________________ 
42 AliPHOSIndexToObject::AliPHOSIndexToObject(AliPHOS * det)
43 {
44   // ctor called once to initialize the detector in use
45
46   fDetector = det ; 
47 }
48
49 //____________________________________________________________________________ 
50 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance()
51 {
52   // Returns the pointer of the unique instance already defined
53   
54   AliPHOSIndexToObject * rv = 0 ;
55   if ( fgObjGetter )
56     rv = fgObjGetter ;
57   else
58     cout << "AliPHOSIndexToObject::GetInstance ERROR: not yet initialized" << endl ;
59   
60   return rv ;
61 }
62
63 //____________________________________________________________________________ 
64 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance(AliPHOS * det)
65 {
66   // Creates and returns the pointer of the unique instance
67   // Must be called only when the environment has changed (a new event for exemple)
68
69   if ( fgObjGetter )      // delete it if already exists
70     delete fgObjGetter ; 
71
72   fgObjGetter = new AliPHOSIndexToObject(det) ; 
73   
74   return fgObjGetter ; 
75   
76 }
77
78 //____________________________________________________________________________ 
79 AliPHOSDigit * AliPHOSIndexToObject::GimeDigit(Int_t index)
80 {
81   // returns the object AliPHOSDigit stored at array position index in TreeD
82
83   AliPHOSDigit * rv = 0 ; 
84
85   if ( index >= fDetector->Digits()->GetEntries() ) 
86     cout << "AliPHOSIndexToObject::GimeDigit: index " << index << " larger than available entries " 
87          <<  fDetector->Digits()->GetEntries() << endl ; 
88   else if ( index != -1) 
89     rv =  (AliPHOSDigit *) (fDetector->Digits()->At(index) ) ; 
90
91   return rv ;
92   
93 }
94 //____________________________________________________________________________ 
95 TParticle * AliPHOSIndexToObject::GimePrimaryParticle(Int_t index)
96 {
97   // returns the object TParticle stored at array position index in TreeK
98
99   TParticle * rv = 0 ; 
100      
101   if ( index >= gAlice->Particles()->GetEntries() ) 
102     cout << "AliPHOSIndexToObject::GimePrimaryParticles: index " << index << " larger than available entries " 
103          <<  gAlice->Particles()->GetEntries() << endl ; 
104   else 
105     rv =  (TParticle *) (gAlice->Particles()->At(index) ) ; 
106
107   return rv ;
108   
109 }
110
111 //____________________________________________________________________________ 
112 AliPHOSRecParticle * AliPHOSIndexToObject::GimeRecParticle(Int_t index)
113 {
114   // returns the object AliPHOSRecParticle stored at array position index in TreeR/PHOSRP
115   // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
116   // therefore the links are lost
117
118   AliPHOSRecParticle * rv = 0 ; 
119
120   AliPHOSRecParticle::RecParticlesList * rplist = *(fDetector->RecParticles()) ; 
121
122   Int_t rpentries  = 0 ; 
123
124   if (rplist) 
125     rpentries = rplist->GetEntries() ;
126   
127   fReconstruct = gAlice->TreeR() ; 
128   
129   if (!rpentries) {
130     fReconstruct->SetBranchAddress( "PHOSRP", &rplist ) ;
131     fReconstruct->GetEvent(0) ;
132     rpentries = rplist->GetEntries() ;  
133   }     
134   
135   if ( index >= rpentries )  // ERROR 
136     cout << "AliPHOSIndexToObject::GimeRecParticle: index " << index << " larger than available entries " 
137            <<  rpentries << endl ; 
138   else 
139     rv =  (AliPHOSRecParticle *) (*(fDetector->RecParticles()) )->At(index)  ; 
140   
141   return rv ;
142   
143 }
144
145 //____________________________________________________________________________ 
146 AliRecPoint * AliPHOSIndexToObject::GimeRecPoint(Int_t index, TString type)
147 {
148   // returns the object AliPHOSRecPoint stored at array position index in TreeR/PHOSEmcRP or TreeR/PHOSPpsdRP
149   // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
150   // therefore the links are lost
151
152   AliPHOSRecPoint * rv = 0 ; 
153   
154   AliPHOSRecPoint::RecPointsList * emclist = *(fDetector->EmcRecPoints() ); 
155   AliPHOSRecPoint::RecPointsList * ppsdlist = *(fDetector->PpsdRecPoints() ); 
156
157   Int_t emcentries  = 0 ; 
158   Int_t ppsdentries = 0 ; 
159
160   if (emclist) 
161     emcentries = emclist->GetEntries() ;
162
163   if (ppsdlist)
164     ppsdentries= ppsdlist->GetEntries() ;
165
166   fReconstruct = gAlice->TreeR() ; 
167   
168   if (!emcentries && !ppsdentries) {
169     fReconstruct->SetBranchAddress("PHOSEmcRP",&emclist);
170     fReconstruct->SetBranchAddress("PHOSPpsdRP",&ppsdlist);
171     fReconstruct->GetEvent(0) ;
172     emcentries = emclist->GetEntries() ;
173     ppsdentries= ppsdlist->GetEntries() ;
174   }     
175
176   if ( type == "emc" ) {
177     if ( index >= emcentries ) 
178       cout << "AliPHOSIndexToObject::GimeRecPoint emc: index " << index << " larger than available entries " 
179            <<  emcentries << endl ; 
180     else 
181       rv =  (AliPHOSEmcRecPoint *) ( emclist->At(index) ) ;
182   } 
183   else if ( type == "ppsd" ) {  
184     if ( index >= ppsdentries ) 
185       cout << "AliPHOSIndexToObject::GimeRecPoint ppsd: index " << index << " larger than available entries " 
186            <<  ppsdentries << endl ; 
187     else if (index != -1) 
188       rv =  (AliPHOSPpsdRecPoint *) (ppsdlist->At(index) ) ;
189   } else
190     cout << "AliPHOSIndexToObject::GimeRecPoint: " << type << " is an unknown type " << endl
191          << " valid types are : emc " << endl 
192          << "                   ppsd " << endl ;
193   
194   return rv ;
195   
196 }
197
198 //____________________________________________________________________________ 
199 AliPHOSTrackSegment * AliPHOSIndexToObject::GimeTrackSegment(Int_t index)
200 {
201   // returns the object AliPHOSTrackSegment stored at array position index in TreeR/PHOSTS
202   // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
203   // therefore the links are lost
204
205   AliPHOSTrackSegment * rv = 0 ; 
206
207   AliPHOSTrackSegment::TrackSegmentsList * tslist = *( fDetector->TrackSegments()) ; 
208
209   Int_t tsentries  = 0 ; 
210
211   if (tslist) 
212     tsentries = tslist->GetEntries() ;
213   
214   fReconstruct = gAlice->TreeR() ; 
215   
216   if (!tsentries) {
217     fReconstruct->SetBranchAddress( "PHOSTS", &tslist ) ;
218     fReconstruct->GetEvent(0) ;
219     tsentries = tslist->GetEntries() ;  
220   }     
221   
222   if ( index >= tsentries )  // ERROR 
223       cout << "AliPHOSIndexToObject::GimeTrackSegment: index " << index << " larger than available entries " 
224            <<  tsentries << endl ; 
225   else 
226     rv =  (AliPHOSTrackSegment *) (tslist->At(index) ) ; 
227   
228   return rv ;
229   
230 }