source: trunk/MagicSoft/Mars/meventdisp/MGEvtDisplay.cc@ 1988

Last change on this file since 1988 was 1966, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 18.4 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): Thomas Bretz 10/2001 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25#include "MGEvtDisplay.h"
26
27#include <stdlib.h> // atoi
28
29#include <TGTab.h> // TGTab
30#include <TGMenu.h> // TGPopupMenu
31#include <TCanvas.h> // TCanvas::Print
32#include <TGLabel.h> // TGLabel
33#include <TGButton.h> // TGPictureButton
34#include <TGMsgBox.h> // TGMsgBox
35#include <TGTextEntry.h> // TGTextEntry
36#include <TGFileDialog.h> // TGFileDialog
37#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
38
39#include <TG3DLine.h> // TGHorizontal3DLine
40 // use TGSplitter instead for root<3.00
41
42#include "MParList.h"
43#include "MTaskList.h"
44#include "MEvtLoop.h"
45#include "MCamDisplay.h"
46#include "MReadMarsFile.h"
47#include "MGeomCamMagic.h"
48#include "MRawEvtHeader.h"
49
50#include "MMcEvt.hxx"
51
52ClassImp(MGEvtDisplay);
53
54enum MGCamDisplayCommand
55{
56 kEvtPrev,
57 kEvtNext,
58 kEvtNumber,
59
60 kFileSaveAs,
61 kFileSaveAsRoot,
62 kFileSaveAsC,
63 kFileSaveAsPS,
64 kFileSaveAsEPS,
65 kFileSaveAsGIF,
66 kFilePrint,
67 kClose
68};
69
70// --------------------------------------------------------------------------
71//
72// Return a pointer to the parameter list.
73//
74MParList *MGEvtDisplay::GetParList() const
75{
76 return fEvtLoop->GetParList();
77}
78
79// --------------------------------------------------------------------------
80//
81// Return a pointer to the task list.
82//
83MTaskList *MGEvtDisplay::GetTaskList() const
84{
85 return (MTaskList*)GetParList()->FindObject("MTaskList");
86}
87
88// --------------------------------------------------------------------------
89//
90// Return a pointer to the reader task (MReadTree)
91//
92MReadTree *MGEvtDisplay::GetReader() const
93{
94 return (MReadTree*)GetTaskList()->FindObject("MRead");
95}
96
97// --------------------------------------------------------------------------
98//
99// Add the top part of the frame: This is filename and treename display
100//
101void MGEvtDisplay::AddTopFramePart1(TGVerticalFrame *frame,
102 const char *filename,
103 const char *treename)
104{
105 //
106 // --- the top1 part of the window ---
107 //
108 TGHorizontalFrame *top1 = new TGHorizontalFrame(frame, 300, 100);
109 fList->Add(top1);
110
111 //
112 // create gui elements
113 //
114 TGLabel *lfile = new TGLabel(top1, new TGString("File:"));
115 TGLabel *file = new TGLabel(top1, new TGString(filename));
116 TGLabel *ltree = new TGLabel(top1, new TGString("Tree:"));
117 TGLabel *tree = new TGLabel(top1, new TGString(treename));
118
119 fList->Add(lfile);
120 fList->Add(file);
121 fList->Add(ltree);
122 fList->Add(tree);
123
124 //
125 // layout and add gui elements in/to frame
126 //
127 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
128 fList->Add(laystd);
129
130 top1->AddFrame(lfile, laystd);
131 top1->AddFrame(file, laystd);
132 top1->AddFrame(ltree, laystd);
133 top1->AddFrame(tree, laystd);
134
135 //
136 // --- the top1 part of the window ---
137 //
138 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 300, 100);
139 fList->Add(top2);
140
141 fEvtInfo = new TGLabel(top2, new TGString(""));
142 fList->Add(fEvtInfo);
143 top2->AddFrame(fEvtInfo, laystd);
144
145 //
146 // layout and add frames
147 //
148 TGLayoutHints *laytop1 = new TGLayoutHints(kLHintsTop);
149 fList->Add(laytop1);
150 frame->AddFrame(top1, laytop1);
151 frame->AddFrame(top2, laytop1);
152}
153
154// --------------------------------------------------------------------------
155//
156// Add the second part of the top frame: This are the event number controls
157//
158void MGEvtDisplay::AddTopFramePart2(TGVerticalFrame *frame)
159{
160 //
161 // --- the top2 part of the window ---
162 //
163 TGHorizontalFrame *top2 = new TGHorizontalFrame(frame, 300, 100);
164 fList->Add(top2);
165
166 //
167 // Create the gui elements
168 //
169 TGTextButton *prevevt = new TGTextButton(top2, "<< Previous Event", kEvtPrev);
170 prevevt->Associate(this);
171
172 TGLabel *evtnr = new TGLabel(top2, new TGString("Event: "));
173
174 fTxtEvtNr = new TGTextEntry(top2, new TGTextBuffer(100), kEvtNumber);
175 fTxtEvtNr->Resize(60, fTxtEvtNr->GetDefaultHeight());
176 fTxtEvtNr->Associate(this);
177
178 fNumOfEvts = new TGLabel(top2, "out of Events.");
179
180 TGTextButton *nextevt = new TGTextButton (top2, "Next Event >>", kEvtNext);
181 nextevt->Associate(this);
182
183 //
184 // Add gui elements to 'atotodel'
185 //
186 fList->Add(prevevt);
187 fList->Add(evtnr);
188 fList->Add(fTxtEvtNr);
189 fList->Add(fNumOfEvts);
190 fList->Add(nextevt);
191
192 //
193 // add the gui elements to the frame
194 //
195 TGLayoutHints *laystd = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 10, 10, 10, 10);
196
197 fList->Add(laystd);
198
199 top2->AddFrame(prevevt, laystd);
200 top2->AddFrame(evtnr, laystd);
201 top2->AddFrame(fTxtEvtNr, laystd);
202 top2->AddFrame(fNumOfEvts, laystd);
203 top2->AddFrame(nextevt, laystd);
204
205 frame->AddFrame(top2, new TGLayoutHints(kLHintsCenterX));
206}
207
208// --------------------------------------------------------------------------
209//
210// Add a tab with an embedded canvas for an camera display and return the
211// pointer to the canvas
212//
213TCanvas *MGEvtDisplay::AddTab(TString name)
214{
215 TGLayoutHints *laycanvas = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY|kLHintsExpandX|kLHintsExpandY);
216 fList->Add(laycanvas);
217
218 // Add new tab
219 TGCompositeFrame *f = fEvtDisplay->AddTab(name);
220
221 // create root embedded canvas and add it to the tab
222 TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name+"Display", f, f->GetWidth(), f->GetHeight());
223 f->AddFrame(ec, laycanvas);
224 fList->Add(ec);
225
226 // set background and border mode of the canvas
227 TCanvas &c = *ec->GetCanvas();
228 c.SetBorderMode(0);
229
230 // layout and map new tab
231#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,00)
232 MapSubwindows();
233 Layout();
234#else
235 Layout();
236 MapSubwindows();
237#endif
238
239 // display new tab in the main frame
240 gClient->ProcessEventsFor(fEvtDisplay);
241
242 // return pointer to new canvas
243 return &c;
244}
245
246// --------------------------------------------------------------------------
247//
248// Add the mid frame: This are the two tabs with the canvas in the right one
249//
250void MGEvtDisplay::AddMidFrame(TGHorizontalFrame *frame)
251{
252 //
253 // create tab control
254 //
255 TGTab *tabs = new TGTab(frame, 300, 300);
256
257 //
258 // Create Tab1
259 //
260 fTab1 = tabs->AddTab("Setup");
261
262 //
263 // Crete second gui elemet for tab1 (TGVertical Frame)
264 //
265 TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandY, 10, 10, 10, 10);
266 frame->AddFrame(tabs, laytabs);
267
268 //
269 // Create second part of frame
270 //
271 fEvtDisplay = new TGTab(frame, 300, 300);
272
273 fCanvas=AddTab("Photons");
274
275 AddTab("Geometry");
276 MGeomCamMagic geom;
277 MCamDisplay *display = new MCamDisplay(&geom);
278 display->Draw();
279 display->DrawPixelNumbers();
280 fList->Add(display);
281
282 //
283 // Add second part to frame
284 //
285 TGLayoutHints *laydisp = new TGLayoutHints(kLHintsNormal|kLHintsExpandY|kLHintsExpandX, 10, 10, 10, 10);
286 frame->AddFrame(fEvtDisplay, laydisp);
287
288 //
289 // Now add all gui elements to 'autodel'-list
290 //
291 fList->Add(fEvtDisplay);
292 fList->Add(laydisp);
293 fList->Add(laytabs);
294}
295
296// --------------------------------------------------------------------------
297//
298// Add the low frame: These are the buttons Print and Close
299//
300void MGEvtDisplay::AddLowFrame(TGHorizontalFrame *frame)
301{
302 TGTextButton *but = new TGTextButton(frame, "Close", kClose);
303
304 but->Associate(this);
305
306 fList->Add(but);
307
308 TGLayoutHints *laybut = new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10);
309 fList->Add(laybut);
310
311 frame->AddFrame(but, laybut);
312}
313
314// --------------------------------------------------------------------------
315//
316// Create and setup all the three frames and build the window interieur
317//
318void MGEvtDisplay::AddFrames(const char *filename, const char *treename)
319{
320 //
321 // Create the frame elements and add gui elements to it
322 //
323 TGVerticalFrame *frametop = new TGVerticalFrame(this, 300, 100);
324 fList->Add(frametop);
325
326 AddTopFramePart1(frametop, filename, treename);
327 AddTopFramePart2(frametop);
328
329 TGLayoutHints *laytop = new TGLayoutHints(kLHintsTop|kLHintsCenterX);
330 fList->Add(laytop);
331
332 // -----
333
334 TGHorizontalFrame *framemid = new TGHorizontalFrame(this, 300, 100);
335 fList->Add(framemid);
336
337 AddMidFrame(framemid);
338
339 TGLayoutHints *laymid = new TGLayoutHints(kLHintsExpandY|kLHintsExpandX);
340 fList->Add(laymid);
341
342 //
343 // add frame elements to 'autodel'
344 //
345 TGHorizontal3DLine *line1 = new TGHorizontal3DLine(this);
346 TGHorizontal3DLine *line2 = new TGHorizontal3DLine(this);
347 fList->Add(line1);
348 fList->Add(line2);
349
350 TGLayoutHints *layline = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
351 fList->Add(layline);
352
353 // -----
354 TGHorizontalFrame *framelow = new TGHorizontalFrame(this, 300, 100);
355 fList->Add(framelow);
356
357 AddLowFrame(framelow);
358
359 TGLayoutHints *laylow = new TGLayoutHints(kLHintsTop);
360 fList->Add(laylow);
361
362 //
363 // Layout frame elements and add elements to frame
364 //
365 AddFrame(frametop, laytop);
366 AddFrame(line1, layline);
367 AddFrame(framemid, laymid);
368 AddFrame(line2, layline);
369 AddFrame(framelow, laylow);
370}
371
372// --------------------------------------------------------------------------
373//
374// Constructor
375//
376void MGEvtDisplay::AddMenuBar()
377{
378 //
379 // Add all GUI elements and update the event counter
380 //
381 TGLayoutHints *laymenubar = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 2, 2, 2, 2);
382 TGLayoutHints *laymenuitem = new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0);
383 TGLayoutHints *laylinesep = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
384
385 fList->Add(laymenubar);
386 fList->Add(laymenuitem);
387 fList->Add(laylinesep);
388
389 TGPopupMenu *filemenu = new TGPopupMenu(gClient->GetRoot());
390 filemenu->AddEntry("Save &As...", kFileSaveAs);
391 filemenu->AddEntry("Save As display.p&s", kFileSaveAsPS);
392 filemenu->AddEntry("Save As display.&eps", kFileSaveAsEPS);
393 filemenu->AddEntry("Save As display.&gif", kFileSaveAsGIF);
394 filemenu->AddEntry("Save As display.&C", kFileSaveAsC);
395 filemenu->AddEntry("Save As display.&root", kFileSaveAsRoot);
396 filemenu->AddSeparator();
397 filemenu->AddEntry("&Print...", kFilePrint);
398 filemenu->AddSeparator();
399 filemenu->AddEntry("E&xit", kClose);
400 filemenu->Associate(this);
401
402 TGMenuBar *menubar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
403 menubar->AddPopup("&File", filemenu, laymenuitem);
404 AddFrame(menubar, laymenubar);
405
406 TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
407 AddFrame(linesep, laylinesep);
408
409 fList->Add(filemenu);
410 fList->Add(menubar);
411 fList->Add(linesep);
412}
413
414MGEvtDisplay::MGEvtDisplay(const char *fname, const char *tname,
415 const TGWindow *p, /*const TGWindow *main,*/
416 UInt_t w, UInt_t h)
417// : TGTransientFrame(p, main, w, h), fInitOk(kFALSE)
418: TGMainFrame(p, w, h), fInitOk(kFALSE)
419{
420 //
421 // create an autodelete-list for the gui elements
422 //
423 fList = new TList;
424 fList->SetOwner();
425
426 //
427 // Setup an empty job, with a reader task only.
428 // All tasks and parameter containers are deleted automatically
429 // (via SetOwner())
430 //
431 MTaskList *tlist = new MTaskList;
432 tlist->SetOwner();
433
434 MReadMarsFile *read = new MReadMarsFile(tname, fname);
435 read->DisableAutoScheme();
436 tlist->AddToList(read);
437
438 MParList *plist = new MParList;
439 plist->SetOwner();
440 plist->AddToList(tlist);
441
442 fEvtLoop = new MEvtLoop;
443 fEvtLoop->SetOwner();
444 fEvtLoop->SetParList(plist);
445
446 AddMenuBar();
447 AddFrames(fname, tname);
448
449 SetWMSizeHints(450, 400, 1000, 1000, 10, 10);
450 Move(rand()%100+50, rand()%100+50);
451}
452
453// --------------------------------------------------------------------------
454//
455// Destructs the graphical members and the eventloop members
456//
457MGEvtDisplay::~MGEvtDisplay()
458{
459 fEvtLoop->PostProcess();
460 delete fEvtLoop;
461
462 delete fList;
463}
464
465// --------------------------------------------------------------------------
466//
467// The close message is generated by the window manager when its close
468// window menu item is selected.
469//
470void MGEvtDisplay::CloseWindow()
471{
472 delete this;
473}
474
475void MGEvtDisplay::UpdateMcLabel()
476{
477 MMcEvt *evt=(MMcEvt*)GetParList()->FindObject("MMcEvt");
478 if (!evt)
479 return;
480
481 TString txt = " ";
482
483 switch (evt->GetPartId())
484 {
485 case kGAMMA:
486 txt += "Gamma";
487 break;
488 case kPROTON:
489 txt += "Proton";
490 break;
491 case kHELIUM:
492 txt += "Helium";
493 break;
494 default:
495 txt += "Unknown Particle Id#";
496 txt += evt->GetPartId();
497 }
498
499 txt += ": E=";
500 txt += (int)(evt->GetEnergy()+.5);
501 txt += "GeV r=";
502 txt += (int)(evt->GetImpact()/100+.5);
503 txt += "m ZA=";
504 txt += (int)(evt->GetTheta()*180/TMath::Pi()+.5);
505 txt += "° ";
506 txt += evt->GetPhotElfromShower();
507 txt += "PhEl";
508
509 const MRawEvtHeader *hed = (MRawEvtHeader*)GetParList()->FindObject("MRawEvtHeader");
510 if (hed)
511 {
512 txt += " DAQEvt #";
513 txt += hed->GetDAQEvtNumber();
514 }
515
516 fEvtInfo->SetText(txt);
517
518 //
519 // Seems to be necessary to newly layout the upper part to display
520 // the whole line of text
521 //
522 TGFrame &f = *(TGFrame*)fEvtInfo->GetParent()->GetParent();
523 f.Layout();
524 f.MapSubwindows();
525}
526
527// --------------------------------------------------------------------------
528//
529// Checks if the event number is valid, and if so reads the new event
530// and updates the display
531//
532void MGEvtDisplay::ReadinEvent()
533{
534 if (GetTaskList()->Process())
535 {
536 GetReader()->DecEventNum();
537 UpdateDisplay();
538 UpdateMcLabel();
539 }
540
541 fTxtEvtNr->SetText(Form("%d", GetReader()->GetNumEntry()+1));
542}
543
544void MGEvtDisplay::ReadFirstEvent()
545{
546 fInitOk = fEvtLoop->PreProcess();
547
548 if (fInitOk)
549 ReadinEvent();
550
551 TGString *txt = new TGString(Form("out of %d Events", GetReader()->GetEntries()));
552 fNumOfEvts->SetText(txt);
553}
554
555// --------------------------------------------------------------------------
556//
557// Opens a save as dialog, and tries to store the canvas
558// in the given output format
559//
560void MGEvtDisplay::SaveAsDialog() const
561{
562 static const char *gSaveAsTypes[] =
563 {
564 "PostScript", "*.ps",
565 "Encapsulated PostScript", "*.eps",
566 "Gif files", "*.gif",
567 "Macro files", "*.C",
568 "ROOT files", "*.root",
569 "All files", "*",
570 NULL, NULL
571 };
572
573 static TString dir(".");
574
575 TGFileInfo fi; // fFileName and fIniDir deleted in ~TGFileInfo
576
577 fi.fFileTypes = (const char**)gSaveAsTypes;
578 fi.fIniDir = StrDup(dir);
579
580 new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
581
582 if (!fi.fFilename)
583 return;
584
585 dir = fi.fIniDir;
586
587 if (strstr(fi.fFilename, ".root") ||
588 strstr(fi.fFilename, ".ps") ||
589 strstr(fi.fFilename, ".eps") ||
590 strstr(fi.fFilename, ".gif"))
591 {
592 fCanvas->SaveAs(fi.fFilename);
593 return;
594 }
595 if (strstr(fi.fFilename, ".C"))
596 {
597 fCanvas->SaveSource(fi.fFilename);
598 return;
599 }
600 Warning("SaveAsDialog", "Unknown Extension: %s", fi.fFilename);
601}
602
603// --------------------------------------------------------------------------
604//
605// ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
606//
607// Processes information from all GUI items.
608// Selecting an item usually generates an event with 4 parameters.
609// The first two are packed into msg (first and second bytes).
610// The other two are parm1 and parm2.
611//
612Bool_t MGEvtDisplay::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
613{
614 if (GET_MSG(msg)!=kC_TEXTENTRY && GET_MSG(msg)!=kC_COMMAND)
615 return kTRUE;
616
617 switch(GET_SUBMSG(msg))
618 {
619 case kTE_ENTER:
620 case kCM_BUTTON:
621 if (parm1==kClose)
622 {
623 CloseWindow();
624 return kTRUE;
625 }
626
627 if (!fInitOk)
628 return kTRUE;
629
630 switch(GET_SUBMSG(msg))
631 {
632 case kTE_ENTER:
633 if (GetReader()->SetEventNum(atoi(fTxtEvtNr->GetText())-1))
634 ReadinEvent();
635 return kTRUE;
636
637 case kCM_BUTTON:
638 switch (parm1)
639 {
640 case kEvtPrev:
641 if (GetReader()->DecEventNum())
642 ReadinEvent();
643 return kTRUE;
644
645 case kEvtNext:
646 if (GetReader()->IncEventNum())
647 ReadinEvent();
648 return kTRUE;
649 }
650 return kTRUE;
651 }
652 return kTRUE;
653
654 case kCM_MENU:
655 switch (parm1)
656 {
657 case kFileSaveAs:
658 SaveAsDialog();
659 return kTRUE;
660 case kFileSaveAsRoot:
661 fCanvas->SaveAs("display.root");
662 return kTRUE;
663 case kFileSaveAsC:
664 // FIXME: The line opening the canvas is wrong.
665 fCanvas->SaveSource("display.C");
666 return kTRUE;
667 case kFileSaveAsPS:
668 fCanvas->SaveAs("display.ps");
669 return kTRUE;
670 case kFileSaveAsEPS:
671 fCanvas->SaveAs("display.eps");
672 return kTRUE;
673 case kFileSaveAsGIF:
674 fCanvas->SaveAs("display.gif");
675 return kTRUE;
676 case kFilePrint:
677 fCanvas->Print();
678 return kTRUE;
679 case kClose:
680 CloseWindow();
681 return kTRUE;
682 }
683 return kTRUE;
684 }
685 return kTRUE;
686}
687
Note: See TracBrowser for help on using the repository browser.