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

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