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

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