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

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