Geant4  10.02.p01
ExG4RunAction01.cc
Go to the documentation of this file.
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 // $Id$
27 //
30 
31 #include "ExG4RunAction01.hh"
32 
33 #include "G4Run.hh"
34 #include "G4RunManager.hh"
35 #include "G4UImanager.hh"
36 #include "G4VVisManager.hh"
37 //#include "G4ios.hh"
38 //#include <iomanip>
39 
40 #include "Randomize.hh"
41 
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
47  : G4UserRunAction(),
48  fMessenger(this),
49  fRndmFileName(fgkDefaultRndmFileName),
50  fVerboseLevel(1),
51  fSaveRndm(false),
52  fReadRndm(false),
53  fAutoSeed(false)
54 {
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
69  if ( fVerboseLevel > 0 ) {
70  G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
71  }
72 
73  // read Rndm status
74  if ( fReadRndm ) {
75  G4cout << "\n---> rndm status restored from file: " << fRndmFileName << G4endl;
76  G4Random::restoreEngineStatus(fRndmFileName);
77  G4Random::showEngineStatus();
78  }
79 
80  // automatic (time-based) random seeds for each run
81  if ( fAutoSeed ) {
84 
85  G4cout << "*******************" << G4endl;
86  G4cout << "*** AUTOSEED ON ***" << G4endl;
87  G4cout << "*******************" << G4endl;
88 
89  long seeds[2];
90  time_t systime = time(NULL);
91  seeds[0] = (long) systime;
92  seeds[1] = (long) (systime*G4UniformRand());
93  G4Random::setTheSeeds(seeds);
94  G4Random::showEngineStatus();
95  }
96 
97  // save Rndm status
98  if ( fSaveRndm ) {
99  G4int runNumber = run->GetRunID();
100  std::ostringstream fileName;
101  fileName << "run" << runNumber << ".rndm";
102  G4Random::saveEngineStatus(fileName.str().c_str());
103  G4Random::showEngineStatus();
104  }
105 
107  G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
108  }
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112 
113 void ExG4RunAction01::EndOfRunAction(const G4Run* run)
114 {
115  // save Rndm status
116  if ( fSaveRndm ) {
117  G4int runNumber = run->GetRunID();
118  std::ostringstream fileName;
119  fileName << "run" << runNumber << "end.rndm";
120  G4Random::saveEngineStatus(fileName.str().c_str());
121  G4Random::showEngineStatus();
122  }
123 
125  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
126  }
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void BeginOfRunAction(const G4Run *run)
static G4VVisManager * GetConcreteInstance()
void SetRandomNumberStore(G4bool flag)
virtual void EndOfRunAction(const G4Run *run)
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
static const G4String fgkDefaultRndmFileName
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
G4String fRndmFileName
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
#define G4endl
Definition: G4ios.hh:61
void SetRandomNumberStoreDir(const G4String &dir)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446