Import Geant4 10.3.0 source tree
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4RootAnalysisManager.hh 92972 2015-09-23 14:36:03Z gcosmo $
|
||||
// $Id: G4RootAnalysisManager.hh 100648 2016-10-31 10:06:45Z gcosmo $
|
||||
|
||||
// The main manager for Root analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
@@ -43,6 +43,8 @@
|
||||
|
||||
class G4RootFileManager;
|
||||
class G4RootNtupleManager;
|
||||
class G4RootMainNtupleManager;
|
||||
class G4RootPNtupleManager;
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
@@ -50,6 +52,12 @@ class directory;
|
||||
}
|
||||
}
|
||||
|
||||
enum class G4NtupleMergeMode {
|
||||
kNone,
|
||||
kMain,
|
||||
kSlave
|
||||
};
|
||||
|
||||
class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
public:
|
||||
@@ -69,7 +77,12 @@ class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
std::vector<tools::wroot::ntuple*>::iterator EndNtuple();
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator BeginConstNtuple() const;
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator EndConstNtuple() const;
|
||||
|
||||
|
||||
// MT/MPI
|
||||
void SetNtupleMerging(G4bool mergeNtuples,
|
||||
G4int nofReducedNtupleFiles = 0,
|
||||
unsigned int basketSize = fgkDefaultBasketSize);
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) final;
|
||||
@@ -78,11 +91,19 @@ class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
|
||||
private:
|
||||
// constants
|
||||
static constexpr unsigned int fgkDefaultBasketSize = 32000;
|
||||
|
||||
// static data members
|
||||
static G4RootAnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4RootAnalysisManager* fgInstance;
|
||||
|
||||
// methods
|
||||
void SetNtupleMergingMode(G4bool mergeNtuples, G4int nofNtupleFiles);
|
||||
void ClearNtupleManagers();
|
||||
void CreateNtupleManagers();
|
||||
G4int GetNtupleFileNumber();
|
||||
|
||||
template <typename T>
|
||||
G4bool WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
@@ -93,11 +114,15 @@ class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
G4bool WriteH3();
|
||||
G4bool WriteP1();
|
||||
G4bool WriteP2();
|
||||
G4bool WriteNtuple();
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4RootNtupleManager* fNtupleManager;
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
// data members
|
||||
G4int fNofNtupleFiles;
|
||||
G4NtupleMergeMode fNtupleMergeMode;
|
||||
G4RootNtupleManager* fNtupleManager;
|
||||
G4RootPNtupleManager* fSlaveNtupleManager;
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
};
|
||||
|
||||
#include "G4RootAnalysisManager.icc"
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "G4VFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace tools {
|
||||
@@ -59,24 +59,51 @@ class G4RootFileManager : public G4VFileManager
|
||||
G4bool CreateHistoDirectory();
|
||||
G4bool CreateNtupleDirectory();
|
||||
|
||||
// Set methods
|
||||
void SetNofNtupleFiles(G4int nofFiles);
|
||||
void SetBasketSize(unsigned int basketSize);
|
||||
|
||||
// Get methods
|
||||
tools::wroot::directory* GetHistoDirectory() const;
|
||||
tools::wroot::directory* GetNtupleDirectory() const;
|
||||
std::shared_ptr<tools::wroot::file> GetNtupleFile(G4int index) const;
|
||||
tools::wroot::directory* GetMainNtupleDirectory(G4int index) const;
|
||||
unsigned int GetBasketSize() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
G4bool OpenNtupleFiles();
|
||||
G4bool WriteFile(std::shared_ptr<tools::wroot::file> rfile,
|
||||
const G4String& fileName);
|
||||
G4bool CloseFile(std::shared_ptr<tools::wroot::file> rfile,
|
||||
const G4String& fileName);
|
||||
|
||||
// data members
|
||||
std::unique_ptr<tools::wroot::file> fFile;
|
||||
std::shared_ptr<tools::wroot::file> fFile;
|
||||
tools::wroot::directory* fHistoDirectory;
|
||||
tools::wroot::directory* fNtupleDirectory;
|
||||
G4int fNofNtupleFiles;
|
||||
std::vector<std::shared_ptr<tools::wroot::file> > fNtupleFiles;
|
||||
std::vector<tools::wroot::directory*> fMainNtupleDirectories;
|
||||
unsigned int fBasketSize;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void G4RootFileManager::SetNofNtupleFiles(G4int nofFiles)
|
||||
{ fNofNtupleFiles = nofFiles; }
|
||||
|
||||
inline void G4RootFileManager::SetBasketSize(unsigned int basketSize)
|
||||
{ fBasketSize = basketSize; }
|
||||
|
||||
inline tools::wroot::directory* G4RootFileManager::GetHistoDirectory() const
|
||||
{ return fHistoDirectory; }
|
||||
|
||||
inline tools::wroot::directory* G4RootFileManager::GetNtupleDirectory() const
|
||||
{ return fNtupleDirectory; }
|
||||
|
||||
inline unsigned int G4RootFileManager::GetBasketSize() const
|
||||
{ return fBasketSize; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 for Root main ntuple management.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4RootMainNtupleManager_h
|
||||
#define G4RootMainNtupleManager_h 1
|
||||
|
||||
#include "G4BaseAnalysisManager.hh"
|
||||
#include "G4TNtupleDescription.hh"
|
||||
#include "G4RootNtupleManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class G4RootNtupleManager;
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class file;
|
||||
class ntuple;
|
||||
}
|
||||
}
|
||||
|
||||
class G4RootMainNtupleManager : public G4BaseAnalysisManager
|
||||
{
|
||||
friend class G4RootPNtupleManager;
|
||||
friend class G4RootNtupleManager;
|
||||
|
||||
public:
|
||||
explicit G4RootMainNtupleManager(G4RootNtupleManager* ntupleBuilder,
|
||||
const G4AnalysisManagerState& state);
|
||||
~G4RootMainNtupleManager();
|
||||
|
||||
protected:
|
||||
// Types alias
|
||||
using NtupleType = tools::wroot::ntuple;
|
||||
using NtupleDescriptionType = G4TNtupleDescription<NtupleType>;
|
||||
|
||||
// Methods to manipulate ntuples
|
||||
void CreateNtuple(const tools::ntuple_booking& ntupleBooking, G4bool warn = true);
|
||||
void CreateNtuplesFromBooking();
|
||||
G4bool Merge();
|
||||
G4bool Reset(G4bool deleteNtuple);
|
||||
|
||||
// Set methods
|
||||
void SetNtupleFile(std::shared_ptr<tools::wroot::file> rfile);
|
||||
void SetNtupleDirectory(tools::wroot::directory* directory);
|
||||
std::shared_ptr<tools::wroot::file> GetNtupleFile() const;
|
||||
tools::wroot::directory* GetNtupleDirectory() const;
|
||||
|
||||
// Access functions
|
||||
const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector()
|
||||
{ return fNtupleBuilder->GetNtupleDescriptionVector(); }
|
||||
const std::vector<tools::wroot::ntuple*>& GetNtupleVector()
|
||||
{ return fNtupleVector; }
|
||||
unsigned int GetBasketSize() const;
|
||||
|
||||
private:
|
||||
// Data members
|
||||
G4RootNtupleManager* fNtupleBuilder;
|
||||
std::shared_ptr<tools::wroot::file> fNtupleFile;
|
||||
tools::wroot::directory* fNtupleDirectory;
|
||||
std::vector<tools::wroot::ntuple*> fNtupleVector;
|
||||
};
|
||||
|
||||
inline void G4RootMainNtupleManager::SetNtupleFile(std::shared_ptr<tools::wroot::file> rfile)
|
||||
{ fNtupleFile = rfile; }
|
||||
|
||||
inline void G4RootMainNtupleManager::SetNtupleDirectory(tools::wroot::directory* directory)
|
||||
{ fNtupleDirectory = directory; }
|
||||
|
||||
inline std::shared_ptr<tools::wroot::file> G4RootMainNtupleManager::GetNtupleFile() const
|
||||
{ return fNtupleFile; }
|
||||
|
||||
inline tools::wroot::directory* G4RootMainNtupleManager::GetNtupleDirectory() const
|
||||
{ return fNtupleDirectory; }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
#include "tools/wroot/ntuple"
|
||||
|
||||
class G4RootMainNtupleManager;
|
||||
class G4RootFileManager;
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
@@ -45,6 +47,14 @@ class directory;
|
||||
}
|
||||
}
|
||||
|
||||
enum class G4NtupleCreateMode {
|
||||
kNoMergeBeforeOpen,
|
||||
kNoMergeAfterOpen,
|
||||
kMainBeforeOpen,
|
||||
kMainAfterOpen,
|
||||
kUndefined
|
||||
};
|
||||
|
||||
// template specializations used by this class defined below
|
||||
|
||||
template <>
|
||||
@@ -62,9 +72,11 @@ G4bool G4TNtupleManager<tools::wroot::ntuple>::FillNtupleTColumn(
|
||||
class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple>
|
||||
{
|
||||
friend class G4RootAnalysisManager;
|
||||
friend class G4RootMainNtupleManager;
|
||||
|
||||
public:
|
||||
explicit G4RootNtupleManager(const G4AnalysisManagerState& state);
|
||||
explicit G4RootNtupleManager(const G4AnalysisManagerState& state,
|
||||
G4int nofMainManagers = 0);
|
||||
virtual ~G4RootNtupleManager();
|
||||
|
||||
private:
|
||||
@@ -75,6 +87,7 @@ class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple>
|
||||
// Functions specific to the output type
|
||||
|
||||
void SetNtupleDirectory(tools::wroot::directory* directory);
|
||||
void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
|
||||
|
||||
// Methods from the templated base class
|
||||
//
|
||||
@@ -87,9 +100,28 @@ class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple>
|
||||
virtual void FinishTNtuple(
|
||||
NtupleDescriptionType* ntupleDescription) final;
|
||||
|
||||
virtual G4bool Reset(G4bool deleteNtuple);
|
||||
|
||||
// Method for merging
|
||||
//
|
||||
G4bool Merge();
|
||||
|
||||
// Access functions
|
||||
//
|
||||
const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector() const;
|
||||
G4RootMainNtupleManager* GetMainNtupleManager(G4int index) const;
|
||||
unsigned int GetBasketSize() const;
|
||||
|
||||
// Utility functions
|
||||
//
|
||||
void SetCreateMode();
|
||||
|
||||
// data members
|
||||
//
|
||||
G4NtupleCreateMode fCreateMode;
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
tools::wroot::directory* fNtupleDirectory;
|
||||
std::vector<G4RootMainNtupleManager*> fMainNtupleManagers;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
@@ -98,6 +130,14 @@ inline void
|
||||
G4RootNtupleManager::SetNtupleDirectory(tools::wroot::directory* directory)
|
||||
{ fNtupleDirectory = directory; }
|
||||
|
||||
inline void
|
||||
G4RootNtupleManager::SetFileManager(std::shared_ptr<G4RootFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline const std::vector<G4TNtupleDescription<tools::wroot::ntuple>* >&
|
||||
G4RootNtupleManager::GetNtupleDescriptionVector() const
|
||||
{ return fNtupleDescriptionVector; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
template <>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 Root pntuple.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4RootPNtupleDescription_h
|
||||
#define G4RootPNtupleDescription_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/ntuple_booking"
|
||||
#include "tools/wroot/pntuple"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class file;
|
||||
class branch;
|
||||
}
|
||||
}
|
||||
|
||||
struct G4RootPNtupleDescription
|
||||
{
|
||||
G4RootPNtupleDescription()
|
||||
: fFile(nullptr),
|
||||
fNtuple(nullptr),
|
||||
fMainBranches(),
|
||||
fNtupleBooking(),
|
||||
fActivation(true),
|
||||
fIsNtupleOwner(true) {}
|
||||
|
||||
~G4RootPNtupleDescription()
|
||||
{
|
||||
if ( fIsNtupleOwner ) delete fNtuple;
|
||||
}
|
||||
|
||||
tools::wroot::file* fFile;
|
||||
tools::wroot::pntuple* fNtuple;
|
||||
std::vector<tools::wroot::branch*> fMainBranches;
|
||||
tools::ntuple_booking fNtupleBooking;
|
||||
G4bool fActivation;
|
||||
G4bool fIsNtupleOwner;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,353 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 for Root pntuple management.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4RootPNtupleManager_h
|
||||
#define G4RootPNtupleManager_h 1
|
||||
|
||||
#include "G4VNtupleManager.hh"
|
||||
#include "G4RootPNtupleDescription.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class G4RootMainNtupleManager;
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class file;
|
||||
class ntuple;
|
||||
class pntuple;
|
||||
}
|
||||
}
|
||||
|
||||
// Mutex implementation as in pwroot.cpp
|
||||
// with replacement tools::mutex -> G4Mutex
|
||||
|
||||
class mutex : public virtual tools::wroot::imutex {
|
||||
typedef tools::wroot::imutex parent;
|
||||
public:
|
||||
virtual bool lock() {
|
||||
// G4cout << "!!! Mutex lock" << G4endl;
|
||||
m_mutex.lock();
|
||||
return true;}
|
||||
virtual bool unlock() {
|
||||
m_mutex.unlock();
|
||||
// G4cout << "!!! Mutex unlock" << G4endl;
|
||||
return true; }
|
||||
//virtual bool trylock() {return m_mutex.trylock();}
|
||||
public:
|
||||
mutex(G4AutoLock& a_mutex):m_mutex(a_mutex){}
|
||||
virtual ~mutex(){}
|
||||
protected:
|
||||
mutex(const mutex& a_from):parent(a_from),m_mutex(a_from.m_mutex){}
|
||||
mutex& operator=(const mutex&){return *this;}
|
||||
protected:
|
||||
G4AutoLock& m_mutex;
|
||||
};
|
||||
|
||||
class G4RootPNtupleManager : public G4VNtupleManager
|
||||
{
|
||||
friend class G4RootAnalysisManager;
|
||||
|
||||
public:
|
||||
explicit G4RootPNtupleManager(G4RootMainNtupleManager* main,
|
||||
const G4AnalysisManagerState& state);
|
||||
~G4RootPNtupleManager();
|
||||
|
||||
private:
|
||||
enum class G4PNtupleCreateMode {
|
||||
kSlaveBeforeOpen,
|
||||
kSlaveAfterOpen,
|
||||
kUndefined
|
||||
};
|
||||
|
||||
// Methods to manipulate ntuples
|
||||
void CreateNtuple(G4RootPNtupleDescription* ntupleDescription,
|
||||
tools::wroot::ntuple* mainNtuple);
|
||||
void CreateNtuplesFromMain();
|
||||
|
||||
// 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) override;
|
||||
virtual G4int CreateNtupleFColumn(
|
||||
const G4String& name, std::vector<float>* vector) override;
|
||||
virtual G4int CreateNtupleDColumn(
|
||||
const G4String& name, std::vector<double>* vector) override;
|
||||
virtual G4int CreateNtupleSColumn(const G4String& name) override;
|
||||
virtual void FinishNtuple() override;
|
||||
// Create columns in the ntuple with given id
|
||||
virtual G4int CreateNtupleIColumn(G4int ntupleId,
|
||||
const G4String& name, std::vector<int>* vector) override;
|
||||
virtual G4int CreateNtupleFColumn(G4int ntupleId,
|
||||
const G4String& name, std::vector<float>* vector) override;
|
||||
virtual G4int CreateNtupleDColumn(G4int ntupleId,
|
||||
const G4String& name, std::vector<double>* vector) override;
|
||||
virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) override;
|
||||
virtual void FinishNtuple(G4int ntupleId) override;
|
||||
|
||||
// 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 (when more ntuples exist)
|
||||
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
|
||||
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
|
||||
virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final;
|
||||
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
|
||||
const G4String& value) final;
|
||||
virtual G4bool AddNtupleRow(G4int ntupleId) final;
|
||||
virtual G4bool Merge() final;
|
||||
|
||||
// Reset
|
||||
virtual G4bool Reset(G4bool deleteNtuple) final;
|
||||
|
||||
// Activation option
|
||||
//
|
||||
virtual void SetActivation(G4bool activation) final;
|
||||
virtual void SetActivation(G4int ntupleId, G4bool activation) final;
|
||||
virtual G4bool GetActivation(G4int ntupleId) const final;
|
||||
virtual G4bool IsEmpty() const final;
|
||||
|
||||
// Access methods
|
||||
virtual G4int GetNofNtuples() const final;
|
||||
|
||||
private:
|
||||
G4RootPNtupleDescription*
|
||||
GetNtupleDescriptionInFunction(G4int id, G4String function, G4bool warn = true) const;
|
||||
tools::wroot::pntuple*
|
||||
GetNtupleInFunction(G4int id, G4String function, G4bool warn = true) const;
|
||||
tools::wroot::ntuple*
|
||||
GetMainNtupleInFunction(G4int id, G4String function, G4bool warn = true) const;
|
||||
|
||||
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);
|
||||
|
||||
// Data members
|
||||
G4PNtupleCreateMode fCreateMode;
|
||||
G4RootMainNtupleManager* fMainNtupleManager;
|
||||
std::vector<G4RootPNtupleDescription*> fNtupleDescriptionVector;
|
||||
std::vector<tools::wroot::pntuple*> fNtupleVector;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4int G4RootPNtupleManager::CreateNtupleTColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<T>* vector)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("create", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "CreateNtupleTColumn");
|
||||
if ( ! ntupleDescription ) return G4Analysis::kInvalidId;
|
||||
|
||||
// Save column info in booking
|
||||
auto& ntupleBooking = ntupleDescription->fNtupleBooking;
|
||||
auto index = ntupleBooking.columns().size();
|
||||
if ( ! vector )
|
||||
ntupleBooking.template add_column<T>(name);
|
||||
else
|
||||
ntupleBooking.template add_column<T>(name, *vector);
|
||||
|
||||
fLockFirstNtupleColumnId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL2()->Message("create", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return index + fFirstNtupleColumnId;
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4int G4RootPNtupleManager::CreateNtupleTColumn(
|
||||
const G4String& name, std::vector<T>* vector)
|
||||
{
|
||||
auto ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
|
||||
return CreateNtupleTColumn<T>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const std::string& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4RootNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
auto column = dynamic_cast<tools::wroot::pntuple::column_string* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4RootNtupleManager:FillNtupleColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("done fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const T& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
// get ntuple
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
// 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);
|
||||
return false;
|
||||
}
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
|
||||
// get column and check its type
|
||||
auto column = dynamic_cast<tools::wroot::pntuple::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);
|
||||
return false;
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("done fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4RootPNtupleManager::FillNtupleTColumn(G4int columnId, const T& value) {
|
||||
return FillNtupleTColumn(0, columnId, value);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user