]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HBTAN/AliHBTReader.cxx
Non-buffering readers implemented, proper changes in analysis. Compiler warnings...
[u/mrichter/AliRoot.git] / HBTAN / AliHBTReader.cxx
1 #include "AliHBTReader.h"
2
3 #include <TString.h>
4 #include <TObjString.h>
5 #include <TObjArray.h>
6 #include <TClass.h>
7
8 #include "AliHBTParticleCut.h"
9 #include "AliHBTEvent.h"
10 #include "AliHBTRun.h"
11  
12 ClassImp(AliHBTReader)
13 //pure virtual
14     
15 /*************************************************************************************/
16
17 AliHBTReader::AliHBTReader():
18  fCuts(new TObjArray()),
19  fDirs(0x0),
20  fCurrentEvent(0),
21  fCurrentDir(0),
22  fNEventsRead(0),
23  fTracksEvent(0x0),
24  fParticlesEvent(0x0),
25  fParticles(0x0),
26  fTracks(0x0),
27  fIsRead(kFALSE),
28  fBufferEvents(kFALSE)
29 {
30 //constructor
31 }
32 /*************************************************************************************/
33
34 AliHBTReader::AliHBTReader(TObjArray* dirs):
35  fCuts(new TObjArray()),
36  fDirs(dirs),
37  fCurrentEvent(0),
38  fCurrentDir(0),
39  fNEventsRead(0),
40  fTracksEvent(0x0),
41  fParticlesEvent(0x0),
42  fParticles(0x0),
43  fTracks(0x0),
44  fIsRead(kFALSE),
45  fBufferEvents(kFALSE)
46 {
47 //ctor with array of directories to read as parameter
48 }
49 /*************************************************************************************/
50
51 AliHBTReader::~AliHBTReader()
52 {
53 //destructor
54  if(fCuts)
55   {
56    fCuts->SetOwner();
57    delete fCuts;
58   }
59  delete fParticlesEvent;
60  delete fTracksEvent;
61 }
62 /*************************************************************************************/
63
64 Int_t AliHBTReader::Next()
65 {
66 //moves to next event
67   if ( ReadNext() == kTRUE)
68      return kTRUE;
69   
70   if (fBufferEvents)
71    {
72      if ( ReadsTracks() && fTracksEvent) 
73        fTracks->SetEvent(fNEventsRead-1,fTracksEvent);
74      if ( ReadsParticles() && fParticlesEvent)
75        fParticles->SetEvent(fNEventsRead-1,fParticlesEvent);
76    }
77   return kFALSE;
78 }
79 /*************************************************************************************/
80
81 void AliHBTReader::AddParticleCut(AliHBTParticleCut* cut)
82 {
83  //sets the new cut 
84  
85   if (!cut) //if cut is NULL return with error
86    {
87     Error("AddParticleType","NULL pointers are not accepted any more.\nIf You want to accept all particles of this type, set an empty cut ");
88     return;
89    }
90   AliHBTParticleCut *c = (AliHBTParticleCut*)cut->Clone();
91   fCuts->Add(c);
92 }
93 /********************************************************************/
94
95 AliHBTEvent* AliHBTReader::GetParticleEvent(Int_t n)
96  {
97  //returns Nth event with simulated particles
98   if (ReadsParticles() == kFALSE)
99    {
100      Error("GetParticleEvent","This reader is not able to provide simulated particles.");
101      return 0;
102    } 
103    
104   if (!fIsRead) 
105    { 
106     if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
107     if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
108     
109     if (Read(fParticles,fTracks))
110      {
111        Error("GetParticleEvent","Error in reading");
112        return 0x0;
113      }
114     else fIsRead = kTRUE;
115    }
116   return fParticles->GetEvent(n);
117  }
118 /********************************************************************/
119
120 AliHBTEvent* AliHBTReader::GetTrackEvent(Int_t n)
121  {
122  //returns Nth event with reconstructed tracks
123   if (ReadsTracks() == kFALSE)
124    {
125      Error("GetTrackEvent","This reader is not able to provide recosntructed tracks.");
126      return 0;
127    } 
128   if (!fIsRead) 
129    {
130     if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
131     if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
132     
133     if(Read(fParticles,fTracks))
134      {
135        Error("GetTrackEvent","Error in reading");
136        return 0x0;
137      }
138     else fIsRead = kTRUE;
139    }
140   return fTracks->GetEvent(n);
141  }
142 /********************************************************************/
143
144 Int_t AliHBTReader::GetNumberOfPartEvents()
145  {
146  //returns number of events of particles
147   if (ReadsParticles() == kFALSE)
148    {
149      Error("GetNumberOfPartEvents","This reader is not able to provide simulated particles.");
150      return 0;
151    } 
152    
153   if (!fIsRead) 
154    {
155     if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
156     if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
157     
158     if (Read(fParticles,fTracks))
159      {
160        Error("GetNumberOfPartEvents","Error in reading");
161        return 0;
162      }
163     else fIsRead = kTRUE;
164    }
165    return fParticles->GetNumberOfEvents();
166  }
167 /********************************************************************/
168  
169 Int_t AliHBTReader::GetNumberOfTrackEvents()
170  {
171  //returns number of events of tracks
172   if (ReadsTracks() == kFALSE)
173    {
174      Error("GetNumberOfTrackEvents","This reader is not able to provide recosntructed tracks.");
175      return 0;
176    } 
177   if (!fIsRead)
178    {
179      if (ReadsParticles() && (fParticles == 0x0)) fParticles = new AliHBTRun();
180      if (ReadsTracks() && (fTracks == 0x0)) fTracks = new AliHBTRun();
181      
182      if(Read(fParticles,fTracks))
183       {
184         Error("GetNumberOfTrackEvents","Error in reading");
185         return 0;
186       }
187      else fIsRead = kTRUE;
188    }
189   return fTracks->GetNumberOfEvents();
190  }
191 /********************************************************************/
192
193 Int_t AliHBTReader::Read(AliHBTRun* particles, AliHBTRun *tracks)
194 {
195  //reads data and puts put to the particles and tracks objects
196  //reurns 0 if everything is OK
197  //
198   Info("Read","");
199   
200   if (!particles) //check if an object is instatiated
201    {
202      Error("Read"," particles object must be instatiated before passing it to the reader");
203      return 1;
204    }
205   if (!tracks)  //check if an object is instatiated
206    {
207      Error("Read"," tracks object must be instatiated before passing it to the reader");
208      return 1;
209    }
210   particles->Reset();//clear runs == delete all old events
211   tracks->Reset();
212   
213   Rewind();
214   
215   Int_t i = 0;
216   while(Next() == kFALSE)
217    {
218      if (ReadsTracks()) tracks->SetEvent(i,fTracksEvent);
219      if (ReadsParticles()) particles->SetEvent(i,fParticlesEvent);
220      i++;
221    }
222   return 0;
223 }      
224 /*************************************************************************************/
225
226 Bool_t AliHBTReader::Pass(AliHBTParticle* p)
227 {
228  //Method examines whether particle meets all cut and particle type criteria
229   
230    if(p==0x0)//of corse we not pass NULL pointers
231     {
232      Warning("Pass()","No Pasaran! We never accept NULL pointers");
233      return kTRUE;
234     }
235    //if no particle is specified, we pass all particles
236    //excluding NULL pointers, of course
237   if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
238   for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)   
239    {
240      AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
241      if(!cut.Pass(p)) return kFALSE;  //accepted
242    }
243    
244   return kTRUE;//not accepted
245 }
246 /*************************************************************************************/
247
248 Bool_t  AliHBTReader::Pass(Int_t pid)
249 {
250 //this method checks if any of existing cuts accepts this pid particles
251 //or any cuts accepts all particles
252
253  if(pid == 0)
254   return kTRUE;
255
256  if ( fCuts->GetEntriesFast() == 0 ) return kFALSE; //if no cut specified accept all particles
257   
258  for(Int_t i=0; i<fCuts->GetEntriesFast(); i++)   
259    {
260      AliHBTParticleCut &cut = *((AliHBTParticleCut*)fCuts->At(i));
261      //if some of cuts accepts all particles or some accepts particles of this type, accept
262      if ( (cut.GetPID() == 0) || (cut.GetPID() == pid) ) return kFALSE; 
263    }
264  return kTRUE;
265 }
266 /*************************************************************************************/
267
268 TString& AliHBTReader::GetDirName(Int_t entry)
269 {
270 //returns directory name of next one to read
271   TString* retval;//return value
272   if (fDirs ==  0x0)
273    {
274      retval = new TString(".");
275      return *retval;
276    }
277
278   if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string
279    {                                            //note that entry==0 is accepted even if array is empty (size=0)
280      Error("GetDirName","Name out of bounds");
281      retval = new TString();
282      return *retval;
283    }
284
285   if (fDirs->GetEntries() == 0)
286    { 
287      retval = new TString(".");
288      return *retval;
289    }
290
291   TClass *objclass = fDirs->At(entry)->IsA();
292   TClass *stringclass = TObjString::Class();
293
294   TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
295
296   if(dir == 0x0)
297    {
298      Error("GetDirName","Object in TObjArray is not a TObjString or its descendant");
299      retval = new TString();
300      return *retval;
301    }
302   if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data());
303   return dir->String();
304 }
305