1 | #include <TObjectTable.h>
|
---|
2 |
|
---|
3 | #include "MArgs.h"
|
---|
4 | #include "MArray.h"
|
---|
5 |
|
---|
6 | #include "MLog.h"
|
---|
7 | #include "MLogManip.h"
|
---|
8 |
|
---|
9 | #include "MJMerpp.h"
|
---|
10 |
|
---|
11 | using namespace std;
|
---|
12 |
|
---|
13 | //////////////////////////////////////////////////////////////////////////////
|
---|
14 | // //
|
---|
15 | // This is an easy implementation of the Merging process //
|
---|
16 | // (as compilable prog) //
|
---|
17 | // //
|
---|
18 | // at the moment it reads a binary file ("rawtest.bin") which was written //
|
---|
19 | // in the DAQ raw format. //
|
---|
20 | // //
|
---|
21 | // The data are stored in root container objects (classes derived from //
|
---|
22 | // TObject like MRawRunHeader) //
|
---|
23 | // //
|
---|
24 | // This containers are written to a root file ("rawtest.root") //
|
---|
25 | // //
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 |
|
---|
28 | static void StartUpMessage()
|
---|
29 | {
|
---|
30 | gLog << all << endl;
|
---|
31 |
|
---|
32 | // 1 2 3 4 5
|
---|
33 | // 12345678901234567890123456789012345678901234567890
|
---|
34 | gLog << "==================================================" << endl;
|
---|
35 | gLog << " MERPP - MARS V" << MARSVER << endl;
|
---|
36 | gLog << " MARS - Merging and Preprocessing Program" << endl;
|
---|
37 | gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
|
---|
38 | gLog << "==================================================" << endl;
|
---|
39 | gLog << endl;
|
---|
40 | }
|
---|
41 |
|
---|
42 | static void Usage()
|
---|
43 | {
|
---|
44 | // 1 2 3 4 5 6 7 8
|
---|
45 | // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
|
---|
46 | gLog << all << endl;
|
---|
47 | gLog << "Sorry the usage is:" << endl;
|
---|
48 | gLog << " merpp [options] [tel:]seqnumber [outpath [inpath]]" << endl;
|
---|
49 | gLog << " merpp [options] [tel:]seqnumber outpath sumfile.txt" << endl;
|
---|
50 | gLog << " merpp [options] seqfile.txt [outpath [inpath]]" << endl;
|
---|
51 | gLog << " merpp [options] seqfile.txt outpath sumfile.txt" << endl;
|
---|
52 | // gLog << " merpp [options] mysql [outpath [inpath]]" << endl;
|
---|
53 | // gLog << " merpp [options] mysql outpath sumfile.txt" << endl;
|
---|
54 | gLog << " merpp [options] infile.raw.[gz] [outfile.root]" << endl;
|
---|
55 | gLog << " merpp [options] infile.rep [outfile.root]" << endl;
|
---|
56 | gLog << " merpp [options] infile.txt outfile.root" << endl;
|
---|
57 | gLog << endl;
|
---|
58 | gLog << " Arguments:" << endl;
|
---|
59 | gLog << " [tel:]seqnumber Telescope and sequence number to mbe merpped." << endl;
|
---|
60 | gLog << " inpath The input files whether the CC files are." << endl;
|
---|
61 | gLog << " outpath The output path where the outputfile are or stored." << endl;
|
---|
62 | gLog << " sumfile.txt A central control report summary file (--summary can be omitted)." << endl;
|
---|
63 | gLog << " infile.raw[.gz] Magic DAQ binary file." << endl;
|
---|
64 | gLog << " infile.rep Magic Central Control report file." << endl;
|
---|
65 | gLog << " infile.txt Magic DC currents file." << endl;
|
---|
66 | gLog << " outfile.root Merpped root file." << endl;
|
---|
67 | // gLog << " mysql mysql://user:password@host/database/tel:sequence" << endl;
|
---|
68 | gLog << endl;
|
---|
69 | gLog << " Options:" << endl;
|
---|
70 | gLog.Usage();
|
---|
71 | // gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
|
---|
72 | // gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
|
---|
73 | // gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
|
---|
74 | // gLog << " --debug-env=3 Debug setting resources from resource file and command line" << endl;
|
---|
75 | gLog << " --debug-mem Debug memory usage" << endl << endl;
|
---|
76 | gLog << endl;
|
---|
77 | gLog << " File Options:" << endl;
|
---|
78 | gLog << " -c# Compression level #=1..9 [default=2]" << endl;
|
---|
79 | gLog << " -f Force overwrite of an existing file" << endl;
|
---|
80 | gLog << " -u, --update Update an existing file." << endl;
|
---|
81 | gLog << endl;
|
---|
82 | gLog << " Raw Data Options:" << endl;
|
---|
83 | gLog << " -ff Force merpp to ignore broken events and don't stop" << endl;
|
---|
84 | gLog << " --interleave=# Process only each i-th event [default=1]" << endl;
|
---|
85 | gLog << endl;
|
---|
86 | gLog << " Report/Currents File Options:" << endl;
|
---|
87 | gLog << " --auto-time-start Take time automatically from MRawRunHeader" << endl;
|
---|
88 | gLog << " (overwrites --start=, update only)" << endl;
|
---|
89 | gLog << " --auto-time-stop Take time automatically from MRawRunHeader" << endl;
|
---|
90 | gLog << " (overwrites --stop=, update only)" << endl;
|
---|
91 | gLog << " --auto-time Abbrev. for --auto-time-start and auto-time-stop" << endl;
|
---|
92 | gLog << " --start=\"time\" Start event time (format see MTime::SetSqlDateTime, update only)" << endl;
|
---|
93 | gLog << " --stop=\"time\" Stop event time (format see MTime::SetSqlDateTime, update only)" << endl;
|
---|
94 | gLog << endl;
|
---|
95 | gLog << " Report Options:" << endl;
|
---|
96 | gLog << " --rep-run=# Only data corresponding to this run number as" << endl;
|
---|
97 | gLog << " taken from the RUN-REPORT is extracted" << endl;
|
---|
98 | gLog << " --rep-file=# Only data corresponding to this file number as" << endl;
|
---|
99 | gLog << " taken from the RUN-REPORT is extracted" << endl;
|
---|
100 | gLog << " --header-run=# Allow only run-control .rep-files with this" << endl;
|
---|
101 | gLog << " run number in there header" << endl;
|
---|
102 | gLog << " --header-file=# Allow only run-control .rep-files with this" << endl;
|
---|
103 | gLog << " file number in there header" << endl;
|
---|
104 | gLog << " --telescope=# Allow only run-control .rep-files with this" << endl;
|
---|
105 | gLog << " telescope number in there header" << endl;
|
---|
106 | gLog << " --sumfile Check for an all night summary file" << endl;
|
---|
107 | gLog << " (from .rep header)" << endl;
|
---|
108 | gLog << " --allfiles Don't check file type <default>" << endl << endl;
|
---|
109 | gLog << " --only=Name Read only reports described by MReportName. See the" << endl;
|
---|
110 | gLog << " mreport-directory for available classes." << endl;
|
---|
111 | gLog << endl;
|
---|
112 | gLog << " --version, -V Show startup message with version number" << endl;
|
---|
113 | gLog << " -?, -h, --help This help" << endl;
|
---|
114 | gLog << endl;
|
---|
115 | gLog << " Compatibility (deprecated):" << endl;
|
---|
116 | gLog << " --run=# See --rep-run (overwritten by --rep-run)" << endl;
|
---|
117 | gLog << " --runfile=# See --header-run (overwritten by --header-run)" << endl << endl;
|
---|
118 | gLog << " REMARK: - At the moment you can process a .raw _or_ a .rep file, only!" << endl;
|
---|
119 | gLog << " - 'date/time' has the format 'yyyy-mm-dd/hh:mm:ss.mmm'" << endl << endl;
|
---|
120 | }
|
---|
121 |
|
---|
122 | static bool HasExtension(const TString &name)
|
---|
123 | {
|
---|
124 | return
|
---|
125 | name.EndsWith(".rep") || name.EndsWith(".txt") ||
|
---|
126 | name.EndsWith(".raw") || name.EndsWith(".raw.gz");
|
---|
127 | }
|
---|
128 |
|
---|
129 | int main(const int argc, char **argv)
|
---|
130 | {
|
---|
131 | if (!MARS::CheckRootVer())
|
---|
132 | return 0xff;
|
---|
133 |
|
---|
134 | MLog::RedirectErrorHandler(MLog::kColor);
|
---|
135 |
|
---|
136 | //
|
---|
137 | // Evaluate arguments
|
---|
138 | //
|
---|
139 | MArgs arg(argc, argv);
|
---|
140 | gLog.Setup(arg);
|
---|
141 |
|
---|
142 | StartUpMessage();
|
---|
143 |
|
---|
144 | if (arg.HasOnly("-V") || arg.HasOnly("--version"))
|
---|
145 | return 0;
|
---|
146 |
|
---|
147 | if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
|
---|
148 | {
|
---|
149 | Usage();
|
---|
150 | return 2;
|
---|
151 | }
|
---|
152 |
|
---|
153 | const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
|
---|
154 | const Int_t kComprlvl = arg.GetIntAndRemove("-c", 2);
|
---|
155 | const Bool_t kInterleave = arg.GetIntAndRemove("--interleave=", 1);
|
---|
156 | const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
|
---|
157 | const Bool_t kForceProc = arg.HasOnlyAndRemove("-ff");
|
---|
158 | const Int_t run = arg.GetIntAndRemove("--run=", -1);
|
---|
159 | const Int_t kRunNumber = arg.GetIntAndRemove("--rep-run=", run);
|
---|
160 | const Int_t kFileNumber = arg.GetIntAndRemove("--rep-file=", -1);
|
---|
161 | const Bool_t kAutoTime = arg.HasOnlyAndRemove("--auto-time");
|
---|
162 | const Bool_t kAutoTimeStart = arg.HasOnlyAndRemove("--auto-time-start") || kAutoTime;
|
---|
163 | const Bool_t kAutoTimeStop = arg.HasOnlyAndRemove("--auto-time-stop") || kAutoTime;
|
---|
164 | const Int_t runfile = arg.GetIntAndRemove("--runfile=", -1);
|
---|
165 | Int_t kHeaderRun = arg.GetIntAndRemove("--header-run=", runfile);
|
---|
166 | const Int_t kHeaderFile = arg.GetIntAndRemove("--header-file=", -1);
|
---|
167 | const Int_t kTelescope = arg.GetIntAndRemove("--telescope=", -1);
|
---|
168 | Bool_t kUpdate = arg.HasOnlyAndRemove("--update") || arg.HasOnlyAndRemove("-u");
|
---|
169 | const TString kOnly = arg.GetStringAndRemove("--only", "");
|
---|
170 | const Bool_t kNullOut = arg.HasOnlyAndRemove("--dev-null");
|
---|
171 |
|
---|
172 | // Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
|
---|
173 | // kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
|
---|
174 |
|
---|
175 | MTime kTimeStart(arg.GetStringAndRemove("--start="));
|
---|
176 | MTime kTimeStop(arg.GetStringAndRemove("--stop="));
|
---|
177 |
|
---|
178 | if (arg.HasOnlyAndRemove("--sumfile"))
|
---|
179 | kHeaderRun = 0;
|
---|
180 |
|
---|
181 | if (arg.GetNumOptions()>0)
|
---|
182 | {
|
---|
183 | gLog << warn << "WARNING - Unknown commandline options..." << endl;
|
---|
184 | arg.Print("options");
|
---|
185 | gLog << endl;
|
---|
186 | return 2;
|
---|
187 | }
|
---|
188 |
|
---|
189 | //
|
---|
190 | // check for the right usage of the program
|
---|
191 | //
|
---|
192 | if (arg.GetNumArguments()<1 || arg.GetNumArguments()>3)
|
---|
193 | {
|
---|
194 | Usage();
|
---|
195 | return 2;
|
---|
196 | }
|
---|
197 |
|
---|
198 | //
|
---|
199 | // This is to make argv[i] more readable insidethe code
|
---|
200 | //
|
---|
201 | const Int_t narg = arg.GetNumArguments();
|
---|
202 |
|
---|
203 | const TString arg0 = arg.GetArgumentStr(0);
|
---|
204 | const TString arg1 = arg.GetArgumentStr(1);
|
---|
205 | const TString arg2 = arg.GetArgumentStr(2);
|
---|
206 |
|
---|
207 | const Bool_t isseq =
|
---|
208 | (narg==1 && !(HasExtension(arg0) && !arg0.EndsWith(".txt"))) ||
|
---|
209 | (narg==2 && !HasExtension(arg1)) ||
|
---|
210 | (narg==3);
|
---|
211 |
|
---|
212 | TString sequence, kNamein, kNameout;
|
---|
213 | if (isseq)
|
---|
214 | {
|
---|
215 | sequence = arg0;
|
---|
216 | kNameout = arg1;
|
---|
217 | kNamein = arg2;
|
---|
218 |
|
---|
219 | if (HasExtension(arg2)) // set --summary
|
---|
220 | kHeaderRun = 0;
|
---|
221 |
|
---|
222 | kUpdate = kTRUE;
|
---|
223 | }
|
---|
224 | else
|
---|
225 | {
|
---|
226 | kNamein = arg0;
|
---|
227 | kNameout = arg1(0, kNamein.Last('.'));
|
---|
228 | if (!kNameout.EndsWith(".root"))
|
---|
229 | kNameout += ".root";
|
---|
230 | }
|
---|
231 |
|
---|
232 | //
|
---|
233 | // Initialize Non-GUI (batch) mode
|
---|
234 | //
|
---|
235 | gROOT->SetBatch();
|
---|
236 |
|
---|
237 | //
|
---|
238 | // Ignore TObject Streamer (bits, uniqueid) for MArray and MParContainer
|
---|
239 | //
|
---|
240 | MArray::Class()->IgnoreTObjectStreamer();
|
---|
241 | MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
242 |
|
---|
243 | if (kDebugMem)
|
---|
244 | TObject::SetObjectStat(kTRUE);
|
---|
245 |
|
---|
246 | {
|
---|
247 | MJMerpp merpp(Form("MJMerpp %s", arg0.Data()));
|
---|
248 | merpp.SetOverwrite(kOverwrite);
|
---|
249 | merpp.SetCompression(kComprlvl);
|
---|
250 | merpp.SetUpdate(kUpdate);
|
---|
251 | merpp.SetInterleave(kInterleave);
|
---|
252 | merpp.SetForceProcessing(kForceProc);
|
---|
253 | merpp.SetConstrainHeader(kTelescope, kHeaderRun, kHeaderFile);
|
---|
254 | merpp.SetConstrainRunRep(kRunNumber, kFileNumber);
|
---|
255 | merpp.SetOnly(kOnly);
|
---|
256 | merpp.SetTime(kTimeStart, kTimeStop);
|
---|
257 | merpp.SetAutoTime(kAutoTimeStart, kAutoTimeStop);
|
---|
258 | merpp.SetNullOut(kNullOut);
|
---|
259 | //merpp.SetEnvDebug(kDebugEnv);
|
---|
260 | //merpp.SetEnv(&env);
|
---|
261 | //merpp.SetDisplay(d);;
|
---|
262 |
|
---|
263 | merpp.SetPathIn(kNamein);
|
---|
264 | merpp.SetPathOut(kNameout);
|
---|
265 |
|
---|
266 | const Int_t rc = sequence.IsNull() ? merpp.Process() : merpp.ProcessSeq(sequence);
|
---|
267 | if (rc>0)
|
---|
268 | {
|
---|
269 | gLog << err << "Merpp failed." << endl << endl;
|
---|
270 | return rc;
|
---|
271 | }
|
---|
272 |
|
---|
273 | //if (kDebugEnv>0)
|
---|
274 | // env.PrintUntouched();
|
---|
275 | }
|
---|
276 |
|
---|
277 | if (TObject::GetObjectStat())
|
---|
278 | {
|
---|
279 | TObject::SetObjectStat(kFALSE);
|
---|
280 | gObjectTable->Print();
|
---|
281 | }
|
---|
282 |
|
---|
283 | return 0;
|
---|
284 | }
|
---|