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

Last change on this file since 4909 was 4906, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 13.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 << " Input File Options:" << endl;
53 gLog << " -mc You must use this for MC files (PRELIMINARY)" << endl << endl;
54 gLog << " Options:" << endl;
55 gLog.Usage();
56 gLog << " --debug-env Debug setting resources from file" << 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=callistop.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
121 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
122 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
123 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
124 const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
125 const Bool_t kIsMC = arg.HasOnlyAndRemove("-mc");
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 //
201 // Setup sequence and check its validity
202 //
203 MSequence seq(kSequence);
204 if (kPrintSeq)
205 {
206 gLog << all;
207 gLog.Separator(kSequence);
208 seq.Print();
209 gLog << endl;
210 }
211 if (!seq.IsValid())
212 {
213 gLog << err << "Sequence read but not valid!" << endl << endl;
214 return -1;
215 }
216
217 //
218 // Process print options
219 //
220 if (kPrintFiles)
221 {
222 MDirIter Next1, Next2, Next3;
223 seq.SetupPedRuns(Next1, kInpathD);
224 seq.SetupCalRuns(Next2, kInpathD);
225 seq.SetupDatRuns(Next3, kInpathD);
226
227 gLog << all;
228 gLog.Separator("Pedestal Files");
229 Next1.Print("all");
230 gLog << endl;
231 gLog.Separator("Calibration Files");
232 Next2.Print("all");
233 gLog << endl;
234 gLog.Separator("Data Files");
235 Next3.Print("all");
236 gLog << endl;
237 }
238
239 //
240 // Check for existance of all files
241 //
242 MDirIter iter;
243 const Int_t n0 = seq.SetupAllRuns(iter, kInpathD);
244 const Int_t n1 = seq.GetNumAllRuns();
245 if (n0 != n1)
246 {
247 if (kForceExec)
248 gLog << warn << "WARNING";
249 else
250 gLog << err << "ERROR";
251 gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in ";
252 gLog << (kInpathD.IsNull() ? "<defaultpath>" : kInpathD.Data()) << endl;
253 if (!kForceExec)
254 return -1;
255 }
256
257 if (kPrintOnly)
258 return 0;
259
260 //
261 // Initialize root
262 //
263 MArray::Class()->IgnoreTObjectStreamer();
264 MParContainer::Class()->IgnoreTObjectStreamer();
265
266 TApplication app("Callisto", &argc, argv);
267 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
268 {
269 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
270 return 1;
271 }
272
273 //
274 // Update frequency by default = 1Hz
275 //
276 MStatusDisplay *d = new MStatusDisplay;
277
278 // From now on each 'Exit' means: Terminate the application
279 d->SetBit(MStatusDisplay::kExitLoopOnExit);
280 d->SetTitle(kSequence);
281
282 if (kModeC)
283 {
284 //
285 // Calculate pedestal for calibration
286 //
287 MJPedestal job1(Form("MJPedestalC #%d", seq.GetSequence()));
288 job1.SetSequence(seq);
289 job1.SetEnv(kConfig);
290 job1.SetEnvDebug(kDebugEnv);
291 job1.SetDisplay(d);;
292 job1.SetOverwrite(kOverwrite);
293 job1.SetPathData(kInpathD);
294 // job1.SetPathOut(kOutpathC); // not yet needed
295 // job1.SetPathIn(kInpathC); // not yet needed
296
297 if (!job1.ProcessFile())
298 {
299 gLog << err << "Calculation of pedestal failed." << endl << endl;
300 return -1;
301 }
302
303 if (!job1.GetDisplay())
304 {
305 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
306 return 1;
307 }
308
309 //
310 // Do calibration
311 //
312 MJCalibration job2(Form("MJCalibration #%d", seq.GetSequence()));
313 job2.SetSequence(seq);
314 job2.SetEnv(kConfig);
315 job2.SetEnvDebug(kDebugEnv);
316 job2.SetDisplay(d);;
317 job2.SetBadPixels(job1.GetBadPixels());
318 job2.SetOverwrite(kOverwrite);
319 job2.SetPathOut(kOutpathC);
320 job2.SetPathData(kInpathD);
321 // job2.SetPathIn(kInpathC); // not yet needed
322
323 if (!job2.ProcessFile(job1.GetPedestalCam()))
324 {
325 gLog << err << "Calculation of calibration failed." << endl << endl;
326 return -1;
327 }
328
329 if (!job2.GetDisplay())
330 {
331 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
332 return 1;
333 }
334 }
335
336 if (kModeY)
337 {
338 d->Reset();
339
340 //
341 // Calculate starting pedestal for data extraction
342 //
343 MJPedestal job1(Form("MJPedestalY #%d", seq.GetSequence()));
344 job1.SetSequence(seq);
345 job1.SetEnv(kConfig);
346 job1.SetEnvDebug(kDebugEnv);
347 job1.SetDisplay(d);;
348 //job1.SetPathIn(kInpathY); // not yet needed
349 //job1.SetPathOut(kOutpathY); // not yet needed
350 job1.SetPathData(kInpathD);
351 job1.SetOverwrite(kOverwrite);
352
353 if (!job1.ProcessFile())
354 {
355 gLog << err << "Calculation of pedestal failed." << endl << endl;
356 return -1;
357 }
358
359 if (!job1.GetDisplay())
360 {
361 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
362 return 1;
363 }
364
365 //
366 // Extract signal and calibrate it
367 //
368 MJCalibrateSignal job2(Form("MJCalibrateSignal #%d", seq.GetSequence()));
369 job2.SetSequence(seq);
370 job2.SetDisplay(d);;
371 job2.SetEnv(kConfig);
372 job2.SetEnvDebug(kDebugEnv);
373 job2.SetOverwrite(kOverwrite);
374 job2.SetPathIn(kInpathY);
375 job2.SetPathOut(kOutpathY);
376 job2.SetPathData(kInpathD);
377
378 // Where to search for calibration files
379 if (!job2.ProcessFile(job1.GetPedestalCam(), kIsMC))
380 return -1;
381
382 if (!job2.GetDisplay())
383 {
384 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
385 return 1;
386 }
387 }
388
389 if (kBatch || kQuit)
390 {
391 delete d;
392 return 0;
393 }
394
395 // From now on each 'Close' means: Terminate the application
396 d->SetBit(MStatusDisplay::kExitLoopOnClose);
397
398 // Wait until the user decides to exit the application
399 app.Run(kFALSE);
400 return 0;
401}
Note: See TracBrowser for help on using the repository browser.