]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/trains/RunTrain.C
Merge branch 'workdir'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / RunTrain.C
1 /**
2  * @file   RunTrain.C
3  * @author Christian Holm Christensen <cholm@nbi.dk>
4  * @date   Tue Oct 16 17:49:49 2012
5  * 
6  * @brief  Script to run a train 
7  *
8  * @ingroup pwglf_forward_trains
9  */
10 /** 
11  * Build a script 
12  * 
13  * @param name     Name of script 
14  * @param verbose  Whether to be verbose 
15  * @param force    Whether to force re-compilation 
16  * @param debug    Whether to enable debug symbols  
17  * 
18  * @return true on success 
19  *
20  * @ingroup pwglf_forward_trains
21  */
22 Bool_t
23 BuildScript(const char* name, Bool_t verbose, Bool_t force, Bool_t debug)
24 {
25   const char opt[] = { (force ? '+' : debug ? 'g' : '\0'), 
26                        (force && debug ? 'g' : '\0'), '\0' };
27   if (verbose) Printf("Building %s ...",name);
28   Int_t error;
29   Int_t ret = gROOT->LoadMacro(Form("%s.C+%s", name, opt), &error);
30   if (ret < 0 || error) { 
31     Error("BuildScript", "Failed to build %s: %d", error);
32     return false;
33   }
34   return true;
35   
36 }
37
38 /** 
39  * Build all helper classes 
40  * 
41  * @param verbose Whether to be verbose 
42  * @param force   Whether to force re-builds
43  * @param debug   Whether to enable debug symbols 
44  * @param all     Whether to build all helpers 
45  *
46  * @return true on success 
47  *
48  * @ingroup pwglf_forward_trains
49  */
50 Bool_t
51 BuildHelpers(Bool_t verbose, Bool_t force, Bool_t debug,
52              Bool_t all=false)
53 {
54   gSystem->AddIncludePath("-I$ALICE_ROOT/include");
55   gSystem->AddIncludePath("-I$ALICE_ROOT/PWGLF/FORWARD/trains/");
56   gROOT->SetMacroPath(Form("%s:$ALICE_ROOT/PWGLF/FORWARD/trains",
57                            gROOT->GetMacroPath()));
58   gSystem->Load("libANALYSIS");
59   gSystem->Load("libANALYSISalice");
60   const char* scripts[] = { "AvailableSoftware", 
61                             "ChainBuilder", 
62                             "ParUtilities",
63                             "OutputUtilities", 
64                             "Option",
65                             "Helper", 
66                             "TrainSetup",
67                             (all ? "LocalHelper" : 0), 
68                             "ProofHelper", 
69                             "LiteHelper", 
70                             "AAFHelper", 
71                             "PluginHelper", 
72                             "AAFPluginHelper", 
73                             "GridHelper", 
74                             0 };
75   const char** ptr = scripts;
76   while ((*ptr)) {
77     if (!BuildScript(*ptr, verbose, force, debug)) return false;
78     ptr++;
79   }
80   return true;
81 }
82
83 /** 
84  * Show the usage 
85  * 
86  *
87  * @ingroup pwglf_forward_trains
88  */
89 void PlainUsage()
90 {
91   std::cout << "Usage: .x RunTrain.C(NAME,CLASS,OPTIONS)\n\n"
92             << "  NAME       Name of train (free form)\n"
93             << "  CLASS      Name of class implementing TrainSetup\n"
94             << "  OPTIONS    Comma separated list of options\n"
95             << std::endl;
96 }
97
98 /** 
99  * Function to run a train.  
100  * 
101  * @param name  Name of the train. 
102  * @param cls   class name of train setup
103  * @param uri   Exection URI  
104  * @param opts  Optons 
105  * 
106  * @return true on success
107  *
108  * @ingroup pwglf_forward_trains
109  */
110 Bool_t RunTrain(const TString& name, const TString& cls, 
111                 const TUrl& uri,     const TString& opts)
112 {
113   // Check for help 
114   if (name.IsNull() || name.EqualTo("help", TString::kIgnoreCase) || 
115       cls.IsNull()  || cls.EqualTo("help", TString::kIgnoreCase) || 
116       !uri.IsValid()) {
117     PlainUsage();
118     return true;
119   }
120   
121   Bool_t verb = opts.Contains("verbose");
122   // Build our helpers 
123   if (!BuildHelpers(verb, false, true)) return false;
124
125   // Tokenize options 
126   if (!opts.EndsWith(",")) opts.Append(",");
127   opts.Append("url="); 
128   opts.Append(uri.GetUrl());
129   TObjArray* optList = opts.Tokenize(",");
130   return TrainSetup::Main(name, cls, optList, false);
131 }
132 /*
133  * EOF
134  */     
135