]>
Commit | Line | Data |
---|---|---|
8020fb14 | 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 | ||
88cb7938 | 16 | /* $Id$ */ |
b9d0a01d | 17 | |
8020fb14 | 18 | #include <TFile.h> |
19 | #include <TTree.h> | |
20 | #include <TParticle.h> | |
88cb7938 | 21 | #include <TObjString.h> |
22 | #include <TObjArray.h> | |
8020fb14 | 23 | |
24 | #include "AliGenReaderTreeK.h" | |
8020fb14 | 25 | #include "AliHeader.h" |
26 | #include "AliRun.h" | |
88cb7938 | 27 | #include "AliRunLoader.h" |
8020fb14 | 28 | |
29 | ClassImp(AliGenReaderTreeK); | |
30 | ||
88cb7938 | 31 | const TString AliGenReaderTreeK::fgkEventFolderName("GenReaderTreeK"); |
32 | ||
33 | AliGenReaderTreeK::AliGenReaderTreeK(): | |
198bb1c7 | 34 | AliGenReader(), |
35 | fNcurrent(0), | |
36 | fNparticle(0), | |
37 | fNp(0), | |
38 | fInRunLoader(0), | |
39 | fBaseFile(0), | |
40 | fStack(0), | |
41 | fOnlyPrimaries(kFALSE), | |
42 | fDirs(0x0), | |
43 | fCurrentDir(0) | |
8020fb14 | 44 | { |
45 | // Default constructor | |
ae872676 | 46 | } |
47 | ||
88cb7938 | 48 | AliGenReaderTreeK::AliGenReaderTreeK(const AliGenReaderTreeK &reader): |
198bb1c7 | 49 | AliGenReader(reader), |
50 | fNcurrent(0), | |
51 | fNparticle(0), | |
52 | fNp(0), | |
53 | fInRunLoader(0), | |
54 | fBaseFile(0), | |
55 | fStack(0), | |
56 | fOnlyPrimaries(kFALSE), | |
57 | fDirs(0x0), | |
58 | fCurrentDir(0) | |
43342f51 | 59 | { |
198bb1c7 | 60 | reader.Copy(*this); |
43342f51 | 61 | } |
62 | ||
63 | ||
ae872676 | 64 | AliGenReaderTreeK::~AliGenReaderTreeK() |
65 | { | |
66 | // Destructor | |
88cb7938 | 67 | delete fInRunLoader;//it cleans all the loaded data |
68 | delete fDirs; | |
8020fb14 | 69 | } |
70 | ||
71 | void AliGenReaderTreeK::Init() | |
72 | { | |
73 | // Initialization | |
74 | // Connect base file and file to read from | |
75 | ||
76 | TTree *ali = gAlice->TreeE(); | |
77 | if (ali) { | |
88cb7938 | 78 | fBaseFile = ali->GetCurrentFile(); |
8020fb14 | 79 | } else { |
88cb7938 | 80 | printf("\n Warning: Basefile cannot be found !\n"); |
8020fb14 | 81 | } |
88cb7938 | 82 | //if (!fFile) fFile = new TFile(fFileName); |
83 | if (fInRunLoader == 0x0) | |
84 | { | |
85 | fInRunLoader = AliRunLoader::Open((GetDirName(fCurrentDir++)+"/")+fFileName,fgkEventFolderName); | |
86 | fInRunLoader->LoadHeader(); | |
87 | fInRunLoader->LoadKinematics("READ"); | |
88 | } | |
8020fb14 | 89 | } |
90 | ||
91 | Int_t AliGenReaderTreeK::NextEvent() | |
92 | { | |
314a87b5 | 93 | // Read the next event |
8020fb14 | 94 | // cd to file with old kine tree |
95 | if (!fBaseFile) Init(); | |
8020fb14 | 96 | // Get next event |
88cb7938 | 97 | |
98 | if (fNcurrent >= fInRunLoader->GetNumberOfEvents()) | |
99 | { | |
100 | if (fCurrentDir >= fDirs->GetEntries()) | |
101 | { | |
102 | Warning("NextEvent","No more events"); | |
103 | return 0; | |
104 | } | |
105 | delete fInRunLoader; | |
106 | fInRunLoader = AliRunLoader::Open((GetDirName(fCurrentDir++)+"/")+fFileName,fgkEventFolderName); | |
107 | fInRunLoader->LoadHeader(); | |
108 | fInRunLoader->LoadKinematics("READ"); | |
109 | fNcurrent = 0; | |
110 | } | |
111 | fInRunLoader->GetEvent(fNcurrent); | |
112 | fStack = fInRunLoader->Stack(); | |
113 | ||
8020fb14 | 114 | // cd back to base file |
115 | fBaseFile->cd(); | |
116 | // | |
117 | fNcurrent++; | |
118 | fNparticle = 0; | |
88cb7938 | 119 | fNp = fStack->GetNtrack(); |
120 | printf("\n Next event contains %d particles", fNp); | |
314a87b5 | 121 | // |
88cb7938 | 122 | return fNp; |
8020fb14 | 123 | } |
124 | ||
125 | TParticle* AliGenReaderTreeK::NextParticle() | |
126 | { | |
88cb7938 | 127 | //Return next particle |
128 | TParticle* part = GetParticle(fNparticle++); | |
129 | if (part == 0x0) return 0x0; | |
130 | //if only primaries are to be read, and this particle is not primary enter loop | |
131 | if (fOnlyPrimaries && ( part->GetFirstMother() > -1) ) | |
132 | for (;;) | |
133 | { //look for a primary | |
134 | part = GetParticle(fNparticle++); | |
135 | if (part == 0x0) return 0x0; | |
136 | if (part->GetFirstMother() == -1) return part; | |
137 | } | |
138 | ||
139 | return part; | |
8020fb14 | 140 | } |
141 | ||
d1d1da57 | 142 | void AliGenReaderTreeK::RewindEvent() |
143 | { | |
144 | // Go back to the first particle of the event | |
145 | fNparticle = 0; | |
146 | } | |
8020fb14 | 147 | |
148 | ||
ae872676 | 149 | AliGenReaderTreeK& AliGenReaderTreeK::operator=(const AliGenReaderTreeK& rhs) |
150 | { | |
151 | // Assignment operator | |
198bb1c7 | 152 | rhs.Copy(*this); |
ae872676 | 153 | return *this; |
154 | } | |
8020fb14 | 155 | |
198bb1c7 | 156 | void AliGenReaderTreeK::Copy(AliGenReaderTreeK&) const |
157 | { | |
158 | // | |
159 | // Copy | |
160 | // | |
161 | Fatal("Copy","Not implemented!\n"); | |
162 | } | |
163 | ||
8020fb14 | 164 | |
165 | ||
88cb7938 | 166 | TString& AliGenReaderTreeK::GetDirName(Int_t entry) |
167 | { | |
168 | TString* retval;//return value | |
169 | if (fDirs == 0x0) | |
170 | { | |
171 | retval = new TString("."); | |
172 | return *retval; | |
173 | } | |
174 | ||
175 | if ( (entry>fDirs->GetEntries()) || (entry<0))//if out of bounds return empty string | |
176 | { //note that entry==0 is accepted even if array is empty (size=0) | |
177 | Error("GetDirName","Name out of bounds"); | |
178 | retval = new TString(); | |
179 | return *retval; | |
180 | } | |
181 | ||
182 | if (fDirs->GetEntries() == 0) | |
183 | { | |
184 | retval = new TString("."); | |
185 | return *retval; | |
186 | } | |
187 | ||
188 | TObjString *dir = dynamic_cast<TObjString*>(fDirs->At(entry)); | |
189 | if(dir == 0x0) | |
190 | { | |
191 | Error("GetDirName","Object in TObjArray is not a TObjString or its descendant"); | |
192 | retval = new TString(); | |
193 | return *retval; | |
194 | } | |
195 | if (gDebug > 0) Info("GetDirName","Returned ok %s",dir->String().Data()); | |
196 | return dir->String(); | |
197 | } | |
198 | ||
199 | void AliGenReaderTreeK::AddDir(const char* dirname) | |
200 | { | |
201 | //adds a directory to the list of directories where data are looked for | |
202 | if(fDirs == 0x0) | |
203 | { | |
204 | fDirs = new TObjArray(); | |
205 | fDirs->SetOwner(kTRUE); | |
206 | } | |
207 | TObjString *odir= new TObjString(dirname); | |
208 | fDirs->Add(odir); | |
209 | } |