Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -27,81 +27,75 @@
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
using std::to_string;
|
||||
|
||||
//
|
||||
// private template functions
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4TNtupleManager<TN, TF>::G4TNtupleManager(
|
||||
template <typename NT, typename FT>
|
||||
G4TNtupleManager<NT, FT>::G4TNtupleManager(
|
||||
const G4AnalysisManagerState& state)
|
||||
: G4BaseNtupleManager(state),
|
||||
fNtupleDescriptionVector(),
|
||||
fNtupleVector()
|
||||
: G4BaseNtupleManager(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4TNtupleManager<TN, TF>::~G4TNtupleManager()
|
||||
{
|
||||
template <typename NT, typename FT>
|
||||
G4TNtupleManager<NT, FT>::~G4TNtupleManager()
|
||||
{
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
delete ntupleDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4TNtupleDescription<TN, TF>*
|
||||
G4TNtupleManager<TN, TF>::GetNtupleDescriptionInFunction(
|
||||
G4int id, G4String functionName, G4bool warn) const
|
||||
template <typename NT, typename FT>
|
||||
G4TNtupleDescription<NT, FT>*
|
||||
G4TNtupleManager<NT, FT>::GetNtupleDescriptionInFunction(
|
||||
G4int id, std::string_view functionName, G4bool warn) const
|
||||
{
|
||||
auto index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4String inFunction = "G4TNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntuple " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn("Ntuple " + to_string(id) + " does not exist.",
|
||||
fkClass, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fNtupleDescriptionVector[index];
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
TN* G4TNtupleManager<TN, TF>::GetNtupleInFunction(
|
||||
G4int id, G4String functionName, G4bool warn) const
|
||||
template <typename NT, typename FT>
|
||||
NT* G4TNtupleManager<NT, FT>::GetNtupleInFunction(
|
||||
G4int id, std::string_view functionName, G4bool warn) const
|
||||
{
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(id, functionName);
|
||||
if ( ! ntupleDescription ) return nullptr;
|
||||
|
||||
if ( ! ntupleDescription->fNtuple ) {
|
||||
if ( warn ) {
|
||||
G4String inFunction = "G4TNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn("Ntuple " + to_string(id) + " does not exist.",
|
||||
fkClass, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return ntupleDescription->fNtuple;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
template <typename NT, typename FT>
|
||||
template <typename T>
|
||||
G4bool G4TNtupleManager<TN, TF>::FillNtupleTColumn(
|
||||
G4bool G4TNtupleManager<NT, FT>::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const T& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
//G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
//G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// get ntuple
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
@@ -110,38 +104,35 @@ G4bool G4TNtupleManager<TN, TF>::FillNtupleTColumn(
|
||||
// get generic column
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4TNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Ntuple " + to_string(ntupleId) + " column " + to_string(columnId) +
|
||||
" does not exist.",
|
||||
fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
|
||||
// get column and check its type
|
||||
auto column = dynamic_cast<typename TN::template column<T>* >(icolumn);
|
||||
auto column = dynamic_cast<typename NT::template column<T>* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4TNtupleManager:FillNtupleTColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Column type does not match: "
|
||||
" ntuple " + to_string(ntupleId) + " column " + to_string(columnId) +
|
||||
" value " + G4Analysis::ToString(value),
|
||||
fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "ntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "fill", "ntuple T column",
|
||||
" ntupleId " + to_string(ntupleId) +
|
||||
" column " + to_string(columnId) +
|
||||
" value " + G4Analysis::ToString<T>(value));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -149,17 +140,11 @@ G4bool G4TNtupleManager<TN, TF>::FillNtupleTColumn(
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4int G4TNtupleManager<TN, TF>::CreateNtuple(G4NtupleBooking* ntupleBooking)
|
||||
template <typename NT, typename FT>
|
||||
G4int G4TNtupleManager<NT, FT>::CreateNtuple(G4NtupleBooking* ntupleBooking)
|
||||
{
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()
|
||||
->Message("create from booking", "ntuple",
|
||||
ntupleBooking->fNtupleBooking.name());
|
||||
}
|
||||
#endif
|
||||
Message(G4Analysis::kVL4, "create from booking", "ntuple",
|
||||
ntupleBooking->fNtupleBooking.name());
|
||||
|
||||
// The ntuple index
|
||||
auto index = ntupleBooking->fNtupleId - fFirstId;
|
||||
@@ -170,11 +155,9 @@ G4int G4TNtupleManager<TN, TF>::CreateNtuple(G4NtupleBooking* ntupleBooking)
|
||||
if ( index < G4int(fNtupleDescriptionVector.size()) &&
|
||||
fNtupleDescriptionVector[index] ) {
|
||||
delete fNtupleDescriptionVector[index];
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Ntuple description " << ntupleBooking->fNtupleId << " already exists.";
|
||||
G4Exception("G4TNtupleManager::CreateNtuple",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Ntuple description " + to_string(ntupleBooking->fNtupleId) +
|
||||
" already exists.", fkClass, "CreateNtuple");
|
||||
}
|
||||
|
||||
// Allocate the vector element(s)
|
||||
@@ -183,20 +166,18 @@ G4int G4TNtupleManager<TN, TF>::CreateNtuple(G4NtupleBooking* ntupleBooking)
|
||||
}
|
||||
|
||||
// Create ntuple description from ntuple booking.
|
||||
auto ntupleDescription = new G4TNtupleDescription<TN, TF>(ntupleBooking);
|
||||
auto ntupleDescription = new G4TNtupleDescription<NT, FT>(ntupleBooking);
|
||||
fNtupleDescriptionVector[index] = ntupleDescription;
|
||||
|
||||
// Do not create ntuple if it is inactivated
|
||||
if ( fState.GetIsActivation() &&
|
||||
// Do not create ntuple if it is inactivated
|
||||
if ( fState.GetIsActivation() &&
|
||||
( ! ntupleDescription->fActivation ) ) return G4Analysis::kInvalidId;
|
||||
|
||||
|
||||
// Do not create ntuple if it already exists
|
||||
if ( ntupleDescription->fNtuple ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Ntuple " << ntupleBooking->fNtupleId << " already exists.";
|
||||
G4Exception("G4TNtupleManager::CreateNtuple",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Ntuple " + to_string(ntupleBooking->fNtupleId) +
|
||||
" already exists.", fkClass, "CreateNtuple");
|
||||
return ntupleBooking->fNtupleId;
|
||||
}
|
||||
|
||||
@@ -207,19 +188,15 @@ G4int G4TNtupleManager<TN, TF>::CreateNtuple(G4NtupleBooking* ntupleBooking)
|
||||
auto fromBooking = true;
|
||||
FinishTNtuple(ntupleDescription, fromBooking);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()
|
||||
->Message("create from booking", "ntuple",
|
||||
ntupleBooking->fNtupleBooking.name());
|
||||
#endif
|
||||
Message(G4Analysis::kVL3, "create from booking", "ntuple",
|
||||
ntupleBooking->fNtupleBooking.name());
|
||||
|
||||
return ntupleBooking->fNtupleId;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
void G4TNtupleManager<TN, TF>::CreateNtuplesFromBooking(
|
||||
template <typename NT, typename FT>
|
||||
void G4TNtupleManager<NT, FT>::CreateNtuplesFromBooking(
|
||||
const std::vector<G4NtupleBooking*>& ntupleBookings)
|
||||
{
|
||||
// Create ntuple from ntuple bookings.
|
||||
@@ -231,114 +208,113 @@ void G4TNtupleManager<TN, TF>::CreateNtuplesFromBooking(
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4bool
|
||||
G4TNtupleManager<TN, TF>::Reset(G4bool /*deleteNtuple*/)
|
||||
template <typename NT, typename FT>
|
||||
G4bool
|
||||
G4TNtupleManager<NT, FT>::Reset()
|
||||
{
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
// if ( deleteNtuple ) {
|
||||
// delete ntupleDescription->fNtuple;
|
||||
// }
|
||||
// ntupleDescription->fNtuple = 0;
|
||||
delete ntupleDescription;
|
||||
}
|
||||
|
||||
fNtupleDescriptionVector.clear();
|
||||
fNtupleVector.clear();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4bool G4TNtupleManager<TN, TF>::FillNtupleIColumn(
|
||||
template <typename NT, typename FT>
|
||||
void
|
||||
G4TNtupleManager<NT, FT>::Clear()
|
||||
{
|
||||
// Reset function clears all data
|
||||
Reset();
|
||||
|
||||
Message(G4Analysis::kVL2, "clear", "ntuples");
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename NT, typename FT>
|
||||
G4bool G4TNtupleManager<NT, FT>::FillNtupleIColumn(
|
||||
G4int ntupleId, G4int columnId, G4int value)
|
||||
{
|
||||
return FillNtupleTColumn<int>(ntupleId, columnId, value);
|
||||
}
|
||||
}
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4bool G4TNtupleManager<TN, TF>::FillNtupleFColumn(
|
||||
template <typename NT, typename FT>
|
||||
G4bool G4TNtupleManager<NT, FT>::FillNtupleFColumn(
|
||||
G4int ntupleId, G4int columnId, G4float value)
|
||||
{
|
||||
return FillNtupleTColumn<float>(ntupleId, columnId, value);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4bool G4TNtupleManager<TN, TF>::FillNtupleDColumn(
|
||||
template <typename NT, typename FT>
|
||||
G4bool G4TNtupleManager<NT, FT>::FillNtupleDColumn(
|
||||
G4int ntupleId, G4int columnId, G4double value)
|
||||
{
|
||||
return FillNtupleTColumn<double>(ntupleId, columnId, value);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4bool G4TNtupleManager<TN, TF>::FillNtupleSColumn(
|
||||
template <typename NT, typename FT>
|
||||
G4bool G4TNtupleManager<NT, FT>::FillNtupleSColumn(
|
||||
G4int ntupleId, G4int columnId, const G4String& value)
|
||||
{
|
||||
return FillNtupleTColumn<std::string>(ntupleId, columnId, value);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4bool G4TNtupleManager<TN, TF>::AddNtupleRow(
|
||||
template <typename NT, typename FT>
|
||||
G4bool G4TNtupleManager<NT, FT>::AddNtupleRow(
|
||||
G4int ntupleId)
|
||||
{
|
||||
{
|
||||
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", "ntuple row", description);
|
||||
}
|
||||
#endif
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "add", "ntuple row",
|
||||
" ntupleId " + to_string(ntupleId));
|
||||
}
|
||||
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "AddNtupleRow");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
auto ntuple = ntupleDescription->fNtuple;
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
|
||||
auto result = ntuple->add_row();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << " ntupleId " << ntupleId
|
||||
<< "adding row has failed.";
|
||||
G4Exception("G4TNtupleManager::AddTNtupleRow()",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
}
|
||||
G4Analysis::Warn(
|
||||
"Ntuple " + to_string(ntupleId) + " adding row has failed.",
|
||||
fkClass, "AddTNtupleRow");
|
||||
}
|
||||
|
||||
ntupleDescription->fHasFill = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("add", "ntuple row", description);
|
||||
}
|
||||
#endif
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "add", "ntuple row",
|
||||
" ntupleId " + to_string(ntupleId));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
void G4TNtupleManager<TN, TF>::SetActivation(
|
||||
template <typename NT, typename FT>
|
||||
void G4TNtupleManager<NT, FT>::SetActivation(
|
||||
G4bool activation)
|
||||
{
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
ntupleDescription->fActivation = activation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
void G4TNtupleManager<TN, TF>::SetActivation(
|
||||
template <typename NT, typename FT>
|
||||
void G4TNtupleManager<NT, FT>::SetActivation(
|
||||
G4int ntupleId, G4bool activation)
|
||||
{
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetActivation");
|
||||
@@ -348,8 +324,8 @@ void G4TNtupleManager<TN, TF>::SetActivation(
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4bool G4TNtupleManager<TN, TF>::GetActivation(
|
||||
template <typename NT, typename FT>
|
||||
G4bool G4TNtupleManager<NT, FT>::GetActivation(
|
||||
G4int ntupleId) const
|
||||
{
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetActivation");
|
||||
@@ -359,59 +335,59 @@ G4bool G4TNtupleManager<TN, TF>::GetActivation(
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
TN*
|
||||
G4TNtupleManager<TN, TF>::GetNtuple() const
|
||||
template <typename NT, typename FT>
|
||||
NT*
|
||||
G4TNtupleManager<NT, FT>::GetNtuple() const
|
||||
{
|
||||
return GetNtuple(fFirstId);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
TN*
|
||||
G4TNtupleManager<TN, TF>::GetNtuple(G4int ntupleId) const
|
||||
template <typename NT, typename FT>
|
||||
NT*
|
||||
G4TNtupleManager<NT, FT>::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetNtuple");
|
||||
if ( ! ntupleDescription ) return nullptr;
|
||||
|
||||
return ntupleDescription->fNtuple;
|
||||
}
|
||||
if ( ! ntupleDescription ) return nullptr;
|
||||
|
||||
return ntupleDescription->fNtuple;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
typename std::vector<TN*>::iterator
|
||||
G4TNtupleManager<TN, TF>::BeginNtuple()
|
||||
{
|
||||
template <typename NT, typename FT>
|
||||
typename std::vector<NT*>::iterator
|
||||
G4TNtupleManager<NT, FT>::BeginNtuple()
|
||||
{
|
||||
return fNtupleVector.begin();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
typename std::vector<TN*>::iterator
|
||||
G4TNtupleManager<TN, TF>::EndNtuple()
|
||||
{
|
||||
return fNtupleVector.end();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
typename std::vector<TN*>::const_iterator
|
||||
G4TNtupleManager<TN, TF>::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleVector.begin();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
typename std::vector<TN*>::const_iterator
|
||||
G4TNtupleManager<TN, TF>::EndConstNtuple() const
|
||||
{
|
||||
template <typename NT, typename FT>
|
||||
typename std::vector<NT*>::iterator
|
||||
G4TNtupleManager<NT, FT>::EndNtuple()
|
||||
{
|
||||
return fNtupleVector.end();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename TN, typename TF>
|
||||
G4int G4TNtupleManager<TN, TF>::GetNofNtuples() const
|
||||
{
|
||||
template <typename NT, typename FT>
|
||||
typename std::vector<NT*>::const_iterator
|
||||
G4TNtupleManager<NT, FT>::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleVector.begin();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename NT, typename FT>
|
||||
typename std::vector<NT*>::const_iterator
|
||||
G4TNtupleManager<NT, FT>::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleVector.end();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename NT, typename FT>
|
||||
G4int G4TNtupleManager<NT, FT>::GetNofNtuples() const
|
||||
{
|
||||
return G4int(fNtupleVector.size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user