Geant4 10.7.0
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"
35#include "globals.hh"
36
37#include "tools/hdf5/ntuple"
38
39#include <vector>
40#include <memory>
41
43
44// Types alias
45using G4Hdf5File = std::tuple<hid_t, hid_t, hid_t>;
47
48// template specialization used by this class defined below
49
50template <>
51template <>
53 G4int ntupleId, G4int columnId, const std::string& value);
54
55
56class G4Hdf5NtupleManager : public G4TNtupleManager<tools::hdf5::ntuple,
57 G4Hdf5File>
58{
61
62 public:
63 explicit G4Hdf5NtupleManager(const G4AnalysisManagerState& state);
65
66 private:
67 // Set methods
68 void SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager);
69
70 // Access to ntuple vector (needed for Write())
71 const std::vector<Hdf5NtupleDescription*>& GetNtupleDescriptionVector() const;
72
73 // Utility function
74 void CreateTNtuple(Hdf5NtupleDescription* ntupleDescription, G4bool warn);
75
76 // Methods from the templated base class
77 //
78 virtual void CreateTNtupleFromBooking(
79 Hdf5NtupleDescription* ntupleDescription) final;
80
81 virtual void FinishTNtuple(
82 Hdf5NtupleDescription* ntupleDescription,
83 G4bool fromBooking) final;
84
85 // data members
86 //
87 std::shared_ptr<G4Hdf5FileManager> fFileManager;
88};
89
90// inline functions
91
92inline void
93G4Hdf5NtupleManager::SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager)
94{ fFileManager = fileManager; }
95
96inline const std::vector<Hdf5NtupleDescription*>&
97G4Hdf5NtupleManager::GetNtupleDescriptionVector() const
99
100template <>
101template <>
103 G4int ntupleId, G4int columnId, const std::string& value)
104{
105 if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
106 //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
107 return false;
108 }
109
110 // get ntuple
111 auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
112 if ( ! ntuple ) return false;
113
114 // get generic column
115 auto index = columnId - fFirstNtupleColumnId;
116 if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
117 G4ExceptionDescription description;
118 description << " " << "ntupleId " << ntupleId
119 << " columnId " << columnId << " does not exist.";
120 G4Exception("G4TNtupleManager::FillNtupleTColumn()",
121 "Analysis_W011", JustWarning, description);
122 return false;
123 }
124 auto icolumn = ntuple->columns()[index];
125
126 // get column and check its type
127 auto column = dynamic_cast<tools::hdf5::ntuple::column_string* >(icolumn);
128 if ( ! column ) {
129 G4ExceptionDescription description;
130 description << " Column type does not match: "
131 << " ntupleId " << ntupleId
132 << " columnId " << columnId << " value " << value;
133 G4Exception("G4TNtupleManager:FillNtupleTColumn",
134 "Analysis_W011", JustWarning, description);
135 return false;
136 }
137
138 column->fill(value);
139
140#ifdef G4VERBOSE
141 if ( fState.GetVerboseL4() ) {
142 G4ExceptionDescription description;
143 description << " ntupleId " << ntupleId
144 << " columnId " << columnId << " value " << value;
145 fState.GetVerboseL4()->Message("fill", "ntuple T column", description);
146 }
147#endif
148 return true;
149}
150
151#endif
@ 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
std::tuple< hid_t, hid_t, hid_t > G4Hdf5File
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
std::vector< G4TNtupleDescription< tools::hdf5::ntuple, G4Hdf5File > * > fNtupleDescriptionVector
const G4AnalysisManagerState & fState