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