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

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