source: tags/Mars-V0.8.6/star.cc@ 19793

Last change on this file since 19793 was 5101, 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 }
108
109 //
110 // check for the right usage of the program
111 //
112 if (arg.GetNumArguments()!=1)
113 {
114 Usage();
115 return -1;
116 }
117
118 //
119 // Setup sequence file and check for its existance
120 //
121 const TString kSequence = arg.GetArgumentStr(0);
122
123 if (gSystem->AccessPathName(kSequence, kFileExists))
124 {
125 gLog << err << "Sorry, sequence file '" << kSequence << "' doesn't exist." << endl;
126 return -1;
127 }
128
129 //
130 // Setup sequence and check its validity
131 //
132 MSequence seq(kSequence);
133 if (kPrintSeq)
134 {
135 gLog << all;
136 gLog.Separator(kSequence);
137 seq.Print();
138 gLog << endl;
139 }
140 if (!seq.IsValid())
141 {
142 gLog << err << "Sequence read but not valid!" << endl << endl;
143 return -1;
144 }
145
146 //
147 // Process print options
148 //
149 MDirIter iter;
150
151 const Int_t n0 = seq.SetupDatRuns(iter, kInpath);
152 const Int_t n1 = seq.GetNumDatRuns();
153
154 if (kPrintFiles)
155 {
156 gLog << all;
157 gLog.Separator("Data Files");
158 iter.Print("all");
159 gLog << endl;
160 }
161
162 //
163 // Check for existance of all files
164 //
165 if (n0 != n1)
166 {
167 if (kForceExec)
168 gLog << warn << "WARNING";
169 else
170 gLog << err << "ERROR";
171 gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in ";
172 gLog << (kInpath.IsNull() ? "<defaultpath>" : kInpath.Data()) << endl;
173 if (!kForceExec)
174 return -1;
175 }
176
177 if (kPrintOnly)
178 return 0;
179
180 //
181 // Initialize root
182 //
183 MArray::Class()->IgnoreTObjectStreamer();
184 MParContainer::Class()->IgnoreTObjectStreamer();
185
186 TApplication app("Star", &argc, argv);
187 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
188 {
189 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
190 return 1;
191 }
192
193 //
194 // Update frequency by default = 1Hz
195 //
196 MStatusDisplay *d = new MStatusDisplay;
197
198 // From now on each 'Exit' means: Terminate the application
199 d->SetBit(MStatusDisplay::kExitLoopOnExit);
200 d->SetTitle(kSequence);
201
202 //
203 // Do calibration
204 //
205 MJStar job(Form("MJStar #%d", seq.GetSequence()));
206 job.SetSequence(seq);
207 job.SetEnv(kConfig);
208 job.SetEnvDebug(kDebugEnv);
209 job.SetDisplay(d);;
210 job.SetOverwrite(kOverwrite);
211 job.SetPathOut(kOutpath);
212 job.SetPathData(kInpath);
213 // job.SetPathIn(kInpath); // not yet needed
214
215 if (!job.ProcessFile(kIsMC))
216 {
217 gLog << err << "Calculation of image parameters failed." << endl << endl;
218 return -1;
219 }
220
221 if (!job.GetDisplay())
222 {
223 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
224 return 1;
225 }
226
227 if (kBatch || kQuit)
228 {
229 delete d;
230 return 0;
231 }
232
233 // From now on each 'Close' means: Terminate the application
234 d->SetBit(MStatusDisplay::kExitLoopOnClose);
235
236 // Wait until the user decides to exit the application
237 app.Run(kFALSE);
238 return 0;
239}
Note: See TracBrowser for help on using the repository browser.