source: tags/Mars-V2.3/ganymed.cc@ 13661

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