Import Geant4 10.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2017-12-08 12:52:30 +01:00
parent 98e455a940
commit fc6af9e721
2166 changed files with 276760 additions and 100873 deletions
@@ -0,0 +1,110 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
// The base class for Ntuple managers.
// It implements commen functions independent from the output type.
//
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
#ifndef G4BaseNtupleManager_h
#define G4BaseNtupleManager_h 1
#include "G4VNtupleManager.hh"
#include "globals.hh"
class G4BaseNtupleManager : public G4VNtupleManager
{
public:
explicit G4BaseNtupleManager(const G4AnalysisManagerState& state);
virtual ~G4BaseNtupleManager();
// deleted copy constructor & assignment operator
G4BaseNtupleManager(const G4BaseNtupleManager& rhs) = delete;
G4BaseNtupleManager& operator=(const G4BaseNtupleManager& rhs) =delete;
protected:
// Methods for handling ntuples
virtual G4int CreateNtuple(const G4String& name, const G4String& title) = 0;
// Create columns in the last created ntuple
virtual G4int CreateNtupleIColumn(const G4String& name,
std::vector<int>* vector) final;
virtual G4int CreateNtupleFColumn(const G4String& name,
std::vector<float>* vector) final;
virtual G4int CreateNtupleDColumn(const G4String& name,
std::vector<double>* vector) final;
virtual G4int CreateNtupleSColumn(const G4String& name);
virtual void FinishNtuple() final;
// Create columns in the ntuple with given id
virtual G4int CreateNtupleIColumn(G4int ntupleId, const G4String& name,
std::vector<int>* vector) = 0;
virtual G4int CreateNtupleFColumn(G4int ntupleId, const G4String& name,
std::vector<float>* vector) = 0;
virtual G4int CreateNtupleDColumn(G4int ntupleId, const G4String& name,
std::vector<double>* vector) = 0;
virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) = 0;
virtual void FinishNtuple(G4int ntupleId) = 0;
// The ntuple column ids are generated automatically starting from 0;
// with the following function it is possible to change it
// to start from another value
virtual G4bool SetFirstNtupleColumnId(G4int firstId) final;
G4int GetFirstNtupleColumnId() const final;
// Methods to fill ntuples
// Methods for ntuple with id = FirstNtupleId
virtual G4bool FillNtupleIColumn(G4int id, G4int value) final;
virtual G4bool FillNtupleFColumn(G4int id, G4float value) final;
virtual G4bool FillNtupleDColumn(G4int id, G4double value) final;
virtual G4bool FillNtupleSColumn(G4int id, const G4String& value) final;
virtual G4bool AddNtupleRow() final;
// Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) = 0;
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) = 0;
virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) = 0;
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
const G4String& value) = 0;
virtual G4bool AddNtupleRow(G4int ntupleId) = 0;
protected:
G4int fFirstNtupleColumnId;
G4bool fLockFirstNtupleColumnId;
private:
// methods
G4int GetCurrentNtupleId() const;
};
// inline functions
inline G4int G4BaseNtupleManager::GetFirstNtupleColumnId() const {
return fFirstNtupleColumnId;
}
#endif
@@ -0,0 +1,102 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
// The base class for read Ntuple manager.
// It defines functions independent from the output type.
//
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
#ifndef G4BaseRNtupleManager_h
#define G4BaseRNtupleManager_h 1
#include "G4VRNtupleManager.hh"
#include "globals.hh"
#include <vector>
class G4BaseRNtupleManager : public G4VRNtupleManager
{
// Disable using the object managers outside G4VAnalysisManager and
// its messenger
friend class G4VAnalysisReader;
public:
explicit G4BaseRNtupleManager(const G4AnalysisManagerState& state);
virtual ~G4BaseRNtupleManager();
// deleted copy constructor & assignment operator
G4BaseRNtupleManager(const G4BaseRNtupleManager& rhs) = delete;
G4BaseRNtupleManager& operator=(const G4BaseRNtupleManager& rhs) = delete;
protected:
// Methods to read ntuple from a file
// Methods for ntuple with id = FirstNtupleId
virtual G4bool SetNtupleIColumn(const G4String& columnName,
G4int& value) final;
virtual G4bool SetNtupleFColumn(const G4String& columnName,
G4float& value) final;
virtual G4bool SetNtupleDColumn(const G4String& columnName,
G4double& value) final;
virtual G4bool SetNtupleSColumn(const G4String& columnName,
G4String& value) final;
// Methods for ntuple with id > FirstNtupleId
virtual G4bool SetNtupleIColumn(G4int ntupleId,
const G4String& columnName, G4int& value)= 0;
virtual G4bool SetNtupleFColumn(G4int ntupleId,
const G4String& columnName, G4float& value)= 0;
virtual G4bool SetNtupleDColumn(G4int ntupleId,
const G4String& columnName, G4double& value)= 0;
virtual G4bool SetNtupleSColumn(G4int ntupleId,
const G4String& columnName, G4String& value)= 0;
// Bind the ntuple columns of vector type
// Methods for ntuple with id = FirstNtupleId
virtual G4bool SetNtupleIColumn(const G4String& columnName,
std::vector<G4int>& vector) final;
virtual G4bool SetNtupleFColumn(const G4String& columnName,
std::vector<G4float>& vector) final;
virtual G4bool SetNtupleDColumn(const G4String& columnName,
std::vector<G4double>& vector) final;
// Methods for ntuple with id > FirstNtupleId
virtual G4bool SetNtupleIColumn(G4int ntupleId, const G4String& columnName,
std::vector<G4int>& vector) = 0;
virtual G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName,
std::vector<G4float>& vector) = 0;
virtual G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
std::vector<G4double>& vector) = 0;
virtual G4bool GetNtupleRow() final;
virtual G4bool GetNtupleRow(G4int ntupleId) = 0;
// Access methods
virtual G4int GetNofNtuples() const = 0;
private:
// methods
G4int GetCurrentNtupleId() const;
};
#endif
@@ -32,14 +32,14 @@
#ifndef G4TNtupleManager_h
#define G4TNtupleManager_h 1
#include "G4VNtupleManager.hh"
#include "G4BaseNtupleManager.hh"
#include "G4TNtupleDescription.hh"
#include "globals.hh"
#include <vector>
template <typename TNTUPLE>
class G4TNtupleManager : public G4VNtupleManager {
class G4TNtupleManager : public G4BaseNtupleManager {
public:
explicit G4TNtupleManager(const G4AnalysisManagerState& state);
@@ -54,15 +54,13 @@ class G4TNtupleManager : public G4VNtupleManager {
// Methods to create ntuples
//
virtual G4int CreateNtuple(const G4String& name, const G4String& title) final;
// Create columns in the last created ntuple
virtual G4int CreateNtupleIColumn(
const G4String& name, std::vector<int>* vector) final;
virtual G4int CreateNtupleFColumn(
const G4String& name, std::vector<float>* vector) final;
virtual G4int CreateNtupleDColumn(
const G4String& name, std::vector<double>* vector) final;
virtual G4int CreateNtupleSColumn(const G4String& name) final;
virtual void FinishNtuple() final;
// Create columns in the last created ntuple (from base class)
using G4BaseNtupleManager::CreateNtupleIColumn;
using G4BaseNtupleManager::CreateNtupleFColumn;
using G4BaseNtupleManager::CreateNtupleDColumn;
using G4BaseNtupleManager::CreateNtupleSColumn;
using G4BaseNtupleManager::FinishNtuple;
// Create columns in the ntuple with given id
virtual G4int CreateNtupleIColumn(G4int ntupleId,
const G4String& name, std::vector<int>* vector) final;
@@ -74,12 +72,12 @@ class G4TNtupleManager : public G4VNtupleManager {
virtual void FinishNtuple(G4int ntupleId) final;
// Methods to fill ntuples
// Methods for ntuple with id = FirstNtupleId
virtual G4bool FillNtupleIColumn(G4int columnId, G4int value) final;
virtual G4bool FillNtupleFColumn(G4int columnId, G4float value) final;
virtual G4bool FillNtupleDColumn(G4int columnId, G4double value) final;
virtual G4bool FillNtupleSColumn(G4int columnId, const G4String& value) final;
virtual G4bool AddNtupleRow() final;
// Methods for ntuple with id = FirstNtupleId (from base class)
using G4BaseNtupleManager::FillNtupleIColumn;
using G4BaseNtupleManager::FillNtupleFColumn;
using G4BaseNtupleManager::FillNtupleDColumn;
using G4BaseNtupleManager::FillNtupleSColumn;
using G4BaseNtupleManager::AddNtupleRow;
// Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
@@ -98,6 +96,7 @@ class G4TNtupleManager : public G4VNtupleManager {
TNTUPLE* GetNtuple() const;
TNTUPLE* GetNtuple(G4int ntupleId) const;
virtual G4int GetNofNtuples() const final;
virtual G4int GetNofNtupleBookings() const override;
// Iterators
typename std::vector<TNTUPLE*>::iterator BeginNtuple();
@@ -114,15 +113,13 @@ class G4TNtupleManager : public G4VNtupleManager {
// Fuctions which are specific to output type
//
virtual void CreateTNtuple(
G4TNtupleDescription<TNTUPLE>* ntupleDescription,
const G4String& name, const G4String& title) = 0;
virtual void CreateTNtupleFromBooking(
G4TNtupleDescription<TNTUPLE>* ntupleDescription) = 0;
virtual void FinishTNtuple(
G4TNtupleDescription<TNTUPLE>* ntupleDescription) = 0;
void FinishTNtupleNew(G4TNtupleDescription<TNTUPLE>* ntupleDescription);
// Common implementation
//
@@ -134,26 +131,14 @@ class G4TNtupleManager : public G4VNtupleManager {
G4String function,
G4bool warn = true) const;
// template functions for creating/filling ntuple columns
template <typename T>
void CreateTColumnInNtuple(
G4TNtupleDescription<TNTUPLE>* ntupleDescription,
const G4String& name, std::vector<T>* vector);
// template functions for creating/filling ntuple columns
template <typename T>
G4int CreateNtupleTColumn(G4int ntupleId,
const G4String& name, std::vector<T>* vector);
template <typename T>
G4int CreateNtupleTColumn(
const G4String& name, std::vector<T>* vector);
template <typename T>
G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
template <typename T>
G4bool FillNtupleTColumn(G4int columnId, const T& value);
};
#include "G4TNtupleManager.icc"
@@ -36,7 +36,7 @@
template <typename TNTUPLE>
G4TNtupleManager<TNTUPLE>::G4TNtupleManager(
const G4AnalysisManagerState& state)
: G4VNtupleManager(state),
: G4BaseNtupleManager(state),
fNtupleDescriptionVector(),
fNtupleVector()
{}
@@ -94,23 +94,6 @@ G4TNtupleManager<TNTUPLE>::GetNtupleInFunction(
return ntupleDescription->fNtuple;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename T>
void G4TNtupleManager<TNTUPLE>::CreateTColumnInNtuple(
G4TNtupleDescription<TNTUPLE>* ntupleDescription,
const G4String& name, std::vector<T>* vector)
{
if ( ntupleDescription->fNtuple ) {
if ( vector == nullptr ) {
ntupleDescription->fNtuple->template create_column<T>(name);
}
else {
ntupleDescription->fNtuple->template create_column<T>(name, *vector);
}
}
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename T>
@@ -137,7 +120,7 @@ G4int G4TNtupleManager<TNTUPLE>::CreateNtupleTColumn(
ntupleBooking.template add_column<T>(name, *vector);
// Create column if ntuple already exists
CreateTColumnInNtuple<T>(ntupleDescription, name, vector);
// CreateTColumnInNtuple<T>(ntupleDescription, name, vector);
fLockFirstNtupleColumnId = true;
#ifdef G4VERBOSE
@@ -152,16 +135,6 @@ G4int G4TNtupleManager<TNTUPLE>::CreateNtupleTColumn(
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename T>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleTColumn(
const G4String& name, std::vector<T>* vector)
{
auto ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
return CreateNtupleTColumn<T>(ntupleId, name, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename T>
@@ -214,15 +187,6 @@ G4bool G4TNtupleManager<TNTUPLE>::FillNtupleTColumn(
return true;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename T>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleTColumn(
G4int columnId, const T& value)
{
return FillNtupleTColumn<T>(fFirstId, columnId, value);
}
//
// protected functions
//
@@ -308,7 +272,7 @@ G4int G4TNtupleManager<TNTUPLE>::CreateNtuple(
ntupleDescription->fNtupleBooking.set_title(title);
// Create ntuple
CreateTNtuple(ntupleDescription, name, title);
// CreateTNtuple(ntupleDescription, name, title);
fLockFirstId = true;
#ifdef G4VERBOSE
@@ -322,46 +286,6 @@ G4int G4TNtupleManager<TNTUPLE>::CreateNtuple(
return index + fFirstId;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleIColumn(
const G4String& name, std::vector<int>* vector)
{
return CreateNtupleTColumn<int>(name, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleFColumn(
const G4String& name, std::vector<float>* vector)
{
return CreateNtupleTColumn<float>(name, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleDColumn(
const G4String& name, std::vector<double>* vector)
{
return CreateNtupleTColumn<double>(name, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleSColumn(
const G4String& name)
{
return CreateNtupleTColumn<std::string>(name, nullptr);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
void G4TNtupleManager<TNTUPLE>::FinishNtuple()
{
auto ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
FinishNtuple(ntupleId);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleIColumn(
@@ -427,45 +351,6 @@ void G4TNtupleManager<TNTUPLE>::FinishNtuple(
#endif
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleIColumn(
G4int columnId, G4int value)
{
return FillNtupleTColumn<int>(columnId, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleFColumn(
G4int columnId, G4float value)
{
return FillNtupleTColumn<float>(columnId, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleDColumn(
G4int columnId, G4double value)
{
return FillNtupleTColumn<double>(columnId, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleSColumn(
G4int columnId, const G4String& value)
{
return FillNtupleTColumn<std::string>(columnId, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::AddNtupleRow()
{
return AddNtupleRow(fFirstId);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleIColumn(
@@ -627,3 +512,10 @@ G4int G4TNtupleManager<TNTUPLE>::GetNofNtuples() const
{
return fNtupleVector.size();
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::GetNofNtupleBookings() const
{
return fNtupleDescriptionVector.size();
}
@@ -0,0 +1,86 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
// Structure containing the information related to rroot ntuple
//
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
#ifndef G4TRNtupleDescription_h
#define G4TRNtupleDescription_h 1
#include "tools/ntuple_binding"
#include <map>
#include <vector>
namespace tools {
class ntuple_binding;
}
template <typename TNTUPLE>
struct G4TRNtupleDescription
{
G4TRNtupleDescription(TNTUPLE* rntuple)
: fNtuple(rntuple),
fNtupleBinding(new tools::ntuple_binding()),
fIsInitialized(false),
fIVectorBindingMap(),
fFVectorBindingMap(),
fDVectorBindingMap() {}
~G4TRNtupleDescription()
{
delete fNtupleBinding;
delete fNtuple; // CHECK
{for ( auto mapElement : fIVectorBindingMap ) {
delete mapElement.first;
}}
{for ( auto mapElement : fFVectorBindingMap ) {
delete mapElement.first;
}}
{for ( auto mapElement : fDVectorBindingMap ) {
delete mapElement.first;
}}
}
// deleted copy constructor
G4TRNtupleDescription(const G4TRNtupleDescription& rhs) = delete;
// deleted assignement operator
G4TRNtupleDescription& operator=(G4TRNtupleDescription& rhs) = delete;
TNTUPLE* fNtuple;
tools::ntuple_binding* fNtupleBinding;
G4bool fIsInitialized;
// needed for XML
std::map<TNTUPLE*, std::vector<int>* > fIVectorBindingMap;
std::map<TNTUPLE*, std::vector<float>* > fFVectorBindingMap;
std::map<TNTUPLE*, std::vector<double>* > fDVectorBindingMap;
};
#endif
@@ -0,0 +1,118 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
// Class template for read ntuple managers for all output types.
//
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
#ifndef G4TRNtupleManager_h
#define G4TRNtupleManager_h 1
#include "G4BaseRNtupleManager.hh"
#include "G4TRNtupleDescription.hh"
#include "globals.hh"
#include <vector>
template <typename TNTUPLE>
class G4TRNtupleManager : public G4BaseRNtupleManager
{
protected:
explicit G4TRNtupleManager(const G4AnalysisManagerState& state);
virtual ~G4TRNtupleManager();
// Methods to manipulate ntuples
G4bool IsEmpty() const;
G4bool Reset();
// Access methods
TNTUPLE* GetNtuple() const;
TNTUPLE* GetNtuple(G4int ntupleId) const;
// Functions independent from the output type
//
// Methods to read ntuple from a file
G4int SetNtuple(G4TRNtupleDescription<TNTUPLE>* rntupleDescription);
// Methods to bind ntuple (from base class)
using G4BaseRNtupleManager::SetNtupleIColumn;
using G4BaseRNtupleManager::SetNtupleFColumn;
using G4BaseRNtupleManager::SetNtupleDColumn;
using G4BaseRNtupleManager::SetNtupleSColumn;
// Methods to bind ntuple
virtual G4bool SetNtupleIColumn(G4int ntupleId,
const G4String& columnName, G4int& value) final;
virtual G4bool SetNtupleFColumn(G4int ntupleId,
const G4String& columnName, G4float& value) final;
virtual G4bool SetNtupleDColumn(G4int ntupleId,
const G4String& columnName, G4double& value) final;
virtual G4bool SetNtupleSColumn(G4int ntupleId,
const G4String& columnName, G4String& value) final;
// Bind the ntuple columns of vector type
virtual G4bool SetNtupleIColumn(G4int ntupleId, const G4String& columnName,
std::vector<G4int>& vector) override;
virtual G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName,
std::vector<G4float>& vector) override;
virtual G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
std::vector<G4double>& vector) override;
using G4BaseRNtupleManager::GetNtupleRow;
virtual G4bool GetNtupleRow(G4int ntupleId) final;
// Access methods
virtual G4int GetNofNtuples() const final;
// Utility method
G4TRNtupleDescription<TNTUPLE>* GetNtupleDescriptionInFunction(G4int id,
G4String function,
G4bool warn = true) const;
private:
// Fuctions which are specific to output type
//
virtual G4bool GetTNtupleRow(G4TRNtupleDescription<TNTUPLE>* rntupleDescription) = 0;
// Common implementation
//
template <typename T>
G4bool SetNtupleTColumn(G4int ntupleId, const G4String& name,
T& value);
template <typename T>
G4bool SetNtupleTColumn(G4int ntupleId, const G4String& name,
std::vector<T>& vector);
// data members
std::vector<G4TRNtupleDescription<TNTUPLE>*> fNtupleDescriptionVector;
};
#include "G4TRNtupleManager.icc"
#endif
@@ -0,0 +1,296 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// $Id$
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
//_____________________________________________________________________________
template <typename TNTUPLE>
G4TRNtupleManager<TNTUPLE>::G4TRNtupleManager(const G4AnalysisManagerState& state)
: G4BaseRNtupleManager(state),
fNtupleDescriptionVector()
{}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4TRNtupleManager<TNTUPLE>::~G4TRNtupleManager()
{
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
delete ntupleDescription;
}
}
//
// private methods
//
//_____________________________________________________________________________
template <typename TNTUPLE>
G4TRNtupleDescription<TNTUPLE>*
G4TRNtupleManager<TNTUPLE>::GetNtupleDescriptionInFunction(
G4int id, G4String functionName, G4bool warn) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
if ( warn) {
G4String inFunction = "G4TRNtupleManager<TNTUPLE>::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "ntuple " << id << " does not exist.";
G4Exception(inFunction, "Analysis_WR011", JustWarning, description);
}
return nullptr;
}
return fNtupleDescriptionVector[index];
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename T>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleTColumn(
G4int ntupleId, const G4String& columnName, T& value)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple I column", description);
}
#endif
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleTColumn");
if ( ! ntupleDescription ) return false;
auto ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple I colum", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename T>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleTColumn(
G4int ntupleId, const G4String& columnName, std::vector<T>& vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL4()->Message("set", "ntuple I column", description);
}
#endif
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetNtupleTColumn");
if ( ! ntupleDescription ) return false;
auto ntupleBinding = ntupleDescription->fNtupleBinding;
ntupleBinding->add_column(columnName, vector);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId << " " << columnName;
fState.GetVerboseL2()->Message("set", "ntuple T colum", description, true);
}
#endif
return true;
}
//
// protected methods
//
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TRNtupleManager<TNTUPLE>::IsEmpty() const
{
return ! fNtupleDescriptionVector.size();
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TRNtupleManager<TNTUPLE>::Reset()
{
// Reset ntuples
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
ntupleDescription->fNtuple=0;
}
return true;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
TNTUPLE*
G4TRNtupleManager<TNTUPLE>::GetNtuple() const
{
return GetNtuple(fFirstId);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
TNTUPLE*
G4TRNtupleManager<TNTUPLE>::GetNtuple(
G4int ntupleId) const
{
auto rntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetNtuple");
if ( ! rntupleDescription ) return nullptr;
return rntupleDescription->fNtuple;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TRNtupleManager<TNTUPLE>::SetNtuple(
G4TRNtupleDescription<TNTUPLE>* rntupleDescription)
{
G4int id = fNtupleDescriptionVector.size() + fFirstId;
fNtupleDescriptionVector.push_back(rntupleDescription);
return id;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleIColumn(
G4int ntupleId, const G4String& columnName, G4int& value)
{
return SetNtupleTColumn<int>(ntupleId, columnName, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleFColumn(
G4int ntupleId, const G4String& columnName, G4float& value)
{
return SetNtupleTColumn<float>(ntupleId, columnName, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleDColumn(
G4int ntupleId, const G4String& columnName, G4double& value)
{
return SetNtupleTColumn<double>(ntupleId, columnName, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleIColumn(
G4int ntupleId, const G4String& columnName, std::vector<G4int>& vector)
{
return SetNtupleTColumn<int>(ntupleId, columnName, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleFColumn(
G4int ntupleId, const G4String& columnName, std::vector<G4float>& vector)
{
return SetNtupleTColumn<float>(ntupleId, columnName, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleDColumn(
G4int ntupleId, const G4String& columnName, std::vector<G4double>& vector)
{
return SetNtupleTColumn<double>(ntupleId, columnName, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TRNtupleManager<TNTUPLE>::SetNtupleSColumn(
G4int ntupleId, const G4String& columnName, G4String& value)
{
return SetNtupleTColumn<std::string>(ntupleId, columnName, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TRNtupleManager<TNTUPLE>::GetNtupleRow(G4int ntupleId)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("get", "ntuple row", description);
}
#endif
auto ntupleDescription
= GetNtupleDescriptionInFunction(ntupleId, "GetNtupleRow");
if ( ! ntupleDescription ) return false;
auto next = GetTNtupleRow(ntupleDescription);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("get", "ntuple row", description, true);
}
#endif
return next;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int
G4TRNtupleManager<TNTUPLE>::GetNofNtuples() const
{
return fNtupleDescriptionVector.size();
}
@@ -67,11 +67,11 @@ class G4VAnalysisReader
G4String GetFileName() const;
// Methods to read histograms from a file
G4int ReadH1(const G4String& h1Name, const G4String& fileName = "");
G4int ReadH2(const G4String& h2Name, const G4String& fileName = "");
G4int ReadH3(const G4String& h3Name, const G4String& fileName = "");
G4int ReadP1(const G4String& h1Name, const G4String& fileName = "");
G4int ReadP2(const G4String& h2Name, const G4String& fileName = "");
G4int ReadH1(const G4String& h1Name, const G4String& fileName = "", const G4String& dirName = "");
G4int ReadH2(const G4String& h2Name, const G4String& fileName = "", const G4String& dirName = "");
G4int ReadH3(const G4String& h3Name, const G4String& fileName = "", const G4String& dirName = "");
G4int ReadP1(const G4String& h1Name, const G4String& fileName = "", const G4String& dirName = "");
G4int ReadP2(const G4String& h2Name, const G4String& fileName = "", const G4String& dirName = "");
// The ids of histograms and ntuples are generated automatically
// starting from 0; with following functions it is possible to
@@ -86,7 +86,7 @@ class G4VAnalysisReader
G4bool SetFirstNtupleId(G4int firstId);
// Methods to read ntuple from a file
G4int GetNtuple(const G4String& ntupleName, const G4String& fileName = "");
G4int GetNtuple(const G4String& ntupleName, const G4String& fileName = "", const G4String& dirName = "");
// Methods for ntuple with id = FirstNtupleId
G4bool SetNtupleIColumn(const G4String& columnName, G4int& value);
@@ -226,17 +226,17 @@ class G4VAnalysisReader
protected:
// virtual methods
virtual G4int ReadH1Impl(const G4String& h1Name, const G4String& fileName,
G4bool isUserFileName) = 0;
const G4String& dirName, G4bool isUserFileName) = 0;
virtual G4int ReadH2Impl(const G4String& h2Name, const G4String& fileName,
G4bool isUserFileName) = 0;
const G4String& dirName, G4bool isUserFileName) = 0;
virtual G4int ReadH3Impl(const G4String& h3Name, const G4String& fileName,
G4bool isUserFileName) = 0;
const G4String& dirName, G4bool isUserFileName) = 0;
virtual G4int ReadP1Impl(const G4String& p1Name, const G4String& fileName,
G4bool isUserFileName) = 0;
const G4String& dirName, G4bool isUserFileName) = 0;
virtual G4int ReadP2Impl(const G4String& p2Name, const G4String& fileName,
G4bool isUserFileName) = 0;
const G4String& dirName, G4bool isUserFileName) = 0;
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
G4bool isUserFileName) = 0;
const G4String& dirName, G4bool isUserFileName) = 0;
// methods
void SetH1Manager(G4VH1Manager* h1Manager);
@@ -25,7 +25,7 @@
//
// $Id: G4VNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Base class for Ntuple manager.
// The pure abstract base class for Ntuple manager.
// It defines functions independent from the output type.
//
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
@@ -45,28 +45,28 @@ class G4VNtupleManager : public G4BaseAnalysisManager
friend class G4VAnalysisManager;
public:
explicit G4VNtupleManager(const G4AnalysisManagerState& state);
virtual ~G4VNtupleManager();
explicit G4VNtupleManager(const G4AnalysisManagerState& state)
: G4BaseAnalysisManager(state) {}
virtual ~G4VNtupleManager() {}
// deleted copy constructor & assignment operator
G4VNtupleManager(const G4VNtupleManager& rhs) = delete;
G4VNtupleManager& operator=(const G4VNtupleManager& rhs) =delete;
G4VNtupleManager& operator=(const G4VNtupleManager& rhs) = delete;
protected:
//G4VNtupleManager(const G4AnalysisManagerState& state);
//virtual ~G4VNtupleManager();
// Methods for handling ntuples
virtual G4int CreateNtuple(const G4String& name, const G4String& title) = 0;
// Create columns in the last created ntuple
virtual G4int CreateNtupleIColumn(const G4String& name,
std::vector<int>* vector) = 0;
std::vector<int>* vector) = 0;
virtual G4int CreateNtupleFColumn(const G4String& name,
std::vector<float>* vector) = 0;
std::vector<float>* vector) = 0;
virtual G4int CreateNtupleDColumn(const G4String& name,
std::vector<double>* vector) = 0;
std::vector<double>* vector) = 0;
virtual G4int CreateNtupleSColumn(const G4String& name) = 0;
virtual void FinishNtuple() = 0;
// Create columns in the ntuple with given id
virtual G4int CreateNtupleIColumn(G4int ntupleId, const G4String& name,
std::vector<int>* vector) = 0;
@@ -80,8 +80,8 @@ class G4VNtupleManager : public G4BaseAnalysisManager
// The ntuple column ids are generated automatically starting from 0;
// with the following function it is possible to change it
// to start from another value
G4bool SetFirstNtupleColumnId(G4int firstId);
G4int GetFirstNtupleColumnId() const;
virtual G4bool SetFirstNtupleColumnId(G4int firstId) = 0;
virtual G4int GetFirstNtupleColumnId() const = 0;
// Methods to fill ntuples
// Methods for ntuple with id = FirstNtupleId
@@ -90,6 +90,7 @@ class G4VNtupleManager : public G4BaseAnalysisManager
virtual G4bool FillNtupleDColumn(G4int id, G4double value) = 0;
virtual G4bool FillNtupleSColumn(G4int id, const G4String& value) = 0;
virtual G4bool AddNtupleRow() = 0;
// Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) = 0;
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) = 0;
@@ -105,16 +106,8 @@ class G4VNtupleManager : public G4BaseAnalysisManager
// Access methods
virtual G4int GetNofNtuples() const = 0;
protected:
G4int fFirstNtupleColumnId;
G4bool fLockFirstNtupleColumnId;
virtual G4int GetNofNtupleBookings() const = 0;
};
// inline functions
inline G4int G4VNtupleManager::GetFirstNtupleColumnId() const {
return fFirstNtupleColumnId;
}
#endif
@@ -25,8 +25,7 @@
//
// $Id: G4VRNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Base class for read Ntuple manager.
// It defines functions independent from the output type.
// The pure abstract base class for read Ntuple manager.
//
// Author: Ivana Hrivnacova, 09/04/2014 (ivana@ipno.in2p3.fr)
@@ -45,9 +44,9 @@ class G4VRNtupleManager : public G4BaseAnalysisManager
friend class G4VAnalysisReader;
public:
explicit G4VRNtupleManager(const G4AnalysisManagerState& state)
explicit G4VRNtupleManager(const G4AnalysisManagerState& state)
: G4BaseAnalysisManager(state) {}
virtual ~G4VRNtupleManager(){}
virtual ~G4VRNtupleManager() {}
// deleted copy constructor & assignment operator
G4VRNtupleManager(const G4VRNtupleManager& rhs) = delete;
@@ -59,9 +58,9 @@ class G4VRNtupleManager : public G4BaseAnalysisManager
virtual G4bool SetNtupleIColumn(const G4String& columnName,
G4int& value) = 0;
virtual G4bool SetNtupleFColumn(const G4String& columnName,
G4float& value)= 0;
G4float& value) = 0;
virtual G4bool SetNtupleDColumn(const G4String& columnName,
G4double& value)= 0;
G4double& value) = 0;
virtual G4bool SetNtupleSColumn(const G4String& columnName,
G4String& value) = 0;
// Bind the ntuple columns of vector type
@@ -87,11 +86,11 @@ class G4VRNtupleManager : public G4BaseAnalysisManager
std::vector<G4float>& vector) = 0;
virtual G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
std::vector<G4double>& vector) = 0;
virtual G4bool GetNtupleRow()= 0;
virtual G4bool GetNtupleRow() = 0;
virtual G4bool GetNtupleRow(G4int ntupleId) = 0;
// Access methods
virtual G4int GetNofNtuples() const { return 0; }
virtual G4int GetNofNtuples() const = 0;
};
#endif