2 * @file AAFPluginRailway.C
3 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4 * @date Tue Oct 16 19:01:45 2012
6 * @brief AAF (using AliAnalysisAlien) analysis helper
8 * @ingroup pwglf_forward_trains_helper
11 #ifndef AAFPLUGINHELPER_C
12 #define AAFPLUGINHELPER_C
13 #include "PluginRailway.C"
17 # include <AliAnalysisManager.h>
18 # include <AliAnalysisAlien.h>
21 class AliAnalysisAlien;
24 // ===================================================================
26 * Handle analysis on an Alice Analysis Facility (AAF)
28 * This helper is triggered by a URL of the form
31 * proof://[<user>@]<host>[:<port>]/<dsname>[?<options>][#<treename>]
33 * where <host> is a known AAF (e.g., <tt>alice-caf.cern.ch</tt>),
34 * and the <options> contains <tt>plugin</tt>
36 * <dt><user></dt>
37 * <dd>Optional user name</dd>
38 * <dt><host></dt>
39 * <dd>PROOF cluster master host</dd>
40 * <dt><port></dt>
41 * <dd>Optional PROOF cluster port on master host</dd>
42 * <dt><dsname></dt>
43 * <dd>Data set name</dd>
44 * <dt><treename></dt>
45 * <dd>Optional tree name in data set, often <tt>esdTree</tt> or
46 * <tt>aodTree</tt></dd>
47 * <dt><options></dt>
48 * <dd>List of options separated by an &
50 * <dt><tt>dsname</tt>[=<output dataset>]</dt>
51 * <dd>Register tree output (e.g., AOD) as a new data set on the
52 * PROOF cluster. If <output dataset> is not specified, take
53 * the name of the train.</dd>
54 * <dt><tt>storage=<url></tt></dt>
55 * <dd>Specify a non-default storage location for special output
56 * (e.g., AOD trees). <url> should be a valid XRootd
57 * server URI accessible to the slaves - e.g.,
58 * <tt>root://lxplus.cern.ch:10930//tmp</tt>.</dd>
59 * <dt><tt>mode=[default,rec,sim,train,custom]</tt></dt>
60 * <dd>Set the AliROOT mode. If not specified <tt>default</tt>
61 * is assumed. See also CreateAliROOTPar</dd>
62 * <dt><tt>par</tt></dt>
63 * <dd> Use PAR files</dd>
64 * <dt><tt>workers=</tt><i>N</i><tt>[x]</tt></dt>
65 * <dd>Set the number of workers to use. If <tt>x</tt> is appended,
66 * then it's maximum number of workers per slave</dd>
71 * @ingroup pwglf_forward_trains_helper
73 struct AAFPluginRailway : public PluginRailway
79 * @param verbose Verbosity level
81 AAFPluginRailway(const TUrl& url, Int_t verbose)
82 : PluginRailway(url, verbose)
84 fOptions.Add("workers", "N[x]", "Number of workers to use", 0);
85 fOptions.Add("dsname", "NAME", "Make output dataset", "");
86 fOptions.Add("wrapper", "CMD", "Wrapper command", "");
87 fOptions.Add("clear", "Clear all packages");
88 fOptions.Add("reset", "soft|hard", "Reset cluster", "hard");
94 virtual ~AAFPluginRailway() {}
96 * Called before setting up
98 * @return true on success
100 virtual Bool_t PreSetup()
102 // --- Handle software options -----------------------------------
103 TString root = fOptions.Get("root");
104 fHandler->SetRootVersionForProof(Form("VO_ALICE@ROOT::%s", root.Data()));
105 fHandler->SetProofCluster(fUrl.GetHost());
106 fHandler->SetProofDataSet(fUrl.GetFile());
108 // --- Handle worker options -------------------------------------
109 if (fOptions.Has("workers")) {
110 TString nwork = fOptions.Get("workers");
111 if (nwork.EndsWith("x"))
112 fHandler->SetNproofWorkersPerSlave(nwork.Atoi());
114 fHandler->SetNproofWorkers(nwork.Atoi());
117 // --- Check if we're using a wrapper ----------------------------
118 if (fOptions.Has("wrapper")) {
119 TString wrapper = fOptions.Get("wrapper");
120 if (wrapper.IsNull())
121 // In case of no argument, use GDB
122 // Just run and backtrace
123 wrapper = "/usr/bin/gdb --batch -ex run -ex bt --args";
124 Info("ProofRailway::PreSetup", "Using wrapper command: %s",
126 TProof::AddEnvVar("PROOF_WRAPPERCMD", wrapper);
129 // --- Check if we need to clear packages ------------------------
130 fHandler->SetClearPackages(fOptions.Has("clear"));
132 // --- Check if we need to reset first ---------------------------
133 if (fOptions.Has("reset")) {
134 TString reset = fOptions.Get("reset");
135 Bool_t hard = (reset.IsNull() ||
136 reset.EqualTo("hard", TString::kIgnoreCase));
137 Info("AAFPluginRailway::PreSetup", "Will do a %s reset of %s",
138 hard ? "hard" : "soft", fUrl.GetHost());
139 fHandler->SetProofReset(hard ? 2 : 1);
142 return PluginRailway::PreSetup();
145 * Set-up done after the task set-ups
147 * @return true on success
149 virtual Bool_t PostSetup()
151 if (!PluginRailway::PostSetup()) return false;
152 if (fOptions.Has("dsname"))
153 OutputUtilities::RegisterDataset(fOptions.Get("dsname"));
158 * Get the mode identifier
160 * @return Always kProof
162 virtual UShort_t Mode() const { return kProof; }
164 * Get the mode string used for AliAnalysisManager::StartAnalysis
166 virtual const char* ModeString() const { return "proof"; }
170 * @param nEvents Number of events to analyse
172 * @return The return value of AliAnalysisManager::StartAnalysis
174 virtual Long64_t Run(Long64_t nEvents=-1)
176 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
178 TString dsName(fUrl.GetFile());
179 if (fUrl.GetAnchor() && fUrl.GetAnchor()[0] != '\0')
180 dsName.Append(Form("#%s", fUrl.GetAnchor()));
181 return mgr->StartAnalysis(fUrl.GetProtocol(), dsName, nEvents);
184 * @return URI help string
186 virtual const Char_t* UrlHelp() const
188 return "proof://<host>/<dataset>?plugin[&<options>][#<treename>]";
191 * @return Short description
193 virtual const char* Desc() const { return "CAF w/plugin"; }