Geant4-11
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes
G4RootRFileManager Class Reference

#include <G4RootRFileManager.hh>

Inheritance diagram for G4RootRFileManager:
G4VRFileManager G4BaseFileManager

Public Member Functions

void AddFileName (const G4String &fileName)
 
virtual void CloseFiles () final
 
 G4RootRFileManager ()=delete
 
 G4RootRFileManager (const G4AnalysisManagerState &state)
 
G4String GetFileName () const
 
const std::vector< G4String > & GetFileNames () const
 
virtual G4String GetFileType () const final
 
G4String GetFullFileName (const G4String &baseFileName="", G4bool isPerThread=true) const
 
G4String GetHnFileName (const G4String &hnType, const G4String &hnName) const
 
template<typename HT >
std::shared_ptr< G4VTHnRFileManager< HT > > GetHnRFileManager () const
 
G4String GetNtupleFileName (const G4String &ntupleName) const
 
G4String GetNtupleFileName (G4int ntupleFileNumber) const
 
G4String GetPlotFileName () const
 
tools::rroot::file * GetRFile (const G4String &fileName, G4bool isPerThread) const
 
virtual G4bool OpenRFile (const G4String &fileName, G4bool isPerThread)
 
virtual G4bool SetFileName (const G4String &fileName)
 
virtual ~G4RootRFileManager ()
 

Protected Member Functions

void Message (G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
 

Protected Attributes

G4String fFileName
 
std::vector< G4StringfFileNames
 
std::shared_ptr< G4VTHnRFileManager< tools::histo::h1d > > fH1RFileManager { nullptr }
 
std::shared_ptr< G4VTHnRFileManager< tools::histo::h2d > > fH2RFileManager { nullptr }
 
std::shared_ptr< G4VTHnRFileManager< tools::histo::h3d > > fH3RFileManager { nullptr }
 
std::shared_ptr< G4VTHnRFileManager< tools::histo::p1d > > fP1RFileManager { nullptr }
 
std::shared_ptr< G4VTHnRFileManager< tools::histo::p2d > > fP2RFileManager { nullptr }
 
const G4AnalysisManagerStatefState
 

Private Attributes

std::map< G4String, tools::rroot::file * > fRFiles
 

Static Private Attributes

static constexpr std::string_view fkClass { "G4RootRFileManager" }
 

Detailed Description

Definition at line 47 of file G4RootRFileManager.hh.

Constructor & Destructor Documentation

◆ G4RootRFileManager() [1/2]

G4RootRFileManager::G4RootRFileManager ( const G4AnalysisManagerState state)
explicit

Definition at line 41 of file G4RootRFileManager.cc.

42 : G4VRFileManager(state)
43{
44 // Create helpers defined in the base class
45 fH1RFileManager = std::make_shared<G4RootHnRFileManager<histo::h1d>>(this);
46 fH2RFileManager = std::make_shared<G4RootHnRFileManager<histo::h2d>>(this);
47 fH3RFileManager = std::make_shared<G4RootHnRFileManager<histo::h3d>>(this);
48 fP1RFileManager = std::make_shared<G4RootHnRFileManager<histo::p1d>>(this);
49 fP2RFileManager = std::make_shared<G4RootHnRFileManager<histo::p2d>>(this);
50}
std::shared_ptr< G4VTHnRFileManager< tools::histo::h2d > > fH2RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::p2d > > fP2RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::h3d > > fH3RFileManager
G4VRFileManager()=delete
std::shared_ptr< G4VTHnRFileManager< tools::histo::p1d > > fP1RFileManager
std::shared_ptr< G4VTHnRFileManager< tools::histo::h1d > > fH1RFileManager

References G4VRFileManager::fH1RFileManager, G4VRFileManager::fH2RFileManager, G4VRFileManager::fH3RFileManager, G4VRFileManager::fP1RFileManager, and G4VRFileManager::fP2RFileManager.

◆ G4RootRFileManager() [2/2]

G4RootRFileManager::G4RootRFileManager ( )
delete

◆ ~G4RootRFileManager()

G4RootRFileManager::~G4RootRFileManager ( )
virtual

Definition at line 53 of file G4RootRFileManager.cc.

54{
55 for ( auto& rfile : fRFiles ) {
56 delete rfile.second;
57 }
58}
std::map< G4String, tools::rroot::file * > fRFiles

References fRFiles.

Member Function Documentation

◆ AddFileName()

void G4BaseFileManager::AddFileName ( const G4String fileName)
inherited

Definition at line 44 of file G4BaseFileManager.cc.

45{
46 // G4cout << "registering " << fileName << " in manager of " << GetFileType() << G4endl;
47
48 // Do nothing in file name is already present
49 for ( const auto& name : fFileNames ) {
50 if ( name == fileName ) return;
51 }
52
53 fFileNames.push_back(fileName);
54}
std::vector< G4String > fFileNames
const char * name(G4int ptype)

References G4BaseFileManager::fFileNames, and G4InuclParticleNames::name().

◆ CloseFiles()

virtual void G4RootRFileManager::CloseFiles ( )
inlinefinalvirtual

Implements G4VRFileManager.

Definition at line 57 of file G4RootRFileManager.hh.

57{}

◆ GetFileName()

G4String G4BaseFileManager::GetFileName ( ) const
inlineinherited

Definition at line 105 of file G4BaseFileManager.hh.

105 {
106 return fFileName;
107}

References G4BaseFileManager::fFileName.

◆ GetFileNames()

const std::vector< G4String > & G4BaseFileManager::GetFileNames ( ) const
inlineinherited

Definition at line 109 of file G4BaseFileManager.hh.

109 {
110 return fFileNames;
111}

References G4BaseFileManager::fFileNames.

Referenced by G4GenericFileManager::OpenFiles().

◆ GetFileType()

virtual G4String G4RootRFileManager::GetFileType ( ) const
inlinefinalvirtual

Reimplemented from G4BaseFileManager.

Definition at line 54 of file G4RootRFileManager.hh.

54{ return "Root"; }

◆ GetFullFileName()

G4String G4BaseFileManager::GetFullFileName ( const G4String baseFileName = "",
G4bool  isPerThread = true 
) const
inherited

Definition at line 63 of file G4BaseFileManager.cc.

65{
66 G4String fileName(baseFileName);
67 if ( fileName == "" ) fileName = fFileName;
68
69 // Take out file extension
70 auto name = G4Analysis::GetBaseName(fileName);
71
72 // Add thread Id to a file name if MT processing
73 if ( isPerThread && ! fState.GetIsMaster() ) {
74 std::ostringstream os;
76 name.append("_t");
77 name.append(os.str());
78 }
79
80 // Add (back if it was present or is defined) file extension
81 auto extension = G4Analysis::GetExtension(fileName, GetFileType());
82 if ( extension.size() ) {
83 name.append(".");
84 name.append(extension);
85 }
86
87 return name;
88}
virtual G4String GetFileType() const
const G4AnalysisManagerState & fState
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4String GetBaseName(const G4String &fileName)
G4int G4GetThreadId()
Definition: G4Threading.cc:122

References G4BaseFileManager::fFileName, G4Analysis::GetBaseName(), and G4InuclParticleNames::name().

Referenced by G4Hdf5FileManager::GetNtupleFileName(), G4RootFileManager::GetNtupleFileName(), G4XmlRFileManager::GetRFile(), G4Hdf5RFileManager::GetRFile(), GetRFile(), G4Hdf5FileManager::OpenFile(), G4RootFileManager::OpenFile(), G4XmlFileManager::OpenFile(), G4XmlRFileManager::OpenRFile(), G4Hdf5RFileManager::OpenRFile(), and OpenRFile().

◆ GetHnFileName()

G4String G4BaseFileManager::GetHnFileName ( const G4String hnType,
const G4String hnName 
) const
inherited

Definition at line 91 of file G4BaseFileManager.cc.

93{
94 return G4Analysis::GetHnFileName(fFileName, GetFileType(), hnType, hnName);
95}
G4String GetHnFileName(const G4String &fileName, const G4String &fileType, const G4String &hnType, const G4String &hnName)

References G4BaseFileManager::fFileName, G4BaseFileManager::GetFileType(), and G4Analysis::GetHnFileName().

◆ GetHnRFileManager()

template<typename HT >
std::shared_ptr< G4VTHnRFileManager< HT > > G4VRFileManager::GetHnRFileManager ( ) const
inherited

◆ GetNtupleFileName() [1/2]

G4String G4BaseFileManager::GetNtupleFileName ( const G4String ntupleName) const
inherited

Definition at line 98 of file G4BaseFileManager.cc.

99{
101}
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName)

References G4BaseFileManager::fFileName, G4BaseFileManager::GetFileType(), and G4Analysis::GetNtupleFileName().

◆ GetNtupleFileName() [2/2]

G4String G4BaseFileManager::GetNtupleFileName ( G4int  ntupleFileNumber) const
inherited

◆ GetPlotFileName()

G4String G4BaseFileManager::GetPlotFileName ( ) const
inherited

Definition at line 110 of file G4BaseFileManager.cc.

111{
113}
G4String GetPlotFileName(const G4String &fileName)

References G4BaseFileManager::fFileName, and G4Analysis::GetPlotFileName().

◆ GetRFile()

tools::rroot::file * G4RootRFileManager::GetRFile ( const G4String fileName,
G4bool  isPerThread 
) const

Definition at line 99 of file G4RootRFileManager.cc.

101{
102 // Get full file name
103 G4String name = GetFullFileName(fileName, isPerThread);
104
105 auto it = fRFiles.find(name);
106 if ( it != fRFiles.end() )
107 return it->second;
108 else {
109 return nullptr;
110 }
111}
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const

References fRFiles, G4BaseFileManager::GetFullFileName(), and G4InuclParticleNames::name().

◆ Message()

void G4BaseFileManager::Message ( G4int  level,
const G4String action,
const G4String objectType,
const G4String objectName = "",
G4bool  success = true 
) const
inlineprotectedinherited

◆ OpenRFile()

G4bool G4RootRFileManager::OpenRFile ( const G4String fileName,
G4bool  isPerThread 
)
virtual

Definition at line 65 of file G4RootRFileManager.cc.

67{
68 // Get full file name
69 G4String name = GetFullFileName(fileName, isPerThread);
70
71 Message(kVL4, "open", "read analysis file", name);
72
73 // create new file
74 auto newFile = new tools::rroot::file(G4cout, name);
75 newFile->add_unziper('Z',tools::decompress_buffer);
76
77 if ( ! newFile->is_open() ) {
78 Warn("Cannot open file " + name, fkClass, "OpenRFile");
79 delete newFile;
80 return false;
81 }
82
83 // add file in a map and delete the previous file if it exists
84 auto it = fRFiles.find(name);
85 if ( it != fRFiles.end() ) {
86 delete it->second;
87 it->second = newFile;
88 }
89 else {
90 fRFiles[name] = newFile;
91 }
92
93 Message(kVL1, "open", "read analysis file", name);
94
95 return true;
96}
G4GLOB_DLL std::ostream G4cout
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
static constexpr std::string_view fkClass
constexpr G4int kVL1
constexpr G4int kVL4
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

References geant4_check_module_cycles::file, fkClass, fRFiles, G4cout, G4BaseFileManager::GetFullFileName(), G4Analysis::kVL1, G4Analysis::kVL4, G4BaseFileManager::Message(), G4InuclParticleNames::name(), and G4Analysis::Warn().

◆ SetFileName()

G4bool G4BaseFileManager::SetFileName ( const G4String fileName)
inlinevirtualinherited

Reimplemented in G4VFileManager.

Definition at line 99 of file G4BaseFileManager.hh.

99 {
100 // CHECK if still needed in this base class
101 fFileName = fileName;
102 return true;
103}

References G4BaseFileManager::fFileName.

Referenced by G4VFileManager::SetFileName().

Field Documentation

◆ fFileName

G4String G4BaseFileManager::fFileName
protectedinherited

◆ fFileNames

std::vector<G4String> G4BaseFileManager::fFileNames
protectedinherited

◆ fH1RFileManager

std::shared_ptr<G4VTHnRFileManager<tools::histo::h1d> > G4VRFileManager::fH1RFileManager { nullptr }
protectedinherited

◆ fH2RFileManager

std::shared_ptr<G4VTHnRFileManager<tools::histo::h2d> > G4VRFileManager::fH2RFileManager { nullptr }
protectedinherited

◆ fH3RFileManager

std::shared_ptr<G4VTHnRFileManager<tools::histo::h3d> > G4VRFileManager::fH3RFileManager { nullptr }
protectedinherited

◆ fkClass

constexpr std::string_view G4RootRFileManager::fkClass { "G4RootRFileManager" }
staticconstexprprivate

Definition at line 69 of file G4RootRFileManager.hh.

Referenced by OpenRFile().

◆ fP1RFileManager

std::shared_ptr<G4VTHnRFileManager<tools::histo::p1d> > G4VRFileManager::fP1RFileManager { nullptr }
protectedinherited

◆ fP2RFileManager

std::shared_ptr<G4VTHnRFileManager<tools::histo::p2d> > G4VRFileManager::fP2RFileManager { nullptr }
protectedinherited

◆ fRFiles

std::map<G4String, tools::rroot::file*> G4RootRFileManager::fRFiles
private

Definition at line 72 of file G4RootRFileManager.hh.

Referenced by GetRFile(), OpenRFile(), and ~G4RootRFileManager().

◆ fState

const G4AnalysisManagerState& G4BaseFileManager::fState
protectedinherited

The documentation for this class was generated from the following files: