Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4XmlNtupleFileManager.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, 18/06/2013 ([email protected])
28
30#include "G4XmlFileManager.hh"
31#include "G4XmlNtupleManager.hh"
34#include "G4Threading.hh"
35#include "G4AutoLock.hh"
36
37using std::make_shared;
38
39//_____________________________________________________________________________
41 : G4VNtupleFileManager(state, "csv"),
42 fFileManager(nullptr),
43 fNtupleManager(nullptr)
44{}
45
46//_____________________________________________________________________________
48{}
49
50//
51// private methods
52//
53
54//_____________________________________________________________________________
55G4bool G4XmlNtupleFileManager::CloseNtupleFiles()
56{
57 // Close ntuple files
58
59 auto finalResult = true;
60 auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
61 for ( auto ntupleDescription : ntupleVector) {
62 auto result = fFileManager->CloseNtupleFile(ntupleDescription);
63 finalResult = finalResult && result;
64 }
65
66 return finalResult;
67}
68
69//
70// public methods
71//
72
73//_____________________________________________________________________________
74std::shared_ptr<G4VNtupleManager> G4XmlNtupleFileManager::CreateNtupleManager()
75{
76 fNtupleManager = std::make_shared<G4XmlNtupleManager>(fState);
77 fNtupleManager->SetFileManager(fFileManager);
78
79 return fNtupleManager;
80}
81
82//_____________________________________________________________________________
84{
85 // Create ntuples if they are booked
86 // (The files will be created with creating ntuples)
87 fNtupleManager->CreateNtuplesFromBooking(
88 fBookingManager->GetNtupleBookingVector());
89
90 return true;
91}
92
93//_____________________________________________________________________________
95{
96 auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
97
98 for ( auto ntuple : ntupleVector ) {
99 if ( ntuple->fNtuple ) ntuple->fNtuple->write_trailer();
100 }
101
102 return true;
103}
104
105//_____________________________________________________________________________
107{
108 auto finalResult = true;
109
110 // Close ntuple files
111 auto result = CloseNtupleFiles();
112 finalResult = finalResult && result;
113
114 // Reset data
115 if ( ! reset ) {
116 result = Reset();
117 if ( ! result ) {
118 G4ExceptionDescription description;
119 description << " " << "Resetting data failed";
120 G4Exception("G4XmlNtupleFileManager::CloseFile()",
121 "Analysis_W021", JustWarning, description);
122 }
123 finalResult = finalResult && result;
124 }
125
126 return finalResult;
127}
128
129//_____________________________________________________________________________
131{
132// Reset histograms and ntuple
133
134 return fNtupleManager->Reset(true);
135}
136
@ 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
std::shared_ptr< G4NtupleBookingManager > fBookingManager
const G4AnalysisManagerState & fState
virtual G4bool ActionAtOpenFile(const G4String &fileName) override
G4XmlNtupleFileManager(const G4AnalysisManagerState &state)
virtual G4bool Reset() override
virtual G4bool ActionAtWrite() override
virtual std::shared_ptr< G4VNtupleManager > CreateNtupleManager() override
virtual G4bool ActionAtCloseFile(G4bool reset) override