source: trunk/Mars/merpp.cc@ 13228

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