Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Hdf5NtupleManager.hh
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// Manager class for Hdf5 ntuples
28//
29// Author: Ivana Hrivnacova, 20/07/2017 ([email protected])
30
31#ifndef G4Hdf5NtupleManager_h
32#define G4Hdf5NtupleManager_h 1
33
34#include "G4TNtupleManager.hh"
36#include "globals.hh"
37
38#include "toolx/hdf5/ntuple"
39
40#include <memory>
41#include <utility>
42#include <vector>
43
45
46// Types alias
47using G4Hdf5File = std::tuple<hid_t, hid_t, hid_t>;
49
50// template specialization used by this class defined below
51
52template <>
53template <>
55 G4int ntupleId, G4int columnId, const std::string& value);
56
57
58class G4Hdf5NtupleManager : public G4TNtupleManager<toolx::hdf5::ntuple,
59 G4Hdf5File>
60{
63
64 public:
65 explicit G4Hdf5NtupleManager(const G4AnalysisManagerState& state);
67 ~G4Hdf5NtupleManager() override = default;
68
69 private:
70 // Set methods
71 void SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager);
72
73 // Access to ntuple vector (needed for Write())
74 const std::vector<Hdf5NtupleDescription*>& GetNtupleDescriptionVector() const;
75
76 // Utility function
77 void CreateTNtuple(Hdf5NtupleDescription* ntupleDescription, G4bool warn);
78
79 // Methods from the templated base class
80 //
81 void CreateTNtupleFromBooking(Hdf5NtupleDescription* ntupleDescription) final;
82
83 void FinishTNtuple(Hdf5NtupleDescription* ntupleDescription, G4bool fromBooking) final;
84
85 // Static data members
86 static constexpr std::string_view fkClass { "G4Hdf5NtupleManager" };
87
88 // Data members
89 std::shared_ptr<G4Hdf5FileManager> fFileManager { nullptr };
90};
91
92// inline functions
93
94using std::to_string;
95
96inline void
97G4Hdf5NtupleManager::SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager)
98{
99 fFileManager = std::move(fileManager);
100}
101
102inline const std::vector<Hdf5NtupleDescription*>&
103G4Hdf5NtupleManager::GetNtupleDescriptionVector() const
104{ return fNtupleDescriptionVector; }
105
106template <>
107template <>
109 G4int ntupleId, G4int columnId, const std::string& value)
110{
111 if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
112 //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
113 return false;
114 }
115
116 // get ntuple
117 auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
118 if (ntuple == nullptr) return false;
119
120 // get generic column
121 auto index = columnId - fFirstNtupleColumnId;
122 if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
124 "ntupleId " + to_string(ntupleId) + " columnId " + to_string(columnId) +
125 " does not exist.", fkClass, "FillNtupleTColumn");
126 return false;
127 }
128 auto icolumn = ntuple->columns()[index];
129
130 // get column and check its type
131 auto column = dynamic_cast<toolx::hdf5::ntuple::column_string* >(icolumn);
132 if (column == nullptr) {
134 "Column type does not match: ntupleId " + to_string(ntupleId) +
135 " columnId " + to_string(columnId) + " value " + value,
136 fkClass, "FillNtupleTColumn");
137 return false;
138 }
139
140 column->fill(value);
141
142 if ( IsVerbose(G4Analysis::kVL4) ) {
143 Message(G4Analysis::kVL4, "fill", "ntuple T column",
144 " ntupleId " + to_string(ntupleId) +
145 " columnId " + to_string(columnId) +
146 " value " + G4Analysis::ToString(value));
147 }
148
149 return true;
150}
151
152#endif
std::tuple< hid_t, hid_t, hid_t > G4Hdf5File
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
~G4Hdf5NtupleManager() override=default
G4Hdf5NtupleManager()=delete
std::vector< G4TNtupleDescription< toolx::hdf5::ntuple, G4Hdf5File > * > fNtupleDescriptionVector
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
const G4AnalysisManagerState & fState
std::string ToString(const T &value)
constexpr G4int kVL4
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)