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: G4XmlAnalysisManager.cc 85317 2014-10-27 15:58:15Z gcosmo $ 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 "G4XmlAnalysisManager.hh" 30 #include "G4XmlAnalysisManager.hh" 30 #include "G4XmlFileManager.hh" 31 #include "G4XmlFileManager.hh" 31 #include "G4XmlNtupleFileManager.hh" << 32 #include "G4H1ToolsManager.hh" >> 33 #include "G4H2ToolsManager.hh" >> 34 #include "G4H3ToolsManager.hh" >> 35 #include "G4P1ToolsManager.hh" >> 36 #include "G4P2ToolsManager.hh" >> 37 #include "G4XmlNtupleManager.hh" 32 #include "G4AnalysisManagerState.hh" 38 #include "G4AnalysisManagerState.hh" 33 #include "G4AnalysisUtilities.hh" << 34 #include "G4ThreadLocalSingleton.hh" << 35 #include "G4Threading.hh" 39 #include "G4Threading.hh" >> 40 #include "G4AutoLock.hh" 36 41 37 using namespace G4Analysis; << 42 #include "tools/waxml/histos" 38 using std::make_shared; << 43 >> 44 // mutex in a file scope >> 45 >> 46 namespace { >> 47 //Mutex to lock master manager when merging H1 histograms >> 48 G4Mutex mergeH1Mutex = G4MUTEX_INITIALIZER; >> 49 //Mutex to lock master manager when merging H1 histograms >> 50 G4Mutex mergeH2Mutex = G4MUTEX_INITIALIZER; >> 51 //Mutex to lock master manager when merging H1 histograms >> 52 G4Mutex mergeH3Mutex = G4MUTEX_INITIALIZER; >> 53 //Mutex to lock master manager when merging P1 profiles >> 54 G4Mutex mergeP1Mutex = G4MUTEX_INITIALIZER; >> 55 //Mutex to lock master manager when merging P2 profiles >> 56 G4Mutex mergeP2Mutex = G4MUTEX_INITIALIZER; >> 57 } >> 58 >> 59 G4XmlAnalysisManager* G4XmlAnalysisManager::fgMasterInstance = 0; >> 60 G4ThreadLocal G4XmlAnalysisManager* G4XmlAnalysisManager::fgInstance = 0; 39 61 40 //____________________________________________ 62 //_____________________________________________________________________________ 41 G4XmlAnalysisManager* G4XmlAnalysisManager::In 63 G4XmlAnalysisManager* G4XmlAnalysisManager::Instance() 42 { 64 { 43 static G4ThreadLocalSingleton<G4XmlAnalysisM << 65 if ( fgInstance == 0 ) { 44 fgIsInstance = true; << 66 G4bool isMaster = ! G4Threading::IsWorkerThread(); 45 return instance.Instance(); << 67 fgInstance = new G4XmlAnalysisManager(isMaster); >> 68 } >> 69 >> 70 return fgInstance; >> 71 } >> 72 >> 73 //_____________________________________________________________________________ >> 74 G4XmlAnalysisManager::G4XmlAnalysisManager(G4bool isMaster) >> 75 : G4VAnalysisManager("Xml", isMaster), >> 76 fH1Manager(0), >> 77 fH2Manager(0), >> 78 fH3Manager(0), >> 79 fP1Manager(0), >> 80 fP2Manager(0), >> 81 fNtupleManager(0), >> 82 fFileManager(0) >> 83 { >> 84 if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) { >> 85 G4ExceptionDescription description; >> 86 description >> 87 << " " >> 88 << "G4XmlAnalysisManager already exists." >> 89 << "Cannot create another instance."; >> 90 G4Exception("G4XmlAnalysisManager::G4XmlAnalysisManager", >> 91 "Analysis_F001", FatalException, description); >> 92 } >> 93 if ( isMaster ) fgMasterInstance = this; >> 94 fgInstance = this; >> 95 >> 96 // Create managers >> 97 fH1Manager = new G4H1ToolsManager(fState); >> 98 fH2Manager = new G4H2ToolsManager(fState); >> 99 fH3Manager = new G4H3ToolsManager(fState); >> 100 fP1Manager = new G4P1ToolsManager(fState); >> 101 fP2Manager = new G4P2ToolsManager(fState); >> 102 fNtupleManager = new G4XmlNtupleManager(fState); >> 103 fFileManager = new G4XmlFileManager(fState); >> 104 fNtupleManager->SetFileManager(fFileManager); >> 105 // The managers will be deleted by the base class >> 106 >> 107 // Set managers to base class >> 108 SetH1Manager(fH1Manager); >> 109 SetH2Manager(fH2Manager); >> 110 SetH3Manager(fH3Manager); >> 111 SetP1Manager(fP1Manager); >> 112 SetP2Manager(fP2Manager); >> 113 SetNtupleManager(fNtupleManager); >> 114 SetFileManager(fFileManager); >> 115 } >> 116 >> 117 //_____________________________________________________________________________ >> 118 G4XmlAnalysisManager::~G4XmlAnalysisManager() >> 119 { >> 120 if ( fState.GetIsMaster() ) fgMasterInstance = 0; >> 121 fgInstance = 0; >> 122 } >> 123 >> 124 // >> 125 // private methods >> 126 // >> 127 >> 128 //_____________________________________________________________________________ >> 129 G4bool G4XmlAnalysisManager::WriteH1() >> 130 { >> 131 const std::vector<tools::histo::h1d*>& h1Vector >> 132 = fH1Manager->GetH1Vector(); >> 133 const std::vector<G4HnInformation*>& hnVector >> 134 = fH1Manager->GetHnVector(); >> 135 >> 136 if ( ! h1Vector.size() ) return true; >> 137 >> 138 if ( ! G4Threading::IsWorkerThread() ) { >> 139 >> 140 for ( G4int i=0; i<G4int(h1Vector.size()); ++i ) { >> 141 G4HnInformation* info = hnVector[i]; >> 142 G4bool activation = info->GetActivation(); >> 143 G4String name = info->GetName(); >> 144 // skip writing if activation is enabled and H1 is inactivated >> 145 if ( fState.GetIsActivation() && ( ! activation ) ) continue; >> 146 tools::histo::h1d* h1 = h1Vector[i]; >> 147 #ifdef G4VERBOSE >> 148 if ( fState.GetVerboseL3() ) >> 149 fState.GetVerboseL3()->Message("write", "h1d", name); >> 150 #endif >> 151 G4String path = "/"; >> 152 path.append(fFileManager->GetHistoDirectoryName()); >> 153 std::ofstream* hnFile = fFileManager->GetHnFile(); >> 154 G4bool result >> 155 = tools::waxml::write(*hnFile, *h1, path, name); >> 156 if ( ! result ) { >> 157 G4ExceptionDescription description; >> 158 description << " " << "saving histogram " << name << " failed"; >> 159 G4Exception("G4XmlAnalysisManager::Write()", >> 160 "Analysis_W022", JustWarning, description); >> 161 return false; >> 162 } >> 163 fFileManager->LockHistoDirectoryName(); >> 164 } >> 165 } >> 166 else { >> 167 // The worker manager just adds its histograms to the master >> 168 // This operation needs a lock >> 169 G4AutoLock lH1(&mergeH1Mutex); >> 170 fgMasterInstance->fH1Manager->AddH1Vector(h1Vector); >> 171 lH1.unlock(); >> 172 } >> 173 >> 174 return true; >> 175 } >> 176 >> 177 //_____________________________________________________________________________ >> 178 G4bool G4XmlAnalysisManager::WriteH2() >> 179 { >> 180 const std::vector<tools::histo::h2d*>& h2Vector >> 181 = fH2Manager->GetH2Vector(); >> 182 const std::vector<G4HnInformation*>& hnVector >> 183 = fH2Manager->GetHnVector(); >> 184 >> 185 if ( ! h2Vector.size() ) return true; >> 186 >> 187 if ( ! G4Threading::IsWorkerThread() ) { >> 188 >> 189 // h2 histograms >> 190 for ( G4int i=0; i<G4int(h2Vector.size()); ++i ) { >> 191 G4HnInformation* info = hnVector[i]; >> 192 G4bool activation = info->GetActivation(); >> 193 G4String name = info->GetName(); >> 194 // skip writing if inactivated >> 195 if ( fState.GetIsActivation() && ( ! activation ) ) continue; >> 196 tools::histo::h2d* h2 = h2Vector[i]; >> 197 #ifdef G4VERBOSE >> 198 if ( fState.GetVerboseL3() ) >> 199 fState.GetVerboseL3()->Message("write", "h2d", name); >> 200 #endif >> 201 G4String path = "/"; >> 202 path.append(fFileManager->GetHistoDirectoryName()); >> 203 std::ofstream* hnFile = fFileManager->GetHnFile(); >> 204 G4bool result >> 205 = tools::waxml::write(*hnFile, *h2, path, name); >> 206 if ( ! result ) { >> 207 G4ExceptionDescription description; >> 208 description << " " << "saving histogram " << name << " failed"; >> 209 G4Exception("G4XmlAnalysisManager::Write()", >> 210 "Analysis_W022", JustWarning, description); >> 211 return false; >> 212 } >> 213 fFileManager->LockHistoDirectoryName(); >> 214 } >> 215 } >> 216 else { >> 217 // The worker manager just adds its histograms to the master >> 218 // This operation needs a lock >> 219 G4AutoLock lH2(&mergeH2Mutex); >> 220 fgMasterInstance->fH2Manager->AddH2Vector(h2Vector); >> 221 lH2.unlock(); >> 222 } >> 223 >> 224 return true; 46 } 225 } 47 226 48 //____________________________________________ 227 //_____________________________________________________________________________ 49 G4bool G4XmlAnalysisManager::IsInstance() << 228 G4bool G4XmlAnalysisManager::WriteH3() 50 { 229 { 51 return fgIsInstance; << 230 const std::vector<tools::histo::h3d*>& h3Vector >> 231 = fH3Manager->GetH3Vector(); >> 232 const std::vector<G4HnInformation*>& hnVector >> 233 = fH3Manager->GetHnVector(); >> 234 >> 235 if ( ! h3Vector.size() ) return true; >> 236 >> 237 if ( ! G4Threading::IsWorkerThread() ) { >> 238 >> 239 // h3 histograms >> 240 for ( G4int i=0; i<G4int(h3Vector.size()); ++i ) { >> 241 G4HnInformation* info = hnVector[i]; >> 242 G4bool activation = info->GetActivation(); >> 243 G4String name = info->GetName(); >> 244 // skip writing if inactivated >> 245 if ( fState.GetIsActivation() && ( ! activation ) ) continue; >> 246 tools::histo::h3d* h3 = h3Vector[i]; >> 247 #ifdef G4VERBOSE >> 248 if ( fState.GetVerboseL3() ) >> 249 fState.GetVerboseL3()->Message("write", "h3d", name); >> 250 #endif >> 251 G4String path = "/"; >> 252 path.append(fFileManager->GetHistoDirectoryName()); >> 253 std::ofstream* hnFile = fFileManager->GetHnFile(); >> 254 G4bool result >> 255 = tools::waxml::write(*hnFile, *h3, path, name); >> 256 if ( ! result ) { >> 257 G4ExceptionDescription description; >> 258 description << " " << "saving histogram " << name << " failed"; >> 259 G4Exception("G4XmlAnalysisManager::Write()", >> 260 "Analysis_W022", JustWarning, description); >> 261 return false; >> 262 } >> 263 fFileManager->LockHistoDirectoryName(); >> 264 } >> 265 } >> 266 else { >> 267 // The worker manager just adds its histograms to the master >> 268 // This operation needs a lock >> 269 G4AutoLock lH3(&mergeH3Mutex); >> 270 fgMasterInstance->fH3Manager->AddH3Vector(h3Vector); >> 271 lH3.unlock(); >> 272 } >> 273 >> 274 return true; 52 } 275 } 53 276 54 //____________________________________________ 277 //_____________________________________________________________________________ 55 G4XmlAnalysisManager::G4XmlAnalysisManager() << 278 G4bool G4XmlAnalysisManager::WriteP1() 56 : G4ToolsAnalysisManager("Xml") << 57 { 279 { 58 // File Manager << 280 const std::vector<tools::histo::p1d*>& p1Vector 59 auto fileManager = std::make_shared<G4XmlFil << 281 = fP1Manager->GetP1Vector(); 60 SetFileManager(fileManager); << 282 const std::vector<G4HnInformation*>& hnVector >> 283 = fP1Manager->GetHnVector(); 61 284 62 // Ntuple file manager << 285 if ( ! p1Vector.size() ) return true; 63 fNtupleFileManager = std::make_shared<G4XmlN << 286 64 SetNtupleFileManager(fNtupleFileManager); << 287 if ( ! G4Threading::IsWorkerThread() ) { 65 fNtupleFileManager->SetFileManager(std::move << 288 66 fNtupleFileManager->SetBookingManager(fNtupl << 289 for ( G4int i=0; i<G4int(p1Vector.size()); ++i ) { >> 290 G4HnInformation* info = hnVector[i]; >> 291 G4bool activation = info->GetActivation(); >> 292 G4String name = info->GetName(); >> 293 // skip writing if activation is enabled and P1 is inactivated >> 294 if ( fState.GetIsActivation() && ( ! activation ) ) continue; >> 295 tools::histo::p1d* p1 = p1Vector[i]; >> 296 #ifdef G4VERBOSE >> 297 if ( fState.GetVerboseL3() ) >> 298 fState.GetVerboseL3()->Message("write", "p1d", name); >> 299 #endif >> 300 G4String path = "/"; >> 301 path.append(fFileManager->GetProfileDirectoryName()); >> 302 std::ofstream* hnFile = fFileManager->GetHnFile(); >> 303 G4bool result >> 304 = tools::waxml::write(*hnFile, *p1, path, name); >> 305 if ( ! result ) { >> 306 G4ExceptionDescription description; >> 307 description << " " << "saving profile " << name << " failed"; >> 308 G4Exception("G4XmlAnalysisManager::Write()", >> 309 "Analysis_W022", JustWarning, description); >> 310 return false; >> 311 } >> 312 fFileManager->LockProfileDirectoryName(); >> 313 } >> 314 } >> 315 else { >> 316 // The worker manager just adds its profiles to the master >> 317 // This operation needs a lock >> 318 G4AutoLock lP1(&mergeP1Mutex); >> 319 fgMasterInstance->fP1Manager->AddP1Vector(p1Vector); >> 320 lP1.unlock(); >> 321 } >> 322 >> 323 return true; 67 } 324 } >> 325 >> 326 //_____________________________________________________________________________ >> 327 G4bool G4XmlAnalysisManager::WriteP2() >> 328 { >> 329 const std::vector<tools::histo::p2d*>& p2Vector >> 330 = fP2Manager->GetP2Vector(); >> 331 const std::vector<G4HnInformation*>& hnVector >> 332 = fP2Manager->GetHnVector(); >> 333 >> 334 if ( ! p2Vector.size() ) return true; 68 335 >> 336 if ( ! G4Threading::IsWorkerThread() ) { >> 337 >> 338 for ( G4int i=0; i<G4int(p2Vector.size()); ++i ) { >> 339 G4HnInformation* info = hnVector[i]; >> 340 G4bool activation = info->GetActivation(); >> 341 G4String name = info->GetName(); >> 342 // skip writing if activation is enabled and P2 is inactivated >> 343 if ( fState.GetIsActivation() && ( ! activation ) ) continue; >> 344 tools::histo::p2d* p2 = p2Vector[i]; >> 345 #ifdef G4VERBOSE >> 346 if ( fState.GetVerboseL3() ) >> 347 fState.GetVerboseL3()->Message("write", "p2d", name); >> 348 #endif >> 349 G4String path = "/"; >> 350 path.append(fFileManager->GetProfileDirectoryName()); >> 351 std::ofstream* hnFile = fFileManager->GetHnFile(); >> 352 G4bool result >> 353 = tools::waxml::write(*hnFile, *p2, path, name); >> 354 if ( ! result ) { >> 355 G4ExceptionDescription description; >> 356 description << " " << "saving profile " << name << " failed"; >> 357 G4Exception("G4XmlAnalysisManager::Write()", >> 358 "Analysis_W022", JustWarning, description); >> 359 return false; >> 360 } >> 361 fFileManager->LockProfileDirectoryName(); >> 362 } >> 363 } >> 364 else { >> 365 // The worker manager just adds its profiles to the master >> 366 // This operation needs a lock >> 367 G4AutoLock lP2(&mergeP2Mutex); >> 368 fgMasterInstance->fP2Manager->AddP2Vector(p2Vector); >> 369 lP2.unlock(); >> 370 } >> 371 >> 372 return true; >> 373 } >> 374 69 //____________________________________________ 375 //_____________________________________________________________________________ 70 G4XmlAnalysisManager::~G4XmlAnalysisManager() << 376 G4bool G4XmlAnalysisManager::WriteNtuple() >> 377 { >> 378 const std::vector<G4XmlNtupleDescription*>& ntupleVector >> 379 = fNtupleManager->GetNtupleDescriptionVector(); >> 380 >> 381 for ( G4int i=0; i<G4int(ntupleVector.size()); ++i ) { >> 382 if ( ntupleVector[i]->fNtuple ) ntupleVector[i]->fNtuple->write_trailer(); >> 383 } >> 384 >> 385 return true; >> 386 } >> 387 >> 388 //_____________________________________________________________________________ >> 389 G4bool G4XmlAnalysisManager::CloseNtupleFiles() >> 390 { >> 391 const std::vector<G4XmlNtupleDescription*>& ntupleVector >> 392 = fNtupleManager->GetNtupleDescriptionVector(); >> 393 >> 394 // Close ntuple files >> 395 std::vector<G4XmlNtupleDescription*>::const_iterator it; >> 396 for (it = ntupleVector.begin(); it != ntupleVector.end(); it++ ) { >> 397 fFileManager->CloseNtupleFile((*it)); >> 398 } >> 399 >> 400 return true; >> 401 } >> 402 >> 403 >> 404 //_____________________________________________________________________________ >> 405 G4bool G4XmlAnalysisManager::Reset() >> 406 { >> 407 // Reset histograms and ntuple >> 408 >> 409 G4bool finalResult = true; >> 410 >> 411 G4bool result = fH1Manager->Reset(); >> 412 finalResult = finalResult && result; >> 413 >> 414 result = fH2Manager->Reset(); >> 415 finalResult = finalResult && result; >> 416 >> 417 result = fH3Manager->Reset(); >> 418 finalResult = finalResult && result; >> 419 >> 420 result = fP1Manager->Reset(); >> 421 finalResult = finalResult && result; >> 422 >> 423 result = fP2Manager->Reset(); >> 424 finalResult = finalResult && result; >> 425 >> 426 result = fNtupleManager->Reset(); >> 427 finalResult = finalResult && result; >> 428 >> 429 return finalResult; >> 430 } >> 431 >> 432 // >> 433 // protected methods >> 434 // >> 435 >> 436 //_____________________________________________________________________________ >> 437 G4bool G4XmlAnalysisManager::OpenFileImpl(const G4String& fileName) >> 438 { >> 439 G4bool finalResult = true; >> 440 G4bool result = fFileManager->SetFileName(fileName); >> 441 finalResult = finalResult && result; >> 442 >> 443 #ifdef G4VERBOSE >> 444 G4String name = fFileManager->GetFullFileName(); >> 445 if ( fState.GetVerboseL4() ) { >> 446 fState.GetVerboseL4()->Message("open", "analysis file", name); >> 447 } >> 448 #endif >> 449 >> 450 // Only lock file name in file manager >> 451 result = fFileManager->OpenFile(fileName); >> 452 finalResult = finalResult && result; >> 453 >> 454 // Create histograms file (on master) >> 455 if ( fState.GetIsMaster() ) { >> 456 result = fFileManager->CreateHnFile(); >> 457 finalResult = finalResult && result; >> 458 } >> 459 >> 460 // Create ntuples if they are booked >> 461 // (The files will be created with creating ntuples) >> 462 fNtupleManager->CreateNtuplesFromBooking(); >> 463 >> 464 #ifdef G4VERBOSE >> 465 if ( fState.GetVerboseL1() ) >> 466 fState.GetVerboseL1()->Message("open", "analysis file", name); >> 467 #endif >> 468 >> 469 return finalResult; >> 470 } >> 471 >> 472 //_____________________________________________________________________________ >> 473 G4bool G4XmlAnalysisManager::WriteImpl() >> 474 { >> 475 G4bool finalResult = true; >> 476 >> 477 #ifdef G4VERBOSE >> 478 G4String name = fFileManager->GetFullFileName(); >> 479 if ( fState.GetVerboseL4() ) >> 480 fState.GetVerboseL4()->Message("write", "files", name); >> 481 #endif >> 482 >> 483 // ntuples >> 484 WriteNtuple(); >> 485 >> 486 if ( ! fgMasterInstance && >> 487 ( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) || >> 488 ( ! fH3Manager->IsEmpty() ) || ( ! fP1Manager->IsEmpty() ) || >> 489 ( ! fP2Manager->IsEmpty() ) ) ) { >> 490 >> 491 G4ExceptionDescription description; >> 492 description >> 493 << " " << "No master G4XmlAnalysisManager instance exists." >> 494 << G4endl >> 495 << " " << "Histogram data will not be merged."; >> 496 G4Exception("G4XmlAnalysisManager::Write()", >> 497 "Analysis_W031", JustWarning, description); >> 498 >> 499 // Create Hn file per thread >> 500 G4bool result = fFileManager->CreateHnFile(); >> 501 if ( ! result ) return false; >> 502 } >> 503 >> 504 // H1 >> 505 G4bool result = WriteH1(); >> 506 finalResult = finalResult && result; >> 507 >> 508 // H2 >> 509 result = WriteH2(); >> 510 finalResult = finalResult && result; >> 511 >> 512 // H3 >> 513 result = WriteH3(); >> 514 finalResult = finalResult && result; >> 515 >> 516 // P1 >> 517 result = WriteP1(); >> 518 finalResult = finalResult && result; >> 519 >> 520 // P2 >> 521 result = WriteP2(); >> 522 finalResult = finalResult && result; >> 523 >> 524 // Write ASCII if activated >> 525 if ( IsAscii() ) { >> 526 result = WriteAscii(fFileManager->GetFileName()); >> 527 finalResult = finalResult && result; >> 528 } >> 529 >> 530 #ifdef G4VERBOSE >> 531 if ( fState.GetVerboseL1() ) >> 532 fState.GetVerboseL1() >> 533 ->Message("write", "file", fFileManager->GetFullFileName(), finalResult); >> 534 #endif >> 535 >> 536 return finalResult; >> 537 } >> 538 >> 539 //_____________________________________________________________________________ >> 540 G4bool G4XmlAnalysisManager::CloseFileImpl() 71 { 541 { 72 fgIsInstance = false; << 542 G4bool finalResult = true; >> 543 >> 544 #ifdef G4VERBOSE >> 545 if ( fState.GetVerboseL4() ) >> 546 fState.GetVerboseL4()->Message("close", "files", ""); >> 547 #endif >> 548 >> 549 // Unlock file name only >> 550 G4bool result = fFileManager->CloseFile(); >> 551 finalResult = finalResult && result; >> 552 >> 553 // Close Hn file >> 554 result = fFileManager->CloseHnFile(); >> 555 finalResult = finalResult && result; >> 556 >> 557 // Close ntuple files >> 558 if ( ( ! G4Threading::IsMultithreadedApplication() ) || >> 559 ( ! fState.GetIsMaster() ) ) { >> 560 // In sequential mode or in MT mode only on workers >> 561 result = CloseNtupleFiles(); >> 562 finalResult = finalResult && result; >> 563 } >> 564 >> 565 // reset data >> 566 result = Reset(); >> 567 if ( ! result ) { >> 568 G4ExceptionDescription description; >> 569 description << " " << "Resetting data failed"; >> 570 G4Exception("G4XmlAnalysisManager::CloseFile()", >> 571 "Analysis_W021", JustWarning, description); >> 572 } >> 573 finalResult = finalResult && result; >> 574 >> 575 // delete files if empty >> 576 // (ntuple files are created only if an ntuple is created) >> 577 if ( fFileManager->GetHnFile() && >> 578 fH1Manager->IsEmpty() && fH2Manager->IsEmpty() && fH3Manager->IsEmpty() && >> 579 fP1Manager->IsEmpty() && fP2Manager->IsEmpty() ) { >> 580 result = ! std::remove(fFileManager->GetFullFileName()); >> 581 // std::remove returns 0 when success >> 582 if ( ! result ) { >> 583 G4ExceptionDescription description; >> 584 description << " " << "Removing file " >> 585 << fFileManager->GetFullFileName() << " failed"; >> 586 G4Exception("G4XmlAnalysisManager::CloseFile()", >> 587 "Analysis_W021", JustWarning, description); >> 588 } >> 589 finalResult = finalResult && result; >> 590 #ifdef G4VERBOSE >> 591 if ( fState.GetVerboseL1() ) >> 592 fState.GetVerboseL1() >> 593 ->Message("delete", "empty file", fFileManager->GetFullFileName()); >> 594 #endif >> 595 } >> 596 else { >> 597 #ifdef G4VERBOSE >> 598 if ( fState.GetVerboseL2() ) >> 599 fState.GetVerboseL2() >> 600 ->Message("close", "files", ""); >> 601 #endif >> 602 } >> 603 >> 604 return finalResult; 73 } 605 } 74 606