source: tags/Mars-V0.9.2/sponde.cc@ 14941

Last change on this file since 14941 was 7001, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 8.9 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 on <" << __DATE__ << ">" << endl;
33 gLog << " Using ROOT v" << ROOTVER << endl;
34 gLog << "========================================================" << endl;
35 gLog << endl;
36}
37
38static 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;
55 gLog << " --accurate Fill original energy/theta distribution from data" << endl;
56 gLog << " (do not weight the histogram)" << endl;
57 gLog << " --raw-mc Use the mc sample as it is" << endl << endl;
58 gLog << " Options:" << endl;
59 gLog.Usage();
60 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
61 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
62 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
63 gLog << " --debug-env=3 Debug setting resources from resource file" << endl;
64 gLog << " --debug-mem Debug memory usage" << endl << endl;
65 gLog << endl;
66 gLog << " -q Quit when job is finished" << endl;
67 gLog << " -f Force overwrite of existing files" << endl;
68 gLog << " --print-ds Print Dataset information" << endl;
69 gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
70 gLog << " --config=sponde.rc Resource file [default=sponde.rc]" << endl;
71 gLog << endl;
72 gLog << " --version, -V Show startup message with version number" << endl;
73 gLog << " -?, -h, --help This help" << endl << endl;
74 gLog << "Background:" << endl;
75 gLog << " Sponde is a natural satellite of Jupiter. It was discovered by a team" << endl;
76 gLog << " of astronomers from the University of Hawaii led by Scott S. Sheppard," << endl;
77 gLog << " et al in 2001, and given the temporary designation S/2001 J 5. Sponde" << endl;
78 gLog << " is about 2 kilometers in diameter, and orbits Jupiter at an average" << endl;
79 gLog << " of 23,487,000 kilometers. It is also designated as Jupiter XXXVI." << endl;
80 gLog << " It is named after one of the Horae (Hours), which presided over the" << endl;
81 gLog << " seventh hour (libations poured after lunch). The Hours, godesses of" << endl;
82 gLog << " the time of day but also of the seasons, were daughters of Zeus and" << endl;
83 gLog << " Themis." << endl;
84 gLog << " It belongs to the Pasipha‰ group, irregular retrograde moons orbiting" << endl;
85 gLog << " Jupiter at distances ranging between 22.8 and 24.1 Gm, and with" << endl;
86 gLog << " inclinations ranging between 144.5ø and 158.3ø." << endl << endl;
87}
88
89int main(int argc, char **argv)
90{
91 //
92 // Evaluate arguments
93 //
94 MArgs arg(argc, argv, kTRUE);
95 gLog.Setup(arg);
96
97 StartUpMessage();
98
99 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
100 return 0;
101
102 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
103 {
104 Usage();
105 return 2;
106 }
107
108 const TString kConfig = arg.GetStringAndRemove("--config=", "sponde.rc");
109
110 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-ds");
111 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
112 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
113 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
114 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
115
116 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
117 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
118 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
119
120 const Bool_t kRefill = arg.HasOnlyAndRemove("--refill");
121 const Bool_t kSimple = !arg.HasOnlyAndRemove("--accurate");
122 const Bool_t kRawMc = arg.HasOnlyAndRemove("--raw-mc");
123
124 if (arg.GetNumOptions()>0)
125 {
126 gLog << warn << "WARNING - Unknown commandline options..." << endl;
127 arg.Print("options");
128 gLog << endl;
129 return 2;
130 }
131
132 //
133 // check for the right usage of the program
134 //
135 if (arg.GetNumArguments()<2 || arg.GetNumArguments()>3)
136 {
137 Usage();
138 return 2;
139 }
140
141 //
142 // Setup sequence file and check for its existance
143 //
144 const TString kInfile = arg.GetArgumentStr(0);
145 const TString kDataset = arg.GetArgumentStr(1);
146 const TString kOutfile = arg.GetArgumentStr(2);
147
148 if (gSystem->AccessPathName(kInfile, kFileExists))
149 {
150 gLog << err << "Sorry, sequences file '" << kInfile << "' doesn't exist." << endl;
151 return 2;
152 }
153 if (gSystem->AccessPathName(kDataset, kFileExists))
154 {
155 gLog << err << "Sorry, dataset file '" << kDataset << "' doesn't exist." << endl;
156 return 2;
157 }
158
159 if (kDebugMem)
160 TObject::SetObjectStat(kTRUE);
161
162 //
163 // Setup sequence and check its validity
164 //
165 MDataSet seq(kDataset);
166 if (kPrintSeq || kPrintFiles)
167 {
168 gLog << all;
169 gLog.Separator(kDataset);
170 seq.Print(kPrintFiles?"files":"");
171 gLog << endl;
172 }
173 if (!seq.IsValid())
174 {
175 gLog << err << "Sequences read but not valid!" << endl << endl;
176 return 2;
177 }
178
179 //
180 // Initialize root
181 //
182 MArray::Class()->IgnoreTObjectStreamer();
183 MParContainer::Class()->IgnoreTObjectStreamer();
184
185 TApplication app("sponde", &argc, argv);
186 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
187 {
188 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
189 return 1;
190 }
191
192 //
193 // Update frequency by default = 1Hz
194 //
195 MStatusDisplay *d = new MStatusDisplay;
196
197 // From now on each 'Exit' means: Terminate the application
198 d->SetBit(MStatusDisplay::kExitLoopOnExit);
199 d->SetTitle(kDataset);
200
201 //
202 // Calculate pedestal for pedestal-calculation and calibration
203 //
204 MEnv env(kConfig);
205
206 MJSpectrum job(Form("MJSpectrum #%d", seq.GetNumAnalysis()));
207 job.SetEnv(&env);
208 job.SetEnvDebug(kDebugEnv);
209 job.SetDisplay(d);;
210 job.SetOverwrite(kOverwrite);
211 job.SetPathOut(kOutfile);
212 job.SetPathIn(kInfile);
213
214 job.EnableRefilling(kRefill);
215 job.EnableSimpleMode(kSimple);
216 job.EnableRawMc(kRawMc);
217
218 if (!job.Process(seq))
219 {
220 gLog << err << "Calculation of spectrum failed." << endl << endl;
221 return 2;
222 }
223 if (kDebugEnv>0)
224 env.PrintUntouched();
225
226 if (!job.GetDisplay())
227 {
228 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
229 return 1;
230 }
231
232 if (kBatch || kQuit)
233 delete d;
234 else
235 {
236 // From now on each 'Close' means: Terminate the application
237 d->SetBit(MStatusDisplay::kExitLoopOnClose);
238
239 // Wait until the user decides to exit the application
240 app.Run(kFALSE);
241 }
242
243 if (TObject::GetObjectStat())
244 {
245 TObject::SetObjectStat(kFALSE);
246 gObjectTable->Print();
247 }
248
249 return 0;
250}
Note: See TracBrowser for help on using the repository browser.