source: tags/Mars-V2.3/merpp.cc@ 17373

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