source: branches/MarsGapdTimeJitter/ceres.cc@ 18106

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