3 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4 * @date Tue Oct 16 18:57:18 2012
6 * @brief Base class for helpers using the AliAnalysisAlien plugin
8 * @ingroup pwglf_forward_trains_helper
11 #ifndef PLUGINHELPER_C
12 #define PLUGINHELPER_C
15 # include "AvailableSoftware.C"
16 # include "ParUtilities.C"
17 # include "OutputUtilities.C"
22 # include <AliAnalysisManager.h>
23 # include <AliAnalysisAlien.h>
26 class AliAnalysisAlien;
29 // ===================================================================
31 * Handle analysis on using the AliAnalysisAlien plugin - i.e., AAF or Grid
33 * This helper is triggered by a URL of the form
36 * <protocol>://[<user>@][<host>][:<port>]/[<file>][?<options>][#<anchor>]
38 * where <options> contains <tt>plugin</tt>
40 * <dt><options></dt>
41 * <dd>List of options separated by an &
43 * <dt><tt>storage=<url></tt></dt>
44 * <dd>Specify a non-default storage location for special output
45 * (e.g., AOD trees). <url> should be a valid XRootd
46 * server URI accessible to the slaves - e.g.,
47 * <tt>root://lxplus.cern.ch:10930//tmp</tt>.</dd>
48 * <dt><tt>mode=[default,rec,sim,train,custom]</tt></dt>
49 * <dd>Set the AliROOT mode. If not specified <tt>default</tt>
50 * is assumed. See also CreateAliROOTPar</dd>
51 * <dt><tt>par</tt></dt>
52 * <dd>Use par files</dd>
53 * <dt><tt>aliroot=<version></tt></dt>
54 * <dd>Set AliROOT version to use </dd>
55 * <dt><tt>root=<version></tt></dt>
56 * <dd>Set ROOT version to use </dd>
61 * @ingroup pwglf_forward_trains_helper
63 struct PluginHelper : public Helper
69 * @param verbose Verbosity level
71 PluginHelper(const TUrl& url, Int_t verbose)
72 : Helper(url, verbose), fHandler(0), fUsePars(false),
73 fExtraLibs(), fExtraPars(), fExtraSrcs()
75 fHandler = new AliAnalysisAlien();
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");
84 fExtraLibs.SetOwner();
85 fExtraPars.SetOwner();
86 fExtraSrcs.SetOwner();
91 * @param o Object to copy from
93 PluginHelper(const PluginHelper& o)
94 : Helper(o), fHandler(o.fHandler), fUsePars(o.fUsePars),
95 fExtraLibs(), fExtraPars(), fExtraSrcs()
100 * @param o Object to assign from
102 * @return Reference to this
104 PluginHelper& operator=(const PluginHelper& o)
106 if (&o == this) return *this;
107 Helper::operator=(o);
108 fHandler = o.fHandler;
109 fUsePars = o.fUsePars;
115 virtual ~PluginHelper() {}
117 * Load a library/PAR/script
120 * @param slaves If true, also load on slaves
122 * @return true on success
124 virtual Bool_t LoadLibrary(const TString& name,
128 TString fullName(MakeLibraryName(name));
129 Int_t ret = gSystem->Load(fullName);
130 if (ret < 0) return false;
132 fHandler->AddAdditionalLibrary(fullName);
133 fExtraLibs.Add(new TObjString(fullName));
137 if (!ParUtilities::Find(name)) {
138 Error("PluginHelper::LoadLibrary", "Failed to find PAR file %s",
142 if (!ParUtilities::Build(name)) {
143 Error("PluginHelper::LoadLibrary", "Failed to build PAR file %s",
147 fHandler->EnablePackage(name);
148 fExtraPars.Add(new TObjString(name));
153 * Load a source file, and compile it
155 * @param name Name of the source file
156 * @param copy If true, copy here instead of link
158 * @return true on success
160 virtual Bool_t LoadSource(const TString& name, bool copy=false)
163 if (!Helper::LoadSource(name, copy)) return false;
164 s.Append(Form(" %s", gSystem->BaseName(name.Data())));
165 fHandler->SetAnalysisSource(s);
166 fExtraSrcs.Add(new TObjString(name));
171 * Set-up to load the AliROOT libraries
173 * @return true on success
175 virtual Bool_t LoadAliROOT()
177 if (!gSystem->Getenv("ALICE_ROOT")) {
178 Error("PluginHelper::LoadAliROOT", "Local AliROOT not available");
181 Bool_t tmp = fUsePars;
184 if (!LoadLibrary("STEERBase")) return false;
185 if (!LoadLibrary("ESD")) return false;
186 if (!LoadLibrary("AOD")) return false;
187 if (!LoadLibrary("ANALYSIS")) return false;
188 if (!LoadLibrary("OADB")) return false;
189 if (!LoadLibrary("ANALYSISalice")) return false;
195 * Set-up done before task set-ups
197 * @return true on success
199 virtual Bool_t PreSetup()
201 // --- Set prefered GSI method ---------------------------------
202 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
204 TString aliroot("last");
205 TString root("last");
206 if (fOptions.Has("aliroot")) aliroot = fOptions.Get("aliroot");
207 if (fOptions.Has("root")) root = fOptions.Get("root");
209 AvailableSoftware::Check(aliroot, root);
210 fOptions.Set("aliroot", aliroot);
211 fOptions.Set("root", root);
213 fUsePars = fOptions.Has("par");
215 fHandler->SetROOTVersion(root);
216 fHandler->SetAliROOTVersion(aliroot);
217 // Execute through interpreter until patch is applied
218 fHandler->SetDropToShell(false);
219 if (fOptions.Has("mode"))
220 fHandler->SetAliRootMode(fOptions.Get("mode"));
222 fHandler->SetAliRootMode("default");
227 * Set-up done after the task set-ups
229 * @return true on success
231 virtual Bool_t PostSetup()
233 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
235 Error("PluginHelper::PostSetup", "No analysis manager defined");
238 mgr->SetGridHandler(fHandler);
240 fHandler->SetJobTag(mgr->GetName());
241 fHandler->SetAnalysisMacro(Form("%s.C", mgr->GetName()));
243 if (fOptions.Has("storage"))
244 OutputUtilities::RegisterStorage(fOptions.Get("storage"));
249 * Pure virtual overload
253 virtual Long64_t Run(Long64_t) = 0;
255 * Pure virtual overload
257 * @return Short description
259 virtual const char* Desc() const = 0;
261 * Pure virtual overload
263 * @return URI help string
265 virtual const Char_t* UrlHelp() const = 0;
269 * @param option Options
271 virtual void Print(Option_t* option="") const
273 Helper::Print(option);
274 fHandler->Print(option);
276 AliAnalysisAlien* fHandler;