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

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