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

Last change on this file since 618 was 609, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 11.8 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 runheader = new MRawRunHeader();
42 plist->AddToList(runheader);
43
44 evtheader = new MRawEvtHeader();
45 plist->AddToList(evtheader);
46 evttime = new MTime();
47 plist->AddToList(evttime);
48 evtdata = new MRawEvtData();
49 plist->AddToList(evtdata);
50 evtcrate = new MRawCrateArray();
51 plist->AddToList(evtcrate);
52
53
54 readin = new MReadTree ( filename, treename ) ;
55 readin->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", readin->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
189 //
190 // Map the window, set up the layout, etc.
191 //
192
193 SetWMSizeHints(450, 400, 1000, 1000, 10, 10 ) ; // set the smallest and biggest size of the Main frame
194
195 MapSubwindows();
196
197 Layout();
198
199 SetWindowName("FadcDisplay");
200 SetIconName("FadcDisp");
201
202 MapWindow();
203
204 //
205 // readin the first event and update the window
206 //
207
208 readin->GetEvent() ;
209 CreatePixelList() ;
210 UpdateEventCounter() ;
211
212}
213
214
215MGFadcDisp::~MGFadcDisp()
216{
217 // close the file
218
219 readin->PostProcess() ;
220
221 delete runheader ;
222 delete evtheader ;
223 delete evttime ;
224 delete evtdata ;
225 delete evtcrate ;
226
227 delete plist ;
228
229 delete readin ;
230
231 // destruct the graphical members
232
233 delete fButtonPrint ;
234 delete fButtonClose ;
235
236 // delete fCan ;
237 delete fECanDigScope ;
238 delete fTabDisplay ;
239
240 delete fPixSlider ;
241 delete fButtonPrevPix ;
242 delete fButtonNextPix ;
243 delete fMid1 ;
244 delete fPixelList;
245 delete fTabControl ;
246
247 delete fLabelEvtNr ;
248 delete fLabelTotNr ;
249 //delete fTxtBufEvtNr ;
250 delete fTxtEvtNr ;
251 delete fButtonNextEvt ;
252 delete fButtonPrevEvt ;
253 delete fLabelTree ;
254 delete fNameTree ;
255 delete fNameFile ;
256 delete fLabelFile ;
257 delete fTop2 ;
258 delete fTop1 ;
259
260 delete fFrameLow ;
261 delete fLineSep2 ;
262 delete fFrameMid ;
263 delete fLineSep1 ;
264 delete fFrameTop ;
265}
266
267
268void MGFadcDisp::CloseWindow()
269{
270 // Got close message for this MainFrame. Calls parent CloseWindow()
271 // (which destroys the window) and terminate the application.
272 // The close message is generated by the window manager when its close
273 // window menu item is selected.
274
275 delete this ;
276}
277
278
279void MGFadcDisp::CreatePixelList() {
280 //
281 // after a new event is read in one has to update
282 // the list of pixels in the fPixelList (TGListBox)
283 //
284
285 Int_t redraw ;
286
287 MRawEvtPixelIter fPixelIter( evtdata );
288 char wortdummy[100] ;
289
290 // put the selection of the last event in memory
291 redraw = fPixelList->GetSelected() ;
292
293 fPixelList->RemoveEntries(0, fPixelsinList) ;
294 fPixelsinList = 0 ;
295
296 while ( fPixelIter.Next() )
297 {
298 // cout << fPixelIter.GetPixelId() << endl ;
299 sprintf( wortdummy, "%d", fPixelIter.GetPixelId() ) ;
300
301 fPixelList->AddEntry( wortdummy, fPixelsinList++ ) ;
302 }
303
304 fPixelList->MapSubwindows() ;
305 fPixelList->Layout() ;
306
307 // check if the pixel from last event also occurs in this event
308
309 Bool_t neuzeich = kFALSE ;
310 fPixelIter.Reset() ;
311
312 while ( fPixelIter.Next() )
313 {
314 if (fPixelIter.GetPixelId() == redraw )
315 neuzeich = kTRUE ;
316 }
317
318 if ( neuzeich == kTRUE )
319 {
320 sprintf(wortdummy, "GRAPH%d", redraw ) ;
321
322 fCan->Clear() ;
323 fCan->cd() ;
324
325 evtdata->Draw(wortdummy) ;
326
327 fCan->Modified() ;
328 fCan->Update() ;
329
330 fPixelList->Select(redraw, kTRUE) ;
331 }
332 else
333 {
334 fCan->Clear() ;
335 fCan->cd() ;
336 fCan->Modified() ;
337 fCan->Update() ;
338
339 }
340
341
342}
343
344void MGFadcDisp::UpdateEventCounter()
345{
346 // Update the event counter
347
348 char wortdummy[256] ;
349
350 sprintf (wortdummy, "%d", readin->GetEventNum() ) ;
351
352 fTxtEvtNr->SetText(wortdummy) ;
353
354
355
356}
357
358void MGFadcDisp::ReadinEvent(Int_t iEvt)
359{
360 Int_t buttons = 4, retval = 0 ;
361
362 // first check if the new event is in the range of possible events
363
364 if ( (iEvt < 0) || (iEvt>= readin->GetEntries()) ) {
365 new TGMsgBox(fClient->GetRoot(), this,
366 "WARNING!",
367 "The event number is out of range!!!",
368 kMBIconExclamation, buttons, &retval);
369 UpdateEventCounter() ;
370 return ;
371 }
372 else {
373 readin->SetEventNum(iEvt) ;
374 readin->GetEvent() ;
375 CreatePixelList() ;
376 UpdateEventCounter() ;
377 }
378}
379
380
381
382
383Bool_t MGFadcDisp::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
384{
385 //------------------------------------------------------------------
386 //
387 // ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
388 //
389 // Processes information from all GUI items.
390 // Selecting an item usually generates an event with 4 parameters.
391 // The first two are packed into msg (first and second bytes).
392 // The other two are parm1 and parm2.
393 //
394 //------------------------------------------------------------------
395 char wortdummy[256] ;
396 Int_t buttons = 4, retval = 0 ;
397
398 switch(GET_MSG(msg))
399 {
400 case kC_COMMAND:
401
402 switch(GET_SUBMSG(msg))
403 {
404
405 case kCM_BUTTON:
406
407 switch (parm1)
408 {
409 case M_PREVEVT:
410
411 ReadinEvent(readin->GetEventNum()-1 ) ;
412
413 break;
414
415 case M_NEXTEVT:
416
417 ReadinEvent(readin->GetEventNum()+1 ) ;
418
419 break;
420
421
422 case M_PRINT:
423 new TGMsgBox(fClient->GetRoot(), this,
424 "INFORMATION!",
425 "Your are invited to program that!!",
426 kMBIconExclamation, buttons, &retval);
427
428 break ;
429 case M_CLOSE:
430
431 CloseWindow() ;
432 break;
433
434 }
435
436 case kCM_LISTBOX:
437 switch (parm1)
438 {
439 case M_PIXELLIST:
440 sprintf(wortdummy, "GRAPH%d",fPixelList->GetSelected() ) ;
441
442 fCan->Clear() ;
443 fCan->cd() ;
444
445 evtdata->Draw(wortdummy) ;
446
447 fCan->Modified() ;
448 fCan->Update() ;
449
450
451 break;
452 }
453 break;
454
455 }
456
457 case kC_TEXTENTRY:
458
459 switch(GET_SUBMSG(msg))
460 {
461 case kTE_TEXTCHANGED:
462
463 break ;
464 case kTE_ENTER:
465
466 sprintf(wortdummy, "%s", fTxtEvtNr->GetText()) ;
467 cout << wortdummy<< endl ;
468
469 cout << atoi(wortdummy) << endl ;
470
471
472 ReadinEvent( atoi(wortdummy) ) ;
473
474 break;
475 }
476
477 break;
478
479 default:
480 break;
481 }
482
483 return kTRUE ;
484}
Note: See TracBrowser for help on using the repository browser.