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 "MDataSet.h"
|
---|
19 | #include "MJCut.h"
|
---|
20 |
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | static void StartUpMessage()
|
---|
24 | {
|
---|
25 | gLog << all << endl;
|
---|
26 |
|
---|
27 | // 1 2 3 4 5
|
---|
28 | // 12345678901234567890123456789012345678901234567890
|
---|
29 | gLog << "========================================================" << endl;
|
---|
30 | gLog << " Ganymed - MARS V" << MARSVER << endl;
|
---|
31 | gLog << " MARS -- Gammas Are Now Your Most Exciting Discovery" << endl;
|
---|
32 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
---|
33 | gLog << " Using ROOT v" << ROOTVER << endl;
|
---|
34 | gLog << "========================================================" << endl;
|
---|
35 | gLog << endl;
|
---|
36 | }
|
---|
37 |
|
---|
38 | static 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 << " ganymed [-c] [-y] [options] sequences.txt" << endl << endl;
|
---|
45 | gLog << " Arguments:" << endl;
|
---|
46 | gLog << " dataset.txt: Ascii file defining a collection of sequences" << endl;
|
---|
47 | gLog << " For more details see MDataSet." << 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 << " -q Quit when job is finished" << endl;
|
---|
59 | gLog << " -f Force overwrite of existing files" << endl;
|
---|
60 | gLog << " --n=[n] Analysis number" << endl;
|
---|
61 | gLog << " --out=path Path to write the all output to [def=local path]" << endl;
|
---|
62 | gLog << " --outf=filename Filename for output file (eg. status display)" << endl;
|
---|
63 | gLog << " --sum[=filename] Enable writing of summary file (events after cut0)" << endl;
|
---|
64 | gLog << " --res[=filename] Enable writing of result file (surviving events)" << endl;
|
---|
65 | gLog << " --write-only Only write output files. No histograms filled." << endl;
|
---|
66 | gLog << " --print-seq Print Sequences information" << endl;
|
---|
67 | gLog << " --print-files Print Files taken from Sequences ('+' found, '-' missing)" << endl;
|
---|
68 | gLog << " --config=ganymed.rc Resource file [default=ganymed.rc]" << endl;
|
---|
69 | gLog << endl;
|
---|
70 | gLog << " --version, -V Show startup message with version number" << endl;
|
---|
71 | gLog << " -?, -h, --help This help" << endl;
|
---|
72 | gLog << endl;
|
---|
73 | }
|
---|
74 |
|
---|
75 | int main(int argc, char **argv)
|
---|
76 | {
|
---|
77 | StartUpMessage();
|
---|
78 |
|
---|
79 | //
|
---|
80 | // Evaluate arguments
|
---|
81 | //
|
---|
82 | MArgs arg(argc, argv, kTRUE);
|
---|
83 |
|
---|
84 | if (arg.HasOnly("-V") || arg.HasOnly("--version"))
|
---|
85 | return 0;
|
---|
86 |
|
---|
87 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
---|
88 | {
|
---|
89 | Usage();
|
---|
90 | return -1;
|
---|
91 | }
|
---|
92 |
|
---|
93 | gLog.Setup(arg);
|
---|
94 |
|
---|
95 | const TString kConfig = arg.GetStringAndRemove("--config=", "ganymed.rc");
|
---|
96 |
|
---|
97 | const Bool_t kPrintSeq = arg.HasOnlyAndRemove("--print-seq");
|
---|
98 | const Bool_t kPrintFiles = arg.HasOnlyAndRemove("--print-files");
|
---|
99 | const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
|
---|
100 | const Bool_t kWriteOnly = arg.HasOnlyAndRemove("--write-only");
|
---|
101 | Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
|
---|
102 | kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
|
---|
103 |
|
---|
104 | const Bool_t kQuit = arg.HasOnlyAndRemove("-q");
|
---|
105 | const Bool_t kBatch = arg.HasOnlyAndRemove("-b");
|
---|
106 | const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
|
---|
107 | //const Bool_t kForceExec = arg.HasOnlyAndRemove("-ff");
|
---|
108 |
|
---|
109 | const Int_t kNumAnalysis = arg.GetIntAndRemove("--n=", -1);
|
---|
110 | const TString kOutpath = arg.GetStringAndRemove("--out=", ".");
|
---|
111 | const TString kOutfile = arg.GetStringAndRemove("--outf=", "");
|
---|
112 | const Bool_t kWriteSummary = arg.HasOnlyAndRemove("--sum");
|
---|
113 | const TString kNameSummary = arg.GetStringAndRemove("--sum=");
|
---|
114 | const Bool_t kWriteResult = arg.HasOnlyAndRemove("--res");
|
---|
115 | const TString kNameResult = arg.GetStringAndRemove("--res=");
|
---|
116 |
|
---|
117 | if (arg.GetNumOptions()>0)
|
---|
118 | {
|
---|
119 | gLog << warn << "WARNING - Unknown commandline options..." << endl;
|
---|
120 | arg.Print("options");
|
---|
121 | gLog << endl;
|
---|
122 | }
|
---|
123 |
|
---|
124 | //
|
---|
125 | // check for the right usage of the program
|
---|
126 | //
|
---|
127 | if (arg.GetNumArguments()!=1)
|
---|
128 | {
|
---|
129 | Usage();
|
---|
130 | return -1;
|
---|
131 | }
|
---|
132 |
|
---|
133 | //
|
---|
134 | // Setup sequence file and check for its existance
|
---|
135 | //
|
---|
136 | const TString kSequences = arg.GetArgumentStr(0);
|
---|
137 |
|
---|
138 | if (gSystem->AccessPathName(kSequences, kFileExists))
|
---|
139 | {
|
---|
140 | gLog << err << "Sorry, sequences file '" << kSequences << "' doesn't exist." << endl;
|
---|
141 | return -1;
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (gSystem->AccessPathName(kConfig, kFileExists))
|
---|
145 | {
|
---|
146 | gLog << err << "Sorry, config file '" << kConfig << "' doesn't exist." << endl;
|
---|
147 | return -1;
|
---|
148 | }
|
---|
149 |
|
---|
150 | if (kDebugMem)
|
---|
151 | TObject::SetObjectStat(kTRUE);
|
---|
152 |
|
---|
153 | //
|
---|
154 | // Setup sequence and check its validity
|
---|
155 | //
|
---|
156 | MDataSet seq(kSequences);
|
---|
157 | if (kNumAnalysis>=0)
|
---|
158 | seq.SetNumAnalysis(kNumAnalysis);
|
---|
159 | if (kPrintSeq || kPrintFiles)
|
---|
160 | {
|
---|
161 | gLog << all;
|
---|
162 | gLog.Separator(kSequences);
|
---|
163 | seq.Print(kPrintFiles?"files":"");
|
---|
164 | gLog << endl;
|
---|
165 | }
|
---|
166 | if (!seq.IsValid())
|
---|
167 | {
|
---|
168 | gLog << err << "Sequences read but not valid!" << endl << endl;
|
---|
169 | return -1;
|
---|
170 | }
|
---|
171 |
|
---|
172 | //
|
---|
173 | // Initialize root
|
---|
174 | //
|
---|
175 | MArray::Class()->IgnoreTObjectStreamer();
|
---|
176 | MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
177 |
|
---|
178 | TApplication app("Ganymed", &argc, argv);
|
---|
179 | if (!gROOT->IsBatch() && !gClient || gROOT->IsBatch() && !kBatch)
|
---|
180 | {
|
---|
181 | gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
---|
182 | return 1;
|
---|
183 | }
|
---|
184 |
|
---|
185 | //
|
---|
186 | // Update frequency by default = 1Hz
|
---|
187 | //
|
---|
188 | MStatusDisplay *d = new MStatusDisplay;
|
---|
189 |
|
---|
190 | // From now on each 'Exit' means: Terminate the application
|
---|
191 | d->SetBit(MStatusDisplay::kExitLoopOnExit);
|
---|
192 | d->SetTitle(kSequences);
|
---|
193 |
|
---|
194 | //
|
---|
195 | // Calculate pedestal for pedestal-calculation and calibration
|
---|
196 | //
|
---|
197 | MEnv env(kConfig);
|
---|
198 |
|
---|
199 | MJCut job(Form("MJCut #%d", seq.GetNumAnalysis()));
|
---|
200 | job.SetEnv(&env);
|
---|
201 | job.SetEnvDebug(kDebugEnv);
|
---|
202 | job.SetDisplay(d);;
|
---|
203 | job.SetOverwrite(kOverwrite);
|
---|
204 | job.SetPathOut(kOutpath);
|
---|
205 | job.SetNameOutFile(kOutfile);
|
---|
206 | job.SetNameSummaryFile(kNameSummary);
|
---|
207 | job.SetNameResultFile(kNameResult);
|
---|
208 | job.EnableWriteOnly(kWriteOnly);
|
---|
209 | if (kWriteSummary) // Don't change flag set in SetNameSummaryFile
|
---|
210 | job.EnableStorageOfSummary();
|
---|
211 | if (kWriteResult) // Don't change flag set in SetNameSummaryFile
|
---|
212 | job.EnableStorageOfResult();
|
---|
213 |
|
---|
214 | if (!job.ProcessFile(seq))
|
---|
215 | {
|
---|
216 | gLog << err << "Calculation of cuts failed." << endl << endl;
|
---|
217 | return -1;
|
---|
218 | }
|
---|
219 | if (kDebugEnv>0)
|
---|
220 | env.PrintUntouched();
|
---|
221 |
|
---|
222 | if (!job.GetDisplay())
|
---|
223 | {
|
---|
224 | gLog << warn << "Display closed by user... execution aborted." << endl << endl;
|
---|
225 | return 1;
|
---|
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 | }
|
---|