Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4Hdf5RFileManager.cc
이 파일의 문서화 페이지로 가기
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 // $Id$
27 
28 // Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
29 
30 #include "G4Hdf5RFileManager.hh"
32 #include "G4AnalysisUtilities.hh"
33 
34 #include "tools/hdf5/h2file"
35 #include <tools/zlib>
36 
37 #include <iostream>
38 #include <cstdio>
39 
40 using namespace G4Analysis;
41 
42 //_____________________________________________________________________________
44 
45 //_____________________________________________________________________________
47  : G4BaseFileManager(state),
48  fRFiles()
49 {
50 }
51 
52 //_____________________________________________________________________________
54 {
55 }
56 
57 //
58 // private methods
59 //
60 
61 //_____________________________________________________________________________
63  G4bool isPerThread)
64 {
65  // Get full file name
66  G4String name = GetFullFileName(fileName, isPerThread);
67 
68 #ifdef G4VERBOSE
69  if ( fState.GetVerboseL4() )
70  fState.GetVerboseL4()->Message("open", "read analysis file", name);
71 #endif
72 
73  // create new file
74  hid_t newFile = H5Fopen(name, H5F_ACC_RDONLY, H5P_DEFAULT);
75  if ( newFile < 0 ) {
76  G4ExceptionDescription description;
77  description << " " << "Cannot open file " << name;
78  G4Exception("G4Hdf5RFileManager::OpenFile()",
79  "Analysis_WR001", JustWarning, description);
80  return false;
81  }
82 
83  // newFile->add_unziper('Z',tools::decompress_buffer);
84 
85  // add file in a map
86  std::map<G4String, hid_t>::iterator it
87  = fRFiles.find(name);
88  if ( it != fRFiles.end() ) {
89  it->second = newFile;
90  }
91  else {
92  fRFiles[name] = newFile;
93  }
94 
95 #ifdef G4VERBOSE
96  if ( fState.GetVerboseL1() )
98  ->Message("open", "read analysis file", name);
99 #endif
100 
101  return true;
102 }
103 
104 //_____________________________________________________________________________
105 hid_t G4Hdf5RFileManager::OpenDirectory(hid_t file, const G4String& directoryName)
106 {
107 #ifdef G4VERBOSE
108  if ( fState.GetVerboseL4() ) {
109  fState.GetVerboseL4()->Message("open", "read directory", directoryName);
110  }
111 #endif
112 
113  auto directory = tools_H5Gopen(file, directoryName);
114  if ( directory < 0 ) {
115  G4ExceptionDescription description;
116  description << " "
117  << "cannot open directory " << directoryName;
118  G4Exception("G4Hdf5RFileManager::OpenDirectory()",
119  "Analysis_W001", JustWarning, description);
120  return kInvalidId;
121  }
122  else {
123 #ifdef G4VERBOSE
124  if ( fState.GetVerboseL2() ) {
125  fState.GetVerboseL2()->Message("open", "read directory", directoryName);
126  }
127 #endif
128  return directory;
129  }
130 }
131 
132 //_____________________________________________________________________________
133 hid_t G4Hdf5RFileManager::GetRDirectory(const G4String& directoryType,
134  const G4String& fileName,
135  const G4String& dirName,
136  G4bool isPerThread)
137 {
138  // Get or open a file
139  auto rfile = GetRFile(fileName, isPerThread);
140  if ( rfile < 0 ) {
141  // Try to open it if not found in the map
142  if ( ! OpenRFile(fileName, isPerThread) ) return kInvalidId;
143  rfile = GetRFile(fileName, isPerThread);
144  }
145 
146  // Use default directory name if not specified
147  auto newDirName = dirName;
148  if ( newDirName == "" ) {
149  // if ( fDefaultDirectory > 0 ) {
150  // // Return the default directory if the name is not set and the default directory
151  // // already exists
152  // directory = fDefaultDirectory;
153  // return true;
154  // } else {
155  // Create the default directory if the name is not set and the default directory
156  // does not yet exist
157  newDirName = fgkDefaultDirectoryName;
158  newDirName += "_";
159  newDirName += directoryType;
160  }
161 
162  // Open directory
163  return OpenDirectory(rfile, newDirName);
164 }
165 
166 
167 //
168 // public methods
169 //
170 
171 //_____________________________________________________________________________
173  G4bool isPerThread) const
174 {
175  // Get full file name
176  G4String name = GetFullFileName(fileName, isPerThread);
177 
178  std::map<G4String, hid_t>::const_iterator it
179  = fRFiles.find(name);
180  if ( it != fRFiles.end() )
181  return it->second;
182  else {
183  return kInvalidId;
184  }
185 }
186 
187 //_____________________________________________________________________________
188 hid_t G4Hdf5RFileManager::GetHistoRDirectory(const G4String& fileName, const G4String& dirName,
189  G4bool isPerThread)
190 {
191  return GetRDirectory("histograms", fileName, dirName, isPerThread);
192 }
193 
194 //_____________________________________________________________________________
195 hid_t G4Hdf5RFileManager::GetNtupleRDirectory(const G4String& fileName, const G4String& dirName,
196  G4bool isPerThread)
197 {
198  return GetRDirectory("ntuples", fileName, dirName, isPerThread);
199 }
200 
201 
const XML_Char * name
Definition: expat.h:151
const G4AnalysisVerbose * GetVerboseL2() const
hid_t GetRFile(const G4String &fileName, G4bool isPerThread) const
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
hid_t OpenRFile(const G4String &fileName, G4bool isPerThread)
std::map< G4String, hid_t > fRFiles
hid_t GetRDirectory(const G4String &directoryType, const G4String &fileName, const G4String &dirName, G4bool isPerThread)
hid_t OpenDirectory(hid_t file, const G4String &directoryName)
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
static const G4String fgkDefaultDirectoryName
bool G4bool
Definition: G4Types.hh:79
hid_t GetNtupleRDirectory(const G4String &fileName, const G4String &dirName, G4bool isPerThread)
const G4AnalysisVerbose * GetVerboseL4() const
const G4int kInvalidId
const G4AnalysisManagerState & fState
G4Hdf5RFileManager(const G4AnalysisManagerState &state)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
TFile * file
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
hid_t GetHistoRDirectory(const G4String &fileName, const G4String &dirName, G4bool isPerThread)
const G4AnalysisVerbose * GetVerboseL1() const