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

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