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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #ifndef G4RunManager_h
00068 #define G4RunManager_h 1
00069
00070
00071 class G4VUserDetectorConstruction;
00072 class G4VUserPhysicsList;
00073 class G4UserRunAction;
00074 class G4VUserPrimaryGeneratorAction;
00075 class G4UserEventAction;
00076 class G4UserStackingAction;
00077 class G4UserTrackingAction;
00078 class G4UserSteppingAction;
00079
00080 class G4VPhysicalVolume;
00081 class G4LogicalVolume;
00082 class G4Region;
00083 class G4Timer;
00084 class G4RunMessenger;
00085 class G4DCtable;
00086 class G4Run;
00087 class G4PrimaryTransformer;
00088
00089 #include "G4RunManagerKernel.hh"
00090 #include "G4Event.hh"
00091 #include "G4EventManager.hh"
00092 #include "globals.hh"
00093 #include <vector>
00094 #include <algorithm>
00095
00096 class G4RunManager
00097 {
00098 public:
00099 static G4RunManager* GetRunManager();
00100
00101
00102
00103 private:
00104 static G4RunManager* fRunManager;
00105
00106 public:
00107 G4RunManager();
00108 virtual ~G4RunManager();
00109
00110
00111
00112
00113 public:
00114 virtual void BeamOn(G4int n_event,const char* macroFile=0,G4int n_select=-1);
00115
00116
00117
00118
00119
00120
00121
00122
00123 virtual void Initialize();
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 virtual void DefineWorldVolume(G4VPhysicalVolume * worldVol,
00136 G4bool topologyIsChanged=true);
00137
00138
00139
00140
00141
00143
00144
00145 virtual void AbortRun(G4bool softAbort=false);
00146
00147
00148
00149
00150
00151 virtual void AbortEvent();
00152
00153
00154
00155
00156 public:
00157
00158 virtual void InitializeGeometry();
00159 virtual void InitializePhysics();
00160
00161
00162
00163
00164
00165 virtual G4bool ConfirmBeamOnCondition();
00166 virtual void RunInitialization();
00167 virtual void DoEventLoop(G4int n_event,const char* macroFile=0,G4int n_select=-1);
00168 virtual void RunTermination();
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 virtual void InitializeEventLoop(G4int n_event,const char* macroFile=0,G4int n_select=-1);
00184 virtual void ProcessOneEvent(G4int i_event);
00185 virtual void TerminateOneEvent();
00186 virtual void TerminateEventLoop();
00187
00188
00190
00191
00192 virtual G4Event* GenerateEvent(G4int i_event);
00193 virtual void AnalyzeEvent(G4Event* anEvent);
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 public:
00205
00206
00207
00208
00209
00210 void DumpRegion(const G4String& rname) const;
00211
00212
00213 void DumpRegion(G4Region* region=0) const;
00214
00215
00216
00217 protected:
00218 void StackPreviousEvent(G4Event* anEvent);
00219
00220 protected:
00221 G4RunManagerKernel * kernel;
00222 G4EventManager * eventManager;
00223
00224 G4VUserDetectorConstruction * userDetector;
00225 G4VUserPhysicsList * physicsList;
00226 G4UserRunAction * userRunAction;
00227 G4VUserPrimaryGeneratorAction * userPrimaryGeneratorAction;
00228 G4UserEventAction * userEventAction;
00229 G4UserStackingAction * userStackingAction;
00230 G4UserTrackingAction * userTrackingAction;
00231 G4UserSteppingAction * userSteppingAction;
00232
00233 private:
00234 G4RunMessenger* runMessenger;
00235
00236 protected:
00237 G4bool geometryInitialized;
00238 G4bool physicsInitialized;
00239 G4bool runAborted;
00240 G4bool initializedAtLeastOnce;
00241 G4bool geometryToBeOptimized;
00242
00243 G4int runIDCounter;
00244 G4int verboseLevel;
00245 G4Timer * timer;
00246 G4DCtable* DCtable;
00247
00248 G4Run* currentRun;
00249 G4Event* currentEvent;
00250 std::vector<G4Event*>* previousEvents;
00251 G4int n_perviousEventsToBeStored;
00252 G4int numberOfEventToBeProcessed;
00253
00254 G4bool storeRandomNumberStatus;
00255 G4int storeRandomNumberStatusToG4Event;
00256 G4String randomNumberStatusDir;
00257 G4String randomNumberStatusForThisRun;
00258 G4String randomNumberStatusForThisEvent;
00259
00260 G4VPhysicalVolume* currentWorld;
00261
00262 G4int nParallelWorlds;
00263
00264 G4String msgText;
00265 G4int n_select_msg;
00266 G4int numberOfEventProcessed;
00267
00268 public:
00269 virtual void rndmSaveThisRun();
00270 virtual void rndmSaveThisEvent();
00271 virtual void RestoreRandomNumberStatus(const G4String& fileN);
00272
00273 public:
00274 inline void SetUserInitialization(G4VUserDetectorConstruction* userInit)
00275 { userDetector = userInit; }
00276 inline void SetUserInitialization(G4VUserPhysicsList* userInit)
00277 {
00278 physicsList = userInit;
00279 kernel->SetPhysics(userInit);
00280 }
00281 inline void SetUserAction(G4UserRunAction* userAction)
00282 { userRunAction = userAction; }
00283 inline void SetUserAction(G4VUserPrimaryGeneratorAction* userAction)
00284 { userPrimaryGeneratorAction = userAction; }
00285 inline void SetUserAction(G4UserEventAction* userAction)
00286 {
00287 eventManager->SetUserAction(userAction);
00288 userEventAction = userAction;
00289 }
00290 inline void SetUserAction(G4UserStackingAction* userAction)
00291 {
00292 eventManager->SetUserAction(userAction);
00293 userStackingAction = userAction;
00294 }
00295 inline void SetUserAction(G4UserTrackingAction* userAction)
00296 {
00297 eventManager->SetUserAction(userAction);
00298 userTrackingAction = userAction;
00299 }
00300 inline void SetUserAction(G4UserSteppingAction* userAction)
00301 {
00302 eventManager->SetUserAction(userAction);
00303 userSteppingAction = userAction;
00304 }
00305
00306 inline const G4VUserDetectorConstruction* GetUserDetectorConstruction() const
00307 { return userDetector; }
00308 inline const G4VUserPhysicsList* GetUserPhysicsList() const
00309 { return physicsList; }
00310 inline const G4UserRunAction* GetUserRunAction() const
00311 { return userRunAction; }
00312 inline const G4VUserPrimaryGeneratorAction* GetUserPrimaryGeneratorAction() const
00313 { return userPrimaryGeneratorAction; }
00314 inline const G4UserEventAction* GetUserEventAction() const
00315 { return userEventAction; }
00316 inline const G4UserStackingAction* GetUserStackingAction() const
00317 { return userStackingAction; }
00318 inline const G4UserTrackingAction* GetUserTrackingAction() const
00319 { return userTrackingAction; }
00320 inline const G4UserSteppingAction* GetUserSteppingAction() const
00321 { return userSteppingAction; }
00322
00323
00324 inline void SetNumberOfAdditionalWaitingStacks(G4int iAdd)
00325 { eventManager->SetNumberOfAdditionalWaitingStacks(iAdd); }
00326
00327
00328
00329
00330
00331 inline const G4String& GetVersionString() const
00332 { return kernel->GetVersionString(); }
00333
00334 inline void SetPrimaryTransformer(G4PrimaryTransformer* pt)
00335 { kernel->SetPrimaryTransformer(pt); }
00336
00337 inline void StoreRandomNumberStatusToG4Event(G4int vl)
00338
00339
00340
00341
00342 {
00343 storeRandomNumberStatusToG4Event = vl;
00344 eventManager->StoreRandomNumberStatusToG4Event(vl);
00345 }
00346 inline G4int GetFlagRandomNumberStatusToG4Event() const
00347 { return storeRandomNumberStatusToG4Event; }
00348
00349 public:
00350 inline void SetRandomNumberStore(G4bool flag)
00351 { storeRandomNumberStatus = flag; }
00352 inline G4bool GetRandomNumberStore() const
00353 { return storeRandomNumberStatus; }
00354 inline void SetRandomNumberStoreDir(const G4String& dir)
00355 {
00356 G4String dirStr = dir;
00357 if( dirStr(dirStr.length()-1) != '/' ) dirStr += "/";
00358 #ifndef WIN32
00359 G4String shellCmd = "mkdir -p ";
00360 #else
00361 std::replace(dirStr.begin(), dirStr.end(),'/','\\');
00362 G4String shellCmd = "if not exist " + dirStr + " mkdir ";
00363 #endif
00364 shellCmd += dirStr;
00365 randomNumberStatusDir = dirStr;
00366 G4int sysret = system(shellCmd);
00367 if(sysret!=0)
00368 {
00369 G4String errmsg = "\"" + shellCmd + "\" returns non-zero value. Directory creation failed.";
00370 G4Exception("GrRunManager::SetRandomNumberStoreDir","Run0071",JustWarning,errmsg);
00371 G4cerr << " return value = " << sysret << G4endl;
00372 }
00373 }
00374 inline const G4String& GetRandomNumberStoreDir() const
00375 { return randomNumberStatusDir; }
00376 inline const G4String& GetRandomNumberStatusForThisRun() const
00377 { return randomNumberStatusForThisRun; }
00378 inline const G4String& GetRandomNumberStatusForThisEvent() const
00379 {
00380 if(storeRandomNumberStatusToG4Event==0 || storeRandomNumberStatusToG4Event==2)
00381 { G4Exception("GrRunManager::SetRandomNumberStoreDir",
00382 "Run0072",JustWarning,
00383 "Random number status is not available for this event."); }
00384 return randomNumberStatusForThisEvent;
00385 }
00386
00387 public:
00388 inline void GeometryHasBeenModified()
00389 { kernel->GeometryHasBeenModified(); }
00390
00391
00392
00393
00394
00395 inline void PhysicsHasBeenModified()
00396 { kernel->PhysicsHasBeenModified(); }
00397
00398
00399
00400
00401
00402
00403 inline void CutOffHasBeenModified()
00404 {
00405 G4cerr << "CutOffHasBeenModified becomes obsolete." << G4endl;
00406 G4cerr << "It is safe to remove invoking this method." << G4endl;
00407 }
00408
00409 public:
00410 void ReOptimizeMotherOf(G4VPhysicalVolume*);
00411
00412
00413
00414
00415
00416
00417 void ReOptimize(G4LogicalVolume*);
00418
00419
00420 public:
00421 inline void SetVerboseLevel(G4int vl)
00422 { verboseLevel = vl;
00423 kernel->SetVerboseLevel(vl); }
00424 inline G4int GetVerboseLevel() const
00425 { return verboseLevel; }
00426
00427 inline void SetGeometryToBeOptimized(G4bool vl)
00428 {
00429 if(geometryToBeOptimized != vl)
00430 {
00431 geometryToBeOptimized = vl;
00432 kernel->GeometryHasBeenModified();
00433 kernel->SetGeometryToBeOptimized(vl);
00434 }
00435 }
00436 inline G4bool GetGeometryToBeOptimized()
00437 { return geometryToBeOptimized; }
00438
00439 public:
00440 inline void SetNumberOfEventsToBeStored(G4int val)
00441 { n_perviousEventsToBeStored = val; }
00442
00443
00444
00445
00446 inline const G4Run* GetCurrentRun() const
00447 { return currentRun; }
00448
00449
00450 inline const G4Event* GetCurrentEvent() const
00451 { return currentEvent; }
00452
00453
00454 inline const G4Event* GetPreviousEvent(G4int i) const
00455 {
00456 if(i>=1 && i<=n_perviousEventsToBeStored)
00457 { return (*previousEvents)[i-1]; }
00458 return 0;
00459 }
00460
00461
00462
00463
00464 inline void SetRunIDCounter(G4int i)
00465 { runIDCounter = i; }
00466
00467
00468
00469 public:
00470 inline G4int GetNumberOfParallelWorld() const
00471 { return nParallelWorlds; }
00472 inline void SetNumberOfEventsToBeProcessed(G4int val)
00473 { numberOfEventToBeProcessed = val; }
00474 inline void SetDCtable(G4DCtable* DCtbl)
00475 { DCtable = DCtbl; }
00476
00477 public:
00478 void ConstructScoringWorlds();
00479 protected:
00480 void UpdateScoring();
00481 };
00482
00483 #endif
00484