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

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