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

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