source: trunk/Mars/ceres.cc@ 16211

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