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

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