Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4XmlNtupleManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $ 26 27 27 // Author: Ivana Hrivnacova, 18/06/2013 (ivan 28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr) 28 29 29 #include "G4XmlNtupleManager.hh" 30 #include "G4XmlNtupleManager.hh" >> 31 #include "G4XmlNtupleDescription.hh" 30 #include "G4XmlFileManager.hh" 32 #include "G4XmlFileManager.hh" 31 #include "G4AnalysisManagerState.hh" 33 #include "G4AnalysisManagerState.hh" 32 #include "G4AnalysisUtilities.hh" << 33 #include "G4UnitsTable.hh" 34 #include "G4UnitsTable.hh" 34 35 35 #include "tools/ntuple_booking" 36 #include "tools/ntuple_booking" 36 37 37 using namespace G4Analysis; << 38 #include <iostream> >> 39 #include <cstdio> 38 40 39 //____________________________________________ 41 //_____________________________________________________________________________ 40 G4XmlNtupleManager::G4XmlNtupleManager(const G 42 G4XmlNtupleManager::G4XmlNtupleManager(const G4AnalysisManagerState& state) 41 : G4TNtupleManager<tools::waxml::ntuple, std: << 43 : G4VNtupleManager(state), 42 {} << 44 fFileManager(0), >> 45 fNtupleVector() >> 46 { >> 47 } 43 48 44 // << 49 //_____________________________________________________________________________ >> 50 G4XmlNtupleManager::~G4XmlNtupleManager() >> 51 { >> 52 std::vector<G4XmlNtupleDescription*>::iterator it; >> 53 for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) { >> 54 delete (*it); >> 55 } >> 56 } >> 57 >> 58 // 45 // private methods 59 // private methods 46 // 60 // 47 61 48 //____________________________________________ 62 //_____________________________________________________________________________ 49 void G4XmlNtupleManager::CreateTNtupleFromBook << 63 tools::waxml::ntuple::column<int>* 50 XmlNtupleDescription* ntupleDescription) << 64 G4XmlNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const >> 65 { >> 66 G4XmlNtupleDescription* ntupleDecription >> 67 = GetNtupleInFunction(ntupleId, "GetNtupleIColumn"); >> 68 if ( ! ntupleDecription ) return 0; >> 69 >> 70 std::map<G4int, tools::waxml::ntuple::column<int>* >& ntupleIColumnMap >> 71 = ntupleDecription->fNtupleIColumnMap; >> 72 std::map<G4int, tools::waxml::ntuple::column<int>* >::const_iterator it >> 73 = ntupleIColumnMap.find(columnId); >> 74 if ( it == ntupleIColumnMap.end() ) { >> 75 G4ExceptionDescription description; >> 76 description << " " << "ntupleId " << ntupleId >> 77 << "column " << columnId << " does not exist."; >> 78 G4Exception("G4XmlNtupleManager::GetNtupleIColumn()", >> 79 "Analysis_W009", JustWarning, description); >> 80 return 0; >> 81 } >> 82 >> 83 return it->second; >> 84 } >> 85 >> 86 //_____________________________________________________________________________ >> 87 tools::waxml::ntuple::column<float>* >> 88 G4XmlNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const >> 89 { >> 90 G4XmlNtupleDescription* ntupleDecription >> 91 = GetNtupleInFunction(ntupleId, "GetNtupleFColumn"); >> 92 if ( ! ntupleDecription ) return 0; >> 93 >> 94 std::map<G4int, tools::waxml::ntuple::column<float>* >& ntupleFColumnMap >> 95 = ntupleDecription->fNtupleFColumnMap; >> 96 std::map<G4int, tools::waxml::ntuple::column<float>* >::const_iterator it >> 97 = ntupleFColumnMap.find(columnId); >> 98 if ( it == ntupleFColumnMap.end() ) { >> 99 G4ExceptionDescription description; >> 100 description << " " << "ntupleId " << ntupleId >> 101 << "column " << columnId << " does not exist."; >> 102 G4Exception("G4XmlNtupleManager::GetNtupleFColumn()", >> 103 "Analysis_W009", JustWarning, description); >> 104 return 0; >> 105 } >> 106 >> 107 return it->second; >> 108 } >> 109 >> 110 //_____________________________________________________________________________ >> 111 tools::waxml::ntuple::column<double>* >> 112 G4XmlNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const >> 113 { >> 114 G4XmlNtupleDescription* ntupleDecription >> 115 = GetNtupleInFunction(ntupleId, "GetNtupleDColumn"); >> 116 if ( ! ntupleDecription ) return 0; >> 117 >> 118 std::map<G4int, tools::waxml::ntuple::column<double>* >& ntupleDColumnMap >> 119 = ntupleDecription->fNtupleDColumnMap; >> 120 std::map<G4int, tools::waxml::ntuple::column<double>* >::const_iterator it >> 121 = ntupleDColumnMap.find(columnId); >> 122 if ( it == ntupleDColumnMap.end() ) { >> 123 G4ExceptionDescription description; >> 124 description << " " << "ntupleId " << ntupleId >> 125 << "column " << columnId << " does not exist."; >> 126 G4Exception("G4XmlNtupleManager::GetNtupleFColumn()", >> 127 "Analysis_W009", JustWarning, description); >> 128 return 0; >> 129 } >> 130 >> 131 return it->second; >> 132 } >> 133 >> 134 //_____________________________________________________________________________ >> 135 G4XmlNtupleDescription* G4XmlNtupleManager::GetNtupleInFunction(G4int id, >> 136 G4String functionName, G4bool warn, >> 137 G4bool /*onlyIfActive*/) const >> 138 { >> 139 G4int index = id - fFirstId; >> 140 if ( index < 0 || index >= G4int(fNtupleVector.size()) ) { >> 141 if ( warn) { >> 142 G4String inFunction = "G4XmlNtupleManager::"; >> 143 inFunction += functionName; >> 144 G4ExceptionDescription description; >> 145 description << " " << "ntuple " << id << " does not exist."; >> 146 G4Exception(inFunction, "Analysis_W007", JustWarning, description); >> 147 } >> 148 return 0; >> 149 } >> 150 >> 151 return fNtupleVector[index]; >> 152 } >> 153 >> 154 // >> 155 // protected methods >> 156 // >> 157 >> 158 //_____________________________________________________________________________ >> 159 void G4XmlNtupleManager::CreateNtuplesFromBooking() 51 { 160 { >> 161 // Create ntuple from ntuple_booking. >> 162 >> 163 // Do not create ntuples on master thread >> 164 if ( G4AnalysisManagerState::IsMT() && fState.GetIsMaster() ) return; >> 165 >> 166 std::vector<G4XmlNtupleDescription*>::iterator itn; >> 167 for (itn = fNtupleVector.begin(); itn != fNtupleVector.end(); itn++ ) { >> 168 >> 169 tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking; >> 170 if ( ! ntupleBooking ) continue; >> 171 >> 172 // Create ntuple from ntuple_booking. >> 173 #ifdef G4VERBOSE >> 174 if ( fState.GetVerboseL4() ) >> 175 fState.GetVerboseL4() >> 176 ->Message("create from booking", "ntuple", ntupleBooking->m_name); >> 177 #endif >> 178 52 // create a file for this ntuple 179 // create a file for this ntuple 53 if ( ! fFileManager->CreateNtupleFile(ntup << 180 if ( ! fFileManager->CreateNtupleFile((*itn)) ) continue; 54 181 55 // create ntuple 182 // create ntuple 56 ntupleDescription->SetNtuple( << 183 (*itn)->fNtuple 57 new tools::waxml::ntuple( << 184 = new tools::waxml::ntuple(*((*itn)->fFile), G4cerr, *ntupleBooking); 58 *(ntupleDescription->GetFile()), G << 185 59 ntupleDescription->GetNtupleBookin << 186 if ( ntupleBooking->m_columns.size() ) { 60 } << 187 // store ntuple columns in local maps >> 188 const std::vector<tools::ntuple_booking::col_t>& columns >> 189 = ntupleBooking->m_columns; >> 190 std::vector<tools::ntuple_booking::col_t>::const_iterator it; >> 191 G4int index = 0; >> 192 for ( it = columns.begin(); it!=columns.end(); ++it) { >> 193 if ( (*it).second == tools::_cid(int(0) ) ) { >> 194 (*itn)->fNtupleIColumnMap[index++] >> 195 = (*itn)->fNtuple->find_column<int>((*it).first); >> 196 } >> 197 else if( (*it).second == tools::_cid(float(0) ) ) { >> 198 (*itn)->fNtupleFColumnMap[index++] >> 199 = (*itn)->fNtuple->find_column<float>((*it).first); >> 200 } >> 201 else if((*it).second== tools::_cid(double(0))) { >> 202 (*itn)->fNtupleDColumnMap[index++] >> 203 = (*itn)->fNtuple->find_column<double>((*it).first); >> 204 } >> 205 else { >> 206 G4ExceptionDescription description; >> 207 description << " " >> 208 << "Unsupported column type " << (*it).first; >> 209 G4Exception("G4XmlNtupleManager::CreateNtuplesFromBooking()", >> 210 "Analysis_W004", JustWarning, description); >> 211 } >> 212 } >> 213 } >> 214 FinishNtuple(); >> 215 #ifdef G4VERBOSE >> 216 if ( fState.GetVerboseL3() ) >> 217 fState.GetVerboseL3() >> 218 ->Message("create from booking", "ntuple", ntupleBooking->m_name); >> 219 #endif >> 220 } >> 221 } >> 222 >> 223 //_____________________________________________________________________________ >> 224 G4bool G4XmlNtupleManager::IsEmpty() const >> 225 { >> 226 return ! fNtupleVector.size(); >> 227 } >> 228 >> 229 //_____________________________________________________________________________ >> 230 G4bool G4XmlNtupleManager::Reset() >> 231 { >> 232 // Reset ntuples 61 233 >> 234 std::vector<G4XmlNtupleDescription*>::iterator it; >> 235 for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) { >> 236 delete (*it)->fNtuple; >> 237 (*it)->fNtuple = 0; >> 238 } >> 239 >> 240 return true; >> 241 } >> 242 62 //____________________________________________ 243 //_____________________________________________________________________________ 63 void G4XmlNtupleManager::FinishTNtuple( << 244 tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple() const 64 XmlNtupleDescription* ntupleDescription, << 245 { 65 G4bool /*fromBooking*/) << 246 return GetNtuple(fFirstId); >> 247 } 66 248 >> 249 //_____________________________________________________________________________ >> 250 tools::waxml::ntuple* G4XmlNtupleManager::GetNtuple(G4int ntupleId) const 67 { 251 { 68 // Do nothing if the base file name was not << 252 G4XmlNtupleDescription* ntupleDescription 69 if (fFileManager->GetFileName().size() == 0u << 253 = GetNtupleInFunction(ntupleId, "GetNtuple"); >> 254 >> 255 return ntupleDescription->fNtuple; >> 256 } 70 257 71 // Create ntuple from booking << 258 //_____________________________________________________________________________ 72 if (ntupleDescription->GetNtuple() == nullpt << 259 G4int G4XmlNtupleManager::CreateNtuple(const G4String& name, 73 CreateTNtupleFromBooking(ntupleDescription << 260 const G4String& title) >> 261 { >> 262 #ifdef G4VERBOSE >> 263 if ( fState.GetVerboseL4() ) >> 264 fState.GetVerboseL4()->Message("create", "ntuple", name); >> 265 #endif >> 266 >> 267 // Create ntuple description >> 268 G4int index = fNtupleVector.size(); >> 269 G4XmlNtupleDescription* ntupleDescription >> 270 = new G4XmlNtupleDescription(); >> 271 fNtupleVector.push_back(ntupleDescription); >> 272 >> 273 // Create ntuple booking >> 274 ntupleDescription->fNtupleBooking = new tools::ntuple_booking(); >> 275 ntupleDescription->fNtupleBooking->m_name = name; >> 276 ntupleDescription->fNtupleBooking->m_title = title; >> 277 >> 278 // Create ntuple if the file is open (what means here that >> 279 // a filename was already set) >> 280 if ( fFileManager->GetFileName().size() ) { >> 281 if ( fFileManager->CreateNtupleFile(ntupleDescription) ) { >> 282 ntupleDescription->fNtuple >> 283 = new tools::waxml::ntuple(*(ntupleDescription->fFile)); >> 284 // ntuple object is deleted when closing a file >> 285 } 74 } 286 } 75 287 76 // Return if creating ntuple failed << 288 fLockFirstId = true; 77 if (ntupleDescription->GetNtuple() == nullpt << 289 78 Warn("Creating ntuple has failed. ", fkCla << 290 #ifdef G4VERBOSE 79 return; << 291 if ( fState.GetVerboseL2() ) { >> 292 G4ExceptionDescription description; >> 293 description << name << " ntupleId " << index + fFirstId; >> 294 fState.GetVerboseL2()->Message("create", "ntuple", description); >> 295 } >> 296 #endif >> 297 >> 298 return index + fFirstId; >> 299 } >> 300 >> 301 //_____________________________________________________________________________ >> 302 G4int G4XmlNtupleManager::CreateNtupleIColumn(const G4String& name) >> 303 { >> 304 G4int ntupleId = fNtupleVector.size() + fFirstId - 1; >> 305 return CreateNtupleIColumn(ntupleId, name); >> 306 } >> 307 >> 308 //_____________________________________________________________________________ >> 309 G4int G4XmlNtupleManager::CreateNtupleFColumn(const G4String& name) >> 310 { >> 311 G4int ntupleId = fNtupleVector.size() + fFirstId - 1; >> 312 return CreateNtupleFColumn(ntupleId, name); >> 313 } >> 314 >> 315 //_____________________________________________________________________________ >> 316 G4int G4XmlNtupleManager::CreateNtupleDColumn(const G4String& name) >> 317 { >> 318 G4int ntupleId = fNtupleVector.size() + fFirstId - 1; >> 319 return CreateNtupleDColumn(ntupleId, name); >> 320 } >> 321 >> 322 //_____________________________________________________________________________ >> 323 void G4XmlNtupleManager::FinishNtuple() >> 324 { >> 325 G4int ntupleId = fNtupleVector.size() + fFirstId - 1; >> 326 FinishNtuple(ntupleId); >> 327 } >> 328 >> 329 //_____________________________________________________________________________ >> 330 G4int G4XmlNtupleManager::CreateNtupleIColumn(G4int ntupleId, const G4String& name) >> 331 { >> 332 #ifdef G4VERBOSE >> 333 if ( fState.GetVerboseL4() ) { >> 334 G4ExceptionDescription description; >> 335 description << name << " ntupleId " << ntupleId; >> 336 fState.GetVerboseL4()->Message("create", "ntuple I column", description); >> 337 } >> 338 #endif >> 339 >> 340 G4XmlNtupleDescription* ntupleDescription >> 341 = GetNtupleInFunction(ntupleId, "CreateNtupleIColumn"); >> 342 tools::ntuple_booking* ntupleBooking >> 343 = ntupleDescription->fNtupleBooking; >> 344 >> 345 if ( ! ntupleBooking ) { >> 346 G4ExceptionDescription description; >> 347 description << " " >> 348 << "Ntuple " << ntupleId << " has to be created first. "; >> 349 G4Exception("G4XmlNtupleManager::CreateNtupleIColumn()", >> 350 "Analysis_W005", JustWarning, description); >> 351 return -1; >> 352 } >> 353 >> 354 // Save column info in booking >> 355 G4int index = ntupleBooking->m_columns.size(); >> 356 ntupleBooking->add_column<int>(name); >> 357 >> 358 // Create column if ntuple already exists >> 359 if ( ntupleDescription->fNtuple ) { >> 360 tools::waxml::ntuple::column<int>* column >> 361 = ntupleDescription->fNtuple->create_column<int>(name); >> 362 ntupleDescription->fNtupleIColumnMap[index] = column; >> 363 } >> 364 >> 365 fLockFirstNtupleColumnId = true; >> 366 >> 367 #ifdef G4VERBOSE >> 368 if ( fState.GetVerboseL2() ) { >> 369 G4ExceptionDescription description; >> 370 description << name << " ntupleId " << ntupleId; >> 371 fState.GetVerboseL2()->Message("create", "ntuple I column", description); >> 372 } >> 373 #endif >> 374 >> 375 return index + fFirstNtupleColumnId; >> 376 } >> 377 >> 378 //_____________________________________________________________________________ >> 379 G4int G4XmlNtupleManager::CreateNtupleFColumn(G4int ntupleId, const G4String& name) >> 380 { >> 381 #ifdef G4VERBOSE >> 382 if ( fState.GetVerboseL4() ) { >> 383 G4ExceptionDescription description; >> 384 description << name << " ntupleId " << ntupleId; >> 385 fState.GetVerboseL4()->Message("create", "ntuple F column", description); >> 386 } >> 387 #endif >> 388 >> 389 G4XmlNtupleDescription* ntupleDescription >> 390 = GetNtupleInFunction(ntupleId, "CreateNtupleFColumn"); >> 391 tools::ntuple_booking* ntupleBooking >> 392 = ntupleDescription->fNtupleBooking; >> 393 >> 394 if ( ! ntupleBooking ) { >> 395 G4ExceptionDescription description; >> 396 description << " " >> 397 << "Ntuple " << ntupleId << " has to be created first. "; >> 398 G4Exception("G4XmlNtupleManager::CreateNtupleFColumn()", >> 399 "Analysis_W005", JustWarning, description); >> 400 return -1; 80 } 401 } 81 402 82 // Update ntuple name if cycle >0 << 403 // Save column info in booking 83 auto ntupleName = ntupleDescription->GetNtup << 404 G4int index = ntupleBooking->m_columns.size(); 84 // if (ntupleDescription->GetCycle() > 0) { << 405 ntupleBooking->add_column<float>(name); 85 if (GetCycle() > 0) { << 406 86 ntupleName.append("_v"); << 407 // Create column if ntuple already exists 87 ntupleName.append(std::to_string(GetCycle( << 408 if ( ntupleDescription->fNtuple ) { >> 409 tools::waxml::ntuple::column<float>* column >> 410 = ntupleDescription->fNtuple->create_column<float>(name); >> 411 ntupleDescription->fNtupleFColumnMap[index] = column; >> 412 } >> 413 >> 414 fLockFirstNtupleColumnId = true; >> 415 >> 416 #ifdef G4VERBOSE >> 417 if ( fState.GetVerboseL2() ) { >> 418 G4ExceptionDescription description; >> 419 description << name << " ntupleId " << ntupleId; >> 420 fState.GetVerboseL2()->Message("create", "ntuple F column", description); >> 421 } >> 422 #endif >> 423 >> 424 return index + fFirstNtupleColumnId; >> 425 } >> 426 >> 427 //_____________________________________________________________________________ >> 428 G4int G4XmlNtupleManager::CreateNtupleDColumn(G4int ntupleId, const G4String& name) >> 429 { >> 430 #ifdef G4VERBOSE >> 431 if ( fState.GetVerboseL4() ) { >> 432 G4ExceptionDescription description; >> 433 description << name << " ntupleId " << ntupleId; >> 434 fState.GetVerboseL4()->Message("create", "ntuple D column", description); >> 435 } >> 436 #endif >> 437 >> 438 G4XmlNtupleDescription* ntupleDescription >> 439 = GetNtupleInFunction(ntupleId, "CreateNtupleDColumn"); >> 440 tools::ntuple_booking* ntupleBooking >> 441 = ntupleDescription->fNtupleBooking; >> 442 >> 443 if ( ! ntupleBooking ) { >> 444 G4ExceptionDescription description; >> 445 description << " " >> 446 << "Ntuple " << ntupleId << " has to be created first. "; >> 447 G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()", >> 448 "Analysis_W005", JustWarning, description); >> 449 return -1; >> 450 } >> 451 >> 452 // Save column info in booking >> 453 G4int index = ntupleBooking->m_columns.size(); >> 454 ntupleBooking->add_column<double>(name); >> 455 >> 456 // Create column if ntuple already exists >> 457 if ( ntupleDescription->fNtuple ) { >> 458 tools::waxml::ntuple::column<double>* column >> 459 = ntupleDescription->fNtuple->create_column<double>(name); >> 460 ntupleDescription->fNtupleDColumnMap[index] = column; >> 461 } >> 462 >> 463 fLockFirstNtupleColumnId = true; >> 464 >> 465 #ifdef G4VERBOSE >> 466 if ( fState.GetVerboseL2() ) { >> 467 G4ExceptionDescription description; >> 468 description << name << " ntupleId " << ntupleId; >> 469 fState.GetVerboseL2()->Message("create", "ntuple D column", description); >> 470 } >> 471 #endif >> 472 >> 473 return index + fFirstNtupleColumnId; >> 474 } >> 475 >> 476 //_____________________________________________________________________________ >> 477 void G4XmlNtupleManager::FinishNtuple(G4int ntupleId) >> 478 { >> 479 G4XmlNtupleDescription* ntupleDescription >> 480 = GetNtupleInFunction(ntupleId, "FinishNtuple"); >> 481 tools::ntuple_booking* ntupleBooking >> 482 = ntupleDescription->fNtupleBooking; >> 483 >> 484 if ( ! ntupleBooking ) { >> 485 G4ExceptionDescription description; >> 486 description << " " >> 487 << "Ntuple " << ntupleId << " has to be created first. "; >> 488 G4Exception("G4XmlNtupleManager::CreateNtupleDColumn()", >> 489 "Analysis_W005", JustWarning, description); >> 490 return; 88 } 491 } 89 492 90 // Write header << 493 #ifdef G4VERBOSE 91 G4String path = "/"; << 494 if ( fState.GetVerboseL4() ) { 92 path.append(fFileManager->GetNtupleDirectory << 495 G4ExceptionDescription description; 93 ntupleDescription->GetNtuple() << 496 description << ntupleBooking->m_name << " ntupleId " << ntupleId; 94 ->write_header(path, ntupleName, << 497 fState.GetVerboseL4()->Message("finish", "ntuple", description); 95 ntupleDescription->GetNtupl << 498 } 96 fFileManager->LockDirectoryNames(); << 499 #endif >> 500 >> 501 // Finish ntuple if ntuple already exists >> 502 if ( ntupleDescription->fNtuple ) { >> 503 G4String path = "/"; >> 504 path.append(fFileManager->GetNtupleDirectoryName()); >> 505 ntupleDescription->fNtuple >> 506 ->write_header(path, ntupleBooking->m_name, ntupleBooking->m_title); >> 507 >> 508 fFileManager->LockNtupleDirectoryName(); >> 509 } >> 510 >> 511 #ifdef G4VERBOSE >> 512 if ( fState.GetVerboseL2() ) { >> 513 G4ExceptionDescription description; >> 514 description << ntupleBooking->m_name << " ntupleId " << ntupleId; >> 515 fState.GetVerboseL2()->Message("finish", "ntuple", description); >> 516 } >> 517 #endif >> 518 } >> 519 >> 520 //_____________________________________________________________________________ >> 521 G4bool G4XmlNtupleManager::FillNtupleIColumn(G4int columnId, G4int value) >> 522 { >> 523 return FillNtupleIColumn(fFirstId, columnId, value); >> 524 } >> 525 >> 526 //_____________________________________________________________________________ >> 527 G4bool G4XmlNtupleManager::FillNtupleFColumn(G4int columnId, G4float value) >> 528 { >> 529 return FillNtupleFColumn(fFirstId, columnId, value); >> 530 } >> 531 >> 532 //_____________________________________________________________________________ >> 533 G4bool G4XmlNtupleManager::FillNtupleDColumn(G4int columnId, G4double value) >> 534 { >> 535 return FillNtupleDColumn(fFirstId, columnId, value); >> 536 } >> 537 >> 538 //_____________________________________________________________________________ >> 539 G4bool G4XmlNtupleManager::FillNtupleIColumn(G4int ntupleId, G4int columnId, >> 540 G4int value) >> 541 { >> 542 tools::waxml::ntuple::column<int>* column >> 543 = GetNtupleIColumn(ntupleId, columnId); >> 544 if ( ! column ) { >> 545 G4ExceptionDescription description; >> 546 description << " " << "column " << columnId << " does not exist."; >> 547 G4Exception("G4XmlNtupleManager::FillNtupleIColumn()", >> 548 "Analysis_W009", JustWarning, description); >> 549 return false; >> 550 } >> 551 >> 552 column->fill(value); >> 553 #ifdef G4VERBOSE >> 554 if ( fState.GetVerboseL4() ) { >> 555 G4ExceptionDescription description; >> 556 description << " ntupleId " << ntupleId >> 557 << " columnId " << columnId << " value " << value; >> 558 fState.GetVerboseL4()->Message("fill", "ntuple I column", description); >> 559 } >> 560 #endif >> 561 return true; >> 562 } >> 563 //_____________________________________________________________________________ >> 564 G4bool G4XmlNtupleManager::FillNtupleFColumn(G4int ntupleId, G4int columnId, >> 565 G4float value) >> 566 { >> 567 tools::waxml::ntuple::column<float>* column >> 568 = GetNtupleFColumn(ntupleId, columnId); >> 569 if ( ! column ) { >> 570 G4ExceptionDescription description; >> 571 description << " " << "column " << columnId << " does not exist."; >> 572 G4Exception("G4XmlNtupleManager::FillNtupleFColumn()", >> 573 "Analysis_W009", JustWarning, description); >> 574 return false; >> 575 } >> 576 >> 577 column->fill(value); >> 578 #ifdef G4VERBOSE >> 579 if ( fState.GetVerboseL4() ) { >> 580 G4ExceptionDescription description; >> 581 description << " ntupleId " << ntupleId >> 582 << " columnId " << columnId << " value " << value; >> 583 fState.GetVerboseL4()->Message("fill", "ntuple F column", description); >> 584 } >> 585 #endif >> 586 return true; >> 587 } >> 588 >> 589 //_____________________________________________________________________________ >> 590 G4bool G4XmlNtupleManager::FillNtupleDColumn(G4int ntupleId, G4int columnId, >> 591 G4double value) >> 592 { >> 593 tools::waxml::ntuple::column<double>* column >> 594 = GetNtupleDColumn(ntupleId, columnId); >> 595 if ( ! column ) { >> 596 G4ExceptionDescription description; >> 597 description << " " << "column " << columnId << " does not exist."; >> 598 G4Exception("G4XmlNtupleManager::FillNtupleDColumn()", >> 599 "Analysis_W009", JustWarning, description); >> 600 return false; >> 601 } >> 602 >> 603 column->fill(value); >> 604 #ifdef G4VERBOSE >> 605 if ( fState.GetVerboseL4() ) { >> 606 G4ExceptionDescription description; >> 607 description << " ntupleId " << ntupleId >> 608 << " columnId " << columnId << " value " << value; >> 609 fState.GetVerboseL4()->Message("fill", "ntuple D column", description); >> 610 } >> 611 #endif >> 612 return true; >> 613 } >> 614 >> 615 //_____________________________________________________________________________ >> 616 G4bool G4XmlNtupleManager::AddNtupleRow() >> 617 { >> 618 return AddNtupleRow(fFirstId); >> 619 } >> 620 >> 621 //_____________________________________________________________________________ >> 622 G4bool G4XmlNtupleManager::AddNtupleRow(G4int ntupleId) >> 623 { >> 624 #ifdef G4VERBOSE >> 625 if ( fState.GetVerboseL4() ) { >> 626 G4ExceptionDescription description; >> 627 description << " ntupleId " << ntupleId; >> 628 fState.GetVerboseL4()->Message("add", "ntuple row", description); >> 629 } >> 630 #endif >> 631 >> 632 G4XmlNtupleDescription* ntupleDescription >> 633 = GetNtupleInFunction(ntupleId, "AddNtupleRow"); >> 634 >> 635 if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) { >> 636 G4ExceptionDescription description; >> 637 description << " " << "ntuple does not exist. "; >> 638 G4Exception("G4XmlNtupleManager::AddNtupleRow()", >> 639 "Analysis_W008", JustWarning, description); >> 640 return false; >> 641 } >> 642 >> 643 ntupleDescription->fNtuple->add_row(); >> 644 #ifdef G4VERBOSE >> 645 if ( fState.GetVerboseL4() ) { >> 646 G4ExceptionDescription description; >> 647 description << " ntupleId " << ntupleId; >> 648 fState.GetVerboseL4()->Message("add", "ntuple row", description); >> 649 } >> 650 #endif >> 651 >> 652 return true; 97 } 653 } >> 654 98 655