Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RootRFileManager.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 ([email protected])
28
29#include "G4RootRFileManager.hh"
32
33#include "tools/rroot/file"
34#include <tools/zlib>
35
36#include <iostream>
37#include <cstdio>
38
39//_____________________________________________________________________________
41 : G4BaseFileManager(state),
42 fRFiles()
43{
44}
45
46//_____________________________________________________________________________
48{
49 for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
50 delete fRFiles[i];
51 }
52}
53
54//
55// public methods
56//
57
58//_____________________________________________________________________________
60 G4bool isPerThread)
61{
62 // Get full file name
63 G4String name = GetFullFileName(fileName, isPerThread);
64
65#ifdef G4VERBOSE
66 if ( fState.GetVerboseL4() )
67 fState.GetVerboseL4()->Message("open", "read analysis file", name);
68#endif
69
70 // create new file
71 tools::rroot::file* newFile = new tools::rroot::file(G4cout, name);
72 newFile->add_unziper('Z',tools::decompress_buffer);
73
74 if ( ! newFile->is_open() ) {
75 G4ExceptionDescription description;
76 description << " " << "Cannot open file " << name;
77 G4Exception("G4RootRFileManager::OpenFile()",
78 "Analysis_WR001", JustWarning, description);
79 delete newFile;
80 return false;
81 }
82
83 // add file in a map and delete the previous file if it exists
84 std::map<G4String, tools::rroot::file*>::iterator it
85 = fRFiles.find(name);
86 if ( it != fRFiles.end() ) {
87 delete it->second;
88 it->second = newFile;
89 }
90 else {
91 fRFiles[name] = newFile;
92 }
93
94#ifdef G4VERBOSE
95 if ( fState.GetVerboseL1() )
97 ->Message("open", "read analysis file", name);
98#endif
99
100 return true;
101}
102
103//_____________________________________________________________________________
104tools::rroot::file* G4RootRFileManager::GetRFile(const G4String& fileName,
105 G4bool isPerThread) const
106{
107 // Get full file name
108 G4String name = GetFullFileName(fileName, isPerThread);
109
110 std::map<G4String, tools::rroot::file*>::const_iterator it
111 = fRFiles.find(name);
112 if ( it != fRFiles.end() )
113 return it->second;
114 else {
115 return nullptr;
116 }
117}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
const G4AnalysisVerbose * GetVerboseL1() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
const G4AnalysisManagerState & fState
G4RootRFileManager(const G4AnalysisManagerState &state)
virtual G4bool OpenRFile(const G4String &fileName, G4bool isPerThread)
tools::rroot::file * GetRFile(const G4String &fileName, G4bool isPerThread) const