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 |
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | static 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" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
|
---|
33 | gLog << "========================================================" << endl;
|
---|
34 | gLog << endl;
|
---|
35 | }
|
---|
36 |
|
---|
37 | static 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|number" << endl << endl;
|
---|
44 | gLog << " Arguments:" << endl;
|
---|
45 | gLog << " sequence.txt: Ascii file defining a sequence of runs" << endl;
|
---|
46 | gLog << " number: The sequence number (using file in the datacenter)" << 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 |
|
---|
78 | static 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 |
|
---|
91 | int main(int argc, char **argv)
|
---|
92 | {
|
---|
93 | if (!MARS::CheckRootVer())
|
---|
94 | return 0xff;
|
---|
95 |
|
---|
96 | MLog::RedirectErrorHandler(MLog::kColor);
|
---|
97 |
|
---|
98 | //
|
---|
99 | // Evaluate arguments
|
---|
100 | //
|
---|
101 | MArgs arg(argc, argv, kTRUE);
|
---|
102 | gLog.Setup(arg);
|
---|
103 |
|
---|
104 | StartUpMessage();
|
---|
105 |
|
---|
106 | if (arg.HasOnly("-V") || arg.HasOnly("--version"))
|
---|
107 | return 0;
|
---|
108 |
|
---|
109 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
---|
110 | {
|
---|
111 | Usage();
|
---|
112 | return 2;
|
---|
113 | }
|
---|
114 |
|
---|
115 | const TString kConfig = arg.GetStringAndRemove("--config=", "star.rc");
|
---|
116 |
|
---|
117 | const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
|
---|
118 | const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
|
---|
119 | const Bool_t kPrintFound = arg.HasOnlyAndRemove("--print-found");
|
---|
120 | const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
|
---|
121 | Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
|
---|
122 | kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
|
---|
123 |
|
---|
124 | const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
|
---|
125 | const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
|
---|
126 | const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
|
---|
127 | //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
|
---|
128 | const Bool_t kIsMC = arg.HasOnlyAndRemove("-mc");
|
---|
129 | const Bool_t kNoMuons = arg.HasOnlyAndRemove("--no-muons");
|
---|
130 |
|
---|
131 | const TString kInpath = arg.GetStringAndRemove("--ind=", "");
|
---|
132 | const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
|
---|
133 |
|
---|
134 | if (arg.GetNumOptions()>0)
|
---|
135 | {
|
---|
136 | gLog << warn << "WARNING - Unknown commandline options..." << endl;
|
---|
137 | arg.Print("options");
|
---|
138 | gLog << endl;
|
---|
139 | return 2;
|
---|
140 | }
|
---|
141 |
|
---|
142 | //
|
---|
143 | // check for the right usage of the program
|
---|
144 | //
|
---|
145 | if (arg.GetNumArguments()!=1)
|
---|
146 | {
|
---|
147 | Usage();
|
---|
148 | return 2;
|
---|
149 | }
|
---|
150 |
|
---|
151 | //
|
---|
152 | // Setup sequence file and check for its existance
|
---|
153 | //
|
---|
154 | TString kSequence = arg.GetArgumentStr(0);
|
---|
155 |
|
---|
156 | //
|
---|
157 | // Something special for datacenter access
|
---|
158 | //
|
---|
159 | if (!MSequence::InflatePath(kSequence, kIsMC))
|
---|
160 | return 2;
|
---|
161 |
|
---|
162 | //
|
---|
163 | // Setup sequence and check its validity
|
---|
164 | //
|
---|
165 | MSequence seq(kSequence, kInpath);
|
---|
166 | if (!seq.IsMonteCarlo())
|
---|
167 | seq.SetMonteCarlo(kIsMC);
|
---|
168 | if (kPrintSeq)
|
---|
169 | {
|
---|
170 | gLog << all;
|
---|
171 | gLog.Separator(kSequence);
|
---|
172 | seq.Print();
|
---|
173 | gLog << endl;
|
---|
174 | }
|
---|
175 | if (!seq.IsValid())
|
---|
176 | {
|
---|
177 | gLog << err << "Sequence read but not valid!" << endl << endl;
|
---|
178 | return 2;
|
---|
179 | }
|
---|
180 |
|
---|
181 | //
|
---|
182 | // Process print options
|
---|
183 | //
|
---|
184 | if (kPrintFiles)
|
---|
185 | PrintFiles(seq, kInpath, kFALSE);
|
---|
186 | if (kPrintFound)
|
---|
187 | PrintFiles(seq, kInpath, kTRUE);
|
---|
188 |
|
---|
189 | //
|
---|
190 | // Initialize root
|
---|
191 | //
|
---|
192 | MArray::Class()->IgnoreTObjectStreamer();
|
---|
193 | MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
194 |
|
---|
195 | TApplication app("star", &argc, argv);
|
---|
196 | if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
|
---|
197 | {
|
---|
198 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
---|
199 | return 1;
|
---|
200 | }
|
---|
201 |
|
---|
202 | //
|
---|
203 | // Update frequency by default = 1Hz
|
---|
204 | //
|
---|
205 | MStatusDisplay *d = new MStatusDisplay;
|
---|
206 |
|
---|
207 | // From now on each 'Exit' means: Terminate the application
|
---|
208 | d->SetBit(MStatusDisplay::kExitLoopOnExit);
|
---|
209 | d->SetTitle(kSequence);
|
---|
210 |
|
---|
211 | if (kDebugMem)
|
---|
212 | TObject::SetObjectStat(kTRUE);
|
---|
213 |
|
---|
214 | //
|
---|
215 | // Do calibration in a block (debug mem)
|
---|
216 | //
|
---|
217 | MEnv env(kConfig);
|
---|
218 | if (!env.IsValid())
|
---|
219 | {
|
---|
220 | gLog << err << "Configuration file " << kConfig << " not found." << endl;
|
---|
221 | return 0xfe;
|
---|
222 | }
|
---|
223 |
|
---|
224 | {
|
---|
225 | MJStar job(Form("MJStar #%d", seq.GetSequence()));
|
---|
226 | job.SetSequence(seq);
|
---|
227 | job.SetEnv(&env);
|
---|
228 | job.SetEnvDebug(kDebugEnv);
|
---|
229 | job.SetDisplay(d);;
|
---|
230 | job.SetOverwrite(kOverwrite);
|
---|
231 | job.SetPathOut(kOutpath);
|
---|
232 | // job.SetPathIn(kInpath); // not yet needed
|
---|
233 | if (kNoMuons)
|
---|
234 | job.DisableMuonAnalysis();
|
---|
235 |
|
---|
236 | if (!job.Process())
|
---|
237 | {
|
---|
238 | gLog << err << "Calculation of image parameters failed." << endl << endl;
|
---|
239 | return 2;
|
---|
240 | }
|
---|
241 |
|
---|
242 | if (kDebugEnv>0)
|
---|
243 | env.PrintUntouched();
|
---|
244 |
|
---|
245 | if (!job.GetDisplay())
|
---|
246 | {
|
---|
247 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
---|
248 | return 1;
|
---|
249 | }
|
---|
250 | }
|
---|
251 |
|
---|
252 | if (kBatch || kQuit)
|
---|
253 | delete d;
|
---|
254 | else
|
---|
255 | {
|
---|
256 | // From now on each 'Close' means: Terminate the application
|
---|
257 | d->SetBit(MStatusDisplay::kExitLoopOnClose);
|
---|
258 |
|
---|
259 | // Wait until the user decides to exit the application
|
---|
260 | app.Run(kFALSE);
|
---|
261 | }
|
---|
262 |
|
---|
263 | if (TObject::GetObjectStat())
|
---|
264 | {
|
---|
265 | TObject::SetObjectStat(kFALSE);
|
---|
266 | gObjectTable->Print();
|
---|
267 | }
|
---|
268 |
|
---|
269 | return 0;
|
---|
270 | }
|
---|