source: tags/Mars-V2.2/sponde.cc@ 13661

Last change on this file since 13661 was 9276, checked in by tbretz, 16 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 "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 << " --force-runtime Force usage of runtime instead of eff. observation time." << endl;
54 gLog << 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 and command line" << endl;
61 gLog << " --debug-mem Debug memory usage" << endl << endl;
62 gLog << " --rc=Name:Option Set or overwrite a resource of the resource file." << endl;
63 gLog << " (Note, that this option can be used multiple times." << endl;
64 gLog << endl;
65 gLog << " -q Quit when job is finished" << endl;
66 gLog << " -f Force overwrite of existing files" << endl;
67 gLog << " --print-ds Print Dataset information" << endl;
68 gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
69 gLog << " --config=sponde.rc Resource file [default=sponde.rc]" << endl;
70 gLog << " --ind=path Path to mc/star files [default=datacenter path]" << endl;
71 gLog << " --ins=path Path to sequence files [default=datacenter path]" << endl;
72 gLog << " --dataset=number Choose a dataset from a collection of datasets" << endl;
73 gLog << " in your file (for more details see MDataSet)" << endl;
74 gLog << endl;
75 gLog << " --version, -V Show startup message with version number" << endl;
76 gLog << " -?, -h, --help This help" << endl << endl;
77 gLog << "Background:" << endl;
78 gLog << " Sponde is a natural satellite of Jupiter. It was discovered by a team" << endl;
79 gLog << " of astronomers from the University of Hawaii led by Scott S. Sheppard," << endl;
80 gLog << " et al in 2001, and given the temporary designation S/2001 J 5. Sponde" << endl;
81 gLog << " is about 2 kilometers in diameter, and orbits Jupiter at an average" << endl;
82 gLog << " of 23,487,000 kilometers. It is also designated as Jupiter XXXVI." << endl;
83 gLog << " It is named after one of the Horae (Hours), which presided over the" << endl;
84 gLog << " seventh hour (libations poured after lunch). The Hours, godesses of" << endl;
85 gLog << " the time of day but also of the seasons, were daughters of Zeus and" << endl;
86 gLog << " Themis." << endl;
87 gLog << " It belongs to the Pasipha‰ group, irregular retrograde moons orbiting" << endl;
88 gLog << " Jupiter at distances ranging between 22.8 and 24.1 Gm, and with" << endl;
89 gLog << " inclinations ranging between 144.5ø and 158.3ø." << endl << endl;
90}
91
92int main(int argc, char **argv)
93{
94 if (!MARS::CheckRootVer())
95 return 0xff;
96
97 //
98 // Evaluate arguments
99 //
100 MArgs arg(argc, argv);
101 gLog.Setup(arg);
102
103 StartUpMessage();
104
105 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
106 return 0;
107
108 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
109 {
110 Usage();
111 return 2;
112 }
113
114 const TString kConfig = arg.GetStringAndRemove("--config=", "sponde.rc");
115
116 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-ds");
117 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
118 const Int_t kNumDataset = arg.GetIntAndRemove("--dataset=", -1);
119 const TString kPathDataFiles = arg.GetStringAndRemove("--ind=", "");
120 const TString kPathSequences = arg.GetStringAndRemove("--ins=", "");
121 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
122 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
123 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
124
125 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
126 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
127 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
128
129 const Bool_t kForceTheta = arg.HasOnlyAndRemove("--force-theta");
130 const Bool_t kForceRunTime = arg.HasOnlyAndRemove("--force-runtime");
131
132 //
133 // check for the right usage of the program (number of arguments)
134 //
135 if (arg.GetNumArguments()<2 || arg.GetNumArguments()>3)
136 {
137 gLog << warn << "WARNING - Wrong number of arguments..." << endl;
138 Usage();
139 return 2;
140 }
141
142 //
143 // Now we access/read the resource file. This will remove all
144 // --rc= from the list of arguments.
145 //
146 MEnv env(kConfig);
147 if (!env.IsValid())
148 {
149 gLog << err << "ERROR - Reading resource file " << kConfig << "." << endl;
150 return 0xfe;
151 }
152
153 // And move the resource options from the command line to the MEnv
154 if (!env.TakeEnv(arg, kDebugEnv>2))
155 return 0xfd;
156
157 //
158 // check for the right usage of the program (number of options)
159 //
160 if (arg.GetNumOptions()>0)
161 {
162 gLog << warn << "WARNING - Unknown command line options..." << endl;
163 arg.Print("options");
164 gLog << endl;
165 return 2;
166 }
167
168 //
169 // Setup sequence file and check for its existence
170 //
171 TString kInfile = arg.GetArgumentStr(0);
172 TString kDataset = arg.GetArgumentStr(1);
173 TString kOutfile = arg.GetArgumentStr(2);
174
175 if (kOutfile.IsNull() && kBatch)
176 {
177 gLog << err << "Writing no outputfile but running in batch mode is nonsense." << endl;
178 return 2;
179 }
180
181 gSystem->ExpandPathName(kInfile);
182 gSystem->ExpandPathName(kDataset);
183 gSystem->ExpandPathName(kOutfile);
184
185 if (gSystem->AccessPathName(kInfile, kFileExists))
186 {
187 gLog << err << "Sorry, ganymed root-file '" << kInfile << "' doesn't exist." << endl;
188 return 2;
189 }
190 if (gSystem->AccessPathName(kDataset, kFileExists))
191 {
192 gLog << err << "Sorry, dataset file '" << kDataset << "' doesn't exist." << endl;
193 return 2;
194 }
195
196 if (kDebugMem)
197 TObject::SetObjectStat(kTRUE);
198
199 //
200 // Setup sequence and check its validity
201 //
202 MDataSet seq(kDataset, (UInt_t)kNumDataset, kPathSequences, kPathDataFiles);
203 if (kPrintSeq || kPrintFiles)
204 {
205 gLog << all;
206 gLog.Separator(kDataset);
207 seq.Print(kPrintFiles?"files":"");
208 gLog << endl;
209 }
210 if (!seq.IsValid())
211 {
212 gLog << err << "Dataset read but not valid (maybe analysis number not set)!" << endl << endl;
213 return 2;
214 }
215
216 if (!seq.IsMonteCarlo())
217 gLog << warn << "Dataset file seems not to be a Monte Carlo dataset." << endl << endl;
218
219
220 //
221 // Initialize root
222 //
223 MArray::Class()->IgnoreTObjectStreamer();
224 MParContainer::Class()->IgnoreTObjectStreamer();
225
226 TApplication app("sponde", &argc, argv);
227 if ((!gROOT->IsBatch() && !gClient) || (gROOT->IsBatch() && !kBatch))
228 {
229 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
230 return 1;
231 }
232
233 //
234 // Update frequency by default = 1Hz
235 //
236 MStatusDisplay *d = new MStatusDisplay;
237
238 // From now on each 'Exit' means: Terminate the application
239 d->SetBit(MStatusDisplay::kExitLoopOnExit);
240 d->SetTitle(Form("-- Sponde: %s --", kDataset.Data()));
241
242 //
243 // Calculate spectrum (block for debug-mem)
244 //
245 {
246 MJSpectrum job(Form("Spectrum - %s", gSystem->BaseName(kInfile)));
247 job.SetEnv(&env);
248 job.SetEnvDebug(kDebugEnv);
249 job.SetDisplay(d);;
250 job.SetOverwrite(kOverwrite);
251 job.SetPathOut(kOutfile);
252 job.SetPathIn(kInfile);
253
254 job.ForceTheta(kForceTheta);
255 job.ForceRunTime(kForceRunTime);
256
257 if (!job.Process(seq))
258 {
259 gLog << err << "Calculation of spectrum failed." << endl << endl;
260 return 2;
261 }
262 if (kDebugEnv>0 || gLog.GetDebugLevel()>=2)
263 env.PrintUntouched();
264
265 if (!job.GetDisplay())
266 {
267 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
268 return 1;
269 }
270 }
271
272 if (kBatch || kQuit)
273 delete d;
274 else
275 {
276 // From now on each 'Close' means: Terminate the application
277 d->SetBit(MStatusDisplay::kExitLoopOnClose);
278
279 // Wait until the user decides to exit the application
280 app.Run(kFALSE);
281 }
282
283 if (TObject::GetObjectStat())
284 {
285 TObject::SetObjectStat(kFALSE);
286 gObjectTable->Print();
287 }
288
289 return 0;
290}
Note: See TracBrowser for help on using the repository browser.