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 |
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | static 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 |
|
---|
37 | static 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 |
|
---|
87 | int 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 | TString kInfile = arg.GetArgumentStr(0);
|
---|
163 | TString kDataset = arg.GetArgumentStr(1);
|
---|
164 | 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 | gSystem->ExpandPathName(kInfile);
|
---|
173 | gSystem->ExpandPathName(kDataset);
|
---|
174 | gSystem->ExpandPathName(kOutfile);
|
---|
175 |
|
---|
176 | if (gSystem->AccessPathName(kInfile, kFileExists))
|
---|
177 | {
|
---|
178 | gLog << err << "Sorry, ganymed root-file '" << kInfile << "' doesn't exist." << endl;
|
---|
179 | return 2;
|
---|
180 | }
|
---|
181 | if (gSystem->AccessPathName(kDataset, kFileExists))
|
---|
182 | {
|
---|
183 | gLog << err << "Sorry, dataset file '" << kDataset << "' doesn't exist." << endl;
|
---|
184 | return 2;
|
---|
185 | }
|
---|
186 |
|
---|
187 | if (kDebugMem)
|
---|
188 | TObject::SetObjectStat(kTRUE);
|
---|
189 |
|
---|
190 | //
|
---|
191 | // Setup sequence and check its validity
|
---|
192 | //
|
---|
193 | MDataSet seq(kDataset);
|
---|
194 | if (kPrintSeq || kPrintFiles)
|
---|
195 | {
|
---|
196 | gLog << all;
|
---|
197 | gLog.Separator(kDataset);
|
---|
198 | seq.Print(kPrintFiles?"files":"");
|
---|
199 | gLog << endl;
|
---|
200 | }
|
---|
201 | if (!seq.IsValid())
|
---|
202 | {
|
---|
203 | gLog << err << "Dataset read but not valid (maybe analysis number not set)!" << endl << endl;
|
---|
204 | return 2;
|
---|
205 | }
|
---|
206 |
|
---|
207 | if (!seq.IsMonteCarlo())
|
---|
208 | gLog << warn << "Dataset file seems not to be a Monte Carlo dataset." << endl << endl;
|
---|
209 |
|
---|
210 |
|
---|
211 | //
|
---|
212 | // Initialize root
|
---|
213 | //
|
---|
214 | MArray::Class()->IgnoreTObjectStreamer();
|
---|
215 | MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
216 |
|
---|
217 | TApplication app("sponde", &argc, argv);
|
---|
218 | if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
|
---|
219 | {
|
---|
220 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
---|
221 | return 1;
|
---|
222 | }
|
---|
223 |
|
---|
224 | //
|
---|
225 | // Update frequency by default = 1Hz
|
---|
226 | //
|
---|
227 | MStatusDisplay *d = new MStatusDisplay;
|
---|
228 |
|
---|
229 | // From now on each 'Exit' means: Terminate the application
|
---|
230 | d->SetBit(MStatusDisplay::kExitLoopOnExit);
|
---|
231 | d->SetTitle(kDataset);
|
---|
232 |
|
---|
233 | //
|
---|
234 | // Calculate spectrum (block for debug-mem)
|
---|
235 | //
|
---|
236 | {
|
---|
237 | MJSpectrum job(Form("Spectrum - %s", kInfile.Data()));
|
---|
238 | job.SetEnv(&env);
|
---|
239 | job.SetEnvDebug(kDebugEnv);
|
---|
240 | job.SetDisplay(d);;
|
---|
241 | job.SetOverwrite(kOverwrite);
|
---|
242 | job.SetPathOut(kOutfile);
|
---|
243 | job.SetPathIn(kInfile);
|
---|
244 |
|
---|
245 | job.ForceTheta(kForceTheta);
|
---|
246 |
|
---|
247 | if (!job.Process(seq))
|
---|
248 | {
|
---|
249 | gLog << err << "Calculation of spectrum failed." << endl << endl;
|
---|
250 | return 2;
|
---|
251 | }
|
---|
252 | if (kDebugEnv>0 || gLog.GetDebugLevel()>=2)
|
---|
253 | env.PrintUntouched();
|
---|
254 |
|
---|
255 | if (!job.GetDisplay())
|
---|
256 | {
|
---|
257 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
---|
258 | return 1;
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | if (kBatch || kQuit)
|
---|
263 | delete d;
|
---|
264 | else
|
---|
265 | {
|
---|
266 | // From now on each 'Close' means: Terminate the application
|
---|
267 | d->SetBit(MStatusDisplay::kExitLoopOnClose);
|
---|
268 |
|
---|
269 | // Wait until the user decides to exit the application
|
---|
270 | app.Run(kFALSE);
|
---|
271 | }
|
---|
272 |
|
---|
273 | if (TObject::GetObjectStat())
|
---|
274 | {
|
---|
275 | TObject::SetObjectStat(kFALSE);
|
---|
276 | gObjectTable->Print();
|
---|
277 | }
|
---|
278 |
|
---|
279 | return 0;
|
---|
280 | }
|
---|