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

Last change on this file since 4732 was 4732, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 10.8 KB
Line 
1#include <TROOT.h>
2#include <TClass.h>
3#include <TGClient.h>
4#include <TApplication.h>
5
6#include "MLog.h"
7#include "MLogManip.h"
8
9#include "MArgs.h"
10#include "MArray.h"
11#include "MDirIter.h"
12
13#include "MStatusDisplay.h"
14
15#include "MSequence.h"
16#include "MJPedestal.h"
17#include "MJCalibration.h"
18#include "MJCalibrateSignal.h"
19
20using namespace std;
21
22static void StartUpMessage()
23{
24 gLog << all << endl;
25
26 // 1 2 3 4 5
27 // 12345678901234567890123456789012345678901234567890
28 gLog << "========================================================" << endl;
29 gLog << " Callisto - MARS V" << MARSVER << endl;
30 gLog << " MARS -- CALibrate LIght Signals and Time Offsets" << endl;
31 gLog << " Compiled on <" << __DATE__ << ">" << endl;
32 gLog << " Using ROOT v" << ROOTVER << endl;
33 gLog << "========================================================" << endl;
34 gLog << endl;
35}
36
37static void Usage()
38{
39 // 1 2 3 4 5 6 7 8
40 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
41 gLog << all << endl;
42 gLog << "Sorry the usage is:" << endl;
43 gLog << " callisto [-c] [-y] [options] sequence.txt" << endl << endl;
44 gLog << " Arguments:" << endl;
45 gLog << " sequence.txt: An ascii file defining a sequence of runs" << endl;
46 gLog << " Root Options:" << endl;
47 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
48 gLog << " Operation Modes:" << endl;
49 gLog << " -c Calculate the calibration constants" << endl;
50 gLog << " -y Extract and calibrate signal" << endl << endl;
51 gLog << " Options:" << endl;
52 gLog.Usage();
53 gLog << " --debug-env Debug setting resources from file" << endl << endl;
54 gLog << endl;
55 gLog << " -f Force overwrite of existing files" << endl;
56 gLog << " --ind=path Path where to search for the data files" << endl;
57 gLog << " [default=standard path in datacenter]" << endl;
58 gLog << " --iny=path Path where to search for the calibration files" << endl;
59 gLog << " [default=local path or output path of Mode-C]" << endl;
60 gLog << " --outc=path Path to write Mode-C result to [def=local path]" << endl;
61 gLog << " --outy=path Path to write Mode-Y result to [def=local path]" << endl;
62 gLog << " --out=path Path to write the all results to [def=local path]" << endl;
63 gLog << " (overwrites --outc and --outy)" << endl;
64 gLog << " --path=path Path to write the all results to [def=local path]" << endl;
65 gLog << " (overwrites --iny, --outc and --outy)" << endl;
66 gLog << " --print-seq Print Sequence information" << endl;
67 gLog << " --print-files Print Files taken from Sequence" << endl;
68 gLog << " --print-only Do not excute anything except print" << endl;
69 gLog << " --config=callisto.rc Resource file [default=callistop.rc]" << endl;
70 gLog << endl;
71 gLog << " -?, -h, --help This help" << endl << endl;
72 gLog << " Setup of the two jobs run by callisto (MJPedestal and MJCalibration)" << endl;
73 gLog << " can be done with the resource file. See MJPedestal and MJCalibration" << endl;
74 gLog << " especially CheckEnv() for more details. Command line options might" << endl;
75 gLog << " be overwritten by the resource file." << endl << endl;
76 gLog << " If running in Mode-C and Mode-Y --iny= is obsolete, instead --outc=" << endl;
77 gLog << " is used." << endl << endl;
78 gLog << "Description:" << endl;
79 gLog << " callisto will calculate pedestals from pedestal-files defined in a" << endl;
80 gLog << " sequence-file. This pedestals are used to calculate the calibration" << endl;
81 gLog << " contants. These constants are stored in a so called calibration-file" << endl;
82 gLog << " together with some datacheck plots which can be viewed using either" << endl;
83 gLog << " showplot or MStatusDisplay in the interpreter." << endl;
84 gLog << endl;
85}
86
87int main(int argc, char **argv)
88{
89 StartUpMessage();
90
91 //
92 // Evaluate arguments
93 //
94 MArgs arg(argc, argv);
95
96 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
97 {
98 Usage();
99 return -1;
100 }
101
102 gLog.Setup(arg);
103
104 const TString kConfig = arg.GetStringAndRemove("--config=", "callisto.rc");
105
106 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
107 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
108 const Bool_t kPrintOnly = arg.HasOnlyAndRemove("--print-only");
109 const Bool_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env");
110
111 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
112
113 const TString kInpathD = arg.GetStringAndRemove("--ind=", "");
114 TString kInpathY = arg.GetStringAndRemove("--iny=", ".");
115 TString kOutpathY = arg.GetStringAndRemove("--outy=", ".");
116 TString kOutpathC = arg.GetStringAndRemove("--outc=", ".");
117 const TString kOutpath = arg.GetStringAndRemove("--out=", "");
118 const TString kPath = arg.GetStringAndRemove("--path=", "");
119
120 const Bool_t kModeC = arg.HasOnlyAndRemove("-c");
121 const Bool_t kModeY = arg.HasOnlyAndRemove("-y");
122
123 if (!kModeC && !kModeY)
124 {
125 gLog << err << "Neither calibration (-c) nor signal extraction (-y) mode specified!" << endl;
126 Usage();
127 return 0;
128 }
129 if (!kOutpath.IsNull())
130 {
131 kOutpathC = kOutpath;
132 kOutpathY = kOutpath;
133 }
134 if (!kPath.IsNull())
135 {
136 kOutpathC = kOutpath;
137 kOutpathY = kOutpath;
138 kInpathY = kOutpath;
139 }
140
141 if (kModeC && kModeY)
142 kInpathY = kOutpathC;
143
144 if (arg.GetNumOptions()>0)
145 {
146 gLog << warn << "WARNING - Unknown commandline options..." << endl;
147 arg.Print("options");
148 gLog << endl;
149 }
150
151 //
152 // check for the right usage of the program
153 //
154 if (arg.GetNumArguments()!=1)
155 {
156 Usage();
157 return -1;
158 }
159
160 const TString kSequence = arg.GetArgumentStr(0);
161
162 TApplication app("Callisto", &argc, argv);
163 if (gROOT->IsBatch() || !gClient)
164 {
165 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
166 return 1;
167 }
168
169 MSequence seq(kSequence);
170 if (kPrintSeq)
171 {
172 gLog << all;
173 gLog.Separator(kSequence);
174 seq.Print();
175 gLog << endl;
176 }
177 if (!seq.IsValid())
178 {
179 gLog << err << "Sequence invalid!" << endl << endl;
180 return -1;
181 }
182
183 if (kPrintFiles)
184 {
185 MDirIter Next1, Next2, Next3;
186 seq.SetupPedRuns(Next1, kInpathD);
187 seq.SetupCalRuns(Next2, kInpathD);
188 seq.SetupDatRuns(Next3, kInpathD);
189
190 gLog << all;
191 gLog.Separator("Pedestal Files");
192 Next1.Print("all");
193 gLog << endl;
194 gLog.Separator("Calibration Files");
195 Next2.Print("all");
196 gLog << endl;
197 gLog.Separator("Data Files");
198 Next3.Print("all");
199 gLog << endl;
200 }
201
202 if (kPrintOnly)
203 return 0;
204
205 MArray::Class()->IgnoreTObjectStreamer();
206 MParContainer::Class()->IgnoreTObjectStreamer();
207
208 //
209 // Update frequency by default = 1Hz
210 //
211 MStatusDisplay *d = new MStatusDisplay;
212
213 // From now on each 'Exit' means: Terminate the application
214 d->SetBit(MStatusDisplay::kExitLoopOnExit);
215 d->SetTitle(kSequence);
216
217 if (kModeC)
218 {
219 MJPedestal job1(Form("MJPedestalC #%d", seq.GetSequence()));
220 job1.SetSequence(seq);
221 job1.SetEnv(kConfig);
222 job1.SetEnvDebug(kDebugEnv);
223 job1.SetDisplay(d);;
224 job1.SetOverwrite(kOverwrite);
225 job1.SetPathData(kInpathD);
226 // job1.SetPathOut(kOutpathC); // not yet needed
227 // job1.SetPathIn(kInpathC); // not yet needed
228
229 if (!job1.ProcessFile())
230 {
231 gLog << err << "Calculation of pedestal failed." << endl << endl;
232 return -1;
233 }
234
235 if (!job1.GetDisplay())
236 {
237 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
238 return 1;
239 }
240
241 MJCalibration job2(Form("MJCalibration #%d", seq.GetSequence()));
242 job2.SetSequence(seq);
243 job2.SetEnv(kConfig);
244 job2.SetEnvDebug(kDebugEnv);
245 job2.SetDisplay(d);;
246 job2.SetBadPixels(job1.GetBadPixels());
247 job2.SetOverwrite(kOverwrite);
248 job2.SetPathOut(kOutpathC);
249 job2.SetPathData(kInpathD);
250 // job2.SetPathIn(kInpathC); // not yet needed
251
252 if (!job2.ProcessFile(job1.GetPedestalCam()))
253 {
254 gLog << err << "Calculation of calibration failed." << endl << endl;
255 return -1;
256 }
257
258 if (!job2.GetDisplay())
259 {
260 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
261 return 1;
262 }
263
264 gLog << endl << endl;
265 }
266
267 if (kModeY)
268 {
269 d->Reset();
270
271 MJPedestal job1(Form("MJPedestalY #%d", seq.GetSequence()));
272 job1.SetSequence(seq);
273 job1.SetEnv(kConfig);
274 job1.SetEnvDebug(kDebugEnv);
275 job1.SetDisplay(d);;
276 //job1.SetPathIn(kInpathY); // not yet needed
277 //job1.SetPathOut(kOutpathY); // not yet needed
278 job1.SetPathData(kInpathD);
279 job1.SetOverwrite(kOverwrite);
280
281 if (!job1.ProcessFile())
282 {
283 gLog << err << "Calculation of pedestal failed." << endl << endl;
284 return -1;
285 }
286
287 if (!job1.GetDisplay())
288 {
289 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
290 return 1;
291 }
292
293 MJCalibrateSignal job2(Form("MJCalibrateSignal #%d", seq.GetSequence()));
294 job2.SetSequence(seq);
295 job2.SetDisplay(d);;
296 job2.SetEnv(kConfig);
297 job2.SetEnvDebug(kDebugEnv);
298 job2.SetOverwrite(kOverwrite);
299 job2.SetPathIn(kInpathY);
300 job2.SetPathOut(kOutpathY);
301 job2.SetPathData(kInpathD);
302
303 // Where to search for calibration files
304 if (!job2.ProcessFile(job1.GetPedestalCam()))
305 return -1;
306
307 if (!job2.GetDisplay())
308 {
309 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
310 return 1;
311 }
312
313 gLog << endl << endl;
314 }
315
316 // From now on each 'Close' means: Terminate the application
317 d->SetBit(MStatusDisplay::kExitLoopOnClose);
318
319 // Wait until the user decides to exit the application
320 app.Run(kFALSE);
321 return 0;
322}
Note: See TracBrowser for help on using the repository browser.