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 "MJCut.h"
|
---|
20 |
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | static void StartUpMessage()
|
---|
24 | {
|
---|
25 | gLog << all << endl;
|
---|
26 |
|
---|
27 | // 1 2 3 4 5
|
---|
28 | // 12345678901234567890123456789012345678901234567890
|
---|
29 | gLog << "========================================================" << endl;
|
---|
30 | gLog << " Ganymed - MARS V" << MARSVER << endl;
|
---|
31 | gLog << " MARS -- Gammas Are Now Your Most Exciting Discovery" << 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 << " ganymed [-c] [-y] [options] sequences.txt" << endl << endl;
|
---|
45 | gLog << " Arguments:" << endl;
|
---|
46 | gLog << " dataset.txt: Ascii file defining a collection of sequences" << endl;
|
---|
47 | gLog << " For more details see MDataSet." << endl;
|
---|
48 | gLog << " Root Options:" << endl;
|
---|
49 | gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
|
---|
50 | gLog << " Operation Mode:" << endl;
|
---|
51 | gLog << " -mc Monte Carlo dataset (no times)" << endl;
|
---|
52 | gLog << " --wobble Force wobble mode (overwrites dataset)" << endl;
|
---|
53 | gLog << " --no-wobble Force normal mode (overwrites dataset)" << endl << endl;
|
---|
54 | gLog << " Options:" << endl;
|
---|
55 | gLog.Usage();
|
---|
56 | gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
|
---|
57 | gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
|
---|
58 | gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
|
---|
59 | gLog << " --debug-env=3 Debug setting resources from resource file" << endl;
|
---|
60 | gLog << " --debug-mem Debug memory usage" << endl << endl;
|
---|
61 | gLog << endl;
|
---|
62 | gLog << " -q Quit when job is finished" << endl;
|
---|
63 | gLog << " -f Force overwrite of existing files" << endl;
|
---|
64 | gLog << " --n=[n] Analysis number" << endl;
|
---|
65 | gLog << " --out=path Path to write the all output to [def=local path]" << endl;
|
---|
66 | gLog << " --outf=filename Filename for output file (eg. status display)" << endl;
|
---|
67 | gLog << " --sum[=filename] Enable writing of summary file (events after cut0)" << endl;
|
---|
68 | // gLog << " --res[=filename] Enable writing of result file (surviving events)" << endl;
|
---|
69 | gLog << " --skip-res Disable writing of result events" << endl;
|
---|
70 | gLog << " --write-only Only write output files. No histograms filled." << endl;
|
---|
71 | gLog << " --print-ds Print Dataset information" << endl;
|
---|
72 | gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
|
---|
73 | gLog << " --full-display Show as many plots as possible" << endl;
|
---|
74 | gLog << " --config=ganymed.rc Resource file [default=ganymed.rc]" << endl;
|
---|
75 | gLog << endl;
|
---|
76 | gLog << " --version, -V Show startup message with version number" << endl;
|
---|
77 | gLog << " -?, -h, --help This help" << endl << endl;
|
---|
78 | gLog << "Background:" << endl;
|
---|
79 | gLog << " Ganymed is the largest moon of Jupiter, a large, icy, outer moon that" << endl;
|
---|
80 | gLog << " is scarred with impact craters and many parallel faults. It has a" << endl;
|
---|
81 | gLog << " diameter of about 5268km and orbits Jupiter at a mean distance of" << endl;
|
---|
82 | gLog << " 1,070,000km. It has a magnetic field and probably has a molten iron" << endl;
|
---|
83 | gLog << " core. It takes Ganymed 7.15 days to orbit Jupiter. Its mass is" << endl;
|
---|
84 | gLog << " 1.5e23kg. It was independently discovered by Galileo and S.Marius in"<< endl;
|
---|
85 | gLog << " 1610. Ganymed is the largest moon in the solar system; it is also" << endl;
|
---|
86 | gLog << " larger than the planets Mercury and Pluto." << endl << endl;
|
---|
87 | }
|
---|
88 |
|
---|
89 | int 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=", "ganymed.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 | const Bool_t kWriteOnly = arg.HasOnlyAndRemove("--write-only");
|
---|
115 | const Bool_t kFullDisplay = arg.HasOnlyAndRemove("--full-display");
|
---|
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 kBatch = arg.HasOnlyAndRemove("-b");
|
---|
121 | const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
|
---|
122 | //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
|
---|
123 |
|
---|
124 | const Bool_t kIsMc = arg.HasOnlyAndRemove("-mc");
|
---|
125 | const Bool_t kWobbleModeOn = arg.HasOnlyAndRemove("--wobble");
|
---|
126 | const Bool_t kWobbleModeOff = arg.HasOnlyAndRemove("--no-wobble");
|
---|
127 |
|
---|
128 | const Int_t kNumAnalysis = arg.GetIntAndRemove("--n=", -1);
|
---|
129 | const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
|
---|
130 | const TString kOutfile = arg.GetStringAndRemove("--outf=", "");
|
---|
131 | const Bool_t kWriteSummary = arg.HasOnlyAndRemove("--sum");
|
---|
132 | const TString kNameSummary = arg.GetStringAndRemove("--sum=");
|
---|
133 | const Bool_t kSkipResult = arg.HasOnlyAndRemove("--skip-res");
|
---|
134 | // const Bool_t kWriteResult = arg.HasOnlyAndRemove("--res");
|
---|
135 | // const TString kNameResult = arg.GetStringAndRemove("--res=");
|
---|
136 |
|
---|
137 | if (kWobbleModeOn && kWobbleModeOff)
|
---|
138 | {
|
---|
139 | gLog << err << "ERROR - Wobble mode options are exclusive." << endl;
|
---|
140 | Usage();
|
---|
141 | return 2;
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (arg.GetNumOptions()>0)
|
---|
145 | {
|
---|
146 | gLog << warn << "WARNING - Unknown commandline options..." << endl;
|
---|
147 | arg.Print("options");
|
---|
148 | gLog << endl;
|
---|
149 | return 2;
|
---|
150 | }
|
---|
151 |
|
---|
152 | //
|
---|
153 | // check for the right usage of the program
|
---|
154 | //
|
---|
155 | if (arg.GetNumArguments()!=1)
|
---|
156 | {
|
---|
157 | Usage();
|
---|
158 | return 2;
|
---|
159 | }
|
---|
160 |
|
---|
161 | //
|
---|
162 | // Setup sequence file and check for its existance
|
---|
163 | //
|
---|
164 | const TString kSequences = arg.GetArgumentStr(0);
|
---|
165 |
|
---|
166 | if (gSystem->AccessPathName(kSequences, kFileExists))
|
---|
167 | {
|
---|
168 | gLog << err << "Sorry, sequences file '" << kSequences << "' doesn't exist." << endl;
|
---|
169 | return 2;
|
---|
170 | }
|
---|
171 |
|
---|
172 | if (gSystem->AccessPathName(kConfig, kFileExists))
|
---|
173 | {
|
---|
174 | gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl;
|
---|
175 | return 2;
|
---|
176 | }
|
---|
177 |
|
---|
178 | if (kDebugMem)
|
---|
179 | TObject::SetObjectStat(kTRUE);
|
---|
180 |
|
---|
181 | //
|
---|
182 | // Setup sequence and check its validity
|
---|
183 | //
|
---|
184 | MDataSet seq(kSequences);
|
---|
185 | if (kNumAnalysis>=0)
|
---|
186 | seq.SetNumAnalysis(kNumAnalysis);
|
---|
187 | if (kPrintSeq || kPrintFiles)
|
---|
188 | {
|
---|
189 | gLog << all;
|
---|
190 | gLog.Separator(kSequences);
|
---|
191 | seq.Print(kPrintFiles?"files":"");
|
---|
192 | gLog << endl;
|
---|
193 | }
|
---|
194 | if (!seq.IsValid())
|
---|
195 | {
|
---|
196 | gLog << err << "Sequences read but not valid!" << endl << endl;
|
---|
197 | return 2;
|
---|
198 | }
|
---|
199 |
|
---|
200 | //
|
---|
201 | // Initialize root
|
---|
202 | //
|
---|
203 | MArray::Class()->IgnoreTObjectStreamer();
|
---|
204 | MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
205 |
|
---|
206 | TApplication app("Ganymed", &argc, argv);
|
---|
207 | if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
|
---|
208 | {
|
---|
209 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
---|
210 | return 1;
|
---|
211 | }
|
---|
212 |
|
---|
213 | Bool_t iswobble = seq.IsWobbleMode();
|
---|
214 | if (kWobbleModeOn)
|
---|
215 | iswobble = kTRUE;
|
---|
216 | if (kWobbleModeOff)
|
---|
217 | iswobble = kFALSE;
|
---|
218 |
|
---|
219 | //
|
---|
220 | // Update frequency by default = 1Hz
|
---|
221 | //
|
---|
222 | MStatusDisplay *d = new MStatusDisplay;
|
---|
223 |
|
---|
224 | // From now on each 'Exit' means: Terminate the application
|
---|
225 | d->SetBit(MStatusDisplay::kExitLoopOnExit);
|
---|
226 | d->SetTitle(kSequences);
|
---|
227 |
|
---|
228 | //
|
---|
229 | // Calculate pedestal for pedestal-calculation and calibration
|
---|
230 | //
|
---|
231 | MEnv env(kConfig);
|
---|
232 |
|
---|
233 | MJCut job(Form("MJCut #%d", seq.GetNumAnalysis()));
|
---|
234 | job.SetEnv(&env);
|
---|
235 | job.SetEnvDebug(kDebugEnv);
|
---|
236 | job.SetDisplay(d);;
|
---|
237 | job.SetOverwrite(kOverwrite);
|
---|
238 | job.SetPathOut(kOutpath);
|
---|
239 | job.SetNameOutFile(kOutfile);
|
---|
240 | job.SetNameSummaryFile(kNameSummary);
|
---|
241 | //job.SetNameResultFile(kNameResult);
|
---|
242 | job.EnableWriteOnly(kWriteOnly);
|
---|
243 | job.EnableWobbleMode(iswobble);
|
---|
244 | job.EnableFullDisplay(kFullDisplay);
|
---|
245 | job.EnableMonteCarloMode(kIsMc);
|
---|
246 | job.EnableStorageOfResult(!kSkipResult);
|
---|
247 | if (kWriteSummary) // Don't change flag set in SetNameSummaryFile
|
---|
248 | job.EnableStorageOfSummary();
|
---|
249 | //if (kWriteResult) // Don't change flag set in SetNameSummaryFile
|
---|
250 | // job.EnableStorageOfResult();
|
---|
251 |
|
---|
252 | if (!job.Process(seq))
|
---|
253 | {
|
---|
254 | gLog << err << "Calculation of cuts failed." << endl << endl;
|
---|
255 | return 2;
|
---|
256 | }
|
---|
257 | if (kDebugEnv>0)
|
---|
258 | env.PrintUntouched();
|
---|
259 |
|
---|
260 | if (!job.GetDisplay())
|
---|
261 | {
|
---|
262 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
---|
263 | return 1;
|
---|
264 | }
|
---|
265 |
|
---|
266 | if (kBatch || kQuit)
|
---|
267 | delete d;
|
---|
268 | else
|
---|
269 | {
|
---|
270 | // From now on each 'Close' means: Terminate the application
|
---|
271 | d->SetBit(MStatusDisplay::kExitLoopOnClose);
|
---|
272 |
|
---|
273 | // Wait until the user decides to exit the application
|
---|
274 | app.Run(kFALSE);
|
---|
275 | }
|
---|
276 |
|
---|
277 | if (TObject::GetObjectStat())
|
---|
278 | {
|
---|
279 | TObject::SetObjectStat(kFALSE);
|
---|
280 | gObjectTable->Print();
|
---|
281 | }
|
---|
282 |
|
---|
283 | return 0;
|
---|
284 | }
|
---|