source: trunk/Mars/ceres.cc@ 19845

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