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

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