00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifdef G4VIS_BUILD_DAWN_DRIVER
00035
00036
00037
00038
00039
00040 #include "G4FukuiRenderer.hh"
00041
00042 #define __G_ANSI_C__
00043
00044 #include "G4VisManager.hh"
00045
00046 #include "G4VSceneHandler.hh"
00047 #include "G4FukuiRendererSceneHandler.hh"
00048 #include "G4FukuiRendererViewer.hh"
00049 #include "G4FRClientServer.hh"
00050 #include "G4FRConst.hh"
00051 #include "G4FRFeatures.hh"
00052
00053
00054 const int FR_DEFAULT_CONNECTION_TIME = 5 ;
00055 const char FR_ENV_CONNECTION_TIME [] = "G4DAWN_CONNECTION_TIME";
00056 const char FR_ENV_DAWN_GUI_ALWAYS [] = "G4DAWN_GUI_ALWAYS";
00057
00058
00059 G4FukuiRenderer::G4FukuiRenderer ():
00060 G4VGraphicsSystem ("FukuiRenderer",
00061 "DAWN",
00062 FR_DAWNFILE_FEATURES,
00063 G4VGraphicsSystem::threeD),
00064 fPrimDest() ,
00065 fIPMode( G4FukuiRenderer::IP_UNIX ),
00066 flag_use_gui (false) ,
00067 flag_connected (0)
00068 {
00069
00070 if( ( getenv( FR_ENV_DAWN_GUI_ALWAYS ) != NULL ) && \
00071 ( strcmp( getenv( FR_ENV_DAWN_GUI_ALWAYS ),"0" ) ) )
00072 {
00073 flag_use_gui = true ;
00074 }
00075 }
00076
00077
00078
00079 G4FukuiRenderer::~G4FukuiRenderer ()
00080 {
00081 if( flag_connected ) {
00082
00083 fPrimDest.SendLine( FR_TERMINATE_DAWND ) ;
00084
00085
00086 fPrimDest.DisConnect();
00087 flag_connected = 0 ;
00088 }
00089 }
00090
00091
00092 G4VSceneHandler* G4FukuiRenderer::CreateSceneHandler (const G4String& name)
00093 {
00094 G4VSceneHandler* p = new G4FukuiRendererSceneHandler (*this, name);
00095
00096 if(!flag_connected) { delete p ; p = NULL ; }
00097
00098 return p;
00099 }
00100
00101
00102 G4VViewer* G4FukuiRenderer::CreateViewer (G4VSceneHandler& scene, const G4String& name)
00103 {
00104 if(!flag_connected) return NULL;
00105 G4VViewer* pView =
00106 new G4FukuiRendererViewer ((G4FukuiRendererSceneHandler&) scene, name);
00107 return pView;
00108 }
00109
00110
00111 void G4FukuiRenderer::UseInetDomainAuto()
00112 {
00113 int pid ;
00114
00115 #if defined DEBUG_FR_SYSTEM
00116 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00117 G4cout << "***** Unix Inet Domain (AUTO mode)" << G4endl;
00118 #endif
00119 fIPMode = G4FukuiRenderer::IP_UNIX ;
00120
00121 if( ( pid = fork() ) == 0 ) {
00122 if ( execlp ( "dawn", "dawn", "-G" , (char *)0 ) < 0 )
00123 {
00124 perror("dawn") ;
00125 }
00126 } else {
00127
00128
00129 int connection_time = FR_DEFAULT_CONNECTION_TIME ;
00130 if( getenv( FR_ENV_CONNECTION_TIME ) != NULL ) {
00131 int sscanf_status = \
00132 sscanf( getenv( FR_ENV_CONNECTION_TIME ), "%d", &connection_time) ;
00133 if ( sscanf_status == EOF ) {
00134 connection_time = FR_DEFAULT_CONNECTION_TIME ;
00135 }
00136 }
00137
00138
00139
00140 sleep(connection_time);
00141
00142
00143 this->ConnectPort();
00144 }
00145
00146 if(!flag_connected) {
00147 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00148 G4cout << "***** ERROR: Connection failed" << G4endl;
00149 }
00150 else {
00151 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00152 G4cout << "***** GEANT4 is connected to FukuiRenderer DAWN ";
00153 G4cout << "in the same host" << G4endl;
00154 }
00155 }
00156
00157 }
00158
00159
00160
00161 void
00162 G4FukuiRenderer::UseInetDomain()
00163 {
00164 #if defined DEBUG_FR_SYSTEM
00165 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00166 G4cout << "***** INET Domain " << G4endl;
00167 #endif
00168 fIPMode = G4FukuiRenderer::IP_INET ;
00169
00170 this->ConnectPort();
00171
00172 if(!flag_connected) {
00173 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00174 G4cout << "***** ERROR: Connection failed" << G4endl;
00175 }
00176 else {
00177 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00178 G4cout << "GEANT4 is connected to FukuiRenderer DAWN via socket" ;
00179 G4cout << G4endl;
00180 }
00181 }
00182
00183 }
00184
00185 void
00186 G4FukuiRenderer::ConnectPort( int max_port_incr )
00187 {
00188
00189 int connect_trial = 0 ;
00190 while(1) {
00191 if ( ++connect_trial > max_port_incr ) {
00192 this->flag_connected = 0 ;
00193 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00194 G4cout << "***** INET Connection failed." << G4endl;
00195 G4cout << " Maybe, you have not invoked DAWN yet," << G4endl;
00196 G4cout << " or too many DAWN's are already running" << G4endl;
00197 G4cout << " in the server host." << G4endl;
00198 }
00199 fPrimDest.IncrementPortNumber( (- FR_MAX_PORT_INCR) );
00200 return ;
00201 } else if ( fPrimDest.ConnectINET() ) {
00202
00203 this->flag_connected = 1 ;
00204 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00205 G4cout << "***** GEANT4 is connected to port " ;
00206 G4cout << fPrimDest.GetPortNumber() ;
00207 G4cout << " of server" << G4endl;
00208 }
00209 break ;
00210 } else {
00211
00212 this->flag_connected = 0 ;
00213 fPrimDest.IncrementPortNumber();
00214 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00215 G4cout << "***** GEANT4 incremented targeting port to " ;
00216 G4cout << fPrimDest.GetPortNumber() << G4endl;
00217 }
00218
00219 }
00220
00221 }
00222 }
00223
00224
00225
00226 void G4FukuiRenderer::UseBSDUnixDomainAuto()
00227 {
00228 int pid ;
00229
00230 #if defined DEBUG_FR_SYSTEM
00231 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00232 G4cout << "***** UseBSDUnixDomainAuto " << G4endl;
00233 #endif
00234 fIPMode = G4FukuiRenderer::IP_UNIX ;
00235
00236 if( ( pid = fork() ) == 0 ) {
00237 if ( execlp ( "dawn", "dawn", "-g" , (char *)0 ) < 0 )
00238 {
00239 perror("dawn") ;
00240 }
00241 } else {
00242
00243
00244
00245 int connection_time = FR_DEFAULT_CONNECTION_TIME ;
00246 if( getenv( FR_ENV_CONNECTION_TIME ) != NULL ) {
00247 int sscanf_status = \
00248 sscanf( getenv( FR_ENV_CONNECTION_TIME ), "%d", &connection_time) ;
00249 if ( sscanf_status == EOF ) { connection_time = FR_DEFAULT_CONNECTION_TIME ;}
00250 }
00251 sleep(connection_time);
00252
00253
00254 this->flag_connected = fPrimDest.ConnectUnix();
00255
00256
00257 if(!flag_connected) {
00258 if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
00259 G4cout << "***** ERROR: Connection failed" << G4endl;
00260 } else {
00261 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) {
00262 G4cout << "*** GEANT4 is connected to FukuiRenderer DAWN ";
00263 G4cout << "in the same host" << G4endl;
00264 }
00265 }
00266
00267 }
00268
00269 }
00270
00271
00272 #endif // G4VIS_BUILD_DAWN_DRIVER