Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 /* 27 * ============================================================================= 28 * 29 * Filename: CexmcRunManager.hh 30 * 31 * Description: run manager 32 * 33 * Version: 1.0 34 * Created: 03.11.2009 20:17:20 35 * Revision: none 36 * Compiler: gcc 37 * 38 * Author: Alexey Radkov (), 39 * Company: PNPI 40 * 41 * ============================================================================= 42 */ 43 44 #ifndef CEXMC_RUN_MANAGER_HH 45 #define CEXMC_RUN_MANAGER_HH 46 47 #include <set> 48 #include <limits> 49 #ifdef CEXMC_USE_PERSISTENCY 50 #include <boost/archive/binary_oarchive.hpp> 51 #endif 52 #include <G4RunManager.hh> 53 #include "CexmcRunSObject.hh" 54 #include "CexmcException.hh" 55 #include "CexmcCommon.hh" 56 57 class CexmcRunManagerMessenger; 58 class CexmcPhysicsManager; 59 class CexmcEventFastSObject; 60 #ifdef CEXMC_USE_CUSTOM_FILTER 61 class CexmcCustomFilterEval; 62 #endif 63 64 65 typedef std::set< CexmcOutputDataType > CexmcOutputDataTypeSet; 66 67 68 class CexmcRunManager : public G4RunManager 69 { 70 public: 71 explicit CexmcRunManager( const G4String & projectId = "", 72 const G4String & rProject = "", 73 G4bool overrideExistingProject = false ); 74 75 virtual ~CexmcRunManager(); 76 77 public: 78 void SetPhysicsManager( CexmcPhysicsManager * physicsManager_ ); 79 80 void SetProductionModelType( 81 CexmcProductionModelType productionModelType_ ); 82 83 void SetGdmlFileName( const G4String & gdmlFileName_ ); 84 85 void SetGdmlFileValidation( G4bool on = true ); 86 87 void SetGuiMacroName( const G4String & guiMacroName_ ); 88 89 void SetEventCountPolicy( CexmcEventCountPolicy value ); 90 91 void SetEventDataVerboseLevel( CexmcEventDataVerboseLevel value ); 92 93 void RegisterScenePrimitives( void ); 94 95 #ifdef CEXMC_USE_PERSISTENCY 96 void ReadProject( void ); 97 98 void SaveProject( void ); 99 100 void PrintReadRunData( void ) const; 101 102 void ReadAndPrintEventsData( void ) const; 103 104 void PrintReadData( const CexmcOutputDataTypeSet & outputData ) const; 105 106 void ReplayEvents( G4int nEvents = 0 ); 107 108 void SeekTo( G4int eventNmb = 1 ); 109 110 void SkipInteractionsWithoutEDTonWrite( G4bool on = true ); 111 112 #ifdef CEXMC_USE_CUSTOM_FILTER 113 void SetCustomFilter( const G4String & cfFileName_ ); 114 #endif 115 #endif 116 117 void BeamParticleChangeHook( void ); 118 119 void SetupConstructionHook( void ); 120 121 public: 122 CexmcPhysicsManager * GetPhysicsManager( void ); 123 124 CexmcProductionModelType GetProductionModelType( void ) const; 125 126 G4String GetGdmlFileName( void ) const; 127 128 G4bool ShouldGdmlFileBeValidated( void ) const; 129 130 G4String GetGuiMacroName( void ) const; 131 132 G4bool ProjectIsSaved( void ) const; 133 134 G4bool ProjectIsRead( void ) const; 135 136 G4String GetProjectsDir( void ) const; 137 138 G4String GetProjectId( void ) const; 139 140 #ifdef CEXMC_USE_PERSISTENCY 141 boost::archive::binary_oarchive * GetEventsArchive( void ) const; 142 143 boost::archive::binary_oarchive * GetFastEventsArchive( void ) const; 144 #endif 145 146 CexmcEventDataVerboseLevel GetEventDataVerboseLevel( void ) const; 147 148 protected: 149 void DoEventLoop( G4int nEvent, const char * macroFile, 150 G4int nSelect ); 151 152 private: 153 void DoCommonEventLoop( G4int nEvent, const G4String & cmd, 154 G4int nSelect ); 155 156 #ifdef CEXMC_USE_PERSISTENCY 157 void DoReadEventLoop( G4int nEvent ); 158 159 void SaveCurrentTPTEvent( const CexmcEventFastSObject & evFastSObject, 160 const CexmcAngularRangeList & angularRanges, 161 G4bool writeToDatabase ); 162 #endif 163 164 private: 165 void ReadPreinitProjectData( void ); 166 167 private: 168 CexmcBasePhysicsUsed basePhysicsUsed; 169 170 CexmcProductionModelType productionModelType; 171 172 G4String gdmlFileName; 173 174 G4bool shouldGdmlFileBeValidated; 175 176 G4bool zipGdmlFile; 177 178 G4String projectsDir; 179 180 G4String projectId; 181 182 G4String rProject; 183 184 G4String guiMacroName; 185 186 G4String cfFileName; 187 188 CexmcEventCountPolicy eventCountPolicy; 189 190 G4bool skipInteractionsWithoutEDTonWrite; 191 192 CexmcEventDataVerboseLevel evDataVerboseLevel; 193 194 CexmcEventDataVerboseLevel rEvDataVerboseLevel; 195 196 private: 197 G4int numberOfEventsProcessed; 198 199 G4int numberOfEventsProcessedEffective; 200 201 G4int curEventRead; 202 203 #ifdef CEXMC_USE_PERSISTENCY 204 private: 205 boost::archive::binary_oarchive * eventsArchive; 206 207 boost::archive::binary_oarchive * fastEventsArchive; 208 209 CexmcRunSObject sObject; 210 211 #ifdef CEXMC_USE_CUSTOM_FILTER 212 CexmcCustomFilterEval * customFilter; 213 #endif 214 #endif 215 216 private: 217 CexmcPhysicsManager * physicsManager; 218 219 private: 220 CexmcRunManagerMessenger * messenger; 221 }; 222 223 224 inline void CexmcRunManager::SetPhysicsManager( 225 CexmcPhysicsManager * physicsManager_ ) 226 { 227 physicsManager = physicsManager_; 228 } 229 230 231 inline void CexmcRunManager::SetProductionModelType( 232 CexmcProductionModelType productionModelType_ ) 233 { 234 if ( ProjectIsRead() ) 235 throw CexmcException( CexmcCmdIsNotAllowed ); 236 237 productionModelType = productionModelType_; 238 } 239 240 241 inline void CexmcRunManager::SetGdmlFileName( const G4String & gdmlFileName_ ) 242 { 243 if ( ProjectIsRead() ) 244 throw CexmcException( CexmcCmdIsNotAllowed ); 245 246 gdmlFileName = gdmlFileName_; 247 } 248 249 250 inline void CexmcRunManager::SetGdmlFileValidation( G4bool on ) 251 { 252 shouldGdmlFileBeValidated = on; 253 } 254 255 256 inline void CexmcRunManager::SetGuiMacroName( const G4String & guiMacroName_ ) 257 { 258 guiMacroName = guiMacroName_; 259 } 260 261 262 inline void CexmcRunManager::SetEventCountPolicy( 263 CexmcEventCountPolicy value ) 264 { 265 if ( ProjectIsRead() ) 266 throw CexmcException( CexmcCmdIsNotAllowed ); 267 268 eventCountPolicy = value; 269 } 270 271 272 inline void CexmcRunManager::SetEventDataVerboseLevel( 273 CexmcEventDataVerboseLevel value ) 274 { 275 if ( ProjectIsRead() && value > rEvDataVerboseLevel ) 276 throw CexmcException( CexmcPoorEventData ); 277 278 evDataVerboseLevel = value; 279 } 280 281 282 inline CexmcPhysicsManager * CexmcRunManager::GetPhysicsManager( void ) 283 { 284 return physicsManager; 285 } 286 287 288 inline CexmcProductionModelType 289 CexmcRunManager::GetProductionModelType( void ) const 290 { 291 return productionModelType; 292 } 293 294 295 inline G4String CexmcRunManager::GetGdmlFileName( void ) const 296 { 297 return gdmlFileName; 298 } 299 300 301 inline G4bool CexmcRunManager::ShouldGdmlFileBeValidated( void ) const 302 { 303 return shouldGdmlFileBeValidated; 304 } 305 306 307 inline G4String CexmcRunManager::GetGuiMacroName( void ) const 308 { 309 return guiMacroName; 310 } 311 312 313 inline G4bool CexmcRunManager::ProjectIsSaved( void ) const 314 { 315 return projectId != ""; 316 } 317 318 319 inline G4bool CexmcRunManager::ProjectIsRead( void ) const 320 { 321 return rProject != ""; 322 } 323 324 325 inline G4String CexmcRunManager::GetProjectsDir( void ) const 326 { 327 return projectsDir; 328 } 329 330 331 inline G4String CexmcRunManager::GetProjectId( void ) const 332 { 333 return projectId; 334 } 335 336 337 #ifdef CEXMC_USE_PERSISTENCY 338 339 inline boost::archive::binary_oarchive * CexmcRunManager::GetEventsArchive( 340 void ) const 341 { 342 return eventsArchive; 343 } 344 345 346 inline boost::archive::binary_oarchive * CexmcRunManager::GetFastEventsArchive( 347 void ) const 348 { 349 return fastEventsArchive; 350 } 351 352 353 inline void CexmcRunManager::ReplayEvents( G4int nEvents ) 354 { 355 if ( ! ProjectIsRead() ) 356 return; 357 358 if ( nEvents == 0 ) 359 nEvents = std::numeric_limits< G4int >::max(); 360 361 BeamOn( nEvents ); 362 } 363 364 365 inline void CexmcRunManager::SeekTo( G4int eventNmb ) 366 { 367 if ( ! ProjectIsRead() ) 368 return; 369 370 curEventRead = eventNmb; 371 } 372 373 374 inline void CexmcRunManager::SkipInteractionsWithoutEDTonWrite( G4bool on ) 375 { 376 skipInteractionsWithoutEDTonWrite = on; 377 } 378 379 #endif 380 381 382 inline CexmcEventDataVerboseLevel CexmcRunManager::GetEventDataVerboseLevel( 383 void ) const 384 { 385 return evDataVerboseLevel; 386 } 387 388 389 #endif 390 391