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

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