Geant4  10.01.p02
G4BaseFileManager.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: G4BaseFileManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 10/09/2014 (ivana@ipno.in2p3.fr)
29 
30 #include "G4BaseFileManager.hh"
31 
32 #include "G4Threading.hh"
33 
34 //_____________________________________________________________________________
36  : fState(state),
37  fFileName("")
38 {
39 }
40 
41 //_____________________________________________________________________________
43 {
44 }
45 
46 //
47 // private methods
48 //
49 
50 //_____________________________________________________________________________
52 {
53  G4String extension;
54  if ( name.find(".") != std::string::npos ) {
55  extension = name.substr(name.find("."));
56  name = name.substr(0, name.find("."));
57  }
58  else {
59  extension = ".";
60  extension.append(GetFileType());
61  }
62  return extension;
63 }
64 
65 //
66 // public methods
67 //
68 
69 //_____________________________________________________________________________
71  G4bool isPerThread) const
72 {
73  G4String name(baseFileName);
74  if ( name == "" ) name = fFileName;
75 
76  // Take out file extension
77  G4String extension = TakeOffExtension(name);
78 
79  // Add thread Id to a file name if MT processing
80  if ( isPerThread && ! fState.GetIsMaster() ) {
81  std::ostringstream os;
83  name.append("_t");
84  name.append(os.str());
85  }
86 
87  // Add (back if it was present) file extension
88  name.append(extension);
89 
90  return name;
91 }
92 
93 //_____________________________________________________________________________
95 {
97 
98  // Take out file extension
99  G4String extension = TakeOffExtension(name);
100 
101  // Add ntupleName
102  name.append("_nt_");
103  name.append(ntupleName);
104 
105  // Add thread Id to a file name if MT processing
106  if ( ! fState.GetIsMaster() ) {
107  std::ostringstream os;
109  name.append("_t");
110  name.append(os.str());
111  }
112 
113  // Add (back if it was present) file extension
114  name.append(extension);
115 
116  return name;
117 }
118 
119 //_____________________________________________________________________________
121  const G4String& hnName) const
122 {
124 
125  // Take out file extension
126  G4String extension = TakeOffExtension(name);
127 
128  // Add _hnType_hnName
129  name.append("_");
130  name.append(hnType);
131  name.append("_");
132  name.append(hnName);
133 
134  // Add (back if it was present) file extension
135  name.append(extension);
136 
137  return name;
138 }
139 
140 //_____________________________________________________________________________
142 {
143  G4String fileType = fState.GetType();
144  fileType.toLower();
145  return fileType;
146 }
147 
148 
const G4AnalysisManagerState & fState
G4String GetNtupleFileName(const G4String &ntupleName) const
G4String name
Definition: TRTMaterials.hh:40
G4String GetHnFileName(const G4String &hnType, const G4String &hnName) const
virtual ~G4BaseFileManager()
G4String GetFileType() const
bool G4bool
Definition: G4Types.hh:79
G4String TakeOffExtension(G4String &name) const
G4BaseFileManager(const G4AnalysisManagerState &state)
void toLower()
G4String & append(const G4String &)
G4String GetFullFileName(const G4String &baseFileName="", G4bool isPerThread=true) const
G4int G4GetThreadId()
Definition: G4Threading.cc:127