AliPhysics  5a28df1 (5a28df1)
PluginRailway.C
Go to the documentation of this file.
1 
11 #ifndef PLUGINHELPER_C
12 #define PLUGINHELPER_C
13 #include "Railway.C"
14 #ifndef __CINT__
15 # include "AvailableSoftware.C"
16 # include "ParUtilities.C"
17 # include "OutputUtilities.C"
18 # include <TUrl.h>
19 # include <TString.h>
20 # include <TEnv.h>
21 # include <AliAnalysisManager.h>
22 # include <AliAnalysisAlien.h>
23 #else
24 class TUrl;
25 class AliAnalysisAlien;
26 #endif
27 
28 // ===================================================================
62 struct PluginRailway : public Railway
63 {
70  PluginRailway(const TUrl& url, Int_t verbose)
71  : Railway(url, verbose), fHandler(0), fUsePars(false),
73  {
74  fHandler = new AliAnalysisAlien();
75 
76  fOptions.Add("aliphysics", "VERSION", "AliPhysics version", "last");
77  fOptions.Add("aliroot", "VERSION", "AliROOT version", "last");
78  fOptions.Add("root", "VERSION", "ROOT version", "last");
79  fOptions.Add("par", "Use par files");
80  fOptions.Add("mode", "default|rec|sim", "AliROOT mode", "default");
81  fOptions.Add("storage", "URL", "Location for external storage", "");
82  fOptions.Add("plugin", "Use AliEn handler");
83  fOptions.Add("testpar", "Test build PARs");
84 
85  fExtraLibs.SetOwner();
86  fExtraPars.SetOwner();
87  fExtraSrcs.SetOwner();
88  }
97  {}
106  {
107  if (&o == this) return *this;
109  fHandler = o.fHandler;
110  fUsePars = o.fUsePars;
112  return *this;
113  }
117  virtual ~PluginRailway() {}
131  void UsePar(Bool_t& use)
132  {
133  Bool_t tmp = fUsePars;
134  fUsePars = use;
135  use = tmp;
136  }
144  virtual Bool_t AddIncludePath(const TString& path)
145  {
146  Railway::AddIncludePath(path); // Also do on client
147  TString p(path);
148  if (!p.BeginsWith("-")) {
149  // IF the path does not begin with a -, we assume its a path
150  p.Prepend("-I");
151  }
152  fHandler->AddIncludePath(p);
153  return true;
154  }
164  virtual Bool_t LoadLibrary(const TString& name,
165  Bool_t slaves=true,
166  Bool_t forcePar=false)
167  {
168  Info("LoadLibrary", "Loading %s (slaves=%d, forcePar=%d)",
169  name.Data(), slaves, forcePar);
170  if (!fUsePars && !forcePar) {
171  TString fullName(MakeLibraryName(name));
172  Int_t ret = gSystem->Load(fullName);
173  if (ret < 0) return false;
174  if (slaves) {
175  fHandler->AddAdditionalLibrary(fullName);
176  fExtraLibs.Add(new TObjString(fullName));
177  }
178  }
179  else {
180  if (fExtraPars.FindObject(name)) return true;
181  Info("LoadLibrary", "Looking for PAR %s", name.Data());
182  if (!ParUtilities::Find(name)) {
183  Error("PluginRailway::LoadLibrary", "Failed to find PAR file %s",
184  name.Data());
185  return false;
186  }
187  Info("LoadLibrary", "Building PAR %s", name.Data());
188  if (fTestBuild && !ParUtilities::Build(name)) {
189  Error("PluginRailway::LoadLibrary", "Failed to build PAR file %s",
190  name.Data());
191  return false;
192  }
193  fHandler->EnablePackage(name);
194  fExtraPars.Add(new TObjString(name));
195  }
196  return true;
197  }
206  virtual Bool_t LoadSource(const TString& name, bool copy=false)
207  {
208  static TString s;
209  if (!Railway::LoadSource(name, copy)) return false;
210  s.Append(Form(" %s", gSystem->BaseName(name.Data())));
211  fHandler->SetAnalysisSource(s);
212  fExtraSrcs.Add(new TObjString(name));
213  return true;
214  }
215 
221  virtual Bool_t LoadAliROOT()
222  {
223  if (!gSystem->Getenv("ALICE_ROOT")) {
224  Error("PluginRailway::LoadAliROOT", "Local AliROOT not available");
225  return false;
226  }
227  Bool_t tmp = fUsePars;
228  fUsePars = false;
229 
230  if (!LoadLibrary("STEERBase")) return false;
231  if (!LoadLibrary("ESD")) return false;
232  if (!LoadLibrary("AOD")) return false;
233  if (!LoadLibrary("ANALYSIS")) return false;
234  if (!LoadLibrary("ANALYSISalice")) return false;
235  fUsePars = tmp;
236 
237  return true;
238  }
245  {
246  if (!gSystem->Getenv("ALICE_PHYSICS")) {
247  Error("PluginRailway::LoadAliPhysics", "Local AliPhysics not available");
248  return false;
249  }
250  Bool_t tmp = fUsePars;
251  fUsePars = false;
252 
253  // if (!LoadLibrary("OADB")) return false;
254  fUsePars = tmp;
255 
256  return true;
257  }
263  virtual Bool_t PreSetup()
264  {
265  // --- Set prefered GSI method ---------------------------------
266  gEnv->SetValue("XSec.GSI.DelegProxy", "2");
267 
268  TString aliroot("last");
269  TString root("last");
270  TString aliphysics("last");
271  if (fOptions.Has("aliphysics")) aliphysics = fOptions.Get("aliphysics");
272  if (fOptions.Has("aliroot")) aliroot = fOptions.Get("aliroot");
273  if (fOptions.Has("root")) root = fOptions.Get("root");
274 
275  AvailableSoftware::Check(aliphysics, aliroot, root);
276  fOptions.Set("aliphysics", aliphysics);
277  fOptions.Set("aliroot", aliroot);
278  fOptions.Set("root", root);
279 
280  fUsePars = fOptions.Has("par");
281  fTestBuild = fOptions.Has("testpar");
282 
283  // fHandler->SetAPIVersion("V1.1x");
284  fHandler->SetROOTVersion(root);
285  fHandler->SetAliROOTVersion(aliroot);
286  fHandler->SetAliPhysicsVersion(aliphysics);
287  // Add AliPhysics include path
288  fHandler->AddIncludePath("-I.");
289  fHandler->AddIncludePath("-I$ALICE_PHYSICS/include");
290  fHandler->AddIncludePath("-I$ALICE_ROOT/include");
291  // Execute through interpreter until patch is applied
292  fHandler->SetDropToShell(false);
293  if (fOptions.Has("mode"))
294  fHandler->SetAliRootMode(fOptions.Get("mode"));
295  else
296  fHandler->SetAliRootMode("default");
297 
298  return true;
299  }
305  virtual Bool_t PostSetup()
306  {
307  AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
308  if (!mgr) {
309  Error("PluginRailway::PostSetup", "No analysis manager defined");
310  return false;
311  }
312  mgr->SetGridHandler(fHandler);
313 
314  fHandler->SetJobTag(mgr->GetName());
315  fHandler->SetAnalysisMacro(Form("%s.C", mgr->GetName()));
316 
317  if (fOptions.Has("storage"))
319 
320  return true;
321  };
327  virtual Long64_t Run(Long64_t) = 0;
333  virtual const char* Desc() const = 0;
339  virtual const Char_t* UrlHelp() const = 0;
345  virtual void Print(Option_t* option="") const
346  {
347  Railway::Print(option);
348  fHandler->Print(option);
349  }
356 };
357 #endif
358 //
359 // EOF
360 //
virtual Bool_t PreSetup()
OptionList fOptions
Definition: Railway.C:663
const char * url
const TString & MakeLibraryName(const TString &name)
Definition: Railway.C:498
virtual const char * Desc() const =0
long long Long64_t
Definition: External.C:43
virtual Bool_t AddIncludePath(const TString &path)
TSystem * gSystem
virtual const Char_t * UrlHelp() const =0
char Char_t
Definition: External.C:18
virtual void Print(Option_t *="") const
Definition: Railway.C:430
Railway & operator=(const Railway &)
Definition: Railway.C:71
Special output handling.
virtual Long64_t Run(Long64_t)=0
Definition: External.C:92
const TString & Get(const TString &name) const
Definition: Option.C:596
virtual Bool_t LoadAliPhysics()
PluginRailway(const PluginRailway &o)
Definition: PluginRailway.C:94
Bool_t Has(const TString &name) const
Definition: Option.C:584
int Int_t
Definition: External.C:63
static Bool_t Find(const TString &what)
Definition: ParUtilities.C:65
PluginRailway & operator=(const PluginRailway &o)
static Bool_t Check(TString &aliphysics, TString &aliroot, TString &root)
void Set(const TString &name, const TString &value)
Definition: Option.C:736
virtual Bool_t LoadSource(const TString &name, bool copy=false)
virtual Bool_t AddIncludePath(const TString &path)
Definition: Railway.C:201
Option * Add(const TString &name, const TString &arg, const TString &desc, const TString &val="")
Definition: Option.C:421
PAR file utilities.
Find available packages.
virtual void Print(Option_t *option="") const
virtual Bool_t PostSetup()
virtual Bool_t LoadAliROOT()
PluginRailway(const TUrl &url, Int_t verbose)
Definition: PluginRailway.C:70
Base class for analysis helpers.
virtual Bool_t LoadLibrary(const TString &name, Bool_t slaves=true, Bool_t forcePar=false)
virtual ~PluginRailway()
AliAnalysisAlien * fHandler
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
static Bool_t Build(const TString &what)
Definition: ParUtilities.C:130
void UsePar(Bool_t &use)
virtual Bool_t LoadSource(const TString &name, bool copy=false)
Definition: Railway.C:231
static Bool_t RegisterStorage(const TString &url)