ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TNtupleManager.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4TNtupleManager.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 // Class template for ntuple managers for all output types.
28 //
29 // Author: Ivana Hrivnacova, 19/06/2015 (ivana@ipno.in2p3.fr)
30 
31 #ifndef G4TNtupleManager_h
32 #define G4TNtupleManager_h 1
33 
34 #include "G4BaseNtupleManager.hh"
35 #include "G4TNtupleDescription.hh"
36 #include "globals.hh"
37 
38 #include <vector>
39 
40 template <typename TNTUPLE>
42 
43  public:
44  explicit G4TNtupleManager(const G4AnalysisManagerState& state);
46 
47  protected:
48  // Methods to manipulate ntuples
49  virtual void CreateNtuplesFromBooking();
50  G4bool IsEmpty() const;
51  virtual G4bool Reset(G4bool deleteNtuple);
52 
53  // Methods to create ntuples
54  //
55  virtual G4int CreateNtuple(const G4String& name, const G4String& title) override;
56 
57  // Create columns in the last created ntuple (from base class)
63  // Create columns in the ntuple with given id
64  virtual G4int CreateNtupleIColumn(G4int ntupleId,
65  const G4String& name, std::vector<int>* vector) final;
66  virtual G4int CreateNtupleFColumn(G4int ntupleId,
67  const G4String& name, std::vector<float>* vector) final;
68  virtual G4int CreateNtupleDColumn(G4int ntupleId,
69  const G4String& name, std::vector<double>* vector) final;
70  virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) final;
71  virtual void FinishNtuple(G4int ntupleId) final;
72 
73  // Methods to fill ntuples
74  // Methods for ntuple with id = FirstNtupleId (from base class)
80  // Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
81  virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
82  virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
83  virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final;
84  virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
85  const G4String& value) final;
86  virtual G4bool AddNtupleRow(G4int ntupleId) override;
87 
88  // Activation option
89  //
90  virtual void SetActivation(G4bool activation) final;
91  virtual void SetActivation(G4int ntupleId, G4bool activation) final;
92  virtual G4bool GetActivation(G4int ntupleId) const final;
93 
94  // Access methods
95  TNTUPLE* GetNtuple() const;
96  TNTUPLE* GetNtuple(G4int ntupleId) const;
97  virtual G4int GetNofNtuples() const final;
98  virtual G4int GetNofNtupleBookings() const override;
99 
100  // Iterators
101  typename std::vector<TNTUPLE*>::iterator BeginNtuple();
102  typename std::vector<TNTUPLE*>::iterator EndNtuple();
103  typename std::vector<TNTUPLE*>::const_iterator BeginConstNtuple() const;
104  typename std::vector<TNTUPLE*>::const_iterator EndConstNtuple() const;
105 
106  // Data members
107  std::vector<G4TNtupleDescription<TNTUPLE>*> fNtupleDescriptionVector;
108  std::vector<TNTUPLE*> fNtupleVector;
109 
110  private:
111  // methods
112 
113  // Fuctions which are specific to output type
114  //
115  virtual void CreateTNtupleFromBooking(
116  G4TNtupleDescription<TNTUPLE>* ntupleDescription) = 0;
117 
118  virtual void FinishTNtuple(
119  G4TNtupleDescription<TNTUPLE>* ntupleDescription,
120  G4bool fromBooking) = 0;
121 
122  // Common implementation
123  //
124 
126  G4String function,
127  G4bool warn = true) const;
128  TNTUPLE* GetNtupleInFunction(G4int id,
129  G4String function,
130  G4bool warn = true) const;
131 
132  // template functions for creating/filling ntuple columns
133 
134  template <typename T>
135  G4int CreateNtupleTColumn(G4int ntupleId,
136  const G4String& name, std::vector<T>* vector);
137 
138  template <typename T>
139  G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
140 };
141 
142 #include "G4TNtupleManager.icc"
143 
144 #endif
145