source: trunk/MagicSoft/Simulation/Corsika/GuiSimone/MainFrameSimone.cxx@ 417

Last change on this file since 417 was 416, checked in by harald, 25 years ago
add information about the progress during readin the cer files.
File size: 16.6 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 // inform about progress
336
337 if (!( i_cer %1000) )
338 {
339 cout << i_cer << endl ;
340 sprintf ( datname, "%d", fNumEvents ) ;
341
342 fDirNum->RemoveEntry(1) ;
343 fDirNum->AddEntry(datname,1) ;
344 fDirNum->MapSubwindows() ;
345 fDirNum->Layout() ;
346 }
347
348
349 // create the file names
350
351 sprintf ( cername, "%s/cer%06d", fInputPath, i_cer ) ;
352 sprintf ( datname, "%s/dat%06d", fInputPath, i_cer ) ;
353
354 // try to open the files
355
356 cerfile.open( cername );
357
358 if ( cerfile.bad() ) {
359
360 fNumEvents = i_cer -1 ;
361
362 sprintf ( datname, "%d", fNumEvents ) ;
363
364 fDirNum->RemoveEntry(1) ;
365 fDirNum->AddEntry(datname,1) ;
366 fDirNum->MapSubwindows() ;
367 fDirNum->Layout() ;
368
369 break ;
370 }
371
372 Event.read( cerfile );
373
374 //
375 // fill Ntuple
376 //
377
378 fNtup->Fill( Event.get_primary() ,
379 Event.get_energy() ,
380 Event.get_coreX(),
381 Event.get_coreY() ) ;
382
383
384 cerfile.close();
385
386 }
387
388 //
389 // set some value of this class
390 //
391 sprintf ( fNtupPath, "%s", fInputPath) ;
392
393 return (kTRUE) ;
394}
395
396// ======================================================================
397// ======================================================================
398
399Bool_t MainFrameSimone::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
400{
401 Int_t retval = 0 ;
402 Char_t wort[100] ;
403 Char_t testfile[100] ;
404 Char_t extens[5] ;
405 Char_t command[110] ;
406
407 TGFileItem *item ; // to process items in the file view container
408 void *np = NULL ; // null pointer
409
410 TCanvas *canvas = fCanvasRun->GetCanvas();
411
412 // Process events generated by the buttons in the frame.
413
414 switch (GET_MSG(msg)) {
415 case kC_COMMAND:
416 switch (GET_SUBMSG(msg)) {
417 case kCM_BUTTON:
418
419 switch (parm1) {
420 case M_CDIR_UP :
421 sprintf ( fInputPath, "\0") ;
422 fSelectButton->SetState(kButtonDisabled) ;
423 fDir2->RemoveEntry(1) ;
424 fDir2->AddEntry(fInputPath,1) ;
425 fDir2->MapSubwindows() ;
426 fDir2->Layout() ;
427
428 //
429 // goto the parent directory
430 //
431 gSystem->ChangeDirectory("..") ;
432 fDir->RemoveEntry(1) ;
433 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
434 fDir->AddEntry(wort,1) ;
435 fDir->MapSubwindows() ;
436 fDir->Layout() ;
437 fFileCont->ChangeDirectory( wort ) ;
438 fFileCont->DisplayDirectory() ;
439
440 break ;
441
442 case M_LIST_MODE:
443 fFileView->SetViewMode(kLVList) ;
444 fDetail->SetState(kButtonUp) ;
445 break ;
446
447 case M_DETAIL_MODE:
448 fFileView->SetViewMode(kLVDetails) ;
449 fListMode->SetState(kButtonUp) ;
450 break ;
451
452 case M_BUTTON_SELECT:
453
454 if ( fFileCont->NumSelected() == 1 ) {
455 //
456 // one file selected
457 //
458 item = (TGFileItem *) fFileCont->GetNextSelected(&np) ;
459
460 if ( S_ISDIR(item->GetType()) ) { // file is directory
461
462 sprintf (fInputPath, "%s/%s",
463 gSystem->WorkingDirectory(),
464 item->GetItemName()->GetString()) ;
465
466 fDir2->RemoveEntry(1) ;
467 fDir2->AddEntry(fInputPath,1) ;
468 fDir2->MapSubwindows() ;
469 fDir2->Layout() ;
470
471 }
472 }
473 break;
474
475 case M_BUTTON_PARTID:
476 if ( CheckNtup() )
477 {
478 fNtup->Draw("PartID") ;
479 canvas->Modified() ;
480 canvas->Update() ;
481 }
482 else
483 printf("No Ntuple exist!!\n");
484 break;
485
486 case M_BUTTON_ENERGY:
487 if ( CheckNtup() )
488 {
489 fNtup->Draw("Energy") ;
490 canvas->Modified() ;
491 canvas->Update() ;
492 }
493 else
494 printf("No Ntuple exist!!\n");
495 break;
496
497 case M_BUTTON_CORE:
498 if ( CheckNtup() )
499 {
500 fNtup->Draw("CoreY:CoreX") ;
501 canvas->Modified() ;
502 canvas->Update() ;
503 }
504 else
505 printf("No Ntuple exist!!\n");
506 break;
507
508 case M_CTRL_EXIT:
509 CloseWindow() ;
510 break;
511
512 case M_CTRL_PWD:
513 printf ("WorkingDirectory -> %s <- \n", gSystem->WorkingDirectory() ) ;
514 break ;
515
516 case M_CTRL_PATH:
517 printf ("Input Path: -> %s <- \n", fInputPath ) ;
518 break ;
519 }
520
521 break;
522
523 case kCM_CHECKBUTTON:
524
525 break;
526
527 case kCM_RADIOBUTTON:
528 break;
529
530
531 case kCM_MENU:
532 switch (parm1) {
533 case M_FILE_EXIT:
534 CloseWindow() ;
535 break;
536
537 }
538 break ;
539
540 default:
541 break;
542
543 }
544
545 case kC_CONTAINER:
546 switch (GET_SUBMSG(msg)) {
547
548 // case kCT_ITEMCLICK:
549 // printf ("itemclick\n");
550 // break;
551
552
553 case kCT_ITEMDBLCLICK:
554 //
555 // process the double click in the file view container
556 //
557
558 if ( parm1 == kButton1) {
559 if ( fFileCont->NumSelected() == 1 ) {
560 //
561 // one file selected
562 //
563 item = (TGFileItem *) fFileCont->GetNextSelected(&np) ;
564
565 if ( S_ISDIR(item->GetType()) ) { // file is directory
566
567 sprintf (wort, "%s", item->GetItemName()->GetString()) ;
568
569 //
570 // check if in this directory the file cer000001 exits
571 // if it exists, do not open the stuff
572 //
573
574 if ( CerFileExist( wort ) ) {
575 printf ("Warning: Cer files in directory\n") ;
576 fSelectButton->SetState(kButtonUp) ;
577 }
578 else {
579 sprintf (fInputPath,"\0") ;
580 fSelectButton->SetState(kButtonDisabled) ;
581 fDir2->RemoveEntry(1) ;
582 fDir2->AddEntry(fInputPath,1) ;
583 fDir2->MapSubwindows() ;
584 fDir2->Layout() ;
585 //
586 // goto directory
587 //
588 fFileCont->ChangeDirectory ( wort ) ;
589 gSystem->ChangeDirectory( wort ) ;
590
591 sprintf (wort, "%s", gSystem->WorkingDirectory() ) ;
592 fDir->RemoveEntry(1) ;
593 fDir->AddEntry( wort, 1 ) ;
594 fDir->MapSubwindows() ;
595 fDir->Layout() ;
596 }
597
598 }
599 else { // item is a file
600 sprintf (testfile, "%s", item->GetItemName()->GetString() ) ;
601
602 //
603 // determine the file type by extensions
604 //
605
606 for (Int_t i = 0 ; i<5; i++)
607 extens[i] = '\0' ;
608
609 for ( Int_t i=0; testfile[i] != '\0'; i++) {
610 if ( testfile[i] == '.') {
611 strncpy (extens, &testfile[i+1], 4 ) ;
612 break ;
613 }
614 }
615
616 //
617 // postscript file
618 //
619
620 if ( ! strcmp(extens, "ps") ) {
621 sprintf ( command, "gv %s/%s &",
622 gSystem->WorkingDirectory(),
623 testfile ) ;
624 gSystem->Exec(command) ;
625 break ;
626 }
627
628
629
630
631 }
632 }
633 }
634 else if ( parm1 == kButton3) { // right mouse double click
635 printf ("huschel kButton3\n");
636 }
637
638 break;
639
640 }
641 break ;
642
643
644 default:
645 break;
646 }
647 return kTRUE;
648}
649
650
Note: See TracBrowser for help on using the repository browser.