AliPhysics  1811c8f (1811c8f)
ProofTerminate.C
Go to the documentation of this file.
1 
11 #ifndef __CINT__
12 # include <TString.h>
13 # include <TSystem.h>
14 # include <TFile.h>
15 # include <TObjArray.h>
16 # include <TObjString.h>
17 # include <TError.h>
18 # include <TEnv.h>
19 # include <TROOT.h>
20 # include <AliAnalysisManager.h>
21 # include <TKey.h>
22 # include <fstream>
23 # include "ParUtilities.C"
24 #else
25 class TString;
26 class AliAnalysisManager;
27 #endif
28 
35 Bool_t LoadLib(const char* libName)
36 {
37  if (gSystem->Load(libName) < 0) {
38  Error("ProofTerminate", "Failed to load library %s",libName);
39  return false;
40  }
41  Info("ProofTerminate","Loaded library %s",libName);
42  return true;
43 }
51 Bool_t LoadPar(const char* parName)
52 {
53  if (!ParUtilities::Build(parName)) {
54  Error("ProofTerminate","Failed to load PAR %s",parName);
55  return false;
56  }
57  Info("ProofTerminate","Loaded package %s",parName);
58  return true;
59 }
60 
61 //______________________________________________________________________________
63 {
64  // Loat the analysis manager from a file.
65  TFile *file = TFile::Open(fname);
66  if (!file) {
67  ::Error("LoadAnalysisManager", "Cannot open file %s", fname);
68  return 0;
69  }
70  TIter nextkey(file->GetListOfKeys());
71  AliAnalysisManager *mgr = 0;
72  TKey *key;
73  while ((key=(TKey*)nextkey())) {
74  if (!strcmp(key->GetClassName(), "AliAnalysisManager"))
75  mgr = (AliAnalysisManager*)file->Get(key->GetName());
76  }
77  if (!mgr)
78  ::Error("LoadAnalysisManager",
79  "No analysis manager found in file %s", fname);
80  file->ls();
81  return mgr;
82 }
83 
97 Bool_t Setup(const TString& name,
98  const TString& libs,
99  const TString& pars,
100  const TString& srcs,
101  Bool_t localLibsNotPar=true)
102 {
103  // Load basic ROOT libraries
104  gSystem->AddDynamicPath("/usr/lib");
105  if (gSystem->Load("libTree") < 0) return false;
106  if (gSystem->Load("libGeom") < 0) return false;
107  if (gSystem->Load("libVMC") < 0) return false;
108  if (gSystem->Load("libPhysics") < 0) return false;
109  if (gSystem->Load("libMinuit") < 0) return false;
110 
111  // Load basic AliROOT libraries
112  if (gSystem->Load("libSTEERBase") < 0) return false;
113  if (gSystem->Load("libESD") < 0) return false;
114  if (gSystem->Load("libAOD") < 0) return false;
115  if (gSystem->Load("libANALYSIS") < 0) return false;
116  if (gSystem->Load("libOADB") < 0) return false;
117  if (gSystem->Load("libANALYSISalice") < 0) return false;
118 
119  // Load libraries
120  if (!libs.IsNull()) {
121  TObjArray* libsArray = libs.Tokenize(" ");
122  TObjString* lib = 0;
123  TIter nextLib(libsArray);
124  while ((lib = static_cast<TObjString*>(nextLib()))) {
125  const TString& libName = lib->String();
126  if (libName.Contains("libSTEERBase") ||
127  libName.Contains("libESD") ||
128  libName.Contains("libAOD") ||
129  libName.Contains("libANALYSIS") ||
130  libName.Contains("libOADB") ||
131  libName.Contains("libANALYSISalice")) continue;
132  if (!libName.Contains(".so")) continue;
133  if (!LoadLib(libName.Data())) return false;
134  }
135  libsArray->Delete();
136  }
137 
138  // Load packages
139  if (!pars.IsNull()) {
140  TObjArray* parArray = pars.Tokenize(" ");
141  TObjString* par = 0;
142  TIter nextPar(parArray);
143  while ((par = static_cast<TObjString*>(nextPar()))) {
144  TString parName(par->String());
145  if (parName.EndsWith(".par")) parName.ReplaceAll(".par", "");
146  if (parName.EqualTo("STEERBase") ||
147  parName.EqualTo("ESD") ||
148  parName.EqualTo("AOD") ||
149  parName.EqualTo("ANALYSIS") ||
150  parName.EqualTo("OADB") ||
151  parName.EqualTo("ANALYSISalice")) continue;
152  Bool_t ret = false;
153  TString asLib = Form("lib%s.so", parName.Data());
154  if (localLibsNotPar) ret = LoadLib(asLib.Data());
155  if (!ret) ret = LoadPar(parName.Data());
156  if (!ret) return false;
157  }
158  }
159 
160  // Load sources
161  if (!srcs.IsNull()) {
162  TObjArray* srcArray = srcs.Tokenize(" ");
163  TObjString* src = 0;
164  TIter nextSrc(srcArray);
165  while ((src = static_cast<TObjString*>(nextSrc()))) {
166  const TString& srcName = src->String();
167  gROOT->ProcessLine(Form(".L %s+g", srcName.Data()));
168  }
169  }
170 
171  // Load the analysis manager from file
172  TString base(name);
173  base.Append(".root");
174  if (gSystem->AccessPathName(base.Data())) {
175  // Couldn't read from current directory, try sub-dir
176  TString sub(gSystem->ConcatFileName(name, base));
177  if (gSystem->AccessPathName(sub)) {
178  Error("ProofTerminate","Couldn't find manager file %s",base.Data());
179  return false;
180  }
181  base = sub;
182  }
184  if (!mgr) {
185  Error("ProofTerminate", "Failed to load manager from %s",base.Data());
186  return false;
187  }
188  if (!name.EqualTo(mgr->GetName())) {
189  Error("ProofTerminate","Read manager %s is not %s",
190  mgr->GetName(),name.Data());
191  return false;
192  }
193  Info("ProofTerminate","Loaded analysis manager");
194 
195  // If we do a local merge, do not do any else
196  return true;
197 }
198 
213  const TString& libs,
214  const TString& pars,
215  const TString& srcs,
216  Bool_t localLibsNotPar=true)
217 {
218  if (!Setup(name, libs, pars, srcs, localLibsNotPar)) return false;
219 
220  // Run the terminate job
221  Info("ProofTerminate","Starting terminate job locally");
222 
223 
224  AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
225  mgr->SetSkipTerminate(false);
226  TTree* dummy = 0;
227  if (mgr->StartAnalysis("gridterminate", dummy, -1, 0) < 0) return false;
228 
229  return true;
230 }
231 
232 //
233 // EOF
234 //
235 
TSystem * gSystem
Bool_t LoadLib(const char *libName)
Bool_t LoadPar(const char *parName)
Bool_t ProofTerminate(const TString &name, const TString &libs, const TString &pars, const TString &srcs, Bool_t localLibsNotPar=true)
PAR file utilities.
Bool_t Setup(const TString &name, const TString &libs, const TString &pars, const TString &srcs, Bool_t localLibsNotPar=true)
TFile * file
TList with histograms for a given trigger.
bool Bool_t
Definition: External.C:53
AliAnalysisManager * LoadAnalysisManager(const char *fname)
static Bool_t Build(const TString &what)
Definition: ParUtilities.C:130