Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AnalysisUtilities.hh
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
27// Author: Ivana Hrivnacova, 04/07/2012 ([email protected])
28
29#ifndef G4AnalysisUtilities_h
30#define G4AnalysisUtilities_h 1
31
32#include "G4Exception.hh"
33#include "globals.hh"
34
35#include <vector>
36#include <memory>
37#include <string_view>
38
39// Enumeration for definition of available output types
40
41enum class G4AnalysisOutput {
42 kCsv,
43 kHdf5,
44 kRoot,
45 kXml,
46 kNone
47};
48
49namespace G4Analysis
50{
51
52// Constant expressions
53//
54constexpr G4int kX { 0 };
55constexpr G4int kY { 1 };
56constexpr G4int kZ { 2 };
57constexpr G4int kInvalidId { -1 };
58constexpr G4int kVL0 { 0 };
59constexpr G4int kVL1 { 1 };
60constexpr G4int kVL2 { 2 };
61constexpr G4int kVL3 { 3 };
62constexpr G4int kVL4 { 4 };
63constexpr unsigned int kDim1 { 1 };
64constexpr unsigned int kDim2 { 2 };
65constexpr unsigned int kDim3 { 3 };
66constexpr unsigned int kMaxDim { kDim3 };
67constexpr unsigned int kDefaultBasketSize { 32000 };
68constexpr unsigned int kDefaultBasketEntries {4000 };
69constexpr std::string_view kNamespaceName { "G4Analysis" };
70
71// Warning
72//
73void Warn(const G4String& message,
74 const std::string_view inClass,
75 const std::string_view inFunction);
76
77// Get unit value with added handling of "none"
78G4double GetUnitValue(const G4String& unit);
79
80// Tokenizer with taking into account composed strings within ""
81void Tokenize(const G4String& line, std::vector<G4String>& tokens);
82
83// Get output type from name
84G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn = true);
85size_t GetOutputId(const G4String& outputName, G4bool warn = true);
87
88// Get short hnType from the tools object
89template <typename HT>
91{
92 // tools::histo::h1d etc.
93 G4String hnTypeLong = HT::s_class();
94
95 // tools::histo::h1d -> h1 etc.
96 return hnTypeLong.substr(14, 2);
97}
98
99template <typename HT>
101{
102 // tools::histo::h1d etc.
103 G4String hnTypeLong = HT::s_class();
104
105 // tools::histo::h1d -> h1 etc.
106 return hnTypeLong[14] == 'p';
107}
108
109// String conversion
110template <typename T>
111inline
112std::string ToString(const T& value)
113{ return std::to_string(value); }
114
115template <>
116inline
117std::string ToString<std::string>(const std::string& value)
118{ return value; }
119
120// File names utilities
121
122// Get file base name (without dot)
123G4String GetBaseName(const G4String& fileName);
124
125// Get file base extension (without dot)
126G4String GetExtension(const G4String& fileName,
127 const G4String& defaultExtension = "");
128
129// Compose and return the histogram or profile specific file name:
130// - add _hn_hnName suffix to the file base name
131// - add file extension if not present
133 const G4String& fileName,
134 const G4String& fileType,
135 const G4String& hnType,
136 const G4String& hnName);
137
138// Update Hn file name:
139// - add _vN suffix to the base namer if cycle > 0
141 const G4String& fileName,
142 const G4String& fileType,
143 G4int cycle = 0);
144
145// Compose and return the ntuple specific file name:
146// - add _nt_ntupleName suffix to the file base name
147// - add _vN suffix if cycle > 0
148// - add _tN suffix if called on thread worker
149// - add file extension if not present
151 const G4String& fileName,
152 const G4String& fileType,
153 const G4String& ntupleName,
154 G4int cycle = 0);
155
156// Compose and return the ntuple specific file name:
157// - add _mFN suffix to the file base name where FN = ntupleFileNumber
158// - add _vN suffix if cycle > 0
159// - add file extension if not present
161 const G4String& fileName,
162 const G4String& fileType,
163 G4int ntupleFileNumber,
164 G4int cycle = 0);
165
166// Update file base name with the thread suffix:
167// - add _vN suffix if cycle > 0
168// - add _tN suffix if called on thread worker
169// - add file extension if not present
171 const G4String& fileName,
172 const G4String& fileType,
173 G4int cycle = 0);
174
175// Generate plot file name for an output file name
176G4String GetPlotFileName(const G4String& fileName);
177
178}
179
180/*
181// make possible to print enumerators in class enum as integer
182template <typename Enumeration>
183auto as_integer(Enumeration const value)
184 -> typename std::underlying_type<Enumeration>::type
185{
186 return static_cast<typename std::underlying_type<Enumeration>::type>(value);
187}
188*/
189
190#endif
191
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
constexpr unsigned int kDefaultBasketSize
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
size_t GetOutputId(const G4String &outputName, G4bool warn=true)
constexpr G4int kVL1
std::string ToString(const T &value)
constexpr G4int kVL2
std::string ToString< std::string >(const std::string &value)
G4String GetTnFileName(const G4String &fileName, const G4String &fileType, G4int cycle=0)
G4String GetPlotFileName(const G4String &fileName)
constexpr std::string_view kNamespaceName
G4double GetUnitValue(const G4String &unit)
G4String GetOutputName(G4AnalysisOutput outputType)
constexpr unsigned int kMaxDim
constexpr G4int kVL3
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName, G4int cycle=0)
constexpr G4int kVL4
constexpr G4int kVL0
constexpr G4int kInvalidId
constexpr unsigned int kDefaultBasketEntries
constexpr G4int kX
G4String GetHnType()
G4String GetHnFileName(const G4String &fileName, const G4String &fileType, const G4String &hnType, const G4String &hnName)
G4String GetBaseName(const G4String &fileName)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
constexpr G4int kZ
constexpr G4int kY