source: trunk/MagicSoft/Mars/sponde.cc@ 8757

Last change on this file since 8757 was 8741, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 9.5 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 "MJSpectrum.h"
20
21using namespace std;
22
23static void StartUpMessage()
24{
25 gLog << all << endl;
26
27 // 1 2 3 4 5
28 // 12345678901234567890123456789012345678901234567890123456
29 gLog << "========================================================" << endl;
30 gLog << " Sponde - MARS V" << MARSVER << endl;
31 gLog << " MARS -- SPectrum ON DEmand" << 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 << " sponde [options] inputfile.root mcdataset.txt [outputfile.root]" << endl << endl;
44 gLog << " Arguments:" << endl;
45 gLog << " inputfile.root: Ganymed output [and result] file" << endl;
46 gLog << " mcdataset.txt: Dataset describing the Monte Carlos to be used" << endl;
47 gLog << " For more details see MDataSet." << endl;
48 gLog << " outputfile.root: Optional file in which the result is stored" << endl << 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 << " --force-theta Force execution even with non-fitting theta distributions." << endl;
53 gLog << endl;
54 gLog << " Options:" << endl;
55 gLog.Usage();
56 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
57 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
58 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
59 gLog << " --debug-env=3 Debug setting resources from resource file and command line" << endl;
60 gLog << " --debug-mem Debug memory usage" << endl << endl;
61 gLog << " --rc=Name:Option Set or overwrite a resource of the resource file." << endl;
62 gLog << " (Note, that this option can be used multiple times." << endl;
63 gLog << endl;
64 gLog << " -q Quit when job is finished" << endl;
65 gLog << " -f Force overwrite of existing files" << endl;
66 gLog << " --print-ds Print Dataset information" << endl;
67 gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
68 gLog << " --config=sponde.rc Resource file [default=sponde.rc]" << endl;
69 gLog << endl;
70 gLog << " --version, -V Show startup message with version number" << endl;
71 gLog << " -?, -h, --help This help" << endl << endl;
72 gLog << "Background:" << endl;
73 gLog << " Sponde is a natural satellite of Jupiter. It was discovered by a team" << endl;
74 gLog << " of astronomers from the University of Hawaii led by Scott S. Sheppard," << endl;
75 gLog << " et al in 2001, and given the temporary designation S/2001 J 5. Sponde" << endl;
76 gLog << " is about 2 kilometers in diameter, and orbits Jupiter at an average" << endl;
77 gLog << " of 23,487,000 kilometers. It is also designated as Jupiter XXXVI." << endl;
78 gLog << " It is named after one of the Horae (Hours), which presided over the" << endl;
79 gLog << " seventh hour (libations poured after lunch). The Hours, godesses of" << endl;
80 gLog << " the time of day but also of the seasons, were daughters of Zeus and" << endl;
81 gLog << " Themis." << endl;
82 gLog << " It belongs to the Pasipha‰ group, irregular retrograde moons orbiting" << endl;
83 gLog << " Jupiter at distances ranging between 22.8 and 24.1 Gm, and with" << endl;
84 gLog << " inclinations ranging between 144.5ø and 158.3ø." << endl << endl;
85}
86
87int main(int argc, char **argv)
88{
89 if (!MARS::CheckRootVer())
90 return 0xff;
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=", "sponde.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 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
121 const Bool_t kForceTheta = arg.HasOnlyAndRemove("--force-theta");
122
123 //
124 // check for the right usage of the program (number of arguments)
125 //
126 if (arg.GetNumArguments()<2 || arg.GetNumArguments()>3)
127 {
128 gLog << warn << "WARNING - Wrong number of arguments..." << endl;
129 Usage();
130 return 2;
131 }
132
133 //
134 // Now we access/read the resource file. This will remove all
135 // --rc= from the list of arguments.
136 //
137 MEnv env(kConfig);
138 if (!env.IsValid())
139 {
140 gLog << err << "ERROR - Reading resource file " << kConfig << "." << endl;
141 return 0xfe;
142 }
143
144 // And move the resource options from the command line to the MEnv
145 if (!env.TakeEnv(arg, kDebugEnv>2))
146 return 0xfd;
147
148 //
149 // check for the right usage of the program (number of options)
150 //
151 if (arg.GetNumOptions()>0)
152 {
153 gLog << warn << "WARNING - Unknown command line options..." << endl;
154 arg.Print("options");
155 gLog << endl;
156 return 2;
157 }
158
159 //
160 // Setup sequence file and check for its existence
161 //
162 const TString kInfile = arg.GetArgumentStr(0);
163 const TString kDataset = arg.GetArgumentStr(1);
164 const TString kOutfile = arg.GetArgumentStr(2);
165
166 if (kOutfile.IsNull() && kBatch)
167 {
168 gLog << err << "Writing no outputfile but running in batch mode is nonsense." << endl;
169 return 2;
170 }
171
172 if (gSystem->AccessPathName(kInfile, kFileExists))
173 {
174 gLog << err << "Sorry, sequences file '" << kInfile << "' doesn't exist." << endl;
175 return 2;
176 }
177 if (gSystem->AccessPathName(kDataset, kFileExists))
178 {
179 gLog << err << "Sorry, dataset file '" << kDataset << "' doesn't exist." << endl;
180 return 2;
181 }
182
183 if (kDebugMem)
184 TObject::SetObjectStat(kTRUE);
185
186 //
187 // Setup sequence and check its validity
188 //
189 MDataSet seq(kDataset);
190 if (kPrintSeq || kPrintFiles)
191 {
192 gLog << all;
193 gLog.Separator(kDataset);
194 seq.Print(kPrintFiles?"files":"");
195 gLog << endl;
196 }
197 if (!seq.IsValid())
198 {
199 gLog << err << "Dataset read but not valid (maybe analysis number not set)!" << endl << endl;
200 return 2;
201 }
202
203 if (!seq.IsMonteCarlo())
204 gLog << warn << "Dataset file seems not to be a Monte Carlo dataset." << endl << endl;
205
206
207 //
208 // Initialize root
209 //
210 MArray::Class()->IgnoreTObjectStreamer();
211 MParContainer::Class()->IgnoreTObjectStreamer();
212
213 TApplication app("sponde", &argc, argv);
214 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
215 {
216 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
217 return 1;
218 }
219
220 //
221 // Update frequency by default = 1Hz
222 //
223 MStatusDisplay *d = new MStatusDisplay;
224
225 // From now on each 'Exit' means: Terminate the application
226 d->SetBit(MStatusDisplay::kExitLoopOnExit);
227 d->SetTitle(kDataset);
228
229 //
230 // Calculate spectrum (block for debug-mem)
231 //
232 {
233 MJSpectrum job(Form("Spectrum - %s", kInfile.Data()));
234 job.SetEnv(&env);
235 job.SetEnvDebug(kDebugEnv);
236 job.SetDisplay(d);;
237 job.SetOverwrite(kOverwrite);
238 job.SetPathOut(kOutfile);
239 job.SetPathIn(kInfile);
240
241 job.ForceTheta(kForceTheta);
242
243 if (!job.Process(seq))
244 {
245 gLog << err << "Calculation of spectrum failed." << endl << endl;
246 return 2;
247 }
248 if (kDebugEnv>0)
249 env.PrintUntouched();
250
251 if (!job.GetDisplay())
252 {
253 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
254 return 1;
255 }
256 }
257
258 if (kBatch || kQuit)
259 delete d;
260 else
261 {
262 // From now on each 'Close' means: Terminate the application
263 d->SetBit(MStatusDisplay::kExitLoopOnClose);
264
265 // Wait until the user decides to exit the application
266 app.Run(kFALSE);
267 }
268
269 if (TObject::GetObjectStat())
270 {
271 TObject::SetObjectStat(kFALSE);
272 gObjectTable->Print();
273 }
274
275 return 0;
276}
Note: See TracBrowser for help on using the repository browser.