Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 // $Id: G4XmlRFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 10/09/2014 (ivana@ipno.in2p3.fr)
29 
30 #include "G4XmlRFileManager.hh"
32 
33 #include "tools/waxml/begend"
34 
35 //_____________________________________________________________________________
37  : G4BaseFileManager(state),
38  fReadFactory(0),
39  fRFiles()
40 {
41 }
42 
43 //_____________________________________________________________________________
45 {
46  for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
47  delete fRFiles[i];
48  }
49  delete fReadFactory;
50 }
51 
52 //
53 // public methods
54 //
55 
56 //_____________________________________________________________________________
58 {
59  // Get full file name (add only extension)
60  G4bool isPerThread = false;
61  G4String name = GetFullFileName(fileName, isPerThread);
62 
63 #ifdef G4VERBOSE
64  if ( fState.GetVerboseL4() )
65  fState.GetVerboseL4()->Message("open", "read analysis file", name);
66 #endif
67 
68  G4bool verbose = false;
69 
70  // create factory (if it does not yet exist)
71  if ( ! fReadFactory ) {
72  fReadFactory = new tools::xml::default_factory();
73  }
74 
75  // create new file
76  tools::raxml* newFile
77  = new tools::raxml(*fReadFactory, G4cout, verbose);
78 
79  // clear objects
80  // (this should not be needed when starting a new raxml)
81  std::vector<tools::raxml_out>& objs = newFile->objects();
82  objs.clear();
83 
84  G4bool compressed = false;
85  if ( ! newFile->load_file(name, compressed) ) {
86  G4ExceptionDescription description;
87  description << " " << "Cannot open file " << name;
88  G4Exception("G4XmlRFileManager::OpenRFile()",
89  "Analysis_WR001", JustWarning, description);
90  delete newFile;
91  return false;
92  }
93 
94  // add file in a map and delete the previous file if it exists
95  std::map<G4String, tools::raxml*>::iterator it
96  = fRFiles.find(name);
97  if ( it != fRFiles.end() ) {
98  delete it->second;
99  it->second = newFile;
100  }
101  else {
102  fRFiles[name] = newFile;
103  }
104 
105 #ifdef G4VERBOSE
106  if ( fState.GetVerboseL1() )
108  ->Message("open", "read analysis file", name);
109 #endif
110 
111  return true;
112 }
113 
114 //_____________________________________________________________________________
115 tools::raxml* G4XmlRFileManager::GetRFile(const G4String& fileName) const
116 {
117  // Get full file name (add only extension)
118  G4bool isPerThread = false;
119  G4String name = GetFullFileName(fileName, isPerThread);
120 
121  std::map<G4String, tools::raxml*>::const_iterator it
122  = fRFiles.find(name);
123  if ( it != fRFiles.end() )
124  return it->second;
125  else {
126  return nullptr;
127  }
128 }
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const XML_Char * name
Definition: expat.h:151
const G4AnalysisManagerState & fState
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
const G4AnalysisVerbose * GetVerboseL4() const
bool G4bool
Definition: G4Types.hh:79
tools::raxml * GetRFile(const G4String &fileName) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4XmlRFileManager(const G4AnalysisManagerState &state)
virtual G4bool OpenRFile(const G4String &fileName)
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
const G4AnalysisVerbose * GetVerboseL1() const