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

Last change on this file since 2678 was 2678, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 9.6 KB
Line 
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
24using 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
41static 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
56static 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'
77MTime 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
89int 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("MReportDAQ");
238 r->AddToList("MReportDrive");
239 r->AddToList("MReportCamera");
240 r->AddToList("MReportTrigger");
241 }
242 read = r;
243
244 MWriteRootFile *w = new MWriteRootFile(kNameout, option, "Magic root-file", kComprlvl);
245 if (isdc)
246 {
247 w->AddContainer("MTimeCurrents", "DC");
248 w->AddContainer("MCameraDC", "DC");
249 w->AddContainer("MReportCurrents", "DC");
250 }
251 else
252 {
253 w->AddContainer("MReportCamera", "Camera");
254 w->AddContainer("MTimeCamera", "Camera");
255 w->AddContainer("MCameraAUX", "Camera");
256 w->AddContainer("MCameraCalibration", "Camera");
257 w->AddContainer("MCameraCooling", "Camera");
258 w->AddContainer("MCameraHV", "Camera");
259 w->AddContainer("MCameraLV", "Camera");
260 w->AddContainer("MCameraLids", "Camera");
261 w->AddContainer("MReportTrigger", "Trigger");
262 w->AddContainer("MTimeTrigger", "Trigger");
263 w->AddContainer("MReportDrive", "Drive");
264 w->AddContainer("MTimeDrive", "Drive");
265 // w->AddContainer("MReportDAQ", "DAQ");
266 // w->AddContainer("MTimeDAQ", "DAQ");
267 }
268 write = w;
269 }
270 else
271 {
272 read = new MRawFileRead(kNamein);
273 write = new MRawFileWrite(kNameout, option, "Magic root-file", kComprlvl);
274 }
275
276 tasks.AddToList(read);
277 tasks.AddToList(write);
278
279 //
280 // create the looping object and tell it about the parameters to use
281 // and the tasks to execute
282 //
283 MEvtLoop magic;
284 magic.SetParList(&plist);
285
286 //
287 // Start the eventloop which reads the raw file (MRawFileRead) and
288 // write all the information into a root file (MRawFileWrite)
289 //
290 // between reading and writing we can do, transformations, checks, etc.
291 // (I'm think of a task like MRawDataCheck)
292 //
293 if (!magic.Eventloop())
294 {
295 gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
296 return -1;
297 }
298
299 tasks.PrintStatistics();
300
301 gLog << all << "Merpp finished successfull!" << endl;
302 return 0;
303}
304
305
Note: See TracBrowser for help on using the repository browser.