1 /**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //-----------------------------------------------------------------
26 #include <TEventList.h>
27 #include <TEntryList.h>
28 #include <TTreeFormula.h>
31 #include <TGridResult.h>
35 #include "AliRunTag.h"
36 #include "AliEventTag.h"
37 #include "AliTagAnalysis.h"
38 #include "AliEventTagCuts.h"
39 #include "AliRunTagCuts.h"
40 #include "AliXMLCollection.h"
44 ClassImp(AliTagAnalysis)
46 TChain *AliTagAnalysis::fgChain = 0;
48 //___________________________________________________________________________
49 AliTagAnalysis::AliTagAnalysis():
55 //Default constructor for a AliTagAnalysis
58 //___________________________________________________________________________
59 AliTagAnalysis::~AliTagAnalysis() {
60 //Default destructor for a AliTagAnalysis
63 //___________________________________________________________________________
64 Bool_t AliTagAnalysis::AddTagsFile(const char *alienUrl) {
66 // Add a single tags file to the chain
70 if (! fgChain || ! fChain ) {
71 TChain *fgChain = new TChain("T");
75 TFile *f = TFile::Open(alienUrl,"READ");
76 fChain->Add(alienUrl);
77 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
80 if (fChain->GetEntries() == 0 )
86 //___________________________________________________________________________
87 void AliTagAnalysis::ChainLocalTags(const char *dirname) {
88 //Searches the entries of the provided direcory
89 //Chains the tags that are stored locally
90 fTagDirName = dirname;
93 TChain *fgChain = new TChain("T");
96 const char * tagPattern = "tag.root";
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
101 while((name = gSystem->GetDirEntry(dirp))) {
102 if (strstr(name,tagPattern)) {
103 fTagFilename = fTagDirName;
105 fTagFilename += name;
107 fChain->Add(fTagFilename);
110 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
114 //___________________________________________________________________________
115 void AliTagAnalysis::ChainGridTags(TGridResult *res) {
116 //Loops overs the entries of the TGridResult
117 //Chains the tags that are stored in the GRID
119 Int_t nEntries = ftagresult->GetEntries();
121 TChain *fgChain = new TChain("T");
124 TString gridname = "alien://";
127 for(Int_t i = 0; i < nEntries; i++) {
128 alienUrl = ftagresult->GetKey(i,"turl");
129 fChain->Add(alienUrl);
134 //___________________________________________________________________________
135 TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
136 //Queries the tag chain using the defined
137 //event tag cuts from the AliEventTagCuts object
138 //and returns a TChain along with the associated TEventList
139 AliInfo(Form("Querying the tags........"));
142 TChain *fESDchain = new TChain("esdTree");
144 TEventList *fEventList = new TEventList();
146 //Defining tag objects
147 AliRunTag *tag = new AliRunTag;
148 AliEventTag *evTag = new AliEventTag;
149 fChain->SetBranchAddress("AliTAG",&tag);
156 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
157 fChain->GetEntry(iTagFiles);
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);
168 iAccepted += iEvents;
170 if(path != "") fESDchain->AddFile(path);
171 else if(turl != "") fESDchain->AddFile(turl);
174 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
175 fESDchain->SetEventList(fEventList);
180 //___________________________________________________________________________
181 TChain *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........"));
188 TChain *fESDchain = new TChain("esdTree");
190 TEventList *fEventList = new TEventList();
192 //Defining tag objects
193 AliRunTag *tag = new AliRunTag;
194 AliEventTag *evTag = new AliEventTag;
195 fChain->SetBranchAddress("AliTAG",&tag);
201 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
202 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
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();
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);
223 iAccepted += iEvents;
225 if(path != "") fESDchain->AddFile(path);
226 else if(turl != "") fESDchain->AddFile(turl);
229 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
230 fESDchain->SetEventList(fEventList);
235 //___________________________________________________________________________
236 Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
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........"));
242 AliXMLCollection *collection = new AliXMLCollection();
243 collection->SetCollectionName(name);
244 collection->WriteHeader();
247 //TEntryList *fEventList = new TEntryList();
252 //Defining tag objects
253 AliRunTag *tag = new AliRunTag;
254 AliEventTag *evTag = new AliEventTag;
255 fChain->SetBranchAddress("AliTAG",&tag);
257 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
259 TEntryList *fList = new TEntryList();
260 fChain->GetEntry(iTagFiles);
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();
268 lfn = turl(8,turl.Length());
269 if(EvTagCuts->IsAccepted(evTag)) fList->Enter(i);
271 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
274 collection->Export();
279 //___________________________________________________________________________
280 Bool_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........"));
286 AliXMLCollection *collection = new AliXMLCollection();
287 collection->SetCollectionName(name);
288 collection->WriteHeader();
294 //Defining tag objects
295 AliRunTag *tag = new AliRunTag;
296 AliEventTag *evTag = new AliEventTag;
297 fChain->SetBranchAddress("AliTAG",&tag);
299 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
300 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
303 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
305 TEntryList *fList = new TEntryList();
306 fChain->GetEntry(iTagFiles);
307 if (current != fChain->GetTreeNumber()) {
308 fRunFormula->UpdateFormulaLeaves();
309 fEventFormula->UpdateFormulaLeaves();
310 current = fChain->GetTreeNumber();
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);
322 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fList);
325 collection->Export();
330 //___________________________________________________________________________
331 TChain *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;
336 TChain *fESDchain = new TChain("esdTree");
338 TEventList *fEventList = new TEventList();
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));
349 if(fsystem == "pp") iAccepted += 100;
350 else if(fsystem == "PbPb") iAccepted += 1;
353 fESDchain->SetEventList(fEventList);
355 AliInfo(Form("Number of selected events: %d",fEventList->GetN()));