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

Last change on this file since 2672 was 2632, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 8.8 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 << " -?/-h: This help" << endl << endl;
71 gLog << " REMARK: At the moment you can process a .raw _or_ a .rep file, only!" << endl << endl;
72}
73
74int main(const int argc, char **argv)
75{
76 StartUpMessage();
77
78 //
79 // Evaluate arguments
80 //
81 MArgs arg(argc, argv);
82
83 if (arg.HasOption("-?") || arg.HasOption("-h"))
84 {
85 Usage();
86 return -1;
87 }
88
89 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
90 gLog.SetNoColors();
91
92 const Int_t kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
93 Bool_t kUpdate = arg.HasOption("-u") && arg.GetIntAndRemove("-u")==1;
94
95 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
96
97 //
98 // check for the right usage of the program
99 //
100 if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
101 {
102 Usage();
103 return -1;
104 }
105
106 //
107 // This is to make argv[i] more readable insidethe code
108 //
109 TString kNamein = arg.GetArgumentStr(0);
110 TString kNameout = arg.GetArgumentStr(1);
111
112 const Bool_t isreport = kNamein.EndsWith(".rep");
113 const Bool_t isdc = kNamein.EndsWith(".txt");
114
115 if (!kNamein.EndsWith(".raw") && !isreport && !isdc)
116 kNamein += ".raw";
117
118 if (kNameout.IsNull())
119 kNameout = kNamein(0, kNamein.Last('.'));
120
121 if (!kNameout.EndsWith(".root"))
122 kNameout += ".root";
123
124 //
125 // Initialize Non-GUI (batch) mode
126 //
127 gROOT->SetBatch();
128
129 //
130 // check whether the given files are OK.
131 //
132 if (gSystem->AccessPathName(kNamein, kFileExists))
133 {
134 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
135 return -1;
136 }
137
138 const Bool_t fileexist = !gSystem->AccessPathName(kNameout, kFileExists);
139 const Bool_t writeperm = !gSystem->AccessPathName(kNameout, kWritePermission);
140
141 if (fileexist && !writeperm)
142 {
143 gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
144 return -1;
145 }
146
147 if (fileexist && !kUpdate)
148 {
149 gLog << err << "Sorry, file '" << kNameout << "' already existing." << endl;
150 return -1;
151 }
152
153 if (!fileexist && kUpdate)
154 {
155 gLog << warn << "File '" << kNameout << "' doesn't yet exist." << endl;
156 kUpdate=kFALSE;
157 }
158
159 MArray::Class()->IgnoreTObjectStreamer();
160 MParContainer::Class()->IgnoreTObjectStreamer();
161
162 //
163 // create a (empty) list of parameters which can be used by the tasks
164 // and an (empty) list of tasks which should be executed
165 //
166 MParList plist;
167
168 MTaskList tasks;
169 tasks.SetOwner();
170 plist.AddToList(&tasks);
171
172 //
173 // ---- The following is only necessary to supress some output ----
174 //
175 MRawRunHeader runheader;
176 plist.AddToList(&runheader);
177
178 MRawEvtHeader evtheader;
179 plist.AddToList(&evtheader);
180
181 MRawEvtData evtdata;
182 plist.AddToList(&evtdata);
183
184 MRawCrateArray cratearray;
185 plist.AddToList(&cratearray);
186
187 MTime evttime;
188 plist.AddToList(&evttime);
189
190 //
191 // create the tasks which should be executed and add them to the list
192 // in the case you don't need parameter containers, all of them can
193 // be created by MRawFileRead::PreProcess
194 //
195 MTask *read = 0;
196 MTask *write = 0;
197
198 const TString option(kUpdate ? "UPDATE" : "RECREATE");
199 if (isreport || isdc)
200 {
201 MReportFileRead *r = new MReportFileRead(kNamein);
202 if (isdc)
203 {
204 r->SetHasNoHeader();
205 r->AddToList("MReportCurrents");
206 }
207 else
208 {
209 r->AddToList("MReportDAQ");
210 r->AddToList("MReportDrive");
211 r->AddToList("MReportCamera");
212 r->AddToList("MReportTrigger");
213 }
214 read = r;
215
216 MWriteRootFile *w = new MWriteRootFile(kNameout, option, "Magic root-file", kComprlvl);
217 /*
218 w->AddContainer("MReportDAQ", "DAQ");
219 w->AddContainer("MTimeDAQ", "DAQ");
220 w->AddContainer("MReportDrive", "Drive");
221 w->AddContainer("MTimeDrive", "Drive");
222 */
223 if (isdc)
224 {
225 w->AddContainer("MTimeCurrents", "DC");
226 w->AddContainer("MCameraDC", "DC");
227 w->AddContainer("MReportCurrents", "DC");
228 }
229 else
230 {
231 w->AddContainer("MReportCamera", "Camera");
232 w->AddContainer("MTimeCamera", "Camera");
233 w->AddContainer("MCameraAUX", "Camera");
234 w->AddContainer("MCameraCalibration", "Camera");
235 w->AddContainer("MCameraCooling", "Camera");
236 w->AddContainer("MCameraHV", "Camera");
237 w->AddContainer("MCameraLV", "Camera");
238 w->AddContainer("MCameraLids", "Camera");
239 w->AddContainer("MReportTrigger", "Trigger");
240 w->AddContainer("MTimeTrigger", "Trigger");
241 w->AddContainer("MReportDrive", "Drive");
242 w->AddContainer("MTimeDrive", "Drive");
243 }
244 write = w;
245 }
246 else
247 {
248 read = new MRawFileRead(kNamein);
249 write = new MRawFileWrite(kNameout, option, "Magic root-file", kComprlvl);
250 }
251 tasks.AddToList(read);
252 tasks.AddToList(write);
253
254 //
255 // create the looping object and tell it about the parameters to use
256 // and the tasks to execute
257 //
258 MEvtLoop magic;
259 magic.SetParList(&plist);
260
261 //
262 // Start the eventloop which reads the raw file (MRawFileRead) and
263 // write all the information into a root file (MRawFileWrite)
264 //
265 // between reading and writing we can do, transformations, checks, etc.
266 // (I'm think of a task like MRawDataCheck)
267 //
268 if (!magic.Eventloop())
269 {
270 gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
271 return -1;
272 }
273
274 tasks.PrintStatistics();
275
276 gLog << all << "Merpp finished successfull!" << endl;
277 return 0;
278}
279
280
Note: See TracBrowser for help on using the repository browser.