]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTagAnalysis.cxx
New AddFile method
[u/mrichter/AliRoot.git] / STEER / AliTagAnalysis.cxx
CommitLineData
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>
2f514327 25#include <TFile.h>
c7e89ea3 26#include <TEventList.h>
2f514327 27#include <TEntryList.h>
5b7be856 28#include <TTreeFormula.h>
c7e89ea3 29
30//ROOT-AliEn
31#include <TGridResult.h>
32
33#include "AliLog.h"
34
35#include "AliRunTag.h"
36#include "AliEventTag.h"
37#include "AliTagAnalysis.h"
38#include "AliEventTagCuts.h"
a3acd4e8 39#include "AliRunTagCuts.h"
b6003316 40#include "AliXMLCollection.h"
c7e89ea3 41
2f514327 42class TTree;
43
c7e89ea3 44ClassImp(AliTagAnalysis)
45
46TChain *AliTagAnalysis::fgChain = 0;
47
54ac820d 48//___________________________________________________________________________
49AliTagAnalysis::AliTagAnalysis():
50 TObject(),
fe12e09c 51 ftagresult(0x0),
52 fTagDirName(),
53 fChain(0x0)
c7e89ea3 54{
54ac820d 55 //Default constructor for a AliTagAnalysis
c7e89ea3 56}
57
54ac820d 58//___________________________________________________________________________
59AliTagAnalysis::~AliTagAnalysis() {
60//Default destructor for a AliTagAnalysis
c7e89ea3 61}
62
6e2eae7e 63//___________________________________________________________________________
64Bool_t AliTagAnalysis::AddTagsFile(const char *alienUrl) {
65
66 // Add a single tags file to the chain
67
68 Bool_t rv = kTRUE ;
69
70 if (! fgChain || ! fChain ) {
71 TChain *fgChain = new TChain("T");
72 fChain = fgChain;
73 }
74
75 TFile *f = TFile::Open(alienUrl,"READ");
76 fChain->Add(alienUrl);
77 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
78 delete f;
79
80 if (fChain->GetEntries() == 0 )
81 rv = kFALSE ;
82
83 return rv ;
84}
85
54ac820d 86//___________________________________________________________________________
87void AliTagAnalysis::ChainLocalTags(const char *dirname) {
c7e89ea3 88 //Searches the entries of the provided direcory
89 //Chains the tags that are stored locally
90 fTagDirName = dirname;
91 TString fTagFilename;
92
93 TChain *fgChain = new TChain("T");
94 fChain = fgChain;
95
f2313c5b 96 const char * tagPattern = "tag.root";
c7e89ea3 97 // Open the working directory
98 void * dirp = gSystem->OpenDirectory(fTagDirName);
99 const char * name = 0x0;
100 // Add all files matching *pattern* to the chain
54ac820d 101 while((name = gSystem->GetDirEntry(dirp))) {
102 if (strstr(name,tagPattern)) {
103 fTagFilename = fTagDirName;
104 fTagFilename += "/";
105 fTagFilename += name;
c7e89ea3 106
54ac820d 107 fChain->Add(fTagFilename);
54ac820d 108 }//pattern check
109 }//directory loop
c7e89ea3 110 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
111}
112
113
54ac820d 114//___________________________________________________________________________
115void AliTagAnalysis::ChainGridTags(TGridResult *res) {
c7e89ea3 116 //Loops overs the entries of the TGridResult
117 //Chains the tags that are stored in the GRID
118 ftagresult = res;
119 Int_t nEntries = ftagresult->GetEntries();
120
121 TChain *fgChain = new TChain("T");
122 fChain = fgChain;
123
124 TString gridname = "alien://";
125 TString alienUrl;
126
54ac820d 127 for(Int_t i = 0; i < nEntries; i++) {
128 alienUrl = ftagresult->GetKey(i,"turl");
54ac820d 129 fChain->Add(alienUrl);
54ac820d 130 }//grid result loop
c7e89ea3 131}
132
133
54ac820d 134//___________________________________________________________________________
a3acd4e8 135TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
c7e89ea3 136 //Queries the tag chain using the defined
137 //event tag cuts from the AliEventTagCuts object
b6003316 138 //and returns a TChain along with the associated TEventList
c7e89ea3 139 AliInfo(Form("Querying the tags........"));
140
df16faa3 141 //ESD file chain
142 TChain *fESDchain = new TChain("esdTree");
143 //Event list
144 TEventList *fEventList = new TEventList();
c7e89ea3 145
146 //Defining tag objects
147 AliRunTag *tag = new AliRunTag;
148 AliEventTag *evTag = new AliEventTag;
149 fChain->SetBranchAddress("AliTAG",&tag);
150
d021d0d7 151 TString guid = 0;
152 TString turl = 0;
153 TString path = 0;
c7e89ea3 154
df16faa3 155 Int_t iAccepted = 0;
156 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
54ac820d 157 fChain->GetEntry(iTagFiles);
a3acd4e8 158 if(RunTagCuts->IsAccepted(tag)) {
159 Int_t iEvents = tag->GetNEvents();
160 const TClonesArray *tagList = tag->GetEventTags();
161 for(Int_t i = 0; i < iEvents; i++) {
162 evTag = (AliEventTag *) tagList->At(i);
163 guid = evTag->GetGUID();
164 turl = evTag->GetTURL();
165 path = evTag->GetPath();
166 if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
167 }//event loop
168 iAccepted += iEvents;
d021d0d7 169
a3acd4e8 170 if(path != "") fESDchain->AddFile(path);
171 else if(turl != "") fESDchain->AddFile(turl);
172 }//run tags cut
54ac820d 173 }//tag file loop
df16faa3 174 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
175 fESDchain->SetEventList(fEventList);
c7e89ea3 176
df16faa3 177 return fESDchain;
c7e89ea3 178}
179
5b7be856 180//___________________________________________________________________________
181TChain *AliTagAnalysis::QueryTags(const char *fRunCut, const char *fEventCut) {
182 //Queries the tag chain using the defined
183 //event tag cuts from the AliEventTagCuts object
184 //and returns a TChain along with the associated TEventList
185 AliInfo(Form("Querying the tags........"));
186
187 //ESD file chain
188 TChain *fESDchain = new TChain("esdTree");
189 //Event list
190 TEventList *fEventList = new TEventList();
191
192 //Defining tag objects
193 AliRunTag *tag = new AliRunTag;
194 AliEventTag *evTag = new AliEventTag;
195 fChain->SetBranchAddress("AliTAG",&tag);
196
197 TString guid = 0;
198 TString turl = 0;
199 TString path = 0;
200
201 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
202 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
203
204 Int_t current = -1;
205 Int_t iAccepted = 0;
206 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
207 fChain->GetEntry(iTagFiles);
208 if (current != fChain->GetTreeNumber()) {
209 fRunFormula->UpdateFormulaLeaves();
210 fEventFormula->UpdateFormulaLeaves();
211 current = fChain->GetTreeNumber();
212 }
213 if(fRunFormula->EvalInstance(iTagFiles) == 1) {
214 Int_t iEvents = fEventFormula->GetNdata();
215 const TClonesArray *tagList = tag->GetEventTags();
216 for(Int_t i = 0; i < iEvents; i++) {
217 evTag = (AliEventTag *) tagList->At(i);
218 guid = evTag->GetGUID();
219 turl = evTag->GetTURL();
220 path = evTag->GetPath();
221 if(fEventFormula->EvalInstance(i) == 1) fEventList->Enter(iAccepted+i);
222 }//event loop
223 iAccepted += iEvents;
224
225 if(path != "") fESDchain->AddFile(path);
226 else if(turl != "") fESDchain->AddFile(turl);
227 }//run tag cut
228 }//tag file loop
229 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
230 fESDchain->SetEventList(fEventList);
231
232 return fESDchain;
233}
234
b6003316 235//___________________________________________________________________________
a3acd4e8 236Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
b6003316 237 //Queries the tag chain using the defined
238 //event tag cuts from the AliEventTagCuts object
239 //and returns a XML collection
240 AliInfo(Form("Creating the collection........"));
241
242 AliXMLCollection *collection = new AliXMLCollection();
243 collection->SetCollectionName(name);
244 collection->WriteHeader();
245
6e2eae7e 246 //Event list
247 //TEntryList *fEventList = new TEntryList();
b6003316 248 TString guid = 0x0;
c6e443c8 249 TString turl = 0x0;
eb771b73 250 TString lfn = 0x0;
b6003316 251
252 //Defining tag objects
253 AliRunTag *tag = new AliRunTag;
254 AliEventTag *evTag = new AliEventTag;
255 fChain->SetBranchAddress("AliTAG",&tag);
256
257 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
5b7be856 258 //Event list
259 TEntryList *fList = new TEntryList();
b6003316 260 fChain->GetEntry(iTagFiles);
a3acd4e8 261 if(RunTagCuts->IsAccepted(tag)) {
262 Int_t iEvents = tag->GetNEvents();
263 const TClonesArray *tagList = tag->GetEventTags();
264 for(Int_t i = 0; i < iEvents; i++) {
265 evTag = (AliEventTag *) tagList->At(i);
266 guid = evTag->GetGUID();
267 turl = evTag->GetTURL();
eb771b73 268 lfn = turl(8,turl.Length());
5b7be856 269 if(EvTagCuts->IsAccepted(evTag)) fList->Enter(i);
270 }//event loop
271 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
272 }//run tag cuts
273 }//tag file loop
274 collection->Export();
275
276 return kTRUE;
277}
278
279//___________________________________________________________________________
280Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, const char *fRunCut, const char *fEventCut) {
281 //Queries the tag chain using the defined
282 //event tag cuts from the AliEventTagCuts object
283 //and returns a XML collection
284 AliInfo(Form("Creating the collection........"));
285
286 AliXMLCollection *collection = new AliXMLCollection();
287 collection->SetCollectionName(name);
288 collection->WriteHeader();
2f514327 289
5b7be856 290 TString guid = 0x0;
291 TString turl = 0x0;
292 TString lfn = 0x0;
293
294 //Defining tag objects
295 AliRunTag *tag = new AliRunTag;
296 AliEventTag *evTag = new AliEventTag;
297 fChain->SetBranchAddress("AliTAG",&tag);
298
299 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
300 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
301
302 Int_t current = -1;
303 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
304 //Event list
305 TEntryList *fList = new TEntryList();
306 fChain->GetEntry(iTagFiles);
307 if (current != fChain->GetTreeNumber()) {
308 fRunFormula->UpdateFormulaLeaves();
309 fEventFormula->UpdateFormulaLeaves();
310 current = fChain->GetTreeNumber();
311 }
312 if(fRunFormula->EvalInstance(iTagFiles) == 1) {
313 Int_t iEvents = fEventFormula->GetNdata();
314 const TClonesArray *tagList = tag->GetEventTags();
315 for(Int_t i = 0; i < iEvents; i++) {
316 evTag = (AliEventTag *) tagList->At(i);
317 guid = evTag->GetGUID();
318 turl = evTag->GetTURL();
319 lfn = turl(8,turl.Length());
320 if(fEventFormula->EvalInstance(i) == 1) fList->Enter(i);
a3acd4e8 321 }//event loop
5b7be856 322 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
a3acd4e8 323 }//run tag cuts
b6003316 324 }//tag file loop
325 collection->Export();
326
327 return kTRUE;
328}
c7e89ea3 329
df122a89 330//___________________________________________________________________________
2f514327 331TChain *AliTagAnalysis::GetInputChain(const char* system, const char*global, const char *wn) {
332 //returns the chain+event list - used in batch sessions
333 TString fsystem = system;
334 Int_t iAccepted = 0;
335 //ESD file chain
336 TChain *fESDchain = new TChain("esdTree");
df122a89 337 //Event list
338 TEventList *fEventList = new TEventList();
2f514327 339 AliXMLCollection *collection1 = AliXMLCollection::Open(global);
340 AliXMLCollection *collection2 = AliXMLCollection::Open(wn);
341 collection1->OverlapCollection(collection2);
342 collection1->Reset();
343 while (collection1->Next()) {
344 AliInfo(Form("Adding: %s",collection1->GetTURL("")));
345 fESDchain->Add(collection1->GetTURL(""));
346 TEntryList *list = (TEntryList *)collection1->GetEventList("");
347 for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i));
348
349 if(fsystem == "pp") iAccepted += 100;
350 else if(fsystem == "PbPb") iAccepted += 1;
351 }
df122a89 352
2f514327 353 fESDchain->SetEventList(fEventList);
354
355 AliInfo(Form("Number of selected events: %d",fEventList->GetN()));
df122a89 356
2f514327 357 return fESDchain;
df122a89 358}