Step size region by region.
[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       fTree->Fill();
90   }
91   return kTRUE;
92 }
93
94 TString& AliJetParticlesReader::GetDirName(Int_t entry)
95 {
96   //returns directory name of entry to read
97   TString* retval;//return value
98   if (fDirs == 0)
99     {
100      retval = new TString(".");
101      return *retval;
102     }
103
104   if ((entry>fDirs->GetEntries()) || (entry<0))
105     //if out of bounds return empty string
106     //note that entry==0 is accepted even if array is empty (size=0)
107     {
108       Error("GetDirName","Entry out of bounds");
109       retval = new TString();
110       return *retval;
111     }
112
113   if (fDirs->GetEntries() == 0)
114     { 
115       retval = new TString(".");
116       return *retval;
117     }
118
119   TClass *objclass = fDirs->At(entry)->IsA();
120   TClass *stringclass = TObjString::Class();
121
122   TObjString *dir = (TObjString*)objclass->DynamicCast(stringclass,fDirs->At(entry));
123   if(dir == 0)
124    {
125      Error("GetDirName","Object in TObjArray is not a TObjString");
126      retval = new TString();
127      return *retval;
128    }
129
130   //Info("GetDirName","Returned ok %s",dir->String().Data());
131   return dir->String();
132 }
133