source: trunk/Mars/ceres.cc@ 10102

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