]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTagAnalysis.cxx
Example macro for the creation of tags (P.Christakoglou)
[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>
25#include <TFile.h>
26#include <TEventList.h>
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"
37
38class TTree;
39
40ClassImp(AliTagAnalysis)
41
42TChain *AliTagAnalysis::fgChain = 0;
43
44//______________________________________________________________________________
45AliTagAnalysis::AliTagAnalysis(): TObject()//local mode
46{
47 //==============Default constructor for a AliTagAnalysis==================
48 ftagresult = 0;
49}
50
51//______________________________________________________________________________
52AliTagAnalysis::~AliTagAnalysis()
53{
54//================Default destructor for a AliTagAnalysis=======================
55}
56
57//______________________________________________________________________________
58void AliTagAnalysis::ChainLocalTags(const char *dirname) //local version
59{
60 //Searches the entries of the provided direcory
61 //Chains the tags that are stored locally
62 fTagDirName = dirname;
63 TString fTagFilename;
64
65 TChain *fgChain = new TChain("T");
66 fChain = fgChain;
67
68 const char * tagPattern = "tag";
69 // Open the working directory
70 void * dirp = gSystem->OpenDirectory(fTagDirName);
71 const char * name = 0x0;
72 // Add all files matching *pattern* to the chain
73 while((name = gSystem->GetDirEntry(dirp)))
74 {
75 if (strstr(name,tagPattern))
76 {
77 fTagFilename = fTagDirName;
78 fTagFilename += "/";
79 fTagFilename += name;
80
81 TFile * fTag = TFile::Open(fTagFilename);
82 if((!fTag) || (!fTag->IsOpen()))
83 {
84 AliError(Form("Tag file not opened!!!"));
85 continue;
86 }
87 fChain->Add(fTagFilename);
88 fTag->Close();
89 delete fTag;
90 }//pattern check
91 }//directory loop
92 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
93}
94
95
96//______________________________________________________________________________
97void AliTagAnalysis::ChainGridTags(TGridResult *res)
98{
99 //Loops overs the entries of the TGridResult
100 //Chains the tags that are stored in the GRID
101 ftagresult = res;
102 Int_t nEntries = ftagresult->GetEntries();
103
104 TChain *fgChain = new TChain("T");
105 fChain = fgChain;
106
107 TString gridname = "alien://";
108 TString alienUrl;
109
110 for(Int_t i = 0; i < nEntries; i++)
111 {
112 alienUrl = ftagresult->GetKey(i,"turl");
113 TFile *f = TFile::Open(alienUrl,"READ");
114 fChain->Add(alienUrl);
115 //f->Close();
116 delete f;
117 }//grid result loop
118}
119
120
121//______________________________________________________________________________
122TList *AliTagAnalysis::QueryTags(AliEventTagCuts *EvTagCuts)
123{
124 //Queries the tag chain using the defined
125 //event tag cuts from the AliEventTagCuts object
126 AliInfo(Form("Querying the tags........"));
127
128 //file info list
129 TList *list = new TList();
130
131 Int_t iAccepted = 0, evCounter = 0;
132
133 //Defining tag objects
134 AliRunTag *tag = new AliRunTag;
135 AliEventTag *evTag = new AliEventTag;
136 fChain->SetBranchAddress("AliTAG",&tag);
137
138 Long64_t size = -1;
139 const char* md5 = 0;
140 const char* guid = 0;
141 const char* turl = 0;
142
143 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++)
144 {
145 TEventList *fEventList = new TEventList();
146 evCounter = 0;
147 fChain->GetEntry(iTagFiles);
148 Int_t iEvents = tag->GetNEvents();
149 const TClonesArray *tagList = tag->GetEventTags();
150 for(Int_t i = 0; i < iEvents; i++)
151 {
152 evTag = (AliEventTag *) tagList->At(i);
153 size = evTag->GetSize();
154 md5 = evTag->GetMD5();
155 guid = evTag->GetGUID();
156 turl = evTag->GetTURL();
157 if(EvTagCuts->IsAccepted(evTag))
158 {
159 fEventList->Enter(i);
160 evCounter++;
161
162 iAccepted++;
163 }
164 }//event loop
165
166 //adding a TFileInfo object to the list
167 if(evCounter != 0)
168 list->Add(new TFileInfo(turl,size,guid,md5,-1,-1,-1,fEventList));
169 fEventList->Clear("");
170 delete fEventList;
171 }//tag file loop
172 AliInfo(Form("Accepted events: %d",iAccepted));
173
174 return list;
175}
176
177