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

Last change on this file since 5504 was 5387, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 13.3 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 calibration
283 //
284 MJPedestal job1(Form("MJPedestalC #%d", seq.GetSequence()));
285 job1.SetSequence(seq);
286 job1.SetEnv(kConfig);
287 job1.SetEnvDebug(kDebugEnv);
288 job1.SetDisplay(d);;
289 job1.SetOverwrite(kOverwrite);
290 job1.SetPathData(kInpathD);
291 // job1.SetPathOut(kOutpathC); // not yet needed
292 // job1.SetPathIn(kInpathC); // not yet needed
293
294 if (!job1.ProcessFile())
295 {
296 gLog << err << "Calculation of pedestal failed." << endl << endl;
297 return -1;
298 }
299
300 if (!job1.GetDisplay())
301 {
302 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
303 return 1;
304 }
305
306 //
307 // Do calibration
308 //
309 MJCalibration job2(Form("MJCalibration #%d", seq.GetSequence()));
310 job2.SetSequence(seq);
311 job2.SetEnv(kConfig);
312 job2.SetEnvDebug(kDebugEnv);
313 job2.SetDisplay(d);;
314 job2.SetBadPixels(job1.GetBadPixels());
315 job2.SetOverwrite(kOverwrite);
316 job2.SetPathOut(kOutpathC);
317 job2.SetPathData(kInpathD);
318 // job2.SetPathIn(kInpathC); // not yet needed
319
320 if (!job2.ProcessFile(job1.GetPedestalCam()))
321 {
322 gLog << err << "Calculation of calibration failed." << endl << endl;
323 return -1;
324 }
325
326 if (!job2.GetDisplay())
327 {
328 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
329 return 1;
330 }
331 }
332
333 if (kModeY)
334 {
335 d->Reset();
336
337 //
338 // Calculate starting pedestal for data extraction
339 //
340 MJPedestal job1(Form("MJPedestalY #%d", seq.GetSequence()));
341 job1.SetSequence(seq);
342 job1.SetEnv(kConfig);
343 job1.SetEnvDebug(kDebugEnv);
344 job1.SetDisplay(d);;
345 job1.SetPathIn(kInpathY);
346 //job1.SetPathOut(kOutpathY); // not yet needed
347 job1.SetPathData(kInpathD);
348 job1.SetOverwrite(kOverwrite);
349
350 if (!job1.ProcessFile())
351 {
352 gLog << err << "Calculation of pedestal failed." << endl << endl;
353 return -1;
354 }
355
356 if (!job1.GetDisplay())
357 {
358 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
359 return 1;
360 }
361
362 //
363 // Extract signal and calibrate it
364 //
365 MJCalibrateSignal job2(Form("MJCalibrateSignal #%d", seq.GetSequence()));
366 job2.SetSequence(seq);
367 job2.SetDisplay(d);;
368 job2.SetEnv(kConfig);
369 job2.SetEnvDebug(kDebugEnv);
370 job2.SetOverwrite(kOverwrite);
371 job2.SetPathIn(kInpathY);
372 job2.SetPathOut(kOutpathY);
373 job2.SetPathData(kInpathD);
374
375 // Where to search for calibration files
376 if (!job2.ProcessFile(job1.GetPedestalCam()))
377 return -1;
378
379 if (!job2.GetDisplay())
380 {
381 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
382 return 1;
383 }
384 }
385
386 if (kBatch || kQuit)
387 {
388 delete d;
389 return 0;
390 }
391
392 // From now on each 'Close' means: Terminate the application
393 d->SetBit(MStatusDisplay::kExitLoopOnClose);
394
395 // Wait until the user decides to exit the application
396 app.Run(kFALSE);
397 return 0;
398}
Note: See TracBrowser for help on using the repository browser.