Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 27 // Author: Ivana Hrivnacova, 25/07/2014 (ivana 28 29 #include "G4XmlRNtupleManager.hh" 30 #include "G4XmlRFileManager.hh" 31 #include "G4AnalysisManagerState.hh" 32 #include "G4AnalysisUtilities.hh" 33 34 using namespace G4Analysis; 35 using std::to_string; 36 37 // 38 // utility function (to be provided in tools) 39 // 40 41 namespace tools { 42 namespace aida { 43 template <class T> 44 bool to_vector(base_ntu& a_ntu,std::vector<T>& 45 a_vec.clear(); 46 const std::vector<base_col*>& cols = a_ntu.c 47 if(cols.empty()) return false; 48 base_col* _base_col = cols.front(); 49 aida_col<T>* _col = safe_cast<base_col, aida 50 if(!_col) return false; 51 a_ntu.start(); 52 uint64 _rows = a_ntu.rows(); 53 a_vec.resize(_rows); 54 T v; 55 {for(uint64 row=0;row<_rows;row++) { 56 if(!a_ntu.next()) {a_vec.clear();return fa 57 if(!_col->get_entry(v)) {a_vec.clear();ret 58 a_vec[row] = v; 59 }} 60 return true; 61 } 62 }} 63 64 //____________________________________________ 65 G4XmlRNtupleManager::G4XmlRNtupleManager(const 66 : G4TRNtupleManager<tools::aida::ntuple>(stat 67 {} 68 69 // 70 // private methods 71 // 72 73 //____________________________________________ 74 G4int G4XmlRNtupleManager::ReadNtupleImpl(cons 75 cons 76 cons 77 G4bo 78 { 79 Message(kVL4, "read", "ntuple", ntupleName); 80 81 // Ntuples are saved per object and per thre 82 // but apply the ntuple name and the thread 83 // only if fileName is not provided explicit 84 auto fullFileName = fileName; 85 if ( ! isUserFileName ) { 86 fullFileName = fFileManager->GetNtupleFile 87 } 88 89 auto handler = fFileManager->GetHandler<tool 90 fullFileName, 91 if (handler == nullptr) return kInvalidId; 92 93 auto rntuple = static_cast<tools::aida::ntup 94 auto id = SetNtuple(new G4TRNtupleDescriptio 95 96 Message(kVL2, "read", "ntuple", ntupleName, 97 98 return id; 99 } 100 101 //____________________________________________ 102 G4bool G4XmlRNtupleManager::SetNtupleIColumn(G 103 c 104 s 105 { 106 // Override base class default implementation 107 108 Message(kVL4, "set", "ntuple I column", 109 " ntupleId " + to_string(ntupleId) + " " + 110 111 auto ntupleDescription = GetNtupleDescriptio 112 if (ntupleDescription == nullptr) return fal 113 114 // not supported 115 //tools::ntuple_binding* ntupleBinding = ntu 116 //ntupleBinding->add_column(columnName, vect 117 118 auto subNtuple = new tools::aida::ntuple(G4c 119 ntupleDescription->fIVectorBindingMap[subNtu 120 tools::ntuple_binding* ntupleBinding = ntupl 121 ntupleBinding->add_column_cid(columnName, *s 122 123 Message(kVL2, "set", "ntuple I column", 124 " ntupleId " + to_string(ntupleId) + " " + 125 126 return true; 127 } 128 129 //____________________________________________ 130 G4bool G4XmlRNtupleManager::SetNtupleFColumn(G 131 c 132 s 133 { 134 // Override base class default implementation 135 136 Message(kVL4, "set", "ntuple F column", 137 " ntupleId " + to_string(ntupleId) + " " + 138 139 140 auto ntupleDescription = GetNtupleDescriptio 141 if (ntupleDescription == nullptr) return fal 142 143 // not supported 144 //tools::ntuple_binding* ntupleBinding = ntu 145 //ntupleBinding->add_column(columnName, vect 146 147 auto subNtuple = new tools::aida::ntuple(G4c 148 ntupleDescription->fFVectorBindingMap[subNtu 149 tools::ntuple_binding* ntupleBinding = ntupl 150 ntupleBinding->add_column_cid(columnName, *s 151 152 Message(kVL4, "set", "ntuple F column", 153 " ntupleId " + to_string(ntupleId) + " " + 154 155 return true; 156 } 157 158 //____________________________________________ 159 G4bool G4XmlRNtupleManager::SetNtupleDColumn(G 160 c 161 s 162 { 163 // Override base class default implementation 164 165 Message(kVL4, "set", "ntuple D column", 166 " ntupleId " + to_string(ntupleId) + " " + 167 168 auto ntupleDescription = GetNtupleDescriptio 169 if (ntupleDescription == nullptr) return fal 170 171 // not supported 172 //tools::ntuple_binding* ntupleBinding = ntu 173 //ntupleBinding->add_column(columnName, vect 174 175 auto subNtuple = new tools::aida::ntuple(G4c 176 ntupleDescription->fDVectorBindingMap[subNtu 177 tools::ntuple_binding* ntupleBinding = ntupl 178 ntupleBinding->add_column_cid(columnName, *s 179 180 Message(kVL2, "set", "ntuple D column", 181 " ntupleId " + to_string(ntupleId) + " " + 182 183 return true; 184 } 185 186 //____________________________________________ 187 G4bool G4XmlRNtupleManager::SetNtupleSColumn(G 188 c 189 s 190 { 191 // Override base class default implementation 192 193 Message(kVL4, "set", "ntuple S column", 194 " ntupleId " + to_string(ntupleId) + " " + 195 196 auto ntupleDescription = GetNtupleDescriptio 197 if (ntupleDescription == nullptr) return fal 198 199 // not supported 200 //tools::ntuple_binding* ntupleBinding = ntu 201 //ntupleBinding->add_column(columnName, vect 202 203 auto subNtuple = new tools::aida::ntuple(G4c 204 ntupleDescription->fSVectorBindingMap[subNtu 205 tools::ntuple_binding* ntupleBinding = ntupl 206 ntupleBinding->add_column_cid(columnName, *s 207 208 Message(kVL2, "set", "ntuple S column", 209 " ntupleId " + to_string(ntupleId) + " " + 210 211 return true; 212 } 213 214 //____________________________________________ 215 G4bool G4XmlRNtupleManager::GetTNtupleRow( 216 G4TRNtupleDescription<tools::aida::ntuple>* 217 { 218 auto ntuple = ntupleDescription->fNtuple; 219 220 G4bool isInitialized = ntupleDescription->fI 221 if ( ! isInitialized ) { 222 tools::ntuple_binding* ntupleBinding = ntu 223 if ( ! ntuple->set_binding(std::cout, *ntu 224 Warn("Ntuple initialization failed !!", 225 return false; 226 } 227 ntupleDescription->fIsInitialized = true; 228 ntuple->start(); 229 } 230 231 G4bool next = ntuple->next(); 232 if ( next ) { 233 if ( ! ntuple->get_row() ) { 234 Warn("Ntuple get_row() failed !!", fkCla 235 return false; 236 } 237 238 // fill vector from sub ntuples 239 for ( auto [key, value] : ntupleDescriptio 240 tools::aida::to_vector<int>(*key, *value 241 } 242 for ( auto [key, value] : ntupleDescriptio 243 tools::aida::to_vector<float>(*key, *val 244 } 245 for ( auto [key, value] : ntupleDescriptio 246 tools::aida::to_vector<double>(*key, *va 247 } 248 for ( auto [key, value] : ntupleDescriptio 249 tools::aida::to_vector<std::string>(*key 250 } 251 } 252 253 return next; 254 } 255