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

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