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

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