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
+85 -118
View File
@@ -34,6 +34,9 @@
#include "tools/wroot/file"
#include "tools/wroot/ntuple"
using namespace G4Analysis;
using std::to_string;
// mutex in a file scope
namespace {
@@ -41,13 +44,13 @@ namespace {
G4Mutex pntupleMutex = G4MUTEX_INITIALIZER;
//_____________________________________________________________________________
void NotExistException(const G4String& what, G4int id, const G4String& functionName)
void NotExistWarning(const G4String& what, G4int id,
std::string_view className,
std::string_view functionName)
{
G4String inFunction = "G4RootPNtupleManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << what << " id= " << id << " does not exist.";
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
Warn(what + " id= " + to_string(id) + " does not exist.",
className, functionName);
}
}
@@ -58,13 +61,10 @@ G4RootPNtupleManager::G4RootPNtupleManager(const G4AnalysisManagerState& state,
std::shared_ptr<G4RootMainNtupleManager> main,
G4bool rowWise, G4bool rowMode)
: G4BaseNtupleManager(state),
fBookingManager(bookingManger),
fMainNtupleManager(main),
fNtupleDescriptionVector(),
fNtupleVector(),
fBookingManager(std::move(bookingManger)),
fMainNtupleManager(std::move(main)),
fRowWise(rowWise),
fRowMode(rowMode),
fCreateNtuples(true)
fRowMode(rowMode)
{}
//_____________________________________________________________________________
@@ -72,7 +72,7 @@ G4RootPNtupleManager::~G4RootPNtupleManager()
{
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
delete ntupleDescription;
}
}
}
//
@@ -80,53 +80,53 @@ G4RootPNtupleManager::~G4RootPNtupleManager()
//
//_____________________________________________________________________________
G4RootPNtupleDescription*
G4RootPNtupleDescription*
G4RootPNtupleManager::GetNtupleDescriptionInFunction(
G4int id, G4String functionName, G4bool warn) const
{
G4int id, std::string_view functionName, G4bool warn) const
{
auto index = id - fFirstId;
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
if ( warn) {
NotExistException("ntuple description", id, functionName);
NotExistWarning("ntuple description", id, fkClass, functionName);
}
return nullptr;
return nullptr;
}
return fNtupleDescriptionVector[index];
}
//_____________________________________________________________________________
tools::wroot::base_pntuple*
tools::wroot::base_pntuple*
G4RootPNtupleManager::GetNtupleInFunction(
G4int id, G4String functionName, G4bool warn) const
{
G4int id, std::string_view functionName, G4bool warn) const
{
auto ntupleDescription = GetNtupleDescriptionInFunction(id, functionName);
if ( ! ntupleDescription ) return nullptr;
if ( ! ntupleDescription->fBasePNtuple ) {
if ( warn ) {
NotExistException("ntuple", id, functionName);
NotExistWarning("ntuple", id, fkClass, functionName);
}
return nullptr;
}
}
return ntupleDescription->fBasePNtuple;
}
//_____________________________________________________________________________
tools::wroot::ntuple*
G4RootPNtupleManager::GetMainNtupleInFunction(
G4int id, G4String functionName, G4bool warn) const
{
G4int id, std::string_view functionName, G4bool warn) const
{
auto& mainNtupleVector = fMainNtupleManager->GetNtupleVector();
auto index = id - fFirstId;
if ( index < 0 || index >= G4int(mainNtupleVector.size()) ) {
if ( warn) {
NotExistException("main ntuple", id, functionName);
NotExistWarning("main ntuple", id, fkClass, functionName);
}
return nullptr;
return nullptr;
}
return mainNtupleVector[index];
}
@@ -139,20 +139,12 @@ void G4RootPNtupleManager::CreateNtupleFromMain(
G4RootPNtupleDescription* ntupleDescription,
tools::wroot::ntuple* mainNtuple)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
fState.GetVerboseL4()
->Message("create from main", "pntuple", mainNtuple->name());
}
#endif
Message(kVL4, "create from main", "pntuple", mainNtuple->name());
auto file = fMainNtupleManager->GetNtupleFile(&ntupleDescription->fDescription);
if ( ! file ) {
G4String inFunction = "G4RootPNtupleManager::::CreateNtupleFromMain";
G4ExceptionDescription description;
description
<< "Cannot create pntuple. Main ntuple file does not exist." << G4endl;
G4Exception(inFunction, "Analysis_W002", JustWarning, description);
Warn("Cannot create pntuple. Main ntuple file does not exist.",
fkClass, "CreateNtupleFromMain");
return;
}
@@ -165,55 +157,50 @@ void G4RootPNtupleManager::CreateNtupleFromMain(
G4bool verbose = true;
if ( fRowWise ) {
auto mainBranch = mainNtuple->get_row_wise_branch();
tools::wroot::mt_ntuple_row_wise* mtNtuple
auto mtNtuple
= new tools::wroot::mt_ntuple_row_wise(
G4cout, rfile->byte_swap(), rfile->compression(),
mainNtuple->dir().seek_directory(),
*mainBranch, mainBranch->basket_size(),
*mainBranch, mainBranch->basket_size(),
ntupleDescription->fDescription.fNtupleBooking, verbose);
ntupleDescription->fNtuple
= static_cast<tools::wroot::imt_ntuple*>(mtNtuple);
ntupleDescription->fBasePNtuple
= static_cast<tools::wroot::base_pntuple*>(mtNtuple);
}
}
else {
std::vector<tools::uint32> basketSizes;
tools_vforcit(tools::wroot::branch*, ntupleDescription->fMainBranches, it) {
basketSizes.push_back((*it)->basket_size());
}
auto basketEntries = fMainNtupleManager->GetBasketEntries();
tools::wroot::mt_ntuple_column_wise* mtNtuple =
auto mtNtuple =
new tools::wroot::mt_ntuple_column_wise(
G4cout, rfile->byte_swap(), rfile->compression(),
mainNtuple->dir().seek_directory(),
ntupleDescription->fMainBranches, basketSizes,
ntupleDescription->fDescription.fNtupleBooking,
ntupleDescription->fDescription.fNtupleBooking,
fRowMode, basketEntries, verbose);
ntupleDescription->fNtuple
= static_cast<tools::wroot::imt_ntuple*>(mtNtuple);
ntupleDescription->fBasePNtuple
= static_cast<tools::wroot::base_pntuple*>(mtNtuple);
}
ntupleDescription->fDescription.fIsNtupleOwner = true;
ntupleDescription->fDescription.fIsNtupleOwner = true;
// // pntuple object is not deleted automatically
fNtupleVector.push_back(ntupleDescription->fNtuple);
fNtupleVector.push_back(ntupleDescription->fNtuple);
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() ) {
fState.GetVerboseL3()
->Message("create from main", "pntuple", mainNtuple->name());
}
#endif
Message(kVL3, "create from main", "pntuple", mainNtuple->name());
}
//_____________________________________________________________________________
void G4RootPNtupleManager::CreateNtuplesFromMain()
{
// Create ntuple from booking (if not yet done) and main ntuple
// Create ntuple from booking (if not yet done) and main ntuple
// This function is called from the first Fill call.
// Create pntuple descriptions from ntuple booking.
@@ -221,13 +208,13 @@ void G4RootPNtupleManager::CreateNtuplesFromMain()
for ( auto g4NtupleBooking : g4NtupleBookings ) {
auto ntupleDescription = new G4RootPNtupleDescription(g4NtupleBooking);
// Save g4booking, activation in pntuple booking
fNtupleDescriptionVector.push_back(ntupleDescription);
fNtupleDescriptionVector.push_back(ntupleDescription);
}
auto& mainNtupleVector = fMainNtupleManager->GetNtupleVector();
G4int lcounter = 0;
for ( auto mainNtuple : mainNtupleVector ) {
for ( auto mainNtuple : mainNtupleVector ) {
auto& ntupleDescription = fNtupleDescriptionVector[lcounter++];
CreateNtupleFromMain(ntupleDescription, mainNtuple);
}
@@ -242,55 +229,51 @@ G4int G4RootPNtupleManager::CreateNtuple(G4NtupleBooking* /*booking*/)
// Nothing to be done here.
return G4Analysis::kInvalidId;
}
}
//_____________________________________________________________________________
G4bool G4RootPNtupleManager::FillNtupleIColumn(
G4int ntupleId, G4int columnId, G4int value)
{
return FillNtupleTColumn<int>(ntupleId, columnId, value);
}
}
//_____________________________________________________________________________
G4bool G4RootPNtupleManager::FillNtupleFColumn(
G4int ntupleId, G4int columnId, G4float value)
{
return FillNtupleTColumn<float>(ntupleId, columnId, value);
}
}
//_____________________________________________________________________________
G4bool G4RootPNtupleManager::FillNtupleDColumn(
G4int ntupleId, G4int columnId, G4double value)
{
return FillNtupleTColumn<double>(ntupleId, columnId, value);
}
}
//_____________________________________________________________________________
G4bool G4RootPNtupleManager::FillNtupleSColumn(
G4int ntupleId, G4int columnId, const G4String& value)
{
return FillNtupleTColumn<std::string>(ntupleId, columnId, value);
}
}
//_____________________________________________________________________________
G4bool G4RootPNtupleManager::AddNtupleRow(G4int ntupleId)
{
{
if (fCreateNtuples) {
CreateNtuplesFromMain();
}
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
//G4cout << "Skipping AddNtupleRow for " << ntupleId << G4endl;
return false;
}
//G4cout << "Skipping AddNtupleRow for " << ntupleId << G4endl;
return false;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("add", "pntuple row", description);
}
#endif
if ( IsVerbose(kVL4) ) {
Message(kVL4, "add", "pntuple row", " ntupleId " + to_string(ntupleId));
}
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "AddNtupleRow");
if ( ! ntupleDescription ) return false;
@@ -300,26 +283,20 @@ G4bool G4RootPNtupleManager::AddNtupleRow(G4int ntupleId)
G4AutoLock lock(&pntupleMutex);
lock.unlock();
mutex toolsLock(lock);
auto result
auto result
= ntupleDescription->fNtuple->add_row(toolsLock, *rfile);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << " ntupleId " << ntupleId
<< "adding row has failed.";
G4Exception("G4RootPNtupleManager::AddNtupleRow()",
"Analysis_W022", JustWarning, description);
Warn("NtupleId " + to_string(ntupleId) + "adding row failed.",
fkClass, "AddNtupleRow");
}
ntupleDescription->fDescription.fHasFill = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL3()->Message("add", "pntuple row", description);
}
#endif
if ( IsVerbose(kVL3) ) {
Message(kVL3, "add", "pntuple row", " ntupleId " + to_string(ntupleId));
}
return true;
}
@@ -335,57 +312,47 @@ G4bool G4RootPNtupleManager::Merge()
continue;
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
fState.GetVerboseL4()
->Message("merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
}
#endif
if ( IsVerbose(kVL4) ) {
Message(kVL4, "merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
}
auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
G4AutoLock lock(&pntupleMutex);
lock.unlock();
mutex toolsLock(lock);
auto result
auto result
= ntupleDescription->fNtuple->end_fill(toolsLock, *rfile);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << " ntuple " << ntupleDescription->fDescription.fNtupleBooking.name()
<< "end fill has failed.";
G4Exception("G4RootPNtupleManager::Merge()",
"Analysis_W031", JustWarning, description);
Warn("Ntuple " + ntupleDescription->fDescription.fNtupleBooking.name() +
"end fill has failed.", fkClass, "Merge");
}
delete ntupleDescription->fNtuple;
ntupleDescription->fNtuple = nullptr;
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() ) {
fState.GetVerboseL3()
->Message("merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
}
#endif
if ( IsVerbose(kVL3) ) {
Message(kVL3, "merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
}
}
return true;
}
//_____________________________________________________________________________
G4bool G4RootPNtupleManager::Reset(G4bool deleteNtuple)
void G4RootPNtupleManager::Clear()
{
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
if ( deleteNtuple ) {
delete ntupleDescription->fNtuple;
}
ntupleDescription->fNtuple = nullptr;
delete ntupleDescription->fNtuple;
}
fNtupleVector.clear();
return true;
}
fNtupleDescriptionVector.clear();
fNtupleVector.clear();
Message(kVL2, "clear", "pntuples");
}
//_____________________________________________________________________________
@@ -394,7 +361,7 @@ void G4RootPNtupleManager::SetActivation(
{
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
ntupleDescription->fDescription.fActivation = activation;
}
}
}
//_____________________________________________________________________________
@@ -426,7 +393,7 @@ G4int G4RootPNtupleManager::GetNofNtuples() const
//_____________________________________________________________________________
void G4RootPNtupleManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
{
{
fRowWise = rowWise;
fRowMode = rowMode;
}