Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4XmlRNtupleManager.cc
이 파일의 문서화 페이지로 가기
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 // Author: Ivana Hrivnacova, 25/07/2014 (ivana@ipno.in2p3.fr)
29 
30 #include "G4XmlRNtupleManager.hh"
32 
33 //
34 // utility function (to be provided in tools)
35 //
36 
37 namespace tools {
38 namespace aida {
39 template <class T>
40 bool to_vector(base_ntu& a_ntu,std::vector<T>& a_vec) {
41  a_vec.clear();
42  const std::vector<base_col*>& cols = a_ntu.cols();
43  if(cols.empty()) return false;
44  base_col* _base_col = cols.front();
45  aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
46  if(!_col) return false;
47  a_ntu.start();
48  uint64 _rows = a_ntu.rows();
49  a_vec.resize(_rows);
50  T v;
51  {for(uint64 row=0;row<_rows;row++) {
52  if(!a_ntu.next()) {a_vec.clear();return false;}
53  if(!_col->get_entry(v)) {a_vec.clear();return false;}
54  a_vec[row] = v;
55  }}
56  return true;
57 }
58 }}
59 
60 //_____________________________________________________________________________
62  : G4TRNtupleManager<tools::aida::ntuple>(state)
63 {}
64 
65 //_____________________________________________________________________________
67 {}
68 
69 //
70 // private methods
71 //
72 
73 //_____________________________________________________________________________
75  const G4String& columnName,
76  std::vector<G4int>& vector)
77 {
78 // Override base class default implementation
79 
80 #ifdef G4VERBOSE
81  if ( fState.GetVerboseL4() ) {
82  G4ExceptionDescription description;
83  description << " ntupleId " << ntupleId << " " << columnName;
84  fState.GetVerboseL4()->Message("set", "ntuple I column", description);
85  }
86 #endif
87 
88  auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleIColumn");
89  if ( ! ntupleDescription ) return false;
90 
91  // not supported
92  //tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
93  //ntupleBinding->add_column(columnName, vector);
94 
95  auto subNtuple = new tools::aida::ntuple(G4cout, columnName);
96  ntupleDescription->fIVectorBindingMap[subNtuple] = &vector;
97  tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
98  ntupleBinding->add_column_cid(columnName, *subNtuple);
99 
100 #ifdef G4VERBOSE
101  if ( fState.GetVerboseL2() ) {
102  G4ExceptionDescription description;
103  description << " ntupleId " << ntupleId << " " << columnName;
104  fState.GetVerboseL2()->Message("set", "ntuple I colum", description, true);
105  }
106 #endif
107 
108  return true;
109 }
110 
111 //_____________________________________________________________________________
113  const G4String& columnName,
114  std::vector<G4float>& vector)
115 {
116 // Override base class default implementation
117 
118 #ifdef G4VERBOSE
119  if ( fState.GetVerboseL4() ) {
120  G4ExceptionDescription description;
121  description << " ntupleId " << ntupleId << " " << columnName;
122  fState.GetVerboseL4()->Message("set", "ntuple F column of vector", description);
123  }
124 #endif
125 
126  auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleFColumn");
127  if ( ! ntupleDescription ) return false;
128 
129  // not supported
130  //tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
131  //ntupleBinding->add_column(columnName, vector);
132 
133  auto subNtuple = new tools::aida::ntuple(G4cout, columnName);
134  ntupleDescription->fFVectorBindingMap[subNtuple] = &vector;
135  tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
136  ntupleBinding->add_column_cid(columnName, *subNtuple);
137 
138 #ifdef G4VERBOSE
139  if ( fState.GetVerboseL2() ) {
140  G4ExceptionDescription description;
141  description << " ntupleId " << ntupleId << " " << columnName;
142  fState.GetVerboseL2()->Message("set", "ntuple F colum", description, true);
143  }
144 #endif
145 
146  return true;
147 }
148 
149 //_____________________________________________________________________________
151  const G4String& columnName,
152  std::vector<G4double>& vector)
153 {
154 // Override base class default implementation
155 
156 #ifdef G4VERBOSE
157  if ( fState.GetVerboseL4() ) {
158  G4ExceptionDescription description;
159  description << " ntupleId " << ntupleId << " " << columnName;
160  fState.GetVerboseL4()->Message("set", "ntuple D column of vector", description);
161  }
162 #endif
163 
164  auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleDColumn");
165  if ( ! ntupleDescription ) return false;
166 
167  // not supported
168  //tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
169  //ntupleBinding->add_column(columnName, vector);
170 
171  auto subNtuple = new tools::aida::ntuple(G4cout, columnName);
172  ntupleDescription->fDVectorBindingMap[subNtuple] = &vector;
173  tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
174  ntupleBinding->add_column_cid(columnName, *subNtuple);
175 
176 #ifdef G4VERBOSE
177  if ( fState.GetVerboseL2() ) {
178  G4ExceptionDescription description;
179  description << " ntupleId " << ntupleId << " " << columnName;
180  fState.GetVerboseL2()->Message("set", "ntuple D colum", description, true);
181  }
182 #endif
183 
184  return true;
185 }
186 
187 //_____________________________________________________________________________
190 {
191  auto ntuple = ntupleDescription->fNtuple;
192 
193  G4bool isInitialized = ntupleDescription->fIsInitialized;
194  if ( ! isInitialized ) {
195  tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
196  if ( ! ntuple->set_binding(std::cout, *ntupleBinding) ) {
197  G4ExceptionDescription description;
198  description
199  << " "
200  << "Ntuple initialization failed !!";
201  G4Exception("G4XmlRNtuple::GetNtupleRow()",
202  "Analysis_WR021", JustWarning, description);
203  return false;
204  }
205  ntupleDescription->fIsInitialized = true;
206  ntuple->start();
207  }
208 
209  G4bool next = ntuple->next();
210  if ( next ) {
211  if ( ! ntuple->get_row() ) {
212  G4ExceptionDescription description;
213  description
214  << " "
215  << "Ntuple get_row() failed !!";
216  G4Exception("G4XmlRNtuple::GetNtupleRow()",
217  "Analysis_WR021", JustWarning, description);
218  return false;
219  }
220 
221  // fill vector from sub ntuples
222 
223  {std::map<tools::aida::ntuple*, std::vector<int>* >::iterator it;
224  for ( it = ntupleDescription->fIVectorBindingMap.begin();
225  it != ntupleDescription->fIVectorBindingMap.end(); it++) {
226  tools::aida::to_vector<int>(*(it->first), *(it->second));
227  }}
228  {std::map<tools::aida::ntuple*, std::vector<float>* >::iterator it;
229  for ( it = ntupleDescription->fFVectorBindingMap.begin();
230  it != ntupleDescription->fFVectorBindingMap.end(); it++) {
231  tools::aida::to_vector<float>(*(it->first), *(it->second));
232  }}
233  {std::map<tools::aida::ntuple*, std::vector<double>* >::iterator it;
234  for ( it = ntupleDescription->fDVectorBindingMap.begin();
235  it != ntupleDescription->fDVectorBindingMap.end(); it++) {
236  tools::aida::to_vector<double>(*(it->first), *(it->second));
237  }}
238  }
239 
240  return next;
241 }
const G4AnalysisVerbose * GetVerboseL2() const
bool to_vector(base_ntu &a_ntu, std::vector< T > &a_vec)
virtual G4bool SetNtupleFColumn(G4int ntupleId, const G4String &columnName, std::vector< G4float > &vector) final
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
tools::ntuple_binding * fNtupleBinding
TTree * ntuple
virtual G4bool SetNtupleIColumn(G4int ntupleId, const G4String &columnName, std::vector< G4int > &vector) final
G4TRNtupleDescription< tools::aida::ntuple > * GetNtupleDescriptionInFunction(G4int id, G4String function, G4bool warn=true) const
std::map< TNTUPLE *, std::vector< float > * > fFVectorBindingMap
bool G4bool
Definition: G4Types.hh:79
const G4AnalysisVerbose * GetVerboseL4() const
virtual G4bool GetTNtupleRow(G4TRNtupleDescription< tools::aida::ntuple > *ntupleDescription) final
unsigned long long uint64
Definition: config.h:32
virtual G4bool SetNtupleDColumn(G4int ntupleId, const G4String &columnName, std::vector< G4double > &vector) final
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
std::map< TNTUPLE *, std::vector< double > * > fDVectorBindingMap
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4GLOB_DLL std::ostream G4cout
std::map< TNTUPLE *, std::vector< int > * > fIVectorBindingMap
G4bool isInitialized()
const G4AnalysisManagerState & fState
G4XmlRNtupleManager(const G4AnalysisManagerState &state)