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

Last change on this file since 8741 was 8741, checked in by tbretz, 17 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#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 if (gSystem->AccessPathName(kSequences, kFileExists))
210 {
211 gLog << err << "Sorry, dataset file '" << kSequences << "' doesn't exist." << endl;
212 return 2;
213 }
214
215 if (gSystem->AccessPathName(kConfig, kFileExists))
216 {
217 gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl;
218 return 2;
219 }
220
221 if (kDebugMem)
222 TObject::SetObjectStat(kTRUE);
223
224 //
225 // Setup sequence and check its validity
226 //
227 MDataSet seq(kSequences, (UInt_t)kNumDataset, kPathSequences, kPathDataFiles);
228 if (!seq.IsMonteCarlo())
229 seq.SetMonteCarlo(kIsMc);
230 if (kWobbleModeOn || kWobbleModeOff)
231 seq.SetWobbleMode(kWobbleModeOn);
232 if (kNumAnalysis>=0)
233 seq.SetNumAnalysis(kNumAnalysis);
234 if (kPrintSeq || kPrintFiles)
235 {
236 gLog << all;
237 gLog.Separator(kSequences);
238 seq.Print(kPrintFiles?"files":"");
239 gLog << endl;
240 }
241 if (!seq.IsValid())
242 {
243 gLog << err << "Dataset read but not valid (maybe analysis number not set)!" << endl << endl;
244 return 2;
245 }
246
247 //
248 // Initialize root
249 //
250 MArray::Class()->IgnoreTObjectStreamer();
251 MParContainer::Class()->IgnoreTObjectStreamer();
252
253 TApplication app("ganymed", &argc, argv);
254 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
255 {
256 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
257 return 1;
258 }
259
260 //
261 // Update frequency by default = 1Hz
262 //
263 MStatusDisplay *d = new MStatusDisplay;
264
265 // From now on each 'Exit' means: Terminate the application
266 d->SetBit(MStatusDisplay::kExitLoopOnExit);
267 d->SetTitle(kSequences);
268
269 //
270 // Run cut program. (block for debug-mem)
271 //
272 {
273 MJCut job(Form("MJCut #%d", seq.GetNumAnalysis()));
274 job.SetEnv(&env);
275 job.SetEnvDebug(kDebugEnv);
276 job.SetDisplay(d);;
277 job.SetOverwrite(kOverwrite);
278 job.SetPathOut(kOutpath);
279 job.SetNameOutFile(kOutfile);
280 job.SetNameSummaryFile(kNameSummary);
281 //job.SetNameResultFile(kNameResult);
282 job.EnableWriteOnly(kWriteOnly);
283 //if (kFullDisplay)
284 // job.EnableFullDisplay(kFullDisplay);
285 job.EnableStorageOfResult(!kSkipResult);
286 if (kWriteSummary) // Don't change flag set in SetNameSummaryFile
287 job.EnableStorageOfSummary();
288 //if (kWriteResult) // Don't change flag set in SetNameSummaryFile
289 // job.EnableStorageOfResult();
290
291 const Int_t rc = job.Process(seq);
292 if (rc<=0)
293 {
294 gLog << err << "Calculation of cuts failed." << endl << endl;
295
296 //error coding for the automatic analysis (to be filled into the database)
297 switch (rc)
298 {
299 case 0: // MJCut failed
300 return 3;
301 case -1: // Source not found
302 return 4;
303 case -2: // FillRndSrcCam failed
304 return 5;
305 case -3: // Processing off-data failed
306 return 6;
307 case -4: // Processing on-data failed
308 return 7;
309 }
310 return 2;
311 }
312
313 if (kDebugEnv>0)
314 env.PrintUntouched();
315
316 if (!job.GetDisplay())
317 {
318 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
319 return 1;
320 }
321 }
322
323 if (kBatch || kQuit)
324 delete d;
325 else
326 {
327 // From now on each 'Close' means: Terminate the application
328 d->SetBit(MStatusDisplay::kExitLoopOnClose);
329
330 // Wait until the user decides to exit the application
331 app.Run(kFALSE);
332 }
333
334 if (TObject::GetObjectStat())
335 {
336 TObject::SetObjectStat(kFALSE);
337 gObjectTable->Print();
338 }
339
340 return 0;
341}
Note: See TracBrowser for help on using the repository browser.