]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/trains/trainMain.cxx
Added ignores
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / trainMain.cxx
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>
28 #include <TROOT.h>
29 #include <TList.h>
30 #include <TObjString.h>
31 #include <TString.h>
32
33 #include <iostream>
34 #include <iomanip>
35
36 /** 
37  * Custom timer to do a deferred start after the application 
38  * has been started 
39  */
40 struct Deferred : public TTimer
41 {
42   Deferred(const TString& name, const TString& cls, 
43            const TCollection* opts)
44     : TTimer(1000, false), 
45       fName(name), 
46       fClass(cls), 
47       fOptions(opts)
48   {
49     Start(1000, true);
50   }
51   Bool_t Notify()
52   {
53     // gSystem->RemoveTimer(this);
54     Info("Notify", "Will run train setup: %s (%s)", 
55          fName.Data(), fClass.Data());
56     return TrainSetup::Main(fName, fClass, fOptions);
57   }
58   TString fName;
59   TString fClass;
60   const TCollection* fOptions;
61 };
62
63 /** 
64  * Append directory to header and script search path
65  * 
66  * @param dir Directory
67  * 
68  * @ingroup pwglf_forward_trains_run
69  */
70 void AppendPath(const char* dir)
71 {
72   gROOT->SetMacroPath(Form("%s:%s",gROOT->GetMacroPath(), dir));
73   gSystem->AddIncludePath(Form("-I%s", dir));
74 }
75 /** 
76  * Print a fake option description.  Used for options specific to this
77  * program.
78  * 
79  * @param o    Output stream 
80  * @param opt  Option (including meta argument)
81  * @param desc Option description.
82  * 
83  * @ingroup pwglf_forward_trains_run
84  */
85 void PrintFakeOption(std::ostream& o, const char* opt, const char* desc)
86 {
87   o << "  --" << std::left << std::setw(30) << opt << " " << desc << std::endl;
88 }
89
90 /** 
91  * Print usage information 
92  * 
93  * @param progname Program name 
94  * @param o        Output stream
95  * @param r        Optional runner. 
96  * 
97  * @ingroup pwglf_forward_trains_run
98  */
99 void Usage(const char* progname, std::ostream& o)
100 {
101   o << "Usage: " << progname << " --class=CLASS --name=NAME [OPTIONS]\n\n"
102     << "PROGRAM OPTIONS:\n";
103   PrintFakeOption(o, "class=CLASS",       "Train class");
104   PrintFakeOption(o, "name=NAME",         "Name of train");
105   PrintFakeOption(o, "include=DIRECTORY", "Append dir to macro/header path");
106   PrintFakeOption(o, "batch",             "Batch mode");
107 }
108
109 int
110 main(int argc, char** argv)
111 {
112   TList optList;
113   TString name;
114   TString cls;
115   Bool_t  batch = false;
116   Bool_t  help  = false;
117
118   // --- Parse options -----------------------------------------------
119   for (int i = 1; i < argc; i++) { 
120     if (argv[i][0] == '-' && argv[i][1] == '-') { 
121       TString arg(argv[i]);
122       TString val("");
123       arg.ReplaceAll("\"'", "");
124       Int_t   eq = arg.Index("=");
125       if (eq != kNPOS) val = arg(eq+1, arg.Length()-eq-1);
126       if      (arg.BeginsWith("--class"))   cls  = val;
127       else if (arg.BeginsWith("--name"))    name = val;
128       else if (arg.BeginsWith("--include")) AppendPath(val);
129       else if (arg.BeginsWith("--batch"))   batch = true;
130       else if (arg.BeginsWith("--help"))    help  = true;
131       else optList.Add(new TObjString(&(argv[i][2])));
132     }
133   }
134   // --- check for help ----------------------------------------------
135   if (help && cls.IsNull()) {
136     if (cls.IsNull()) {
137       Usage(argv[0], std::cout);
138       return 0;
139     }
140     optList.Add(new TObjString("help"));
141   }
142
143   // --- Check name and class ----------------------------------------
144   if (name.IsNull()) { 
145     Error("main", "No name specified");
146     return 1;
147   }
148   if (cls.IsNull()) { 
149     Error("main", "No class specified");
150     return 1;
151   }
152
153   // --- Setup script path -------------------------------------------
154   const char* aliPath  = gSystem->ExpandPathName("$ALICE_ROOT");
155   const char* fwdPath  = gSystem->ExpandPathName("$ALICE_ROOT/PWGLF/FORWARD/");
156   AppendPath(aliPath);
157   AppendPath(Form("%s/include",   aliPath));
158   AppendPath(Form("%s/trains",    fwdPath));
159   AppendPath(Form("%s/analysis2", fwdPath));
160
161
162   // --- Set-up Application ------------------------------------------
163   TApplication* app = 0;
164   gROOT->SetBatch(true);
165   if (!batch) { 
166     gROOT->SetBatch(false);
167     app = new TGApplication("runTrain", 0, 0);
168     app->InitializeGraphics();
169   }
170
171   // --- run, possibly in a timer ------------------------------------
172   Bool_t ret = true;
173   if (batch) 
174     ret = TrainSetup::Main(name, cls, &optList);
175   else {
176     new Deferred(name, cls, &optList);
177     Info("main", "Running application (%s)", gROOT->IsBatch() 
178          ? "batch" : "normal");
179     gApplication->Run();
180   }
181
182   // --- Return ------------------------------------------------------
183   return ret ? 0 : 1;
184 }
185 //
186 // EOF
187 //
188
189         
190