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: G4RootRFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $ 26 27 27 // Author: Ivana Hrivnacova, 10/09/2014 (ivan 28 // Author: Ivana Hrivnacova, 10/09/2014 (ivana@ipno.in2p3.fr) 28 29 29 #include "G4RootRFileManager.hh" 30 #include "G4RootRFileManager.hh" 30 #include "G4RootRFileDef.hh" << 31 #include "G4RootHnRFileManager.hh" << 32 #include "G4AnalysisManagerState.hh" 31 #include "G4AnalysisManagerState.hh" 33 #include "G4AnalysisUtilities.hh" << 34 32 35 #include "tools/rroot/file" 33 #include "tools/rroot/file" 36 #include "toolx/zlib" << 34 #include <tools/zlib> 37 35 38 using namespace G4Analysis; << 36 #include <iostream> 39 using namespace tools; << 37 #include <cstdio> 40 38 41 //____________________________________________ 39 //_____________________________________________________________________________ 42 G4RootRFileManager::G4RootRFileManager(const G 40 G4RootRFileManager::G4RootRFileManager(const G4AnalysisManagerState& state) 43 : G4VRFileManager(state) << 41 : G4BaseFileManager(state), >> 42 fRFiles() 44 { 43 { 45 // Create helpers defined in the base class << 46 fH1RFileManager = std::make_shared<G4RootHnR << 47 fH2RFileManager = std::make_shared<G4RootHnR << 48 fH3RFileManager = std::make_shared<G4RootHnR << 49 fP1RFileManager = std::make_shared<G4RootHnR << 50 fP2RFileManager = std::make_shared<G4RootHnR << 51 } 44 } 52 45 53 //____________________________________________ 46 //_____________________________________________________________________________ 54 G4RootRFileManager::~G4RootRFileManager() 47 G4RootRFileManager::~G4RootRFileManager() 55 { << 48 { 56 // Delete all open file and their directorie << 49 for (G4int i=0; i<G4int(fRFiles.size()); ++i) { 57 for ( auto& mapElement : fRFiles ) { << 50 delete fRFiles[i]; 58 auto rfileTuple = mapElement.second; << 51 } 59 delete std::get<1>(*rfileTuple); // histo << 60 delete std::get<2>(*rfileTuple);; // ntupl << 61 delete std::get<0>(*rfileTuple); // rfile << 62 delete rfileTuple; << 63 } << 64 } 52 } 65 53 66 // 54 // 67 // public methods 55 // public methods 68 // 56 // 69 57 70 //____________________________________________ 58 //_____________________________________________________________________________ 71 G4bool G4RootRFileManager::OpenRFile(const G4S 59 G4bool G4RootRFileManager::OpenRFile(const G4String& fileName, 72 G4bool is 60 G4bool isPerThread) 73 { 61 { 74 // Get full file name 62 // Get full file name 75 G4String name = GetFullFileName(fileName, is 63 G4String name = GetFullFileName(fileName, isPerThread); 76 64 77 Message(kVL4, "open", "read analysis file", << 65 #ifdef G4VERBOSE >> 66 if ( fState.GetVerboseL4() ) >> 67 fState.GetVerboseL4()->Message("open", "read analysis file", name); >> 68 #endif 78 69 79 // create new file 70 // create new file 80 auto newFile = new tools::rroot::file(G4cout << 71 tools::rroot::file* newFile = new tools::rroot::file(G4cout, name); 81 newFile->add_unziper('Z',toolx::decompress_b << 72 newFile->add_unziper('Z',tools::decompress_buffer); 82 << 73 83 if ( ! newFile->is_open() ) { 74 if ( ! newFile->is_open() ) { 84 Warn("Cannot open file " + name, fkClass, << 75 G4ExceptionDescription description; >> 76 description << " " << "Cannot open file " << name; >> 77 G4Exception("G4RootRFileManager::OpenFile()", >> 78 "Analysis_WR001", JustWarning, description); 85 delete newFile; 79 delete newFile; 86 return false; 80 return false; 87 } 81 } 88 82 89 auto newFileTuple = new G4RootRFile(newFile, << 90 << 91 // add file in a map and delete the previous 83 // add file in a map and delete the previous file if it exists 92 auto it = fRFiles.find(name); << 84 std::map<G4String, tools::rroot::file*>::iterator it 93 if ( it != fRFiles.end() ) { << 85 = fRFiles.find(name); >> 86 if ( it != fRFiles.end() ) { 94 delete it->second; 87 delete it->second; 95 it->second = newFileTuple; << 88 it->second = newFile; 96 } 89 } 97 else { 90 else { 98 fRFiles[name] = newFileTuple; << 91 fRFiles[name] = newFile; 99 } << 92 } 100 93 101 Message(kVL1, "open", "read analysis file", << 94 #ifdef G4VERBOSE >> 95 if ( fState.GetVerboseL1() ) >> 96 fState.GetVerboseL1() >> 97 ->Message("open", "read analysis file", name); >> 98 #endif 102 99 103 return true; 100 return true; 104 } << 101 } 105 << 102 106 //____________________________________________ 103 //_____________________________________________________________________________ 107 G4RootRFile* G4RootRFileManager::GetRFile(cons << 104 tools::rroot::file* G4RootRFileManager::GetRFile(const G4String& fileName, 108 G4bo << 105 G4bool isPerThread) const 109 { << 106 { 110 // Get full file name 107 // Get full file name 111 G4String name = GetFullFileName(fileName, is 108 G4String name = GetFullFileName(fileName, isPerThread); 112 109 113 auto it = fRFiles.find(name); << 110 std::map<G4String, tools::rroot::file*>::const_iterator it 114 if (it != fRFiles.end()) { << 111 = fRFiles.find(name); >> 112 if ( it != fRFiles.end() ) 115 return it->second; 113 return it->second; 116 } << 114 else { 117 return nullptr; << 115 return nullptr; >> 116 } 118 } 117 } 119 118