Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

EDGui.cxx

Go to the documentation of this file.
00001 
00002 #include "TSystem.h"
00003 
00004 #include "bfemDisplay/EDGui.h"
00005 #include "bfemDisplay/Enum.h"
00006 
00007 
00008 const char *filetypes[] = { "All files",     "*",
00009                             "ROOT files",    "*.root",
00010                             "ROOT macros",   "*.C",
00011                             0,               0 };
00012 
00013 #define RAW_PATH_FILE "rawPath"
00014 #define RECON_PATH_FILE "reconPath"
00015 
00016 
00017 EDGui::EDGui( const TGWindow *p, UInt_t w, UInt_t h, EDControl *evtCtrl ): TGMainFrame( p, w, h ) {
00018 
00019   m_evtCtrl = evtCtrl;
00020 
00021   m_isRealData = kTRUE;
00022 
00023   // Clear data file path names.
00024   sprintf( m_RawFilePath, "%s", "" );
00025   sprintf( m_ReconFilePath, "%s", "" );
00026 
00027   // Create a menu bar at top of main window.
00028 
00029   m_MenuBarLayout = new TGLayoutHints( kLHintsTop | kLHintsLeft | kLHintsExpandX,
00030                                        1, 1, 1, 1 );
00031   m_MenuBarItemLayout = new TGLayoutHints( kLHintsTop | kLHintsLeft, 4, 0, 0, 0 );
00032 
00033   m_MenuFile = new TGPopupMenu( fClient->GetRoot() );
00034   m_CascadeOpen = new TGPopupMenu( fClient->GetRoot() );
00035   m_CascadeOpen->AddEntry( "&Raw", kCascadeRaw );
00036   m_CascadeOpen->AddEntry( "R&econ", kCascadeRecon );
00037   m_MenuFile->AddPopup( "&Open", m_CascadeOpen );
00038   m_MenuFile->AddEntry( "&Save", kFileSave );
00039   m_MenuFile->AddEntry( "&Exit", kFileExit );
00040   m_MenuFile->Associate( this );
00041 
00042   m_MenuMode = new TGPopupMenu( fClient->GetRoot() );
00043   m_MenuMode->AddEntry( "&Display", kModeDisplay );
00044   m_MenuMode->AddEntry( "&Analysis", kModeAnalysis );
00045   m_MenuMode->Associate( this );
00046   m_MenuMode->CheckEntry( kModeDisplay );  // Start in event display mode.
00047   m_ModeIsDisplay = kTRUE;
00048 
00049   m_MenuBar = new TGMenuBar( this, 1, 1 );
00050   m_MenuBar->AddPopup( "&File", m_MenuFile, m_MenuBarItemLayout );
00051   m_MenuBar->AddPopup( "&Mode", m_MenuMode, new TGLayoutHints( kLHintsTop | kLHintsRight, 0, 4, 0, 0 ) );
00052 
00053   AddFrame( m_MenuBar, m_MenuBarLayout );
00054 
00055   // Group frame showing data file paths.
00056 
00057   ifstream rawFile;
00058   ifstream reconFile;
00059   Char_t msg[ 200 ];
00060 
00061   if ( !gSystem->AccessPathName( RAW_PATH_FILE, kFileExists ) ) {
00062 
00063     // Read raw data file name if available.
00064     rawFile.open( RAW_PATH_FILE );
00065     rawFile >> m_RawFilePath;
00066     rawFile.close();
00067     if ( !gSystem->AccessPathName( m_RawFilePath, kFileExists ) ) {
00068       // Check that the file with that name is available.
00069       m_rawFileExists = kTRUE;
00070       // Check data type : raw or mc.
00071       TString *inputfile = new TString( m_RawFilePath );
00072       if (inputfile->Contains( "G4Sim" ) ) m_isRealData = kFALSE;
00073       else if (inputfile->Contains( "raw" ) )m_isRealData = kTRUE;
00074       else  {
00075         new TGMsgBox( fClient->GetRoot(), this, "Error", "Input file neither a raw nor a G4Sim file!!!", 0, kMBOk );
00076         sprintf( m_RawFilePath, "%s", "" );
00077         m_rawFileExists = kFALSE;
00078       }
00079     }
00080     else {
00081       sprintf( msg, "Cannot find last raw file \"%s\".", m_RawFilePath );
00082       new  TGMsgBox( fClient->GetRoot(), this, "Warning", msg, 0, kMBOk );
00083       sprintf( m_RawFilePath, "%s", "" );
00084       m_rawFileExists = kFALSE;
00085     }
00086 
00087   }
00088 
00089   else {
00090 
00091     sprintf( msg, "Cannot find raw data history file \"%s\".", RAW_PATH_FILE );
00092     new  TGMsgBox( fClient->GetRoot(), this, "Warning", msg, 0, kMBOk );
00093     m_rawFileExists = kFALSE;
00094 
00095   }
00096 
00097   if ( !gSystem->AccessPathName( RECON_PATH_FILE, kFileExists ) ) {
00098 
00099     // Read recon data file name if available.
00100     reconFile.open( RECON_PATH_FILE );
00101     reconFile >> m_ReconFilePath;
00102     reconFile.close();
00103     if ( !gSystem->AccessPathName( m_ReconFilePath, kFileExists ) ) {
00104       // Check that the file with that name is available.
00105       m_reconFileExists = kTRUE;
00106     }
00107     else {
00108       sprintf( msg, "Cannot find last recon file \"%s\".", m_ReconFilePath );
00109       new  TGMsgBox( fClient->GetRoot(), this, "Warning", msg, 0, kMBOk );
00110       sprintf( m_ReconFilePath, "%s", "" );
00111       m_reconFileExists = kFALSE;
00112     }
00113 
00114   }
00115 
00116   else {
00117 
00118     sprintf( msg, "Cannot find recon data history file \"%s\".", RECON_PATH_FILE );
00119     new  TGMsgBox( fClient->GetRoot(), this, "Warning", msg, 0, kMBOk );
00120     m_reconFileExists = kFALSE;
00121 
00122   }
00123 
00124   m_FileGroup = new TGGroupFrame( this, "Data files" );
00125 
00126   Char_t Text[ 100 ];
00127   sprintf( Text, "Raw: %s", m_RawFilePath );
00128   m_RawText = new TGLabel( m_FileGroup, Text );
00129   m_FileGroup->AddFrame( m_RawText, new TGLayoutHints( kLHintsExpandY, 1, 1, 10, 0 ) );
00130   sprintf( Text, "Recon: %s", m_ReconFilePath );
00131   m_ReconText = new TGLabel( m_FileGroup, Text );
00132   m_FileGroup->AddFrame( m_ReconText, new TGLayoutHints( kLHintsExpandY, 1, 1, 10, 1 ) );
00133 
00134   AddFrame( m_FileGroup, new TGLayoutHints( kLHintsExpandX, 20, 20, 20, 10  ) );
00135 
00136   // Horizontal frame for Event and Histo button groups.
00137   m_HorizFrame = new TGCompositeFrame( this, 100, 100, kHorizontalFrame );
00138 
00139   // Event control group frame.
00140   // This frame consists of a group of instances of the EDButtonFrame class, which is
00141   // derived from TGComposite frame ROOT class.  The derived class consists of a picture button
00142   // followed by some text and possibly another GUI object like a text entry widget.
00143 
00144   m_EventGroup = new TGGroupFrame( m_HorizFrame, "Event control" );
00145 
00146   m_LabelMode = new TGLabel( m_EventGroup, "Mode: Display" );  // Label showing mode ( event display or analysis ).
00147   ULong_t green;
00148   gClient->GetColorByName( "green", green );
00149   m_LabelMode->SetBackgroundColor( green );
00150   m_EventGroup->AddFrame( m_LabelMode, new TGLayoutHints( kLHintsLeft, 1, 1, 10, 5 ) );
00151 
00152   m_NextPic = ( TGPicture* )gClient->GetPicture( "arrow_right.xpm" );
00153   m_CtrlNext = new EDButtonFrame( this, m_EventGroup, m_NextPic, kGoNext, "Next event" );
00154   m_EventGroup->AddFrame( m_CtrlNext, new TGLayoutHints( kLHintsLeft, 1, 1, 10, 1 ) );
00155 
00156   m_PrevPic = ( TGPicture* )gClient->GetPicture( "arrow_left.xpm" );
00157   m_CtrlPrev = new EDButtonFrame( this, m_EventGroup, m_PrevPic, kGoPrev, "Previous event" );
00158   m_EventGroup->AddFrame( m_CtrlPrev, new TGLayoutHints( kLHintsLeft, 1, 1, 10, 1 ) );
00159 
00160   m_CtrlGoto = new EDButtonFrame( this, m_EventGroup, m_NextPic, kGoto, "Goto event", m_txtEntryGoto );
00161   m_EventGroup->AddFrame( m_CtrlGoto, new TGLayoutHints( kLHintsLeft, 1, 1, 10, 1 ) );
00162   m_txtEntryGoto->Resize( 60, 15 );
00163 
00164   m_AllPic = ( TGPicture* )gClient->GetPicture( "last_t.xpm" );
00165   m_CtrlAll = new EDButtonFrame( this, m_EventGroup, m_AllPic, kGoToEnd, "Cue" );
00166   m_EventGroup->AddFrame( m_CtrlAll, new TGLayoutHints( kLHintsLeft, 1, 1, 10, 1 ) );
00167 
00168   m_RewPic = ( TGPicture* )gClient->GetPicture( "first_t.xpm" );
00169   m_CtrlRew = new EDButtonFrame( this, m_EventGroup, m_RewPic, kRewind, "Review" );
00170   m_EventGroup->AddFrame( m_CtrlRew, new TGLayoutHints( kLHintsLeft, 1, 1, 10, 1 ) );
00171 
00172   m_StopPic = ( TGPicture* )gClient->GetPicture( "record_t.xpm" );
00173   m_CtrlStop = new EDButtonFrame( this, m_EventGroup, m_StopPic, kStop, "Stop" );
00174   m_EventGroup->AddFrame( m_CtrlStop, new TGLayoutHints( kLHintsLeft, 1, 1, 10, 1 ) );
00175 
00176   m_HorizFrame->AddFrame( m_EventGroup, new TGLayoutHints( kLHintsLeft, 20, 20, 10, 10 ) );
00177 
00178   // Histogram display group.
00179 
00180   m_HistoGroup = new TGGroupFrame( m_HorizFrame, "Histogram selection", kHorizontalFrame );
00181 
00182   m_HButtonTKR = new TGTextButton( m_HistoGroup, "&TKR", kHistTKR );
00183   m_HistoGroup->AddFrame( m_HButtonTKR, new TGLayoutHints( kLHintsLeft, 1, 5, 10, 1 ) );
00184   m_HButtonTKR->Associate( this );
00185   m_HButtonCAL = new TGTextButton( m_HistoGroup, "&CAL", kHistCAL );
00186   m_HistoGroup->AddFrame( m_HButtonCAL, new TGLayoutHints( kLHintsLeft, 1, 5, 10, 1 ) );
00187   m_HButtonCAL->Associate( this );
00188   m_HButtonACD = new TGTextButton( m_HistoGroup, "&ACD", kHistACD );
00189   m_HistoGroup->AddFrame( m_HButtonACD, new TGLayoutHints( kLHintsLeft, 1, 5, 10, 1 ) );
00190   m_HButtonACD->Associate( this );
00191   m_HButtonXGT = new TGTextButton( m_HistoGroup, "&XGT", kHistXGT );
00192   m_HistoGroup->AddFrame( m_HButtonXGT, new TGLayoutHints( kLHintsLeft, 1, 5, 10, 1 ) );
00193   m_HButtonXGT->Associate( this );
00194   m_HButtonTOTl = new TGTextButton( m_HistoGroup, "&TOTl", kHistTOTl );
00195   m_HistoGroup->AddFrame( m_HButtonTOTl, new TGLayoutHints( kLHintsLeft, 1, 5, 10, 1 ) );
00196   m_HButtonTOTl->Associate( this );
00197   m_HButtonTOTr = new TGTextButton( m_HistoGroup, "&TOTr", kHistTOTr );
00198   m_HistoGroup->AddFrame( m_HButtonTOTr, new TGLayoutHints( kLHintsLeft, 1, 5, 10, 1 ) );
00199   m_HButtonTOTr->Associate( this );
00200 
00201   m_HButtonTKR->SetState( kButtonDisabled );
00202   m_HButtonCAL->SetState( kButtonDisabled );
00203   m_HButtonACD->SetState( kButtonDisabled );
00204   m_HButtonXGT->SetState( kButtonDisabled );
00205   m_HButtonTOTl->SetState( kButtonDisabled );
00206   m_HButtonTOTr->SetState( kButtonDisabled );
00207 
00208   m_HorizFrame->AddFrame( m_HistoGroup, new TGLayoutHints( kLHintsRight, 20, 20, 10, 10 ) );
00209 
00210   AddFrame( m_HorizFrame, new TGLayoutHints( kLHintsCenterX, 0, 0, 0, 0 ) );
00211 
00212 
00213   MapSubwindows();
00214   SetWindowName( "EventControl" );
00215   Resize ( 601, 421 );
00216   MapWindow();
00217 
00218 }
00219 
00220 
00221 EDGui::~EDGui() {
00222 
00223 
00224   delete m_HButtonTKR;
00225   delete m_HButtonCAL;
00226   delete m_HButtonACD;
00227   delete m_HButtonXGT;
00228   delete m_HButtonTOTl;
00229   delete m_HButtonTOTr;
00230   delete m_HistoGroup;
00231 
00232   delete m_StopPic;
00233   delete m_CtrlStop;
00234   delete m_RewPic;
00235   delete m_CtrlRew;
00236   delete m_AllPic;
00237   delete m_CtrlAll;
00238   delete m_txtEntryGoto;
00239   delete m_CtrlGoto;
00240   delete m_PrevPic;
00241   delete m_CtrlPrev;
00242   //  delete m_NextPic;
00243   delete m_CtrlNext;
00244   delete m_LabelMode;
00245   delete m_EventGroup;
00246 
00247   delete m_RawText;
00248   delete m_ReconText;
00249   delete m_FileGroup;
00250 
00251   delete m_MenuMode;
00252   delete m_CascadeOpen;
00253   delete m_MenuFile;
00254   delete m_MenuBar;
00255 
00256 }
00257 
00258 
00259 Bool_t EDGui::ProcessMessage( Long_t msg, Long_t parm1, Long_t ) {
00260 
00261   TGFileInfo fileInfo;
00262   ofstream rawFile;
00263   ofstream reconFile;
00264   Char_t Text[ 100 ];
00265 
00266   if ( GET_MSG( msg ) == kC_COMMAND ) {
00267 
00268     if ( GET_SUBMSG( msg ) == kCM_MENU ) {
00269 
00270       switch( parm1 ) {
00271 
00272       case kCascadeRaw:
00273 
00274         // Open raw data file.
00275 
00276         fileInfo.fFileTypes = ( char ** )filetypes;
00277 
00278         // Specify initial directory ( this should work but it doesn't.  Not yet implemented
00279         // in ROOT? )
00280         /*      Char_t IniDir[ 100 ];
00281         sprintf( IniDir,  "/home/msgc" );
00282         fileInfo.fIniDir = IniDir;*/
00283 
00284         new TGFileDialog( fClient->GetRoot(), this, kFDOpen, &fileInfo );
00285 
00286         if ( fileInfo.fFilename != NULL ) {
00287           TString *s = new TString( fileInfo.fFilename );
00288           if ( !s->Contains( "root" ) ) {
00289             new TGMsgBox( fClient->GetRoot(), this, "Error", "Must be a ROOT file.", 0, kMBOk );
00290             break;
00291           }
00292           if ( s->Contains( "recon" ) ) {
00293             new TGMsgBox( fClient->GetRoot(), this, "Error", "You selected a recon file!", 0, kMBOk );
00294             break;
00295           }
00296           delete s;
00297           sprintf( m_RawFilePath, "%s", fileInfo.fFilename );
00298           sprintf( Text, "Raw: %s", m_RawFilePath );
00299           m_RawText->SetText( Text );
00300           m_FileGroup->Layout();
00301 
00302           rawFile.open( RAW_PATH_FILE, ios::out );
00303           rawFile << m_RawFilePath;
00304           rawFile.close();
00305 
00306           m_rawFileExists = kTRUE;
00307 
00308           TString *inputfile = new TString( m_RawFilePath );
00309           if (inputfile->Contains( "G4Sim" ) ) m_isRealData = kFALSE;
00310           else if (inputfile->Contains( "raw" ) )m_isRealData = kTRUE;
00311           else {
00312             new TGMsgBox( fClient->GetRoot(), this, "Error", "Input file neither a raw nor a G4Sim file!!!\n Select another one!", 0, kMBOk );
00313             sprintf( m_RawFilePath, "%s", "" );
00314             m_rawFileExists = kFALSE;
00315             break;
00316           }
00317 
00318           m_evtCtrl->processCommand( kReqRawFile );
00319 
00320         }
00321 
00322         break;
00323 
00324       case kCascadeRecon:
00325 
00326         // Open recon data file.
00327 
00328         fileInfo.fFileTypes = ( char ** )filetypes;
00329 
00330         new TGFileDialog( fClient->GetRoot(), this, kFDOpen, &fileInfo );
00331 
00332         if ( fileInfo.fFilename != NULL ) {
00333           TString *s = new TString( fileInfo.fFilename );
00334           if ( !s->Contains( "root" ) ) {
00335             new TGMsgBox( fClient->GetRoot(), this, "Error", "Must be a ROOT file.", 0, kMBOk );
00336             break;
00337           }
00338           if ( !s->Contains( "recon" ) ) {
00339             new TGMsgBox( fClient->GetRoot(), this, "Error", "File name must contain string \"recon\".", 0, kMBOk );
00340             break;
00341           }
00342           delete s;
00343           sprintf( m_ReconFilePath, "%s", fileInfo.fFilename );
00344           sprintf( Text, "Recon: %s", m_ReconFilePath );
00345           m_ReconText->SetText( Text );
00346           m_FileGroup->Layout();
00347 
00348           reconFile.open( RECON_PATH_FILE, ios::out );
00349           reconFile << m_ReconFilePath;
00350           reconFile.close();
00351 
00352           m_reconFileExists = kTRUE;
00353 
00354           m_evtCtrl->processCommand( kReqReconFile );
00355 
00356         }
00357 
00358         break;
00359 
00360       case kFileExit:
00361         // Close all windows and exit.
00362         m_evtCtrl->processCommand( kReqExit );
00363         break;
00364 
00365       case kModeDisplay:
00366 
00367         // Switch to display mode.
00368 
00369         SetModeDisplay();
00370         Layout();
00371         m_evtCtrl->processCommand( kReqDisplay );
00372 
00373         break;
00374 
00375       case kModeAnalysis:
00376 
00377         // Switch to analysis mode.
00378 
00379         /*      err = WriteCommand( kReqAnalysis );
00380 
00381                 if ( err ) break;*/
00382 
00383         m_MenuMode->UnCheckEntry( kModeDisplay );
00384         m_MenuMode->CheckEntry( kModeAnalysis );
00385 
00386         m_LabelMode->SetText( "Mode: Analysis" );
00387 
00388         m_ModeIsDisplay = kFALSE;
00389 
00390         m_CtrlGoto->SetText( "Go forward" );
00391         m_CtrlGoto->Layout();
00392         m_CtrlAll->SetText( "All events" );
00393         m_CtrlAll->Layout();
00394         m_CtrlRew->SetText( "Rewind" );
00395         m_CtrlRew->Layout();
00396 
00397         m_HButtonTKR->SetState( kButtonUp );
00398         m_HButtonCAL->SetState( kButtonUp );
00399         m_HButtonACD->SetState( kButtonUp );
00400         m_HButtonXGT->SetState( kButtonUp );
00401         m_HButtonTOTl->SetState( kButtonUp );
00402         m_HButtonTOTr->SetState( kButtonUp );
00403 
00404         Resize( 601, 421 );
00405         Layout();
00406 
00407         m_evtCtrl->processCommand( kReqAnalysis );
00408 
00409         break;
00410 
00411       default: break;
00412 
00413       }
00414 
00415     }
00416 
00417     if ( GET_SUBMSG( msg ) == kCM_BUTTON ) {
00418 
00419       if ( !m_rawFileExists ) {
00420         new TGMsgBox( fClient->GetRoot(), this, "Error", "Please first select a raw data file.", 0, kMBOk );
00421         return( kFALSE );
00422       }
00423 
00424       switch( parm1 ) {
00425 
00426       case kGoNext:
00427         if ( m_ModeIsDisplay ) m_evtCtrl->processCommand( kReqDisplayNext );
00428         else m_evtCtrl->processCommand( kReqAnalNext );
00429         break;
00430 
00431       case kGoPrev:
00432         if ( m_ModeIsDisplay ) m_evtCtrl->processCommand( kReqPrev );
00433         // Not available for analysis mode.
00434         break;
00435 
00436       case kGoto:
00437         Char_t evtNo[ 20 ];
00438         sprintf( evtNo, "%s", m_txtEntryGoto->GetText() );
00439         if ( m_ModeIsDisplay ) m_evtCtrl->processCommand( Int_t( kReqDisplayGoto ), atoi( evtNo ) );
00440         else m_evtCtrl->processCommand( Int_t( kReqAnalGoto ), atoi( evtNo ) );
00441         break;
00442 
00443       case kGoToEnd:
00444         if ( m_ModeIsDisplay ) m_evtCtrl->processCommand( kReqCue );
00445         else  m_evtCtrl->processCommand( kReqAll );
00446         break;
00447 
00448       case kRewind:
00449         if ( m_ModeIsDisplay ) m_evtCtrl->processCommand( kReqReview );
00450         else m_evtCtrl->processCommand( kReqRewind );
00451         break;
00452 
00453       case kStop:
00454         if ( m_ModeIsDisplay ) m_evtCtrl->processCommand( kReqDisplayStop );
00455         else  m_evtCtrl->processCommand( kReqAnalStop );
00456         break;
00457 
00458       case kHistTKR:
00459         m_evtCtrl->processCommand( kReqHistTKR );
00460         break;
00461 
00462       case kHistCAL:
00463         m_evtCtrl->processCommand( kReqHistCAL );
00464         break;
00465 
00466       case kHistACD:
00467         m_evtCtrl->processCommand( kReqHistACD );
00468         break;
00469 
00470       case kHistXGT:
00471         m_evtCtrl->processCommand( kReqHistXGT );
00472         break;
00473 
00474       case kHistTOTl:
00475         m_evtCtrl->processCommand( kReqHistTOTl );
00476         break;
00477 
00478       case kHistTOTr:
00479         m_evtCtrl->processCommand( kReqHistTOTr );
00480         break;
00481 
00482       default: break;
00483 
00484       }
00485 
00486     }
00487 
00488   }
00489 
00490   return( kTRUE );
00491 
00492 }
00493 
00494 
00495 void EDGui::SetModeDisplay() {
00496 
00497   // Switch to display mode.
00498 
00499   /*    err = WriteCommand( kReqDisplay );
00500 
00501         if ( err ) break;*/
00502 
00503   m_MenuMode->UnCheckEntry( kModeAnalysis );
00504   m_MenuMode->CheckEntry( kModeDisplay );
00505 
00506   m_LabelMode->SetText( "Mode: Display" );
00507 
00508   m_ModeIsDisplay = kTRUE;
00509 
00510   m_CtrlGoto->SetText( "Goto event" );
00511   m_CtrlGoto->Layout();
00512   m_CtrlAll->SetText( "Cue" );
00513   m_CtrlAll->Layout();
00514   m_CtrlRew->SetText( "Review" );
00515   m_CtrlRew->Layout();
00516 
00517   m_HButtonTKR->SetState( kButtonDisabled );
00518   m_HButtonCAL->SetState( kButtonDisabled );
00519   m_HButtonACD->SetState( kButtonDisabled );
00520   m_HButtonXGT->SetState( kButtonDisabled );
00521   m_HButtonTOTl->SetState( kButtonDisabled );
00522   m_HButtonTOTr->SetState( kButtonDisabled );
00523 
00524   Resize( 601, 421 );
00525 
00526 }
00527 
00528 
00529 
00530 

Generated at Mon Nov 26 18:20:07 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000