]>
Commit | Line | Data |
---|---|---|
c7e89ea3 | 1 | /************************************************************************** |
2 | * Author: Panos Christakoglou. * | |
3 | * Contributors are mentioned in the code where appropriate. * | |
4 | * * | |
5 | * Permission to use, copy, modify and distribute this software and its * | |
6 | * documentation strictly for non-commercial purposes is hereby granted * | |
7 | * without fee, provided that the above copyright notice appears in all * | |
8 | * copies and that both the copyright notice and this permission notice * | |
9 | * appear in the supporting documentation. The authors make no claims * | |
10 | * about the suitability of this software for any purpose. It is * | |
11 | * provided "as is" without express or implied warranty. * | |
12 | **************************************************************************/ | |
13 | ||
14 | /* $Id$ */ | |
15 | ||
16 | //----------------------------------------------------------------- | |
17 | // AliTagAnalysis class | |
18 | // This is the class to deal with the tag analysis | |
19 | // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch | |
20 | //----------------------------------------------------------------- | |
21 | ||
22 | //ROOT | |
23 | #include <TSystem.h> | |
24 | #include <TChain.h> | |
c7e89ea3 | 25 | #include <TEventList.h> |
df122a89 | 26 | #include <TTreeFormula.h> |
c7e89ea3 | 27 | |
28 | //ROOT-AliEn | |
29 | #include <TGridResult.h> | |
30 | ||
31 | #include "AliLog.h" | |
32 | ||
33 | #include "AliRunTag.h" | |
34 | #include "AliEventTag.h" | |
35 | #include "AliTagAnalysis.h" | |
36 | #include "AliEventTagCuts.h" | |
a3acd4e8 | 37 | #include "AliRunTagCuts.h" |
b6003316 | 38 | #include "AliXMLCollection.h" |
c7e89ea3 | 39 | |
c7e89ea3 | 40 | ClassImp(AliTagAnalysis) |
41 | ||
42 | TChain *AliTagAnalysis::fgChain = 0; | |
43 | ||
54ac820d | 44 | //___________________________________________________________________________ |
45 | AliTagAnalysis::AliTagAnalysis(): | |
46 | TObject(), | |
fe12e09c | 47 | ftagresult(0x0), |
48 | fTagDirName(), | |
49 | fChain(0x0) | |
c7e89ea3 | 50 | { |
54ac820d | 51 | //Default constructor for a AliTagAnalysis |
c7e89ea3 | 52 | } |
53 | ||
54ac820d | 54 | //___________________________________________________________________________ |
55 | AliTagAnalysis::~AliTagAnalysis() { | |
56 | //Default destructor for a AliTagAnalysis | |
c7e89ea3 | 57 | } |
58 | ||
54ac820d | 59 | //___________________________________________________________________________ |
60 | void AliTagAnalysis::ChainLocalTags(const char *dirname) { | |
c7e89ea3 | 61 | //Searches the entries of the provided direcory |
62 | //Chains the tags that are stored locally | |
63 | fTagDirName = dirname; | |
64 | TString fTagFilename; | |
65 | ||
66 | TChain *fgChain = new TChain("T"); | |
67 | fChain = fgChain; | |
68 | ||
f2313c5b | 69 | const char * tagPattern = "tag.root"; |
c7e89ea3 | 70 | // Open the working directory |
71 | void * dirp = gSystem->OpenDirectory(fTagDirName); | |
72 | const char * name = 0x0; | |
73 | // Add all files matching *pattern* to the chain | |
54ac820d | 74 | while((name = gSystem->GetDirEntry(dirp))) { |
75 | if (strstr(name,tagPattern)) { | |
76 | fTagFilename = fTagDirName; | |
77 | fTagFilename += "/"; | |
78 | fTagFilename += name; | |
c7e89ea3 | 79 | |
54ac820d | 80 | fChain->Add(fTagFilename); |
54ac820d | 81 | }//pattern check |
82 | }//directory loop | |
c7e89ea3 | 83 | AliInfo(Form("Chained tag files: %d ",fChain->GetEntries())); |
84 | } | |
85 | ||
86 | ||
54ac820d | 87 | //___________________________________________________________________________ |
88 | void AliTagAnalysis::ChainGridTags(TGridResult *res) { | |
c7e89ea3 | 89 | //Loops overs the entries of the TGridResult |
90 | //Chains the tags that are stored in the GRID | |
91 | ftagresult = res; | |
92 | Int_t nEntries = ftagresult->GetEntries(); | |
93 | ||
94 | TChain *fgChain = new TChain("T"); | |
95 | fChain = fgChain; | |
96 | ||
97 | TString gridname = "alien://"; | |
98 | TString alienUrl; | |
99 | ||
54ac820d | 100 | for(Int_t i = 0; i < nEntries; i++) { |
101 | alienUrl = ftagresult->GetKey(i,"turl"); | |
54ac820d | 102 | fChain->Add(alienUrl); |
54ac820d | 103 | }//grid result loop |
c7e89ea3 | 104 | } |
105 | ||
106 | ||
54ac820d | 107 | //___________________________________________________________________________ |
a3acd4e8 | 108 | TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) { |
c7e89ea3 | 109 | //Queries the tag chain using the defined |
110 | //event tag cuts from the AliEventTagCuts object | |
b6003316 | 111 | //and returns a TChain along with the associated TEventList |
c7e89ea3 | 112 | AliInfo(Form("Querying the tags........")); |
113 | ||
df16faa3 | 114 | //ESD file chain |
115 | TChain *fESDchain = new TChain("esdTree"); | |
116 | //Event list | |
117 | TEventList *fEventList = new TEventList(); | |
c7e89ea3 | 118 | |
119 | //Defining tag objects | |
120 | AliRunTag *tag = new AliRunTag; | |
121 | AliEventTag *evTag = new AliEventTag; | |
122 | fChain->SetBranchAddress("AliTAG",&tag); | |
123 | ||
d021d0d7 | 124 | TString guid = 0; |
125 | TString turl = 0; | |
126 | TString path = 0; | |
c7e89ea3 | 127 | |
df16faa3 | 128 | Int_t iAccepted = 0; |
129 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
54ac820d | 130 | fChain->GetEntry(iTagFiles); |
a3acd4e8 | 131 | if(RunTagCuts->IsAccepted(tag)) { |
132 | Int_t iEvents = tag->GetNEvents(); | |
133 | const TClonesArray *tagList = tag->GetEventTags(); | |
134 | for(Int_t i = 0; i < iEvents; i++) { | |
135 | evTag = (AliEventTag *) tagList->At(i); | |
136 | guid = evTag->GetGUID(); | |
137 | turl = evTag->GetTURL(); | |
138 | path = evTag->GetPath(); | |
139 | if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i); | |
140 | }//event loop | |
141 | iAccepted += iEvents; | |
d021d0d7 | 142 | |
a3acd4e8 | 143 | if(path != "") fESDchain->AddFile(path); |
144 | else if(turl != "") fESDchain->AddFile(turl); | |
145 | }//run tags cut | |
54ac820d | 146 | }//tag file loop |
df16faa3 | 147 | AliInfo(Form("Accepted events: %d",fEventList->GetN())); |
148 | fESDchain->SetEventList(fEventList); | |
c7e89ea3 | 149 | |
df16faa3 | 150 | return fESDchain; |
c7e89ea3 | 151 | } |
152 | ||
df122a89 | 153 | //___________________________________________________________________________ |
154 | TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fEventCut) { | |
155 | //Queries the tag chain using the defined | |
156 | //event tag cuts from the AliEventTagCuts object | |
157 | //and returns a TChain along with the associated TEventList | |
158 | AliInfo(Form("Querying the tags........")); | |
159 | ||
160 | //ESD file chain | |
161 | TChain *fESDchain = new TChain("esdTree"); | |
162 | //Event list | |
163 | TEventList *fEventList = new TEventList(); | |
164 | ||
165 | //Defining tag objects | |
166 | AliRunTag *tag = new AliRunTag; | |
167 | AliEventTag *evTag = new AliEventTag; | |
168 | fChain->SetBranchAddress("AliTAG",&tag); | |
169 | ||
170 | TString guid = 0; | |
171 | TString turl = 0; | |
172 | TString path = 0; | |
173 | ||
174 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
175 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
176 | ||
177 | Int_t current = -1; | |
178 | Int_t iAccepted = 0; | |
179 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
180 | fChain->GetEntry(iTagFiles); | |
181 | if (current != fChain->GetTreeNumber()) { | |
182 | fRunFormula->UpdateFormulaLeaves(); | |
183 | fEventFormula->UpdateFormulaLeaves(); | |
184 | current = fChain->GetTreeNumber(); | |
185 | } | |
186 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
187 | Int_t iEvents = fEventFormula->GetNdata(); | |
188 | const TClonesArray *tagList = tag->GetEventTags(); | |
189 | for(Int_t i = 0; i < iEvents; i++) { | |
190 | evTag = (AliEventTag *) tagList->At(i); | |
191 | guid = evTag->GetGUID(); | |
192 | turl = evTag->GetTURL(); | |
193 | path = evTag->GetPath(); | |
194 | if(fEventFormula->EvalInstance(i) == 1) fEventList->Enter(iAccepted+i); | |
195 | }//event loop | |
196 | iAccepted += iEvents; | |
197 | ||
198 | if(path != "") fESDchain->AddFile(path); | |
199 | else if(turl != "") fESDchain->AddFile(turl); | |
200 | }//run tag cut | |
201 | }//tag file loop | |
202 | AliInfo(Form("Accepted events: %d",fEventList->GetN())); | |
203 | fESDchain->SetEventList(fEventList); | |
204 | ||
205 | return fESDchain; | |
206 | } | |
207 | ||
b6003316 | 208 | //___________________________________________________________________________ |
a3acd4e8 | 209 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) { |
b6003316 | 210 | //Queries the tag chain using the defined |
211 | //event tag cuts from the AliEventTagCuts object | |
212 | //and returns a XML collection | |
213 | AliInfo(Form("Creating the collection........")); | |
214 | ||
215 | AliXMLCollection *collection = new AliXMLCollection(); | |
216 | collection->SetCollectionName(name); | |
217 | collection->WriteHeader(); | |
218 | ||
219 | //Event list | |
220 | TEventList *fEventList = new TEventList(); | |
221 | TString guid = 0x0; | |
c6e443c8 | 222 | TString turl = 0x0; |
eb771b73 | 223 | TString lfn = 0x0; |
b6003316 | 224 | |
225 | //Defining tag objects | |
226 | AliRunTag *tag = new AliRunTag; | |
227 | AliEventTag *evTag = new AliEventTag; | |
228 | fChain->SetBranchAddress("AliTAG",&tag); | |
229 | ||
230 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
231 | fChain->GetEntry(iTagFiles); | |
a3acd4e8 | 232 | if(RunTagCuts->IsAccepted(tag)) { |
233 | Int_t iEvents = tag->GetNEvents(); | |
234 | const TClonesArray *tagList = tag->GetEventTags(); | |
235 | for(Int_t i = 0; i < iEvents; i++) { | |
236 | evTag = (AliEventTag *) tagList->At(i); | |
237 | guid = evTag->GetGUID(); | |
238 | turl = evTag->GetTURL(); | |
eb771b73 | 239 | lfn = turl(8,turl.Length()); |
a3acd4e8 | 240 | if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(i); |
241 | }//event loop | |
eb771b73 | 242 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,fEventList); |
a3acd4e8 | 243 | fEventList->Clear(); |
244 | }//run tag cuts | |
b6003316 | 245 | }//tag file loop |
246 | collection->Export(); | |
247 | ||
248 | return kTRUE; | |
249 | } | |
c7e89ea3 | 250 | |
df122a89 | 251 | //___________________________________________________________________________ |
252 | Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut, const char *fEventCut) { | |
253 | //Queries the tag chain using the defined | |
254 | //event tag cuts from the AliEventTagCuts object | |
255 | //and returns a XML collection | |
256 | AliInfo(Form("Creating the collection........")); | |
257 | ||
258 | AliXMLCollection *collection = new AliXMLCollection(); | |
259 | collection->SetCollectionName(name); | |
260 | collection->WriteHeader(); | |
261 | ||
262 | //Event list | |
263 | TEventList *fEventList = new TEventList(); | |
264 | TString guid = 0x0; | |
265 | TString turl = 0x0; | |
eb771b73 | 266 | TString lfn = 0x0; |
df122a89 | 267 | |
268 | //Defining tag objects | |
269 | AliRunTag *tag = new AliRunTag; | |
270 | AliEventTag *evTag = new AliEventTag; | |
271 | fChain->SetBranchAddress("AliTAG",&tag); | |
272 | ||
273 | TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain); | |
274 | TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain); | |
275 | ||
276 | Int_t current = -1; | |
277 | for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) { | |
278 | fChain->GetEntry(iTagFiles); | |
279 | if (current != fChain->GetTreeNumber()) { | |
280 | fRunFormula->UpdateFormulaLeaves(); | |
281 | fEventFormula->UpdateFormulaLeaves(); | |
282 | current = fChain->GetTreeNumber(); | |
283 | } | |
284 | if(fRunFormula->EvalInstance(iTagFiles) == 1) { | |
285 | Int_t iEvents = fEventFormula->GetNdata(); | |
286 | const TClonesArray *tagList = tag->GetEventTags(); | |
287 | for(Int_t i = 0; i < iEvents; i++) { | |
288 | evTag = (AliEventTag *) tagList->At(i); | |
289 | guid = evTag->GetGUID(); | |
290 | turl = evTag->GetTURL(); | |
eb771b73 | 291 | lfn = turl(8,turl.Length()); |
df122a89 | 292 | if(fEventFormula->EvalInstance(i) == 1) fEventList->Enter(i); |
293 | }//event loop | |
eb771b73 | 294 | collection->WriteBody(iTagFiles+1,guid,lfn,turl,fEventList); |
df122a89 | 295 | fEventList->Clear(); |
296 | }//run tag cuts | |
297 | }//tag file loop | |
298 | collection->Export(); | |
299 | ||
300 | return kTRUE; | |
301 | } |