]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliTagAnalysis.cxx
Writing the ESDfriends to a separate branch of the ESD tree.
[u/mrichter/AliRoot.git] / STEER / AliTagAnalysis.cxx
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"
37 #include "AliRunTagCuts.h"
38 #include "AliXMLCollection.h"
39
40 class TTree;
41
42 ClassImp(AliTagAnalysis)
43
44 TChain *AliTagAnalysis::fgChain = 0;
45
46 //___________________________________________________________________________
47 AliTagAnalysis::AliTagAnalysis(): 
48   TObject(),
49   ftagresult(0x0),
50   fTagDirName(),
51   fChain(0x0)
52 {
53   //Default constructor for a AliTagAnalysis
54 }
55
56 //___________________________________________________________________________
57 AliTagAnalysis::~AliTagAnalysis() {
58 //Default destructor for a AliTagAnalysis
59 }
60
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;
66   TString fTagFilename;
67   
68   TChain *fgChain = new TChain("T");
69   fChain = fgChain;
70   
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;
79       fTagFilename += "/";
80       fTagFilename += name;
81                 
82       fChain->Add(fTagFilename);  
83     }//pattern check
84   }//directory loop
85   AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
86 }
87
88
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
93   ftagresult = res;
94   Int_t nEntries = ftagresult->GetEntries();
95  
96   TChain *fgChain = new TChain("T");
97   fChain = fgChain;
98
99   TString gridname = "alien://";
100   TString alienUrl;
101  
102   for(Int_t i = 0; i < nEntries; i++) {
103     alienUrl = ftagresult->GetKey(i,"turl");
104     fChain->Add(alienUrl);
105   }//grid result loop  
106 }
107
108
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........"));
115   
116   //ESD file chain
117   TChain *fESDchain = new TChain("esdTree");
118   //Event list
119   TEventList *fEventList = new TEventList();
120   
121   //Defining tag objects
122   AliRunTag *tag = new AliRunTag;
123   AliEventTag *evTag = new AliEventTag;
124   fChain->SetBranchAddress("AliTAG",&tag);
125
126   TString guid = 0;
127   TString turl = 0;
128   TString path = 0;
129
130   Int_t iAccepted = 0;
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);
142       }//event loop
143       iAccepted += iEvents;
144     
145       if(path != "") fESDchain->AddFile(path);
146       else if(turl != "") fESDchain->AddFile(turl);
147     }//run tags cut
148   }//tag file loop
149   AliInfo(Form("Accepted events: %d",fEventList->GetN()));
150   fESDchain->SetEventList(fEventList);
151    
152   return fESDchain;
153 }
154
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........"));
161
162   AliXMLCollection *collection = new AliXMLCollection();
163   collection->SetCollectionName(name);
164   collection->WriteHeader();
165
166   //Event list
167   TEventList *fEventList = new TEventList();
168   TString guid = 0x0;
169   TString turl = 0x0;
170   
171   //Defining tag objects
172   AliRunTag *tag = new AliRunTag;
173   AliEventTag *evTag = new AliEventTag;
174   fChain->SetBranchAddress("AliTAG",&tag);
175
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);
186       }//event loop
187       collection->WriteBody(iTagFiles+1,guid,turl,fEventList);
188       fEventList->Clear();
189     }//run tag cuts
190   }//tag file loop
191   collection->Export();
192
193   return kTRUE;
194 }
195