source: trunk/MagicSoft/Mars/star.cc@ 6459

Last change on this file since 6459 was 6453, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.9 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 "MArgs.h"
12#include "MArray.h"
13#include "MDirIter.h"
14
15#include "MStatusDisplay.h"
16
17#include "MSequence.h"
18#include "MJStar.h"
19
20using namespace std;
21
22static void StartUpMessage()
23{
24 gLog << all << endl;
25
26 // 1 2 3 4 5 6
27 // 123456789012345678901234567890123456789012345678901234567890
28 gLog << "========================================================" << endl;
29 gLog << " Star - MARS V" << MARSVER << endl;
30 gLog << " MARS -- STandard Analysis and Reconstruction" << endl;
31 gLog << " Compiled on <" << __DATE__ << ">" << endl;
32 gLog << " Using ROOT v" << ROOTVER << endl;
33 gLog << "========================================================" << endl;
34 gLog << endl;
35}
36
37static void Usage()
38{
39 // 1 2 3 4 5 6 7 8
40 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
41 gLog << all << endl;
42 gLog << "Sorry the usage is:" << endl;
43 gLog << " star [options] sequence.txt" << endl << endl;
44 gLog << " Arguments:" << endl;
45 gLog << " sequence.txt: Ascii file defining a sequence of runs" << endl;
46 gLog << " For more details see MSequence" << endl;
47 gLog << " Root Options:" << endl;
48 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
49 gLog << " Options:" << endl;
50 gLog.Usage();
51 gLog << " --debug-env Debug setting resources from file" << endl;
52 gLog << " --debug-mem Debug memory usage" << endl << endl;
53 gLog << endl;
54 gLog << " Input Options:" << endl;
55 gLog << " -mc You must use this for MC files (PRELIMINARY)" << endl << 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 execution if not all files found" << endl;
60 gLog << " --ind=path Path where to search for the calibrated data (Y)" << endl;
61 gLog << " [default=standard path in datacenter]" << endl;
62 gLog << " --out=path Path to write the all results to [def=local path]" << endl;
63 gLog << " (overwrites --outc and --outy)" << endl;
64 gLog << " --print-seq Print Sequence information" << endl;
65 gLog << " --print-files Print Files taken from Sequence" << endl;
66 gLog << " --print-only Do not excute anything except print" << endl;
67 gLog << " --config=star.rc Resource file [default=star.rc]" << endl;
68 gLog << endl;
69 gLog << " --version, -V Show startup message with version number" << endl;
70 gLog << " -?, -h, --help This help" << endl << endl;
71}
72
73int main(int argc, char **argv)
74{
75 StartUpMessage();
76
77 //
78 // Evaluate arguments
79 //
80 MArgs arg(argc, argv, kTRUE);
81
82 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
83 return 0;
84
85 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
86 {
87 Usage();
88 return -1;
89 }
90
91 gLog.Setup(arg);
92
93 const TString kConfig = arg.GetStringAndRemove("--config=", "star.rc");
94
95 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
96 //const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
97 //const Bool_t kPrintOnly = arg.HasOnlyAndRemove("--print-only");
98 const Bool_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env");
99 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
100
101 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
102 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
103 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
104 //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
105 const Bool_t kIsMC = arg.HasOnlyAndRemove("-mc");
106
107 const TString kInpath = arg.GetStringAndRemove("--ind=", "");
108 const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
109
110 if (arg.GetNumOptions()>0)
111 {
112 gLog << warn << "WARNING - Unknown commandline options..." << endl;
113 arg.Print("options");
114 gLog << endl;
115 return -1;
116 }
117
118 //
119 // check for the right usage of the program
120 //
121 if (arg.GetNumArguments()!=1)
122 {
123 Usage();
124 return -1;
125 }
126
127 //
128 // Setup sequence file and check for its existance
129 //
130 const TString kSequence = arg.GetArgumentStr(0);
131
132 if (gSystem->AccessPathName(kSequence, kFileExists))
133 {
134 gLog << err << "Sorry, sequence file '" << kSequence << "' doesn't exist." << endl;
135 return -1;
136 }
137
138 //
139 // Setup sequence and check its validity
140 //
141 MSequence seq(kSequence);
142 if (kPrintSeq)
143 {
144 gLog << all;
145 gLog.Separator(kSequence);
146 seq.Print();
147 gLog << endl;
148 }
149 if (!seq.IsValid())
150 {
151 gLog << err << "Sequence read but not valid!" << endl << endl;
152 return -1;
153 }
154
155 //
156 // Process print options
157 //
158 /*
159 MDirIter iter;
160
161 const Int_t n0 = seq.SetupDatRuns(iter, kInpath);
162 const Int_t n1 = seq.GetNumDatRuns();
163
164 if (kPrintFiles)
165 {
166 gLog << all;
167 gLog.Separator("Data Files");
168 iter.Print("all");
169 gLog << endl;
170 }
171
172 //
173 // Check for existance of all files
174 //
175 if (n0 != n1)
176 {
177 if (kForceExec)
178 gLog << warn << "WARNING";
179 else
180 gLog << err << "ERROR";
181 gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in ";
182 gLog << (kInpath.IsNull() ? "<defaultpath>" : kInpath.Data()) << endl;
183 if (!kForceExec)
184 return -1;
185 }
186
187 if (kPrintOnly)
188 return 0;
189 */
190
191 //
192 // Initialize root
193 //
194 MArray::Class()->IgnoreTObjectStreamer();
195 MParContainer::Class()->IgnoreTObjectStreamer();
196
197 TApplication app("Star", &argc, argv);
198 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
199 {
200 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
201 return 1;
202 }
203
204 //
205 // Update frequency by default = 1Hz
206 //
207 MStatusDisplay *d = new MStatusDisplay;
208
209 // From now on each 'Exit' means: Terminate the application
210 d->SetBit(MStatusDisplay::kExitLoopOnExit);
211 d->SetTitle(kSequence);
212
213 if (kDebugMem)
214 TObject::SetObjectStat(kTRUE);
215
216 //
217 // Do calibration in a block (debug mem)
218 //
219 {
220 MJStar job(Form("MJStar #%d", seq.GetSequence()));
221 job.SetSequence(seq);
222 job.SetEnv(kConfig);
223 job.SetEnvDebug(kDebugEnv);
224 job.SetDisplay(d);;
225 job.SetOverwrite(kOverwrite);
226 job.SetPathOut(kOutpath);
227 job.SetPathData(kInpath);
228 // job.SetPathIn(kInpath); // not yet needed
229
230 if (!job.ProcessFile(kIsMC))
231 {
232 gLog << err << "Calculation of image parameters failed." << endl << endl;
233 return -1;
234 }
235
236 if (!job.GetDisplay())
237 {
238 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
239 return 1;
240 }
241 }
242
243 if (kBatch || kQuit)
244 delete d;
245 else
246 {
247 // From now on each 'Close' means: Terminate the application
248 d->SetBit(MStatusDisplay::kExitLoopOnClose);
249
250 // Wait until the user decides to exit the application
251 app.Run(kFALSE);
252 }
253
254 if (TObject::GetObjectStat())
255 {
256 TObject::SetObjectStat(kFALSE);
257 gObjectTable->Print();
258 }
259
260 return 0;
261}
Note: See TracBrowser for help on using the repository browser.