source: tags/Mars-V0.9.2/star.cc@ 10102

Last change on this file since 10102 was 7001, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 8.5 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 << " --no-muons Switch off Muon analysis (for fast tests)" << endl;
69 gLog << " --print-seq Print Sequence information" << endl;
70 gLog << " --print-files Print Files taken from Sequence" << endl;
71 gLog << " --print-found Print Files found from Sequence" << endl;
72 gLog << " --config=star.rc Resource file [default=star.rc]" << endl;
73 gLog << endl;
74 gLog << " --version, -V Show startup message with version number" << endl;
75 gLog << " -?, -h, --help This help" << endl << endl;
76}
77
78static void PrintFiles(const MSequence &seq, const TString &kInpathD, Bool_t allopt)
79{
80 const char *prep = allopt ? "Found" : "Scheduled";
81
82 MDirIter Next;
83 seq.SetupDatRuns(Next, MSequence::kCalibrated, kInpathD);
84
85 gLog << all;
86 gLog.Separator(Form("%s Data Files", prep));
87 Next.Print(allopt?"all":"");
88 gLog << endl;
89}
90
91int main(int argc, char **argv)
92{
93 //
94 // Evaluate arguments
95 //
96 MArgs arg(argc, argv, kTRUE);
97 gLog.Setup(arg);
98
99 StartUpMessage();
100
101 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
102 return 0;
103
104 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
105 {
106 Usage();
107 return 2;
108 }
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 const Bool_t kNoMuons = arg.HasOnlyAndRemove("--no-muons");
125
126 const TString kInpath = arg.GetStringAndRemove("--ind=", "");
127 const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
128
129 if (arg.GetNumOptions()>0)
130 {
131 gLog << warn << "WARNING - Unknown commandline options..." << endl;
132 arg.Print("options");
133 gLog << endl;
134 return 2;
135 }
136
137 //
138 // check for the right usage of the program
139 //
140 if (arg.GetNumArguments()!=1)
141 {
142 Usage();
143 return 2;
144 }
145
146 //
147 // Setup sequence file and check for its existance
148 //
149 const TString kSequence = arg.GetArgumentStr(0);
150
151 if (gSystem->AccessPathName(kSequence, kFileExists))
152 {
153 gLog << err << "Sorry, sequence file '" << kSequence << "' doesn't exist." << endl;
154 return 2;
155 }
156
157 if (gSystem->AccessPathName(kConfig, kFileExists))
158 {
159 gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl;
160 return 2;
161 }
162
163 //
164 // Setup sequence and check its validity
165 //
166 MSequence seq(kSequence);
167 if (kPrintSeq)
168 {
169 gLog << all;
170 gLog.Separator(kSequence);
171 seq.Print();
172 gLog << endl;
173 }
174 if (!seq.IsValid())
175 {
176 gLog << err << "Sequence read but not valid!" << endl << endl;
177 return 2;
178 }
179
180 //
181 // Process print options
182 //
183 if (kPrintFiles)
184 PrintFiles(seq, kInpath, kFALSE);
185 if (kPrintFound)
186 PrintFiles(seq, kInpath, kTRUE);
187
188 //
189 // Initialize root
190 //
191 MArray::Class()->IgnoreTObjectStreamer();
192 MParContainer::Class()->IgnoreTObjectStreamer();
193
194 TApplication app("star", &argc, argv);
195 if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
196 {
197 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
198 return 1;
199 }
200
201 //
202 // Update frequency by default = 1Hz
203 //
204 MStatusDisplay *d = new MStatusDisplay;
205
206 // From now on each 'Exit' means: Terminate the application
207 d->SetBit(MStatusDisplay::kExitLoopOnExit);
208 d->SetTitle(kSequence);
209
210 if (kDebugMem)
211 TObject::SetObjectStat(kTRUE);
212
213 //
214 // Do calibration in a block (debug mem)
215 //
216 MEnv env(kConfig);
217 {
218 MJStar job(Form("MJStar #%d", seq.GetSequence()));
219 job.SetSequence(seq);
220 job.SetEnv(&env);
221 job.SetEnvDebug(kDebugEnv);
222 job.SetDisplay(d);;
223 job.SetOverwrite(kOverwrite);
224 job.SetPathOut(kOutpath);
225 job.SetPathData(kInpath);
226 // job.SetPathIn(kInpath); // not yet needed
227 if (kNoMuons)
228 job.DisableMuonAnalysis();
229
230 if (!job.Process(kIsMC))
231 {
232 gLog << err << "Calculation of image parameters failed." << endl << endl;
233 return 2;
234 }
235
236 if (kDebugEnv>0)
237 env.PrintUntouched();
238
239 if (!job.GetDisplay())
240 {
241 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
242 return 1;
243 }
244 }
245
246 if (kBatch || kQuit)
247 delete d;
248 else
249 {
250 // From now on each 'Close' means: Terminate the application
251 d->SetBit(MStatusDisplay::kExitLoopOnClose);
252
253 // Wait until the user decides to exit the application
254 app.Run(kFALSE);
255 }
256
257 if (TObject::GetObjectStat())
258 {
259 TObject::SetObjectStat(kFALSE);
260 gObjectTable->Print();
261 }
262
263 return 0;
264}
Note: See TracBrowser for help on using the repository browser.