source: trunk/MagicSoft/Mars/callisto.cc@ 6698

Last change on this file since 6698 was 6604, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 21.4 KB
Line 
1#include <TROOT.h>
2#include <TClass.h>
3#include <TSystem.h>
4#include <TGClient.h>
5#include <TApplication.h>
6#include <TObjectTable.h>
7
8#include "MLog.h"
9#include "MLogManip.h"
10
11#include "MEnv.h"
12#include "MArgs.h"
13#include "MArray.h"
14#include "MDirIter.h"
15
16#include "MStatusDisplay.h"
17
18#include "MSequence.h"
19#include "MJPedestal.h"
20#include "MJCalibration.h"
21#include "MJCalibrateSignal.h"
22#include "MJCalibTest.h"
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 << " Callisto - MARS V" << MARSVER << endl;
34 gLog << " MARS -- CALibrate LIght Signals and Time Offsets" << endl;
35 gLog << " Compiled on <" << __DATE__ << ">" << endl;
36 gLog << " Using ROOT v" << ROOTVER << endl;
37 gLog << "========================================================" << endl;
38 gLog << endl;
39}
40
41static void Usage()
42{
43 // 1 2 3 4 5 6 7 8
44 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
45 gLog << all << endl;
46 gLog << "Sorry the usage is:" << endl;
47 gLog << " callisto [-c] [-y] [options] sequence.txt" << endl << endl;
48 gLog << " Arguments:" << endl;
49 gLog << " sequence.txt: Ascii file defining a sequence of runs" << endl;
50 gLog << " For more details see MSequence" << endl;
51 gLog << " Root Options:" << endl;
52 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
53 gLog << " Operation Modes:" << endl;
54 gLog << " -c Calculate the calibration constants" << endl;
55 gLog << " -y Extract and calibrate signal" << endl << endl;
56 gLog << " Data Type (exclusive):" << endl;
57 gLog << " -raw Read input from raw-data" << endl;
58 gLog << " -mc Input root-files are monte carlo files" << endl;
59 gLog << " -root Read input from root-files (merpped) <default>" << endl << endl;
60 gLog << " Options:" << endl;
61 gLog.Usage();
62 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
63 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
64 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
65 gLog << " --debug-env=3 Debug setting resources from resource file" << endl;
66 gLog << " --debug-mem Debug memory usage" << endl << endl;
67 gLog << endl;
68 gLog << " -q Quit when job is finished" << endl;
69 gLog << " -f Force overwrite of existing files" << endl;
70 gLog << " --ind=path Path where to search for the data files" << endl;
71 gLog << " [default=standard path in datacenter]" << endl;
72 gLog << " --iny=path Path where to search for the calibration files" << endl;
73 gLog << " [default=local path or output path of Mode-C]" << endl;
74 gLog << " --outc=path Path to write Mode-C result to [def=local path]" << endl;
75 gLog << " --outy=path Path to write Mode-Y result to [def=local path]" << endl;
76 gLog << " --out=path Path to write the all results to [def=local path]" << endl;
77 gLog << " (overwrites --outc and --outy)" << endl;
78 gLog << " --path=path Path to write the all results to [def=local path]" << endl;
79 gLog << " (overwrites --iny, --outc and --outy)" << endl;
80 gLog << " --print-seq Print Sequence information" << endl;
81 gLog << " --print-files Print Files taken from Sequence" << endl;
82 gLog << " --print-found Print Files found from Sequence" << endl;
83 gLog << " --use-test Apply calibration constants to same calibration" << endl;
84 gLog << " file (for testing, calibration mode only)" << endl;
85 gLog << " --config=callisto.rc Resource file [default=callisto.rc]" << endl;
86 gLog << endl;
87 gLog << " --version, -V Show startup message with version number" << endl;
88 gLog << " -?, -h, --help This help" << endl << endl;
89 gLog << " Setup of the two jobs run by callisto (MJPedestal and MJCalibration)" << endl;
90 gLog << " can be done with the resource file. See MJPedestal and MJCalibration" << endl;
91 gLog << " especially CheckEnv() for more details. Command line options might" << endl;
92 gLog << " be overwritten by the resource file." << endl << endl;
93 gLog << " If running in Mode-C and Mode-Y --iny= is obsolete, instead --outc=" << endl;
94 gLog << " is used." << endl << endl;
95 gLog << " Using --iny=, --outc=, --outy=, --out= or --path= automatically" << endl;
96 gLog << " enables the corresponmding modes. In this case -c/-y are obsolete." << endl << endl;
97 gLog << "Description:" << endl;
98 gLog << " callisto will calculate pedestals from pedestal-files defined in a" << endl;
99 gLog << " sequence-file. This pedestals are used to calculate the calibration" << endl;
100 gLog << " contants. These constants are stored in a so called calibration-file" << endl;
101 gLog << " together with some datacheck plots which can be viewed using either" << endl;
102 gLog << " showplot or MStatusDisplay in the interpreter. A description of a" << endl;
103 gLog << " sequence-file can be found in the class reference of MSequence." << endl << endl;
104 gLog << "Background:" << endl;
105 gLog << " Callisto is a large, icy, dark-colored, low-density outer moon of" << endl;
106 gLog << " Jupiter that is scarred with impact craters and ejecta. It has a" << endl;
107 gLog << " diameter of about 4800km, the second-largest moon of Jupiter; it is" << endl;
108 gLog << " roughly the size of Mercury. Callisto has the largest-known impact" << endl;
109 gLog << " crater in the Solar System, Valhalla, which has a bright patch 600km" << endl;
110 gLog << " across and rings that go out to almost 3000km. Callisto orbits" << endl;
111 gLog << " Jupiter at a mean distance of 1,883,000km. Its mass is 1.1e23 kg. It" << endl;
112 gLog << " takes Callisto 16.7 days to orbit Jupiter in a synchronous orbit." << endl;
113 gLog << " Jupiter's moon Callisto was discovered independantly by Galileo and" << endl;
114 gLog << " S.Marius in 1610." << endl << endl;
115 gLog << "Example:" << endl;
116 gLog << " callisto -f --outc=mycal/ --outy=mysignal/ --log sequence02345.txt" << endl;
117 gLog << endl;
118}
119
120static void PrintFiles(const MSequence &seq, const TString &kInpathD, Bool_t raw, Bool_t all)
121{
122 const char *prep = all ? "Found" : "Scheduled";
123
124 MDirIter Next1, Next2, Next3;
125 seq.SetupPedRuns(Next1, kInpathD, "P", raw);
126 seq.SetupCalRuns(Next2, kInpathD, "C", raw);
127 seq.SetupDatRuns(Next3, kInpathD, "D", raw);
128
129 gLog << all;
130 gLog.Separator(Form("%s Pedestal Files", prep));
131 Next1.Print(all?"all":"");
132 gLog << endl;
133 gLog.Separator(Form("%s Calibration Files", prep));
134 Next2.Print(all?"all":"");
135 gLog << endl;
136 gLog.Separator(Form("%s Data Files", prep));
137 Next3.Print(all?"all":"");
138 gLog << endl;
139}
140
141int main(int argc, char **argv)
142{
143 StartUpMessage();
144
145 //
146 // Evaluate arguments
147 //
148 MArgs arg(argc, argv, kTRUE);
149
150 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
151 return 0;
152
153 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
154 {
155 Usage();
156 return -1;
157 }
158
159 gLog.Setup(arg);
160
161 const TString kConfig = arg.GetStringAndRemove("--config=", "callisto.rc");
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 const Bool_t kUseTest = arg.HasOnlyAndRemove("--use-test");
167 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
168 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
169 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
170
171 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
172 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
173 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
174 //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
175
176 const TString kInpathD = arg.GetStringAndRemove("--ind=", "");
177 TString kInpathY = arg.GetStringAndRemove("--iny=", "");
178 TString kOutpathY = arg.GetStringAndRemove("--outy=", "");
179 TString kOutpathC = arg.GetStringAndRemove("--outc=", "");
180 const TString kOutpath = arg.GetStringAndRemove("--out=", "");
181 const TString kPath = arg.GetStringAndRemove("--path=", "");
182
183 Bool_t kModeC = arg.HasOnlyAndRemove("-c");
184 Bool_t kModeY = arg.HasOnlyAndRemove("-y");
185
186 MJCalib::DataType_t kDataType = MJCalib::kIsUseRootData; // root
187 if (arg.HasOnlyAndRemove("-raw"))
188 kDataType = MJCalib::kIsUseRawData; // raw
189 if (arg.HasOnlyAndRemove("-mc"))
190 kDataType = MJCalib::kIsUseMC; // monte carlo
191
192 if (!kInpathY.IsNull() || !kOutpathY.IsNull() || !kOutpath.IsNull() || !kPath.IsNull())
193 kModeY = kTRUE;
194 if (!kOutpathC.IsNull() || !kOutpath.IsNull() || !kPath.IsNull())
195 kModeC = kTRUE;
196
197 if (!kModeC && !kModeY /*&& !kUseTest*/)
198 {
199 gLog << err << "Neither calibration (-c) nor signal extraction (-y) or test-mode (--use-test) specified!" << endl;
200 Usage();
201 return 0;
202 }
203
204 if ((kModeC/* || kUseTest*/) && kOutpathC.IsNull())
205 kOutpathC = ".";
206 if (kModeY)
207 {
208 if (kInpathY.IsNull())
209 kInpathY = ".";
210 if (kOutpathY.IsNull())
211 kOutpathY = ".";
212 }
213 if (!kOutpath.IsNull())
214 {
215 kOutpathC = kOutpath;
216 kOutpathY = kOutpath;
217 }
218 if (!kPath.IsNull())
219 {
220 kOutpathC = kOutpath;
221 kOutpathY = kOutpath;
222 kInpathY = kOutpath;
223 }
224
225 if (kModeC && kModeY)
226 kInpathY = kOutpathC;
227
228 if (arg.GetNumOptions()>0)
229 {
230 gLog << warn << "WARNING - Unknown commandline options..." << endl;
231 arg.Print("options");
232 gLog << endl;
233 return -1;
234 }
235
236 //
237 // check for the right usage of the program
238 //
239 if (arg.GetNumArguments()!=1)
240 {
241 Usage();
242 return -1;
243 }
244
245 //
246 // Setup sequence file and check for its existance
247 //
248 const TString kSequence = arg.GetArgumentStr(0);
249
250 if (gSystem->AccessPathName(kSequence, kFileExists))
251 {
252 gLog << err << "Sorry, sequence file '" << kSequence << "' doesn't exist." << endl;
253 return -1;
254 }
255
256 if (gSystem->AccessPathName(kConfig, kFileExists))
257 {
258 gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl;
259 return -1;
260 }
261
262 if (kDebugMem)
263 TObject::SetObjectStat(kTRUE);
264
265 //
266 // Setup sequence and check its validity
267 //
268 MSequence seq(kSequence);
269 if (kPrintSeq)
270 {
271 gLog << all;
272 gLog.Separator(kSequence);
273 seq.Print();
274 gLog << endl;
275 }
276 if (!seq.IsValid())
277 {
278 gLog << err << "Sequence read but not valid!" << endl << endl;
279 return -1;
280 }
281
282 //
283 // Process print options
284 //
285 if (kPrintFiles)
286 PrintFiles(seq, kInpathD, kDataType==MJCalib::kIsUseRawData, kFALSE);
287 if (kPrintFound)
288 PrintFiles(seq, kInpathD, kDataType==MJCalib::kIsUseRawData, kTRUE);
289/*
290 //
291 // Check for existance of all files
292 //
293 MDirIter iter;
294 const Int_t n0 = seq.SetupAllRuns(iter, kInpathD, "[DPC]");
295 const Int_t n1 = seq.GetNumAllRuns();
296 if (n0 != n1)
297 {
298 if (kForceExec)
299 gLog << warn << "WARNING";
300 else
301 gLog << err << "ERROR";
302 gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in ";
303 gLog << (kInpathD.IsNull() ? "<defaultpath>" : kInpathD.Data()) << endl;
304 if (!kForceExec)
305 return -1;
306 }
307
308 if (kPrintOnly)
309 return 0;
310 */
311 //
312 // Initialize root
313 //
314 MArray::Class()->IgnoreTObjectStreamer();
315 MParContainer::Class()->IgnoreTObjectStreamer();
316
317 TApplication app("Callisto", &argc, argv);
318 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
319 {
320 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
321 return 1;
322 }
323
324 //
325 // Update frequency by default = 1Hz
326 //
327 MStatusDisplay *d = new MStatusDisplay;
328
329 // From now on each 'Exit' means: Terminate the application
330 d->SetBit(MStatusDisplay::kExitLoopOnExit);
331 d->SetTitle(kSequence);
332
333 MEnv env(kConfig);
334 if (kModeC/* || kUseTest*/)
335 {
336 //
337 // Calculate pedestal for pedestal-calculation and calibration
338 //
339 MJPedestal job1(Form("MJPedestalC1 #%d", seq.GetSequence()));
340 job1.SetNoStorage();
341 job1.SetSequence(seq);
342 job1.SetEnv(&env);
343 job1.SetEnvDebug(kDebugEnv);
344 job1.SetDisplay(d);
345 job1.SetOverwrite(kOverwrite);
346 job1.SetPathData(kInpathD);
347 job1.SetDataType(kDataType);
348
349 job1.SetExtractionFundamental();
350 // job1.SetPathOut(kOutpathC); // not yet needed
351 // job1.SetPathIn(kInpathC); // not yet needed
352
353 if (!job1.ProcessFile())
354 {
355 gLog << err << "Calculation of pedestal failed." << endl << endl;
356 return -1;
357 }
358
359 if (!job1.GetDisplay())
360 {
361 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
362 return 1;
363 }
364
365 //
366 // Calculate pedestal and pedestal resolution
367 //
368 MJPedestal job2(Form("MJPedestalC2 #%d", seq.GetSequence()));
369 job2.SetNoStorage();
370 job2.SetSequence(seq);
371 job2.SetEnv(&env);
372 job2.SetEnvDebug(kDebugEnv);
373 job2.SetDisplay(d);;
374 job2.SetOverwrite(kOverwrite);
375 job2.SetPathData(kInpathD);
376 job2.SetDataType(kDataType);
377 // job1.SetPathOut(kOutpathC); // not yet needed
378 // job1.SetPathIn(kInpathC); // not yet needed
379
380 //job2.SetExtractorResolution();
381 job2.SetExtractionWithExtractorRndm();
382 job2.SetExtractor(job1.GetExtractor());
383 job2.SetPedestals(job1.GetPedestalCam());
384 job2.SetBadPixels(job1.GetBadPixels());
385
386 if (!job2.ProcessFile())
387 {
388 gLog << err << "Calculation of pedestal resolution failed." << endl << endl;
389 return -1;
390 }
391
392 if (!job2.GetDisplay())
393 {
394 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
395 return 1;
396 }
397
398 //
399 // Do calibration
400 //
401 MJCalibration job3(Form("MJCalibration #%d", seq.GetSequence()));
402 job3.SetSequence(seq);
403 job3.SetEnv(&env);
404 job3.SetEnvDebug(kDebugEnv);
405 job3.SetDisplay(d);
406 job3.SetOverwrite(kOverwrite);
407 job3.SetPathOut(kOutpathC);
408 job3.SetPathData(kInpathD);
409 job3.SetDataType(kDataType);
410 // job2.SetPathIn(kInpathC); // not yet needed
411
412 job3.SetBadPixels(job2.GetBadPixels());
413 job3.SetExtractor(job2.GetExtractor());
414 job3.SetExtractorCam(job2.GetPedestalCam());
415
416 if (!job3.ProcessFile(job1.GetPedestalCam()))
417 {
418 gLog << err << "Calculation of calibration failed." << endl << endl;
419 return -1;
420 }
421
422 if (kDebugEnv>0)
423 env.PrintUntouched();
424
425 if (!job3.GetDisplay())
426 {
427 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
428 return 1;
429 }
430
431 if (kUseTest)
432 {
433 MJCalibTest job4(Form("MJCalibTest #%d", seq.GetSequence()));
434 job4.SetBadPixels(job2.GetBadPixels());
435 job4.SetSequence(seq);
436 job4.SetEnv(&env);
437 job4.SetEnvDebug(kDebugEnv);
438 job4.SetDisplay(d);;
439 job4.SetOverwrite(kOverwrite);
440 job4.SetPathOut(kOutpathC);
441 job4.SetPathData(kInpathD);
442 job4.SetDataType(kDataType);
443
444 if (!job4.ProcessFile(job1.GetPedestalCam()))
445 {
446 gLog << err << "Calibration of calibration failed." << endl << endl;
447 return -1;
448 }
449
450 if (kDebugEnv>0)
451 env.PrintUntouched();
452
453 if (!job4.GetDisplay())
454 {
455 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
456 return 1;
457 }
458 }
459 }
460
461 if (kModeY)
462 {
463 d->Reset();
464
465 //
466 // Calculate starting pedestal for data extraction
467 //
468 MJPedestal job1(Form("MJPedestalY1 #%d", seq.GetSequence()));
469 job1.SetNoStorage();
470 job1.SetSequence(seq);
471 job1.SetEnv(&env);
472 job1.SetEnvDebug(kDebugEnv);
473 job1.SetDisplay(d);
474 job1.SetNoDisplay();
475 job1.SetOverwrite(kOverwrite);
476 job1.SetPathData(kInpathD);
477 job1.SetPathIn(kInpathY);
478 job1.SetDataType(kDataType);
479 //job1.SetPathOut(kOutpathY); // not yet needed
480 job1.SetUseData();
481 job1.SetExtractionFundamental();
482
483 if (!job1.ProcessFile())
484 {
485 gLog << err << "Calculation of fundamental pedestal failed." << endl << endl;
486 return -1;
487 }
488
489 if (!job1.GetDisplay())
490 {
491 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
492 return 1;
493 }
494
495 //
496 // Calculate pedestal and pedestal resolution
497 //
498 MJPedestal job2(Form("MJPedestalY2 #%d", seq.GetSequence()));
499 job2.SetNoStorage();
500 job2.SetSequence(seq);
501 job2.SetEnv(&env);
502 job2.SetEnvDebug(kDebugEnv);
503 job2.SetDisplay(d);
504 job2.SetNoDisplay();
505 job2.SetOverwrite(kOverwrite);
506 job2.SetPathData(kInpathD);
507 job2.SetPathIn(kInpathY);
508 job2.SetDataType(kDataType);
509 // job1.SetPathOut(kOutpathC); // not yet needed
510 // job1.SetPathIn(kInpathC); // not yet needed
511
512 job2.SetUseData();
513 job2.SetExtractionWithExtractor();
514 job2.SetExtractor(job1.GetExtractor());
515 job2.SetPedestals(job1.GetPedestalCam());
516 job2.SetBadPixels(job1.GetBadPixels());
517
518 if (!job2.ProcessFile())
519 {
520 gLog << err << "Calculation of pedestal from extrtactor (random) failed." << endl << endl;
521 return -1;
522 }
523
524 if (!job2.GetDisplay())
525 {
526 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
527 return 1;
528 }
529
530 //
531 // Calculate pedestal and pedestal resolution
532 //
533 MJPedestal job3(Form("MJPedestalY3 #%d", seq.GetSequence()));
534 job3.SetNoStorage();
535 job3.SetSequence(seq);
536 job3.SetEnv(&env);
537 job3.SetEnvDebug(kDebugEnv);
538 job3.SetDisplay(d);
539 job3.SetNoDisplay();
540 job3.SetOverwrite(kOverwrite);
541 job3.SetPathData(kInpathD);
542 job3.SetPathIn(kInpathY);
543 job3.SetDataType(kDataType);
544 // job1.SetPathOut(kOutpathC); // not yet needed
545 // job1.SetPathIn(kInpathC); // not yet needed
546
547 job3.SetUseData();
548 job3.SetExtractionWithExtractorRndm();
549 job3.SetExtractor(job1.GetExtractor());
550 job3.SetPedestals(job1.GetPedestalCam());
551 job3.SetBadPixels(job1.GetBadPixels());
552
553 if (!job3.ProcessFile())
554 {
555 gLog << err << "Calculation of pedestal from extractor failed." << endl << endl;
556 return -1;
557 }
558
559 if (!job3.GetDisplay())
560 {
561 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
562 return 1;
563 }
564
565 //
566 // Extract signal and calibrate it
567 //
568 MJCalibrateSignal job4(Form("MJCalibrateSignal #%d", seq.GetSequence()));
569 job4.SetSequence(seq);
570 job4.SetDisplay(d);;
571 job4.SetEnv(&env);
572 job4.SetEnvDebug(kDebugEnv);
573 job4.SetOverwrite(kOverwrite);
574 job4.SetPathIn(kInpathY);
575 job4.SetPathOut(kOutpathY);
576 job4.SetPathData(kInpathD);
577 job4.SetDataType(kDataType);
578
579 // Where to search for calibration files
580 if (!job4.ProcessFile(job1.GetPedestalCam(), job2.GetPedestalCam(), job3.GetPedestalCam()))
581 return -1;
582
583 if (kDebugEnv>0)
584 env.PrintUntouched();
585
586 if (!job4.GetDisplay())
587 {
588 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
589 return 1;
590 }
591 }
592
593 if (kBatch || kQuit)
594 delete d;
595 else
596 {
597 // From now on each 'Close' means: Terminate the application
598 d->SetBit(MStatusDisplay::kExitLoopOnClose);
599
600 // Wait until the user decides to exit the application
601 app.Run(kFALSE);
602 }
603
604 if (TObject::GetObjectStat())
605 {
606 TObject::SetObjectStat(kFALSE);
607 gObjectTable->Print();
608 }
609
610 return 0;
611}
612
Note: See TracBrowser for help on using the repository browser.