source: branches/start/MagicSoft/Simulation/Corsika/GuiSimone/MainFrameSimone.cxx@ 14476

Last change on this file since 14476 was 413, checked in by harald, 24 years ago
Import to start CVS control
File size: 16.3 KB
Line 
1//
2//
3//
4#define START_DIRECTORY "/dat1"
5#define S_ISDIR(m) (((m)&(0170000)) == (0040000))
6
7#include <TApplication.h>
8#include <TGMsgBox.h>
9
10#include "MainFrameSimone.hxx"
11
12
13
14MainFrameSimone::MainFrameSimone(const TGWindow *p, UInt_t w, UInt_t h)
15 : TGMainFrame(p, w, h)
16{
17 sprintf (fInputPath, "\0" ) ;
18 fNumEvents = 0 ;
19
20 fNtup = new TNtuple ("fNtup", "Ntuple with Run distributions",
21 "PartID:Energy:CoreX:CoreY") ;
22 //
23 // Create a main frame with a number of different buttons.
24 //
25
26 //
27 // First create the MenuBar.
28 //
29
30 fLayMenuBar = new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX,
31 2, 2, 2, 2 ) ;
32 fLayMenuItem = new TGLayoutHints ( kLHintsTop | kLHintsLeft ,
33 0, 4, 0, 0 ) ;
34
35
36 fFileMenu = new TGPopupMenu ( fClient->GetRoot() ) ;
37 fFileMenu->AddEntry ("Exit", M_FILE_EXIT ) ;
38
39 //
40 // the button messages are handled by main frame (this)
41 //
42 fFileMenu->Associate(this) ;
43
44
45 fMenuBar = new TGMenuBar ( this, 1, 1, kHorizontalFrame ) ;
46 fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem ) ;
47
48 AddFrame(fMenuBar, fLayMenuBar ) ;
49
50
51 //
52 // create the Tab
53 //
54
55 fFrame = new TGCompositeFrame (this, 300,300, kHorizontalFrame ) ;
56
57 fLayTab = new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX , 5, 5, 5, 5 ) ;
58 fTab = new TGTab ( fFrame, 400, 400 ) ;
59
60 TGCompositeFrame *tf = fTab->AddTab("Input") ;
61 fTabF1 = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
62
63 tf->AddFrame(fTabF1, fLayTab ) ;
64
65 fTabF1a = new TGCompositeFrame (tf, 100, 100, kHorizontalFrame) ;
66 tf->AddFrame(fTabF1a, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
67
68 fTabF1b = new TGCompositeFrame (tf, 100, 100, kVerticalFrame) ;
69 tf->AddFrame(fTabF1b, new TGLayoutHints ( kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 5, 5, 5, 5 ) ) ;
70
71 fDir = new TGListBox(fTabF1, -1) ;
72 fDir->Resize(350,20) ;
73 char temp[100] ;
74 // sprintf ( temp, "%s", START_DIRECTORY ) ;
75 sprintf ( temp, "%s", gSystem->WorkingDirectory() ) ;
76 fDir->AddEntry(temp, 1) ;
77 fTabF1->AddFrame( fDir, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
78
79
80 fPicCdup = fClient->GetPicture("tb_uplevel.xpm") ;
81 fCdup = new TGPictureButton(fTabF1, fPicCdup, M_CDIR_UP ) ;
82 fCdup->SetToolTipText("One Level up!") ;
83 fCdup->Associate(this) ;
84 fTabF1->AddFrame (fCdup, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
85
86 fPicList = fClient->GetPicture("tb_list.xpm") ;
87 fListMode = new TGPictureButton(fTabF1, fPicList, M_LIST_MODE ) ;
88 fListMode->SetToolTipText("List Mode") ;
89 fListMode->Associate(this) ;
90 fListMode->SetState(kButtonUp) ;
91 fListMode->AllowStayDown(kTRUE) ;
92 fTabF1->AddFrame (fListMode, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
93
94 fPicDetail = fClient->GetPicture("tb_details.xpm") ;
95 fDetail = new TGPictureButton(fTabF1, fPicDetail, M_DETAIL_MODE ) ;
96 fDetail->SetToolTipText("Details Mode") ;
97 fDetail->Associate(this) ;
98 fDetail->SetState(kButtonEngaged) ;
99 fDetail->AllowStayDown(kTRUE) ;
100 fTabF1->AddFrame (fDetail, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5) ) ;
101
102
103 fSelectButton = new TGTextButton(fTabF1b, "Select", M_BUTTON_SELECT );
104 fSelectButton->SetToolTipText("To select a path with Mmcs data files!");
105 fSelectButton->SetState(kButtonDisabled);
106 fSelectButton->Associate(this) ;
107
108 fTabF1b->AddFrame(fSelectButton,
109 new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5) ) ;
110
111 fFileView = new TGListView(fTabF1b, 540, 380 ) ;
112 fFileCont = new TGFileContainer(fFileView->GetViewPort(), 100, 100,
113 kVerticalFrame, fgWhitePixel) ;
114
115 fFileCont->Associate(this) ;
116 fFileView->GetViewPort()->SetBackgroundColor(fgWhitePixel) ;
117 fFileView->SetContainer(fFileCont) ;
118 fFileCont->SetFilter("*") ;
119 // fFileCont->ChangeDirectory(START_DIRECTORY) ;
120 fFileCont->ChangeDirectory(gSystem->WorkingDirectory()) ;
121 fFileView->SetViewMode(kLVDetails);
122 fFileCont->Sort(kSortByName) ;
123
124 fTabF1b->AddFrame(fFileView, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5) ) ;
125
126 //
127 // create Tab 2
128 //
129
130 tf = fTab->AddTab("Run Dist") ;
131 fTabF2 = new TGCompositeFrame (tf, 100, 100, kVerticalFrame) ;
132
133 tf->AddFrame(fTabF2, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5)) ;
134
135 // create the vertical subframes
136
137 fTabF2a = new TGCompositeFrame (fTabF2, 100, 100, kHorizontalFrame) ;
138 fTabF2->AddFrame(fTabF2a, fLayTab ) ;
139
140 fTabF2b = new TGCompositeFrame (fTabF2, 300, 300, kHorizontalFrame) ;
141 fTabF2->AddFrame(fTabF2b,
142 new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX |kLHintsExpandY, 5, 5, 5, 5 ) ) ;
143
144 fTabF2c = new TGCompositeFrame (fTabF2, 100, 100, kHorizontalFrame) ;
145 fTabF2->AddFrame(fTabF2c,new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
146
147 // create the entries in first subframe
148
149 fLabelInput = new TGLabel(fTabF2a, new TGString("Title:") );
150 fTabF2a->AddFrame( fLabelInput, new TGLayoutHints(kLHintsTop | kLHintsLeft , 5, 5, 5, 5 ) ) ;
151
152 fDir2 = new TGListBox(fTabF2a, -1) ;
153 fDir2->Resize(350,20) ;
154 sprintf ( temp, "%s", fInputPath ) ;
155 fDir2->AddEntry(temp, 1) ;
156 fTabF2a->AddFrame( fDir2, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5 ) ) ;
157
158 fLabelNumEvts = new TGLabel(fTabF2a, new TGString("Number of Events:") );
159 fTabF2a->AddFrame( fLabelNumEvts, new TGLayoutHints(kLHintsTop | kLHintsLeft , 5, 5, 5, 5 ) ) ;
160
161 fDirNum = new TGListBox(fTabF2a, -1) ;
162 fDirNum->Resize(50,20) ;
163 fTabF2a->AddFrame( fDirNum,
164 new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5 ) ) ;
165
166 fButtonPlot = new TGTextButton(fTabF2a, "PLOT", M_BUTTON_PLOT );
167 fButtonPlot->Associate(this) ;
168 fTabF2a->AddFrame (fButtonPlot, new TGLayoutHints(kLHintsTop | kLHintsLeft, 50, 50, 5, 5) );
169
170 // create the entries in the second subframe
171
172 fCanvasRun = new TRootEmbeddedCanvas("fCanvasRun", fTabF2b, 300, 300 ) ;
173 fTabF2b->AddFrame(fCanvasRun, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY | kLHintsExpandX, 5, 5, 5, 5 ) ) ;
174
175 // create the entries in the second subframe
176
177 fButtonPartID = new TGTextButton(fTabF2c, "PartId", M_BUTTON_PARTID );
178 fButtonPartID->Associate(this) ;
179 fTabF2c->AddFrame (fButtonPartID, new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2) );
180
181 fButtonEnergy = new TGTextButton(fTabF2c, "Energy", M_BUTTON_ENERGY );
182 fButtonEnergy->Associate(this) ;
183 fTabF2c->AddFrame (fButtonEnergy, new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2) );
184
185 fButtonCore = new TGTextButton(fTabF2c, "CoreX", M_BUTTON_CORE );
186 fButtonCore->Associate(this) ;
187 fTabF2c->AddFrame (fButtonCore, new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2) );
188
189 //
190 // create Tab 3
191 //
192
193 tf = fTab->AddTab("Control") ;
194 fTabF3 = new TGCompositeFrame (tf, 100, 100, kVerticalFrame) ;
195
196
197 fButton1 = new TGTextButton(fTabF3, "&Exit", M_CTRL_EXIT);
198 fButton2 = new TGTextButton(fTabF3, "Working Directory", M_CTRL_PWD);
199 fButton3 = new TGTextButton(fTabF3, "Input Path", M_CTRL_PATH);
200
201 fButton1->Associate(this) ;
202 fButton2->Associate(this) ;
203 fButton3->Associate(this) ;
204
205 fLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 10, 10, 10);
206
207 fTabF3->AddFrame (fButton1, fLayout ) ;
208 fTabF3->AddFrame (fButton2, fLayout ) ;
209 fTabF3->AddFrame (fButton3, fLayout ) ;
210
211 tf->AddFrame(fTabF3, fLayTab) ;
212
213 fFrame->AddFrame ( fTab, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5) );
214
215 AddFrame(fFrame, new TGLayoutHints (kLHintsExpandX|kLHintsExpandY) ) ;
216
217
218
219 //
220 //
221 //
222
223 MapSubwindows();
224
225 Layout();
226
227 SetWindowName("MainSimone");
228 SetIconName("MainSimone");
229
230 MapWindow();
231}
232
233// ======================================================================
234// ======================================================================
235
236MainFrameSimone::~MainFrameSimone() {
237
238 delete fButton1 ;
239 delete fButton2 ;
240 delete fFrame, fTab, fTabF1, fTabF2, fTabF3 ;
241 delete fTabF1a, fTabF1b ;
242 delete fDir, fCdup, fListMode, fDetail ;
243 delete fFileCont, fFileView ;
244 delete fFileMenu, fMenuBar;
245 delete fLayout, fLayMenuBar, fLayMenuItem, fLayTab ;
246
247 delete fPicCdup, fPicList, fPicDetail ;
248
249}
250
251// ======================================================================
252// ======================================================================
253
254void MainFrameSimone::CloseWindow()
255{
256 // Got close message for this MainFrame. Calls parent CloseWindow()
257 // (which destroys the window) and terminate the application.
258 // The close message is generated by the window manager when its close
259 // window menu item is selected.
260
261 TGMainFrame::CloseWindow();
262 gROOT->GetApplication()->Terminate(0) ;
263
264}
265
266// ======================================================================
267// ======================================================================
268
269Bool_t MainFrameSimone::CerFileExist(Char_t *dir)
270{
271 Char_t testfile[110] ;
272 FILE *unit ;
273
274 sprintf (testfile, "%s/%s/cer000001",
275 gSystem->WorkingDirectory(), dir ) ;
276 //
277 // try to open the testfile
278 //
279
280 if ( (unit = fopen (testfile, "r" )) == 0 ) {
281 //
282 // doesn't exist --> kFALSE
283 return (kFALSE) ;
284 }
285 else {
286 fclose ( unit ) ;
287
288 return ( kTRUE ) ;
289 }
290
291 return (kFALSE) ;
292}
293
294// ======================================================================
295// ======================================================================
296Bool_t MainFrameSimone::CheckNtup()
297{
298 if ( ! strcmp( fInputPath, "\0") ) {
299 printf ("No InputPath specified!! Do this before!!\n") ;
300 return (kFALSE) ;
301 }
302
303
304 if ( ! strcmp ( fInputPath, fNtupPath ) ) {
305 return (kTRUE) ;
306 }
307 else {
308
309 if ( ReadDataToNtup() ) {
310 return (kTRUE) ;
311 }
312 }
313
314 return (kFALSE) ;
315}
316
317// ======================================================================
318// ======================================================================
319
320Bool_t MainFrameSimone::ReadDataToNtup()
321{
322 Char_t cername[256] ;
323 Char_t datname[256] ;
324
325 ifstream cerfile ;
326
327 COREventHeader Event ;
328
329 printf("readin the input path: %s \n", fInputPath ) ;
330
331 fNtup->Reset() ;
332
333 for (int i_cer = 1; i_cer <= 100000; i_cer++ ) {
334
335 // create the file names
336
337 sprintf ( cername, "%s/cer%06d", fInputPath, i_cer ) ;
338 sprintf ( datname, "%s/dat%06d", fInputPath, i_cer ) ;
339
340 // try to open the files
341
342 cerfile.open( cername );
343
344 if ( cerfile.bad() ) {
345
346 fNumEvents = i_cer -1 ;
347
348 sprintf ( datname, "%d", fNumEvents ) ;
349
350 fDirNum->RemoveEntry(1) ;
351 fDirNum->AddEntry(datname,1) ;
352 fDirNum->MapSubwindows() ;
353 fDirNum->Layout() ;
354
355 break ;
356 }
357
358 Event.read( cerfile );
359
360 //
361 // fill Ntuple
362 //
363
364 fNtup->Fill( Event.get_primary() ,
365 Event.get_energy() ,
366 Event.get_coreX(),
367 Event.get_coreY() ) ;
368
369
370 cerfile.close();
371
372 }
373
374 //
375 // set some value of this class
376 //
377 sprintf ( fNtupPath, "%s", fInputPath) ;
378
379 return (kTRUE) ;
380}
381
382// ======================================================================
383// ======================================================================
384
385Bool_t MainFrameSimone::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
386{
387 Int_t retval = 0 ;
388 Char_t wort[100] ;
389 Char_t testfile[100] ;
390 Char_t extens[5] ;
391 Char_t command[110] ;
392
393 TGFileItem *item ; // to process items in the file view container
394 void *np = NULL ; // null pointer
395
396 TCanvas *canvas = fCanvasRun->GetCanvas();
397
398 // Process events generated by the buttons in the frame.
399
400 switch (GET_MSG(msg)) {
401 case kC_COMMAND:
402 switch (GET_SUBMSG(msg)) {
403 case kCM_BUTTON:
404
405 switch (parm1) {
406 case M_CDIR_UP :
407 sprintf ( fInputPath, "\0") ;
408 fSelectButton->SetState(kButtonDisabled) ;
409 fDir2->RemoveEntry(1) ;
410 fDir2->AddEntry(fInputPath,1) ;
411 fDir2->MapSubwindows() ;
412 fDir2->Layout() ;
413
414 //
415 // goto the parent directory
416 //
417 gSystem->ChangeDirectory("..") ;
418 fDir->RemoveEntry(1) ;
419 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
420 fDir->AddEntry(wort,1) ;
421 fDir->MapSubwindows() ;
422 fDir->Layout() ;
423 fFileCont->ChangeDirectory( wort ) ;
424 fFileCont->DisplayDirectory() ;
425
426 break ;
427
428 case M_LIST_MODE:
429 fFileView->SetViewMode(kLVList) ;
430 fDetail->SetState(kButtonUp) ;
431 break ;
432
433 case M_DETAIL_MODE:
434 fFileView->SetViewMode(kLVDetails) ;
435 fListMode->SetState(kButtonUp) ;
436 break ;
437
438 case M_BUTTON_SELECT:
439
440 if ( fFileCont->NumSelected() == 1 ) {
441 //
442 // one file selected
443 //
444 item = (TGFileItem *) fFileCont->GetNextSelected(&np) ;
445
446 if ( S_ISDIR(item->GetType()) ) { // file is directory
447
448 sprintf (fInputPath, "%s/%s",
449 gSystem->WorkingDirectory(),
450 item->GetItemName()->GetString()) ;
451
452 fDir2->RemoveEntry(1) ;
453 fDir2->AddEntry(fInputPath,1) ;
454 fDir2->MapSubwindows() ;
455 fDir2->Layout() ;
456
457 }
458 }
459 break;
460
461 case M_BUTTON_PARTID:
462 if ( CheckNtup() )
463 {
464 fNtup->Draw("PartID") ;
465 canvas->Modified() ;
466 canvas->Update() ;
467 }
468 else
469 printf("No Ntuple exist!!\n");
470 break;
471
472 case M_BUTTON_ENERGY:
473 if ( CheckNtup() )
474 {
475 fNtup->Draw("Energy") ;
476 canvas->Modified() ;
477 canvas->Update() ;
478 }
479 else
480 printf("No Ntuple exist!!\n");
481 break;
482
483 case M_BUTTON_CORE:
484 if ( CheckNtup() )
485 {
486 fNtup->Draw("CoreY:CoreX") ;
487 canvas->Modified() ;
488 canvas->Update() ;
489 }
490 else
491 printf("No Ntuple exist!!\n");
492 break;
493
494 case M_CTRL_EXIT:
495 CloseWindow() ;
496 break;
497
498 case M_CTRL_PWD:
499 printf ("WorkingDirectory -> %s <- \n", gSystem->WorkingDirectory() ) ;
500 break ;
501
502 case M_CTRL_PATH:
503 printf ("Input Path: -> %s <- \n", fInputPath ) ;
504 break ;
505 }
506
507 break;
508
509 case kCM_CHECKBUTTON:
510
511 break;
512
513 case kCM_RADIOBUTTON:
514 break;
515
516
517 case kCM_MENU:
518 switch (parm1) {
519 case M_FILE_EXIT:
520 CloseWindow() ;
521 break;
522
523 }
524 break ;
525
526 default:
527 break;
528
529 }
530
531 case kC_CONTAINER:
532 switch (GET_SUBMSG(msg)) {
533
534 // case kCT_ITEMCLICK:
535 // printf ("itemclick\n");
536 // break;
537
538
539 case kCT_ITEMDBLCLICK:
540 //
541 // process the double click in the file view container
542 //
543
544 if ( parm1 == kButton1) {
545 if ( fFileCont->NumSelected() == 1 ) {
546 //
547 // one file selected
548 //
549 item = (TGFileItem *) fFileCont->GetNextSelected(&np) ;
550
551 if ( S_ISDIR(item->GetType()) ) { // file is directory
552
553 sprintf (wort, "%s", item->GetItemName()->GetString()) ;
554
555 //
556 // check if in this directory the file cer000001 exits
557 // if it exists, do not open the stuff
558 //
559
560 if ( CerFileExist( wort ) ) {
561 printf ("Warning: Cer files in directory\n") ;
562 fSelectButton->SetState(kButtonUp) ;
563 }
564 else {
565 sprintf (fInputPath,"\0") ;
566 fSelectButton->SetState(kButtonDisabled) ;
567 fDir2->RemoveEntry(1) ;
568 fDir2->AddEntry(fInputPath,1) ;
569 fDir2->MapSubwindows() ;
570 fDir2->Layout() ;
571 //
572 // goto directory
573 //
574 fFileCont->ChangeDirectory ( wort ) ;
575 gSystem->ChangeDirectory( wort ) ;
576
577 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
578 fDir->RemoveEntry(1) ;
579 fDir->AddEntry( wort, 1 ) ;
580 fDir->MapSubwindows() ;
581 fDir->Layout() ;
582 }
583
584 }
585 else { // item is a file
586 sprintf (testfile, "%s", item->GetItemName()->GetString() ) ;
587
588 //
589 // determine the file type by extensions
590 //
591
592 for (Int_t i = 0 ; i<5; i++)
593 extens[i] = '\0' ;
594
595 for ( Int_t i=0; testfile[i] != '\0'; i++) {
596 if ( testfile[i] == '.') {
597 strncpy (extens, &testfile[i+1], 4 ) ;
598 break ;
599 }
600 }
601
602 //
603 // postscript file
604 //
605
606 if ( ! strcmp(extens, "ps") ) {
607 sprintf ( command, "gv %s/%s &",
608 gSystem->WorkingDirectory(),
609 testfile ) ;
610 gSystem->Exec(command) ;
611 break ;
612 }
613
614
615
616
617 }
618 }
619 }
620 else if ( parm1 == kButton3) { // right mouse double click
621 printf ("huschel kButton3\n");
622 }
623
624 break;
625
626 }
627 break ;
628
629
630 default:
631 break;
632 }
633 return kTRUE;
634}
635
636
Note: See TracBrowser for help on using the repository browser.