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>
29 #include <TGridResult.h>
33 #include "AliRunTag.h"
34 #include "AliEventTag.h"
35 #include "AliTagAnalysis.h"
36 #include "AliEventTagCuts.h"
37 #include "AliRunTagCuts.h"
38 #include "AliXMLCollection.h"
42 ClassImp(AliTagAnalysis)
44 TChain *AliTagAnalysis::fgChain = 0;
46 //___________________________________________________________________________
47 AliTagAnalysis::AliTagAnalysis():
53 //Default constructor for a AliTagAnalysis
56 //___________________________________________________________________________
57 AliTagAnalysis::~AliTagAnalysis() {
58 //Default destructor for a AliTagAnalysis
61 //___________________________________________________________________________
62 void AliTagAnalysis::ChainLocalTags(const char *dirname) {
63 //Searches the entries of the provided direcory
64 //Chains the tags that are stored locally
65 fTagDirName = dirname;
68 TChain *fgChain = new TChain("T");
71 const char * tagPattern = "tag.root";
72 // Open the working directory
73 void * dirp = gSystem->OpenDirectory(fTagDirName);
74 const char * name = 0x0;
75 // Add all files matching *pattern* to the chain
76 while((name = gSystem->GetDirEntry(dirp))) {
77 if (strstr(name,tagPattern)) {
78 fTagFilename = fTagDirName;
82 fChain->Add(fTagFilename);
85 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
89 //___________________________________________________________________________
90 void AliTagAnalysis::ChainGridTags(TGridResult *res) {
91 //Loops overs the entries of the TGridResult
92 //Chains the tags that are stored in the GRID
94 Int_t nEntries = ftagresult->GetEntries();
96 TChain *fgChain = new TChain("T");
99 TString gridname = "alien://";
102 for(Int_t i = 0; i < nEntries; i++) {
103 alienUrl = ftagresult->GetKey(i,"turl");
104 fChain->Add(alienUrl);
109 //___________________________________________________________________________
110 TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
111 //Queries the tag chain using the defined
112 //event tag cuts from the AliEventTagCuts object
113 //and returns a TChain along with the associated TEventList
114 AliInfo(Form("Querying the tags........"));
117 TChain *fESDchain = new TChain("esdTree");
119 TEventList *fEventList = new TEventList();
121 //Defining tag objects
122 AliRunTag *tag = new AliRunTag;
123 AliEventTag *evTag = new AliEventTag;
124 fChain->SetBranchAddress("AliTAG",&tag);
131 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
132 fChain->GetEntry(iTagFiles);
133 if(RunTagCuts->IsAccepted(tag)) {
134 Int_t iEvents = tag->GetNEvents();
135 const TClonesArray *tagList = tag->GetEventTags();
136 for(Int_t i = 0; i < iEvents; i++) {
137 evTag = (AliEventTag *) tagList->At(i);
138 guid = evTag->GetGUID();
139 turl = evTag->GetTURL();
140 path = evTag->GetPath();
141 if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
143 iAccepted += iEvents;
145 if(path != "") fESDchain->AddFile(path);
146 else if(turl != "") fESDchain->AddFile(turl);
149 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
150 fESDchain->SetEventList(fEventList);
155 //___________________________________________________________________________
156 Bool_t AliTagAnalysis::CreateXMLCollection(const char* name, AliRunTagCuts *RunTagCuts, AliEventTagCuts *EvTagCuts) {
157 //Queries the tag chain using the defined
158 //event tag cuts from the AliEventTagCuts object
159 //and returns a XML collection
160 AliInfo(Form("Creating the collection........"));
162 AliXMLCollection *collection = new AliXMLCollection();
163 collection->SetCollectionName(name);
164 collection->WriteHeader();
167 TEventList *fEventList = new TEventList();
171 //Defining tag objects
172 AliRunTag *tag = new AliRunTag;
173 AliEventTag *evTag = new AliEventTag;
174 fChain->SetBranchAddress("AliTAG",&tag);
176 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
177 fChain->GetEntry(iTagFiles);
178 if(RunTagCuts->IsAccepted(tag)) {
179 Int_t iEvents = tag->GetNEvents();
180 const TClonesArray *tagList = tag->GetEventTags();
181 for(Int_t i = 0; i < iEvents; i++) {
182 evTag = (AliEventTag *) tagList->At(i);
183 guid = evTag->GetGUID();
184 turl = evTag->GetTURL();
185 if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(i);
187 collection->WriteBody(iTagFiles+1,guid,turl,fEventList);
191 collection->Export();