File indexing completed on 2026-04-17 07:51:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include "RunAction.hh"
0029
0030 #include "globals.hh"
0031 #include "G4Threading.hh"
0032
0033 #include "G4IAEAphspWriter.hh"
0034 #include "G4IAEAphspWriterStack.hh"
0035 #include "IAEAphspRun.hh"
0036
0037
0038
0039
0040 RunAction::~RunAction()
0041 {
0042 G4cout << "Destroying RunAction object" << G4endl;
0043 if (fIAEAphspWriterStack) {
0044 fIAEAphspWriterStack->ClearZphspVec();
0045 delete fIAEAphspWriterStack;
0046 }
0047 }
0048
0049
0050
0051
0052 G4Run* RunAction::GenerateRun()
0053 {
0054
0055
0056
0057 if ( G4Threading::IsMultithreadedApplication() ) {
0058 if (!(IsMaster()) && fIAEAphspWriterStack ) {
0059 G4cout << "Generating a worker IAEAphspRun with IAEAphspWriterStack!!"
0060 << G4endl;
0061 return new IAEAphspRun(fIAEAphspWriterStack);
0062 }
0063 else {
0064 if (IsMaster()) G4cout << "Generating a master IAEAphspRun!!" << G4endl;
0065 else G4cout << "Generating a worker IAEAphspRun!!" << G4endl;
0066 return new IAEAphspRun();
0067 }
0068 }
0069 else {
0070 if (fIAEAphspWriterStack)
0071 return new IAEAphspRun(fIAEAphspWriterStack);
0072 else
0073 return new IAEAphspRun();
0074 }
0075 }
0076
0077
0078
0079
0080 void RunAction::EndOfRunAction(const G4Run* aRun)
0081 {
0082 G4cout << "RunAction::EndOfRunAction() " << G4endl;
0083
0084 if ( G4Threading::IsMultithreadedApplication() ) {
0085 if (IsMaster()) {
0086 auto masterRun = static_cast<const IAEAphspRun*>(aRun);
0087 auto iaeaphspWriter = masterRun->GetIAEAphspWriter();
0088 if (iaeaphspWriter) {
0089
0090 iaeaphspWriter->CloseIAEAphspOutFiles();
0091 }
0092 }
0093 }
0094 else {
0095 const IAEAphspRun* constRun = dynamic_cast<const IAEAphspRun*>(aRun);
0096 IAEAphspRun* iaeaRun = const_cast<IAEAphspRun*>(constRun);
0097
0098 auto phspStack = iaeaRun->GetIAEAphspWriterStack();
0099
0100 if (phspStack) {
0101 iaeaRun->DumpToIAEAphspFiles(phspStack);
0102
0103
0104 const G4int histories = iaeaRun->GetNumberOfEvent();
0105 const size_t nPhsp = phspStack->GetZphspVec()->size();
0106 auto iaeaphspWriter = iaeaRun->GetIAEAphspWriter();
0107 if (iaeaphspWriter) {
0108 for (size_t jj = 0; jj < nPhsp; jj++)
0109 iaeaphspWriter->SumOrigHistories(jj, histories);
0110
0111 iaeaphspWriter->CloseIAEAphspOutFiles();
0112 }
0113 else {
0114 G4ExceptionDescription msg;
0115 msg << "Could not get G4IAEAphspWriter object after dumping info"
0116 << "from G4IAEAphspWriterStack."
0117 << G4endl;
0118 G4Exception("RunAction::EndOfRunAction()",
0119 "RunAction001", FatalException, msg);
0120 }
0121 }
0122 }
0123 }
0124
0125
0126
0127
0128 void RunAction::SetIAEAphspWriterStack(const G4String& namePrefix)
0129 {
0130 fIAEAphspWriterStack = new G4IAEAphspWriterStack(namePrefix);
0131 }
0132
0133
0134
0135
0136 void RunAction::AddZphsp(const G4double val)
0137 {
0138 if (fIAEAphspWriterStack) {
0139 fIAEAphspWriterStack->AddZphsp(val);
0140 }
0141 else {
0142 G4ExceptionDescription msg;
0143 msg << "z_phsp value passed, but no IAEAphsp output file name provided!"
0144 << G4endl;
0145 G4Exception("RunAction::AddZphsp()",
0146 "RunAction002", FatalException, msg);
0147 }
0148 }