source: tags/Mars-V0.9/ganymed.cc@ 10102

Last change on this file since 10102 was 6874, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.2 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 "MJCut.h"
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 << " 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
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 << " 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 << " --wobble Wobble Mode" << endl << endl;
52 gLog << " Options:" << endl;
53 gLog.Usage();
54 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
55 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
56 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
57 gLog << " --debug-env=3 Debug setting resources from resource file" << endl;
58 gLog << " --debug-mem Debug memory usage" << endl << endl;
59 gLog << endl;
60 gLog << " -q Quit when job is finished" << endl;
61 gLog << " -f Force overwrite of existing files" << endl;
62 gLog << " --n=[n] Analysis number" << endl;
63 gLog << " --out=path Path to write the all output to [def=local path]" << endl;
64 gLog << " --outf=filename Filename for output file (eg. status display)" << endl;
65 gLog << " --sum[=filename] Enable writing of summary file (events after cut0)" << endl;
66 gLog << " --res[=filename] Enable writing of result file (surviving events)" << endl;
67 gLog << " --write-only Only write output files. No histograms filled." << endl;
68 gLog << " --print-ds Print Dataset information" << endl;
69 gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
70 gLog << " --config=ganymed.rc Resource file [default=ganymed.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 << " Ganymed is the largest moon of Jupiter, a large, icy, outer moon that" << endl;
76 gLog << " is scarred with impact craters and many parallel faults. It has a" << endl;
77 gLog << " diameter of about 5268km and orbits Jupiter at a mean distance of" << endl;
78 gLog << " 1,070,000km. It has a magnetic field and probably has a molten iron" << endl;
79 gLog << " core. It takes Ganymed 7.15 days to orbit Jupiter. Its mass is" << endl;
80 gLog << " 1.5e23kg. It was independently discovered by Galileo and S.Marius in"<< endl;
81 gLog << " 1610. Ganymed is the largest moon in the solar system; it is also" << endl;
82 gLog << " larger than the planets Mercury and Pluto." << endl << endl;
83}
84
85int main(int argc, char **argv)
86{
87 StartUpMessage();
88
89 //
90 // Evaluate arguments
91 //
92 MArgs arg(argc, argv, kTRUE);
93
94 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
95 return 0;
96
97 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
98 {
99 Usage();
100 return -1;
101 }
102
103 gLog.Setup(arg);
104
105 const TString kConfig = arg.GetStringAndRemove("--config=", "ganymed.rc");
106
107 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-ds");
108 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
109 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
110 const Bool_t kWriteOnly = arg.HasOnlyAndRemove("--write-only");
111 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
112 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
113
114 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
115 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
116 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
117 //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
118
119 const Bool_t kModeWobble = arg.HasOnlyAndRemove("--wobble");
120
121 const Int_t kNumAnalysis = arg.GetIntAndRemove("--n=", -1);
122 const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
123 const TString kOutfile = arg.GetStringAndRemove("--outf=", "");
124 const Bool_t kWriteSummary = arg.HasOnlyAndRemove("--sum");
125 const TString kNameSummary = arg.GetStringAndRemove("--sum=");
126 const Bool_t kWriteResult = arg.HasOnlyAndRemove("--res");
127 const TString kNameResult = arg.GetStringAndRemove("--res=");
128
129 if (arg.GetNumOptions()>0)
130 {
131 gLog << warn << "WARNING - Unknown commandline options..." << endl;
132 arg.Print("options");
133 gLog << endl;
134 }
135
136 //
137 // check for the right usage of the program
138 //
139 if (arg.GetNumArguments()!=1)
140 {
141 Usage();
142 return -1;
143 }
144
145 //
146 // Setup sequence file and check for its existance
147 //
148 const TString kSequences = arg.GetArgumentStr(0);
149
150 if (gSystem->AccessPathName(kSequences, kFileExists))
151 {
152 gLog << err << "Sorry, sequences file '" << kSequences << "' doesn't exist." << endl;
153 return -1;
154 }
155
156 if (gSystem->AccessPathName(kConfig, kFileExists))
157 {
158 gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl;
159 return -1;
160 }
161
162 if (kDebugMem)
163 TObject::SetObjectStat(kTRUE);
164
165 //
166 // Setup sequence and check its validity
167 //
168 MDataSet seq(kSequences);
169 if (kNumAnalysis>=0)
170 seq.SetNumAnalysis(kNumAnalysis);
171 if (kPrintSeq || kPrintFiles)
172 {
173 gLog << all;
174 gLog.Separator(kSequences);
175 seq.Print(kPrintFiles?"files":"");
176 gLog << endl;
177 }
178 if (!seq.IsValid())
179 {
180 gLog << err << "Sequences read but not valid!" << endl << endl;
181 return -1;
182 }
183
184 //
185 // Initialize root
186 //
187 MArray::Class()->IgnoreTObjectStreamer();
188 MParContainer::Class()->IgnoreTObjectStreamer();
189
190 TApplication app("Ganymed", &argc, argv);
191 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
192 {
193 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
194 return 1;
195 }
196
197 //
198 // Update frequency by default = 1Hz
199 //
200 MStatusDisplay *d = new MStatusDisplay;
201
202 // From now on each 'Exit' means: Terminate the application
203 d->SetBit(MStatusDisplay::kExitLoopOnExit);
204 d->SetTitle(kSequences);
205
206 //
207 // Calculate pedestal for pedestal-calculation and calibration
208 //
209 MEnv env(kConfig);
210
211 MJCut job(Form("MJCut #%d", seq.GetNumAnalysis()));
212 job.SetEnv(&env);
213 job.SetEnvDebug(kDebugEnv);
214 job.SetDisplay(d);;
215 job.SetOverwrite(kOverwrite);
216 job.SetPathOut(kOutpath);
217 job.SetNameOutFile(kOutfile);
218 job.SetNameSummaryFile(kNameSummary);
219 job.SetNameResultFile(kNameResult);
220 job.EnableWriteOnly(kWriteOnly);
221 job.EnableWobbleMode(kModeWobble);
222 if (kWriteSummary) // Don't change flag set in SetNameSummaryFile
223 job.EnableStorageOfSummary();
224 if (kWriteResult) // Don't change flag set in SetNameSummaryFile
225 job.EnableStorageOfResult();
226
227 if (!job.ProcessFile(seq))
228 {
229 gLog << err << "Calculation of cuts failed." << endl << endl;
230 return -1;
231 }
232 if (kDebugEnv>0)
233 env.PrintUntouched();
234
235 if (!job.GetDisplay())
236 {
237 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
238 return 1;
239 }
240
241 if (kBatch || kQuit)
242 delete d;
243 else
244 {
245 // From now on each 'Close' means: Terminate the application
246 d->SetBit(MStatusDisplay::kExitLoopOnClose);
247
248 // Wait until the user decides to exit the application
249 app.Run(kFALSE);
250 }
251
252 if (TObject::GetObjectStat())
253 {
254 TObject::SetObjectStat(kFALSE);
255 gObjectTable->Print();
256 }
257
258 return 0;
259}
Note: See TracBrowser for help on using the repository browser.