source: trunk/Mars/ceres.cc@ 20044

Last change on this file since 20044 was 19957, checked in by tbretz, 5 years ago
Make sure that TTime is split in root 6, see bug report 10757
File size: 15.6 KB
Line 
1#include <TClass.h>
2#include <TSystem.h>
3#include <TApplication.h>
4#include <TObjectTable.h>
5
6#include <TVector2.h>
7
8#include "zofits.h"
9
10#include "MArray.h"
11
12#include "MLog.h"
13#include "MLogManip.h"
14
15#include "MStatusDisplay.h"
16
17#include "MEnv.h"
18#include "MArgs.h"
19#include "MDirIter.h"
20
21#include "MJSimulation.h"
22
23
24using namespace std;
25
26static void StartUpMessage()
27{
28 gLog << all << endl;
29
30 // 1 2 3 4 5
31 // 12345678901234567890123456789012345678901234567890
32 gLog << "====================================================" << endl;
33 gLog << " Ceres - MARS V" << MARSVER << endl;
34 gLog << " MARS - Camera Electronics and REflector Simulation" << endl;
35 gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
36 gLog << "====================================================" << endl;
37 gLog << endl;
38}
39
40static void Usage()
41{
42 gLog << all << endl;
43 gLog << "Sorry the usage is:" << endl;
44 gLog << " ceres [options] [inputfiles|sequence.txt]" << endl << endl;
45 gLog << " inputfiles MMCS (CORSIKA) binary (cherenkov) files, wildcards allowed." << endl;
46 gLog << " sequence.txt A sequence file." << endl;
47 gLog << " Root Options:" << endl;
48 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
49 gLog << " Options:" << endl;
50 gLog.Usage();
51 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
52 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
53 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
54 gLog << " --debug-env=3 Debug setting resources from resource file and" << endl;
55 gLog << " 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 << " Output options:" << endl;
61 gLog << " -q Quit when job is finished" << endl;
62 gLog << " -f Force overwrite of existing files" << endl;
63 gLog << " -ff Force reading of file even if problems occur" << endl;
64 gLog << " --out=path Path to write all results to [def=local path]" << endl;
65 gLog << " --ind=path Input path of Corsika files if sequence used" << endl;
66 gLog << " [def=standard path in datacenter]" << endl;
67 gLog << " --check Can be used to check whether the input files are valid." << endl;
68 gLog << " 0 is returned in case of success. Warnings can be" << endl;
69 gLog << " suppressed with -v1." << endl;
70 gLog << " --outf=filename Output filename. Combines all input files into" << endl;
71 gLog << " one output file. (Note that the output file will" << endl;
72 gLog << " contain only the headers corresponding to the" << endl;
73 gLog << " first input file)" << endl;
74 gLog << " --dev-null Suppress output of files (for test purpose)" << endl;
75 gLog << " --print-seq Print Sequence information [sequence only]" << endl;
76 gLog << " --print-files Print Files taken from Sequence" << endl;
77 gLog << " --print-found Print Files found from Sequence" << endl;
78 gLog << " --config=ceres.rc Resource file [default=reflector.rc]" << endl;
79 gLog << endl;
80 gLog << " --mode=pedestal Execution mode. Produce either pedestals," << endl;
81 gLog << " --mode=calibration calibration data (no input files required) or" << endl;
82 gLog << " --mode=data process data files [default]" << endl << endl;
83 gLog << " --run-number=# Optionally set the run number to simulate" << endl;
84 gLog << " --fits Write FITS output files instead of root files." << endl;
85 gLog << " --zfits-rows Number of rows compressed into one tile (see zofit.h)." << endl;
86 gLog << " --zfits-threads Number of threads for compression (see zofits.h)." << endl;
87 gLog << " --list The specified .txt file contains a file list" << endl;
88 gLog << " (see MDirIter::ReadFile)." << endl << endl;
89 gLog << endl;
90// gLog << " -f: force reading of runheader" << endl;
91 gLog << " --version, -V Show startup message with version number" << endl;
92 gLog << " -?, -h, --help This help" << endl << endl;
93 gLog << "Background:" << endl;
94 gLog << " Ceres, formal designation 1 Ceres, is the smallest identified dwarf planet in" << endl;
95 gLog << " the Solar System and the only one in the asteroid belt. It was discovered on" << endl;
96 gLog << " January 1, 1801, by Giuseppe Piazzi, and is named after the Roman goddess" << endl;
97 gLog << " Ceres, the goddess of growing plants, the harvest, and of motherly love." << endl;
98 gLog << " With a diameter of about 950km, Ceres is by far the largest and most massive" << endl;
99 gLog << " body in the asteroid belt, and contains a third of the belt's total mass." << endl;
100 gLog << " Recent observations have revealed that it is spherical, unlike the irregular" << endl;
101 gLog << " shapes of smaller bodies with lower gravity. The surface of Ceres is probably" << endl;
102 gLog << " made of a mixture of water ice and various hydrated minerals like carbonates" << endl;
103 gLog << " and clays. Ceres appears to be differentiated into a rocky core and ice mantle." << endl;
104 gLog << " It may harbour an ocean of liquid water underneath its surface, which makes it" << endl;
105 gLog << " a potential target in the search for extraterrestrial life." << endl;
106 gLog << " Ceres' apparent magnitude ranges from 6.7 to 9.3, hence at its brightest is" << endl;
107 gLog << " still too dim to be seen with the naked eye. On Sept. 27, 2007, NASA launched" << endl;
108 gLog << " the Dawn space probe to explore Vesta and Ceres." << endl << endl;
109 gLog << "Example:" << endl;
110 gLog << " ceres -f --out=outpath/ cer000001 cer000002" << endl;
111 gLog << endl;
112}
113
114static void PrintFiles(const MArgs &arg, Bool_t allopt)
115{
116 const char *prep = allopt ? "Found" : "Scheduled";
117
118 gLog << all;
119 gLog.Separator(Form("%s Data Files", prep));
120 for (int i=0; i<arg.GetNumArguments(); i++)
121 if (!allopt || gSystem->AccessPathName(arg.GetArgumentStr(i), kFileExists)==0)
122 gLog << arg.GetArgumentStr(i) << endl;
123 gLog << endl;
124}
125
126
127static void PrintFiles(const MSequence &seq, const TString &kInpathD, Bool_t allopt)
128{
129 const char *prep = allopt ? "Found" : "Scheduled";
130
131 MDirIter Next;
132 seq.GetRuns(Next, MSequence::kCorsika, kInpathD);
133
134 gLog << all;
135 gLog.Separator(Form("%s Data Files", prep));
136 Next.Print(allopt?"all":"");
137 gLog << endl;
138}
139
140int main(int argc, char **argv)
141{
142 if (!MARS::CheckRootVer())
143 return 0xff;
144
145 MLog::RedirectErrorHandler(MLog::kColor);
146
147 //
148 // Evaluate arguments
149 //
150 MArgs arg(argc, argv);
151 gLog.Setup(arg);
152
153 const Bool_t kCheckOnly = arg.HasOnlyAndRemove("--check");
154
155 if (!kCheckOnly)
156 StartUpMessage();
157
158 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
159 return 0;
160
161 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
162 {
163 Usage();
164 return 2;
165 }
166
167 const Bool_t kBatch = arg.HasOnlyAndRemove("-b") || kCheckOnly;
168 //const Int_t kCompLvl = arg.GetIntAndRemove("--comp=", 1);
169 const Bool_t kForce = arg.HasOnlyAndRemove("-ff") && !kCheckOnly;
170 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
171 const Bool_t kNullOut = arg.HasOnlyAndRemove("--dev-null");
172 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
173 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
174
175 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
176 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
177 const Bool_t kPrintFound = arg.HasOnlyAndRemove("--print-found");
178
179 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
180 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
181
182 const TString kConfig = arg.GetStringAndRemove("--config=", "ceres.rc");
183 const TString kInpath = arg.GetStringAndRemove("--ind=", "");
184 const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
185 const TString kOutfile = arg.GetStringAndRemove("--outf=", "");
186
187 const Int_t kRunNumber = arg.GetIntAndRemove("--run-number=", -1);
188
189 const TString kOpMode = arg.GetStringAndRemove("--mode=", "data");
190 const Bool_t kFitsFile = arg.HasOnlyAndRemove("--fits");
191 const Bool_t kFileList = arg.HasOnlyAndRemove("--list");
192
193 // This is here because it is global
194 zofits::DefaultNumRowsPerTile(arg.GetIntAndRemove("--zfits-rows", 100));
195 zofits::DefaultNumThreads(arg.GetIntAndRemove("--zfits-threads", 0));
196
197 Int_t opmode = -1;
198 if (TString("data").BeginsWith(kOpMode, TString::kIgnoreCase))
199 opmode = MJSimulation::kModeData;
200 if (TString("pointrun").BeginsWith(kOpMode, TString::kIgnoreCase))
201 opmode = MJSimulation::kModePointRun;
202 if (TString("pedestal").BeginsWith(kOpMode, TString::kIgnoreCase))
203 opmode = MJSimulation::kModePed;
204 if (TString("calibration").BeginsWith(kOpMode, TString::kIgnoreCase))
205 opmode = MJSimulation::kModeCal;
206
207 if (opmode<0)
208 {
209 gLog << err << "ERROR - Wrong mode specified..." << endl;
210 Usage();
211 return 2;
212 }
213
214 //
215 // check for the right usage of the program (number of arguments)
216 if (arg.GetNumArguments()<1 && opmode==MJSimulation::kModeData)
217 {
218 gLog << warn << "WARNING - Wrong number of arguments..." << endl;
219 Usage();
220 return 2;
221 }
222
223 //
224 // for compatibility with the first version of ceres
225 //
226 if (arg.GetNumArguments()==1 && opmode==MJSimulation::kModeData)
227 {
228 if (arg.GetArgumentStr(0)=="pedestal")
229 {
230 opmode = MJSimulation::kModePed;
231 arg.RemoveArgument(0);
232 }
233 if (arg.GetArgumentStr(0)=="calibration")
234 {
235 opmode = MJSimulation::kModeCal;
236 arg.RemoveArgument(0);
237 }
238 }
239
240 if (arg.GetNumArguments()>0 && opmode!=MJSimulation::kModeData)
241 {
242 gLog << warn << "WARNING - No arguments allowed in this mode..." << endl;
243 Usage();
244 return 2;
245 }
246
247 //
248 // Now we access/read the resource file. This will remove all
249 // --rc= from the list of arguments.
250 //
251 MEnv env(kConfig, "ceres.rc");
252 if (!env.IsValid())
253 {
254 gLog << err << "ERROR - Reading resource file " << kConfig << "." << endl;
255 return 0xfe;
256 }
257
258 // And move the resource options from the command line to the MEnv
259 if (!env.TakeEnv(arg, kDebugEnv>2))
260 return 0xfd;
261
262 //
263 // check for the right usage of the program (number of options)
264 //
265 if (arg.GetNumOptions()>0)
266 {
267 gLog << warn << "WARNING - Unknown commandline options..." << endl;
268 arg.Print("options");
269 gLog << endl;
270 return 2;
271 }
272
273 //
274 // Setup sequence file and check for its existance
275 //
276 TString kSequence = arg.GetNumArguments()==1 ? arg.GetArgumentStr(0) : "";
277
278 //
279 // Check if the first argument (if any) is a sequence file or not
280 //
281 if (!kSequence.EndsWith(".txt"))
282 kSequence = "";
283
284 //
285 // Something special for datacenter access
286 //
287 if (!kSequence.IsNull() && !MSequence::InflateSeq(kSequence, kTRUE))
288 return 2;
289
290 //
291 // Setup sequence and check its validity
292 //
293 MSequence seq(kFileList ? "" : kSequence, kInpath);
294 if (!kSequence.IsNull() && !kFileList)
295 {
296 if (kPrintSeq)
297 {
298 gLog << all;
299 gLog.Separator(kSequence);
300 seq.Print();
301 gLog << endl;
302 }
303 if (seq.IsValid() && !seq.IsMonteCarlo())
304 {
305 gLog << err << "Sequence is not a Monte Carlo Sequence." << endl << endl;
306 return 2;
307 }
308 if (!seq.IsValid())
309 {
310 gLog << err << "Sequence read but not valid!" << endl << endl;
311 return 2;
312 }
313
314 //
315 // Process print options
316 //
317 if (kPrintFiles)
318 PrintFiles(seq, kInpath, kFALSE);
319 if (kPrintFound)
320 PrintFiles(seq, kInpath, kTRUE);
321 }
322 else
323 {
324 if (kFileList)
325 {
326 arg.RemoveArgument(0);
327
328 MDirIter Next;
329 Next.ReadList(kSequence);
330
331 TString name;
332 while (!(name=Next()).IsNull())
333 arg.AddEntry(name);
334 }
335
336 if (kPrintFiles)
337 PrintFiles(arg, kFALSE);
338 if (kPrintFound)
339 PrintFiles(arg, kTRUE);
340 }
341
342 //
343 // Initialize root
344 //
345 TVector2::Class()->IgnoreTObjectStreamer();
346 MArray::Class()->IgnoreTObjectStreamer();
347 MParContainer::Class()->IgnoreTObjectStreamer();
348 TTime::Class()->SetCanSplit(true);
349
350 if (kCheckOnly)
351 gROOT->SetBatch();
352
353 TApplication app("ceres", &argc, argv);
354 if ((!gROOT->IsBatch() && !gClient) || (gROOT->IsBatch() && !kBatch))
355 {
356 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
357 return 1;
358 }
359
360 //
361 // Update frequency by default = 1Hz
362 //
363 MStatusDisplay *d = new MStatusDisplay;
364
365 // From now on each 'Exit' means: Terminate the application
366 d->SetBit(MStatusDisplay::kExitLoopOnExit);
367 d->SetTitle(seq.IsValid() ? Form("-- Ceres: %s --", kSequence.Data()) : "-- Ceres --");
368
369 if (kDebugMem)
370 TObject::SetObjectStat(kTRUE);
371
372 //
373 // Do star in a block (debug mem)
374 //
375 {
376 MJSimulation job(seq.IsValid() ? Form("Ceres #%d", seq.GetSequence()) : "Ceres");
377 //job.SetSequence(seq);
378 job.SetEnv(&env);
379 job.SetEnvDebug(kDebugEnv);
380 job.SetDisplay(d);;
381 job.SetOverwrite(kOverwrite);
382 job.SetPathOut(kOutpath);
383 job.SetFileOut(kOutfile);
384 job.SetNullOut(kNullOut);
385 job.SetForceMode(kForce);
386 job.SetWriteFitsFile(kFitsFile);
387 job.SetMode(opmode);
388 job.SetCommandLine(MArgs::GetCommandLine(argc, argv));
389 job.SetRunNumber(kRunNumber);
390
391 // job.SetPathIn(kInpath); // not yet needed
392
393 if (!job.Process(arg, seq, kCheckOnly))
394 {
395 if (job.GetDisplay())
396 delete d;
397
398 if (!kCheckOnly)
399 gLog << err << "Calculation of ceres failed." << endl << endl;
400 return 2;
401 }
402
403 if (kDebugEnv>0)
404 env.PrintUntouched();
405
406 if (!job.GetDisplay())
407 {
408 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
409 return 1;
410 }
411 }
412
413 if (kBatch || kQuit)
414 delete d;
415 else
416 {
417 // From now on each 'Close' means: Terminate the application
418 d->SetBit(MStatusDisplay::kExitLoopOnClose);
419
420 // Wait until the user decides to exit the application
421 app.Run(kFALSE);
422 }
423
424 if (TObject::GetObjectStat())
425 {
426 TObject::SetObjectStat(kFALSE);
427 gObjectTable->Print();
428 }
429
430 return 0;
431}
Note: See TracBrowser for help on using the repository browser.