source: tags/Mars-V0.8.3/star.cc@ 17873

Last change on this file since 17873 was 2563, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.4 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 "MBlindPixelCalc.h"
20#include "MSigmabarCalc.h"
21#include "MImgCleanStd.h"
22#include "MHillasCalc.h"
23#include "MHillasSrcCalc.h"
24#include "MWriteRootFile.h"
25
26using namespace std;
27
28//////////////////////////////////////////////////////////////////////////////
29//
30// This is an easy implementation of the Star process
31// (as compilable prog)
32//
33//////////////////////////////////////////////////////////////////////////////
34
35static void StartUpMessage()
36{
37 gLog << all << endl;
38
39 // 1 2 3 4 5
40 // 12345678901234567890123456789012345678901234567890
41 gLog << "==================================================" << endl;
42 gLog << " STAR - MARS V" << MARSVER << endl;
43 gLog << " MARS - STandard Analysis and Reconstruction" << endl;
44 gLog << " Compiled on <" << __DATE__ << ">" << endl;
45 gLog << " Using ROOT v" << ROOTVER << endl;
46 gLog << "==================================================" << endl;
47 gLog << endl;
48}
49
50static void Usage()
51{
52 gLog << all << endl;
53 gLog << "Sorry the usage is:" << endl;
54 gLog << " star [-a0] [-vn] [-cn] inputfile[.root] outputfile[.root]" << endl << endl;
55 gLog << " input file: Merpped or MC root file." << endl;
56 gLog << " ouput file: Star-file (image parameter file)" << endl;
57 gLog << " -a0: Do not use Ansii codes." << endl;
58 gLog << " -cn: Compression level n=1..9 [default=2]" << endl;
59 gLog << " -vn: Verbosity level n [default=2]" << endl;
60 gLog << " -u1: Update File (instead of Recreate)" << endl;
61 gLog << " -tn: Telescope Serial Number n [default=0]" << endl << endl;
62 gLog << " -> Further setup is not possible at the moment, please use" << endl;
63 gLog << " the star.C root macro instead. Using an input card will" << endl;
64 gLog << " be implemented in the future." << endl << endl;
65}
66
67int main(const int argc, char **argv)
68{
69 StartUpMessage();
70
71 //
72 // Evaluate arguments
73 //
74 MArgs arg(argc, argv);
75
76 //
77 // Set verbosity to highest level.
78 //
79 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
80
81 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
82 gLog.SetNoColors();
83
84 const int kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
85 const int kTelIndex = arg.HasOption("-t") ? arg.GetIntAndRemove("-t") : 0;
86 const bool kUpdate = arg.HasOption("-u") && arg.GetIntAndRemove("-u")==1;
87
88 //
89 // check for the right usage of the program
90 //
91 if (arg.GetNumArguments()!=2)
92 {
93 Usage();
94 return -1;
95 }
96
97 //
98 // This is to make argv[i] more readable inside the code
99 //
100 TString kNamein = arg.GetArgumentStr(0);
101 TString kNameout = arg.GetArgumentStr(1);
102
103 if (!kNamein.EndsWith(".root"))
104 kNamein += ".root";
105
106 if (!kNameout.EndsWith(".root"))
107 kNameout += ".root";
108
109 //
110 // Initialize Non-GUI (batch) mode
111 //
112 gROOT->SetBatch();
113
114 //
115 // check whether the given files are OK.
116 //
117 if (gSystem->AccessPathName(kNamein, kFileExists))
118 {
119 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
120 return -1;
121 }
122
123 if (!gSystem->AccessPathName(kNameout, kFileExists))
124 {
125 if (kUpdate)
126 gLog << warn << "Warning: File doesn't '" << kNameout << "' exist... recreating." << endl;
127 }
128
129 if (kUpdate || gSystem->AccessPathName(kNameout, kFileExists))
130 if (!gSystem->AccessPathName(kNameout, kWritePermission))
131 {
132 gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
133 return -1;
134 }
135
136 MArray::Class()->IgnoreTObjectStreamer();
137 MParContainer::Class()->IgnoreTObjectStreamer();
138
139 //
140 // Create a empty Parameter List and an empty Task List
141 // The tasklist is identified in the eventloop by its name
142 //
143 MParList plist;
144
145 MTaskList tlist;
146 plist.AddToList(&tlist);
147
148 //
149 // Now setup the tasks and tasklist:
150 // ---------------------------------
151 //
152 MReadMarsFile read("Events", kNamein);
153 read.DisableAutoScheme();
154
155 MGeomApply apply;
156 MMcPedestalCopy pcopy;
157 MMcPedestalNSBAdd pnsb;
158 MCerPhotCalc ncalc;
159 MBlindPixelCalc blind;
160 MSigmabarCalc sgcal;
161 MImgCleanStd clean;
162 MHillasCalc hcalc;
163 MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
164 MWriteRootFile write(kNameout, kUpdate?"UPDATE":"RECREATE", "Star output", kComprlvl);
165
166 tlist.AddToList(&read);
167 tlist.AddToList(&apply);
168 tlist.AddToList(&pcopy);
169 tlist.AddToList(&pnsb);
170 tlist.AddToList(&ncalc);
171 tlist.AddToList(&blind);
172 tlist.AddToList(&sgcal);
173 tlist.AddToList(&clean);
174 tlist.AddToList(&hcalc);
175 tlist.AddToList(&scalc);
176 tlist.AddToList(&write);
177
178 //
179 // Set the serial number for all tasks in the current tasklist
180 //
181 tlist.SetSerialNumber(kTelIndex);
182
183 //
184 // Setup tasks
185 //
186 blind.SetUseInterpolation();
187
188 write.AddContainer(write.AddSerialNumber("MMcEvt"), "Events");
189 write.AddContainer(write.AddSerialNumber("MSigmabar"), "Events");
190 write.AddContainer(write.AddSerialNumber("MHillas"), "Events");
191 write.AddContainer(write.AddSerialNumber("MHillasExt"), "Events");
192 write.AddContainer(write.AddSerialNumber("MHillasSrc"), "Events");
193 write.AddContainer(write.AddSerialNumber("MNewImagePar"), "Events");
194 write.AddContainer(write.AddSerialNumber("MSrcPosCam"), "RunHeaders");
195 if (!kUpdate)
196 {
197 write.AddContainer("MRawRunHeader", "RunHeaders");
198 write.AddContainer("MMcRunHeader", "RunHeaders");
199 }
200
201 //
202 // Create and set up the eventloop
203 //
204 MEvtLoop evtloop;
205 evtloop.SetParList(&plist);
206
207 //
208 // Execute your analysis
209 //
210 if (!evtloop.Eventloop())
211 {
212 gLog << err << "ERROR: Star eventloop failed!" << endl;
213 return -1;
214 }
215
216 // tlist.PrintStatistics();
217
218 gLog << all << "Star finished successfull!" << endl;
219 return 0;
220}
Note: See TracBrowser for help on using the repository browser.