Loading...
Searching...
No Matches
G4RootMpiAnalysisManager.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
27// Author: Ivana Hrivnacova, 21/11/2018 (ivana@ipno.in2p3.fr)
28
33#include "G4AnalysisUtilities.hh"
34
35#include <tools/impi>
36
37using namespace G4Analysis;
38
39//_____________________________________________________________________________
44
45//_____________________________________________________________________________
48{
49 fgInstance = this;
50
51 // Reset the ntuple file manager
52 fNtupleFileManager.reset();
53
54 // Ntuple file manager
55 fNtupleFileManager = std::make_shared<G4RootMpiNtupleFileManager>(fState);
56 SetNtupleFileManager(fNtupleFileManager);
57 fNtupleFileManager->SetFileManager(fFileManager);
58 fNtupleFileManager->SetBookingManager(fNtupleBookingManager);
59}
60
61//_____________________________________________________________________________
66
67//
68// public methods
69//
70
71//_____________________________________________________________________________
73 G4int mpiRank, G4int mpiSize,
74 G4int nofNtupleFiles)
75{
76 // G4cout << "SetMpiNtupleMerging: "
77 // << impi << ", "
78 // << mpiRank << ","
79 // << mpiSize << ","
80 // << nofNtupleFiles << G4endl;
81
82 std::static_pointer_cast<G4RootMpiNtupleFileManager>(fNtupleFileManager)
83 ->SetMpiNtupleMerging(impi, mpiRank, mpiSize, nofNtupleFiles);
84}
85
86//
87// protected methods
88//
89
90//_____________________________________________________________________________
92{
93 if ( fNtupleFileManager->GetMergeMode() == G4NtupleMergeMode::kNone ) {
94 return G4ToolsAnalysisManager::OpenFileImpl(fileName);
95 }
96
97 // Create ntuple manager(s)
98 // and set it to base class which takes then their ownership
99 if ( ! fVNtupleManager ) {
100 SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
101 }
102
103 auto result = true;
104
105 // Open file
106 // In difference from base class a file is open also on slave ranks
107 result &= fFileManager->OpenFile(fileName);
108
109 // Open ntuple file(s) and create ntuples from bookings
110 result &= fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
111
112 return result;
113}
114
115//_____________________________________________________________________________
117{
118
119 auto result = true;
120
121 // Call base class method
122 result &= G4ToolsAnalysisManager::WriteImpl();
123
124 // Write file also on Slave
125 // (skipped in base class)
126 if ( fNtupleFileManager->GetMergeMode() == G4NtupleMergeMode::kSlave ) {
127 // write all open files
128 result &= fFileManager->WriteFiles();
129 }
130
131 Message(kVL2, "write", "slave files", "", result);
132
133 return result;
134}
135
136//_____________________________________________________________________________
138{
139// Cannot call base class function, as we need to close files also
140// on slave; an option in the base class can be added for this in future
141
142 Message(kVL4, "close", "files");
143
144 auto result = true;
145 if (fVNtupleFileManager) {
146 result &= fVNtupleFileManager->ActionAtCloseFile();
147 }
148
149 // close file also on Slave
150 // - the conditoon used in the base class is commented out
151 // if ( (fVNtupleFileManager == nullptr) ||
152 // (fVNtupleFileManager->GetMergeMode() != G4NtupleMergeMode::kSlave) ) {
153 if ( ! fVFileManager->CloseFiles() ) {
154 Warn("Closing files failed", fkClass, "CloseFileImpl");
155 result = false;
156 }
157 // }
158
159 // delete empty files
160 if ( ! fVFileManager->DeleteEmptyFiles() ) {
161 Warn("Deleting empty files failed", fkClass, "CloseFileImpl");
162 result = false;
163 }
164
165 // reset histograms
166 if ( reset ) {
167 if ( ! Reset() ) {
168 Warn("Resetting data failed", fkClass, "CloseFileImpl");
169 result = false;
170 }
171 }
172
173 Message(kVL3, "close", "files", "", result);
174 G4cout << "### Done G4RootMpiAnalysisManager::CloseFileImpl" << G4endl;
175
176 return result;
177}
void SetMpiNtupleMerging(tools::impi *impi, G4int mpiRank, G4int mpiSize, G4int nofReducedNtupleFiles=0)
G4RootMpiAnalysisManager(G4bool isMaster=true)
virtual G4bool OpenFileImpl(const G4String &fileName) final
static G4RootMpiAnalysisManager * fgInstance
static G4RootMpiAnalysisManager * Instance()
virtual G4bool CloseFileImpl(G4bool reset) final

Applications | User Support | Publications | Collaboration