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 "MHTriggerLvl0.h"
|
---|
18 | #include "MHCamera.h" // ::Class()
|
---|
19 |
|
---|
20 | #include "MStatusDisplay.h"
|
---|
21 |
|
---|
22 | #include "MImgCleanStd.h"
|
---|
23 | #include "MHillasCalc.h"
|
---|
24 | #include "MHillasSrcCalc.h"
|
---|
25 |
|
---|
26 | #include "MArgs.h"
|
---|
27 |
|
---|
28 | // --------------------------------------------------------------------
|
---|
29 |
|
---|
30 | #include "MTime.h"
|
---|
31 | #include "MRawEvtHeader.h" // MRawEvtHeader
|
---|
32 | #include "MRawRunHeader.h" // MRawRunHeader
|
---|
33 |
|
---|
34 | class MOnlineDump : public MTask
|
---|
35 | {
|
---|
36 | private:
|
---|
37 | MFillH *fFill1;
|
---|
38 | MFillH *fFill2;
|
---|
39 | MFillH *fFill3;
|
---|
40 | MFRealTimePeriod *fFilter;
|
---|
41 |
|
---|
42 | UInt_t fRunNumber;
|
---|
43 | UInt_t fEvtNumber;
|
---|
44 |
|
---|
45 | MRawEvtHeader *fRawEvtHeader;
|
---|
46 | MRawRunHeader *fRawRunHeader;
|
---|
47 |
|
---|
48 | MTime *fEvtTime;
|
---|
49 | Double_t fTime;
|
---|
50 |
|
---|
51 | void SetNoContextMenu(TObject *c)
|
---|
52 | {
|
---|
53 | if (fDisplay->HasCanvas((TCanvas*)c))
|
---|
54 | c->ResetBit(kNoContextMenu);
|
---|
55 | }
|
---|
56 | void DisplayTriggerRate()
|
---|
57 | {
|
---|
58 | if (*fEvtTime==0)
|
---|
59 | fEvtTime->SetTime(gSystem->Now());
|
---|
60 |
|
---|
61 | if (fEvtNumber==0 || fRawRunHeader->GetRunNumber()!=fRunNumber)
|
---|
62 | {
|
---|
63 | fEvtNumber = fRawEvtHeader->GetDAQEvtNumber();
|
---|
64 | fRunNumber = fRawRunHeader->GetRunNumber();
|
---|
65 | fTime = *fEvtTime;
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | const UInt_t evts = fRawEvtHeader->GetDAQEvtNumber() - fEvtNumber;
|
---|
70 | const Double_t sec = *fEvtTime-fTime;
|
---|
71 |
|
---|
72 | if (evts>0 && sec>0 && fDisplay)
|
---|
73 | fDisplay->SetStatusLine2(Form("Trigger Rate: %.1fHz", evts/sec));
|
---|
74 | }
|
---|
75 |
|
---|
76 | public:
|
---|
77 | MOnlineDump() { fName = "MOnlineDump"; }
|
---|
78 | Int_t PreProcess(MParList *pList)
|
---|
79 | {
|
---|
80 | if (gROOT->IsBatch())
|
---|
81 | {
|
---|
82 | *fLog << err << "We are in batch mode!" << endl;
|
---|
83 | return kFALSE;
|
---|
84 | }
|
---|
85 | if (!fDisplay)
|
---|
86 | {
|
---|
87 | *fLog << err << "fDisplay not set." << endl;
|
---|
88 | return kFALSE;
|
---|
89 | }
|
---|
90 |
|
---|
91 | MTaskList *tasks = (MTaskList*)pList->FindObject("MTaskList");
|
---|
92 | if (!tasks)
|
---|
93 | {
|
---|
94 | *fLog << err << "MTaskList not found... abort." << endl;
|
---|
95 | return kFALSE;
|
---|
96 | }
|
---|
97 |
|
---|
98 | fFill1 = (MFillH*)tasks->FindObject("MFillCamEvent");
|
---|
99 | if (!fFill1)
|
---|
100 | {
|
---|
101 | *fLog << err << "MFillCamEvent not found... abort." << endl;
|
---|
102 | return kFALSE;
|
---|
103 | }
|
---|
104 | fFill2 = (MFillH*)tasks->FindObject("MFillEvent");
|
---|
105 | if (!fFill2)
|
---|
106 | {
|
---|
107 | *fLog << err << "MFillEvent not found... abort." << endl;
|
---|
108 | return kFALSE;
|
---|
109 | }
|
---|
110 | fFill3 = (MFillH*)tasks->FindObject("MFillTriggerLvl0");
|
---|
111 | if (!fFill3)
|
---|
112 | {
|
---|
113 | *fLog << err << "MFillTriggerLvl0 not found... abort." << endl;
|
---|
114 | return kFALSE;
|
---|
115 | }
|
---|
116 | fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
|
---|
117 | if (!fRawEvtHeader)
|
---|
118 | {
|
---|
119 | *fLog << err << "MRawEvtHeader not found... abort." << endl;
|
---|
120 | return kFALSE;
|
---|
121 | }
|
---|
122 |
|
---|
123 | fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
124 | if (!fRawRunHeader)
|
---|
125 | {
|
---|
126 | *fLog << err << "MRawRunHeader not found... abort." << endl;
|
---|
127 | return kFALSE;;
|
---|
128 | }
|
---|
129 |
|
---|
130 | fEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
|
---|
131 | if (!fEvtTime)
|
---|
132 | {
|
---|
133 | *fLog << err << "MRawEvtTime not found... abort." << endl;
|
---|
134 | return kFALSE;
|
---|
135 | }
|
---|
136 |
|
---|
137 | fRunNumber = 0xffffffff;
|
---|
138 | fEvtNumber = 0;
|
---|
139 |
|
---|
140 | SetNoContextMenu((TObject*)fFill1->GetCanvas());
|
---|
141 | SetNoContextMenu((TObject*)fFill2->GetCanvas());
|
---|
142 | SetNoContextMenu((TObject*)fFill3->GetCanvas());
|
---|
143 |
|
---|
144 | return kTRUE;
|
---|
145 | }
|
---|
146 | Int_t Process()
|
---|
147 | {
|
---|
148 | DisplayTriggerRate();
|
---|
149 |
|
---|
150 | if (fDisplay)
|
---|
151 | fDisplay->SetProgressBarPosition((Float_t)fEvtNumber/fRawRunHeader->GetNumEvents());
|
---|
152 |
|
---|
153 | return kTRUE;
|
---|
154 | }
|
---|
155 | Int_t PostProcess()
|
---|
156 | {
|
---|
157 | if (fDisplay)
|
---|
158 | fDisplay->SetProgressBarPosition(1);
|
---|
159 |
|
---|
160 | return kTRUE;
|
---|
161 | }
|
---|
162 | // ClassDef(MOnlineDump, 0) // Task to fill a histogram with data from a parameter container
|
---|
163 | };
|
---|
164 | //ClassImp(MOnlineDump);
|
---|
165 | // --------------------------------------------------------------------
|
---|
166 |
|
---|
167 | void StartUpMessage()
|
---|
168 | {
|
---|
169 | gLog << all << endl;
|
---|
170 |
|
---|
171 | // 1 2 3 4 5
|
---|
172 | // 12345678901234567890123456789012345678901234567890
|
---|
173 | gLog << "==================================================" << endl;
|
---|
174 | gLog << " MONA V" << MARSVER << " " << endl;
|
---|
175 | gLog << " Magic Online Analysis " << endl;
|
---|
176 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
---|
177 | gLog << " Using ROOT v" << ROOTVER << endl;
|
---|
178 | gLog << "==================================================" << endl;
|
---|
179 | gLog << endl;
|
---|
180 | }
|
---|
181 |
|
---|
182 | void Remove(TMethod *m, const char *name)
|
---|
183 | {
|
---|
184 | if (TString(m->GetName()).BeginsWith(name))
|
---|
185 | m->SetMenuItem(kMenuNoMenu);
|
---|
186 | }
|
---|
187 |
|
---|
188 | void ChangeContextMenus()
|
---|
189 | {
|
---|
190 | TList l;
|
---|
191 | MHCamera::Class()->GetMenuItems(&l);
|
---|
192 | TIter Next(&l);
|
---|
193 | TMethod *m=NULL;
|
---|
194 | while ((m=(TMethod*)Next()))
|
---|
195 | {
|
---|
196 | Remove(m, "DrawClone");
|
---|
197 | Remove(m, "SetName");
|
---|
198 | Remove(m, "Delete");
|
---|
199 | Remove(m, "DrawClass");
|
---|
200 | Remove(m, "Dump");
|
---|
201 | Remove(m, "Inspect");
|
---|
202 | Remove(m, "Smooth");
|
---|
203 | Remove(m, "Fit");
|
---|
204 | Remove(m, "Divide");
|
---|
205 | Remove(m, "Add");
|
---|
206 | Remove(m, "Multiply");
|
---|
207 | Remove(m, "Delete");
|
---|
208 | Remove(m, "SetLineAttributes");
|
---|
209 | Remove(m, "SetFillAttributes");
|
---|
210 | Remove(m, "SetMarkerAttributes");
|
---|
211 | Remove(m, "SetDrawOption");
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | Bool_t Loop(MStatusDisplay *display, Int_t port)
|
---|
216 | {
|
---|
217 | //
|
---|
218 | // create the tasks which should be executed and add them to the list
|
---|
219 | // in the case you don't need parameter containers, all of them can
|
---|
220 | // be created by MRawFileRead::PreProcess
|
---|
221 | //
|
---|
222 | MRawSocketRead reader;
|
---|
223 | reader.SetPort(port);
|
---|
224 |
|
---|
225 | //
|
---|
226 | // create a (empty) list of parameters which can be used by the tasks
|
---|
227 | // and an (empty) list of tasks which should be executed
|
---|
228 | //
|
---|
229 | MParList plist;
|
---|
230 |
|
---|
231 | MTaskList tasks;
|
---|
232 | plist.AddToList(&tasks);
|
---|
233 | tasks.AddToList(&reader);
|
---|
234 |
|
---|
235 | MGeomApply geomapl;
|
---|
236 | MCerPhotAnal2 ncalc;
|
---|
237 | tasks.AddToList(&geomapl);
|
---|
238 | tasks.AddToList(&ncalc);
|
---|
239 |
|
---|
240 | MFillH fill1("MHEvent", "MCerPhotEvt", "MFillEvent");
|
---|
241 | MFillH fill2("MHCamEvent", "MCerPhotEvt", "MFillCamEvent");
|
---|
242 |
|
---|
243 | MFRealTimePeriod filter;
|
---|
244 | fill1.SetFilter(&filter);
|
---|
245 |
|
---|
246 | MHTriggerLvl0 trigmap(128, "Above 128");
|
---|
247 | MFillH fill3(&trigmap, "MRawEvtData", "MFillTriggerLvl0");
|
---|
248 |
|
---|
249 | tasks.AddToList(&filter);
|
---|
250 | tasks.AddToList(&fill1);
|
---|
251 | tasks.AddToList(&fill2);
|
---|
252 | tasks.AddToList(&fill3);
|
---|
253 |
|
---|
254 | MOnlineDump dump;
|
---|
255 | dump.SetFilter(&filter);
|
---|
256 | tasks.AddToList(&dump);
|
---|
257 |
|
---|
258 | MImgCleanStd clean;
|
---|
259 | MHillasCalc hcalc;
|
---|
260 | MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
|
---|
261 | MFillH hfill3("MHHillas", "MHillas", "MFillHillas");
|
---|
262 | MFillH hfill4("MHHillasSrc","MHillasSrc", "MFillHillasSrc");
|
---|
263 | tasks.AddToList(&clean);
|
---|
264 | tasks.AddToList(&hcalc);
|
---|
265 | tasks.AddToList(&scalc);
|
---|
266 | tasks.AddToList(&hfill3);
|
---|
267 | tasks.AddToList(&hfill4);
|
---|
268 |
|
---|
269 | MEvtLoop magic;
|
---|
270 | magic.SetParList(&plist);
|
---|
271 |
|
---|
272 | magic.SetDisplay(display);
|
---|
273 | magic.SetProgressBar((TGProgressBar*)NULL);
|
---|
274 |
|
---|
275 | if (!magic.Eventloop())
|
---|
276 | {
|
---|
277 | gLog << err << "Mona Eventloop error..." << endl;
|
---|
278 | return kFALSE;
|
---|
279 | }
|
---|
280 |
|
---|
281 | tasks.PrintStatistics();
|
---|
282 | return kTRUE;
|
---|
283 | }
|
---|
284 |
|
---|
285 | //
|
---|
286 | // By defining the function return type 'void' instead of
|
---|
287 | // 'void*' we tell TThread to create a detached thread,
|
---|
288 | // but calling Exit() in a detached thread results in a crash
|
---|
289 | // when the TGApplication is terminated.
|
---|
290 | //
|
---|
291 | void *thread(void *ptr)
|
---|
292 | {
|
---|
293 | const Int_t port = *(Int_t*)ptr;
|
---|
294 |
|
---|
295 | MStatusDisplay d;
|
---|
296 | d.Resize(740, 600);
|
---|
297 |
|
---|
298 | //
|
---|
299 | // If a loop is stopped reinitialize a new loop until the
|
---|
300 | // user requested to exit the program.
|
---|
301 | //
|
---|
302 | while (d.CheckStatus()!=MStatusDisplay::kFileExit)
|
---|
303 | Loop(&d, port);
|
---|
304 |
|
---|
305 | gLog << dbg << "Exit System Loop... " << flush;
|
---|
306 | gSystem->ExitLoop();
|
---|
307 | gLog << "done." << endl;
|
---|
308 |
|
---|
309 | TThread::Self()->Exit();
|
---|
310 | return 0;
|
---|
311 | }
|
---|
312 |
|
---|
313 | /*
|
---|
314 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
|
---|
315 | #include <TRootGuiFactory.h>
|
---|
316 | #include <TPluginManager.h>
|
---|
317 | void InitGuiFactory()
|
---|
318 | {
|
---|
319 | if (gROOT->IsBatch())
|
---|
320 | gROOT->SetBatch(kFALSE);
|
---|
321 |
|
---|
322 | //
|
---|
323 | // Must be loaded by hand, because it is not loaded by TGApplication.
|
---|
324 | // We could also use TApplication instead, but TApplication doesn't
|
---|
325 | // deal with the DISPLAY variable in a convient way.
|
---|
326 | //
|
---|
327 | TPluginHandler *h;
|
---|
328 | if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", "root")))
|
---|
329 | {
|
---|
330 | if (h->LoadPlugin() == -1)
|
---|
331 | return;
|
---|
332 | gGuiFactory = (TGuiFactory*)h->ExecPlugin(0);
|
---|
333 | }
|
---|
334 | }
|
---|
335 | #endif
|
---|
336 | */
|
---|
337 |
|
---|
338 | static void Usage()
|
---|
339 | {
|
---|
340 | gLog << all << endl;
|
---|
341 | gLog << "Sorry the usage is:" << endl;
|
---|
342 | gLog << " mona [-?] [-h] [-a0] [-h] [-pn] [-vn]" << endl << endl;
|
---|
343 | gLog << " -a0: Do not use Ansii codes." << endl;
|
---|
344 | gLog << " -pn: TCP/IP port n [default=7000]" << endl;
|
---|
345 | gLog << " -vn: Verbosity level n [default=2]" << endl << endl;
|
---|
346 | gLog << " -?/-h: This help" << endl << endl;
|
---|
347 | }
|
---|
348 |
|
---|
349 |
|
---|
350 | int main(int argc, char **argv)
|
---|
351 | {
|
---|
352 | StartUpMessage();
|
---|
353 |
|
---|
354 | //
|
---|
355 | // Evaluate arguments
|
---|
356 | //
|
---|
357 | MArgs arg(argc, (const char**)argv);
|
---|
358 |
|
---|
359 | if (arg.HasOption("-?") || arg.HasOption("-h"))
|
---|
360 | {
|
---|
361 | Usage();
|
---|
362 | return -1;
|
---|
363 | }
|
---|
364 |
|
---|
365 | //
|
---|
366 | // Set verbosity to highest level.
|
---|
367 | //
|
---|
368 | gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
|
---|
369 |
|
---|
370 | if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
|
---|
371 | gLog.SetNoColors();
|
---|
372 |
|
---|
373 | const Int_t port = arg.HasOption("-p") ? arg.GetIntAndRemove("-p") : 7000;
|
---|
374 |
|
---|
375 | //
|
---|
376 | // check for the right usage of the program
|
---|
377 | //
|
---|
378 | if (arg.GetNumArguments()>0)
|
---|
379 | {
|
---|
380 | Usage();
|
---|
381 | return -1;
|
---|
382 | }
|
---|
383 |
|
---|
384 | TApplication app("Mars", &argc, argv);
|
---|
385 | if (gROOT->IsBatch() || !gClient)
|
---|
386 | {
|
---|
387 | gLog << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
|
---|
388 | return 1;
|
---|
389 | }
|
---|
390 |
|
---|
391 | /*
|
---|
392 | TGApplication app("Mona", &argc, argv);
|
---|
393 |
|
---|
394 | #if ROOT_VERSION_CODE < ROOT_VERSION(3,10,02)
|
---|
395 | InitGuiFactory();
|
---|
396 | #endif
|
---|
397 | */
|
---|
398 |
|
---|
399 | ChangeContextMenus();
|
---|
400 |
|
---|
401 | //
|
---|
402 | // Starting MStatusDisplay in the thread results in hangs
|
---|
403 | // if the thread is terminated (by return)
|
---|
404 | //
|
---|
405 | gLog << dbg << "Starting Thread..." << endl;
|
---|
406 | TThread t(thread, (void*)&port);
|
---|
407 | t.Run();
|
---|
408 |
|
---|
409 | gLog << dbg << "Starting System loop... " << endl;
|
---|
410 | app.Run(kTRUE);
|
---|
411 | gLog << dbg << "System loop stopped." << endl;
|
---|
412 |
|
---|
413 | return 0;
|
---|
414 | }
|
---|