source: trunk/MagicSoft/Mars/ganymed.cc@ 8363

Last change on this file since 8363 was 8088, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 11.8 KB
Line 
1#include <TROOT.h>
2#include <TClass.h>
3#include <TSystem.h>
4#include <TGClient.h>
5#include <TApplication.h>
6#include <TObjectTable.h>
7
8#include "MLog.h"
9#include "MLogManip.h"
10
11#include "MEnv.h"
12#include "MArgs.h"
13#include "MArray.h"
14#include "MDirIter.h"
15
16#include "MStatusDisplay.h"
17
18#include "MDataSet.h"
19#include "MJCut.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 << " Ganymed - MARS V" << MARSVER << endl;
31 gLog << " MARS -- Gammas Are Now Your Most Exciting Discovery" << endl;
32 gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << 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 << " ganymed [options] dataset.txt|number" << endl << endl;
44 gLog << " Arguments:" << endl;
45 gLog << " dataset.txt: ASCII file defining a collection of sequences" << endl;
46 gLog << " number: The dataset number (using file in the datacenter)" << endl;
47 gLog << " For more details see MDataSet." << endl;
48 gLog << " Root Options:" << endl;
49 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
50 gLog << " Operation Mode:" << endl;
51 gLog << " -mc Monte Carlo dataset (no times)" << endl;
52 gLog << " --wobble Force wobble mode (overwrites dataset)" << endl;
53 gLog << " --no-wobble Force normal mode (overwrites dataset)" << endl << endl;
54 gLog << " Options:" << endl;
55 gLog.Usage();
56 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
57 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
58 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
59 gLog << " --debug-env=3 Debug setting resources from resource file" << endl;
60 gLog << " --debug-mem Debug memory usage" << endl << endl;
61 gLog << endl;
62 gLog << " -q Quit when job is finished" << endl;
63 gLog << " -f Force overwrite of existing files" << endl;
64 gLog << " --n=number Analysis number (required if not in dataset file)" << endl;
65 gLog << " --out=path Path to write the all output to [def=local path]" << endl;
66 gLog << " --ind=path Path to data/star files [default=datacenter path]" << endl;
67 gLog << " --ins=path Path to sequence files [default=datacenter path]" << endl;
68 gLog << " --outf=filename Filename for output file (eg. status display)" << endl;
69 gLog << " --sum[=filename] Enable writing of summary file (events after cut0)" << endl;
70// gLog << " --res[=filename] Enable writing of result file (surviving events)" << endl;
71 gLog << " --skip-res Disable writing of result events" << endl;
72 gLog << " --write-only Only write output files. No histograms filled." << endl;
73 gLog << " --print-ds Print Dataset information" << endl;
74 gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
75// gLog << " --full-display Show as many plots as possible" << endl;
76 gLog << " --config=ganymed.rc Resource file [default=ganymed.rc]" << endl;
77 gLog << endl;
78 gLog << " --version, -V Show startup message with version number" << endl;
79 gLog << " -?, -h, --help This help" << endl << endl;
80 gLog << "Background:" << endl;
81 gLog << " Ganymed is the largest moon of Jupiter, a large, icy, outer moon that" << endl;
82 gLog << " is scarred with impact craters and many parallel faults. It has a" << endl;
83 gLog << " diameter of about 5268km and orbits Jupiter at a mean distance of" << endl;
84 gLog << " 1,070,000km. It has a magnetic field and probably has a molten iron" << endl;
85 gLog << " core. It takes Ganymed 7.15 days to orbit Jupiter. Its mass is" << endl;
86 gLog << " 1.5e23kg. It was independently discovered by Galileo and S.Marius in"<< endl;
87 gLog << " 1610. Ganymed is the largest moon in the solar system; it is also" << endl;
88 gLog << " larger than the planets Mercury and Pluto." << endl << endl;
89}
90
91int main(int argc, char **argv)
92{
93 if (!MARS::CheckRootVer())
94 return 0xff;
95
96 MLog::RedirectErrorHandler(MLog::kColor);
97
98 //
99 // Evaluate arguments
100 //
101 MArgs arg(argc, argv, kTRUE);
102 gLog.Setup(arg);
103
104 StartUpMessage();
105
106 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
107 return 0;
108
109 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
110 {
111 Usage();
112 return 2;
113 }
114
115 const TString kConfig = arg.GetStringAndRemove("--config=", "ganymed.rc");
116
117 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-ds");
118 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
119 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
120 const Bool_t kWriteOnly = arg.HasOnlyAndRemove("--write-only");
121// const Bool_t kFullDisplay = arg.HasOnlyAndRemove("--full-display");
122 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
123 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
124
125 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
126 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
127 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
128 //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
129
130 const Bool_t kIsMc = arg.HasOnlyAndRemove("-mc");
131 const Bool_t kWobbleModeOn = arg.HasOnlyAndRemove("--wobble");
132 const Bool_t kWobbleModeOff = arg.HasOnlyAndRemove("--no-wobble");
133
134 const Int_t kNumAnalysis = arg.GetIntAndRemove("--n=", -1);
135 const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
136 const TString kOutfile = arg.GetStringAndRemove("--outf=", "");
137 const TString kPathDataFiles = arg.GetStringAndRemove("--ind=", "");
138 const TString kPathSequences = arg.GetStringAndRemove("--ins=", "");
139 const Bool_t kWriteSummary = arg.HasOnlyAndRemove("--sum");
140 const TString kNameSummary = arg.GetStringAndRemove("--sum=");
141 const Bool_t kSkipResult = arg.HasOnlyAndRemove("--skip-res");
142// const Bool_t kWriteResult = arg.HasOnlyAndRemove("--res");
143// const TString kNameResult = arg.GetStringAndRemove("--res=");
144
145 if (kWobbleModeOn && kWobbleModeOff)
146 {
147 gLog << err << "ERROR - Wobble mode options are exclusive." << endl;
148 Usage();
149 return 2;
150 }
151
152 if (arg.GetNumOptions()>0)
153 {
154 gLog << warn << "WARNING - Unknown command-line options..." << endl;
155 arg.Print("options");
156 gLog << endl;
157 return 2;
158 }
159
160 //
161 // check for the right usage of the program
162 //
163 if (arg.GetNumArguments()!=1)
164 {
165 Usage();
166 return 2;
167 }
168
169 //
170 // Setup sequence file and check for its existence
171 //
172 TString kSequences = arg.GetArgumentStr(0);
173
174 //
175 // Something special for datacenter access
176 //
177 if (kSequences.IsDigit())
178 {
179 const Int_t numseq = kSequences.Atoi();
180 kSequences = Form("/magic/datasets/%05d/dataset%08d.txt", numseq/1000, numseq);
181 gLog << inf << "inflated dataset file: " << kSequences << endl;
182 }
183
184 if (gSystem->AccessPathName(kSequences, kFileExists))
185 {
186 gLog << err << "Sorry, dataset file '" << kSequences << "' doesn't exist." << endl;
187 return 2;
188 }
189
190 if (gSystem->AccessPathName(kConfig, kFileExists))
191 {
192 gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl;
193 return 2;
194 }
195
196 if (kDebugMem)
197 TObject::SetObjectStat(kTRUE);
198
199 //
200 // Setup sequence and check its validity
201 //
202 MDataSet seq(kSequences, kPathSequences, kPathDataFiles);
203 if (kNumAnalysis>=0)
204 seq.SetNumAnalysis(kNumAnalysis);
205 if (kPrintSeq || kPrintFiles)
206 {
207 gLog << all;
208 gLog.Separator(kSequences);
209 seq.Print(kPrintFiles?"files":"");
210 gLog << endl;
211 }
212 if (!seq.IsValid())
213 {
214 gLog << err << "Dataset read but not valid (maybe analysis number not set)!" << endl << endl;
215 return 2;
216 }
217
218 //
219 // Initialize root
220 //
221 MArray::Class()->IgnoreTObjectStreamer();
222 MParContainer::Class()->IgnoreTObjectStreamer();
223
224 TApplication app("ganymed", &argc, argv);
225 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
226 {
227 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
228 return 1;
229 }
230
231 Bool_t iswobble = seq.IsWobbleMode();
232 if (kWobbleModeOn)
233 iswobble = kTRUE;
234 if (kWobbleModeOff)
235 iswobble = kFALSE;
236
237 //
238 // Update frequency by default = 1Hz
239 //
240 MStatusDisplay *d = new MStatusDisplay;
241
242 // From now on each 'Exit' means: Terminate the application
243 d->SetBit(MStatusDisplay::kExitLoopOnExit);
244 d->SetTitle(kSequences);
245
246 //
247 // Calculate pedestal for pedestal-calculation and calibration
248 //
249 MEnv env(kConfig);
250 if (!env.IsValid())
251 {
252 gLog << err << "Configuration file " << kConfig << " not found." << endl;
253 return 0xfe;
254 }
255
256 MJCut job(Form("MJCut #%d", seq.GetNumAnalysis()));
257 job.SetEnv(&env);
258 job.SetEnvDebug(kDebugEnv);
259 job.SetDisplay(d);;
260 job.SetOverwrite(kOverwrite);
261 job.SetPathOut(kOutpath);
262 job.SetNameOutFile(kOutfile);
263 job.SetNameSummaryFile(kNameSummary);
264 //job.SetNameResultFile(kNameResult);
265 job.EnableWriteOnly(kWriteOnly);
266 job.EnableWobbleMode(iswobble);
267 //if (kFullDisplay)
268 // job.EnableFullDisplay(kFullDisplay);
269 job.EnableMonteCarloMode(kIsMc);
270 job.EnableStorageOfResult(!kSkipResult);
271 if (kWriteSummary) // Don't change flag set in SetNameSummaryFile
272 job.EnableStorageOfSummary();
273 //if (kWriteResult) // Don't change flag set in SetNameSummaryFile
274 // job.EnableStorageOfResult();
275
276 const Int_t rc = job.Process(seq);
277 if (rc<=0)
278 {
279 gLog << err << "Calculation of cuts failed." << endl << endl;
280
281 //error coding for the automatic analysis (to be filled into the database)
282 switch (rc)
283 {
284 case 0: // MJCut failed
285 return 3;
286 case -1: // Source not found
287 return 4;
288 case -2: // FillRndSrcCam failed
289 return 5;
290 case -3: // Processing off-data failed
291 return 6;
292 case -4: // Processing on-data failed
293 return 7;
294 }
295 return 2;
296 }
297
298 if (kDebugEnv>0)
299 env.PrintUntouched();
300
301 if (!job.GetDisplay())
302 {
303 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
304 return 1;
305 }
306
307 if (kBatch || kQuit)
308 delete d;
309 else
310 {
311 // From now on each 'Close' means: Terminate the application
312 d->SetBit(MStatusDisplay::kExitLoopOnClose);
313
314 // Wait until the user decides to exit the application
315 app.Run(kFALSE);
316 }
317
318 if (TObject::GetObjectStat())
319 {
320 TObject::SetObjectStat(kFALSE);
321 gObjectTable->Print();
322 }
323
324 return 0;
325}
Note: See TracBrowser for help on using the repository browser.