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>
30 #include <TGridResult.h>
34 #include "AliRunTag.h"
35 #include "AliEventTag.h"
36 #include "AliTagAnalysis.h"
37 #include "AliEventTagCuts.h"
38 #include "AliRunTagCuts.h"
39 #include "AliXMLCollection.h"
43 ClassImp(AliTagAnalysis)
45 TChain *AliTagAnalysis::fgChain = 0;
47 //___________________________________________________________________________
48 AliTagAnalysis::AliTagAnalysis():
54 //Default constructor for a AliTagAnalysis
57 //___________________________________________________________________________
58 AliTagAnalysis::~AliTagAnalysis() {
59 //Default destructor for a AliTagAnalysis
62 //___________________________________________________________________________
63 void AliTagAnalysis::ChainLocalTags(const char *dirname) {
64 //Searches the entries of the provided direcory
65 //Chains the tags that are stored locally
66 fTagDirName = dirname;
69 TChain *fgChain = new TChain("T");
72 const char * tagPattern = "tag.root";
73 // Open the working directory
74 void * dirp = gSystem->OpenDirectory(fTagDirName);
75 const char * name = 0x0;
76 // Add all files matching *pattern* to the chain
77 while((name = gSystem->GetDirEntry(dirp))) {
78 if (strstr(name,tagPattern)) {
79 fTagFilename = fTagDirName;
83 fChain->Add(fTagFilename);
86 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
90 //___________________________________________________________________________
91 void AliTagAnalysis::ChainGridTags(TGridResult *res) {
92 //Loops overs the entries of the TGridResult
93 //Chains the tags that are stored in the GRID
95 Int_t nEntries = ftagresult->GetEntries();
97 TChain *fgChain = new TChain("T");
100 TString gridname = "alien://";
103 for(Int_t i = 0; i < nEntries; i++) {
104 alienUrl = ftagresult->GetKey(i,"turl");
105 fChain->Add(alienUrl);
110 //___________________________________________________________________________
111 TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
112 //Queries the tag chain using the defined
113 //event tag cuts from the AliEventTagCuts object
114 //and returns a TChain along with the associated TEventList
115 AliInfo(Form("Querying the tags........"));
118 TChain *fESDchain = new TChain("esdTree");
120 TEventList *fEventList = new TEventList();
122 //Defining tag objects
123 AliRunTag *tag = new AliRunTag;
124 AliEventTag *evTag = new AliEventTag;
125 fChain->SetBranchAddress("AliTAG",&tag);
132 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
133 fChain->GetEntry(iTagFiles);
134 if(RunTagCuts->IsAccepted(tag)) {
135 Int_t iEvents = tag->GetNEvents();
136 const TClonesArray *tagList = tag->GetEventTags();
137 for(Int_t i = 0; i < iEvents; i++) {
138 evTag = (AliEventTag *) tagList->At(i);
139 guid = evTag->GetGUID();
140 turl = evTag->GetTURL();
141 path = evTag->GetPath();
142 if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
144 iAccepted += iEvents;
146 if(path != "") fESDchain->AddFile(path);
147 else if(turl != "") fESDchain->AddFile(turl);
150 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
151 fESDchain->SetEventList(fEventList);
156 //___________________________________________________________________________
157 Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
158 //Queries the tag chain using the defined
159 //event tag cuts from the AliEventTagCuts object
160 //and returns a XML collection
161 AliInfo(Form("Creating the collection........"));
163 AliXMLCollection *collection = new AliXMLCollection();
164 collection->SetCollectionName(name);
165 collection->WriteHeader();
168 TEventList *fEventList = new TEventList();
173 //Defining tag objects
174 AliRunTag *tag = new AliRunTag;
175 AliEventTag *evTag = new AliEventTag;
176 fChain->SetBranchAddress("AliTAG",&tag);
178 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
179 fChain->GetEntry(iTagFiles);
180 if(RunTagCuts->IsAccepted(tag)) {
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 turl = evTag->GetTURL();
187 lfn = turl(8,turl.Length());
189 if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(i);
191 collection->WriteBody(iTagFiles+1,guid,lfn,turl,fEventList);
195 collection->Export();
200 //___________________________________________________________________________
201 TChain *AliTagAnalysis::GetInputChain(const char* system, const char*global, const char *wn) {
202 //returns the chain+event list - used in batch sessions
203 TString fsystem = system;
206 TChain *fESDchain = new TChain("esdTree");
208 TEventList *fEventList = new TEventList();
209 AliXMLCollection *collection1 = AliXMLCollection::Open(global);
210 AliXMLCollection *collection2 = AliXMLCollection::Open(wn);
211 collection1->OverlapCollection(collection2);
212 collection1->Reset();
213 while (collection1->Next()) {
214 AliInfo(Form("Adding: %s",collection1->GetTURL("")));
215 fESDchain->Add(collection1->GetTURL(""));
216 TEntryList *list = (TEntryList *)collection1->GetEventList("");
217 for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i));
219 if(fsystem == "pp") iAccepted += 100;
220 else if(fsystem == "PbPb") iAccepted += 1;
223 fESDchain->SetEventList(fEventList);
225 AliInfo(Form("Number of selected events: %d",fEventList->GetN()));