Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RootNtupleManager.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: G4RootNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Manager class for Root ntuples.
29 // It implements functions specific to Root ntuples.
30 //
31 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
32 
33 #ifndef G4RootNtupleManager_h
34 #define G4RootNtupleManager_h 1
35 
36 #include "G4TNtupleManager.hh"
37 #include "globals.hh"
38 
39 #include "tools/wroot/ntuple"
40 
42 class G4RootFileManager;
43 
44 namespace tools {
45 namespace wroot {
46 class directory;
47 }
48 }
49 
50 enum class G4NtupleCreateMode {
56 };
57 
58 // template specializations used by this class defined below
59 
60 template <>
61 template <>
63  G4int ntupleId, G4int columnId, const std::string& value);
64 
65 
66 class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple>
67 {
68  friend class G4RootAnalysisManager;
70 
71  public:
72  explicit G4RootNtupleManager(const G4AnalysisManagerState& state,
73  G4int nofMainManagers = 0,
74  G4bool rowWise = true);
75  virtual ~G4RootNtupleManager();
76 
77  private:
78  // Types alias
81 
82  // Functions specific to the output type
83 
84  void SetNtupleDirectory(tools::wroot::directory* directory);
85  void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
86 
87  // Utility function
88  void CreateTNtuple(NtupleDescriptionType* ntupleDescription);
89 
90  // Methods from the templated base class
91 
92  virtual void CreateTNtupleFromBooking(
93  NtupleDescriptionType* ntupleDescription) final;
94 
95  virtual void FinishTNtuple(
96  NtupleDescriptionType* ntupleDescription) final;
97 
98  virtual G4bool Reset(G4bool deleteNtuple);
99 
100  // Method for merging
101  //
102  G4bool Merge();
103 
104  // Access functions
105  //
106  const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector() const;
108  unsigned int GetBasketSize() const;
109 
110  // Utility functions
111  //
112  void SetCreateMode();
113 
114  // data members
115  //
117  std::shared_ptr<G4RootFileManager> fFileManager;
118  tools::wroot::directory* fNtupleDirectory;
119  std::vector<G4RootMainNtupleManager*> fMainNtupleManagers;
120 };
121 
122 // inline functions
123 
124 inline void
125 G4RootNtupleManager::SetNtupleDirectory(tools::wroot::directory* directory)
126 { fNtupleDirectory = directory; }
127 
128 inline void
129 G4RootNtupleManager::SetFileManager(std::shared_ptr<G4RootFileManager> fileManager)
130 { fFileManager = fileManager; }
131 
132 inline const std::vector<G4TNtupleDescription<tools::wroot::ntuple>* >&
134 { return fNtupleDescriptionVector; }
135 
136 //_____________________________________________________________________________
137 template <>
138 template <>
140  G4int ntupleId, G4int columnId, const std::string& value)
141 {
142  if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
143  //G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
144  return false;
145  }
146 
147  auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
148  if ( ! ntuple ) return false;
149 
150  auto index = columnId - fFirstNtupleColumnId;
151  if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
152  G4ExceptionDescription description;
153  description << " " << "ntupleId " << ntupleId
154  << " columnId " << columnId << " does not exist.";
155  G4Exception("G4RootNtupleManager::FillNtupleTColumn()",
156  "Analysis_W011", JustWarning, description);
157  return false;
158  }
159 
160  auto icolumn = ntuple->columns()[index];
161  auto column = dynamic_cast<tools::wroot::ntuple::column_string* >(icolumn);
162  if ( ! column ) {
163  G4ExceptionDescription description;
164  description << " Column type does not match: "
165  << " ntupleId " << ntupleId
166  << " columnId " << columnId << " value " << value;
167  G4Exception("G4RootNtupleManager:FillNtupleColumn",
168  "Analysis_W011", JustWarning, description);
169  return false;
170  }
171 
172  column->fill(value);
173 
174 #ifdef G4VERBOSE
175  if ( fState.GetVerboseL4() ) {
176  G4ExceptionDescription description;
177  description << " ntupleId " << ntupleId
178  << " columnId " << columnId << " value " << value;
179  fState.GetVerboseL4()->Message("fill", "ntuple T column", description);
180  }
181 #endif
182  return true;
183 }
184 
185 #endif
186 
187 
std::vector< G4TNtupleDescription< tools::wroot::ntuple > * > fNtupleDescriptionVector
G4RootMainNtupleManager * GetMainNtupleManager(G4int index) const
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4NtupleCreateMode fCreateMode
G4RootNtupleManager(const G4AnalysisManagerState &state, G4int nofMainManagers=0, G4bool rowWise=true)
TTree * ntuple
virtual G4bool GetActivation(G4int ntupleId) const final
std::vector< G4RootMainNtupleManager * > fMainNtupleManagers
unsigned int GetBasketSize() const
TNTUPLE * GetNtupleInFunction(G4int id, G4String function, G4bool warn=true) const
void SetNtupleDirectory(tools::wroot::directory *directory)
bool G4bool
Definition: G4Types.hh:79
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T &value)
G4NtupleCreateMode
const G4AnalysisVerbose * GetVerboseL4() const
virtual G4bool Reset(G4bool deleteNtuple)
void CreateTNtuple(NtupleDescriptionType *ntupleDescription)
std::shared_ptr< G4RootFileManager > fFileManager
const std::vector< NtupleDescriptionType * > & GetNtupleDescriptionVector() const
tools::wroot::ntuple NtupleType
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
virtual void CreateTNtupleFromBooking(NtupleDescriptionType *ntupleDescription) final
tools::wroot::directory * fNtupleDirectory
virtual void FinishTNtuple(NtupleDescriptionType *ntupleDescription) final
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
void SetFileManager(std::shared_ptr< G4RootFileManager > fileManager)
const G4AnalysisManagerState & fState