source: branches/Mars_use_drstimefiles/sponde.cc@ 19311

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