]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/trains/AAFPluginHelper.C
Changed scripts for new TrainSetup
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / AAFPluginHelper.C
CommitLineData
fdfd93b4 1/**
2 * @file AAFPluginHelper.C
3 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4 * @date Tue Oct 16 19:01:45 2012
5 *
6 * @brief AAF (using AliAnalysisAlien) analysis helper
7 *
8 * @ingroup pwglf_forward_trains_helper
9 *
10 */
11#ifndef AAFPLUGINHELPER_C
12#define AAFPLUGINHELPER_C
13#include "PluginHelper.C"
14#ifndef __CINT__
15# include <TUrl.h>
16# include <TString.h>
17# include <AliAnalysisManager.h>
18# include <AliAnalysisAlien.h>
19#else
20class TUrl;
21class AliAnalysisAlien;
22#endif
23
24// ===================================================================
25/**
26 * Handle analysis on an Alice Analysis Facility (AAF)
27 *
28 * This helper is triggered by a URL of the form
29 *
30 * @code
31 * proof://[<user>@]<host>[:<port>]/<dsname>[?<options>][#<treename>]
32 * @endcode
33 * where &lt;host@gt; is a known AAF (e.g., <tt>alice-caf.cern.ch</tt>),
34 * and the &lt;options&gt; contains <tt>plugin</tt>
35 * <dl>
36 * <dt>&lt;user@gt;</dt>
37 * <dd>Optional user name</dd>
38 * <dt>&lt;host@gt;</dt>
39 * <dd>PROOF cluster master host</dd>
40 * <dt>&lt;port@gt;</dt>
41 * <dd>Optional PROOF cluster port on master host</dd>
42 * <dt>&lt;dsname@gt;</dt>
43 * <dd>Data set name</dd>
44 * <dt>&lt;treename@gt;</dt>
45 * <dd>Optional tree name in data set, often <tt>esdTree</tt> or
46 * <tt>aodTree</tt></dd>
47 * <dt>&lt;options@gt;</dt>
48 * <dd>List of options separated by an &amp;
49 * <dl>
50 * <dt><tt>dsname</tt>[=&lt;output dataset&gt;]</dt>
51 * <dd>Register tree output (e.g., AOD) as a new data set on the
52 * PROOF cluster. If &lt;output dataset&gt; is not specified, take
53 * the name of the train.</dd>
54 * <dt><tt>storage=&lt;url&gt;</tt></dt>
55 * <dd>Specify a non-default storage location for special output
56 * (e.g., AOD trees). &lt;url&gt; 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</tt>. 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>
67 * </dl>
68 * </dd>
69 * </dl>
70 *
71 * @ingroup pwglf_forward_trains_helper
72 */
73struct AAFPluginHelper : public PluginHelper
74{
75 /**
76 * Constructor
77 *
78 * @param url Url
79 * @param opts Options
80 */
81 AAFPluginHelper(const TUrl& url, Int_t verbose)
82 : PluginHelper(url, verbose)
83 {
9021ee82 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");
46b25775 87 fOptions.Add("clear", "Clear all packages");
88 fOptions.Add("reset", "soft|hard", "Reset cluster", "hard");
fdfd93b4 89
90 }
91 /**
92 * Destructor
93 */
94 virtual ~AAFPluginHelper() {}
95 /**
96 * Called before setting up
97 *
98 * @return true on success
99 */
100 virtual Bool_t PreSetup()
101 {
46b25775 102 // --- Handle software options -----------------------------------
fdfd93b4 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());
46b25775 107
108 // --- Handle worker options -------------------------------------
fdfd93b4 109 if (fOptions.Has("workers")) {
110 TString nwork = fOptions.Get("workers");
111 if (nwork.EndsWith("x"))
112 fHandler->SetNproofWorkersPerSlave(nwork.Atoi());
113 else
114 fHandler->SetNproofWorkers(nwork.Atoi());
115 }
46b25775 116
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("ProofHelper::PreSetup", "Using wrapper command: %s",
125 wrapper.Data());
126 TProof::AddEnvVar("PROOF_WRAPPERCMD", wrapper);
127 }
128
129 // --- Check if we need to clear packages ------------------------
130 fHandler->SetClearPackages(fOptions.Has("clear"));
131
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("AAFPluginHelper::PreSetup", "Will do a %s reset of %s",
138 hard ? "hard" : "soft", fUrl.GetHost());
139 fHandler->SetProofReset(hard ? 2 : 1);
140 }
141
fdfd93b4 142 return PluginHelper::PreSetup();
143 }
144 /**
145 * Set-up done after the task set-ups
146 *
147 * @return true on success
148 */
149 virtual Bool_t PostSetup()
150 {
151 if (!PluginHelper::PostSetup()) return false;
152 if (fOptions.Has("dsname"))
153 OutputUtilities::RegisterDataset(fOptions.Get("dsname"));
154
155 return true;
156 };
157 /**
158 * Get the mode identifier
159 *
160 * @return Always kProof
161 */
162 virtual UShort_t Mode() const { return kProof; }
163 /**
164 * Get the mode string used for AliAnalysisManager::StartAnalysis
165 */
166 virtual const char* ModeString() const { return "proof"; }
167 /**
168 * Start the analysis
169 *
170 * @param nEvents Number of events to analyse
171 *
172 * @return The return value of AliAnalysisManager::StartAnalysis
173 */
174 virtual Long64_t Run(Long64_t nEvents=-1)
175 {
176 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
177
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);
182 }
183 /**
184 * @return URI help string
185 */
186 virtual const Char_t* UrlHelp() const
187 {
188 return "proof://<host>/<dataset>?plugin[&<options>][#<treename>]";
189 }
190 /**
191 * @return Short description
192 */
193 virtual const char* Desc() const { return "CAF w/plugin"; }
194};
195#endif
196//
197// EOF
198//