source: tags/Mars-V2.1.1/merpp.cc@ 13445

Last change on this file since 13445 was 9060, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 12.5 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 files whether 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 << endl;
113 gLog << " --version, -V Show startup message with version number" << endl;
114 gLog << " -?, -h, --help This help" << endl;
115 gLog << endl;
116 gLog << " Compatibility (deprecated):" << endl;
117 gLog << " --run=# See --rep-run (overwritten by --rep-run)" << endl;
118 gLog << " --runfile=# See --header-run (overwritten by --header-run)" << endl << endl;
119 gLog << " REMARK: - At the moment you can process a .raw _or_ a .rep file, only!" << endl;
120 gLog << " - 'date/time' has the format 'yyyy-mm-dd/hh:mm:ss.mmm'" << endl << endl;
121}
122
123static bool HasExtension(const TString &name)
124{
125 return
126 name.EndsWith(".rep") || name.EndsWith(".txt") ||
127 name.EndsWith(".raw") || name.EndsWith(".raw.gz") ||
128 name.EndsWith(".root");
129}
130
131int main(const int argc, char **argv)
132{
133 if (!MARS::CheckRootVer())
134 return 0xff;
135
136 MLog::RedirectErrorHandler(MLog::kColor);
137
138 //
139 // Evaluate arguments
140 //
141 MArgs arg(argc, argv);
142 gLog.Setup(arg);
143
144 StartUpMessage();
145
146 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
147 return 0;
148
149 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
150 {
151 Usage();
152 return 2;
153 }
154
155 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
156 const Int_t kComprlvl = arg.GetIntAndRemove("-c", 2);
157 const Bool_t kInterleave = arg.GetIntAndRemove("--interleave=", 1);
158 const Bool_t kOverwrite = arg.HasOnlyAndRemove("-f");
159 const Bool_t kForceProc = arg.HasOnlyAndRemove("-ff");
160 const Int_t run = arg.GetIntAndRemove("--run=", -1);
161 const Int_t kRunNumber = arg.GetIntAndRemove("--rep-run=", run);
162 const Int_t kFileNumber = arg.GetIntAndRemove("--rep-file=", -1);
163 const Bool_t kAutoTime = arg.HasOnlyAndRemove("--auto-time");
164 const Bool_t kAutoTimeStart = arg.HasOnlyAndRemove("--auto-time-start") || kAutoTime;
165 const Bool_t kAutoTimeStop = arg.HasOnlyAndRemove("--auto-time-stop") || kAutoTime;
166 const Int_t runfile = arg.GetIntAndRemove("--runfile=", -1);
167 Int_t kHeaderRun = arg.GetIntAndRemove("--header-run=", runfile);
168 const Int_t kHeaderFile = arg.GetIntAndRemove("--header-file=", -1);
169 const Int_t kTelescope = arg.GetIntAndRemove("--telescope=", -1);
170 Bool_t kUpdate = arg.HasOnlyAndRemove("--update") || arg.HasOnlyAndRemove("-u");
171 const TString kOnly = arg.GetStringAndRemove("--only", "");
172 const Bool_t kNullOut = arg.HasOnlyAndRemove("--dev-null");
173
174// Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
175// kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
176
177 MTime kTimeStart(arg.GetStringAndRemove("--start="));
178 MTime kTimeStop(arg.GetStringAndRemove("--stop="));
179
180 if (arg.HasOnlyAndRemove("--sumfile"))
181 kHeaderRun = 0;
182
183 if (arg.GetNumOptions()>0)
184 {
185 gLog << warn << "WARNING - Unknown commandline options..." << endl;
186 arg.Print("options");
187 gLog << endl;
188 return 2;
189 }
190
191 //
192 // check for the right usage of the program
193 //
194 if (arg.GetNumArguments()<1 || arg.GetNumArguments()>3)
195 {
196 Usage();
197 return 2;
198 }
199
200 //
201 // This is to make argv[i] more readable insidethe code
202 //
203 const Int_t narg = arg.GetNumArguments();
204
205 const TString arg0 = arg.GetArgumentStr(0);
206 const TString arg1 = arg.GetArgumentStr(1);
207 const TString arg2 = arg.GetArgumentStr(2);
208
209 const Bool_t isseq =
210 (narg==1 && arg0.EndsWith(".txt")) ||
211 (narg==2 && !HasExtension(arg1)) ||
212 (narg==3);
213
214 TString sequence, kNamein, kNameout;
215 if (isseq)
216 {
217 sequence = arg0;
218 kNameout = arg1;
219 kNamein = arg2;
220
221 if (arg2.EndsWith(".txt")) // set --summary
222 {
223 gLog << inf << "Summary file option switched on automatically due to file extension." << endl;
224 kHeaderRun = 0;
225 }
226
227 kUpdate = kTRUE;
228 }
229 else
230 {
231 kNamein = arg0;
232 kNameout = arg1(0, kNamein.Last('.'));
233 if (!kNameout.EndsWith(".root"))
234 kNameout += ".root";
235 }
236
237 //
238 // Initialize Non-GUI (batch) mode
239 //
240 gROOT->SetBatch();
241
242 //
243 // Ignore TObject Streamer (bits, uniqueid) for MArray and MParContainer
244 //
245 MArray::Class()->IgnoreTObjectStreamer();
246 MParContainer::Class()->IgnoreTObjectStreamer();
247
248 if (kDebugMem)
249 TObject::SetObjectStat(kTRUE);
250
251 {
252 MJMerpp merpp(Form("MJMerpp %s", gSystem->BaseName(arg0.Data())));
253 merpp.SetOverwrite(kOverwrite);
254 merpp.SetCompression(kComprlvl);
255 merpp.SetUpdate(kUpdate);
256 merpp.SetInterleave(kInterleave);
257 merpp.SetForceProcessing(kForceProc);
258 merpp.SetConstrainHeader(kTelescope, kHeaderRun, kHeaderFile);
259 merpp.SetConstrainRunRep(kRunNumber, kFileNumber);
260 merpp.SetOnly(kOnly);
261 merpp.SetTime(kTimeStart, kTimeStop);
262 merpp.SetAutoTime(kAutoTimeStart, kAutoTimeStop);
263 merpp.SetNullOut(kNullOut);
264 //merpp.SetEnvDebug(kDebugEnv);
265 //merpp.SetEnv(&env);
266 //merpp.SetDisplay(d);;
267
268 merpp.SetPathIn(kNamein);
269 merpp.SetPathOut(kNameout);
270
271 const Int_t rc = sequence.IsNull() ? merpp.Process() : merpp.ProcessSeq(sequence);
272 if (rc>0)
273 {
274 gLog << err << "Merpp failed." << endl << endl;
275 return rc;
276 }
277
278 //if (kDebugEnv>0)
279 // env.PrintUntouched();
280 }
281
282 if (TObject::GetObjectStat())
283 {
284 TObject::SetObjectStat(kFALSE);
285 gObjectTable->Print();
286 }
287
288 return 0;
289}
Note: See TracBrowser for help on using the repository browser.