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

Last change on this file since 5574 was 5570, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 15.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
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 // job1.SetPathOut(kOutpathC); // not yet needed
299 // job1.SetPathIn(kInpathC); // not yet needed
300
301 if (!job1.ProcessFile())
302 {
303 gLog << err << "Calculation of pedestal failed." << endl << endl;
304 return -1;
305 }
306
307 if (!job1.GetDisplay())
308 {
309 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
310 return 1;
311 }
312
313 //
314 // Calculate pedestal and pedestal resolution
315 //
316 MJPedestal job2(Form("MJPedestalC2 #%d", seq.GetSequence()));
317 job2.SetNoStorage();
318 job2.SetSequence(seq);
319 job2.SetEnv(kConfig);
320 job2.SetEnvDebug(kDebugEnv);
321 job2.SetDisplay(d);;
322 job2.SetOverwrite(kOverwrite);
323 job2.SetPathData(kInpathD);
324 // job1.SetPathOut(kOutpathC); // not yet needed
325 // job1.SetPathIn(kInpathC); // not yet needed
326
327 job2.SetExtractorResolution();
328 job2.SetExtractor(job1.GetExtractor());
329 job2.SetPedestals(job1.GetPedestalCam());
330 job2.SetBadPixels(job1.GetBadPixels());
331
332 if (!job2.ProcessFile())
333 {
334 gLog << err << "Calculation of pedestal resolution failed." << endl << endl;
335 return -1;
336 }
337
338 if (!job2.GetDisplay())
339 {
340 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
341 return 1;
342 }
343
344 //
345 // Do calibration
346 //
347 MJCalibration job3(Form("MJCalibration #%d", seq.GetSequence()));
348 job3.SetSequence(seq);
349 job3.SetEnv(kConfig);
350 job3.SetEnvDebug(kDebugEnv);
351 job3.SetDisplay(d);;
352 job3.SetOverwrite(kOverwrite);
353 job3.SetPathOut(kOutpathC);
354 job3.SetPathData(kInpathD);
355 // job2.SetPathIn(kInpathC); // not yet needed
356
357 job3.SetBadPixels(job2.GetBadPixels());
358 job3.SetExtractor(job2.GetExtractor());
359 job3.SetExtractorCam(job2.GetPedestalCam());
360
361 if (!job3.ProcessFile(job1.GetPedestalCam()))
362 {
363 gLog << err << "Calculation of calibration failed." << endl << endl;
364 return -1;
365 }
366
367 if (!job3.GetDisplay())
368 {
369 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
370 return 1;
371 }
372 }
373
374 if (kModeY)
375 {
376 d->Reset();
377
378 //
379 // Calculate starting pedestal for data extraction
380 //
381 MJPedestal job1(Form("MJPedestalY1 #%d", seq.GetSequence()));
382 job1.SetNoStorage();
383 job1.SetSequence(seq);
384 job1.SetEnv(kConfig);
385 job1.SetEnvDebug(kDebugEnv);
386 job1.SetDisplay(d);;
387 job1.SetOverwrite(kOverwrite);
388 job1.SetPathData(kInpathD);
389 job1.SetPathIn(kInpathY);
390 //job1.SetPathOut(kOutpathY); // not yet needed
391 job1.SetUseData();
392
393 if (!job1.ProcessFile())
394 {
395 gLog << err << "Calculation of pedestal failed." << endl << endl;
396 return -1;
397 }
398
399 if (!job1.GetDisplay())
400 {
401 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
402 return 1;
403 }
404
405 //
406 // Calculate pedestal and pedestal resolution
407 //
408 MJPedestal job2(Form("MJPedestalY2 #%d", seq.GetSequence()));
409 job2.SetNoStorage();
410 job2.SetSequence(seq);
411 job2.SetEnv(kConfig);
412 job2.SetEnvDebug(kDebugEnv);
413 job2.SetDisplay(d);;
414 job2.SetOverwrite(kOverwrite);
415 job2.SetPathData(kInpathD);
416 job1.SetPathIn(kInpathY);
417 // job1.SetPathOut(kOutpathC); // not yet needed
418 // job1.SetPathIn(kInpathC); // not yet needed
419
420 job2.SetUseData();
421 job2.SetExtractorResolution();
422 job2.SetExtractor(job1.GetExtractor());
423 job2.SetPedestals(job1.GetPedestalCam());
424 job2.SetBadPixels(job1.GetBadPixels());
425
426 if (!job2.ProcessFile())
427 {
428 gLog << err << "Calculation of pedestal resolution failed." << endl << endl;
429 return -1;
430 }
431
432 if (!job2.GetDisplay())
433 {
434 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
435 return 1;
436 }
437
438 //
439 // Extract signal and calibrate it
440 //
441 MJCalibrateSignal job3(Form("MJCalibrateSignal #%d", seq.GetSequence()));
442 job3.SetSequence(seq);
443 job3.SetDisplay(d);;
444 job3.SetEnv(kConfig);
445 job3.SetEnvDebug(kDebugEnv);
446 job3.SetOverwrite(kOverwrite);
447 job3.SetPathIn(kInpathY);
448 job3.SetPathOut(kOutpathY);
449 job3.SetPathData(kInpathD);
450
451 // Where to search for calibration files
452 if (!job3.ProcessFile(job1.GetPedestalCam(), job2.GetPedestalCam()))
453 return -1;
454
455 if (!job3.GetDisplay())
456 {
457 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
458 return 1;
459 }
460 }
461
462 if (kBatch || kQuit)
463 delete d;
464 else
465 {
466 // From now on each 'Close' means: Terminate the application
467 d->SetBit(MStatusDisplay::kExitLoopOnClose);
468
469 // Wait until the user decides to exit the application
470 app.Run(kFALSE);
471 }
472
473 if (TObject::GetObjectStat())
474 {
475 TObject::SetObjectStat(kFALSE);
476 gObjectTable->Print();
477 }
478
479 return 0;
480}
481
Note: See TracBrowser for help on using the repository browser.