274 lines
8.6 KiB
Plaintext
274 lines
8.6 KiB
Plaintext
//
|
|
// ********************************************************************
|
|
// * License and Disclaimer *
|
|
// * *
|
|
// * The Geant4 software is copyright of the Copyright Holders of *
|
|
// * the Geant4 Collaboration. It is provided under the terms and *
|
|
// * conditions of the Geant4 Software License, included in the file *
|
|
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
|
// * include a list of copyright holders. *
|
|
// * *
|
|
// * Neither the authors of this software system, nor their employing *
|
|
// * institutes,nor the agencies providing financial support for this *
|
|
// * work make any representation or warranty, express or implied, *
|
|
// * regarding this software system or assume any liability for its *
|
|
// * use. Please see the license in the file LICENSE and URL above *
|
|
// * for the full disclaimer and the limitation of liability. *
|
|
// * *
|
|
// * This code implementation is the result of the scientific and *
|
|
// * technical work of the GEANT4 collaboration. *
|
|
// * By using, copying, modifying or distributing the software (or *
|
|
// * any work based on the software) you agree to acknowledge its *
|
|
// * use in resulting scientific publications, and indicate your *
|
|
// * acceptance of all terms of the Geant4 Software license. *
|
|
// ********************************************************************
|
|
//
|
|
|
|
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
|
|
|
#include "G4AnalysisManagerState.hh"
|
|
#include "G4AnalysisUtilities.hh"
|
|
|
|
using std::to_string;
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4TRNtupleManager<NT>::G4TRNtupleManager(const G4AnalysisManagerState& state)
|
|
: G4BaseRNtupleManager(state)
|
|
{}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4TRNtupleManager<NT>::~G4TRNtupleManager()
|
|
{
|
|
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
|
delete ntupleDescription;
|
|
}
|
|
}
|
|
|
|
//
|
|
// private methods
|
|
//
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4TRNtupleDescription<NT>*
|
|
G4TRNtupleManager<NT>::GetNtupleDescriptionInFunction(
|
|
G4int id, std::string_view functionName, G4bool warn) const
|
|
{
|
|
G4int index = id - fFirstId;
|
|
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
|
|
if ( warn) {
|
|
G4Analysis::Warn("ntuple " + to_string(id) + " does not exist.",
|
|
fkClass, functionName);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
return fNtupleDescriptionVector[index];
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
template <typename T>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleTColumn(
|
|
G4int ntupleId, const G4String& columnName, T& value)
|
|
{
|
|
Message(G4Analysis::kVL4, "set", "ntuple T column",
|
|
" ntupleId " + to_string(ntupleId) + " " + columnName);
|
|
|
|
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleTColumn");
|
|
if ( ! ntupleDescription ) return false;
|
|
|
|
auto ntupleBinding = ntupleDescription->fNtupleBinding;
|
|
ntupleBinding->add_column(columnName, value);
|
|
|
|
Message(G4Analysis::kVL2, "set", "ntuple T column",
|
|
" ntupleId " + to_string(ntupleId) + " " + columnName);
|
|
|
|
return true;
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
template <typename T>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleTColumn(
|
|
G4int ntupleId, const G4String& columnName, std::vector<T>& vector)
|
|
{
|
|
Message(G4Analysis::kVL4, "set", "ntuple T column",
|
|
" ntupleId " + to_string(ntupleId) + " " + columnName);
|
|
|
|
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleTColumn");
|
|
if ( ! ntupleDescription ) return false;
|
|
|
|
auto ntupleBinding = ntupleDescription->fNtupleBinding;
|
|
ntupleBinding->add_column(columnName, vector);
|
|
|
|
Message(G4Analysis::kVL2, "set", "ntuple T column",
|
|
" ntupleId " + to_string(ntupleId) + " " + columnName);
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
//
|
|
// protected methods
|
|
//
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool G4TRNtupleManager<NT>::IsEmpty() const
|
|
{
|
|
return ! fNtupleDescriptionVector.size();
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool G4TRNtupleManager<NT>::Reset()
|
|
{
|
|
// Reset ntuples
|
|
|
|
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
|
delete ntupleDescription->fNtuple;
|
|
ntupleDescription->fNtuple=nullptr;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
NT*
|
|
G4TRNtupleManager<NT>::GetNtuple() const
|
|
{
|
|
return GetNtuple(fFirstId);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
NT*
|
|
G4TRNtupleManager<NT>::GetNtuple(
|
|
G4int ntupleId) const
|
|
{
|
|
auto rntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetNtuple");
|
|
|
|
if ( ! rntupleDescription ) return nullptr;
|
|
|
|
return rntupleDescription->fNtuple;
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4int G4TRNtupleManager<NT>::SetNtuple(
|
|
G4TRNtupleDescription<NT>* rntupleDescription)
|
|
{
|
|
auto id = G4int(fNtupleDescriptionVector.size() + fFirstId);
|
|
|
|
fNtupleDescriptionVector.push_back(rntupleDescription);
|
|
|
|
return id;
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleIColumn(
|
|
G4int ntupleId, const G4String& columnName, G4int& value)
|
|
{
|
|
return SetNtupleTColumn<int>(ntupleId, columnName, value);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleFColumn(
|
|
G4int ntupleId, const G4String& columnName, G4float& value)
|
|
{
|
|
return SetNtupleTColumn<float>(ntupleId, columnName, value);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleDColumn(
|
|
G4int ntupleId, const G4String& columnName, G4double& value)
|
|
{
|
|
return SetNtupleTColumn<double>(ntupleId, columnName, value);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleIColumn(
|
|
G4int ntupleId, const G4String& columnName, std::vector<G4int>& vector)
|
|
{
|
|
return SetNtupleTColumn<int>(ntupleId, columnName, vector);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleFColumn(
|
|
G4int ntupleId, const G4String& columnName, std::vector<G4float>& vector)
|
|
{
|
|
return SetNtupleTColumn<float>(ntupleId, columnName, vector);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleDColumn(
|
|
G4int ntupleId, const G4String& columnName, std::vector<G4double>& vector)
|
|
{
|
|
return SetNtupleTColumn<double>(ntupleId, columnName, vector);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleSColumn(
|
|
G4int ntupleId, const G4String& columnName, G4String& value)
|
|
{
|
|
return SetNtupleTColumn<std::string>(ntupleId, columnName, value);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool
|
|
G4TRNtupleManager<NT>::SetNtupleSColumn(
|
|
G4int ntupleId, const G4String& columnName, std::vector<std::string>& vector)
|
|
{
|
|
return SetNtupleTColumn<std::string>(ntupleId, columnName, vector);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4bool G4TRNtupleManager<NT>::GetNtupleRow(G4int ntupleId)
|
|
{
|
|
Message(G4Analysis::kVL4, "get", "ntuple row",
|
|
"ntupleId " + to_string(ntupleId));
|
|
|
|
auto ntupleDescription
|
|
= GetNtupleDescriptionInFunction(ntupleId, "GetNtupleRow");
|
|
if ( ! ntupleDescription ) return false;
|
|
|
|
auto next = GetTNtupleRow(ntupleDescription);
|
|
|
|
Message(G4Analysis::kVL2, "get", "ntuple row",
|
|
"ntupleId " + to_string(ntupleId));
|
|
|
|
return next;
|
|
}
|
|
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename NT>
|
|
G4int
|
|
G4TRNtupleManager<NT>::GetNofNtuples() const
|
|
{
|
|
return G4int(fNtupleDescriptionVector.size());
|
|
}
|
|
|
|
|