source: tags/Mars-V0.9.4.1/star.cc@ 10575

Last change on this file since 10575 was 7091, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 8.4 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 with ROOT v" << ROOTVER << " on <" << __DATE__ ">" << endl;
33 gLog << "========================================================" << endl;
34 gLog << endl;
35}
36
37static void Usage()
38{
39 // 1 2 3 4 5 6 7 8
40 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
41 gLog << all << endl;
42 gLog << "Sorry the usage is:" << endl;
43 gLog << " star [options] sequence.txt" << endl << endl;
44 gLog << " Arguments:" << endl;
45 gLog << " sequence.txt: Ascii file defining a sequence of runs" << endl;
46 gLog << " For more details see MSequence" << endl;
47 gLog << " Root Options:" << endl;
48 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
49 gLog << " Options:" << endl;
50 gLog.Usage();
51 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
52 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
53 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
54 gLog << " --debug-env=3 Debug setting resources from resource file" << endl;
55 gLog << " --debug-mem Debug memory usage" << endl << endl;
56 gLog << endl;
57 gLog << " Input Options:" << endl;
58 gLog << " -mc You must use this for MC files (PRELIMINARY)" << endl << endl;
59 gLog << " Output options:" << endl;
60 gLog << " -q Quit when job is finished" << endl;
61 gLog << " -f Force overwrite of existing files" << endl;
62 gLog << " -ff Force execution if not all files found" << endl;
63 gLog << " --ind=path Path where to search for the calibrated data (Y)" << endl;
64 gLog << " [default=standard path in datacenter]" << endl;
65 gLog << " --out=path Path to write the all results to [def=local path]" << endl;
66 gLog << " (overwrites --outc and --outy)" << endl;
67 gLog << " --no-muons Switch off Muon analysis (for fast tests)" << 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, MSequence::kCalibrated, kInpathD);
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 //
93 // Evaluate arguments
94 //
95 MArgs arg(argc, argv, kTRUE);
96 gLog.Setup(arg);
97
98 StartUpMessage();
99
100 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
101 return 0;
102
103 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
104 {
105 Usage();
106 return 2;
107 }
108
109 const TString kConfig = arg.GetStringAndRemove("--config=", "star.rc");
110
111 const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
112 const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
113 const Bool_t kPrintFound = arg.HasOnlyAndRemove("--print-found");
114 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
115 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
116 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
117
118 const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
119 const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
120 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
121 //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
122 const Bool_t kIsMC = arg.HasOnlyAndRemove("-mc");
123 const Bool_t kNoMuons = arg.HasOnlyAndRemove("--no-muons");
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 2;
134 }
135
136 //
137 // check for the right usage of the program
138 //
139 if (arg.GetNumArguments()!=1)
140 {
141 Usage();
142 return 2;
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 2;
154 }
155
156 if (gSystem->AccessPathName(kConfig, kFileExists))
157 {
158 gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl;
159 return 2;
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 2;
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 if (kNoMuons)
227 job.DisableMuonAnalysis();
228
229 if (!job.Process(kIsMC))
230 {
231 gLog << err << "Calculation of image parameters failed." << endl << endl;
232 return 2;
233 }
234
235 if (kDebugEnv>0)
236 env.PrintUntouched();
237
238 if (!job.GetDisplay())
239 {
240 gLog << warn << "Display closed by user... execution aborted." << endl << endl;
241 return 1;
242 }
243 }
244
245 if (kBatch || kQuit)
246 delete d;
247 else
248 {
249 // From now on each 'Close' means: Terminate the application
250 d->SetBit(MStatusDisplay::kExitLoopOnClose);
251
252 // Wait until the user decides to exit the application
253 app.Run(kFALSE);
254 }
255
256 if (TObject::GetObjectStat())
257 {
258 TObject::SetObjectStat(kFALSE);
259 gObjectTable->Print();
260 }
261
262 return 0;
263}
Note: See TracBrowser for help on using the repository browser.