Corrected event counter.
[u/mrichter/AliRoot.git] / JETAN / AliJetParticlesReader.cxx
1 // $Id$
2
3 //_________________________________________________________________________
4 ///////////////////////////////////////////////////////////////////////////
5 //                                                                       //
6 // class AliJetParticlesReader                                           //
7 //                                                                       //
8 // This reader reads tracks from Event Summary Data                      //
9 // taken from Piotr.Skowronski@cern.ch                                   //
10 // more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html  //
11 //                                                                       //
12 // loizides@ikf.uni-frankfurt.de                                         //
13 ///////////////////////////////////////////////////////////////////////////
14
15 #include <TClass.h>
16 #include <TObjArray.h>
17 #include <TClonesArray.h>
18 #include <TString.h>
19 #include <TObjString.h>
20 #include <TTree.h>
21 #include "AliJetEventParticles.h"
22 #include "AliJetParticlesReader.h"
23
24  
25 ClassImp(AliJetParticlesReader)
26
27 AliJetParticlesReader::AliJetParticlesReader()
28   : TNamed(),
29     fEventParticles(0),
30     fOwner(kTRUE),
31     fDirs(0),
32     fCurrentEvent(0),
33     fCurrentDir(0),
34     fNEventsRead(0),
35     fFirst(0),
36     fLast(0),
37     fPtMin(0),fPtMax(1000),
38     fEtaMin(-1),fEtaMax(1),
39     fPhiMin(0),fPhiMax(2*TMath::Pi()),
40     fNewTree(0),
41     fTree(0)
42 {
43   //Constructor
44 }
45
46 AliJetParticlesReader::AliJetParticlesReader(TObjArray *dirs)
47   : TNamed(),
48     fEventParticles(0),
49     fOwner(kTRUE),
50     fDirs(dirs),
51     fCurrentEvent(0),
52     fCurrentDir(0),
53     fNEventsRead(0),
54     fFirst(0),
55     fLast(0),
56     fPtMin(0),fPtMax(1000),
57     fEtaMin(-1),fEtaMax(1),
58     fPhiMin(0),fPhiMax(2*TMath::Pi()),
59     fNewTree(0),
60     fTree(0)
61 {
62 }
63
64 AliJetParticlesReader::~AliJetParticlesReader()
65 {
66   //Constructor
67   if((fOwner) && (fEventParticles)) delete fEventParticles;
68 }
69
70 Int_t AliJetParticlesReader::Next()
71 {
72   //moves to next event
73   //if asked to read up to event nb. fLast, 
74   //and it is overcome, report no more events
75   if ((fNEventsRead > fLast) && (fLast > 0) ) return kFALSE;
76   
77   do //if asked to read from event fFirst, rewind to it
78     {
79       if ( ReadNext() == kFALSE) 
80         return kFALSE; //if no more evets, return it
81     } while (fNEventsRead < fFirst);
82    
83   //here we have event
84   if(fTree && fEventParticles){
85       if(fNewTree){
86         fTree->Branch("particles","AliJetEventParticles",&fEventParticles,32000,1);
87         fNewTree=0;
88       }
89       fEventParticles->SetEventNr(fCurrentDir*1000+fCurrentEvent);
90       fTree->Fill();
91   }
92   return kTRUE;
93 }
94
95 TString& AliJetParticlesReader::GetDirName(Int_t entry)
96 {
97   //returns directory name of entry to read
98   TString* retval;//return value
99   if (fDirs == 0)
100     {
101      retval = new TString(".");
102      return *retval;
103     }
104
105   if ((entry>fDirs->GetEntries()) || (entry<0))
106     //if out of bounds return empty string
107     //note that entry==0 is accepted even if array is empty (size=0)
108     {
109       Error("GetDirName","Entry out of bounds");
110       retval = new TString();
111       return *retval;
112     }
113
114   if (fDirs->GetEntries() == 0)
115     { 
116       retval = new TString(".");
117       return *retval;
118     }
119
120   TClass *objclass = fDirs->At(entry)->IsA();
121   TClass *stringclass = TObjString::Class();
122
123   TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
124   if(dir == 0)
125    {
126      Error("GetDirName","Object in TObjArray is not a TObjString");
127      retval = new TString();
128      return *retval;
129    }
130
131   //Info("GetDirName","Returned ok %s",dir->String().Data());
132   return dir->String();
133 }
134