]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/trains/trainMain.cxx
Added general scripts for Terminate, Download, and Monitor for Grid jobs
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / trainMain.cxx
CommitLineData
fdfd93b4 1/*
2 To compile, do
3
4 rootcint -f OptionDict.C -c Option.C
5 g++ `root-config --cflags --libs` \
6 -lVMC -lGeom -lMinuit -lXMLIO -lTree -lTreePlayer \
7 -I$ALICE_ROOT/include -L$ALICE_ROOT/lib/tgt_${ALICE_TARGET} \
8 -lSTEERBase -lESD -lAOD -lANALYSIS -lOADB -lANALYSISalice \
9 trainMain.cxx -o runTrain
10*/
11
12#include "AvailableSoftware.C"
13#include "ChainBuilder.C"
14#include "ParUtilities.C"
15#include "OutputUtilities.C"
16#include "Option.C"
17#include "Helper.C"
18#include "LocalHelper.C"
19#include "ProofHelper.C"
20#include "LiteHelper.C"
21#include "AAFHelper.C"
22#include "PluginHelper.C"
23#include "AAFPluginHelper.C"
24#include "GridHelper.C"
25#include "TrainSetup.C"
26
27#include <TGApplication.h>
73b32206 28#include <TRint.h>
fdfd93b4 29#include <TROOT.h>
30#include <TList.h>
31#include <TObjString.h>
32#include <TString.h>
33
34#include <iostream>
35#include <iomanip>
36
37/**
38 * Custom timer to do a deferred start after the application
39 * has been started
40 */
41struct Deferred : public TTimer
42{
43 Deferred(const TString& name, const TString& cls,
73b32206 44 const TCollection* opts, bool spawn)
fdfd93b4 45 : TTimer(1000, false),
46 fName(name),
47 fClass(cls),
73b32206 48 fOptions(opts),
49 fSpawn(spawn)
fdfd93b4 50 {
51 Start(1000, true);
52 }
46b25775 53 Deferred(const Deferred& o)
54 : TTimer(),
55 fName(o.fName),
56 fClass(o.fClass),
73b32206 57 fOptions(o.fOptions),
58 fSpawn(o.fSpawn)
46b25775 59 {}
60 Deferred& operator=(const Deferred& o)
61 {
62 if (&o == this) return *this;
63 fName = o.fName;
64 fClass = o.fClass;
65 fOptions = o.fOptions;
73b32206 66 fSpawn = o.fSpawn;
46b25775 67 return *this;
68 }
fdfd93b4 69 Bool_t Notify()
70 {
71 // gSystem->RemoveTimer(this);
72 Info("Notify", "Will run train setup: %s (%s)",
73 fName.Data(), fClass.Data());
73b32206 74 return TrainSetup::Main(fName, fClass, fOptions, fSpawn);
fdfd93b4 75 }
76 TString fName;
77 TString fClass;
78 const TCollection* fOptions;
73b32206 79 Bool_t fSpawn;
fdfd93b4 80};
81
82/**
83 * Append directory to header and script search path
84 *
85 * @param dir Directory
86 *
87 * @ingroup pwglf_forward_trains_run
88 */
89void AppendPath(const char* dir)
90{
91 gROOT->SetMacroPath(Form("%s:%s",gROOT->GetMacroPath(), dir));
92 gSystem->AddIncludePath(Form("-I%s", dir));
93}
94/**
95 * Print a fake option description. Used for options specific to this
96 * program.
97 *
98 * @param o Output stream
99 * @param opt Option (including meta argument)
100 * @param desc Option description.
101 *
102 * @ingroup pwglf_forward_trains_run
103 */
104void PrintFakeOption(std::ostream& o, const char* opt, const char* desc)
105{
73b32206 106 o << " --" << std::left << std::setw(30) << opt << " " << desc
107 << std::right << std::endl;
fdfd93b4 108}
109
73b32206 110void ProgramUsage(const char* progname, std::ostream& o)
111{
112 o << "Usage: " << progname
113 << " --class=CLASS --name=NAME --url=URI [OPTIONS]\n\n"
114 << progname << " specific options:\n";
115 PrintFakeOption(o, "class=CLASS", "Train class");
116 PrintFakeOption(o, "name=NAME", "Name of train");
117 PrintFakeOption(o, "include=DIRECTORY", "Append dir to macro/header path");
118 PrintFakeOption(o, "batch", "Batch mode");
119 PrintFakeOption(o, "spawn", "Spawn interactive ROOT shell");
120}
fdfd93b4 121/**
122 * Print usage information
123 *
124 * @param progname Program name
125 * @param o Output stream
126 * @param r Optional runner.
127 *
128 * @ingroup pwglf_forward_trains_run
129 */
130void Usage(const char* progname, std::ostream& o)
131{
73b32206 132 ProgramUsage(progname, o);
8e913be0 133 PrintFakeOption(o, "url=URI", "Execution URI");
134 o << "\nAlternatively to using --url=URI, one can use\n";
135 PrintFakeOption(o, "where=BASE_URI", "Set protocol, user, host, "
136 "and port URI");
137 PrintFakeOption(o, "file=FILE_OR_PATH", "File/path part of URI");
138 PrintFakeOption(o, "options=OPTIONS", "Query options for URI");
139 PrintFakeOption(o, "anchor=ANCHOR", "Query anchor for URI");
fdfd93b4 140}
141
142int
143main(int argc, char** argv)
144{
145 TList optList;
146 TString name;
147 TString cls;
8e913be0 148 TString where;
149 TString file;
150 TString opts;
151 TString anchor;
152 Bool_t batch = false;
153 Bool_t help = false;
154 Bool_t urlSeen = false;
9c686cb4 155 Bool_t spawn = false;
fdfd93b4 156 // --- Parse options -----------------------------------------------
157 for (int i = 1; i < argc; i++) {
158 if (argv[i][0] == '-' && argv[i][1] == '-') {
159 TString arg(argv[i]);
160 TString val("");
161 arg.ReplaceAll("\"'", "");
162 Int_t eq = arg.Index("=");
163 if (eq != kNPOS) val = arg(eq+1, arg.Length()-eq-1);
164 if (arg.BeginsWith("--class")) cls = val;
165 else if (arg.BeginsWith("--name")) name = val;
166 else if (arg.BeginsWith("--include")) AppendPath(val);
8e913be0 167 else if (arg.BeginsWith("--batch")) batch = true;
168 else if (arg.BeginsWith("--help")) help = true;
169 else if (arg.BeginsWith("--where")) where = val;
170 else if (arg.BeginsWith("--file")) file = val;
171 else if (arg.BeginsWith("--opts")) opts = val;
172 else if (arg.BeginsWith("--anchor")) anchor = val;
73b32206 173 else if (arg.BeginsWith("--spawn")) spawn = true;
8e913be0 174 else {
175 if (arg.BeginsWith("--url")) urlSeen = true;
176 optList.Add(new TObjString(&(argv[i][2])));
177 }
178 }
179 }
180 // --- Initial check or URI/WHERE ----------------------------------
181 if (!where.IsNull()) {
182 if (urlSeen) {
183 Error("main", "option --url and --where mutually exclusive");
184 return 1;
fdfd93b4 185 }
8e913be0 186 TUrl u(where);
187 if (!file.IsNull()) u.SetFile(file);
188 if (!opts.IsNull()) u.SetOptions(opts);
189 if (!anchor.IsNull()) u.SetAnchor(anchor);
190 optList.Add(new TObjString(Form("url=%s", u.GetUrl())));
fdfd93b4 191 }
8e913be0 192
fdfd93b4 193 // --- check for help ----------------------------------------------
73b32206 194 if (help) {
fdfd93b4 195 if (cls.IsNull()) {
196 Usage(argv[0], std::cout);
197 return 0;
198 }
73b32206 199 ProgramUsage(argv[0], std::cout);
fdfd93b4 200 optList.Add(new TObjString("help"));
201 }
202
203 // --- Check name and class ----------------------------------------
204 if (name.IsNull()) {
205 Error("main", "No name specified");
206 return 1;
207 }
208 if (cls.IsNull()) {
209 Error("main", "No class specified");
210 return 1;
211 }
212
213 // --- Setup script path -------------------------------------------
214 const char* aliPath = gSystem->ExpandPathName("$ALICE_ROOT");
215 const char* fwdPath = gSystem->ExpandPathName("$ALICE_ROOT/PWGLF/FORWARD/");
216 AppendPath(aliPath);
217 AppendPath(Form("%s/include", aliPath));
218 AppendPath(Form("%s/trains", fwdPath));
219 AppendPath(Form("%s/analysis2", fwdPath));
220
221
222 // --- Set-up Application ------------------------------------------
223 TApplication* app = 0;
224 gROOT->SetBatch(true);
73b32206 225 if (!batch || spawn) {
fdfd93b4 226 gROOT->SetBatch(false);
73b32206 227 if (!spawn)
228 app = new TGApplication("runTrain", 0, 0);
229 else {
230 TRint* rint = new TRint("runTrain", 0, 0, 0, 0, true);
231 rint->SetPrompt("runTrain[%3d]> ");
232 app = rint;
233 }
fdfd93b4 234 app->InitializeGraphics();
235 }
236
237 // --- run, possibly in a timer ------------------------------------
238 Bool_t ret = true;
239 if (batch)
240 ret = TrainSetup::Main(name, cls, &optList);
241 else {
73b32206 242 optList.ls();
243 new Deferred(name, cls, &optList, spawn);
fdfd93b4 244 Info("main", "Running application (%s)", gROOT->IsBatch()
245 ? "batch" : "normal");
246 gApplication->Run();
247 }
248
249 // --- Return ------------------------------------------------------
250 return ret ? 0 : 1;
251}
252//
253// EOF
254//
255
256
257