source: tags/Mars-V0.8.2/mona.cc@ 15829

Last change on this file since 15829 was 2497, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.8 KB
Line 
1#include <TApplication.h>
2
3#include <TThread.h>
4#include <TMethod.h> // GetMenuItems
5
6#include "MParList.h"
7#include "MTaskList.h"
8#include "MEvtLoop.h"
9
10#include "MLogManip.h"
11
12#include "MRawSocketRead.h"
13#include "MGeomApply.h"
14#include "MCerPhotAnal2.h"
15#include "MFillH.h"
16#include "MFRealTimePeriod.h"
17#include "MOnlineDump2.h"
18#include "MHTriggerLvl0.h"
19#include "MHCamera.h" // ::Class()
20
21#include "MStatusDisplay.h"
22
23#include "MImgCleanStd.h"
24#include "MHillasCalc.h"
25#include "MHillasSrcCalc.h"
26
27void StartUpMessage()
28{
29 gLog << all << endl;
30
31 // 1 2 3 4 5
32 // 12345678901234567890123456789012345678901234567890
33 gLog << "==================================================" << endl;
34 gLog << " MONA V" << MARSVER << " " << endl;
35 gLog << " Magic Online Analysis " << endl;
36 gLog << " Compiled on <" << __DATE__ << ">" << endl;
37 gLog << " Using ROOT v" << ROOTVER << endl;
38 gLog << "==================================================" << endl;
39 gLog << endl;
40}
41
42void Remove(TMethod *m, const char *name)
43{
44 if (TString(m->GetName()).BeginsWith(name))
45 m->SetMenuItem(kMenuNoMenu);
46}
47
48void ChangeContextMenus()
49{
50 TList l;
51 MHCamera::Class()->GetMenuItems(&l);
52 TIter Next(&l);
53 TMethod *m=NULL;
54 while ((m=(TMethod*)Next()))
55 {
56 Remove(m, "DrawClone");
57 Remove(m, "SetName");
58 Remove(m, "Delete");
59 Remove(m, "DrawClass");
60 Remove(m, "Dump");
61 Remove(m, "Inspect");
62 Remove(m, "Smooth");
63 Remove(m, "Fit");
64 Remove(m, "Divide");
65 Remove(m, "Add");
66 Remove(m, "Multiply");
67 Remove(m, "Delete");
68 Remove(m, "SetLineAttributes");
69 Remove(m, "SetFillAttributes");
70 Remove(m, "SetMarkerAttributes");
71 Remove(m, "SetDrawOption");
72 }
73}
74
75Bool_t Loop(MStatusDisplay *display)
76{
77 //
78 // create the tasks which should be executed and add them to the list
79 // in the case you don't need parameter containers, all of them can
80 // be created by MRawFileRead::PreProcess
81 //
82 MRawSocketRead reader;
83 reader.SetPort(7000);
84
85 //
86 // create a (empty) list of parameters which can be used by the tasks
87 // and an (empty) list of tasks which should be executed
88 //
89 MParList plist;
90
91 MTaskList tasks;
92 plist.AddToList(&tasks);
93 tasks.AddToList(&reader);
94
95 MGeomApply geomapl;
96 MCerPhotAnal2 ncalc;
97 tasks.AddToList(&geomapl);
98 tasks.AddToList(&ncalc);
99
100 MFillH fill1("MHEvent", "MCerPhotEvt", "MFillEvent");
101 MFillH fill2("MHCamEvent", "MCerPhotEvt", "MFillCamEvent");
102
103 MFRealTimePeriod filter;
104 fill1.SetFilter(&filter);
105
106 MHTriggerLvl0 trigmap(128, "Above 128");
107 MFillH fill3(&trigmap, "MRawEvtData", "MFillTriggerLvl0");
108
109 tasks.AddToList(&filter);
110 tasks.AddToList(&fill1);
111 tasks.AddToList(&fill2);
112 tasks.AddToList(&fill3);
113
114 MOnlineDump2 dump;
115 dump.SetFilter(&filter);
116 tasks.AddToList(&dump);
117
118 MImgCleanStd clean;
119 MHillasCalc hcalc;
120 MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
121 MFillH hfill3("MHHillas", "MHillas", "MFillHillas");
122 MFillH hfill4("MHHillasSrc","MHillasSrc", "MFillHillasSrc");
123 tasks.AddToList(&clean);
124 tasks.AddToList(&hcalc);
125 tasks.AddToList(&scalc);
126 tasks.AddToList(&hfill3);
127 tasks.AddToList(&hfill4);
128
129 MEvtLoop magic;
130 magic.SetParList(&plist);
131
132 magic.SetDisplay(display);
133 magic.SetProgressBar((TGProgressBar*)NULL);
134
135 if (!magic.Eventloop())
136 {
137 gLog << err << "Mona Eventloop error..." << endl;
138 return kFALSE;
139 }
140
141 tasks.PrintStatistics();
142 return kTRUE;
143}
144
145//
146// By defining the function return type 'void' instead of
147// 'void*' we tell TThread to create a detached thread,
148// but calling Exit() in a detached thread results in a crash
149// when the TGApplication is terminated.
150//
151void *thread(void *ptr)
152{
153 MStatusDisplay d;
154 d.Resize(740, 600);
155
156 //
157 // If a loop is stopped reinitialize a new loop until the
158 // user requested to exit the program.
159 //
160 while (d.CheckStatus()!=MStatusDisplay::kFileExit)
161 Loop(&d);
162
163 gLog << dbg << "Exit System Loop... " << flush;
164 gSystem->ExitLoop();
165 gLog << "done." << endl;
166
167 TThread::Self()->Exit();
168 return 0;
169}
170
171/*
172#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
173#include <TRootGuiFactory.h>
174#include <TPluginManager.h>
175void InitGuiFactory()
176{
177 if (gROOT->IsBatch())
178 gROOT->SetBatch(kFALSE);
179
180 //
181 // Must be loaded by hand, because it is not loaded by TGApplication.
182 // We could also use TApplication instead, but TApplication doesn't
183 // deal with the DISPLAY variable in a convient way.
184 //
185 TPluginHandler *h;
186 if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", "root")))
187 {
188 if (h->LoadPlugin() == -1)
189 return;
190 gGuiFactory = (TGuiFactory*)h->ExecPlugin(0);
191 }
192}
193#endif
194*/
195
196int main(int argc, char **argv)
197{
198 StartUpMessage();
199
200 TApplication app("Mars", &argc, argv);
201 if (gROOT->IsBatch() || !gClient)
202 {
203 gLog << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
204 return 1;
205 }
206 /*
207 TGApplication app("Mona", &argc, argv);
208
209#if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
210 InitGuiFactory();
211#endif
212 */
213
214 ChangeContextMenus();
215
216 //
217 // Starting MStatusDisplay in the thread results in hangs
218 // if the thread is terminated (by return)
219 //
220 gLog << dbg << "Starting Thread..." << endl;
221 TThread t(thread);
222 t.Run();
223
224 gLog << dbg << "Starting System loop... " << endl;
225 app.Run(kTRUE);
226 gLog << dbg << "System loop stopped." << endl;
227
228 return 0;
229}
Note: See TracBrowser for help on using the repository browser.