1 | #include <TSystem.h>
|
---|
2 |
|
---|
3 | #include "MParList.h"
|
---|
4 | #include "MTaskList.h"
|
---|
5 | #include "MEvtLoop.h"
|
---|
6 |
|
---|
7 | #include "MRawFileRead.h"
|
---|
8 | #include "MRawFileWrite.h"
|
---|
9 |
|
---|
10 | #include "MReportFileRead.h"
|
---|
11 | #include "MWriteRootFile.h"
|
---|
12 |
|
---|
13 | #include "MLog.h"
|
---|
14 | #include "MLogManip.h"
|
---|
15 |
|
---|
16 | #include "MArgs.h"
|
---|
17 | #include "MTime.h"
|
---|
18 | #include "MArray.h"
|
---|
19 | #include "MRawEvtData.h"
|
---|
20 | #include "MRawRunHeader.h"
|
---|
21 | #include "MRawEvtHeader.h"
|
---|
22 | #include "MRawCrateArray.h"
|
---|
23 |
|
---|
24 | #include "MFDataMember.h"
|
---|
25 |
|
---|
26 | using namespace std;
|
---|
27 |
|
---|
28 | //////////////////////////////////////////////////////////////////////////////
|
---|
29 | // //
|
---|
30 | // This is an easy implementation of the Merging process //
|
---|
31 | // (as compilable prog) //
|
---|
32 | // //
|
---|
33 | // at the moment it reads a binary file ("rawtest.bin") which was written //
|
---|
34 | // in the DAQ raw format. //
|
---|
35 | // //
|
---|
36 | // The data are stored in root container objects (classes derived from //
|
---|
37 | // TObject like MRawRunHeader) //
|
---|
38 | // //
|
---|
39 | // This containers are written to a root file ("rawtest.root") //
|
---|
40 | // //
|
---|
41 | //////////////////////////////////////////////////////////////////////////////
|
---|
42 |
|
---|
43 | static void StartUpMessage()
|
---|
44 | {
|
---|
45 | gLog << all << endl;
|
---|
46 |
|
---|
47 | // 1 2 3 4 5
|
---|
48 | // 12345678901234567890123456789012345678901234567890
|
---|
49 | gLog << "==================================================" << endl;
|
---|
50 | gLog << " MERPP - MARS V" << MARSVER << endl;
|
---|
51 | gLog << " MARS - Merging and Preprocessing Program" << endl;
|
---|
52 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
---|
53 | gLog << " Using ROOT v" << ROOTVER << endl;
|
---|
54 | gLog << "==================================================" << endl;
|
---|
55 | gLog << endl;
|
---|
56 | }
|
---|
57 |
|
---|
58 | static void Usage()
|
---|
59 | {
|
---|
60 | gLog << all << endl;
|
---|
61 | gLog << "Sorry the usage is:" << endl;
|
---|
62 | gLog << " merpp [-h] [-?] [-a0] [-vn] [-cn] [-u1]" << endl;
|
---|
63 | gLog << " inputfile[.rep,[.raw],[.txt]] [outputfile[.root]]" << endl << endl;
|
---|
64 | gLog << " inputfile.raw: Magic DAQ binary file." << endl;
|
---|
65 | gLog << " inputfile.rep: Magic Central Control report file." << endl;
|
---|
66 | gLog << " inputfile.txt: Magic DC currents file." << endl;
|
---|
67 | gLog << " ouputfile.root: Merpped root file." << endl;
|
---|
68 | gLog << " -a0: Do not use Ansii codes." << endl;
|
---|
69 | gLog << " -u1: Update file." << endl;
|
---|
70 | gLog << " -cn: Compression level n=1..9 [default=2]" << endl;
|
---|
71 | gLog << " -vn: Verbosity level n [default=2]" << endl;
|
---|
72 | gLog << " --start=yyyy-mm-dd/hh:mm:ss.mmm: Start event time for merpping report files" << endl;
|
---|
73 | gLog << " --stop=yyyy-mm-dd/hh:mm:ss.mmm: Stop event time for merpping report files" << endl;
|
---|
74 | gLog << " --run=#: Only merpp data corresponding to this run number" << endl;
|
---|
75 | gLog << " -?/-h: This help" << endl << endl;
|
---|
76 | gLog << " REMARK: At the moment you can process a .raw _or_ a .rep file, only!" << endl << endl;
|
---|
77 | }
|
---|
78 |
|
---|
79 | // FIXME: Move to MTime (maybe 'InterpreteCmdline'
|
---|
80 | MTime AnalyseTime(TString str)
|
---|
81 | {
|
---|
82 | Int_t y=0, ms=0, mon=0, d=0, h=0, m=0, s=0;
|
---|
83 |
|
---|
84 | if (7!=sscanf(str.Data(), "%d-%d-%d/%d:%d:%d.%d", &y, &mon, &d, &h, &m, &s, &ms))
|
---|
85 | return MTime();
|
---|
86 |
|
---|
87 | MTime t;
|
---|
88 | t.Set(y, mon, d, h, m, s, ms);
|
---|
89 | return t;
|
---|
90 | }
|
---|
91 |
|
---|
92 | int main(const int argc, char **argv)
|
---|
93 | {
|
---|
94 | StartUpMessage();
|
---|
95 |
|
---|
96 | //
|
---|
97 | // Evaluate arguments
|
---|
98 | //
|
---|
99 | MArgs arg(argc, argv);
|
---|
100 |
|
---|
101 | if (arg.HasOption("-?") || arg.HasOption("-h"))
|
---|
102 | {
|
---|
103 | Usage();
|
---|
104 | return -1;
|
---|
105 | }
|
---|
106 |
|
---|
107 | if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
|
---|
108 | gLog.SetNoColors();
|
---|
109 |
|
---|
110 | const Int_t kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
|
---|
111 | Bool_t kUpdate = arg.HasOption("-u") && arg.GetIntAndRemove("-u")==1;
|
---|
112 |
|
---|
113 | gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
|
---|
114 |
|
---|
115 | MTime kTimeStart(AnalyseTime(arg.GetStringAndRemove("--start=")));
|
---|
116 | MTime kTimeStop(AnalyseTime(arg.GetStringAndRemove("--stop=")));
|
---|
117 | kTimeStart.SetName("MTimeStart");
|
---|
118 | kTimeStop.SetName("MTimeStop");
|
---|
119 |
|
---|
120 | const Int_t kRunNumber = arg.HasOption("--run=") ? arg.GetIntAndRemove("--run=") : -1;
|
---|
121 |
|
---|
122 | if (kTimeStart)
|
---|
123 | gLog << inf << "Start Time: " << kTimeStart << endl;
|
---|
124 | if (kTimeStop)
|
---|
125 | gLog << inf << "Stop Time: " << kTimeStop << endl;
|
---|
126 |
|
---|
127 | //
|
---|
128 | // check for the right usage of the program
|
---|
129 | //
|
---|
130 | if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
|
---|
131 | {
|
---|
132 | Usage();
|
---|
133 | return -1;
|
---|
134 | }
|
---|
135 |
|
---|
136 | //
|
---|
137 | // This is to make argv[i] more readable insidethe code
|
---|
138 | //
|
---|
139 | TString kNamein = arg.GetArgumentStr(0);
|
---|
140 | TString kNameout = arg.GetArgumentStr(1);
|
---|
141 |
|
---|
142 | const Bool_t isreport = kNamein.EndsWith(".rep");
|
---|
143 | const Bool_t isdc = kNamein.EndsWith(".txt");
|
---|
144 |
|
---|
145 | if (!kNamein.EndsWith(".raw") && !isreport && !isdc)
|
---|
146 | kNamein += ".raw";
|
---|
147 |
|
---|
148 | if (kNameout.IsNull())
|
---|
149 | kNameout = kNamein(0, kNamein.Last('.'));
|
---|
150 |
|
---|
151 | if (!kNameout.EndsWith(".root"))
|
---|
152 | kNameout += ".root";
|
---|
153 |
|
---|
154 | //
|
---|
155 | // Initialize Non-GUI (batch) mode
|
---|
156 | //
|
---|
157 | gROOT->SetBatch();
|
---|
158 |
|
---|
159 | //
|
---|
160 | // check whether the given files are OK.
|
---|
161 | //
|
---|
162 | if (gSystem->AccessPathName(kNamein, kFileExists))
|
---|
163 | {
|
---|
164 | gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
|
---|
165 | return -1;
|
---|
166 | }
|
---|
167 |
|
---|
168 | const Bool_t fileexist = !gSystem->AccessPathName(kNameout, kFileExists);
|
---|
169 | const Bool_t writeperm = !gSystem->AccessPathName(kNameout, kWritePermission);
|
---|
170 |
|
---|
171 | if (fileexist && !writeperm)
|
---|
172 | {
|
---|
173 | gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
|
---|
174 | return -1;
|
---|
175 | }
|
---|
176 |
|
---|
177 | if (fileexist && !kUpdate)
|
---|
178 | {
|
---|
179 | gLog << err << "Sorry, file '" << kNameout << "' already existing." << endl;
|
---|
180 | return -1;
|
---|
181 | }
|
---|
182 |
|
---|
183 | if (!fileexist && kUpdate)
|
---|
184 | {
|
---|
185 | gLog << warn << "File '" << kNameout << "' doesn't yet exist." << endl;
|
---|
186 | kUpdate=kFALSE;
|
---|
187 | }
|
---|
188 |
|
---|
189 | MArray::Class()->IgnoreTObjectStreamer();
|
---|
190 | MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
191 |
|
---|
192 | //
|
---|
193 | // create a (empty) list of parameters which can be used by the tasks
|
---|
194 | // and an (empty) list of tasks which should be executed
|
---|
195 | //
|
---|
196 | MParList plist;
|
---|
197 |
|
---|
198 | MTaskList tasks;
|
---|
199 | tasks.SetOwner();
|
---|
200 | plist.AddToList(&tasks);
|
---|
201 |
|
---|
202 | //
|
---|
203 | // ---- The following is only necessary to supress some output ----
|
---|
204 | /*
|
---|
205 | MRawRunHeader runheader;
|
---|
206 | plist.AddToList(&runheader);
|
---|
207 |
|
---|
208 | MRawEvtHeader evtheader;
|
---|
209 | plist.AddToList(&evtheader);
|
---|
210 |
|
---|
211 | MRawEvtData evtdata;
|
---|
212 | plist.AddToList(&evtdata);
|
---|
213 |
|
---|
214 | MRawCrateArray cratearray;
|
---|
215 | plist.AddToList(&cratearray);
|
---|
216 |
|
---|
217 | MTime evttime;
|
---|
218 | plist.AddToList(&evttime);
|
---|
219 | */
|
---|
220 |
|
---|
221 | //
|
---|
222 | // create the tasks which should be executed and add them to the list
|
---|
223 | // in the case you don't need parameter containers, all of them can
|
---|
224 | // be created by MRawFileRead::PreProcess
|
---|
225 | //
|
---|
226 | MTask *read = 0;
|
---|
227 | MFilter *filter = 0;
|
---|
228 | MTask *write = 0;
|
---|
229 |
|
---|
230 | const TString option(kUpdate ? "UPDATE" : "RECREATE");
|
---|
231 | if (isreport || isdc)
|
---|
232 | {
|
---|
233 | MWriteRootFile *w = new MWriteRootFile(kNameout, option, "Magic root-file", kComprlvl);
|
---|
234 | if (isdc)
|
---|
235 | {
|
---|
236 | w->AddContainer("MTimeCurrents", "DC");
|
---|
237 | w->AddContainer("MCameraDC", "DC");
|
---|
238 | w->AddContainer("MReportCurrents", "DC");
|
---|
239 | }
|
---|
240 | else
|
---|
241 | {
|
---|
242 | w->AddContainer("MReportCamera", "Camera");
|
---|
243 | w->AddContainer("MTimeCamera", "Camera");
|
---|
244 | w->AddContainer("MCameraAUX", "Camera");
|
---|
245 | w->AddContainer("MCameraCalibration", "Camera");
|
---|
246 | w->AddContainer("MCameraCooling", "Camera");
|
---|
247 | w->AddContainer("MCameraHV", "Camera");
|
---|
248 | w->AddContainer("MCameraLV", "Camera");
|
---|
249 | w->AddContainer("MCameraLids", "Camera");
|
---|
250 | w->AddContainer("MReportTrigger", "Trigger");
|
---|
251 | w->AddContainer("MTimeTrigger", "Trigger");
|
---|
252 | w->AddContainer("MReportDrive", "Drive");
|
---|
253 | w->AddContainer("MTimeDrive", "Drive");
|
---|
254 | w->AddContainer("MReportCC", "CC");
|
---|
255 | w->AddContainer("MTimeCC", "CC");
|
---|
256 | // w->AddContainer("MReportDAQ", "DAQ");
|
---|
257 | // w->AddContainer("MTimeDAQ", "DAQ");
|
---|
258 | }
|
---|
259 | write = w;
|
---|
260 |
|
---|
261 | MReportFileRead *r = new MReportFileRead(kNamein);
|
---|
262 | r->SetTimeStart(kTimeStart);
|
---|
263 | r->SetTimeStop(kTimeStop);
|
---|
264 | if (isdc)
|
---|
265 | {
|
---|
266 | r->SetHasNoHeader();
|
---|
267 | r->AddToList("MReportCurrents");
|
---|
268 | }
|
---|
269 | else
|
---|
270 | {
|
---|
271 | r->AddToList("MReportCC");
|
---|
272 | //r->AddToList("MReportDAQ");
|
---|
273 | r->AddToList("MReportDrive");
|
---|
274 | r->AddToList("MReportCamera");
|
---|
275 | r->AddToList("MReportTrigger");
|
---|
276 | if (kRunNumber>0)
|
---|
277 | {
|
---|
278 | r->AddToList("MReportRun");
|
---|
279 | filter = new MFDataMember("MReportRun.fRunNumber", '=', kRunNumber);
|
---|
280 | w->SetFilter(filter);
|
---|
281 | }
|
---|
282 | }
|
---|
283 | read = r;
|
---|
284 | }
|
---|
285 | else
|
---|
286 | {
|
---|
287 | read = new MRawFileRead(kNamein);
|
---|
288 | write = new MRawFileWrite(kNameout, option, "Magic root-file", kComprlvl);
|
---|
289 | }
|
---|
290 |
|
---|
291 | tasks.AddToList(read);
|
---|
292 | if (filter)
|
---|
293 | tasks.AddToList(filter);
|
---|
294 | tasks.AddToList(write);
|
---|
295 |
|
---|
296 | //
|
---|
297 | // create the looping object and tell it about the parameters to use
|
---|
298 | // and the tasks to execute
|
---|
299 | //
|
---|
300 | MEvtLoop magic;
|
---|
301 | magic.SetParList(&plist);
|
---|
302 |
|
---|
303 | //
|
---|
304 | // Start the eventloop which reads the raw file (MRawFileRead) and
|
---|
305 | // write all the information into a root file (MRawFileWrite)
|
---|
306 | //
|
---|
307 | // between reading and writing we can do, transformations, checks, etc.
|
---|
308 | // (I'm think of a task like MRawDataCheck)
|
---|
309 | //
|
---|
310 | if (!magic.Eventloop())
|
---|
311 | {
|
---|
312 | gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
|
---|
313 | return -1;
|
---|
314 | }
|
---|
315 |
|
---|
316 | tasks.PrintStatistics();
|
---|
317 |
|
---|
318 | gLog << all << "Merpp finished successfull!" << endl;
|
---|
319 | return 0;
|
---|
320 | }
|
---|
321 |
|
---|
322 |
|
---|