source: tags/Mars-V0.8.7pre/star.cc@ 10107

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