source: trunk/MagicSoft/Mars/star.cc@ 4098

Last change on this file since 4098 was 3183, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 13.8 KB
Line 
1#include <TSystem.h>
2
3#include "MParList.h"
4#include "MTaskList.h"
5#include "MEvtLoop.h"
6/*'
7#include "MLog.h"
8 */
9#include "MLogManip.h"
10
11#include "MArgs.h"
12
13#include "MArray.h"
14#include "MReadMarsFile.h"
15#include "MGeomApply.h"
16#include "MMcPedestalCopy.h"
17#include "MMcPedestalNSBAdd.h"
18#include "MCerPhotCalc.h"
19#include "MCerPhotAnal2.h"
20#include "MBlindPixelCalc.h"
21#include "MSigmabarCalc.h"
22#include "MImgCleanStd.h"
23#include "MHillasCalc.h"
24#include "MHillasSrcCalc.h"
25#include "MWriteRootFile.h"
26#include "MFDataMember.h"
27#include "MFillH.h"
28#include "MReportDrive.h" // PRELIMINARY:
29//#include "MPointingPos.h" // PRELIMINARY:
30//#include "MPointingPosCalc.h"
31
32using namespace std;
33
34//////////////////////////////////////////////////////////////////////////////
35//
36// This is an easy implementation of the Star process
37// (as compilable prog)
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 << " STAR - MARS V" << MARSVER << endl;
49 gLog << " MARS - STandard Analysis and Reconstruction" << 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 << " star [-a0] [-vn] [-cn] inputfile[.root] outputfile[.root]" << endl << endl;
61 gLog << " input file: Merpped or MC root file." << endl;
62 gLog << " ouput file: Star-file (image parameter file)" << endl;
63 gLog << " -a0: Do not use Ansii codes." << endl;
64 gLog << " -cn: Compression level n=1..9 [default=2]" << endl;
65 gLog << " -vn: Verbosity level n [default=2]" << endl;
66 gLog << " -u1: Update File (instead of Recreate)" << endl;
67 gLog << " -tn: Telescope Serial Number n [default=0]" << endl << endl;
68 gLog << " -> Further setup is not possible at the moment, please use" << endl;
69 gLog << " the star.C root macro instead. Using an input card will" << endl;
70 gLog << " be implemented in the future." << endl << endl;
71}
72
73class MJStar : public MParContainer
74{
75private:
76 TString fInputFile;
77 TString fOutputFile;
78
79 Bool_t fIsUpdate;
80 Byte_t fComprLevel;
81
82 Byte_t fSerialIdx;
83
84 Bool_t CheckFiles()
85 {
86 if (fOutputFile.IsNull())
87 {
88 fOutputFile = fInputFile;
89
90 if (fOutputFile.EndsWith(".raw"))
91 fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
92
93 if (fOutputFile.EndsWith(".rep"))
94 fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
95
96 if (fOutputFile.EndsWith(".txt"))
97 fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
98 }
99
100 if (fInputFile.IsNull())
101 {
102 *fLog << err << "Sorry, no input file." << endl;
103 return kFALSE;
104 }
105
106 if (fOutputFile.IsNull())
107 {
108 *fLog << err << "Sorry, no output file." << endl;
109 return kFALSE;
110 }
111
112 if (!fInputFile.EndsWith(".root"))
113 fInputFile += ".root";
114
115 if (!fOutputFile.EndsWith(".root"))
116 fOutputFile += ".root";
117
118 //
119 // check whether the given files are OK.
120 //
121 if (gSystem->AccessPathName(fInputFile, kFileExists))
122 {
123 *fLog << err << "Sorry, the input file '" << fInputFile << "' doesn't exist." << endl;
124 return kFALSE;
125 }
126
127 if (!gSystem->AccessPathName(fOutputFile, kFileExists))
128 {
129 if (fIsUpdate)
130 gLog << warn << "Warning: File doesn't '" << fOutputFile << "' exist... recreating." << endl;
131 }
132
133 if (fIsUpdate || gSystem->AccessPathName(fOutputFile, kFileExists))
134 if (!gSystem->AccessPathName(fOutputFile, kWritePermission))
135 {
136 gLog << err << "Sorry, you don't have write permission for '" << fOutputFile << "'." << endl;
137 return kFALSE;
138 }
139 return kTRUE;
140 }
141
142public:
143 MJStar(const char *name=0, const char *title=0)
144 : fIsUpdate(kFALSE), fComprLevel(1), fSerialIdx(0)
145 {
146 fName = name;
147 fTitle = title;
148 }
149
150 void SetInputFile(const char *f) { fInputFile = f; }
151 void SetOutputFile(const char *f) { fOutputFile = f; }
152 void SetSerialIdx(Byte_t i) { fSerialIdx = i; }
153 void SetComprLevel(Byte_t l) { fComprLevel = l; }
154 void SetUpdate(Bool_t u=kTRUE) { fIsUpdate = u; }
155
156 Bool_t Process()
157 {
158 if (!CheckFiles())
159 return kFALSE;
160
161 //
162 // Create a empty Parameter List and an empty Task List
163 // The tasklist is identified in the eventloop by its name
164 //
165 MParList plist;
166
167 MTaskList tlist;
168 plist.AddToList(&tlist);
169
170 // PRELIMINARY:
171 /*
172 MReportDrive rep;
173 plist.AddToList(&rep);
174 MPointingPos pos;
175 plist.AddToList(&pos);
176 */
177
178 //
179 // Now setup the tasks and tasklist:
180 // ---------------------------------
181 //
182 MReadMarsFile read("Events", fInputFile);
183 read.DisableAutoScheme();
184
185 MGeomApply apply;
186 MMcPedestalCopy pcopy;
187 MMcPedestalNSBAdd pnsb;
188
189 //MPointingPosCalc pcalc;
190
191 MCerPhotCalc ncalc;
192 MCerPhotAnal2 nanal;
193
194 MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);
195 MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);
196
197 ncalc.SetFilter(&f1);
198 nanal.SetFilter(&f2);
199
200 MBlindPixelCalc blind;
201 MSigmabarCalc sgcal;
202 //MFillH fills("MHSigmaTheta", "", "FillSigmaTheta");
203 //MFillH fillb("MHBlindPixels", "", "FillBlindPixels");
204 MImgCleanStd clean;
205 MHillasCalc hcalc;
206 MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
207 MWriteRootFile write(fOutputFile, fIsUpdate?"UPDATE":"RECREATE", "Star output", fComprLevel);
208
209 tlist.AddToList(&read);
210 tlist.AddToList(&f1);
211 tlist.AddToList(&f2);
212 tlist.AddToList(&apply);
213 tlist.AddToList(&pcopy);
214 tlist.AddToList(&pnsb);
215 //tlist.AddToList(&pcalc);
216 tlist.AddToList(&ncalc);
217 tlist.AddToList(&nanal);
218 tlist.AddToList(&blind);
219 tlist.AddToList(&sgcal);
220 //tlist.AddToList(&fills);
221 //tlist.AddToList(&fillb);
222 tlist.AddToList(&clean);
223 tlist.AddToList(&hcalc);
224 tlist.AddToList(&scalc);
225 tlist.AddToList(&write);
226
227 //
228 // Set the serial number for all tasks in the current tasklist
229 //
230 tlist.SetSerialNumber(fSerialIdx);
231
232 //
233 // Setup tasks
234 //
235 blind.SetUseInterpolation();
236
237 write.AddContainer(write.AddSerialNumber("MMcEvt"), "Events", kFALSE);
238 write.AddContainer(write.AddSerialNumber("MSigmabar"), "Events");
239 write.AddContainer(write.AddSerialNumber("MHillas"), "Events");
240 write.AddContainer(write.AddSerialNumber("MHillasExt"), "Events");
241 write.AddContainer(write.AddSerialNumber("MHillasSrc"), "Events");
242 write.AddContainer(write.AddSerialNumber("MNewImagePar"), "Events");
243 write.AddContainer(write.AddSerialNumber("MSrcPosCam"), "RunHeaders");
244 //write.AddContainer(write.AddSerialNumber("MHSigmaTheta"), "RunHeaders");
245 if (!fIsUpdate)
246 {
247 write.AddContainer("MRawRunHeader", "RunHeaders");
248 write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
249 }
250
251 //
252 // Create and set up the eventloop
253 //
254 MEvtLoop evtloop;
255 evtloop.SetParList(&plist);
256
257 //
258 // Execute your analysis
259 //
260 if (!evtloop.Eventloop())
261 {
262 gLog << err << "ERROR: Star eventloop failed!" << endl;
263 return kFALSE;
264 }
265
266 tlist.PrintStatistics();
267
268 //plist.FindObject("MHSigmaTheta")->Write();
269 //plist.FindObject("MHBlindPixels")->Write();
270
271 gLog << all << "Star finished successfull!" << endl;
272
273 return kTRUE;
274 }
275// ClassDef(MJStar, 0)
276};
277
278//ClassImp(MJStar);
279
280
281int main(const int argc, char **argv)
282{
283 StartUpMessage();
284
285 //
286 // Evaluate arguments
287 //
288 MArgs arg(argc, argv);
289
290 //
291 // Set verbosity to highest level.
292 //
293 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
294
295 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
296 gLog.SetNoColors();
297
298 const int kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
299 const int kTelIndex = arg.HasOption("-t") ? arg.GetIntAndRemove("-t") : 0;
300 const bool kUpdate = arg.HasOption("-u") && arg.GetIntAndRemove("-u")==1;
301
302 //
303 // check for the right usage of the program
304 //
305 if (arg.GetNumArguments()!=2)
306 {
307 Usage();
308 return -1;
309 }
310
311 //
312 // Initialize Non-GUI (batch) mode
313 //
314 gROOT->SetBatch();
315
316 MArray::Class()->IgnoreTObjectStreamer();
317 MParContainer::Class()->IgnoreTObjectStreamer();
318
319 MJStar star;
320 star.SetInputFile(arg.GetArgumentStr(0));
321 star.SetOutputFile(arg.GetArgumentStr(1));
322 star.SetComprLevel(kComprlvl);
323 star.SetSerialIdx(kTelIndex);
324 star.SetUpdate(kUpdate);
325
326 if (!star.Process())
327 {
328 gLog << err << "Star failed!" << endl;
329 return -1;
330 }
331
332 gLog << inf << "Star finished successfull!" << endl;
333
334 return 0;
335/*
336 //
337 // This is to make argv[i] more readable inside the code
338 //
339 TString kNamein = arg.GetArgumentStr(0);
340 TString kNameout = arg.GetArgumentStr(1);
341
342 if (!kNamein.EndsWith(".root"))
343 kNamein += ".root";
344
345 if (!kNameout.EndsWith(".root"))
346 kNameout += ".root";
347
348 //
349 // check whether the given files are OK.
350 //
351 if (gSystem->AccessPathName(kNamein, kFileExists))
352 {
353 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
354 return -1;
355 }
356
357 if (!gSystem->AccessPathName(kNameout, kFileExists))
358 {
359 if (kUpdate)
360 gLog << warn << "Warning: File doesn't '" << kNameout << "' exist... recreating." << endl;
361 }
362
363 if (kUpdate || gSystem->AccessPathName(kNameout, kFileExists))
364 if (!gSystem->AccessPathName(kNameout, kWritePermission))
365 {
366 gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
367 return -1;
368 }
369
370 //
371 // Create a empty Parameter List and an empty Task List
372 // The tasklist is identified in the eventloop by its name
373 //
374 MParList plist;
375
376 MTaskList tlist;
377 plist.AddToList(&tlist);
378
379 // PRELIMINARY:
380 // MReportDrive rep;
381 // plist.AddToList(&rep);
382 // MPointingPos pos;
383 // plist.AddToList(&pos);
384
385 //
386 // Now setup the tasks and tasklist:
387 // ---------------------------------
388 //
389 MReadMarsFile read("Events", kNamein);
390 read.DisableAutoScheme();
391
392 MGeomApply apply;
393 MMcPedestalCopy pcopy;
394 MMcPedestalNSBAdd pnsb;
395
396 //MPointingPosCalc pcalc;
397
398 MCerPhotCalc ncalc;
399 MCerPhotAnal2 nanal;
400
401 MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);
402 MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);
403
404 ncalc.SetFilter(&f1);
405 nanal.SetFilter(&f2);
406
407 MBlindPixelCalc blind;
408 MSigmabarCalc sgcal;
409 //MFillH fills("MHSigmaTheta", "", "FillSigmaTheta");
410 //MFillH fillb("MHBlindPixels", "", "FillBlindPixels");
411 MImgCleanStd clean;
412 MHillasCalc hcalc;
413 MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
414 MWriteRootFile write(kNameout, kUpdate?"UPDATE":"RECREATE", "Star output", kComprlvl);
415
416 tlist.AddToList(&read);
417 tlist.AddToList(&f1);
418 tlist.AddToList(&f2);
419 tlist.AddToList(&apply);
420 tlist.AddToList(&pcopy);
421 tlist.AddToList(&pnsb);
422 //tlist.AddToList(&pcalc);
423 tlist.AddToList(&ncalc);
424 tlist.AddToList(&nanal);
425 tlist.AddToList(&blind);
426 tlist.AddToList(&sgcal);
427 //tlist.AddToList(&fills);
428 //tlist.AddToList(&fillb);
429 tlist.AddToList(&clean);
430 tlist.AddToList(&hcalc);
431 tlist.AddToList(&scalc);
432 tlist.AddToList(&write);
433
434 //
435 // Set the serial number for all tasks in the current tasklist
436 //
437 tlist.SetSerialNumber(kTelIndex);
438
439 //
440 // Setup tasks
441 //
442 blind.SetUseInterpolation();
443
444 write.AddContainer(write.AddSerialNumber("MMcEvt"), "Events", kFALSE);
445 write.AddContainer(write.AddSerialNumber("MSigmabar"), "Events");
446 write.AddContainer(write.AddSerialNumber("MHillas"), "Events");
447 write.AddContainer(write.AddSerialNumber("MHillasExt"), "Events");
448 write.AddContainer(write.AddSerialNumber("MHillasSrc"), "Events");
449 write.AddContainer(write.AddSerialNumber("MNewImagePar"), "Events");
450 write.AddContainer(write.AddSerialNumber("MSrcPosCam"), "RunHeaders");
451 //write.AddContainer(write.AddSerialNumber("MHSigmaTheta"), "RunHeaders");
452 if (!kUpdate)
453 {
454 write.AddContainer("MRawRunHeader", "RunHeaders");
455 write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
456 }
457
458 //
459 // Create and set up the eventloop
460 //
461 MEvtLoop evtloop;
462 evtloop.SetParList(&plist);
463
464 //
465 // Execute your analysis
466 //
467 if (!evtloop.Eventloop())
468 {
469 gLog << err << "ERROR: Star eventloop failed!" << endl;
470 return -1;
471 }
472
473 tlist.PrintStatistics();
474
475 //plist.FindObject("MHSigmaTheta")->Write();
476 //plist.FindObject("MHBlindPixels")->Write();
477
478 gLog << all << "Star finished successfull!" << endl;
479 return 0;
480 */
481}
Note: See TracBrowser for help on using the repository browser.