source: tags/Mars-V2.2/ceres.cc@ 19846

Last change on this file since 19846 was 9276, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 8.5 KB
Line 
1#include <TClass.h>
2#include <TSystem.h>
3#include <TApplication.h>
4#include <TObjectTable.h>
5
6#include <TVector2.h>
7
8#include "MArray.h"
9
10#include "MLog.h"
11#include "MLogManip.h"
12
13#include "MStatusDisplay.h"
14
15#include "MEnv.h"
16#include "MArgs.h"
17
18#include "MJSimulation.h"
19
20
21using namespace std;
22
23static void StartUpMessage()
24{
25 gLog << all << endl;
26
27 // 1 2 3 4 5
28 // 12345678901234567890123456789012345678901234567890
29 gLog << "====================================================" << endl;
30 gLog << " Ceres - MARS V" << MARSVER << endl;
31 gLog << " MARS - Camera Electronics and REflector Simulation" << 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 gLog << all << endl;
40 gLog << "Sorry the usage is:" << endl;
41 gLog << " ceres [options] inputfile" << endl << endl;
42 gLog << " inputfile MMCS (CORSIKA) binary (cherenkov) file." << endl;
43 gLog << " Root Options:" << endl;
44 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
45 gLog << " Options:" << endl;
46 gLog.Usage();
47 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
48 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
49 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
50 gLog << " --debug-env=3 Debug setting resources from resource file and" << endl;
51 gLog << " command line" << endl;
52 gLog << " --debug-mem Debug memory usage" << endl << endl;
53 gLog << " --rc=Name:option Set or overwrite a resource of the resource file." << endl;
54 gLog << " (Note, that this option can be used multiple times)" << endl;
55 gLog << endl;
56 gLog << " Output options:" << endl;
57 gLog << " -q Quit when job is finished" << endl;
58 gLog << " -f Force overwrite of existing files" << endl;
59 gLog << " -ff Force reading of file even if problems occur" << endl;
60 gLog << " --out=path Path to write the all results to [def=local path]" << endl;
61 gLog << " --dev-null Suppress output of files (for test purpose)" << endl;
62 gLog << " --config=ceres.rc Resource file [default=reflector.rc]" << endl;
63 gLog << endl;
64// gLog << " -f: force reading of runheader" << endl;
65 gLog << " --version, -V Show startup message with version number" << endl;
66 gLog << " -?, -h, --help This help" << endl << endl;
67 gLog << "Background:" << endl;
68 gLog << " Ceres, formal designation 1 Ceres, is the smallest identified dwarf planet in" << endl;
69 gLog << " the Solar System and the only one in the asteroid belt. It was discovered on" << endl;
70 gLog << " January 1, 1801, by Giuseppe Piazzi, and is named after the Roman goddess" << endl;
71 gLog << " Ceres, the goddess of growing plants, the harvest, and of motherly love." << endl;
72 gLog << " With a diameter of about 950km, Ceres is by far the largest and most massive" << endl;
73 gLog << " body in the asteroid belt, and contains a third of the belt's total mass." << endl;
74 gLog << " Recent observations have revealed that it is spherical, unlike the irregular" << endl;
75 gLog << " shapes of smaller bodies with lower gravity. The surface of Ceres is probably" << endl;
76 gLog << " made of a mixture of water ice and various hydrated minerals like carbonates" << endl;
77 gLog << " and clays. Ceres appears to be differentiated into a rocky core and ice mantle." << endl;
78 gLog << " It may harbour an ocean of liquid water underneath its surface, which makes it" << endl;
79 gLog << " a potential target in the search for extraterrestrial life." << endl;
80 gLog << " Ceres' apparent magnitude ranges from 6.7 to 9.3, hence at its brightest is" << endl;
81 gLog << " still too dim to be seen with the naked eye. On Sept. 27, 2007, NASA launched" << endl;
82 gLog << " the Dawn space probe to explore Vesta and Ceres." << endl << endl;
83 gLog << "Example:" << endl;
84 gLog << " ceres -f --out=outpath/ cer000001 cer000002" << endl;
85 gLog << endl;
86}
87
88int main(int argc, char **argv)
89{
90 if (!MARS::CheckRootVer())
91 return 0xff;
92
93 MLog::RedirectErrorHandler(MLog::kColor);
94
95 //
96 // Evaluate arguments
97 //
98 MArgs arg(argc, argv);
99 gLog.Setup(arg);
100
101 StartUpMessage();
102
103 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
104 return 0;
105
106 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
107 {
108 Usage();
109 return 2;
110 }
111
112 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
113 //const Int_t kCompLvl = arg.GetIntAndRemove("--comp=", 1);
114 const Bool_t kForce = arg.HasOnlyAndRemove("-ff");
115 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
116 const Bool_t kNullOut = arg.HasOnlyAndRemove("--dev-null");
117 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
118 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
119
120 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
121 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
122
123 const TString kConfig = arg.GetStringAndRemove("--config=", "ceres.rc");
124 const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
125
126 //
127 // check for the right usage of the program (number of arguments)
128 if (arg.GetNumArguments()<1/* || arg.GetNumArguments()>2*/)
129 {
130 gLog << warn << "WARNING - Wrong number of arguments..." << endl;
131 Usage();
132 return 2;
133 }
134
135 //
136 // Now we access/read the resource file. This will remove all
137 // --rc= from the list of arguments.
138 //
139 MEnv env(kConfig);
140 if (!env.IsValid())
141 {
142 gLog << err << "ERROR - Reading resource file " << kConfig << "." << endl;
143 return 0xfe;
144 }
145
146 // And move the resource options from the command line to the MEnv
147 if (!env.TakeEnv(arg, kDebugEnv>2))
148 return 0xfd;
149
150 //
151 // check for the right usage of the program (number of options)
152 //
153 if (arg.GetNumOptions()>0)
154 {
155 gLog << warn << "WARNING - Unknown commandline options..." << endl;
156 arg.Print("options");
157 gLog << endl;
158 return 2;
159 }
160
161 //
162 // Initialize root
163 //
164 TVector2::Class()->IgnoreTObjectStreamer();
165 MArray::Class()->IgnoreTObjectStreamer();
166 MParContainer::Class()->IgnoreTObjectStreamer();
167
168 TApplication app("ceres", &argc, argv);
169 if ((!gROOT->IsBatch() && !gClient) || (gROOT->IsBatch() && !kBatch))
170 {
171 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
172 return 1;
173 }
174
175 //
176 // Update frequency by default = 1Hz
177 //
178 MStatusDisplay *d = new MStatusDisplay;
179
180 // From now on each 'Exit' means: Terminate the application
181 d->SetBit(MStatusDisplay::kExitLoopOnExit);
182 d->SetTitle(Form("-- Ceres: %s --", ""/*kNamein.Data()*/));
183
184 if (kDebugMem)
185 TObject::SetObjectStat(kTRUE);
186
187 //
188 // Do star in a block (debug mem)
189 //
190 {
191
192 MJSimulation job("Ceres"/*Form("MJSimulation #%d", seq.GetSequence())*/);
193 //job.SetSequence(seq);
194 job.SetEnv(&env);
195 job.SetEnvDebug(kDebugEnv);
196 job.SetDisplay(d);;
197 job.SetOverwrite(kOverwrite);
198 job.SetPathOut(kOutpath);
199 job.SetNullOut(kNullOut);
200 job.SetForceMode(kForce);
201 // job.SetPathIn(kInpath); // not yet needed
202
203 if (!job.Process(arg))
204 {
205 gLog << err << "Calculation of ceres failed." << endl << endl;
206 return 2;
207 }
208
209 if (kDebugEnv>0)
210 env.PrintUntouched();
211
212 if (!job.GetDisplay())
213 {
214 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
215 return 1;
216 }
217 }
218
219 if (kBatch || kQuit)
220 delete d;
221 else
222 {
223 // From now on each 'Close' means: Terminate the application
224 d->SetBit(MStatusDisplay::kExitLoopOnClose);
225
226 // Wait until the user decides to exit the application
227 app.Run(kFALSE);
228 }
229
230 if (TObject::GetObjectStat())
231 {
232 TObject::SetObjectStat(kFALSE);
233 gObjectTable->Print();
234 }
235
236 return 0;
237}
Note: See TracBrowser for help on using the repository browser.