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

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