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

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