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 on <" << __DATE__ << ">" << endl;
|
---|
33 | gLog << " Using ROOT v" << ROOTVER << endl;
|
---|
34 | gLog << "========================================================" << endl;
|
---|
35 | gLog << endl;
|
---|
36 | }
|
---|
37 |
|
---|
38 | static 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 << " sponde [options] inputfile.root mcdataset.txt [outputfile.root]" << endl << endl;
|
---|
45 | gLog << " Arguments:" << endl;
|
---|
46 | gLog << " inputfile.root: Ganymed output [and result] file" << endl;
|
---|
47 | gLog << " mcdataset.txt: Dataset describing the Monte Carlos to be used" << endl;
|
---|
48 | gLog << " For more details see MDataSet." << endl;
|
---|
49 | gLog << " outputfile.root: Optional file in which the result is stored" << endl << endl;
|
---|
50 | gLog << " Root Options:" << endl;
|
---|
51 | gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
|
---|
52 | gLog << " Operation Mode:" << endl;
|
---|
53 | gLog << " --refill Refill the excess histogram from result file" << endl;
|
---|
54 | gLog << " (usefull to change the binning)" << endl << 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" << endl;
|
---|
61 | gLog << " --debug-mem Debug memory usage" << endl << endl;
|
---|
62 | gLog << endl;
|
---|
63 | gLog << " -q Quit when job is finished" << endl;
|
---|
64 | gLog << " -f Force overwrite of existing files" << endl;
|
---|
65 | gLog << " --print-ds Print Dataset information" << endl;
|
---|
66 | gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
|
---|
67 | gLog << " --config=sponde.rc Resource file [default=sponde.rc]" << endl;
|
---|
68 | gLog << endl;
|
---|
69 | gLog << " --version, -V Show startup message with version number" << endl;
|
---|
70 | gLog << " -?, -h, --help This help" << endl << endl;
|
---|
71 | gLog << "Background:" << endl;
|
---|
72 | gLog << " Sponde is a natural satellite of Jupiter. It was discovered by a team" << endl;
|
---|
73 | gLog << " of astronomers from the University of Hawaii led by Scott S. Sheppard," << endl;
|
---|
74 | gLog << " et al in 2001, and given the temporary designation S/2001 J 5. Sponde" << endl;
|
---|
75 | gLog << " is about 2 kilometers in diameter, and orbits Jupiter at an average" << endl;
|
---|
76 | gLog << " of 23,487,000 kilometers. It is also designated as Jupiter XXXVI." << endl;
|
---|
77 | gLog << " It is named after one of the Horae (Hours), which presided over the" << endl;
|
---|
78 | gLog << " seventh hour (libations poured after lunch). The Hours, godesses of" << endl;
|
---|
79 | gLog << " the time of day but also of the seasons, were daughters of Zeus and" << endl;
|
---|
80 | gLog << " Themis." << endl;
|
---|
81 | gLog << " It belongs to the Pasipha group, irregular retrograde moons orbiting" << endl;
|
---|
82 | gLog << " Jupiter at distances ranging between 22.8 and 24.1 Gm, and with" << endl;
|
---|
83 | gLog << " inclinations ranging between 144.5ø and 158.3ø." << endl << endl;
|
---|
84 | }
|
---|
85 |
|
---|
86 | int 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=", "sponde.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 | Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
|
---|
112 | kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
|
---|
113 |
|
---|
114 | const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
|
---|
115 | const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
|
---|
116 | const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
|
---|
117 |
|
---|
118 | const Bool_t kRefill = arg.HasOnlyAndRemove("--refill");
|
---|
119 |
|
---|
120 | if (arg.GetNumOptions()>0)
|
---|
121 | {
|
---|
122 | gLog << warn << "WARNING - Unknown commandline options..." << endl;
|
---|
123 | arg.Print("options");
|
---|
124 | gLog << endl;
|
---|
125 | return 2;
|
---|
126 | }
|
---|
127 |
|
---|
128 | //
|
---|
129 | // check for the right usage of the program
|
---|
130 | //
|
---|
131 | if (arg.GetNumArguments()<2 || arg.GetNumArguments()>3)
|
---|
132 | {
|
---|
133 | Usage();
|
---|
134 | return 2;
|
---|
135 | }
|
---|
136 |
|
---|
137 | //
|
---|
138 | // Setup sequence file and check for its existance
|
---|
139 | //
|
---|
140 | const TString kInfile = arg.GetArgumentStr(0);
|
---|
141 | const TString kDataset = arg.GetArgumentStr(1);
|
---|
142 | const TString kOutfile = arg.GetArgumentStr(2);
|
---|
143 |
|
---|
144 | if (gSystem->AccessPathName(kInfile, kFileExists))
|
---|
145 | {
|
---|
146 | gLog << err << "Sorry, sequences file '" << kInfile << "' doesn't exist." << endl;
|
---|
147 | return 2;
|
---|
148 | }
|
---|
149 | if (gSystem->AccessPathName(kDataset, kFileExists))
|
---|
150 | {
|
---|
151 | gLog << err << "Sorry, dataset file '" << kDataset << "' doesn't exist." << endl;
|
---|
152 | return 2;
|
---|
153 | }
|
---|
154 |
|
---|
155 | if (kDebugMem)
|
---|
156 | TObject::SetObjectStat(kTRUE);
|
---|
157 |
|
---|
158 | //
|
---|
159 | // Setup sequence and check its validity
|
---|
160 | //
|
---|
161 | MDataSet seq(kDataset);
|
---|
162 | if (kPrintSeq || kPrintFiles)
|
---|
163 | {
|
---|
164 | gLog << all;
|
---|
165 | gLog.Separator(kDataset);
|
---|
166 | seq.Print(kPrintFiles?"files":"");
|
---|
167 | gLog << endl;
|
---|
168 | }
|
---|
169 | if (!seq.IsValid())
|
---|
170 | {
|
---|
171 | gLog << err << "Sequences read but not valid!" << endl << endl;
|
---|
172 | return 2;
|
---|
173 | }
|
---|
174 |
|
---|
175 | //
|
---|
176 | // Initialize root
|
---|
177 | //
|
---|
178 | MArray::Class()->IgnoreTObjectStreamer();
|
---|
179 | MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
180 |
|
---|
181 | TApplication app("Sponde", &argc, argv);
|
---|
182 | if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
|
---|
183 | {
|
---|
184 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
---|
185 | return 1;
|
---|
186 | }
|
---|
187 |
|
---|
188 | //
|
---|
189 | // Update frequency by default = 1Hz
|
---|
190 | //
|
---|
191 | MStatusDisplay *d = new MStatusDisplay;
|
---|
192 |
|
---|
193 | // From now on each 'Exit' means: Terminate the application
|
---|
194 | d->SetBit(MStatusDisplay::kExitLoopOnExit);
|
---|
195 | d->SetTitle(kDataset);
|
---|
196 |
|
---|
197 | //
|
---|
198 | // Calculate pedestal for pedestal-calculation and calibration
|
---|
199 | //
|
---|
200 | MEnv env(kConfig);
|
---|
201 |
|
---|
202 | MJSpectrum job(Form("MJSpectrum #%d", seq.GetNumAnalysis()));
|
---|
203 | job.SetEnv(&env);
|
---|
204 | job.SetEnvDebug(kDebugEnv);
|
---|
205 | job.SetDisplay(d);;
|
---|
206 | job.SetOverwrite(kOverwrite);
|
---|
207 | job.SetPathOut(kOutfile);
|
---|
208 | job.SetPathIn(kInfile);
|
---|
209 | job.EnableRefilling(kRefill);
|
---|
210 |
|
---|
211 | if (!job.Process(seq))
|
---|
212 | {
|
---|
213 | gLog << err << "Calculation of spectrum failed." << endl << endl;
|
---|
214 | return 2;
|
---|
215 | }
|
---|
216 | if (kDebugEnv>0)
|
---|
217 | env.PrintUntouched();
|
---|
218 |
|
---|
219 | if (!job.GetDisplay())
|
---|
220 | {
|
---|
221 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
---|
222 | return 1;
|
---|
223 | }
|
---|
224 |
|
---|
225 | if (kBatch || kQuit)
|
---|
226 | delete d;
|
---|
227 | else
|
---|
228 | {
|
---|
229 | // From now on each 'Close' means: Terminate the application
|
---|
230 | d->SetBit(MStatusDisplay::kExitLoopOnClose);
|
---|
231 |
|
---|
232 | // Wait until the user decides to exit the application
|
---|
233 | app.Run(kFALSE);
|
---|
234 | }
|
---|
235 |
|
---|
236 | if (TObject::GetObjectStat())
|
---|
237 | {
|
---|
238 | TObject::SetObjectStat(kFALSE);
|
---|
239 | gObjectTable->Print();
|
---|
240 | }
|
---|
241 |
|
---|
242 | return 0;
|
---|
243 | }
|
---|