Import Geant4 11.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2021-12-10 14:46:44 +01:00
committed by Ben Morgan
parent 6399a014b6
commit 80e2389dd8
3932 changed files with 202519 additions and 246221 deletions
@@ -28,14 +28,18 @@
#include "G4AnalysisUtilities.hh"
#include "G4BinScheme.hh"
#include "G4Exception.hh"
#include "G4UnitsTable.hh"
#include "G4String.hh"
#include "G4Threading.hh"
#include "G4Filesystem.hh"
using std::to_string;
namespace {
//_____________________________________________________________________________
G4bool GetToken(const G4String& line, G4String& token,
G4bool GetToken(const G4String& line, G4String& token,
std::string::size_type begIdx, std::string::size_type& endIdx)
{
while ( line[begIdx] == ' ') ++begIdx; // Loop checking, 23.06.2015, I. Hrivnacova
@@ -51,84 +55,73 @@ G4bool GetToken(const G4String& line, G4String& token,
token = line.substr(begIdx, endIdx-begIdx);
}
return ( token.length() > 0 );
}
}
}
namespace G4Analysis
{
//_____________________________________________________________________________
void Warn(const G4String& message,
const std::string_view inClass,
const std::string_view inFunction)
{
auto source = std::string(inClass) + "::" + std::string(inFunction);
G4Exception(source.data(), "Analysis_W001", JustWarning, message);
}
//_____________________________________________________________________________
G4bool CheckNbins(G4int nbins)
{
if ( nbins <= 0 ) {
G4ExceptionDescription description;
description
<< " Illegal value of number of bins: nbins <= 0" << G4endl;
G4Exception("G4VAnalysisManager::CheckNbins",
"Analysis_W013", JustWarning, description);
Warn("Illegal value of number of bins: nbins <= 0",
kNamespaceName, "CheckNbins");
return false;
}
else
return true;
}
return true;
}
//_____________________________________________________________________________
G4bool CheckMinMax(G4double xmin, G4double xmax,
G4bool CheckMinMax(G4double xmin, G4double xmax,
const G4String& fcnName, const G4String& binSchemeName)
{
auto result = true;
if ( xmax <= xmin ) {
G4ExceptionDescription description;
description
<< " Illegal values of (xmin >= xmax)" << G4endl;
G4Exception("G4VAnalysisManager::CheckMinMax",
"Analysis_W013", JustWarning, description);
Warn("Illegal value of number of (xmin >= xmax)",
kNamespaceName, "CheckMinMax");
result = false;
}
if ( ( fcnName != "none" ) && ( binSchemeName != "linear" ) ) {
G4ExceptionDescription description;
description
<< " Combining Function and Binning scheme is not supported."
<< G4endl;
G4Exception("G4VAnalysisManager::CheckMinMax",
"Analysis_W013", JustWarning, description);
Warn("Combining Function and Binning scheme is not supported.",
kNamespaceName, "CheckMinMax");
result = false;
}
if ( ( GetBinScheme(binSchemeName) == G4BinScheme::kLog ||
fcnName == "log" || fcnName == "log10" ) && ( xmin == 0 ) ) {
G4ExceptionDescription description;
description
<< " Illegal value of (xmin = 0) with logarithmic function or binning"
<< G4endl;
G4Exception("G4VAnalysisManager::CheckMinMax",
"Analysis_W013", JustWarning, description);
Warn("Illegal value of (xmin = 0) with logarithmic function or binning",
kNamespaceName, "CheckMinMax");
result = false;
}
return result;
}
}
//_____________________________________________________________________________
G4bool CheckEdges(const std::vector<G4double>& edges)
{
if ( edges.size() <= 1 ) {
G4ExceptionDescription description;
description
<< " Illegal edges vector (size <= 1)" << G4endl;
G4Exception("G4VAnalysisManager::CheckEdges",
"Analysis_W013", JustWarning, description);
Warn("Illegal edges vector (size <= 1)",
kNamespaceName, "CheckEdges");
return false;
}
else
return true;
return true;
}
@@ -136,16 +129,12 @@ G4bool CheckEdges(const std::vector<G4double>& edges)
G4bool CheckName(const G4String& name, const G4String& objectType)
{
if ( ! name.size() ) {
G4ExceptionDescription description;
description
<< " Empty " << objectType << " name is not allowed." << G4endl
<< " " << objectType << " was not created." << G4endl;
G4Exception("G4VAnalysisManager::CheckName",
"Analysis_W013", JustWarning, description);
Warn("Empty " + objectType + " name is not allowed.\n" +
objectType + " was not created.", kNamespaceName, "CheckEdges");
return false;
}
else
return true;
return true;
}
//_____________________________________________________________________________
@@ -154,35 +143,35 @@ G4double GetUnitValue(const G4String& unit)
G4double value = 1.;
if ( unit != "none" ) {
value = G4UnitDefinition::GetValueOf(unit);
if ( value == 0. ) value = 1.;
}
if ( value == 0. ) value = 1.;
}
return value;
}
}
//_____________________________________________________________________________
void UpdateTitle(G4String& title,
const G4String& unitName,
void UpdateTitle(G4String& title,
const G4String& unitName,
const G4String& fcnName)
{
if ( fcnName != "none" ) { title += " "; title += fcnName; title += "("; }
if ( unitName != "none" ) { title += " ["; title += unitName; title += "]";}
if ( fcnName != "none" ) { title += ")"; }
}
}
//_____________________________________________________________________________
void Tokenize(const G4String& line, std::vector<G4String>& tokens)
{
// Define start values
std::string::size_type begIdx = 0;
std::string::size_type endIdx = 0;
std::string::size_type endIdx = 0;
G4String token;
do {
if ( GetToken(line, token, begIdx, endIdx) ) {
//G4cout << "got token: '" << token << "'" << G4endl;
//G4cout << "beg, end: " << begIdx << ", " << endIdx << G4endl;
tokens.push_back(token);
}
}
begIdx = endIdx + 1;
}
while ( endIdx < line.length() ); // Loop checking, 23.06.2015, I. Hrivnacova
@@ -197,13 +186,10 @@ G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn) {
else if ( outputName == "none" ) { return G4AnalysisOutput::kNone; }
else {
if (warn) {
G4ExceptionDescription description;
description
<< " \"" << outputName << "\" output type is not supported." << G4endl;
G4Exception("G4Analysis::GetOutputType",
"Analysis_W051", JustWarning, description);
Warn("\"" + outputName + "\" output type is not supported.",
kNamespaceName, "GetOutput");
}
return G4AnalysisOutput::kNone;
return G4AnalysisOutput::kNone;
}
}
@@ -213,10 +199,10 @@ G4String GetOutputName(G4AnalysisOutput output) {
case G4AnalysisOutput::kCsv:
return "csv";
break;
case G4AnalysisOutput::kHdf5:
case G4AnalysisOutput::kHdf5:
return "hdf5";
break;
case G4AnalysisOutput::kRoot:
case G4AnalysisOutput::kRoot:
return "root";
break;
case G4AnalysisOutput::kXml:
@@ -227,12 +213,9 @@ G4String GetOutputName(G4AnalysisOutput output) {
break;
}
// should never reach this line
G4ExceptionDescription description;
description
<< " \"" << static_cast<int>(output) << "\" is not handled." << G4endl
<< " " << "none type will be used.";
G4Exception("G4Analysis::GetOutputName",
"Analysis_W051", JustWarning, description);
Warn("\"" + to_string(static_cast<int>(output)) +
"\" output type is not supported.",
kNamespaceName, "CheckOutputName");
return "none";
}
@@ -241,12 +224,13 @@ G4String GetBaseName(const G4String& fileName)
{
// Get file base name (without dot)
G4String name = fileName;
if ( name.rfind(".") != std::string::npos ) {
name = name.substr(0, name.rfind("."));
G4fs::path filePath(fileName.data());
if ( filePath.has_parent_path()) {
return filePath.parent_path().string() + "/" + filePath.stem().string();
}
return name;
}
return filePath.stem().string();
}
//_____________________________________________________________________________
G4String GetExtension(const G4String& fileName,
@@ -255,21 +239,21 @@ G4String GetExtension(const G4String& fileName,
// Get file base extension (without dot)
// If fileName is provided without extension, return defaultExtension
G4String extension;
if ( fileName.rfind(".") != std::string::npos ) {
extension = fileName.substr(fileName.rfind(".") + 1);
G4fs::path filePath(fileName.data());
if ( filePath.has_extension() ) {
auto extension = filePath.extension().string();
// remove "."
return extension.substr(1, extension.length());
}
if ( ! extension.size() ) {
extension = defaultExtension;
}
return extension;
return defaultExtension;
}
//_____________________________________________________________________________
G4String GetHnFileName(
const G4String& fileName,
const G4String& fileType,
const G4String& hnType,
const G4String& fileType,
const G4String& hnType,
const G4String& hnName)
{
// Compose and return the histogram or profile specific file name:
@@ -277,7 +261,7 @@ G4String GetHnFileName(
// - add file extension if not present
auto name = GetBaseName(fileName);
// Add _hnType_hnName
name.append("_");
name.append(hnType);
@@ -297,7 +281,7 @@ G4String GetHnFileName(
//_____________________________________________________________________________
G4String GetNtupleFileName(
const G4String& fileName,
const G4String& fileType,
const G4String& fileType,
const G4String& ntupleName)
{
// Compose and return the ntuple specific file name:
@@ -306,7 +290,7 @@ G4String GetNtupleFileName(
// - add file extension if not present
auto name = GetBaseName(fileName);
// Add ntupleName
name.append("_nt_");
name.append(ntupleName);
@@ -317,7 +301,7 @@ G4String GetNtupleFileName(
os << G4Threading::G4GetThreadId();
name.append("_t");
name.append(os.str());
}
}
// Add file extension
auto extension = GetExtension(fileName, fileType);
@@ -325,14 +309,14 @@ G4String GetNtupleFileName(
name.append(".");
name.append(extension);
}
return name;
}
//_____________________________________________________________________________
G4String GetNtupleFileName(
const G4String& fileName,
const G4String& fileType,
const G4String& fileType,
G4int ntupleFileNumber)
{
// Compose and return the ntuple specific file name:
@@ -340,7 +324,7 @@ G4String GetNtupleFileName(
// - add file extension if not present
auto name = GetBaseName(fileName);
// Add _M followed by ntupleFileNumber
std::ostringstream os;
os << ntupleFileNumber;
@@ -353,7 +337,7 @@ G4String GetNtupleFileName(
name.append(".");
name.append(extension);
}
return name;
}