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

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