source: trunk/MagicSoft/Mars/sponde.cc@ 6992

Last change on this file since 6992 was 6977, 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 StartUpMessage();
92
93 //
94 // Evaluate arguments
95 //
96 MArgs arg(argc, argv, kTRUE);
97
98 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
99 return 0;
100
101 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
102 {
103 Usage();
104 return 2;
105 }
106
107 gLog.Setup(arg);
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 kRefill = arg.HasOnlyAndRemove("--refill");
122 const Bool_t kSimple = !arg.HasOnlyAndRemove("--accurate");
123 const Bool_t kRawMc = arg.HasOnlyAndRemove("--raw-mc");
124
125 if (arg.GetNumOptions()>0)
126 {
127 gLog << warn << "WARNING - Unknown commandline options..." << endl;
128 arg.Print("options");
129 gLog << endl;
130 return 2;
131 }
132
133 //
134 // check for the right usage of the program
135 //
136 if (arg.GetNumArguments()<2 || arg.GetNumArguments()>3)
137 {
138 Usage();
139 return 2;
140 }
141
142 //
143 // Setup sequence file and check for its existance
144 //
145 const TString kInfile = arg.GetArgumentStr(0);
146 const TString kDataset = arg.GetArgumentStr(1);
147 const TString kOutfile = arg.GetArgumentStr(2);
148
149 if (gSystem->AccessPathName(kInfile, kFileExists))
150 {
151 gLog << err << "Sorry, sequences file '" << kInfile << "' doesn't exist." << endl;
152 return 2;
153 }
154 if (gSystem->AccessPathName(kDataset, kFileExists))
155 {
156 gLog << err << "Sorry, dataset file '" << kDataset << "' doesn't exist." << endl;
157 return 2;
158 }
159
160 if (kDebugMem)
161 TObject::SetObjectStat(kTRUE);
162
163 //
164 // Setup sequence and check its validity
165 //
166 MDataSet seq(kDataset);
167 if (kPrintSeq || kPrintFiles)
168 {
169 gLog << all;
170 gLog.Separator(kDataset);
171 seq.Print(kPrintFiles?"files":"");
172 gLog << endl;
173 }
174 if (!seq.IsValid())
175 {
176 gLog << err << "Sequences read but not valid!" << endl << endl;
177 return 2;
178 }
179
180 //
181 // Initialize root
182 //
183 MArray::Class()->IgnoreTObjectStreamer();
184 MParContainer::Class()->IgnoreTObjectStreamer();
185
186 TApplication app("Sponde", &argc, argv);
187 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
188 {
189 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
190 return 1;
191 }
192
193 //
194 // Update frequency by default = 1Hz
195 //
196 MStatusDisplay *d = new MStatusDisplay;
197
198 // From now on each 'Exit' means: Terminate the application
199 d->SetBit(MStatusDisplay::kExitLoopOnExit);
200 d->SetTitle(kDataset);
201
202 //
203 // Calculate pedestal for pedestal-calculation and calibration
204 //
205 MEnv env(kConfig);
206
207 MJSpectrum job(Form("MJSpectrum #%d", seq.GetNumAnalysis()));
208 job.SetEnv(&env);
209 job.SetEnvDebug(kDebugEnv);
210 job.SetDisplay(d);;
211 job.SetOverwrite(kOverwrite);
212 job.SetPathOut(kOutfile);
213 job.SetPathIn(kInfile);
214
215 job.EnableRefilling(kRefill);
216 job.EnableSimpleMode(kSimple);
217 job.EnableRawMc(kRawMc);
218
219 if (!job.Process(seq))
220 {
221 gLog << err << "Calculation of spectrum failed." << endl << endl;
222 return 2;
223 }
224 if (kDebugEnv>0)
225 env.PrintUntouched();
226
227 if (!job.GetDisplay())
228 {
229 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
230 return 1;
231 }
232
233 if (kBatch || kQuit)
234 delete d;
235 else
236 {
237 // From now on each 'Close' means: Terminate the application
238 d->SetBit(MStatusDisplay::kExitLoopOnClose);
239
240 // Wait until the user decides to exit the application
241 app.Run(kFALSE);
242 }
243
244 if (TObject::GetObjectStat())
245 {
246 TObject::SetObjectStat(kFALSE);
247 gObjectTable->Print();
248 }
249
250 return 0;
251}
Note: See TracBrowser for help on using the repository browser.