ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4XmlRFileManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4XmlRFileManager.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 
27 // Author: Ivana Hrivnacova, 10/09/2014 (ivana@ipno.in2p3.fr)
28 
29 #include "G4XmlRFileManager.hh"
31 
32 #include "tools/waxml/begend"
33 
34 //_____________________________________________________________________________
36  : G4BaseFileManager(state),
37  fReadFactory(0),
38  fRFiles()
39 {
40 }
41 
42 //_____________________________________________________________________________
44 {
45  for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
46  delete fRFiles[i];
47  }
48  delete fReadFactory;
49 }
50 
51 //
52 // public methods
53 //
54 
55 //_____________________________________________________________________________
57 {
58  // Get full file name (add only extension)
59  G4bool isPerThread = false;
60  G4String name = GetFullFileName(fileName, isPerThread);
61 
62 #ifdef G4VERBOSE
63  if ( fState.GetVerboseL4() )
64  fState.GetVerboseL4()->Message("open", "read analysis file", name);
65 #endif
66 
67  G4bool verbose = false;
68 
69  // create factory (if it does not yet exist)
70  if ( ! fReadFactory ) {
71  fReadFactory = new tools::xml::default_factory();
72  }
73 
74  // create new file
75  tools::raxml* newFile
76  = new tools::raxml(*fReadFactory, G4cout, verbose);
77 
78  // clear objects
79  // (this should not be needed when starting a new raxml)
80  std::vector<tools::raxml_out>& objs = newFile->objects();
81  objs.clear();
82 
83  G4bool compressed = false;
84  if ( ! newFile->load_file(name, compressed) ) {
85  G4ExceptionDescription description;
86  description << " " << "Cannot open file " << name;
87  G4Exception("G4XmlRFileManager::OpenRFile()",
88  "Analysis_WR001", JustWarning, description);
89  delete newFile;
90  return false;
91  }
92 
93  // add file in a map and delete the previous file if it exists
94  std::map<G4String, tools::raxml*>::iterator it
95  = fRFiles.find(name);
96  if ( it != fRFiles.end() ) {
97  delete it->second;
98  it->second = newFile;
99  }
100  else {
101  fRFiles[name] = newFile;
102  }
103 
104 #ifdef G4VERBOSE
105  if ( fState.GetVerboseL1() )
107  ->Message("open", "read analysis file", name);
108 #endif
109 
110  return true;
111 }
112 
113 //_____________________________________________________________________________
114 tools::raxml* G4XmlRFileManager::GetRFile(const G4String& fileName) const
115 {
116  // Get full file name (add only extension)
117  G4bool isPerThread = false;
118  G4String name = GetFullFileName(fileName, isPerThread);
119 
120  std::map<G4String, tools::raxml*>::const_iterator it
121  = fRFiles.find(name);
122  if ( it != fRFiles.end() )
123  return it->second;
124  else {
125  return nullptr;
126  }
127 }