ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CsvFileManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4CsvFileManager.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, 18/06/2013 (ivana@ipno.in2p3.fr)
28 
29 #include "G4CsvFileManager.hh"
31 
32 //_____________________________________________________________________________
34  : G4VFileManager(state)
35 {}
36 
37 //_____________________________________________________________________________
39 {}
40 
41 //
42 // public methods
43 //
44 
45 //_____________________________________________________________________________
47 {
48  // Keep file name
49  fFileName = fileName;
50 
51  fLockFileName = true;
53  fIsOpenFile = true;
54 
55  return true;
56 }
57 
58 //_____________________________________________________________________________
60 {
61  // nothing to be done for Csv file
62  return true;
63 }
64 
65 //_____________________________________________________________________________
67 {
68  fLockFileName = false;
69  fIsOpenFile = false;
70  return true;
71 }
72 
73 //_____________________________________________________________________________
76 {
77  G4String ntupleName = ntupleDescription->fNtupleBooking.name();
78 
79 #ifdef G4VERBOSE
80  if ( fState.GetVerboseL4() )
82  ->Message("create", "file", GetNtupleFileName(ntupleName));
83 #endif
84 
85  auto ntupleFile = new std::ofstream(GetNtupleFileName(ntupleName));
86  if ( ntupleFile->fail() ) {
87  delete ntupleFile;
88  G4ExceptionDescription description;
89  description << " " << "Cannot open file "
90  << GetNtupleFileName(ntupleName);
91  G4Exception("G4CsvFileManager::CreateNtupleFile()",
92  "Analysis_W001", JustWarning, description);
93  return false;
94  }
95 
96 #ifdef G4VERBOSE
97  if ( fState.GetVerboseL1() )
99  ->Message("create", "file", GetNtupleFileName(ntupleName));
100 #endif
101 
102  ntupleDescription->fFile = ntupleFile;
103  return true;
104 }
105 
106 //_____________________________________________________________________________
109 {
110  // Do nothing if there is no file
111  if ( ! ntupleDescription->fFile ) return true;
112 
113  G4String ntupleName = ntupleDescription->fNtupleBooking.name();
114 
115 #ifdef G4VERBOSE
116  if ( fState.GetVerboseL4() )
118  ->Message("close", "file", GetNtupleFileName(ntupleName));
119 #endif
120 
121  // close file
122  ntupleDescription->fFile->close();
123 
124 #ifdef G4VERBOSE
125  if ( fState.GetVerboseL1() )
127  ->Message("close", "file", GetNtupleFileName(ntupleName));
128 #endif
129 
130  return true;
131 }
132