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

Last change on this file since 691 was 663, 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 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 ( filename, treename ) ;
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() {
276 //
277 // after a new event is read in one has to update
278 // the list of pixels in the fPixelList (TGListBox)
279 //
280 const Int_t redraw = fPixelList->GetSelected() ;
281
282 MRawEvtPixelIter fPixelIter( fEvtData );
283
284 //
285 // put the selection of the last event in memory
286 //
287 fPixelList->RemoveEntries(0, fPixelIter.GetNumPixels()) ;
288
289 while ( fPixelIter.Next() )
290 {
291 char wortdummy[100] ;
292 // cout << fPixelIter.GetPixelId() << endl ;
293 sprintf( wortdummy, "%d", fPixelIter.GetPixelId() ) ;
294
295 fPixelList->AddEntry( wortdummy, fPixelIter.GetNumEntry()) ;
296 }
297
298 fPixelList->MapSubwindows() ;
299 fPixelList->Layout() ;
300
301 // check if the pixel from last event also occurs in this event
302
303 fPixelIter.Reset() ;
304
305 while ( fPixelIter.Next() )
306 {
307 if (fPixelIter.GetPixelId() != redraw )
308 continue;
309
310 fCan->Clear() ;
311 fCan->cd() ;
312
313 char wortdummy[100] ;
314 sprintf(wortdummy, "GRAPH%d", redraw ) ;
315 fEvtData->Draw(wortdummy) ;
316
317 fCan->Modified() ;
318 fCan->Update() ;
319
320 fPixelList->Select(redraw, kTRUE) ;
321 return;
322 }
323
324 fCan->Clear() ;
325 fCan->cd() ;
326 fCan->Modified() ;
327 fCan->Update() ;
328}
329
330void MGFadcDisp::UpdateEventCounter()
331{
332 // Update the event counter
333
334 char wortdummy[256] ;
335
336 sprintf (wortdummy, "%d", fReadTree->GetEventNum() ) ;
337
338 fTxtEvtNr->SetText(wortdummy) ;
339}
340
341void MGFadcDisp::ReadinEvent(Int_t iEvt)
342{
343 Int_t buttons = 4;
344 Int_t retval = 0 ;
345
346 // first check if the new event is in the range of possible events
347
348 if ( iEvt < 0 || iEvt >= fReadTree->GetEntries() )
349 {
350 new TGMsgBox(fClient->GetRoot(), this,
351 "WARNING!",
352 "The event number is out of range!!!",
353 kMBIconExclamation, buttons, &retval);
354 }
355 else
356 {
357 fReadTree->SetEventNum(iEvt) ;
358 fReadTree->GetEvent() ;
359 CreatePixelList() ;
360 }
361
362 UpdateEventCounter() ;
363}
364
365Bool_t MGFadcDisp::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
366{
367 //------------------------------------------------------------------
368 //
369 // ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
370 //
371 // Processes information from all GUI items.
372 // Selecting an item usually generates an event with 4 parameters.
373 // The first two are packed into msg (first and second bytes).
374 // The other two are parm1 and parm2.
375 //
376 //------------------------------------------------------------------
377 char wortdummy[256] ;
378 Int_t buttons = 4, retval = 0 ;
379
380 switch(GET_MSG(msg))
381 {
382 case kC_COMMAND:
383
384 switch(GET_SUBMSG(msg))
385 {
386
387 case kCM_BUTTON:
388
389 switch (parm1)
390 {
391 case M_PREVEVT:
392 ReadinEvent(fReadTree->GetEventNum()-1 ) ;
393 break;
394
395 case M_NEXTEVT:
396 ReadinEvent(fReadTree->GetEventNum()+1 ) ;
397 break;
398
399
400 case M_PRINT:
401 new TGMsgBox(fClient->GetRoot(), this,
402 "INFORMATION!",
403 "Your are invited to program that!!",
404 kMBIconExclamation, buttons, &retval);
405
406 break ;
407
408 case M_CLOSE:
409 CloseWindow() ;
410 break;
411
412 }
413
414 case kCM_LISTBOX:
415 switch (parm1)
416 {
417 case M_PIXELLIST:
418 sprintf(wortdummy, "GRAPH%d",fPixelList->GetSelected() ) ;
419
420 fCan->Clear() ;
421 fCan->cd() ;
422
423 fEvtData->Draw(wortdummy) ;
424
425 fCan->Modified() ;
426 fCan->Update() ;
427 break;
428 }
429 break;
430
431 }
432
433 case kC_TEXTENTRY:
434
435 switch(GET_SUBMSG(msg))
436 {
437 case kTE_TEXTCHANGED:
438 break ;
439
440 case kTE_ENTER:
441 sprintf(wortdummy, "%s", fTxtEvtNr->GetText()) ;
442 cout << wortdummy<< endl ;
443 cout << atoi(wortdummy) << endl ;
444
445 ReadinEvent( atoi(wortdummy) ) ;
446 break;
447 }
448 break;
449
450 default:
451 break;
452 }
453
454 return kTRUE ;
455}
Note: See TracBrowser for help on using the repository browser.