Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RootAnalysisManager.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 // $Id: G4RootAnalysisManager.hh 100648 2016-10-31 10:06:45Z gcosmo $
27 
28 // The main manager for Root analysis.
29 // It delegates most of functions to the object specific managers.
30 
31 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
32 
33 #ifndef G4RootAnalysisManager_h
34 #define G4RootAnalysisManager_h 1
35 
37 #include "globals.hh"
38 
39 #include "tools/wroot/ntuple"
40 #include "tools/histo/hmpi"
41 
42 #include <memory>
43 
44 class G4RootFileManager;
48 
49 namespace tools {
50 namespace wroot {
51 class directory;
52 }
53 }
54 
55 enum class G4NtupleMergeMode {
56  kNone,
57  kMain,
58  kSlave
59 };
60 
62 {
63  public:
64  explicit G4RootAnalysisManager(G4bool isMaster = true);
65  virtual ~G4RootAnalysisManager();
66 
67  // static methods
69  static G4bool IsInstance();
70 
71  // Access methods
72  tools::wroot::ntuple* GetNtuple() const;
73  tools::wroot::ntuple* GetNtuple(G4int ntupleId) const;
74 
75  // Iterators
76  std::vector<tools::wroot::ntuple*>::iterator BeginNtuple();
77  std::vector<tools::wroot::ntuple*>::iterator EndNtuple();
78  std::vector<tools::wroot::ntuple*>::const_iterator BeginConstNtuple() const;
79  std::vector<tools::wroot::ntuple*>::const_iterator EndConstNtuple() const;
80 
81  // MT/MPI
82  void SetNtupleMerging(G4bool mergeNtuples,
83  G4int nofReducedNtupleFiles = 0,
84  unsigned int basketSize = fgkDefaultBasketSize);
85 
86  protected:
87  // virtual methods from base class
88  virtual G4bool OpenFileImpl(const G4String& fileName) final;
89  virtual G4bool WriteImpl() final;
90  virtual G4bool CloseFileImpl() final;
91  virtual G4bool IsOpenFileImpl() const final;
92 
93  private:
94  // constants
95  static constexpr unsigned int fgkDefaultBasketSize = 32000;
96 
97  // static data members
98  static G4RootAnalysisManager* fgMasterInstance;
99  static G4ThreadLocal G4RootAnalysisManager* fgInstance;
100 
101  // methods
102  void SetNtupleMergingMode(G4bool mergeNtuples, G4int nofNtupleFiles);
103  void ClearNtupleManagers();
104  void CreateNtupleManagers();
105  G4int GetNtupleFileNumber();
106 
107  template <typename T>
108  G4bool WriteT(const std::vector<T*>& htVector,
109  const std::vector<G4HnInformation*>& hnVector,
110  tools::wroot::directory* directory,
111  const G4String& hnType);
112  G4bool WriteH1();
113  G4bool WriteH2();
114  G4bool WriteH3();
115  G4bool WriteP1();
116  G4bool WriteP2();
117  G4bool WriteNtuple();
118  G4bool Reset();
119 
120  // data members
121  G4int fNofNtupleFiles;
122  G4NtupleMergeMode fNtupleMergeMode;
123  G4RootNtupleManager* fNtupleManager;
124  G4RootPNtupleManager* fSlaveNtupleManager;
125  std::shared_ptr<G4RootFileManager> fFileManager;
126 };
127 
128 #include "G4RootAnalysisManager.icc"
129 
130 #endif
virtual G4bool OpenFileImpl(const G4String &fileName) final
std::vector< tools::wroot::ntuple * >::const_iterator BeginConstNtuple() const
virtual G4bool IsOpenFileImpl() const final
virtual G4bool CloseFileImpl() final
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
G4RootAnalysisManager(G4bool isMaster=true)
std::vector< tools::wroot::ntuple * >::const_iterator EndConstNtuple() const
virtual G4bool WriteImpl() final
void SetNtupleMerging(G4bool mergeNtuples, G4int nofReducedNtupleFiles=0, unsigned int basketSize=fgkDefaultBasketSize)
static G4RootAnalysisManager * Instance()
std::vector< tools::wroot::ntuple * >::iterator EndNtuple()
std::vector< tools::wroot::ntuple * >::iterator BeginNtuple()
tools::wroot::ntuple * GetNtuple() const