Geant4  10.02
RunActionMaster.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: RunActionMaster.cc 82310 2014-06-14 00:27:39Z adotti $
27 //
30 
31 #include "G4MPImanager.hh"
32 #include <stdio.h>
33 #include "G4Threading.hh"
34 #include "Analysis.hh"
35 #include "RunActionMaster.hh"
36 #include "g4root.hh" //ROOT Format for output
37 #include "RunMerger.hh"
38 #include "G4MPIscorerMerger.hh"
39 #include "G4MPIhistoMerger.hh" // New code with use of g4analysis
40 #include "Run.hh"
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 {
45 }
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 {
50  return new Run;
51 }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 {
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 void
61 {
63  myana-> Clear();
64  myana->Book();
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 void
70 {
71  //This is executed by master thread. Workers have already
72  //merged their histograms into this master threads
73  G4int rank = G4MPImanager::GetManager()-> GetRank();
74 
75  //Save histograms before MPI merging
76  if (rank == 0)
77  {
78  G4String fname("dose-rank000");
80  myana-> Save(fname);
81  }
82 
83  G4cout << "======================================";
84  G4cout << "===========" << G4endl;
85  G4cout << "Start EndOfRunAction for master thread in rank: " << rank<<G4endl;
86  G4cout << "======================================";
87  G4cout << "===========" << G4endl;
88 
89  //Merging of G4Run object:
90  //All ranks > 0 merge to rank #0
91  RunMerger rm(static_cast<const Run*>(arun));
92  G4int ver = 0 ; //Use 4 for lots of info
93  if ( rank == 0 && ver == 0) ver = 1;
94 
95  if ( ver > 1 ) {
96  G4cout<<"Before merge the Run object has test counter value: "
97  <<static_cast<const Run*>(arun)->GetCounter()<<G4endl;
98  }
99  rm.SetVerbosity( ver );
100  rm.Merge();
101  if ( ver > 1 ) {
102  G4cout<<"After merge the Run object has test counter value: "
103  <<static_cast<const Run*>(arun)->GetCounter()
104  <<" (with 1 thread== number of ranks)"<<G4endl;
105  }
106 
107  //Merge of scorers
108  //ver = 0;
110  {
112  sm.SetVerbosity(ver);
113  sm.Merge();
114  }
115 
116  //Merge of g4analysis objects
117  ver=0;
118  G4MPIhistoMerger hm(G4AnalysisManager::Instance());
119  hm.SetVerbosity(ver);
120  hm.Merge();
121 
122  G4cout << "======================================";
123  G4cout << "==========" << G4endl;
124  G4cout << "End EndOfRunAction for master thread in rank: " << rank << G4endl;
125  G4cout << "======================================";
126  G4cout << "==========" << G4endl;
127 
128  //Save g4analysis objects to a file
129  //NB: It is important that the save is done *after* MPI-merging of histograms
130 
131  //One can save all ranks or just rank0: remember in case of all ranks,
132  //the file of rank0 contains the sum of everything
133  if (true /*rank == 0*/)
134  {
135  char str[64];
136  sprintf(str, "dose-rank%03d", rank);
137  G4String fname(str);
138  if (rank == 0)
139  fname = "dose-merged";
140  Analysis* myana = Analysis::GetAnalysis();
141  myana-> Save(fname);
142  }
143  Analysis* myana = Analysis::GetAnalysis();
144  myana-> Close();
145 }
virtual void EndOfRunAction(const G4Run *arun)
void Clear(Node *)
int G4int
Definition: G4Types.hh:78
void SetVerbosity(G4int ver)
G4GLOB_DLL std::ostream G4cout
static G4ScoringManager * GetScoringManagerIfExist()
MPI manager class.
static Analysis * GetAnalysis()
Definition: Analysis.cc:45
Describe run actions.
Definition: G4Run.hh:46
void Book()
Definition: Analysis.cc:65
static G4MPImanager * GetManager()
virtual G4Run * GenerateRun()
void SetVerbosity(G4int ver)
virtual void BeginOfRunAction(const G4Run *arun)
#define G4endl
Definition: G4ios.hh:61
void SetVerbosity(G4int ver)
Definition: Run.hh:46