source: tags/Mars-V0.8.7pre/ganymed.cc@ 12583

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