EDepSimUserRunAction.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////
2 // $Id: EDepSim::UserRunAction.cc,v 1.12 2011/07/19 20:55:13 mcgrew Exp $
3 //
4 
5 #include <ctime>
6 #include <sys/time.h>
7 
8 #include <Randomize.hh>
9 #include <G4Run.hh>
10 #include <G4RunManager.hh>
11 #include <G4UImanager.hh>
12 #include <G4VVisManager.hh>
13 #include <G4ios.hh>
14 #include <G4Timer.hh>
15 
16 #include <EDepSimLog.hh>
17 
18 #include "EDepSimUserRunAction.hh"
20 
22  : fStartTime("invalid"), fStopTime("invalid"), fSubrunId(-1) {
23  fTimer = new G4Timer;
25 }
26 
28  delete fTimer;
29  delete fMessenger;
30 }
31 
33  // Initialize the run header
34  time_t ltime = time(NULL);
35  fStartTime = ctime(&ltime);
36  fTimer->Start();
37 
38 #ifdef UPDATE_VISUALIZATION
39  if (G4VVisManager::GetConcreteInstance()) {
40  G4UImanager* UI = G4UImanager::GetUIpointer();
41  UI->ApplyCommand("/vis/scene/notifyHandlers");
42  }
43 #endif
44 
45  EDepSimLog("### Run " << aRun->GetRunID() << " starting.");
46 
47 }
48 
49 void EDepSim::UserRunAction::EndOfRunAction(const G4Run* aRun) {
50  fTimer->Stop();
51  time_t ltime = time(NULL);
52  fStopTime = ctime(&ltime);
53 
54  EDepSimLog("### Run " << aRun->GetRunID() << " ending.");
55  EDepSimLog("Number of events = " << aRun->GetNumberOfEvent());
57 
58 
59 #ifdef UPDATE_VISUALIZATION
60  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
61 
62  if( pVVisManager ) {
63  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
64  }
65 #endif
66 }
67 
69  if (seed<0) seed = -seed;
70  EDepSimLog("### Random seed number set to: " << seed);
71  G4Random::setTheSeed(seed);
72 }
73 
74 
76  return G4Random::getTheSeed();
77 }
78 
80  long seed = 0;
81 #ifdef __USE_POSIX
82  struct timeval buffer;
83  gettimeofday(&buffer,NULL);
84  EDepSimLog("### Set seed from local time: " << ctime(&buffer.tv_sec));
85  EDepSimLog("### Micro-second offset: " << buffer.tv_usec);
86  seed = long(buffer.tv_sec + buffer.tv_usec);
87 #else
88 #warning Using seconds since epoch to seed the random generator.
89  seed = time(NULL);
90 #endif
91  // Make sure the seed is positive;
92  if (seed<0) seed = -seed;
93  // Make sure the seed isn't too large.
94  seed = seed % (2l<<(8*sizeof(long)-4));
95  // Make sure the seed is odd and not zero.
96  seed += (seed % 2) + 1;
97  SetSeed(long(seed));
98  // Condition the seed.
99  for (int i=0; i<10000000; ++i) G4UniformRand();
100 }
101 
103  G4RunManager* manager = G4RunManager::GetRunManager();
104  manager->SetRunIDCounter(v);
105 }
106 
108  fSubrunId = v;
109 }
110 
112  return fSubrunId;
113 }
#define EDepSimLog(outStream)
Definition: EDepSimLog.hh:717
int GetDetSimSubrunId() const
Get the subrun id value.
EDepSim::UserRunActionMessenger * fMessenger
The messenger for this action.
void EndOfRunAction(const G4Run *)
G4Timer * fTimer
The running time for the run.
G4String fStopTime
The time that the run was stopped.
static QStrList * l
Definition: config.cpp:1044
void SetTimeSeed()
Build a seed for the generator based on the system time.
int fSubrunId
The cached value of the subrun id.
void BeginOfRunAction(const G4Run *)
G4String fStartTime
The time that the run was started.
int gettimeofday(struct timeval *, struct timezone *)
long GetSeed(void) const
Get the seed that started the low level random generator.