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

Last change on this file since 2371 was 2173, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.0 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-2001
21!
22!
23\* ======================================================================== */
24
25#include "MGFadcDisp.h"
26
27#include <limits.h> // INT_MAX
28#include <stdlib.h> // atoi
29#include <iostream> // 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 "MTaskList.h"
47#include "MReadTree.h"
48#include "MEvtLoop.h"
49#include "MRawEvtData.h"
50#include "MRawEvtPixelIter.h"
51
52ClassImp(MGFadcDisp);
53
54using namespace std;
55
56enum MGFadcDispCommand
57{
58 M_PREVPIXEL = 0x1000,
59 M_NEXTPIXEL = 0x1001,
60
61 M_PIXELLIST = 0x1002
62};
63
64// --------------------------------------------------------------------------
65//
66// Add the missing GUI elements: These are the pixel number controls
67//
68void MGFadcDisp::AddSetupElements()
69{
70 fTab1->ChangeOptions(kHorizontalFrame);
71
72 //
73 // Create first gui element for tab1
74 //
75 fPixelList = new TGListBox(fTab1, M_PIXELLIST);
76 fPixelList->Associate(this);
77 fPixelList->Resize(80, 230);
78
79 TGLayoutHints *layplist = new TGLayoutHints(kLHintsExpandY|kLHintsLeft, 5, 5, 5, 5);
80 fTab1->AddFrame(fPixelList, layplist);
81
82 TGVerticalFrame *midframe = new TGVerticalFrame(fTab1, 300, 100);
83 fList->Add(midframe);
84
85 TGLayoutHints *laytab = new TGLayoutHints(kLHintsRight|kLHintsExpandY, 5, 5, 5, 5);
86 fList->Add(laytab);
87
88 fTab1->AddFrame(midframe, laytab);
89
90 //
91 // Create gui elements for vertical frame
92 //
93 TGTextButton *prevpix = new TGTextButton(midframe, "<< Prev Pixel", M_PREVPIXEL);
94 TGTextButton *nextpix = new TGTextButton(midframe, "Next Pixel >>", M_NEXTPIXEL);
95 prevpix->Associate(this);
96 nextpix->Associate(this);
97
98 TGVSlider *slider = new TGVSlider(midframe, 200, kSlider1|kScaleBoth);
99 slider->Associate(this);
100 slider->SetRange(0, 576);
101
102 //
103 // Layout gui elements
104 //
105 TGLayoutHints *laybut = new TGLayoutHints(kLHintsRight);
106 TGLayoutHints *layslider = new TGLayoutHints(kLHintsCenterX|kLHintsExpandY);
107
108 midframe->AddFrame(prevpix, laybut);
109 midframe->AddFrame(slider, layslider);
110 midframe->AddFrame(nextpix, laybut);
111}
112
113// --------------------------------------------------------------------------
114//
115// Constructor
116//
117MGFadcDisp::MGFadcDisp(const char *filename, const char *treename,
118 const TGWindow *p, /*const TGWindow *main,*/
119 UInt_t w, UInt_t h)
120 : MGEvtDisplay(filename, treename, p, /*main,*/ w, h)
121{
122 //
123 // Add the missing GUI elements (pixellist, pixel number controls)
124 //
125 AddSetupElements();
126
127 //
128 // preprocess eventloop and read in first event (process)
129 //
130 GetReader()->DisableAutoScheme();
131 ReadFirstEvent();
132
133 //
134 // Map the window, set up the layout, etc.
135 //
136 MapSubwindows();
137
138 Layout();
139
140 SetWindowName("Fadc Event Display");
141 SetIconName("Fadc");
142
143 MapWindow();
144
145}
146
147// --------------------------------------------------------------------------
148//
149// return pointer to event data
150//
151MRawEvtData *MGFadcDisp::GetEvent() const
152{
153 return (MRawEvtData*)GetParList()->FindObject("MRawEvtData");
154}
155
156// --------------------------------------------------------------------------
157//
158// after a new event is read in one has to update
159// the list of pixels in the fPixelList (TGListBox)
160//
161void MGFadcDisp::DisplayPixel(Int_t lastsel, Bool_t update)
162{
163 MRawEvtData *data = GetEvent();
164
165 if (!data)
166 return;
167
168 MRawEvtPixelIter pixel(data);
169
170 if (update)
171 {
172 //
173 // put the selection of the last event in memory
174 //
175 while (pixel.Next())
176 {
177 TString txt;
178 txt += pixel.GetPixelId();
179 fPixelList->AddEntrySort(txt, pixel.GetPixelId());
180 }
181
182 fPixelList->MapSubwindows();
183 fPixelList->Layout();
184 }
185
186 //
187 // check if the pixel from last event also occurs in this event
188 //
189 fCanvas->Clear();
190 fCanvas->cd();
191
192 if (lastsel<0 || !pixel.Jump(lastsel))
193 {
194 pixel.Reset();
195 lastsel=0; //pixel.GetPixelId();
196 }
197
198 TString txt("GRAPH");
199 txt += lastsel;
200
201 data->Draw(txt);
202
203 fPixelList->Select(lastsel, kTRUE);
204 fPixelList->SetTopEntry(lastsel);
205
206 fCanvas->Modified();
207 fCanvas->Update();
208}
209
210// --------------------------------------------------------------------------
211//
212// Update the contents of the canvas
213//
214void MGFadcDisp::UpdateDisplay()
215{
216 if (!IsInitOk())
217 return;
218
219 const Int_t lastsel = fPixelList->GetSelected();
220
221 fPixelList->RemoveEntries(0, INT_MAX);
222
223 DisplayPixel(lastsel);
224}
225
226// --------------------------------------------------------------------------
227//
228// ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
229//
230// Processes information from all GUI items.
231// Selecting an item usually generates an event with 4 parameters.
232// The first two are packed into msg (first and second bytes).
233// The other two are parm1 and parm2.
234//
235Bool_t MGFadcDisp::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
236{
237 switch(GET_MSG(msg))
238 {
239 case kC_COMMAND:
240 switch(GET_SUBMSG(msg))
241 {
242 case kCM_BUTTON:
243 switch (parm1)
244 {
245 case M_PREVPIXEL:
246 DisplayPixel(fPixelList->GetSelected()-1, kFALSE);
247 return kTRUE;
248
249 case M_NEXTPIXEL:
250 DisplayPixel(fPixelList->GetSelected()+1, kFALSE);
251 return kTRUE;
252 }
253 break;
254
255 case kCM_LISTBOX:
256 if (parm1 != M_PIXELLIST)
257 break;
258
259 DisplayPixel(fPixelList->GetSelected(), kFALSE);
260 return kTRUE;
261 }
262 break;
263 }
264
265 return MGEvtDisplay::ProcessMessage(msg, parm1, parm2);
266}
Note: See TracBrowser for help on using the repository browser.