source: trunk/MagicSoft/Mars/merpp.cc@ 9054

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