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