]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliTagAnalysis.cxx
Correcting the previous numerical protection.
[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 #include <TFileInfo.h>
28
29 //ROOT-AliEn
30 #include <TGridResult.h>
31
32 #include "AliLog.h"
33
34 #include "AliRunTag.h"
35 #include "AliEventTag.h"
36 #include "AliTagAnalysis.h"
37 #include "AliEventTagCuts.h"
38
39 class TTree;
40
41 ClassImp(AliTagAnalysis)
42
43 TChain *AliTagAnalysis::fgChain = 0;
44
45 //______________________________________________________________________________
46 AliTagAnalysis::AliTagAnalysis(): TObject()//local mode
47 {
48   //==============Default constructor for a AliTagAnalysis==================
49   ftagresult = 0;
50 }
51
52 //______________________________________________________________________________
53 AliTagAnalysis::~AliTagAnalysis()
54 {
55 //================Default destructor for a AliTagAnalysis=======================
56 }
57
58 //______________________________________________________________________________
59 void AliTagAnalysis::ChainLocalTags(const char *dirname) //local version
60 {
61   //Searches the entries of the provided direcory
62   //Chains the tags that are stored locally
63   fTagDirName = dirname;
64   TString fTagFilename;
65   
66   TChain *fgChain = new TChain("T");
67   fChain = fgChain;
68   
69   const char * tagPattern = "tag";
70   // Open the working directory
71   void * dirp = gSystem->OpenDirectory(fTagDirName);
72   const char * name = 0x0;
73   // Add all files matching *pattern* to the chain
74   while((name = gSystem->GetDirEntry(dirp)))
75     {
76       if (strstr(name,tagPattern))
77         { 
78           fTagFilename = fTagDirName;
79           fTagFilename += "/";
80           fTagFilename += name;
81                 
82           TFile * fTag = TFile::Open(fTagFilename);
83           if((!fTag) || (!fTag->IsOpen()))
84             {
85               AliError(Form("Tag file not opened!!!"));
86               continue;
87             } 
88           fChain->Add(fTagFilename);  
89           fTag->Close();
90           delete fTag;
91         }//pattern check
92     }//directory loop
93   AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
94 }
95
96
97 //______________________________________________________________________________
98 void AliTagAnalysis::ChainGridTags(TGridResult *res)
99 {
100   //Loops overs the entries of the TGridResult
101   //Chains the tags that are stored in the GRID
102   ftagresult = res;
103   Int_t nEntries = ftagresult->GetEntries();
104  
105   TChain *fgChain = new TChain("T");
106   fChain = fgChain;
107
108   TString gridname = "alien://";
109   TString alienUrl;
110  
111   for(Int_t i = 0; i < nEntries; i++)
112     {
113       alienUrl = ftagresult->GetKey(i,"turl");
114       TFile *f = TFile::Open(alienUrl,"READ");
115       fChain->Add(alienUrl);
116       //f->Close();
117       delete f;  
118     }//grid result loop  
119 }
120
121
122 //______________________________________________________________________________
123 TChain *AliTagAnalysis::QueryTags(AliEventTagCuts *EvTagCuts)
124 {
125   //Queries the tag chain using the defined 
126   //event tag cuts from the AliEventTagCuts object
127   AliInfo(Form("Querying the tags........"));
128   
129   //ESD file chain
130   TChain *fESDchain = new TChain("esdTree");
131   //Event list
132   TEventList *fEventList = new TEventList();
133   
134   //Defining tag objects
135   AliRunTag *tag = new AliRunTag;
136   AliEventTag *evTag = new AliEventTag;
137   fChain->SetBranchAddress("AliTAG",&tag);
138
139   Long64_t size = -1;
140   const char* md5 = 0;
141   const char* guid = 0;
142   const char* turl = 0;
143
144   Int_t iAccepted = 0;
145   for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
146       fChain->GetEntry(iTagFiles);
147       Int_t iEvents = tag->GetNEvents();
148       const TClonesArray *tagList = tag->GetEventTags();
149       for(Int_t i = 0; i < iEvents; i++) {
150         evTag = (AliEventTag *) tagList->At(i);
151         size = evTag->GetSize();
152         md5 = evTag->GetMD5();
153         guid = evTag->GetGUID(); 
154         turl = evTag->GetTURL(); 
155         if(EvTagCuts->IsAccepted(evTag)) fEventList->Enter(iAccepted+i);
156       }//event loop
157       iAccepted += iEvents;
158
159       fESDchain->Add(turl);
160     }//tag file loop
161   AliInfo(Form("Accepted events: %d",fEventList->GetN()));
162   fESDchain->SetEventList(fEventList);
163    
164   return fESDchain;
165 }
166
167