Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
42 const G4String ExG4RunAction01::fgkDefaultRndmFileName = "run0.rndm";
43 
44 //_____________________________________________________________________________
46  : G4UserRunAction(),
47  fMessenger(this),
48  fRndmFileName(fgkDefaultRndmFileName),
49  fVerboseLevel(1),
50  fSaveRndm(false),
51  fReadRndm(false),
52  fAutoSeed(false)
53 {
55 }
56 
57 //_____________________________________________________________________________
59 {
61 }
62 
63 //_____________________________________________________________________________
65 {
66  if ( fVerboseLevel > 0 ) {
67  G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
68  }
69 
70  // read Rndm status
71  if ( fReadRndm ) {
72  G4cout << "\n---> rndm status restored from file: " << fRndmFileName << G4endl;
75  }
76 
77  // automatic (time-based) random seeds for each run
78  if ( fAutoSeed ) {
81 
82  G4cout << "*******************" << G4endl;
83  G4cout << "*** AUTOSEED ON ***" << G4endl;
84  G4cout << "*******************" << G4endl;
85 
86  long seeds[2];
87  time_t systime = time(NULL);
88  seeds[0] = (long) systime;
89  seeds[1] = (long) (systime*G4UniformRand());
92  }
93 
94  // save Rndm status
95  if ( fSaveRndm ) {
96  G4int runNumber = run->GetRunID();
97  std::ostringstream fileName;
98  fileName << "run" << runNumber << ".rndm";
99  CLHEP::HepRandom::saveEngineStatus(fileName.str().c_str());
101  }
102 
104  G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
105  }
106 }
107 
108 //_____________________________________________________________________________
110 {
111  // save Rndm status
112  if ( fSaveRndm ) {
113  G4int runNumber = run->GetRunID();
114  std::ostringstream fileName;
115  fileName << "run" << runNumber << "end.rndm";
116  CLHEP::HepRandom::saveEngineStatus(fileName.str().c_str());
118  }
119 
121  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
122  }
123 }