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
12 #include "AvailableSoftware.C"
13 #include "ChainBuilder.C"
14 #include "ParUtilities.C"
15 #include "OutputUtilities.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"
27 #include <TGApplication.h>
30 #include <TObjString.h>
37 * Custom timer to do a deferred start after the application
40 struct Deferred : public TTimer
42 Deferred(const TString& name, const TString& cls,
43 const TCollection* opts)
44 : TTimer(1000, false),
51 Deferred(const Deferred& o)
57 Deferred& operator=(const Deferred& o)
59 if (&o == this) return *this;
62 fOptions = o.fOptions;
67 // gSystem->RemoveTimer(this);
68 Info("Notify", "Will run train setup: %s (%s)",
69 fName.Data(), fClass.Data());
70 return TrainSetup::Main(fName, fClass, fOptions);
74 const TCollection* fOptions;
78 * Append directory to header and script search path
80 * @param dir Directory
82 * @ingroup pwglf_forward_trains_run
84 void AppendPath(const char* dir)
86 gROOT->SetMacroPath(Form("%s:%s",gROOT->GetMacroPath(), dir));
87 gSystem->AddIncludePath(Form("-I%s", dir));
90 * Print a fake option description. Used for options specific to this
93 * @param o Output stream
94 * @param opt Option (including meta argument)
95 * @param desc Option description.
97 * @ingroup pwglf_forward_trains_run
99 void PrintFakeOption(std::ostream& o, const char* opt, const char* desc)
101 o << " --" << std::left << std::setw(30) << opt << " " << desc << std::endl;
105 * Print usage information
107 * @param progname Program name
108 * @param o Output stream
109 * @param r Optional runner.
111 * @ingroup pwglf_forward_trains_run
113 void Usage(const char* progname, std::ostream& o)
115 o << "Usage: " << progname << " --class=CLASS --name=NAME [OPTIONS]\n\n"
116 << "PROGRAM OPTIONS:\n";
117 PrintFakeOption(o, "class=CLASS", "Train class");
118 PrintFakeOption(o, "name=NAME", "Name of train");
119 PrintFakeOption(o, "include=DIRECTORY", "Append dir to macro/header path");
120 PrintFakeOption(o, "batch", "Batch mode");
124 main(int argc, char** argv)
129 Bool_t batch = false;
132 // --- Parse options -----------------------------------------------
133 for (int i = 1; i < argc; i++) {
134 if (argv[i][0] == '-' && argv[i][1] == '-') {
135 TString arg(argv[i]);
137 arg.ReplaceAll("\"'", "");
138 Int_t eq = arg.Index("=");
139 if (eq != kNPOS) val = arg(eq+1, arg.Length()-eq-1);
140 if (arg.BeginsWith("--class")) cls = val;
141 else if (arg.BeginsWith("--name")) name = val;
142 else if (arg.BeginsWith("--include")) AppendPath(val);
143 else if (arg.BeginsWith("--batch")) batch = true;
144 else if (arg.BeginsWith("--help")) help = true;
145 else optList.Add(new TObjString(&(argv[i][2])));
148 // --- check for help ----------------------------------------------
149 if (help && cls.IsNull()) {
151 Usage(argv[0], std::cout);
154 optList.Add(new TObjString("help"));
157 // --- Check name and class ----------------------------------------
159 Error("main", "No name specified");
163 Error("main", "No class specified");
167 // --- Setup script path -------------------------------------------
168 const char* aliPath = gSystem->ExpandPathName("$ALICE_ROOT");
169 const char* fwdPath = gSystem->ExpandPathName("$ALICE_ROOT/PWGLF/FORWARD/");
171 AppendPath(Form("%s/include", aliPath));
172 AppendPath(Form("%s/trains", fwdPath));
173 AppendPath(Form("%s/analysis2", fwdPath));
176 // --- Set-up Application ------------------------------------------
177 TApplication* app = 0;
178 gROOT->SetBatch(true);
180 gROOT->SetBatch(false);
181 app = new TGApplication("runTrain", 0, 0);
182 app->InitializeGraphics();
185 // --- run, possibly in a timer ------------------------------------
188 ret = TrainSetup::Main(name, cls, &optList);
190 new Deferred(name, cls, &optList);
191 Info("main", "Running application (%s)", gROOT->IsBatch()
192 ? "batch" : "normal");
196 // --- Return ------------------------------------------------------