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

Last change on this file since 4781 was 4766, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 12.9 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 << " -f Force overwrite of existing files" << endl;
57 gLog << " -ff Force execution if not all files found" << endl;
58 gLog << " --ind=path Path where to search for the data files" << endl;
59 gLog << " [default=standard path in datacenter]" << endl;
60 gLog << " --iny=path Path where to search for the calibration files" << endl;
61 gLog << " [default=local path or output path of Mode-C]" << endl;
62 gLog << " --outc=path Path to write Mode-C result to [def=local path]" << endl;
63 gLog << " --outy=path Path to write Mode-Y result to [def=local path]" << endl;
64 gLog << " --out=path Path to write the all results to [def=local path]" << endl;
65 gLog << " (overwrites --outc and --outy)" << endl;
66 gLog << " --path=path Path to write the all results to [def=local path]" << endl;
67 gLog << " (overwrites --iny, --outc and --outy)" << endl;
68 gLog << " --print-seq Print Sequence information" << endl;
69 gLog << " --print-files Print Files taken from Sequence" << endl;
70 gLog << " --print-only Do not excute anything except print" << endl;
71 gLog << " --config=callisto.rc Resource file [default=callistop.rc]" << endl;
72 gLog << endl;
73 gLog << " -?, -h, --help This help" << endl << endl;
74 gLog << " Setup of the two jobs run by callisto (MJPedestal and MJCalibration)" << endl;
75 gLog << " can be done with the resource file. See MJPedestal and MJCalibration" << endl;
76 gLog << " especially CheckEnv() for more details. Command line options might" << endl;
77 gLog << " be overwritten by the resource file." << endl << endl;
78 gLog << " If running in Mode-C and Mode-Y --iny= is obsolete, instead --outc=" << endl;
79 gLog << " is used." << endl << endl;
80 gLog << " Using --iny=, --outc=, --outy=, --out= or --path= automatically" << endl;
81 gLog << " enables the corresponmding modes. In this case -c/-y are obsolete." << endl << endl;
82 gLog << "Description:" << endl;
83 gLog << " callisto will calculate pedestals from pedestal-files defined in a" << endl;
84 gLog << " sequence-file. This pedestals are used to calculate the calibration" << endl;
85 gLog << " contants. These constants are stored in a so called calibration-file" << endl;
86 gLog << " together with some datacheck plots which can be viewed using either" << endl;
87 gLog << " showplot or MStatusDisplay in the interpreter." << endl << endl;
88 gLog << "Example:" << endl;
89 gLog << " callisto -f --outc=mycal/ --outy=mysignal/ --log sequence02345.txt" << endl;
90 gLog << endl;
91}
92
93int main(int argc, char **argv)
94{
95 StartUpMessage();
96
97 //
98 // Evaluate arguments
99 //
100 MArgs arg(argc, argv);
101
102 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
103 {
104 Usage();
105 return -1;
106 }
107
108 gLog.Setup(arg);
109
110 const TString kConfig = arg.GetStringAndRemove("--config=", "callisto.rc");
111
112 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
113 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
114 const Bool_t kPrintOnly = arg.HasOnlyAndRemove("--print-only");
115 const Bool_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env");
116
117 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
118 const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
119
120 const TString kInpathD = arg.GetStringAndRemove("--ind=", "");
121 TString kInpathY = arg.GetStringAndRemove("--iny=", "");
122 TString kOutpathY = arg.GetStringAndRemove("--outy=", "");
123 TString kOutpathC = arg.GetStringAndRemove("--outc=", "");
124 const TString kOutpath = arg.GetStringAndRemove("--out=", "");
125 const TString kPath = arg.GetStringAndRemove("--path=", "");
126
127 Bool_t kModeC = arg.HasOnlyAndRemove("-c");
128 Bool_t kModeY = arg.HasOnlyAndRemove("-y");
129
130 if (!kInpathY.IsNull() || !kOutpathY.IsNull() || !kOutpath.IsNull() || !kPath.IsNull())
131 kModeY = kTRUE;
132 if (!kOutpathC.IsNull() || !kOutpath.IsNull() || !kPath.IsNull())
133 kModeC = kTRUE;
134
135 if (!kModeC && !kModeY)
136 {
137 gLog << err << "Neither calibration (-c) nor signal extraction (-y) mode specified!" << endl;
138 Usage();
139 return 0;
140 }
141
142 if (kModeC && kOutpathC.IsNull())
143 kOutpathC = ".";
144 if (kModeY)
145 {
146 if (kInpathY.IsNull())
147 kInpathY = ".";
148 if (kOutpathY.IsNull())
149 kOutpathY = ".";
150 }
151 if (!kOutpath.IsNull())
152 {
153 kOutpathC = kOutpath;
154 kOutpathY = kOutpath;
155 }
156 if (!kPath.IsNull())
157 {
158 kOutpathC = kOutpath;
159 kOutpathY = kOutpath;
160 kInpathY = kOutpath;
161 }
162
163 if (kModeC && kModeY)
164 kInpathY = kOutpathC;
165
166 if (arg.GetNumOptions()>0)
167 {
168 gLog << warn << "WARNING - Unknown commandline options..." << endl;
169 arg.Print("options");
170 gLog << endl;
171 }
172
173 //
174 // check for the right usage of the program
175 //
176 if (arg.GetNumArguments()!=1)
177 {
178 Usage();
179 return -1;
180 }
181
182 //
183 // Setup sequence file and check for its existance
184 //
185 const TString kSequence = arg.GetArgumentStr(0);
186
187 if (gSystem->AccessPathName(kSequence, kFileExists))
188 {
189 gLog << err << "Sorry, sequence file '" << kSequence << "' doesn't exist." << endl;
190 return -1;
191 }
192
193 //
194 // Setup sequence and check its validity
195 //
196 MSequence seq(kSequence);
197 if (kPrintSeq)
198 {
199 gLog << all;
200 gLog.Separator(kSequence);
201 seq.Print();
202 gLog << endl;
203 }
204 if (!seq.IsValid())
205 {
206 gLog << err << "Sequence read but not valid!" << endl << endl;
207 return -1;
208 }
209
210 //
211 // Process print options
212 //
213 if (kPrintFiles)
214 {
215 MDirIter Next1, Next2, Next3;
216 seq.SetupPedRuns(Next1, kInpathD);
217 seq.SetupCalRuns(Next2, kInpathD);
218 seq.SetupDatRuns(Next3, kInpathD);
219
220 gLog << all;
221 gLog.Separator("Pedestal Files");
222 Next1.Print("all");
223 gLog << endl;
224 gLog.Separator("Calibration Files");
225 Next2.Print("all");
226 gLog << endl;
227 gLog.Separator("Data Files");
228 Next3.Print("all");
229 gLog << endl;
230 }
231
232 //
233 // Check for existance of all files
234 //
235 MDirIter iter;
236 const Int_t n0 = seq.SetupAllRuns(iter, kInpathD);
237 const Int_t n1 = seq.GetNumAllRuns();
238 if (n0 != n1)
239 {
240 if (kForceExec)
241 gLog << warn << "WARNING";
242 else
243 gLog << err << "ERROR";
244 gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in ";
245 gLog << (kInpathD.IsNull() ? "<defaultpath>" : kInpathD.Data()) << endl;
246 if (!kForceExec)
247 return -1;
248 }
249
250 if (kPrintOnly)
251 return 0;
252
253 //
254 // Initialize root
255 //
256 MArray::Class()->IgnoreTObjectStreamer();
257 MParContainer::Class()->IgnoreTObjectStreamer();
258
259 TApplication app("Callisto", &argc, argv);
260 if (!gROOT->IsBatch() && !gClient)
261 {
262 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
263 return 1;
264 }
265
266 //
267 // Update frequency by default = 1Hz
268 //
269 MStatusDisplay *d = new MStatusDisplay;
270
271 // From now on each 'Exit' means: Terminate the application
272 d->SetBit(MStatusDisplay::kExitLoopOnExit);
273 d->SetTitle(kSequence);
274
275 if (kModeC)
276 {
277 //
278 // Calculate pedestal for calibration
279 //
280 MJPedestal job1(Form("MJPedestalC #%d", seq.GetSequence()));
281 job1.SetSequence(seq);
282 job1.SetEnv(kConfig);
283 job1.SetEnvDebug(kDebugEnv);
284 job1.SetDisplay(d);;
285 job1.SetOverwrite(kOverwrite);
286 job1.SetPathData(kInpathD);
287 // job1.SetPathOut(kOutpathC); // not yet needed
288 // job1.SetPathIn(kInpathC); // not yet needed
289
290 if (!job1.ProcessFile())
291 {
292 gLog << err << "Calculation of pedestal failed." << endl << endl;
293 return -1;
294 }
295
296 if (!job1.GetDisplay())
297 {
298 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
299 return 1;
300 }
301
302 //
303 // Do calibration
304 //
305 MJCalibration job2(Form("MJCalibration #%d", seq.GetSequence()));
306 job2.SetSequence(seq);
307 job2.SetEnv(kConfig);
308 job2.SetEnvDebug(kDebugEnv);
309 job2.SetDisplay(d);;
310 job2.SetBadPixels(job1.GetBadPixels());
311 job2.SetOverwrite(kOverwrite);
312 job2.SetPathOut(kOutpathC);
313 job2.SetPathData(kInpathD);
314 // job2.SetPathIn(kInpathC); // not yet needed
315
316 if (!job2.ProcessFile(job1.GetPedestalCam()))
317 {
318 gLog << err << "Calculation of calibration failed." << endl << endl;
319 return -1;
320 }
321
322 if (!job2.GetDisplay())
323 {
324 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
325 return 1;
326 }
327 }
328
329 if (kModeY)
330 {
331 d->Reset();
332
333 //
334 // Calculate starting pedestal for data extraction
335 //
336 MJPedestal job1(Form("MJPedestalY #%d", seq.GetSequence()));
337 job1.SetSequence(seq);
338 job1.SetEnv(kConfig);
339 job1.SetEnvDebug(kDebugEnv);
340 job1.SetDisplay(d);;
341 //job1.SetPathIn(kInpathY); // not yet needed
342 //job1.SetPathOut(kOutpathY); // not yet needed
343 job1.SetPathData(kInpathD);
344 job1.SetOverwrite(kOverwrite);
345
346 if (!job1.ProcessFile())
347 {
348 gLog << err << "Calculation of pedestal failed." << endl << endl;
349 return -1;
350 }
351
352 if (!job1.GetDisplay())
353 {
354 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
355 return 1;
356 }
357
358 //
359 // Extract signal and calibrate it
360 //
361 MJCalibrateSignal job2(Form("MJCalibrateSignal #%d", seq.GetSequence()));
362 job2.SetSequence(seq);
363 job2.SetDisplay(d);;
364 job2.SetEnv(kConfig);
365 job2.SetEnvDebug(kDebugEnv);
366 job2.SetOverwrite(kOverwrite);
367 job2.SetPathIn(kInpathY);
368 job2.SetPathOut(kOutpathY);
369 job2.SetPathData(kInpathD);
370
371 // Where to search for calibration files
372 if (!job2.ProcessFile(job1.GetPedestalCam()))
373 return -1;
374
375 if (!job2.GetDisplay())
376 {
377 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
378 return 1;
379 }
380 }
381
382 // From now on each 'Close' means: Terminate the application
383 d->SetBit(MStatusDisplay::kExitLoopOnClose);
384
385 // Wait until the user decides to exit the application
386 app.Run(kFALSE);
387 return 0;
388}
Note: See TracBrowser for help on using the repository browser.