]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTagAnalysis.cxx
Parameters of miscalibration in the head of the file (Marian)
[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"
b6003316 37#include "AliXMLCollection.h"
c7e89ea3 38
39class TTree;
40
41ClassImp(AliTagAnalysis)
42
43TChain *AliTagAnalysis::fgChain = 0;
44
54ac820d 45//___________________________________________________________________________
46AliTagAnalysis::AliTagAnalysis():
47 TObject(),
fe12e09c 48 ftagresult(0x0),
49 fTagDirName(),
50 fChain(0x0)
c7e89ea3 51{
54ac820d 52 //Default constructor for a AliTagAnalysis
c7e89ea3 53}
54
54ac820d 55//___________________________________________________________________________
56AliTagAnalysis::~AliTagAnalysis() {
57//Default destructor for a AliTagAnalysis
c7e89ea3 58}
59
54ac820d 60//___________________________________________________________________________
61void AliTagAnalysis::ChainLocalTags(const char *dirname) {
c7e89ea3 62 //Searches the entries of the provided direcory
63 //Chains the tags that are stored locally
64 fTagDirName = dirname;
65 TString fTagFilename;
66
67 TChain *fgChain = new TChain("T");
68 fChain = fgChain;
69
f2313c5b 70 const char * tagPattern = "tag.root";
c7e89ea3 71 // Open the working directory
72 void * dirp = gSystem->OpenDirectory(fTagDirName);
73 const char * name = 0x0;
74 // Add all files matching *pattern* to the chain
54ac820d 75 while((name = gSystem->GetDirEntry(dirp))) {
76 if (strstr(name,tagPattern)) {
77 fTagFilename = fTagDirName;
78 fTagFilename += "/";
79 fTagFilename += name;
c7e89ea3 80
54ac820d 81 TFile * fTag = TFile::Open(fTagFilename);
82 if((!fTag) || (!fTag->IsOpen())) {
83 AliError(Form("Tag file not opened!!!"));
84 continue;
85 }
86 fChain->Add(fTagFilename);
87 fTag->Close();
88 delete fTag;
89 }//pattern check
90 }//directory loop
c7e89ea3 91 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
92}
93
94
54ac820d 95//___________________________________________________________________________
96void AliTagAnalysis::ChainGridTags(TGridResult *res) {
c7e89ea3 97 //Loops overs the entries of the TGridResult
98 //Chains the tags that are stored in the GRID
99 ftagresult = res;
100 Int_t nEntries = ftagresult->GetEntries();
101
102 TChain *fgChain = new TChain("T");
103 fChain = fgChain;
104
105 TString gridname = "alien://";
106 TString alienUrl;
107
54ac820d 108 for(Int_t i = 0; i < nEntries; i++) {
109 alienUrl = ftagresult->GetKey(i,"turl");
110 TFile *f = TFile::Open(alienUrl,"READ");
111 fChain->Add(alienUrl);
112 delete f;
113 }//grid result loop
c7e89ea3 114}
115
116
54ac820d 117//___________________________________________________________________________
118TChain *AliTagAnalysis::QueryTags(AliEventTagCuts *EvTagCuts) {
c7e89ea3 119 //Queries the tag chain using the defined
120 //event tag cuts from the AliEventTagCuts object
b6003316 121 //and returns a TChain along with the associated TEventList
c7e89ea3 122 AliInfo(Form("Querying the tags........"));
123
df16faa3 124 //ESD file chain
125 TChain *fESDchain = new TChain("esdTree");
126 //Event list
127 TEventList *fEventList = new TEventList();
c7e89ea3 128
129 //Defining tag objects
130 AliRunTag *tag = new AliRunTag;
131 AliEventTag *evTag = new AliEventTag;
132 fChain->SetBranchAddress("AliTAG",&tag);
133
d021d0d7 134 TString guid = 0;
135 TString turl = 0;
136 TString path = 0;
c7e89ea3 137
df16faa3 138 Int_t iAccepted = 0;
139 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
54ac820d 140 fChain->GetEntry(iTagFiles);
141 Int_t iEvents = tag->GetNEvents();
142 const TClonesArray *tagList = tag->GetEventTags();
143 for(Int_t i = 0; i < iEvents; i++) {
144 evTag = (AliEventTag *) tagList->At(i);
54ac820d 145 guid = evTag->GetGUID();
146 turl = evTag->GetTURL();
147 path = evTag->GetPath();
148 if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
149 }//event loop
150 iAccepted += iEvents;
d021d0d7 151
152 if(path != "") fESDchain->AddFile(path);
153 else if(turl != "") fESDchain->AddFile(turl);
54ac820d 154 }//tag file loop
df16faa3 155 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
156 fESDchain->SetEventList(fEventList);
c7e89ea3 157
df16faa3 158 return fESDchain;
c7e89ea3 159}
160
b6003316 161//___________________________________________________________________________
162Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliEventTagCuts *EvTagCuts) {
163 //Queries the tag chain using the defined
164 //event tag cuts from the AliEventTagCuts object
165 //and returns a XML collection
166 AliInfo(Form("Creating the collection........"));
167
168 AliXMLCollection *collection = new AliXMLCollection();
169 collection->SetCollectionName(name);
170 collection->WriteHeader();
171
172 //Event list
173 TEventList *fEventList = new TEventList();
174 TString guid = 0x0;
175
176 //Defining tag objects
177 AliRunTag *tag = new AliRunTag;
178 AliEventTag *evTag = new AliEventTag;
179 fChain->SetBranchAddress("AliTAG",&tag);
180
181 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
182 fChain->GetEntry(iTagFiles);
183 Int_t iEvents = tag->GetNEvents();
184 const TClonesArray *tagList = tag->GetEventTags();
185 for(Int_t i = 0; i < iEvents; i++) {
186 evTag = (AliEventTag *) tagList->At(i);
187 guid = evTag->GetGUID();
188 if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(i);
189 }//event loop
190 collection->WriteBody(iTagFiles+1,guid,fEventList);
191 fEventList->Clear();
192 }//tag file loop
193 collection->Export();
194
195 return kTRUE;
196}
c7e89ea3 197