AliPhysics  9c66e61 (9c66e61)
trainMain.cxx
Go to the documentation of this file.
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 "Railway.C"
18 #include "LocalRailway.C"
19 #include "ProofRailway.C"
20 #include "LiteRailway.C"
21 #include "VAFRailway.C"
22 #include "AAFRailway.C"
23 #include "PluginRailway.C"
24 #include "AAFPluginRailway.C"
25 #include "GridRailway.C"
26 #include "TrainSetup.C"
27 
28 #include <TGApplication.h>
29 #include <TRint.h>
30 #include <TROOT.h>
31 #include <TList.h>
32 #include <TObjString.h>
33 #include <TString.h>
34 
35 #include <iostream>
36 #include <iomanip>
37 
42 struct Deferred : public TTimer
43 {
44  Deferred(const TString& name, const TString& cls,
45  const TCollection* opts, bool spawn)
46  : TTimer(1000, false),
47  fName(name),
48  fClass(cls),
49  fOptions(opts),
50  fSpawn(spawn)
51  {
52  Start(1000, true);
53  }
54  Deferred(const Deferred& o)
55  : TTimer(),
56  fName(o.fName),
57  fClass(o.fClass),
58  fOptions(o.fOptions),
59  fSpawn(o.fSpawn)
60  {}
62  {
63  if (&o == this) return *this;
64  fName = o.fName;
65  fClass = o.fClass;
66  fOptions = o.fOptions;
67  fSpawn = o.fSpawn;
68  return *this;
69  }
71  {
72  // gSystem->RemoveTimer(this);
73  // Info("Notify","Will run train setup: %s (%s)",
74  // fName.Data(),fClass.Data());
75  return TrainSetup::Main(fName, fClass, fOptions, true, fSpawn);
76  }
81 };
82 
90 void AppendPath(const char* dir)
91 {
92  gROOT->SetMacroPath(Form("%s:%s",gROOT->GetMacroPath(), dir));
93  gSystem->AddIncludePath(Form("-I%s", dir));
94 }
105 void PrintFakeOption(std::ostream& o, const char* opt, const char* desc)
106 {
107  o << " --" << std::left << std::setw(30) << opt << " " << desc
108  << std::right << std::endl;
109 }
110 
111 void ProgramUsage(const char* progname, std::ostream& o)
112 {
113  o << "Usage: " << progname
114  << " --class=CLASS --name=NAME --url=URI [OPTIONS]\n\n"
115  << progname << " specific options:\n";
116  PrintFakeOption(o, "class=CLASS", "Train class");
117  PrintFakeOption(o, "name=NAME", "Name of train");
118  PrintFakeOption(o, "include=DIRECTORY", "Append dir to macro/header path");
119  PrintFakeOption(o, "define=DEFINE", "Set a preprocessor macro");
120  PrintFakeOption(o, "batch", "Batch mode");
121  PrintFakeOption(o, "spawn", "Spawn interactive ROOT shell");
122 }
131 void Usage(const char* progname, std::ostream& o)
132 {
133  ProgramUsage(progname, o);
134  PrintFakeOption(o, "url=URI", "Execution URI");
135  o << "\nAlternatively to using --url=URI, one can use\n";
136  PrintFakeOption(o, "where=BASE_URI", "Set protocol, user, host, "
137  "and port URI");
138  PrintFakeOption(o, "file=FILE_OR_PATH", "File/path part of URI");
139  PrintFakeOption(o, "options=OPTIONS", "Query options for URI");
140  PrintFakeOption(o, "anchor=ANCHOR", "Query anchor for URI");
141 }
147 void Version(std::ostream& o)
148 {
149  o << "TrainSetup version " << TrainSetup::kVersion << std::endl;
150 }
151 
152 int
153 main(int argc, char** argv)
154 {
155  TList optList;
156  TList paths;
157  TList defines;
158  TString name;
159  TString cls;
160  TString where;
161  TString file;
162  TString opts;
163  TString anchor;
164  Bool_t batch = false;
165  Bool_t help = false;
166  Bool_t urlSeen = false;
167  Bool_t spawn = false;
168  Bool_t version = false;
169  // --- Parse options -----------------------------------------------
170  for (int i = 1; i < argc; i++) {
171  if (argv[i][0] == '-' && argv[i][1] == '-') {
172  TString arg(argv[i]);
173  TString val("");
174  arg.ReplaceAll("\"'", "");
175  Int_t eq = arg.Index("=");
176  if (eq != kNPOS) val = arg(eq+1, arg.Length()-eq-1);
177  if (arg.BeginsWith("--class")) cls = val;
178  else if (arg.BeginsWith("--name")) name = val;
179  else if (arg.BeginsWith("--include")) paths.Add(new TObjString(val));
180  else if (arg.BeginsWith("--define")) defines.Add(new TObjString(val));
181  else if (arg.BeginsWith("--batch")) batch = true;
182  else if (arg.BeginsWith("--help")) help = true;
183  else if (arg.BeginsWith("--where")) where = val;
184  else if (arg.BeginsWith("--file")) file = val;
185  else if (arg.BeginsWith("--opts")) opts = val;
186  else if (arg.BeginsWith("--anchor")) anchor = val;
187  else if (arg.BeginsWith("--spawn")) spawn = true;
188  else if (arg.BeginsWith("--version")) version = true;
189  else {
190  if (arg.BeginsWith("--url")) urlSeen = true;
191  optList.Add(new TObjString(&(argv[i][2])));
192  }
193  }
194  }
195  if (version) {
196  Version(std::cout);
197  return 0;
198  }
199  // --- Set batch mode early ----------------------------------------
200  // Info("main", "Batch mode is set to %d", batch);
201  gROOT->SetBatch(batch);
202 
203  // --- Add to load paths -------------------------------------------
204  // Info("main", "Adding load paths");
205  TIter nextP(&paths);
206  TObject* path = 0;
207  while ((path = nextP())) AppendPath(path->GetName());
208  TIter nextD(&defines);
209  TObject* def = 0;
210  while ((def = nextD()))
211  gSystem->AddIncludePath(Form("-D%s", def->GetName()));
212 
213  // --- Initial check or URI/WHERE ----------------------------------
214  if (!where.IsNull()) {
215  if (urlSeen) {
216  Error("main", "option --url and --where mutually exclusive");
217  return 1;
218  }
219  TUrl u(where);
220  if (!file.IsNull()) u.SetFile(file);
221  if (!opts.IsNull()) u.SetOptions(opts);
222  if (!anchor.IsNull()) u.SetAnchor(anchor);
223  optList.Add(new TObjString(Form("url=%s", u.GetUrl())));
224  }
225 
226  // --- check for help ----------------------------------------------
227  if (help) {
228  if (cls.IsNull()) {
229  Usage(argv[0], std::cout);
230  return 0;
231  }
232  ProgramUsage(argv[0], std::cout);
233  optList.Add(new TObjString("help"));
234  }
235 
236  // --- Check name and class ----------------------------------------
237  if (name.IsNull()) {
238  Error("main", "No name specified");
239  return 1;
240  }
241  if (cls.IsNull()) {
242  Error("main", "No class specified");
243  return 1;
244  }
245 
246  // --- Setup script path -------------------------------------------
247  const char* aliPath = gSystem->ExpandPathName("$ALICE_ROOT");
248  const char* phyPath = gSystem->ExpandPathName("$ALICE_PHYSICS");
249  const char* fwdPath = Form("%s/PWGLF/FORWARD",phyPath);
250  AppendPath(aliPath);
251  AppendPath(Form("%s/include", aliPath));
252  AppendPath(Form("%s/include", phyPath));
253  AppendPath(Form("%s/trains", fwdPath));
254  AppendPath(Form("%s/analysis2", fwdPath));
255  AppendPath(Form("%s/analysis2/trains", fwdPath));
256 
257  // --- Set-up Application ------------------------------------------
258  TApplication* app = 0;
259  if (spawn) {
260  // Info("main", "Creating interpreter application");
261  TRint* rint = new TRint("runTrain", 0, 0, 0, 0, true);
262  rint->SetPrompt("runTrain[%3d]> ");
263  app = rint;
264  }
265  else if (!batch) {
266  // Info("main", "Creating GUI application");
267  app = new TApplication("runTrain", 0, 0);
268  }
269  if (app && !batch) app->InitializeGraphics();
270 
271  // --- run, possibly in a timer ------------------------------------
272  Bool_t ret = true;
273  if (!app)
274  ret = TrainSetup::Main(name, cls, &optList);
275  else {
276  // optList.ls();
277  new Deferred(name, cls, &optList, spawn);
278  gApplication->Run();
279  }
280 
281  // --- Return ------------------------------------------------------
282  return ret ? 0 : 1;
283 }
284 //
285 // EOF
286 //
287 
288 
289 
void AppendPath(const char *dir)
Definition: trainMain.cxx:90
void PrintFakeOption(std::ostream &o, const char *opt, const char *desc)
Definition: trainMain.cxx:105
AAF analysis helper.
Base class for helpers using the AliAnalysisAlien plugin.
Grid Analysis Railway.
TSystem * gSystem
void ProgramUsage(const char *progname, std::ostream &o)
Definition: trainMain.cxx:111
Special output handling.
Definition: External.C:92
AAF analysis helper.
const TCollection * fOptions
Definition: trainMain.cxx:79
void Usage(const char *progname, std::ostream &o)
Definition: trainMain.cxx:131
int Int_t
Definition: External.C:63
TString fName
Definition: trainMain.cxx:77
Proof-Lite analysis helper.
Deferred(const Deferred &o)
Definition: trainMain.cxx:54
Bool_t fSpawn
Definition: trainMain.cxx:80
void Version(std::ostream &o)
Definition: trainMain.cxx:147
Base classs for train specifications.
PAR file utilities.
Deferred(const TString &name, const TString &cls, const TCollection *opts, bool spawn)
Definition: trainMain.cxx:44
Find available packages.
Local analysis helper.
TFile * file
TList with histograms for a given trigger.
Base class for analysis helpers.
Bool_t Notify()
Definition: trainMain.cxx:70
int main(int argc, char **argv)
Definition: trainMain.cxx:153
bool Bool_t
Definition: External.C:53
static Bool_t Main(const TString &name, const TString &cls, const TCollection *opts, Bool_t asProg=true, Bool_t spawn=false)
Definition: TrainSetup.C:443
TString fClass
Definition: trainMain.cxx:78
AAF (using AliAnalysisAlien) analysis helper.
Build a chain.
Deferred & operator=(const Deferred &o)
Definition: trainMain.cxx:61
TDirectoryFile * dir