Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4Hdf5NtupleManager.hh
이 파일의 문서화 페이지로 가기
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 // $Id$
27 
28 // Manager class for Hdf5 ntuples
29 //
30 // Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
31 
32 #ifndef G4Hdf5NtupleManager_h
33 #define G4Hdf5NtupleManager_h 1
34 
35 #include "G4TNtupleManager.hh"
36 #include "globals.hh"
37 
38 #include "tools/hdf5/ntuple"
39 
40 #include <vector>
41 #include <memory>
42 
43 class G4Hdf5FileManager;
44 
45 // template specialization used by this class defined below
46 
47 template <>
48 template <>
50  G4int ntupleId, G4int columnId, const std::string& value);
51 
52 
53 class G4Hdf5NtupleManager : public G4TNtupleManager<tools::hdf5::ntuple>
54 {
55  friend class G4Hdf5AnalysisManager;
56 
57  public:
58  explicit G4Hdf5NtupleManager(const G4AnalysisManagerState& state);
60 
61  private:
62  // Types alias
65 
66  // Set methods
67  void SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager);
68 
69  // Access to ntuple vector (needed for Write())
70  const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector() const;
71 
72  // Methods from the templated base class
73  //
74  virtual void CreateTNtuple(
75  NtupleDescriptionType* ntupleDescription,
76  const G4String& name, const G4String& title) final;
77  virtual void CreateTNtupleFromBooking(
78  NtupleDescriptionType* ntupleDescription) final;
79 
80  virtual void FinishTNtuple(
81  NtupleDescriptionType* ntupleDescription) final;
82 
83  // data members
84  //
85  std::shared_ptr<G4Hdf5FileManager> fFileManager;
86 };
87 
88 // inline functions
89 
90 inline void
91 G4Hdf5NtupleManager::SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager)
92 { fFileManager = fileManager; }
93 
94 inline const std::vector<G4TNtupleDescription<tools::hdf5::ntuple>*>&
96 { return fNtupleDescriptionVector; }
97 
98 template <>
99 template <>
101  G4int ntupleId, G4int columnId, const std::string& value)
102 {
103  if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
104  //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
105  return false;
106  }
107 
108  // get ntuple
109  auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
110  if ( ! ntuple ) return false;
111 
112  // get generic column
113  auto index = columnId - fFirstNtupleColumnId;
114  if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
115  G4ExceptionDescription description;
116  description << " " << "ntupleId " << ntupleId
117  << " columnId " << columnId << " does not exist.";
118  G4Exception("G4TNtupleManager::FillNtupleTColumn()",
119  "Analysis_W011", JustWarning, description);
120  return false;
121  }
122  auto icolumn = ntuple->columns()[index];
123 
124  // get column and check its type
125  auto column = dynamic_cast<tools::hdf5::ntuple::column_string* >(icolumn);
126  if ( ! column ) {
127  G4ExceptionDescription description;
128  description << " Column type does not match: "
129  << " ntupleId " << ntupleId
130  << " columnId " << columnId << " value " << value;
131  G4Exception("G4TNtupleManager:FillNtupleTColumn",
132  "Analysis_W011", JustWarning, description);
133  return false;
134  }
135 
136  column->fill(value);
137 
138 #ifdef G4VERBOSE
139  if ( fState.GetVerboseL4() ) {
140  G4ExceptionDescription description;
141  description << " ntupleId " << ntupleId
142  << " columnId " << columnId << " value " << value;
143  fState.GetVerboseL4()->Message("fill", "ntuple T column", description);
144  }
145 #endif
146  return true;
147 }
148 
149 #endif
150 
std::vector< G4TNtupleDescription< tools::hdf5::ntuple > * > fNtupleDescriptionVector
const XML_Char * name
Definition: expat.h:151
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
TTree * ntuple
virtual G4bool GetActivation(G4int ntupleId) const final
std::shared_ptr< G4Hdf5FileManager > fFileManager
G4Hdf5NtupleManager(const G4AnalysisManagerState &state)
TNTUPLE * GetNtupleInFunction(G4int id, G4String function, G4bool warn=true) const
bool G4bool
Definition: G4Types.hh:79
virtual void CreateTNtupleFromBooking(NtupleDescriptionType *ntupleDescription) final
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T &value)
const G4AnalysisVerbose * GetVerboseL4() const
virtual void CreateTNtuple(NtupleDescriptionType *ntupleDescription, const G4String &name, const G4String &title) final
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
virtual void FinishTNtuple(NtupleDescriptionType *ntupleDescription) final
const std::vector< NtupleDescriptionType * > & GetNtupleDescriptionVector() const
tools::hdf5::ntuple NtupleType
void SetFileManager(std::shared_ptr< G4Hdf5FileManager > fileManager)
const G4AnalysisManagerState & fState