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