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

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