Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4XmlRFileManager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
27// Author: Ivana Hrivnacova, 10/09/2014 (ivana@ipno.in2p3.fr)
28
29#include "G4XmlRFileManager.hh"
33
34#include "toolx/raxml"
35
36using namespace G4Analysis;
37using namespace tools;
38
39//_____________________________________________________________________________
41 : G4VRFileManager(state)
42{
43 // Create helpers defined in the base class
44 fH1RFileManager = std::make_shared<G4XmlHnRFileManager<histo::h1d>>(this);
45 fH2RFileManager = std::make_shared<G4XmlHnRFileManager<histo::h2d>>(this);
46 fH3RFileManager = std::make_shared<G4XmlHnRFileManager<histo::h3d>>(this);
47 fP1RFileManager = std::make_shared<G4XmlHnRFileManager<histo::p1d>>(this);
48 fP2RFileManager = std::make_shared<G4XmlHnRFileManager<histo::p2d>>(this);
49}
50
51//_____________________________________________________________________________
53{
54 for ( auto& rfile : fRFiles ) {
55 delete rfile.second;
56 }
57
58 delete fReadFactory;
59}
60
61//
62// public methods
63//
64
65//_____________________________________________________________________________
67{
68 // Get full file name (add only extension)
69 G4bool isPerThread = false;
70 G4String name = GetFullFileName(fileName, isPerThread);
71
72 Message(kVL4, "open", "read analysis file", name);
73
74 G4bool verbose = false;
75
76 // create factory (if it does not yet exist)
77 if (fReadFactory == nullptr) {
78 fReadFactory = new tools::xml::default_factory();
79 }
80
81 // create new file
82 auto newFile = new toolx::raxml(*fReadFactory, G4cout, verbose);
83
84 // clear objects
85 // (this should not be needed when starting a new raxml)
86 std::vector<tools::raxml_out>& objs = newFile->objects();
87 objs.clear();
88
89 G4bool compressed = false;
90 if ( ! newFile->load_file(name, compressed) ) {
91 Warn(G4String( "Cannot open file ") + name, fkClass, "OpenRFile");
92 delete newFile;
93 return false;
94 }
95
96 // add file in a map and delete the previous file if it exists
97 auto it = fRFiles.find(name);
98 if ( it != fRFiles.end() ) {
99 delete it->second;
100 it->second = newFile;
101 }
102 else {
103 fRFiles[name] = newFile;
104 }
105
106 Message(kVL1, "open", "read analysis file", name);
107
108 return true;
109}
110
111//_____________________________________________________________________________
112toolx::raxml* G4XmlRFileManager::GetRFile(const G4String& fileName) const
113{
114 // Get full file name (add only extension)
115 G4bool isPerThread = false;
116 G4String name = GetFullFileName(fileName, isPerThread);
117
118 auto it = fRFiles.find(name);
119 if (it != fRFiles.end()) {
120 return it->second;
121 }
122 return nullptr;
123}
bool G4bool
Definition: G4Types.hh:86
G4GLOB_DLL std::ostream G4cout
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
std::shared_ptr< G4VTHnRFileManager< tools::histo::h2d > > fH2RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::p2d > > fP2RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::h3d > > fH3RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::p1d > > fP1RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::h1d > > fH1RFileManager
G4XmlRFileManager()=delete
virtual G4bool OpenRFile(const G4String &fileName)
~G4XmlRFileManager() override
toolx::raxml * GetRFile(const G4String &fileName) const
constexpr G4int kVL1
constexpr G4int kVL4
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)