]>
Commit | Line | Data |
---|---|---|
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" | |
ba144d92 | 17 | #include "Railway.C" |
18 | #include "LocalRailway.C" | |
19 | #include "ProofRailway.C" | |
20 | #include "LiteRailway.C" | |
21 | #include "AAFRailway.C" | |
22 | #include "PluginRailway.C" | |
23 | #include "AAFPluginRailway.C" | |
24 | #include "GridRailway.C" | |
fdfd93b4 | 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 | */ | |
41 | struct 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); | |
85f21ab4 | 72 | //Info("Notify","Will run train setup: %s (%s)",fName.Data(),fClass.Data()); |
73 | return TrainSetup::Main(fName, fClass, fOptions, true, fSpawn); | |
fdfd93b4 | 74 | } |
75 | TString fName; | |
76 | TString fClass; | |
77 | const TCollection* fOptions; | |
73b32206 | 78 | Bool_t fSpawn; |
fdfd93b4 | 79 | }; |
80 | ||
81 | /** | |
82 | * Append directory to header and script search path | |
83 | * | |
84 | * @param dir Directory | |
85 | * | |
86 | * @ingroup pwglf_forward_trains_run | |
87 | */ | |
88 | void AppendPath(const char* dir) | |
89 | { | |
90 | gROOT->SetMacroPath(Form("%s:%s",gROOT->GetMacroPath(), dir)); | |
91 | gSystem->AddIncludePath(Form("-I%s", dir)); | |
92 | } | |
93 | /** | |
94 | * Print a fake option description. Used for options specific to this | |
95 | * program. | |
96 | * | |
97 | * @param o Output stream | |
98 | * @param opt Option (including meta argument) | |
99 | * @param desc Option description. | |
100 | * | |
101 | * @ingroup pwglf_forward_trains_run | |
102 | */ | |
103 | void PrintFakeOption(std::ostream& o, const char* opt, const char* desc) | |
104 | { | |
73b32206 | 105 | o << " --" << std::left << std::setw(30) << opt << " " << desc |
106 | << std::right << std::endl; | |
fdfd93b4 | 107 | } |
108 | ||
73b32206 | 109 | void ProgramUsage(const char* progname, std::ostream& o) |
110 | { | |
111 | o << "Usage: " << progname | |
112 | << " --class=CLASS --name=NAME --url=URI [OPTIONS]\n\n" | |
113 | << progname << " specific options:\n"; | |
114 | PrintFakeOption(o, "class=CLASS", "Train class"); | |
115 | PrintFakeOption(o, "name=NAME", "Name of train"); | |
116 | PrintFakeOption(o, "include=DIRECTORY", "Append dir to macro/header path"); | |
871d7b56 | 117 | PrintFakeOption(o, "define=DEFINE", "Set a preprocessor macro"); |
73b32206 | 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 | |
fdfd93b4 | 126 | * |
127 | * @ingroup pwglf_forward_trains_run | |
128 | */ | |
129 | void Usage(const char* progname, std::ostream& o) | |
130 | { | |
73b32206 | 131 | ProgramUsage(progname, o); |
8e913be0 | 132 | PrintFakeOption(o, "url=URI", "Execution URI"); |
133 | o << "\nAlternatively to using --url=URI, one can use\n"; | |
134 | PrintFakeOption(o, "where=BASE_URI", "Set protocol, user, host, " | |
135 | "and port URI"); | |
136 | PrintFakeOption(o, "file=FILE_OR_PATH", "File/path part of URI"); | |
137 | PrintFakeOption(o, "options=OPTIONS", "Query options for URI"); | |
138 | PrintFakeOption(o, "anchor=ANCHOR", "Query anchor for URI"); | |
fdfd93b4 | 139 | } |
140 | ||
141 | int | |
142 | main(int argc, char** argv) | |
143 | { | |
144 | TList optList; | |
1de8812e | 145 | TList paths; |
871d7b56 | 146 | TList defines; |
fdfd93b4 | 147 | TString name; |
148 | TString cls; | |
8e913be0 | 149 | TString where; |
150 | TString file; | |
151 | TString opts; | |
152 | TString anchor; | |
153 | Bool_t batch = false; | |
154 | Bool_t help = false; | |
155 | Bool_t urlSeen = false; | |
9c686cb4 | 156 | Bool_t spawn = false; |
fdfd93b4 | 157 | // --- Parse options ----------------------------------------------- |
158 | for (int i = 1; i < argc; i++) { | |
159 | if (argv[i][0] == '-' && argv[i][1] == '-') { | |
160 | TString arg(argv[i]); | |
161 | TString val(""); | |
162 | arg.ReplaceAll("\"'", ""); | |
163 | Int_t eq = arg.Index("="); | |
164 | if (eq != kNPOS) val = arg(eq+1, arg.Length()-eq-1); | |
165 | if (arg.BeginsWith("--class")) cls = val; | |
166 | else if (arg.BeginsWith("--name")) name = val; | |
1de8812e | 167 | else if (arg.BeginsWith("--include")) paths.Add(new TObjString(val)); |
871d7b56 | 168 | else if (arg.BeginsWith("--define")) defines.Add(new TObjString(val)); |
8e913be0 | 169 | else if (arg.BeginsWith("--batch")) batch = true; |
170 | else if (arg.BeginsWith("--help")) help = true; | |
171 | else if (arg.BeginsWith("--where")) where = val; | |
172 | else if (arg.BeginsWith("--file")) file = val; | |
173 | else if (arg.BeginsWith("--opts")) opts = val; | |
174 | else if (arg.BeginsWith("--anchor")) anchor = val; | |
73b32206 | 175 | else if (arg.BeginsWith("--spawn")) spawn = true; |
8e913be0 | 176 | else { |
177 | if (arg.BeginsWith("--url")) urlSeen = true; | |
178 | optList.Add(new TObjString(&(argv[i][2]))); | |
179 | } | |
180 | } | |
181 | } | |
1de8812e | 182 | // --- Set batch mode early ---------------------------------------- |
183 | // Info("main", "Batch mode is set to %d", batch); | |
184 | gROOT->SetBatch(batch); | |
185 | ||
186 | // --- Add to load paths ------------------------------------------- | |
187 | // Info("main", "Adding load paths"); | |
188 | TIter nextP(&paths); | |
189 | TObject* path = 0; | |
190 | while ((path = nextP())) AppendPath(path->GetName()); | |
871d7b56 CHC |
191 | TIter nextD(&defines); |
192 | TObject* def = 0; | |
193 | while ((def = nextD())) | |
194 | gSystem->AddIncludePath(Form("-D%s", def->GetName())); | |
1de8812e | 195 | |
8e913be0 | 196 | // --- Initial check or URI/WHERE ---------------------------------- |
197 | if (!where.IsNull()) { | |
198 | if (urlSeen) { | |
199 | Error("main", "option --url and --where mutually exclusive"); | |
200 | return 1; | |
fdfd93b4 | 201 | } |
8e913be0 | 202 | TUrl u(where); |
203 | if (!file.IsNull()) u.SetFile(file); | |
204 | if (!opts.IsNull()) u.SetOptions(opts); | |
205 | if (!anchor.IsNull()) u.SetAnchor(anchor); | |
206 | optList.Add(new TObjString(Form("url=%s", u.GetUrl()))); | |
fdfd93b4 | 207 | } |
8e913be0 | 208 | |
fdfd93b4 | 209 | // --- check for help ---------------------------------------------- |
73b32206 | 210 | if (help) { |
fdfd93b4 | 211 | if (cls.IsNull()) { |
212 | Usage(argv[0], std::cout); | |
213 | return 0; | |
214 | } | |
73b32206 | 215 | ProgramUsage(argv[0], std::cout); |
fdfd93b4 | 216 | optList.Add(new TObjString("help")); |
217 | } | |
218 | ||
219 | // --- Check name and class ---------------------------------------- | |
220 | if (name.IsNull()) { | |
221 | Error("main", "No name specified"); | |
222 | return 1; | |
223 | } | |
224 | if (cls.IsNull()) { | |
225 | Error("main", "No class specified"); | |
226 | return 1; | |
227 | } | |
228 | ||
229 | // --- Setup script path ------------------------------------------- | |
230 | const char* aliPath = gSystem->ExpandPathName("$ALICE_ROOT"); | |
66ee9f2f | 231 | const char* fwdPath = gSystem->ExpandPathName("$ALICE_ROOT/PWGLF/FORWARD"); |
fdfd93b4 | 232 | AppendPath(aliPath); |
85f21ab4 | 233 | AppendPath(Form("%s/include", aliPath)); |
234 | AppendPath(Form("%s/trains", fwdPath)); | |
235 | AppendPath(Form("%s/analysis2", fwdPath)); | |
236 | AppendPath(Form("%s/analysis2/trains", fwdPath)); | |
fdfd93b4 | 237 | |
238 | // --- Set-up Application ------------------------------------------ | |
239 | TApplication* app = 0; | |
85f21ab4 | 240 | if (spawn) { |
241 | // Info("main", "Creating interpreter application"); | |
242 | TRint* rint = new TRint("runTrain", 0, 0, 0, 0, true); | |
243 | rint->SetPrompt("runTrain[%3d]> "); | |
244 | app = rint; | |
fdfd93b4 | 245 | } |
85f21ab4 | 246 | else if (!batch) { |
247 | // Info("main", "Creating GUI application"); | |
9eb4f4eb | 248 | app = new TApplication("runTrain", 0, 0); |
85f21ab4 | 249 | } |
250 | if (app && !batch) app->InitializeGraphics(); | |
1de8812e | 251 | |
fdfd93b4 | 252 | // --- run, possibly in a timer ------------------------------------ |
253 | Bool_t ret = true; | |
85f21ab4 | 254 | if (!app) |
fdfd93b4 | 255 | ret = TrainSetup::Main(name, cls, &optList); |
256 | else { | |
85f21ab4 | 257 | // optList.ls(); |
73b32206 | 258 | new Deferred(name, cls, &optList, spawn); |
fdfd93b4 | 259 | gApplication->Run(); |
260 | } | |
261 | ||
262 | // --- Return ------------------------------------------------------ | |
263 | return ret ? 0 : 1; | |
264 | } | |
265 | // | |
266 | // EOF | |
267 | // | |
268 | ||
269 | ||
270 |