Geant4-11
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// Utility functions for checking input parameters
74//
77 const G4String& fcnName = "none",
78 const G4String& binSchemeName = "linear");
79G4bool CheckEdges(const std::vector<G4double>& edges);
80G4bool CheckName(const G4String& name, const G4String& objectType);
81
82// Get unit value with added handling of "none"
83G4double GetUnitValue(const G4String& unit);
84
85// Add unit & fcn to the title
86void UpdateTitle(G4String& title,
87 const G4String& unitName, const G4String& fcnName);
88
89// Tokenizer with taking into account composed strings within ""
90void Tokenize(const G4String& line, std::vector<G4String>& tokens);
91
92// Get output type from name
93G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn = true);
94size_t GetOutputId(const G4String& outputName, G4bool warn = true);
96
97// Get short hnType from the tools object
98template <typename HT>
100{
101 // tools::histo::h1d etc.
102 G4String hnTypeLong = HT::s_class();
103
104 // tools::histo::h1d -> h1 etc.
105 return hnTypeLong.substr(14, 2);
106}
107
108// template <typename HT>
109// G4bool IsProfile()
110// {
111// // tools::histo::h1d etc.
112// G4String hnTypeLong = HT::s_class();
113
114// // tools::histo::h1d -> h1 etc.
115// return (hnTypeLong.substr(14, 1) == "p");
116// }
117
118// String conversion
119template <typename T>
120inline
121std::string ToString(const T& value)
122{ return std::to_string(value); }
123
124template <>
125inline
126std::string ToString<std::string>(const std::string& value)
127{ return value; }
128
129// File names utilities
130
131// Get file base name (without dot)
132G4String GetBaseName(const G4String& fileName);
133
134// Get file base extension (without dot)
135G4String GetExtension(const G4String& fileName,
136 const G4String& defaultExtension = "");
137
138// Compose and return the histogram or profile specific file name:
139// - add _hn_hnName suffix to the file base name
140// - add file extension if not present
142 const G4String& fileName,
143 const G4String& fileType,
144 const G4String& hnType,
145 const G4String& hnName);
146
147// Compose and return the ntuple specific file name:
148// - add _nt_ntupleName suffix to the file base name
149// - add _tN suffix if called on thread worker
150// - add file extension if not present
152 const G4String& fileName,
153 const G4String& fileType,
154 const G4String& ntupleName);
155
156// Compose and return the ntuple specific file name:
157// - add _nt_ntupleName suffix to the file base name
158// - add _tN suffix if called on thread worker
159// - add file extension if not present
161 const G4String& fileName,
162 const G4String& fileType,
163 G4int ntupleFileNumber);
164
165// Update file base name with the thread suffix:
166// - add _tN suffix if called on thread worker
167// - add file extension if not present
169 const G4String& fileName,
170 const G4String& fileType);
171
172// Generate plot file name for an output file name
173G4String GetPlotFileName(const G4String& fileName);
174
175}
176
177/*
178// make possible to print enumerators in class enum as integer
179template <typename Enumeration>
180auto as_integer(Enumeration const value)
181 -> typename std::underlying_type<Enumeration>::type
182{
183 return static_cast<typename std::underlying_type<Enumeration>::type>(value);
184}
185*/
186
187#endif
188
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="")
G4bool CheckMinMax(G4double xmin, G4double xmax, const G4String &fcnName="none", const G4String &binSchemeName="linear")
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
G4String GetTnFileName(const G4String &fileName, const G4String &fileType)
G4bool CheckNbins(G4int nbins)
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)
constexpr G4int kVL4
constexpr G4int kVL0
constexpr G4int kInvalidId
constexpr unsigned int kDefaultBasketEntries
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
constexpr G4int kX
G4bool CheckEdges(const std::vector< G4double > &edges)
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)
G4bool CheckName(const G4String &name, const G4String &objectType)
constexpr G4int kZ
constexpr G4int kY
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName)
const char * name(G4int ptype)