44bool to_vector(base_ntu& a_ntu,std::vector<T>& a_vec) {
46 const std::vector<base_col*>& cols = a_ntu.cols();
47 if(cols.empty())
return false;
48 base_col* _base_col = cols.front();
49 aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
50 if(!_col)
return false;
52 uint64 _rows = a_ntu.rows();
55 {
for(uint64 row=0;row<_rows;row++) {
56 if(!a_ntu.next()) {a_vec.clear();
return false;}
57 if(!_col->get_entry(v)) {a_vec.clear();
return false;}
74G4int G4XmlRNtupleManager::ReadNtupleImpl(
const G4String& ntupleName,
84 auto fullFileName = fileName;
85 if ( ! isUserFileName ) {
86 fullFileName = fFileManager->GetNtupleFileName(ntupleName);
89 auto handler = fFileManager->GetHandler<tools::aida::ntuple>(
90 fullFileName, ntupleName,
"ReadNtupleImpl");
93 auto rntuple =
static_cast<tools::aida::ntuple*
>(handler->object());
104 std::vector<G4int>& vector)
109 " ntupleId " + to_string(ntupleId) +
" " + columnName);
112 if (ntupleDescription ==
nullptr)
return false;
118 auto subNtuple =
new tools::aida::ntuple(
G4cout, columnName);
119 ntupleDescription->fIVectorBindingMap[subNtuple] = &vector;
120 tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
121 ntupleBinding->add_column_cid(columnName, *subNtuple);
124 " ntupleId " + to_string(ntupleId) +
" " + columnName);
132 std::vector<G4float>& vector)
137 " ntupleId " + to_string(ntupleId) +
" " + columnName);
141 if (ntupleDescription ==
nullptr)
return false;
147 auto subNtuple =
new tools::aida::ntuple(
G4cout, columnName);
148 ntupleDescription->fFVectorBindingMap[subNtuple] = &vector;
149 tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
150 ntupleBinding->add_column_cid(columnName, *subNtuple);
153 " ntupleId " + to_string(ntupleId) +
" " + columnName);
161 std::vector<G4double>& vector)
166 " ntupleId " + to_string(ntupleId) +
" " + columnName);
169 if (ntupleDescription ==
nullptr)
return false;
175 auto subNtuple =
new tools::aida::ntuple(
G4cout, columnName);
176 ntupleDescription->fDVectorBindingMap[subNtuple] = &vector;
177 tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
178 ntupleBinding->add_column_cid(columnName, *subNtuple);
181 " ntupleId " + to_string(ntupleId) +
" " + columnName);
189 std::vector<std::string>& vector)
194 " ntupleId " + to_string(ntupleId) +
" " + columnName);
197 if (ntupleDescription ==
nullptr)
return false;
203 auto subNtuple =
new tools::aida::ntuple(
G4cout, columnName);
204 ntupleDescription->fSVectorBindingMap[subNtuple] = &vector;
205 tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
206 ntupleBinding->add_column_cid(columnName, *subNtuple);
209 " ntupleId " + to_string(ntupleId) +
" " + columnName);
215G4bool G4XmlRNtupleManager::GetTNtupleRow(
218 auto ntuple = ntupleDescription->
fNtuple;
221 if ( ! isInitialized ) {
222 tools::ntuple_binding* ntupleBinding = ntupleDescription->
fNtupleBinding;
223 if ( ! ntuple->set_binding(std::cout, *ntupleBinding) ) {
224 Warn(
"Ntuple initialization failed !!", fkClass,
"GetTNtupleRow");
231 G4bool next = ntuple->next();
233 if ( ! ntuple->get_row() ) {
234 Warn(
"Ntuple get_row() failed !!", fkClass,
"GetTNtupleRow");
240 tools::aida::to_vector<int>(*key, *value);
243 tools::aida::to_vector<float>(*key, *value);
246 tools::aida::to_vector<double>(*key, *value);
249 tools::aida::to_vector<std::string>(*key, *value);
G4GLOB_DLL std::ostream G4cout
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
G4TRNtupleDescription< tools::aida::ntuple > * GetNtupleDescriptionInFunction(G4int id, std::string_view function, G4bool warn=true) const
G4int SetNtuple(G4TRNtupleDescription< tools::aida::ntuple > *rntupleDescription)
G4bool SetNtupleIColumn(G4int ntupleId, const G4String &columnName, std::vector< G4int > &vector) final
G4bool SetNtupleFColumn(G4int ntupleId, const G4String &columnName, std::vector< G4float > &vector) final
G4bool SetNtupleSColumn(G4int ntupleId, const G4String &columnName, std::vector< std::string > &vector) final
G4bool SetNtupleDColumn(G4int ntupleId, const G4String &columnName, std::vector< G4double > &vector) final
G4XmlRNtupleManager()=delete
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
tools::ntuple_binding * fNtupleBinding
std::map< NT *, std::vector< std::string > * > fSVectorBindingMap
std::map< NT *, std::vector< float > * > fFVectorBindingMap
std::map< NT *, std::vector< double > * > fDVectorBindingMap
std::map< NT *, std::vector< int > * > fIVectorBindingMap