source: tags/Mars-V2.0/ganymed.cc@ 18817

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