source: trunk/MagicSoft/Mars/meventdisp/MGFadcDisp.cc@ 957

Last change on this file since 957 was 956, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 14.7 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
19! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26#include "MGFadcDisp.h"
27
28#include <stdlib.h> // atoi
29#include <iostream.h> // cout for debugging
30
31#include <TList.h> // TList
32#include <TCanvas.h> // TCanvas
33#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
34
35#include <TGTab.h> // TGTab
36#include <TGLabel.h> // TGLabel
37#include <TGButton.h> // TGPictureButton
38#include <TGSlider.h> // TGVSlider
39#include <TGMsgBox.h> // TGMsgBox
40#include <TGListBox.h> // TGListBox
41#include <TGTextEntry.h> // TGTextEntry
42
43#include <TG3DLine.h> // TGHorizontal3DLine
44 // use TGSplitter instead for root<3.00
45#include "MParList.h"
46#include "MReadTree.h"
47#include "MRawEvtData.h"
48#include "MRawEvtPixelIter.h"
49
50ClassImp(MGFadcDisp);
51
52enum MGFadcDispCommand
53{
54 M_PIXELLIST = 4201,
55 M_PREVEVT,
56 M_NEXTEVT,
57 M_EVTNUMBER,
58
59 M_PREVPIXEL,
60 M_NEXTPIXEL,
61
62 M_PRINT,
63 M_CLOSE
64};
65
66void MGFadcDisp::AddTopFramePart1(TGVerticalFrame *frame,
67 const char *filename,
68 const char *treename)
69{
70 //
71 // --- the top1 part of the window ---
72 //
73 TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 300, 100);
74 fList->Add(top1);
75
76 //
77 // create gui elements
78 //
79 TGLabel *lfile = new TGLabel(top1, new TGString("File:"));
80 TGLabel *file = new TGLabel(top1, new TGString(filename));
81 TGLabel *ltree = new TGLabel(top1, new TGString("Tree:"));
82 TGLabel *tree = new TGLabel(top1, new TGString(treename));
83
84 fList->Add(lfile);
85 fList->Add(file);
86 fList->Add(ltree);
87 fList->Add(tree);
88
89 //
90 // layout and add gui elements in/to frame
91 //
92 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
93 fList->Add(laystd);
94
95 top1->AddFrame(lfile, laystd);
96 top1->AddFrame(file, laystd);
97 top1->AddFrame(ltree, laystd);
98 top1->AddFrame(tree, laystd);
99
100 //
101 // layout and add frame
102 //
103 TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsTop);
104 fList->Add(laytop1);
105
106 frame->AddFrame(top1, laytop1);
107}
108
109void MGFadcDisp::AddTopFramePart2(TGVerticalFrame *frame)
110{
111 //
112 // --- the top2 part of the window ---
113 //
114 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 300, 100);
115 fList->Add(top2);
116
117 //
118 // Create the gui elements
119 //
120 TGTextButton *prevevt = new TGTextButton(top2, "<< Previous Event", M_PREVEVT);
121 prevevt->Associate(this);
122
123 TGLabel *evtnr = new TGLabel(top2, new TGString("Event: "));
124
125 fTxtEvtNr = new TGTextEntry(top2, new TGTextBuffer(100), M_EVTNUMBER);
126 fTxtEvtNr->Resize(60, fTxtEvtNr->GetDefaultHeight());
127 fTxtEvtNr->Associate(this);
128
129 char wortdummy[100];
130 sprintf(wortdummy, "out of %d Events", fReadTree->GetEntries());
131 TGLabel *totnr = new TGLabel(top2, new TGString(wortdummy));
132
133 TGTextButton *nextevt = new TGTextButton (top2, "Next Event >>", M_NEXTEVT);
134 nextevt->Associate(this);
135
136 //
137 // Add gui elements to 'atotodel'
138 //
139 fList->Add(prevevt);
140 fList->Add(evtnr);
141 fList->Add(fTxtEvtNr);
142 fList->Add(totnr);
143 fList->Add(nextevt);
144
145 //
146 // add the gui elements to the frame
147 //
148 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
149 TGLayoutHints *laytentry = new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5);
150
151 fList->Add(laystd);
152 fList->Add(laytentry);
153
154 top2->AddFrame(prevevt, laystd);
155 top2->AddFrame(evtnr, laystd);
156 top2->AddFrame(fTxtEvtNr, laytentry);
157 top2->AddFrame(totnr, laystd);
158 top2->AddFrame(nextevt, laystd);
159
160 frame->AddFrame(top2, new TGLayoutHints(kLHintsCenterX));
161}
162
163void MGFadcDisp::AddMidFrame(TGHorizontalFrame *frame)
164{
165 //
166 // create tab control
167 //
168 TGTab *tabs = new TGTab(frame, 300, 300);
169
170 //
171 // Create Tab1
172 //
173 TGCompositeFrame *tab1 = tabs->AddTab("PixelList");
174 tab1->ChangeOptions(kHorizontalFrame);
175
176 //
177 // Create first gui element for tab1
178 //
179 fPixelList = new TGListBox(tab1, M_PIXELLIST);
180 fPixelList->Associate(this);
181 fPixelList->Resize(80, 230);
182
183 TGLayoutHints *layplist = new TGLayoutHints(kLHintsExpandY|kLHintsLeft, 5, 5, 5, 5);
184 tab1->AddFrame(fPixelList, layplist);
185
186 //
187 // Crete second gui elemet for tab1 (TGVertical Frame)
188 //
189 TGVerticalFrame *mid1 = new TGVerticalFrame(tab1, 300, 100);
190
191 //
192 // Create gui elements for vertical frame
193 //
194 TGTextButton *prevpix = new TGTextButton(mid1, "<< Prev Pixel", M_PREVPIXEL);
195 TGTextButton *nextpix = new TGTextButton(mid1, "Next Pixel >>", M_NEXTPIXEL);
196 prevpix->Associate(this);
197 nextpix->Associate(this);
198
199 TGVSlider *slider = new TGVSlider(mid1, 200, kSlider1|kScaleBoth);
200 slider->Associate(this);
201 slider->SetRange(0, 576);
202
203 //
204 // Layout gui elements
205 //
206 TGLayoutHints *laybut = new TGLayoutHints(kLHintsRight);
207 TGLayoutHints *layslider = new TGLayoutHints(kLHintsCenterX|kLHintsExpandY);
208
209 mid1->AddFrame(prevpix, laybut);
210 mid1->AddFrame(slider, layslider);
211 mid1->AddFrame(nextpix, laybut);
212
213 TGLayoutHints *laytab = new TGLayoutHints(kLHintsRight|kLHintsExpandY, 5, 5, 5, 5);
214 tab1->AddFrame(mid1, laytab);
215
216 TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandY, 10, 10, 10, 10);
217 frame->AddFrame(tabs, laytabs);
218
219 //
220 // Create second part of frame
221 //
222 TGTab *tabdisp = new TGTab(frame, 300, 300);
223
224 TGCompositeFrame *tab2 = tabdisp->AddTab("Digital Scope");
225
226 TRootEmbeddedCanvas *canvas = new TRootEmbeddedCanvas("Digi Scope", tab2, 400, 400);
227
228 TGLayoutHints *laycanvas = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
229 tab2->AddFrame(canvas, laycanvas);
230
231 fCanvas = canvas->GetCanvas();
232
233 //
234 // Add second part to frame
235 //
236 TGLayoutHints *laydisp = new TGLayoutHints(kLHintsNormal|kLHintsExpandY|kLHintsExpandX, 10, 10, 10, 10);
237 frame->AddFrame(tabdisp, laydisp);
238
239 //
240 // Now add all gui elements to 'autodel'-list
241 //
242 fList->Add(tabdisp);
243 fList->Add(canvas);
244 fList->Add(laycanvas);
245 fList->Add(laydisp);
246 fList->Add(fPixelList);
247 fList->Add(layplist);
248 fList->Add(mid1);
249 fList->Add(prevpix);
250 fList->Add(laybut);
251 fList->Add(slider);
252 fList->Add(layslider);
253 fList->Add(nextpix);
254 fList->Add(laytab);
255 fList->Add(laytabs);
256
257}
258
259void MGFadcDisp::AddLowFrame(TGHorizontalFrame *frame)
260{
261 TGTextButton *but1 = new TGTextButton(frame, "Print", M_PRINT);
262 TGTextButton *but2 = new TGTextButton(frame, "Close", M_CLOSE);
263
264 but1->Associate(this);
265 but2->Associate(this);
266
267 fList->Add(but1);
268 fList->Add(but2);
269
270 TGLayoutHints *laybut = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
271 fList->Add(laybut);
272
273 frame->AddFrame(but1, laybut);
274 frame->AddFrame(but2, laybut);
275}
276
277void MGFadcDisp::CreateGui(const char *filename, const char *treename)
278{
279 //
280 // Create the frame elements and add gui elements to it
281 //
282 TGVerticalFrame *frametop = new TGVerticalFrame(this, 300, 100);
283 AddTopFramePart1(frametop, filename, treename);
284 AddTopFramePart2(frametop);
285
286 TGHorizontal3DLine *line1 = new TGHorizontal3DLine(this);
287
288 TGHorizontalFrame *framemid = new TGHorizontalFrame(this, 300, 100);
289 AddMidFrame(framemid);
290
291 TGHorizontal3DLine *line2 = new TGHorizontal3DLine(this);
292
293 TGHorizontalFrame *framelow = new TGHorizontalFrame(this, 300, 100);
294 AddLowFrame(framelow);
295
296 //
297 // add frame elements to 'autodel'
298 //
299 fList->Add(frametop);
300 fList->Add(line1);
301 fList->Add(framemid);
302 fList->Add(line2);
303 fList->Add(framelow);
304
305 //
306 // Layout frame elements and add elements to frame
307 //
308 TGLayoutHints *laytop = new TGLayoutHints(kLHintsTop|kLHintsCenterX);
309 TGLayoutHints *layline = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
310 TGLayoutHints *laymid = new TGLayoutHints(kLHintsExpandY|kLHintsExpandX);
311 TGLayoutHints *laylow = new TGLayoutHints(kLHintsTop);
312
313 fList->Add(laytop);
314 fList->Add(layline);
315 fList->Add(laymid);
316 fList->Add(laylow);
317
318 AddFrame(frametop, laytop);
319 AddFrame(line1, layline);
320 AddFrame(framemid, laymid);
321 AddFrame(line2, layline);
322 AddFrame(framelow, laylow);
323}
324
325void MGFadcDisp::SetupFileAccess(const char *filename, const char *treename)
326{
327 //
328 // Create the file access elements
329 //
330 fEvtData = new MRawEvtData();
331
332 pList = new MParList();
333 pList->AddToList(fEvtData);
334
335 fReadTree = new MReadTree(treename, filename);
336 fReadTree->PreProcess(pList);
337 fReadTree->GetEvent();
338}
339
340MGFadcDisp::MGFadcDisp(char *filename, char *treename,
341 const TGWindow *p, const TGWindow *main,
342 UInt_t w, UInt_t h)
343 : TGTransientFrame(p, main, w, h)
344{
345
346 //
347 // create an autodelete-list for the gui elements
348 //
349 fList = new TList;
350 fList->SetOwner();
351
352 SetupFileAccess(filename, treename);
353 CreateGui(filename, treename);
354
355 //
356 // Map the window, set up the layout, etc.
357 //
358 SetWMSizeHints(450, 400, 1000, 1000, 10, 10 ); // set the smallest and biggest size of the Main frame
359
360 MapSubwindows();
361
362 Layout();
363
364 SetWindowName("FadcDisplay");
365 SetIconName("FadcDisp");
366
367 MapWindow();
368
369 CreatePixelList();
370 UpdateEventCounter();
371}
372
373
374MGFadcDisp::~MGFadcDisp()
375{
376 //
377 // close the file
378 //
379 fReadTree->PostProcess();
380
381 delete fEvtData;
382 delete pList;
383
384 delete fReadTree;
385
386 //
387 // destruct the graphical members
388 //
389 delete fList;
390}
391
392
393void MGFadcDisp::CloseWindow()
394{
395 // Got close message for this MainFrame. Calls parent CloseWindow()
396 // (which destroys the window) and terminate the application.
397 // The close message is generated by the window manager when its close
398 // window menu item is selected.
399
400 delete this;
401}
402
403
404void MGFadcDisp::CreatePixelList(Int_t lastsel)
405{
406 //
407 // after a new event is read in one has to update
408 // the list of pixels in the fPixelList (TGListBox)
409 //
410
411 //
412 // put the selection of the last event in memory
413 //
414 MRawEvtPixelIter pixel(fEvtData);
415 while (pixel.Next())
416 {
417 char wortdummy[100];
418 sprintf(wortdummy, "%d", pixel.GetPixelId());
419 fPixelList->AddEntry(wortdummy, pixel.GetPixelId());
420 }
421
422 fPixelList->MapSubwindows();
423 fPixelList->Layout();
424
425 //
426 // check if the pixel from last event also occurs in this event
427 //
428 fCanvas->Clear();
429 fCanvas->cd();
430
431 if (lastsel<0 || !pixel.Jump(lastsel))
432 {
433 pixel.Reset();
434 lastsel=pixel.GetPixelId();
435
436 }
437
438 char wortdummy[100];
439 sprintf(wortdummy, "GRAPH%d", lastsel);
440 fEvtData->Draw(wortdummy);
441 fPixelList->Select(lastsel, kTRUE);
442
443 fCanvas->Modified();
444 fCanvas->Update();
445}
446
447void MGFadcDisp::UpdateEventCounter()
448{
449 // Update the event counter
450
451 char wortdummy[256];
452
453 sprintf(wortdummy, "%d", fReadTree->GetEventNum());
454
455 fTxtEvtNr->SetText(wortdummy);
456}
457
458void MGFadcDisp::ReadinEvent(UInt_t iEvt)
459{
460 Int_t buttons = 4;
461 Int_t retval = 0;
462
463 // first check if the new event is in the range of possible events
464
465 if (iEvt >= fReadTree->GetEntries())
466 {
467 new TGMsgBox(fClient->GetRoot(), this,
468 "WARNING!",
469 "The event number is out of range!!!",
470 kMBIconExclamation, buttons, &retval);
471 }
472 else
473 {
474 const Int_t lastsel = fPixelList->GetSelected();
475
476 fPixelList->RemoveEntries(0, fEvtData->GetNumPixels());
477
478 fReadTree->SetEventNum(iEvt);
479 fReadTree->GetEvent();
480
481 CreatePixelList(lastsel);
482 }
483
484 UpdateEventCounter();
485}
486
487void MGFadcDisp::DisplayPix(UInt_t i)
488{
489 char wortdummy[256];
490
491 sprintf(wortdummy, "GRAPH%d", i);
492
493 fCanvas->Clear();
494 fCanvas->cd();
495
496 fEvtData->Draw(wortdummy);
497
498 fCanvas->Modified();
499 fCanvas->Update();
500
501 //
502 // FIXME: too complicated!
503 //
504 fPixelList->RemoveEntries(0, fEvtData->GetNumPixels());
505 CreatePixelList(i);
506}
507
508Bool_t MGFadcDisp::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
509{
510 //------------------------------------------------------------------
511 //
512 // ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
513 //
514 // Processes information from all GUI items.
515 // Selecting an item usually generates an event with 4 parameters.
516 // The first two are packed into msg (first and second bytes).
517 // The other two are parm1 and parm2.
518 //
519 //------------------------------------------------------------------
520
521 switch(GET_MSG(msg))
522 {
523 case kC_COMMAND:
524 switch(GET_SUBMSG(msg))
525 {
526 case kCM_BUTTON:
527 switch (parm1)
528 {
529 case M_PREVEVT:
530 ReadinEvent(fReadTree->GetEventNum()-1);
531 return kTRUE;
532
533 case M_NEXTEVT:
534 ReadinEvent(fReadTree->GetEventNum()+1);
535 return kTRUE;
536
537 case M_PREVPIXEL:
538 DisplayPix(fPixelList->GetSelected()-1);
539 return kTRUE;
540
541 case M_NEXTPIXEL:
542 DisplayPix(fPixelList->GetSelected()+1);
543 return kTRUE;
544
545 case M_PRINT:
546 cout << "Sorry, not yet implemented!" << endl;
547 return kTRUE;
548
549 case M_CLOSE:
550 CloseWindow();
551 return kTRUE;
552 }
553 return kTRUE;
554
555 case kCM_LISTBOX:
556 if (parm1 != M_PIXELLIST)
557 return kTRUE;
558
559 DisplayPix(fPixelList->GetSelected());
560 return kTRUE;
561 }
562 return kTRUE;
563
564 case kC_TEXTENTRY:
565 if (GET_SUBMSG(msg) == kTE_ENTER)
566 ReadinEvent(atoi(fTxtEvtNr->GetText()));
567
568 return kTRUE;
569 }
570
571 return kTRUE;
572}
Note: See TracBrowser for help on using the repository browser.