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

Last change on this file since 17873 was 2578, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 8.7 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
91Bool_t Loop(MOnlineDisplay *display, Int_t port)
92{
93 display->Reset();
94
95 //
96 // create the tasks which should be executed and add them to the list
97 // in the case you don't need parameter containers, all of them can
98 // be created by MRawFileRead::PreProcess
99 //
100 MRawSocketRead reader;
101 reader.SetPort(port);
102
103 //
104 // create a (empty) list of parameters which can be used by the tasks
105 // and an (empty) list of tasks which should be executed
106 //
107 MParList plist;
108
109 MTaskList tasks;
110 plist.AddToList(&tasks);
111 tasks.AddToList(&reader);
112
113 MGeomApply geomapl;
114 MCerPhotAnal2 ncalc;
115 tasks.AddToList(&geomapl);
116 tasks.AddToList(&ncalc);
117
118 MEventRateCalc tcalc;
119 tcalc.SetNumEvents(100);
120 tasks.AddToList(&tcalc);
121
122 MFillH fill1("MHEvent", "MCerPhotEvt", "MFillEvent");
123 MFillH fill2("MHCamEvent", "MCerPhotEvt", "MFillCamEvent");
124
125 MFRealTimePeriod filter;
126 fill1.SetFilter(&filter);
127
128 MHTriggerLvl0 trigmap(128, "Above 128");
129 MFillH fill3(&trigmap, "MRawEvtData", "MFillTriggerLvl0");
130
131 tasks.AddToList(&filter);
132
133 tasks.AddToList(&fill1);
134 tasks.AddToList(&fill2);
135 tasks.AddToList(&fill3);
136
137 MHCamEvent hist("PedestalRms");
138 hist.SetType(1);
139 plist.AddToList(&hist);
140
141 // -------------------------------------------
142
143 MHCamEvent maxhi("MaxIdxHi", "Index of slice with maximum content (hi-gain)");
144 MHCamEvent maxlo("MaxIdxLo", "Index of slice with maximum content (lo-gain)");
145 maxhi.SetType(3);
146 maxlo.SetType(4);
147 plist.AddToList(&maxhi);
148 plist.AddToList(&maxlo);
149
150 // -------------------------------------------
151
152 MFillH hfilla("MaxIdxHi", "MRawEvtData", "FillMaxIdxHi");
153 MFillH hfillb("MaxIdxLo", "MRawEvtData", "FillMaxIdxLo");
154 MFillH hfillc("Pedestals [MHCamEvent]", "MPedestalCam", "FillPedestal");
155 MFillH hfilld("PedestalRms", "MPedestalCam", "FillPedestalRms");
156 tasks.AddToList(&hfilla);
157 tasks.AddToList(&hfillb);
158 tasks.AddToList(&hfillc);
159 tasks.AddToList(&hfilld);
160
161 MOnlineDump dump;
162 dump.SetFilter(&filter);
163 display->SetTask(&dump);
164 tasks.AddToList(&dump);
165
166
167 MImgCleanStd clean;
168 MHillasCalc hcalc;
169 MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
170 MFillH hfill3("MHHillas", "MHillas", "MFillHillas");
171 MFillH hfill4("MHHillasSrc","MHillasSrc", "MFillHillasSrc");
172 tasks.AddToList(&clean);
173 tasks.AddToList(&hcalc);
174 tasks.AddToList(&scalc);
175 tasks.AddToList(&hfill3);
176 tasks.AddToList(&hfill4);
177
178 MEvtLoop magic;
179 magic.SetParList(&plist);
180
181 magic.SetDisplay(display);
182 magic.SetProgressBar((TGProgressBar*)NULL);
183
184 if (!magic.Eventloop())
185 {
186 gLog << err << "Mona Eventloop error..." << endl;
187 return kFALSE;
188 }
189
190 tasks.PrintStatistics();
191 return kTRUE;
192}
193
194//
195// By defining the function return type 'void' instead of
196// 'void*' we tell TThread to create a detached thread,
197// but calling Exit() in a detached thread results in a crash
198// when the TGApplication is terminated.
199//
200void *thread(void *ptr)
201{
202 const Int_t port = *((Int_t**)ptr)[0];
203 MOnlineDisplay &d = *((MOnlineDisplay**)ptr)[1];
204
205 //
206 // If a loop is stopped reinitialize a new loop until the
207 // user requested to exit the program.
208 //
209 while (d.CheckStatus()!=MStatusDisplay::kFileExit)
210 Loop(&d, port);
211
212
213 gLog << dbg << "Loop stopped... exit thread()" << endl;
214
215 return 0;
216}
217
218/*
219#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
220#include <TRootGuiFactory.h>
221#include <TPluginManager.h>
222void InitGuiFactory()
223{
224 if (gROOT->IsBatch())
225 gROOT->SetBatch(kFALSE);
226
227 //
228 // Must be loaded by hand, because it is not loaded by TGApplication.
229 // We could also use TApplication instead, but TApplication doesn't
230 // deal with the DISPLAY variable in a convient way.
231 //
232 TPluginHandler *h;
233 if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", "root")))
234 {
235 if (h->LoadPlugin() == -1)
236 return;
237 gGuiFactory = (TGuiFactory*)h->ExecPlugin(0);
238 }
239}
240#endif
241*/
242
243static void Usage()
244{
245 gLog << all << endl;
246 gLog << "Sorry the usage is:" << endl;
247 gLog << " mona [-?] [-h] [-a0] [-h] [-pn] [-vn]" << endl << endl;
248 gLog << " -a0: Do not use Ansii codes." << endl;
249 gLog << " -pn: TCP/IP port n [default=7000]" << endl;
250 gLog << " -vn: Verbosity level n [default=2]" << endl << endl;
251 gLog << " -?/-h: This help" << endl << endl;
252}
253
254
255int main(int argc, char **argv)
256{
257 StartUpMessage();
258
259 //
260 // Evaluate arguments
261 //
262 MArgs arg(argc, argv);
263
264 if (arg.HasOption("-?") || arg.HasOption("-h"))
265 {
266 Usage();
267 return -1;
268 }
269
270 //
271 // Set verbosity to highest level.
272 //
273 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
274
275 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
276 gLog.SetNoColors();
277
278 const Int_t port = arg.HasOption("-p") ? arg.GetIntAndRemove("-p") : 7000;
279
280 //
281 // check for the right usage of the program
282 //
283 if (arg.GetNumArguments()>0)
284 {
285 Usage();
286 return -1;
287 }
288
289 TApplication app("Mars", &argc, argv);
290 if (gROOT->IsBatch() || !gClient)
291 {
292 gLog << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
293 return 1;
294 }
295
296 /*
297 TGApplication app("Mona", &argc, argv);
298
299#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
300 InitGuiFactory();
301#endif
302 */
303
304 ChangeContextMenus();
305
306 //
307 // Starting MStatusDisplay in the thread results in hangs
308 // if the thread is terminated (by return)
309 //
310 gLog << dbg << "Starting Display..." << flush;
311 MOnlineDisplay d;
312 d.SetBit(MStatusDisplay::kExitLoopOnExit);
313 gLog << "done." << endl;
314
315 // gDebug=1;
316
317 gLog << dbg << "Starting Thread..." << flush;
318 const void *ptr[2] = { &port, &d };
319 TThread t(thread, ptr);
320 t.Run();
321 gLog << "done." << endl;
322
323 gLog << dbg << "Starting System loop... " << endl;
324 app.Run(kTRUE);
325 gLog << dbg << "System loop stopped." << endl;
326
327 d.UnmapWindow();
328
329 gLog << dbg << "Waiting for termination of thread... (be patient)" << endl;
330 while (t.GetState()!=TThread::kCanceledState)
331 gSystem->ProcessEvents();
332
333 gLog << dbg << "Thread terminated... joining." << endl;
334
335 TThread::Join(t.GetId()); //- seems that it is implicitly done... why?
336
337 gLog << dbg << "Exit MONA." << endl;
338
339 return 0;
340}
Note: See TracBrowser for help on using the repository browser.