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

Last change on this file since 5368 was 5309, 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 /*
151 MDirIter iter;
152
153 const Int_t n0 = seq.SetupDatRuns(iter, kInpath);
154 const Int_t n1 = seq.GetNumDatRuns();
155
156 if (kPrintFiles)
157 {
158 gLog << all;
159 gLog.Separator("Data Files");
160 iter.Print("all");
161 gLog << endl;
162 }
163
164 //
165 // Check for existance of all files
166 //
167 if (n0 != n1)
168 {
169 if (kForceExec)
170 gLog << warn << "WARNING";
171 else
172 gLog << err << "ERROR";
173 gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in ";
174 gLog << (kInpath.IsNull() ? "<defaultpath>" : kInpath.Data()) << endl;
175 if (!kForceExec)
176 return -1;
177 }
178
179 if (kPrintOnly)
180 return 0;
181 */
182
183 //
184 // Initialize root
185 //
186 MArray::Class()->IgnoreTObjectStreamer();
187 MParContainer::Class()->IgnoreTObjectStreamer();
188
189 TApplication app("Star", &argc, argv);
190 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
191 {
192 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
193 return 1;
194 }
195
196 //
197 // Update frequency by default = 1Hz
198 //
199 MStatusDisplay *d = new MStatusDisplay;
200
201 // From now on each 'Exit' means: Terminate the application
202 d->SetBit(MStatusDisplay::kExitLoopOnExit);
203 d->SetTitle(kSequence);
204
205 //
206 // Do calibration
207 //
208 MJStar job(Form("MJStar #%d", seq.GetSequence()));
209 job.SetSequence(seq);
210 job.SetEnv(kConfig);
211 job.SetEnvDebug(kDebugEnv);
212 job.SetDisplay(d);;
213 job.SetOverwrite(kOverwrite);
214 job.SetPathOut(kOutpath);
215 job.SetPathData(kInpath);
216 // job.SetPathIn(kInpath); // not yet needed
217
218 if (!job.ProcessFile(kIsMC))
219 {
220 gLog << err << "Calculation of image parameters failed." << endl << endl;
221 return -1;
222 }
223
224 if (!job.GetDisplay())
225 {
226 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
227 return 1;
228 }
229
230 if (kBatch || kQuit)
231 {
232 delete d;
233 return 0;
234 }
235
236 // From now on each 'Close' means: Terminate the application
237 d->SetBit(MStatusDisplay::kExitLoopOnClose);
238
239 // Wait until the user decides to exit the application
240 app.Run(kFALSE);
241 return 0;
242}
Note: See TracBrowser for help on using the repository browser.