Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:51:38

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 G4Run* RunAction::GenerateRun()
0053 {
0054   // Generate new RUN object, which is specially
0055   // dedicated to store run-persistent data.
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 {  // sequential mode
0070     if (fIAEAphspWriterStack)
0071       return new IAEAphspRun(fIAEAphspWriterStack);
0072     else
0073       return new IAEAphspRun();
0074   }
0075 }
0076 
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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     // The IAEAphsp files are open at first call of IAEAphspRun::Merge()
0090     iaeaphspWriter->CloseIAEAphspOutFiles();
0091       }
0092     }
0093   }
0094   else {    // sequential mode
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) {  // We defined IAEAphsp stack
0101       iaeaRun->DumpToIAEAphspFiles(phspStack);
0102 
0103       // Update the number of original histories to all files and close
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0127 
0128 void RunAction::SetIAEAphspWriterStack(const G4String& namePrefix)
0129 {
0130   fIAEAphspWriterStack = new G4IAEAphspWriterStack(namePrefix);
0131 }
0132 
0133 
0134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 }