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