source: branches/MarsMoreSimulationTruth/mona.cc@ 20042

Last change on this file since 20042 was 4058, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 8.9 KB
Line 
1#include <TApplication.h>
2
3#include <TThread.h>
4#include <TCanvas.h>
5#include <TMethod.h> // GetMenuItems
6
7#include <TGButton.h>
8
9#include "MParList.h"
10#include "MTaskList.h"
11#include "MEvtLoop.h"
12
13#include "MLogManip.h"
14
15#include "MRawSocketRead.h"
16#include "MGeomApply.h"
17#include "MCerPhotAnal2.h"
18#include "MFillH.h"
19#include "MFRealTimePeriod.h"
20#include "MHTriggerLvl0.h"
21#include "MHCamera.h" // ::Class(), SetFreezed
22#include "MHCamEvent.h" // MHCamEvent
23#include "MHEvent.h" // MHEvent::GetHist()
24
25#include "MOnlineDump.h"
26#include "MOnlineDisplay.h"
27
28#include "MImgCleanStd.h"
29#include "MHillasCalc.h"
30#include "MHillasSrcCalc.h"
31#include "MEventRateCalc.h"
32
33#include "MArgs.h"
34
35// --------------------------------------------------------------------
36
37#include "MTime.h"
38#include "MRawEvtHeader.h" // MRawEvtHeader
39#include "MRawRunHeader.h" // MRawRunHeader
40
41using namespace std;
42
43void StartUpMessage()
44{
45 gLog << all << endl;
46
47 // 1 2 3 4 5
48 // 12345678901234567890123456789012345678901234567890
49 gLog << "==================================================" << endl;
50 gLog << " MONA V" << MARSVER << " " << endl;
51 gLog << " Magic Online Analysis " << endl;
52 gLog << " Compiled on <" << __DATE__ << ">" << endl;
53 gLog << " Using ROOT v" << ROOTVER << endl;
54 gLog << "==================================================" << endl;
55 gLog << endl;
56}
57
58void Remove(TMethod *m, const char *name)
59{
60 if (TString(m->GetName()).BeginsWith(name))
61 m->SetMenuItem(kMenuNoMenu);
62}
63
64void ChangeContextMenus()
65{
66 TList l;
67 MHCamera::Class()->GetMenuItems(&l);
68 TIter Next(&l);
69 TMethod *m=NULL;
70 while ((m=(TMethod*)Next()))
71 {
72 Remove(m, "DrawClone");
73 Remove(m, "SetName");
74 Remove(m, "Delete");
75 Remove(m, "DrawClass");
76 Remove(m, "Dump");
77 Remove(m, "Inspect");
78 Remove(m, "Smooth");
79 Remove(m, "Fit");
80 Remove(m, "Divide");
81 Remove(m, "Add");
82 Remove(m, "Multiply");
83 Remove(m, "Delete");
84 Remove(m, "SetLineAttributes");
85 Remove(m, "SetFillAttributes");
86 Remove(m, "SetMarkerAttributes");
87 Remove(m, "SetDrawOption");
88 }
89}
90
91#include "MPedPhotCam.h"
92Bool_t Loop(MOnlineDisplay *display, Int_t port)
93{
94 display->Reset();
95
96 //
97 // create the tasks which should be executed and add them to the list
98 // in the case you don't need parameter containers, all of them can
99 // be created by MRawFileRead::PreProcess
100 //
101 MRawSocketRead reader;
102 reader.SetPort(port);
103
104 //
105 // create a (empty) list of parameters which can be used by the tasks
106 // and an (empty) list of tasks which should be executed
107 //
108 MParList plist;
109
110 MTaskList tasks;
111 plist.AddToList(&tasks);
112 tasks.AddToList(&reader);
113
114 MPedPhotCam pcam;
115 plist.AddToList(&pcam);
116
117 MGeomApply geomapl;
118 MCerPhotAnal2 ncalc;
119 tasks.AddToList(&geomapl);
120 tasks.AddToList(&ncalc);
121
122 MEventRateCalc tcalc;
123 tcalc.SetNumEvents(100);
124 tasks.AddToList(&tcalc);
125
126 MFillH fill1("MHEvent", "MCerPhotEvt", "MFillEvent");
127 MFillH fill2("MHCamEvent", "MCerPhotEvt", "MFillCamEvent");
128
129 MFRealTimePeriod filter;
130 fill1.SetFilter(&filter);
131
132 MHTriggerLvl0 trigmap(128, "Above 128");
133 MFillH fill3(&trigmap, "MRawEvtData", "MFillTriggerLvl0");
134
135 tasks.AddToList(&filter);
136
137 tasks.AddToList(&fill1);
138 tasks.AddToList(&fill2);
139 tasks.AddToList(&fill3);
140
141 MHCamEvent hist("PedestalRms");
142 hist.SetType(1);
143 plist.AddToList(&hist);
144
145 // -------------------------------------------
146
147 MHCamEvent maxhi("MaxIdxHi", "Index of slice with maximum content (hi-gain)");
148 MHCamEvent maxlo("MaxIdxLo", "Index of slice with maximum content (lo-gain)");
149 maxhi.SetType(3);
150 maxlo.SetType(4);
151 plist.AddToList(&maxhi);
152 plist.AddToList(&maxlo);
153
154 // -------------------------------------------
155
156 MFillH hfilla("MaxIdxHi", "MRawEvtData", "FillMaxIdxHi");
157 MFillH hfillb("MaxIdxLo", "MRawEvtData", "FillMaxIdxLo");
158 MFillH hfillc("Pedestals [MHCamEvent]", "MPedPhotCam", "FillPedestal");
159 MFillH hfilld("PedestalRms", "MPedPhotCam", "FillPedestalRms");
160 tasks.AddToList(&hfilla);
161 tasks.AddToList(&hfillb);
162 tasks.AddToList(&hfillc);
163 tasks.AddToList(&hfilld);
164
165 MOnlineDump dump;
166 dump.SetFilter(&filter);
167 display->SetTask(&dump);
168 tasks.AddToList(&dump);
169
170
171 MImgCleanStd clean;
172 MHillasCalc hcalc;
173 MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
174 MFillH hfill3("MHHillas", "MHillas", "MFillHillas");
175 MFillH hfill4("MHHillasSrc","MHillasSrc", "MFillHillasSrc");
176 tasks.AddToList(&clean);
177 tasks.AddToList(&hcalc);
178 tasks.AddToList(&scalc);
179 tasks.AddToList(&hfill3);
180 tasks.AddToList(&hfill4);
181
182 MEvtLoop magic;
183 magic.SetParList(&plist);
184
185 magic.SetDisplay(display);
186 magic.SetProgressBar((TGProgressBar*)NULL);
187
188 if (!magic.Eventloop())
189 {
190 gLog << err << "Mona Eventloop error..." << endl;
191 return kFALSE;
192 }
193
194 tasks.PrintStatistics();
195 return kTRUE;
196}
197
198//
199// By defining the function return type 'void' instead of
200// 'void*' we tell TThread to create a detached thread,
201// but calling Exit() in a detached thread results in a crash
202// when the TGApplication is terminated.
203//
204void *thread(void *ptr)
205{
206 const Int_t port = *((Int_t**)ptr)[0];
207 MOnlineDisplay &d = *((MOnlineDisplay**)ptr)[1];
208
209 //
210 // If a loop is stopped reinitialize a new loop until the
211 // user requested to exit the program.
212 //
213 while (d.CheckStatus()!=MStatusDisplay::kFileExit)
214 Loop(&d, port);
215
216
217 gLog << dbg << "Loop stopped... exit thread()" << endl;
218
219 return 0;
220}
221
222/*
223#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
224#include <TRootGuiFactory.h>
225#include <TPluginManager.h>
226void InitGuiFactory()
227{
228 if (gROOT->IsBatch())
229 gROOT->SetBatch(kFALSE);
230
231 //
232 // Must be loaded by hand, because it is not loaded by TGApplication.
233 // We could also use TApplication instead, but TApplication doesn't
234 // deal with the DISPLAY variable in a convient way.
235 //
236 TPluginHandler *h;
237 if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", "root")))
238 {
239 if (h->LoadPlugin() == -1)
240 return;
241 gGuiFactory = (TGuiFactory*)h->ExecPlugin(0);
242 }
243}
244#endif
245*/
246
247static void Usage()
248{
249 gLog << all << endl;
250 gLog << "Sorry the usage is:" << endl;
251 gLog << " mona [-?] [-h] [-a0] [-h] [-pn] [-vn]" << endl << endl;
252 gLog << " -a0: Do not use Ansii codes." << endl;
253 gLog << " -pn: TCP/IP port n [default=7000]" << endl;
254 gLog << " -vn: Verbosity level n [default=2]" << endl << endl;
255 gLog << " -?/-h: This help" << endl << endl;
256}
257
258
259int main(int argc, char **argv)
260{
261 StartUpMessage();
262
263 //
264 // Evaluate arguments
265 //
266 MArgs arg(argc, argv);
267
268 if (arg.HasOption("-?") || arg.HasOption("-h"))
269 {
270 Usage();
271 return -1;
272 }
273
274 //
275 // Set verbosity to highest level.
276 //
277 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
278
279 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
280 gLog.SetNoColors();
281
282 const Int_t port = arg.HasOption("-p") ? arg.GetIntAndRemove("-p") : 7000;
283
284 //
285 // check for the right usage of the program
286 //
287 if (arg.GetNumArguments()>0)
288 {
289 Usage();
290 return -1;
291 }
292
293 TApplication app("Mona", &argc, argv);
294 if (gROOT->IsBatch() || !gClient)
295 {
296 gLog << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
297 return 1;
298 }
299
300 /*
301 TGApplication app("Mona", &argc, argv);
302
303#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
304 InitGuiFactory();
305#endif
306 */
307
308 ChangeContextMenus();
309
310 //
311 // Starting MStatusDisplay in the thread results in hangs
312 // if the thread is terminated (by return)
313 //
314 gLog << dbg << "Starting Display..." << flush;
315 MOnlineDisplay d;
316 d.SetWindowName("Magic ONline Analysis");
317 d.SetIconName("Mona");
318
319 d.SetBit(MStatusDisplay::kExitLoopOnExit);
320 gLog << "done." << endl;
321
322 // gDebug=1;
323
324 gLog << dbg << "Starting Thread..." << flush;
325 const void *ptr[2] = { &port, &d };
326 TThread t(thread, ptr);
327 t.Run();
328 gLog << "done." << endl;
329
330 gLog << dbg << "Starting System loop... " << endl;
331 app.Run(kTRUE);
332 gLog << dbg << "System loop stopped." << endl;
333
334 d.UnmapWindow();
335
336 gLog << dbg << "Waiting for termination of thread... (be patient)" << endl;
337 while (t.GetState()!=TThread::kCanceledState)
338 gSystem->ProcessEvents();
339
340 gLog << dbg << "Thread terminated... joining." << endl;
341
342 TThread::Join(t.GetId()); //- seems that it is implicitly done... why?
343
344 gLog << dbg << "Exit MONA." << endl;
345
346 return 0;
347}
Note: See TracBrowser for help on using the repository browser.