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

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