// // ******************************************************************** // * 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 G4TRNtupleManager::G4TRNtupleManager(const G4AnalysisManagerState& state) : G4BaseRNtupleManager(state) {} //_____________________________________________________________________________ template G4TRNtupleManager::~G4TRNtupleManager() { for ( auto ntupleDescription : fNtupleDescriptionVector ) { delete ntupleDescription; } } // // private methods // //_____________________________________________________________________________ template G4TRNtupleDescription* G4TRNtupleManager::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 template G4bool G4TRNtupleManager::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 template G4bool G4TRNtupleManager::SetNtupleTColumn( G4int ntupleId, const G4String& columnName, std::vector& 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 G4bool G4TRNtupleManager::IsEmpty() const { return ! fNtupleDescriptionVector.size(); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::Reset() { // Reset ntuples for ( auto ntupleDescription : fNtupleDescriptionVector ) { delete ntupleDescription->fNtuple; ntupleDescription->fNtuple=nullptr; } return true; } //_____________________________________________________________________________ template NT* G4TRNtupleManager::GetNtuple() const { return GetNtuple(fFirstId); } //_____________________________________________________________________________ template NT* G4TRNtupleManager::GetNtuple( G4int ntupleId) const { auto rntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetNtuple"); if ( ! rntupleDescription ) return nullptr; return rntupleDescription->fNtuple; } //_____________________________________________________________________________ template G4int G4TRNtupleManager::SetNtuple( G4TRNtupleDescription* rntupleDescription) { auto id = G4int(fNtupleDescriptionVector.size() + fFirstId); fNtupleDescriptionVector.push_back(rntupleDescription); return id; } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::SetNtupleIColumn( G4int ntupleId, const G4String& columnName, G4int& value) { return SetNtupleTColumn(ntupleId, columnName, value); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::SetNtupleFColumn( G4int ntupleId, const G4String& columnName, G4float& value) { return SetNtupleTColumn(ntupleId, columnName, value); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::SetNtupleDColumn( G4int ntupleId, const G4String& columnName, G4double& value) { return SetNtupleTColumn(ntupleId, columnName, value); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::SetNtupleIColumn( G4int ntupleId, const G4String& columnName, std::vector& vector) { return SetNtupleTColumn(ntupleId, columnName, vector); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::SetNtupleFColumn( G4int ntupleId, const G4String& columnName, std::vector& vector) { return SetNtupleTColumn(ntupleId, columnName, vector); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::SetNtupleDColumn( G4int ntupleId, const G4String& columnName, std::vector& vector) { return SetNtupleTColumn(ntupleId, columnName, vector); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::SetNtupleSColumn( G4int ntupleId, const G4String& columnName, G4String& value) { return SetNtupleTColumn(ntupleId, columnName, value); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::SetNtupleSColumn( G4int ntupleId, const G4String& columnName, std::vector& vector) { return SetNtupleTColumn(ntupleId, columnName, vector); } //_____________________________________________________________________________ template G4bool G4TRNtupleManager::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 G4int G4TRNtupleManager::GetNofNtuples() const { return G4int(fNtupleDescriptionVector.size()); }