Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CsvRFileManager.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: G4CsvRFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 21/10/2014 (ivana@ipno.in2p3.fr)
29 
30 #include "G4CsvRFileManager.hh"
32 
33 //_____________________________________________________________________________
35  : G4BaseFileManager(state),
36  fRFiles()
37 {
38 }
39 
40 //_____________________________________________________________________________
42 {
43  for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
44  delete fRFiles[i];
45  }
46 }
47 
48 //
49 // public methods
50 //
51 
52 //_____________________________________________________________________________
54 {
55 #ifdef G4VERBOSE
56  if ( fState.GetVerboseL4() )
57  fState.GetVerboseL4()->Message("open", "read analysis file", fileName);
58 #endif
59 
60  // create new file
61  std::ifstream* newFile = new std::ifstream(fileName);
62  if ( ! newFile->is_open() ) {
63  G4ExceptionDescription description;
64  description << " " << "Cannot open file " << fileName;
65  G4Exception("G4CsvAnalysisReader::OpenRFile()",
66  "Analysis_WR001", JustWarning, description);
67  return false;
68  }
69 
70  // add file in a map and delete the previous file if it exists
71  std::map<G4String, std::ifstream*>::iterator it
72  = fRFiles.find(fileName);
73  if ( it != fRFiles.end() ) {
74  delete it->second;
75  it->second = newFile;
76  }
77  else {
78  fRFiles[fileName] = newFile;
79  }
80 
81 #ifdef G4VERBOSE
82  if ( fState.GetVerboseL1() )
84  ->Message("open", "read analysis file", fileName);
85 #endif
86 
87  return true;
88 }
89 
90 //_____________________________________________________________________________
91 std::ifstream* G4CsvRFileManager::GetRFile(const G4String& fileName) const
92 {
93  std::map<G4String, std::ifstream*>::const_iterator it
94  = fRFiles.find(fileName);
95  if ( it != fRFiles.end() )
96  return it->second;
97  else {
98  return nullptr;
99  }
100 }
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
const G4AnalysisManagerState & fState
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4CsvRFileManager(const G4AnalysisManagerState &state)
int G4int
Definition: G4Types.hh:78
const G4AnalysisVerbose * GetVerboseL4() const
std::ifstream * GetRFile(const G4String &fileName) const
bool G4bool
Definition: G4Types.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4bool OpenRFile(const G4String &fileName)
const G4AnalysisVerbose * GetVerboseL1() const