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

Last change on this file since 744 was 730, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 11.6 KB
Line 
1#include "MGFadcDisp.h"
2
3#include <stdlib.h>
4#include <iostream.h>
5
6#include <TGButton.h> // TGPictureButton
7#include <TGLabel.h> // TGLabel
8#include <TGSplitter.h> // TGHorizontal3DLine
9#include <TGTab.h> // TGTab
10#include <TGListBox.h> // TGListBox
11#include <TGSlider.h> // TGVSlider
12#include <TRootEmbeddedCanvas.h> // TRootEmbeddedCanvas
13#include <TCanvas.h>
14#include <TGTextEntry.h>
15#include <TGMsgBox.h>
16
17
18#include "MParList.h"
19#include "MRawRunHeader.h"
20#include "MRawEvtHeader.h"
21#include "MTime.h"
22#include "MRawEvtData.h"
23#include "MRawCrateArray.h"
24#include "MReadTree.h"
25#include "MRawEvtPixelIter.h"
26
27ClassImp(MGFadcDisp)
28
29
30MGFadcDisp::MGFadcDisp(char *filename, char *treename,
31 const TGWindow *p, const TGWindow *main,
32 UInt_t w, UInt_t h )
33 : TGTransientFrame(p, main, w, h )
34{
35 // default constructor
36
37 // first connect the file with this Object
38
39 pList = new MParList();
40
41 fRunHeader = new MRawRunHeader();
42 pList->AddToList(fRunHeader);
43
44 fEvtHeader = new MRawEvtHeader();
45 pList->AddToList(fEvtHeader);
46 fEvtTime = new MTime();
47 pList->AddToList(fEvtTime);
48 fEvtData = new MRawEvtData();
49 pList->AddToList(fEvtData);
50 fEvtCrate = new MRawCrateArray();
51 pList->AddToList(fEvtCrate);
52
53
54 fReadTree = new MReadTree ( treename, filename ) ;
55 fReadTree->PreProcess( pList ) ;
56
57 //
58 // the top part of the window
59 //
60 fFrameTop = new TGVerticalFrame (this, 300, 100 ) ;
61
62 fTop1 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
63
64 fLabelFile = new TGLabel(fTop1, new TGString("File:") );
65 fTop1->AddFrame( fLabelFile, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10)) ;
66
67 fNameFile = new TGLabel(fTop1, new TGString( filename ) );
68 fTop1->AddFrame( fNameFile, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10)) ;
69
70 fLabelTree = new TGLabel(fTop1, new TGString("Tree:") );
71 fTop1->AddFrame( fLabelTree, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10)) ;
72
73 fNameTree = new TGLabel(fTop1, new TGString( treename ) );
74 fTop1->AddFrame( fNameTree, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10)) ;
75
76 fFrameTop->AddFrame(fTop1,new TGLayoutHints (kLHintsTop ) ) ;
77
78 fTop2 = new TGHorizontalFrame (fFrameTop, 300, 100 ) ;
79
80 fButtonPrevEvt = new TGTextButton (fTop2, "<< Previous Event", M_PREVEVT ) ;
81 fButtonPrevEvt->Associate(this) ;
82 fTop2->AddFrame (fButtonPrevEvt, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10 ) ) ;
83
84 fLabelEvtNr = new TGLabel(fTop2, new TGString("Event: ") );
85 fTop2->AddFrame( fLabelEvtNr, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10)) ;
86
87 fTxtEvtNr = new TGTextEntry(fTop2, fTxtBufEvtNr = new TGTextBuffer(100), M_EVTNUMBER);
88 fTxtEvtNr->Resize(60, fTxtEvtNr->GetDefaultHeight());
89 fTxtEvtNr->Associate(this) ;
90 fTop2->AddFrame(fTxtEvtNr, new TGLayoutHints(kLHintsTop | kLHintsLeft,
91 5, 5, 5, 5));
92
93 char wortdummy[100] ;
94 sprintf (wortdummy, "out of %d Events", fReadTree->GetEntries() ) ;
95 fLabelTotNr = new TGLabel(fTop2, new TGString( wortdummy ) );
96 fTop2->AddFrame( fLabelTotNr, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10)) ;
97
98 fButtonNextEvt = new TGTextButton (fTop2, "Next Event >>", M_NEXTEVT ) ;
99 fButtonNextEvt->Associate(this) ;
100 fTop2->AddFrame (fButtonNextEvt, new TGLayoutHints (kLHintsLeft, 10, 10, 10, 10 ) ) ;
101
102
103 fFrameTop->AddFrame(fTop2,new TGLayoutHints ( kLHintsCenterX ) ) ;
104
105
106
107 AddFrame(fFrameTop, new TGLayoutHints (kLHintsTop | kLHintsCenterX ) ) ;
108
109 // a line between top and mid frame
110
111 fLineSep1 = new TGHorizontal3DLine(this) ;
112 AddFrame(fLineSep1, new TGLayoutHints(kLHintsTop | kLHintsExpandX) );
113
114 //
115 // the middle part of the window
116 //
117
118 fFrameMid = new TGHorizontalFrame (this, 300, 100 ) ;
119
120 // the left part is the control tab enviroment
121
122 fTabControl = new TGTab(fFrameMid, 300, 300);
123 TGCompositeFrame *tControl = fTabControl->AddTab("PixelList");
124 tControl->ChangeOptions ( kHorizontalFrame ) ;
125
126
127 fPixelList = new TGListBox(tControl, M_PIXELLIST ) ;
128 fPixelList->Associate(this) ;
129 tControl->AddFrame(fPixelList, new TGLayoutHints(kLHintsExpandY | kLHintsLeft, 5, 5, 5, 5 ) ) ;
130 fPixelList->Resize(80, 230 ) ;
131
132 fMid1 = new TGVerticalFrame (tControl, 300, 100 ) ;
133
134
135 fButtonPrevPix = new TGTextButton (fMid1, "<< Prev Pixel", 9999 ) ;
136 fMid1->AddFrame(fButtonPrevPix, new TGLayoutHints(kLHintsRight) ) ;
137
138 fPixSlider = new TGVSlider (fMid1, 200, kSlider1 | kScaleBoth, 9999 );
139 fPixSlider->Associate(this);
140 fPixSlider->SetRange(0, 576);
141 fMid1->AddFrame(fPixSlider, new TGLayoutHints(kLHintsCenterX | kLHintsExpandY));
142
143 fButtonNextPix = new TGTextButton (fMid1, "Next Pixel >>", 9999 ) ;
144 fMid1->AddFrame(fButtonNextPix, new TGLayoutHints(kLHintsRight) ) ;
145
146 tControl->AddFrame(fMid1, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 5, 5, 5, 5)) ;
147
148 fFrameMid-> AddFrame(fTabControl, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 10, 10, 10 ,10 ) );
149
150 // the right part is the display tab enviroment
151
152 fTabDisplay = new TGTab(fFrameMid, 300, 300);
153 TGCompositeFrame *tDisplay = fTabDisplay->AddTab("Digital Scope");
154
155 fECanDigScope = new TRootEmbeddedCanvas("fECanDigScope", tDisplay, 400, 400 ) ;
156 tDisplay->AddFrame( fECanDigScope, new TGLayoutHints ( kLHintsCenterX | kLHintsCenterY | kLHintsExpandX | kLHintsExpandY ) ) ;
157
158 fCan = fECanDigScope->GetCanvas() ;
159
160
161 fFrameMid-> AddFrame(fTabDisplay, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY | kLHintsExpandX , 10, 10, 10 ,10 ) );
162
163
164 AddFrame(fFrameMid, new TGLayoutHints (kLHintsExpandY | kLHintsExpandX ) ) ;
165
166 // a line between mid and low frame
167
168 fLineSep2 = new TGHorizontal3DLine(this) ;
169 AddFrame(fLineSep2, new TGLayoutHints(kLHintsTop | kLHintsExpandX) );
170
171 // the low part of the window
172 //
173 fFrameLow = new TGHorizontalFrame (this, 300, 100 ) ;
174
175
176 fButtonPrint = new TGTextButton(fFrameLow, "Print", M_PRINT) ;
177 fButtonPrint->Associate(this) ;
178 fFrameLow->AddFrame( fButtonPrint, new TGLayoutHints(kLHintsLeft , 10, 10, 10, 10 ) ) ;
179
180 fButtonClose = new TGTextButton(fFrameLow, "Close", M_CLOSE) ;
181 fButtonClose->Associate(this) ;
182 fFrameLow->AddFrame( fButtonClose, new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10 ) ) ;
183
184
185 AddFrame(fFrameLow, new TGLayoutHints (kLHintsTop ) ) ;
186
187 //
188 // Map the window, set up the layout, etc.
189 //
190 SetWMSizeHints(450, 400, 1000, 1000, 10, 10 ) ; // set the smallest and biggest size of the Main frame
191
192 MapSubwindows();
193
194 Layout();
195
196 SetWindowName("FadcDisplay");
197 SetIconName("FadcDisp");
198
199 MapWindow();
200
201 //
202 // fReadTree the first event and update the window
203 //
204 fReadTree->GetEvent() ;
205 CreatePixelList() ;
206 UpdateEventCounter() ;
207
208}
209
210
211MGFadcDisp::~MGFadcDisp()
212{
213 // close the file
214
215 fReadTree->PostProcess() ;
216
217 delete fRunHeader ;
218 delete fEvtHeader ;
219 delete fEvtTime ;
220 delete fEvtData ;
221 delete fEvtCrate ;
222
223 delete pList ;
224
225 delete fReadTree ;
226
227 // destruct the graphical members
228
229 delete fButtonPrint ;
230 delete fButtonClose ;
231
232 // delete fCan ;
233 delete fECanDigScope ;
234 delete fTabDisplay ;
235
236 delete fPixSlider ;
237 delete fButtonPrevPix ;
238 delete fButtonNextPix ;
239 delete fMid1 ;
240 delete fPixelList;
241 delete fTabControl ;
242
243 delete fLabelEvtNr ;
244 delete fLabelTotNr ;
245 //delete fTxtBufEvtNr ;
246 delete fTxtEvtNr ;
247 delete fButtonNextEvt ;
248 delete fButtonPrevEvt ;
249 delete fLabelTree ;
250 delete fNameTree ;
251 delete fNameFile ;
252 delete fLabelFile ;
253 delete fTop2 ;
254 delete fTop1 ;
255
256 delete fFrameLow ;
257 delete fLineSep2 ;
258 delete fFrameMid ;
259 delete fLineSep1 ;
260 delete fFrameTop ;
261}
262
263
264void MGFadcDisp::CloseWindow()
265{
266 // Got close message for this MainFrame. Calls parent CloseWindow()
267 // (which destroys the window) and terminate the application.
268 // The close message is generated by the window manager when its close
269 // window menu item is selected.
270
271 delete this ;
272}
273
274
275void MGFadcDisp::CreatePixelList(Int_t lastsel)
276{
277 //
278 // after a new event is read in one has to update
279 // the list of pixels in the fPixelList (TGListBox)
280 //
281
282 //
283 // put the selection of the last event in memory
284 //
285 MRawEvtPixelIter pixel(fEvtData);
286 while (pixel.Next())
287 {
288 char wortdummy[100] ;
289 sprintf(wortdummy, "%d", pixel.GetPixelId());
290 fPixelList->AddEntry(wortdummy, pixel.GetPixelId());
291 }
292
293 fPixelList->MapSubwindows();
294 fPixelList->Layout();
295
296 //
297 // check if the pixel from last event also occurs in this event
298 //
299 fCan->Clear() ;
300 fCan->cd() ;
301
302 if (lastsel<0 || !pixel.Jump(lastsel))
303 {
304 pixel.Reset();
305 lastsel=pixel.GetPixelId();
306
307 }
308
309 char wortdummy[100] ;
310 sprintf(wortdummy, "GRAPH%d", lastsel);
311 fEvtData->Draw(wortdummy);
312 fPixelList->Select(lastsel, kTRUE);
313
314 fCan->Modified();
315 fCan->Update();
316}
317
318void MGFadcDisp::UpdateEventCounter()
319{
320 // Update the event counter
321
322 char wortdummy[256] ;
323
324 sprintf (wortdummy, "%d", fReadTree->GetEventNum() ) ;
325
326 fTxtEvtNr->SetText(wortdummy) ;
327}
328
329void MGFadcDisp::ReadinEvent(UInt_t iEvt)
330{
331 Int_t buttons = 4;
332 Int_t retval = 0 ;
333
334 // first check if the new event is in the range of possible events
335
336 if ( iEvt >= fReadTree->GetEntries() )
337 {
338 new TGMsgBox(fClient->GetRoot(), this,
339 "WARNING!",
340 "The event number is out of range!!!",
341 kMBIconExclamation, buttons, &retval);
342 }
343 else
344 {
345 const Int_t lastsel = fPixelList->GetSelected();
346
347 fPixelList->RemoveEntries(0, fEvtData->GetNumPixels());
348
349 fReadTree->SetEventNum(iEvt);
350 fReadTree->GetEvent();
351
352 CreatePixelList(lastsel);
353 }
354
355 UpdateEventCounter();
356}
357
358Bool_t MGFadcDisp::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
359{
360 //------------------------------------------------------------------
361 //
362 // ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
363 //
364 // Processes information from all GUI items.
365 // Selecting an item usually generates an event with 4 parameters.
366 // The first two are packed into msg (first and second bytes).
367 // The other two are parm1 and parm2.
368 //
369 //------------------------------------------------------------------
370 char wortdummy[256] ;
371 Int_t buttons = 4, retval = 0 ;
372
373 switch(GET_MSG(msg))
374 {
375 case kC_COMMAND:
376
377 switch(GET_SUBMSG(msg))
378 {
379
380 case kCM_BUTTON:
381
382 switch (parm1)
383 {
384 case M_PREVEVT:
385 ReadinEvent(fReadTree->GetEventNum()-1 ) ;
386 break;
387
388 case M_NEXTEVT:
389 ReadinEvent(fReadTree->GetEventNum()+1 ) ;
390 break;
391
392
393 case M_PRINT:
394 new TGMsgBox(fClient->GetRoot(), this,
395 "INFORMATION!",
396 "Your are invited to program that!!",
397 kMBIconExclamation, buttons, &retval);
398
399 break ;
400
401 case M_CLOSE:
402 CloseWindow() ;
403 break;
404
405 }
406
407 case kCM_LISTBOX:
408 switch (parm1)
409 {
410 case M_PIXELLIST:
411 sprintf(wortdummy, "GRAPH%d", fPixelList->GetSelected());
412
413 fCan->Clear() ;
414 fCan->cd() ;
415
416 fEvtData->Draw(wortdummy) ;
417
418 fCan->Modified() ;
419 fCan->Update() ;
420 break;
421 }
422 break;
423
424 }
425
426 case kC_TEXTENTRY:
427
428 switch(GET_SUBMSG(msg))
429 {
430 case kTE_TEXTCHANGED:
431 break ;
432
433 case kTE_ENTER:
434 {
435 const char *txt = fTxtEvtNr->GetText();
436 ReadinEvent(atoi(txt));
437 }
438 break;
439 }
440 break;
441
442 default:
443 break;
444 }
445
446 return kTRUE ;
447}
Note: See TracBrowser for help on using the repository browser.