|
||||
File indexing completed on 2025-01-18 09:59:29
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 0027 // Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr) 0028 0029 #include "G4AnalysisUtilities.hh" 0030 0031 #include "tools/waxml/histos" 0032 #include "tools/waxml/begend" 0033 0034 //_____________________________________________________________________________ 0035 template <typename HT> 0036 G4bool G4XmlHnFileManager<HT>::WriteExtra( 0037 HT* ht, const G4String& htName, const G4String& fileName) 0038 { 0039 // create a new file 0040 std::ofstream hnFile(fileName); 0041 0042 // Do nothing if there is no file 0043 if ( ! hnFile.is_open() ) return false; 0044 0045 // Write file opening 0046 tools::waxml::begin(hnFile); 0047 0048 // no directory supported in this mode 0049 G4String path = "/"; 0050 0051 // write histo 0052 auto result = tools::waxml::write(hnFile, *ht, path, htName); 0053 if ( ! result) { 0054 G4Analysis::Warn( 0055 "Saving " + G4Analysis::GetHnType<HT>() + " " + htName + " failed", 0056 fkClass, "WriteExtra"); 0057 return false; 0058 } 0059 0060 // close file 0061 tools::waxml::end(hnFile); 0062 hnFile.close(); 0063 return true; 0064 } 0065 0066 //_____________________________________________________________________________ 0067 template <typename HT> 0068 G4bool G4XmlHnFileManager<HT>::Write( 0069 HT* ht, const G4String& htName, G4String& fileName) 0070 { 0071 if ( fileName.empty()) { 0072 // should not happen 0073 G4cerr << "!!! Xml file name not defined." << G4endl; 0074 G4cerr << "!!! Write " << htName << " failed." << G4endl; 0075 return false; 0076 } 0077 0078 auto hnFile = fFileManager->GetTFile(fileName); 0079 if ( hnFile == nullptr ) { 0080 // This prototype can be used only with OpenFile() mode 0081 G4Analysis::Warn( 0082 G4String("Failed to get Xml file ") + fileName, fkClass, "Write"); 0083 return false; 0084 } 0085 0086 G4String path = "/"; 0087 path.append(fFileManager->GetHistoDirectoryName()); 0088 0089 auto result = tools::waxml::write(*hnFile, *ht, path, htName); 0090 fFileManager->LockDirectoryNames(); 0091 return result; 0092 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |