Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 (ivana@ipno.in2p3.fr)
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 kDefaultBasketSize = 32000;
64constexpr unsigned int kDefaultBasketEntries = 4000;
65constexpr std::string_view kNamespaceName { "G4Analysis" };
66
67// Warning
68//
69void Warn(const G4String& message,
70 const std::string_view inClass,
71 const std::string_view inFunction);
72
73// Get unit value with added handling of "none"
74G4double GetUnitValue(const G4String& unit);
75
76// Tokenizer with taking into account composed strings within ""
77void Tokenize(const G4String& line, std::vector<G4String>& tokens);
78
79// Get output type from name
80G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn = true);
81size_t GetOutputId(const G4String& outputName, G4bool warn = true);
83
84// Get short hnType from the tools object
85template <typename HT>
87{
88 // tools::histo::h1d etc.
89 G4String hnTypeLong = HT::s_class();
90
91 // tools::histo::h1d -> h1 etc.
92 return hnTypeLong.substr(14, 2);
93}
94
95template <typename HT>
97{
98 // tools::histo::h1d etc.
99 G4String hnTypeLong = HT::s_class();
100
101 // tools::histo::h1d -> h1 etc.
102 return hnTypeLong[14] == 'p';
103}
104
105// String conversion
106template <typename T>
107inline
108std::string ToString(const T& value)
109{ return std::to_string(value); }
110
111template <>
112inline
113std::string ToString<std::string>(const std::string& value)
114{ return value; }
115
116// File names utilities
117
118// Get file base name (without dot)
119G4String GetBaseName(const G4String& fileName);
120
121// Get file base extension (without dot)
122G4String GetExtension(const G4String& fileName,
123 const G4String& defaultExtension = "");
124
125// Compose and return the histogram or profile specific file name:
126// - add _hn_hnName suffix to the file base name
127// - add file extension if not present
129 const G4String& fileName,
130 const G4String& fileType,
131 const G4String& hnType,
132 const G4String& hnName);
133
134// Update Hn file name:
135// - add _vN suffix to the base namer if cycle > 0
137 const G4String& fileName,
138 const G4String& fileType,
139 G4int cycle = 0);
140
141// Compose and return the ntuple specific file name:
142// - add _nt_ntupleName suffix to the file base name
143// - add _vN suffix if cycle > 0
144// - add _tN suffix if called on thread worker
145// - add file extension if not present
147 const G4String& fileName,
148 const G4String& fileType,
149 const G4String& ntupleName,
150 G4int cycle = 0);
151
152// Compose and return the ntuple specific file name:
153// - add _mFN suffix to the file base name where FN = ntupleFileNumber
154// - add _vN suffix if cycle > 0
155// - add file extension if not present
157 const G4String& fileName,
158 const G4String& fileType,
159 G4int ntupleFileNumber,
160 G4int cycle = 0);
161
162// Update file base name with the thread suffix:
163// - add _vN suffix if cycle > 0
164// - add _tN suffix if called on thread worker
165// - add file extension if not present
167 const G4String& fileName,
168 const G4String& fileType,
169 G4int cycle = 0);
170
171// Generate plot file name for an output file name
172G4String GetPlotFileName(const G4String& fileName);
173
174}
175
176/*
177// make possible to print enumerators in class enum as integer
178template <typename Enumeration>
179auto as_integer(Enumeration const value)
180 -> typename std::underlying_type<Enumeration>::type
181{
182 return static_cast<typename std::underlying_type<Enumeration>::type>(value);
183}
184*/
185
186#endif
187
G4AnalysisOutput
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 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