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 "AliXMLCollection.h"
41 ClassImp(AliTagAnalysis)
43 TChain *AliTagAnalysis::fgChain = 0;
45 //___________________________________________________________________________
46 AliTagAnalysis::AliTagAnalysis():
52 //Default constructor for a AliTagAnalysis
55 //___________________________________________________________________________
56 AliTagAnalysis::~AliTagAnalysis() {
57 //Default destructor for a AliTagAnalysis
60 //___________________________________________________________________________
61 void AliTagAnalysis::ChainLocalTags(const char *dirname) {
62 //Searches the entries of the provided direcory
63 //Chains the tags that are stored locally
64 fTagDirName = dirname;
67 TChain *fgChain = new TChain("T");
70 const char * tagPattern = "tag.root";
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
75 while((name = gSystem->GetDirEntry(dirp))) {
76 if (strstr(name,tagPattern)) {
77 fTagFilename = fTagDirName;
81 TFile * fTag = TFile::Open(fTagFilename);
82 if((!fTag) || (!fTag->IsOpen())) {
83 AliError(Form("Tag file not opened!!!"));
86 fChain->Add(fTagFilename);
91 AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
95 //___________________________________________________________________________
96 void AliTagAnalysis::ChainGridTags(TGridResult *res) {
97 //Loops overs the entries of the TGridResult
98 //Chains the tags that are stored in the GRID
100 Int_t nEntries = ftagresult->GetEntries();
102 TChain *fgChain = new TChain("T");
105 TString gridname = "alien://";
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);
117 //___________________________________________________________________________
118 TChain *AliTagAnalysis::QueryTags(AliEventTagCuts *EvTagCuts) {
119 //Queries the tag chain using the defined
120 //event tag cuts from the AliEventTagCuts object
121 //and returns a TChain along with the associated TEventList
122 AliInfo(Form("Querying the tags........"));
125 TChain *fESDchain = new TChain("esdTree");
127 TEventList *fEventList = new TEventList();
129 //Defining tag objects
130 AliRunTag *tag = new AliRunTag;
131 AliEventTag *evTag = new AliEventTag;
132 fChain->SetBranchAddress("AliTAG",&tag);
139 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
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);
145 guid = evTag->GetGUID();
146 turl = evTag->GetTURL();
147 path = evTag->GetPath();
148 if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
150 iAccepted += iEvents;
152 if(path != "") fESDchain->AddFile(path);
153 else if(turl != "") fESDchain->AddFile(turl);
155 AliInfo(Form("Accepted events: %d",fEventList->GetN()));
156 fESDchain->SetEventList(fEventList);
161 //___________________________________________________________________________
162 Bool_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........"));
168 AliXMLCollection *collection = new AliXMLCollection();
169 collection->SetCollectionName(name);
170 collection->WriteHeader();
173 TEventList *fEventList = new TEventList();
176 //Defining tag objects
177 AliRunTag *tag = new AliRunTag;
178 AliEventTag *evTag = new AliEventTag;
179 fChain->SetBranchAddress("AliTAG",&tag);
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);
190 collection->WriteBody(iTagFiles+1,guid,fEventList);
193 collection->Export();