source: trunk/MagicSoft/Mars/mona.cc@ 2565

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