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

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