source: trunk/MagicSoft/Mars/ceres.cc@ 9552

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