source: tags/Mars-V2.1/ganymed.cc@ 10009

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