Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  auto 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 {
123 
124  // Take out file extension
125  auto extension = TakeOffExtension(name);
126 
127  // Add _M followed by ntupleFileNumber
128  std::ostringstream os;
129  os << ntupleFileNumber;
130  name.append("_m");
131  name.append(os.str());
132 
133  // Add (back if it was present) file extension
134  name.append(extension);
135 
136  return name;
137 }
138 
139 //_____________________________________________________________________________
141  const G4String& hnName) const
142 {
144 
145  // Take out file extension
146  auto extension = TakeOffExtension(name);
147 
148  // Add _hnType_hnName
149  name.append("_");
150  name.append(hnType);
151  name.append("_");
152  name.append(hnName);
153 
154  // Add (back if it was present) file extension
155  name.append(extension);
156 
157  return name;
158 }
159 
160 //_____________________________________________________________________________
162 {
164 
165  // Take out file extension
166  auto extension = TakeOffExtension(name);
167 
168  // Add .ps extension
169  name.append(".ps");
170 
171  return name;
172 }
173 
174 //_____________________________________________________________________________
176 {
177  G4String fileType = fState.GetType();
178  fileType.toLower();
179  return fileType;
180 }
181 
182 
const XML_Char * name
Definition: expat.h:151
const G4AnalysisManagerState & fState
G4String GetNtupleFileName(const G4String &ntupleName) const
G4String GetPlotFileName() const
G4String GetHnFileName(const G4String &hnType, const G4String &hnName) const
int G4int
Definition: G4Types.hh:78
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:144