ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Hdf5NtupleManager.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 
27 // Manager class for Hdf5 ntuples
28 //
29 // Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
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 
42 class G4Hdf5FileManager;
43 
44 // template specialization used by this class defined below
45 
46 template <>
47 template <>
49  G4int ntupleId, G4int columnId, const std::string& value);
50 
51 
52 class G4Hdf5NtupleManager : public G4TNtupleManager<tools::hdf5::ntuple>
53 {
54  friend class G4Hdf5AnalysisManager;
55 
56  public:
57  explicit G4Hdf5NtupleManager(const G4AnalysisManagerState& state);
59 
60  private:
61  // Types alias
64 
65  // Set methods
66  void SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager);
67 
68  // Access to ntuple vector (needed for Write())
69  const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector() const;
70 
71  // Utility function
72  void CreateTNtuple(NtupleDescriptionType* ntupleDescription, G4bool warn);
73 
74  // Methods from the templated base class
75  //
76  virtual void CreateTNtuple(
77  NtupleDescriptionType* ntupleDescription,
78  const G4String& name, const G4String& title) final;
79  virtual void CreateTNtupleFromBooking(
80  NtupleDescriptionType* ntupleDescription) final;
81 
82  virtual void FinishTNtuple(
83  NtupleDescriptionType* ntupleDescription,
84  G4bool fromBooking) final;
85 
86  // data members
87  //
88  std::shared_ptr<G4Hdf5FileManager> fFileManager;
89 };
90 
91 // inline functions
92 
93 inline void
94 G4Hdf5NtupleManager::SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager)
95 { fFileManager = fileManager; }
96 
97 inline const std::vector<G4TNtupleDescription<tools::hdf5::ntuple>*>&
99 { return fNtupleDescriptionVector; }
100 
101 template <>
102 template <>
104  G4int ntupleId, G4int columnId, const std::string& value)
105 {
106  if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
107  //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
108  return false;
109  }
110 
111  // get ntuple
112  auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
113  if ( ! ntuple ) return false;
114 
115  // get generic column
116  auto index = columnId - fFirstNtupleColumnId;
117  if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
118  G4ExceptionDescription description;
119  description << " " << "ntupleId " << ntupleId
120  << " columnId " << columnId << " does not exist.";
121  G4Exception("G4TNtupleManager::FillNtupleTColumn()",
122  "Analysis_W011", JustWarning, description);
123  return false;
124  }
125  auto icolumn = ntuple->columns()[index];
126 
127  // get column and check its type
128  auto column = dynamic_cast<tools::hdf5::ntuple::column_string* >(icolumn);
129  if ( ! column ) {
130  G4ExceptionDescription description;
131  description << " Column type does not match: "
132  << " ntupleId " << ntupleId
133  << " columnId " << columnId << " value " << value;
134  G4Exception("G4TNtupleManager:FillNtupleTColumn",
135  "Analysis_W011", JustWarning, description);
136  return false;
137  }
138 
139  column->fill(value);
140 
141 #ifdef G4VERBOSE
142  if ( fState.GetVerboseL4() ) {
143  G4ExceptionDescription description;
144  description << " ntupleId " << ntupleId
145  << " columnId " << columnId << " value " << value;
146  fState.GetVerboseL4()->Message("fill", "ntuple T column", description);
147  }
148 #endif
149  return true;
150 }
151 
152 #endif
153