Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Hdf5NtupleFileManager.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, 15/09/2020 ([email protected])
28
31#include "G4Hdf5FileManager.hh"
34
35#include "G4Threading.hh"
36
37#include <iostream>
38
39using namespace G4Analysis;
40
41//
42// utility methods
43//
44
45//_____________________________________________________________________________
47 : G4VNtupleFileManager(state, "hdf5"),
48 fFileManager(nullptr),
49 fNtupleManager(nullptr)
50{}
51
52//_____________________________________________________________________________
54{}
55
56//
57// private methods
58//
59
60//_____________________________________________________________________________
61G4bool G4Hdf5NtupleFileManager::CloseNtupleFiles()
62{
63 // Close ntuple files
64
65 auto finalResult = true;
66 auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
67 for ( auto ntupleDescription : ntupleVector) {
68 auto result = fFileManager->CloseNtupleFile(ntupleDescription);
69 finalResult = finalResult && result;
70 }
71
72 return finalResult;
73}
74
75//
76// public methods
77//
78
79//_____________________________________________________________________________
80std::shared_ptr<G4VNtupleManager> G4Hdf5NtupleFileManager::CreateNtupleManager()
81{
82
83 // The managers will be deleted by the base class
84 fNtupleManager = std::make_shared<G4Hdf5NtupleManager>(fState);
85 fNtupleManager->SetFileManager(fFileManager);
86
87 return fNtupleManager;
88}
89
90//_____________________________________________________________________________
92{
93 // Create ntuples if they are booked
94 // (The files will be created with creating ntuples)
95 fNtupleManager->CreateNtuplesFromBooking(
96 fBookingManager->GetNtupleBookingVector());
97
98 return true;
99}
100
101//_____________________________________________________________________________
103{
104 // notify that ntuple file is not empty
105
106 auto finalResult = true;
107
108 // Notify that ntuple files are not empty
109 auto ntupleVector
110 = fNtupleManager->GetNtupleDescriptionVector();
111
112 for ( auto ntupleDescription : ntupleVector) {
113 if (ntupleDescription->fFile) {
114 auto result = fFileManager->SetIsEmpty(ntupleDescription->fFileName, false);
115 finalResult = finalResult && result;
116 }
117 }
118
119 return finalResult;
120}
121
122//_____________________________________________________________________________
124{
125 auto finalResult = true;
126
127 // Close ntuple files
128 auto result = CloseNtupleFiles();
129 finalResult = finalResult && result;
130
131 if ( ! reset ) {
132 // The ntuples must be always reset when closing file)
133 result = Reset();
134 if ( ! result ) {
135 G4ExceptionDescription description;
136 description << " " << "Resetting data failed";
137 G4Exception("G4Hdf5NtupleFileManager::CloseFile()",
138 "Analysis_W021", JustWarning, description);
139 }
140 finalResult = finalResult && result;
141 }
142
143 return finalResult;
144}
145
146//_____________________________________________________________________________
148{
149 return fNtupleManager->Reset(true);
150}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
G4Hdf5NtupleFileManager(const G4AnalysisManagerState &state)
virtual std::shared_ptr< G4VNtupleManager > CreateNtupleManager() override
virtual G4bool ActionAtOpenFile(const G4String &fileName) override
virtual G4bool ActionAtWrite() override
virtual G4bool Reset() override
virtual G4bool ActionAtCloseFile(G4bool reset) override
std::shared_ptr< G4NtupleBookingManager > fBookingManager
const G4AnalysisManagerState & fState