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