source: tags/Mars-V2.1/star.cc@ 17595

Last change on this file since 17595 was 8904, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 9.4 KB
Line 
1#include <TROOT.h>
2#include <TClass.h>
3#include <TSystem.h>
4#include <TGClient.h>
5#include <TApplication.h>
6#include <TObjectTable.h>
7
8#include "MLog.h"
9#include "MLogManip.h"
10
11#include "MEnv.h"
12#include "MArgs.h"
13#include "MArray.h"
14#include "MDirIter.h"
15
16#include "MStatusDisplay.h"
17
18#include "MSequence.h"
19#include "MJStar.h"
20
21using namespace std;
22
23static void StartUpMessage()
24{
25 gLog << all << endl;
26
27 // 1 2 3 4 5 6
28 // 123456789012345678901234567890123456789012345678901234567890
29 gLog << "========================================================" << endl;
30 gLog << " Star - MARS V" << MARSVER << endl;
31 gLog << " MARS -- STandard Analysis and Reconstruction" << endl;
32 gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
33 gLog << "========================================================" << endl;
34 gLog << endl;
35}
36
37static void Usage()
38{
39 // 1 2 3 4 5 6 7 8
40 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
41 gLog << all << endl;
42 gLog << "Sorry the usage is:" << endl;
43 gLog << " star [options] sequence.txt|number" << endl << endl;
44 gLog << " Arguments:" << endl;
45 gLog << " sequence.txt: Ascii file defining a sequence of runs" << endl;
46 gLog << " number: The sequence number (using file in the datacenter)" << endl;
47 gLog << " For more details see MSequence" << endl;
48 gLog << " Root Options:" << endl;
49 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
50 gLog << " Options:" << endl;
51 gLog.Usage();
52 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
53 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
54 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
55 gLog << " --debug-env=3 Debug setting resources from resource file and command line" << endl;
56 gLog << " --debug-mem Debug memory usage" << endl << endl;
57 gLog << " --rc=Name:option Set or overwrite a resource of the resource file." << endl;
58 gLog << " (Note, that this option can be used multiple times." << endl;
59 gLog << endl;
60 gLog << " Input Options:" << endl;
61 gLog << " -mc You must use this for MC files (PRELIMINARY)" << endl << endl;
62 gLog << " Output options:" << endl;
63 gLog << " -q Quit when job is finished" << endl;
64 gLog << " -f Force overwrite of existing files" << endl;
65 gLog << " -ff Force execution if not all files found" << endl;
66 gLog << " --ind=path Path where to search for the calibrated data (Y)" << endl;
67 gLog << " [default=standard path in datacenter]" << endl;
68 gLog << " --out=path Path to write the all results to [def=local path]" << endl;
69 gLog << " (overwrites --outc and --outy)" << endl;
70 gLog << " --dev-null Suppress output of I-files (for test purpose)" << endl;
71 gLog << " --no-muons Switch off Muon analysis (for fast tests)" << endl;
72 gLog << " --print-seq Print Sequence information" << endl;
73 gLog << " --print-files Print Files taken from Sequence" << endl;
74 gLog << " --print-found Print Files found from Sequence" << endl;
75 gLog << " --config=star.rc Resource file [default=star.rc]" << endl;
76 gLog << endl;
77 gLog << " --version, -V Show startup message with version number" << endl;
78 gLog << " -?, -h, --help This help" << endl << endl;
79}
80
81static void PrintFiles(const MSequence &seq, const TString &kInpathD, Bool_t allopt)
82{
83 const char *prep = allopt ? "Found" : "Scheduled";
84
85 MDirIter Next;
86 seq.SetupDatRuns(Next, MSequence::kCalibrated, kInpathD);
87
88 gLog << all;
89 gLog.Separator(Form("%s Data Files", prep));
90 Next.Print(allopt?"all":"");
91 gLog << endl;
92}
93
94int main(int argc, char **argv)
95{
96 if (!MARS::CheckRootVer())
97 return 0xff;
98
99 MLog::RedirectErrorHandler(MLog::kColor);
100
101 //
102 // Evaluate arguments
103 //
104 MArgs arg(argc, argv, kTRUE);
105 gLog.Setup(arg);
106
107 StartUpMessage();
108
109 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
110 return 0;
111
112 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
113 {
114 Usage();
115 return 2;
116 }
117
118 const TString kConfig = arg.GetStringAndRemove("--config=", "star.rc");
119
120 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
121 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
122 const Bool_t kPrintFound = arg.HasOnlyAndRemove("--print-found");
123 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
124 const Bool_t kNullOut = arg.HasOnlyAndRemove("--dev-null");
125 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
126 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
127
128 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
129 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
130 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
131 //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
132 const Bool_t kIsMC = arg.HasOnlyAndRemove("-mc");
133 const Bool_t kNoMuons = arg.HasOnlyAndRemove("--no-muons");
134
135 const TString kInpath = arg.GetStringAndRemove("--ind=", "");
136 const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
137
138 //
139 // check for the right usage of the program (number of arguments)
140 //
141 if (arg.GetNumArguments()!=1)
142 {
143 gLog << warn << "WARNING - Wrong number of arguments..." << endl;
144 Usage();
145 return 2;
146 }
147
148 //
149 // Now we access/read the resource file. This will remove all
150 // --rc= from the list of arguments.
151 //
152 MEnv env(kConfig);
153 if (!env.IsValid())
154 {
155 gLog << err << "ERROR - Reading resource file " << kConfig << "." << endl;
156 return 0xfe;
157 }
158
159 // And move the resource options from the command line to the MEnv
160 if (!env.TakeEnv(arg, kDebugEnv>2))
161 return 0xfd;
162
163 //
164 // check for the right usage of the program (number of options)
165 //
166 if (arg.GetNumOptions()>0)
167 {
168 gLog << warn << "WARNING - Unknown commandline options..." << endl;
169 arg.Print("options");
170 gLog << endl;
171 return 2;
172 }
173
174 //
175 // Setup sequence file and check for its existance
176 //
177 TString kSequence = arg.GetArgumentStr(0);
178
179 //
180 // Something special for datacenter access
181 //
182 if (!MSequence::InflatePath(kSequence, kIsMC))
183 return 2;
184
185 //
186 // Setup sequence and check its validity
187 //
188 MSequence seq(kSequence, kInpath);
189 if (!seq.IsMonteCarlo())
190 seq.SetMonteCarlo(kIsMC);
191 if (kPrintSeq)
192 {
193 gLog << all;
194 gLog.Separator(kSequence);
195 seq.Print();
196 gLog << endl;
197 }
198 if (!seq.IsValid())
199 {
200 gLog << err << "Sequence read but not valid!" << endl << endl;
201 return 2;
202 }
203
204 //
205 // Process print options
206 //
207 if (kPrintFiles)
208 PrintFiles(seq, kInpath, kFALSE);
209 if (kPrintFound)
210 PrintFiles(seq, kInpath, kTRUE);
211
212 //
213 // Initialize root
214 //
215 MArray::Class()->IgnoreTObjectStreamer();
216 MParContainer::Class()->IgnoreTObjectStreamer();
217
218 TApplication app("star", &argc, argv);
219 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
220 {
221 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
222 return 1;
223 }
224
225 //
226 // Update frequency by default = 1Hz
227 //
228 MStatusDisplay *d = new MStatusDisplay;
229
230 // From now on each 'Exit' means: Terminate the application
231 d->SetBit(MStatusDisplay::kExitLoopOnExit);
232 d->SetTitle(kSequence);
233
234 if (kDebugMem)
235 TObject::SetObjectStat(kTRUE);
236
237 //
238 // Do star in a block (debug mem)
239 //
240 {
241 MJStar job(Form("MJStar #%d", seq.GetSequence()));
242 job.SetSequence(seq);
243 job.SetEnv(&env);
244 job.SetEnvDebug(kDebugEnv);
245 job.SetDisplay(d);;
246 job.SetOverwrite(kOverwrite);
247 job.SetPathOut(kOutpath);
248 job.SetNullOut(kNullOut);
249 // job.SetPathIn(kInpath); // not yet needed
250 if (kNoMuons)
251 job.DisableMuonAnalysis();
252
253 if (!job.Process())
254 {
255 gLog << err << "Calculation of image parameters failed." << endl << endl;
256 return 2;
257 }
258
259 if (kDebugEnv>0)
260 env.PrintUntouched();
261
262 if (!job.GetDisplay())
263 {
264 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
265 return 1;
266 }
267 }
268
269 if (kBatch || kQuit)
270 delete d;
271 else
272 {
273 // From now on each 'Close' means: Terminate the application
274 d->SetBit(MStatusDisplay::kExitLoopOnClose);
275
276 // Wait until the user decides to exit the application
277 app.Run(kFALSE);
278 }
279
280 if (TObject::GetObjectStat())
281 {
282 TObject::SetObjectStat(kFALSE);
283 gObjectTable->Print();
284 }
285
286 return 0;
287}
Note: See TracBrowser for help on using the repository browser.