Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -2,7 +2,6 @@
|
||||
|
||||
if(GEANT4_USE_FREETYPE)
|
||||
add_definitions(-DTOOLS_USE_FREETYPE)
|
||||
add_definitions(-DTOOLS_USE_EXPAT)
|
||||
endif()
|
||||
|
||||
set(G4analysis_COMPONENTS
|
||||
|
||||
@@ -16,6 +16,188 @@ committal in the SVN repository !
|
||||
* Reverse chronological order (last date on top), please *
|
||||
----------------------------------------------------------
|
||||
|
||||
November 15, 2021 I. Hrivnacova (analysis-V10-07-30)
|
||||
- Fixed remaining Coverity issues
|
||||
|
||||
November 15, 2021 I. Hrivnacova (analysis-V10-07-29)
|
||||
- Fixed Coverity issues
|
||||
|
||||
November 09, 2021 I. Hrivnacova (analysis-V10-07-28)
|
||||
- Fix in G4MPIToolsManager: do not call Receive() twice
|
||||
|
||||
November 05, 2021 I. Hrivnacova (analysis-V10-07-27)
|
||||
- Added new public function G4VAnalysisManager::Clear()
|
||||
that deletes all allocated analysis objects and clears
|
||||
their collections.
|
||||
This function should be used as a replacement for deleting
|
||||
the analysis manager in the applications that allocate the
|
||||
analysis data in begin of run and deleted the analysis
|
||||
manager in end of run.
|
||||
- Minor code clean-up
|
||||
|
||||
November 04, 2021 I. Hrivnacova (analysis-V10-07-26)
|
||||
- Renamed G4VAnalysisReader::ReadNtuple(const G4String&)
|
||||
back in GetNtuple. Cannot reproduce the ambiguity error
|
||||
with GetNtuple(G4int).
|
||||
|
||||
October 28, 2021 I. Hrivnacova (analysis-V10-07-25)
|
||||
- Moved data members initialization in header files;
|
||||
added deleted default constructor where appropriate,
|
||||
added explicit keyword to one argument construtors where
|
||||
missing
|
||||
- Use brace data members initialization everywhere
|
||||
- Implemented missing WriteOnAscii() - for h2,h3,p1,p2
|
||||
- Use fonts from tools in G4PlotManager.cc
|
||||
- Removed CMake -DTOOLS_USE_EXPAT definition (not needed)
|
||||
- Added G4ToolsAnalysisMessenger that implements "get" commands
|
||||
/analysis/hn|pn/get id
|
||||
|
||||
October 27, 2021 B.Morgan (analysis-V10-07-24)
|
||||
- Use G4StrUtil functions replacing deprecated G4String member functions
|
||||
|
||||
October 26, 2021 I. Hrivnacova (analysis-V10-07-23)
|
||||
- Fixed G4*RFileManager destructors;
|
||||
thanks to B. Morgan for spotting this bug
|
||||
|
||||
October 25, 2021 I. Hrivnacova (analysis-V10-07-22)
|
||||
- Added public function G4VAnalysisManager::Reset()
|
||||
- Needed when calling files are closed without reset
|
||||
by calling analysisManager->CloseFile(false)
|
||||
(see B5 example with interactive plotting)
|
||||
- Minor fixes:
|
||||
- Do not issue same log messages from generic analysis manager
|
||||
and generic file manager
|
||||
- Do not call SetIsEmpty() twice in Hdf5
|
||||
|
||||
October 22, 2021 I. Hrivnacova (analysis-V10-07-21)
|
||||
- Support for ntuple columns of string vector type
|
||||
for Xml, Hdf5 output type:
|
||||
- added helper code for Xml reader, no update needed for Hdf5
|
||||
|
||||
October 19, 2021 I. Hrivnacova (analysis-V10-07-20)
|
||||
- Implemented support for file system directories with Csv output
|
||||
as proposed in [GitHub PR #32](https://github.com/Geant4/geant4/pull/32)
|
||||
- Fixed reading objects from files with directories (Root, Hdf5)
|
||||
- Implemented handling directories in Generic analysis manager
|
||||
- Clean-up in G4ToolsAnalysisManager
|
||||
- Reimplemented utility functions GetBaseName(), GetExtension() using
|
||||
<filesystem> library
|
||||
|
||||
October 6, 2021 I. Hrivnacova (analysis-V10-07-19)
|
||||
- Added new G4AnalysisManager.hh header defining
|
||||
using G4AnalysisManager = G4GenericAnalysisManager
|
||||
- Removed g4csv.hh, g4hdf5.hh, g4root.hh, g4xml.hh
|
||||
- Reduced output specific type definitions in
|
||||
g4xyz_defs.hh to ntuple end rntuple types
|
||||
- Removed g4analysis.hh with the
|
||||
G4Analysis::MasterInstance() factory method
|
||||
- Removed the default value ("root") for the default file type
|
||||
in G4GenericAnalysisManager - the default must be set by
|
||||
user if using fileNames without extensions
|
||||
- Updated exception codes and messages in accummulables
|
||||
|
||||
September 20, 2021 I. Hrivnacova (analysis-V10-07-18)
|
||||
- clang-tidy performance fixes:
|
||||
- use const auto&, std::move where appropriate
|
||||
- revisited passing by std::shared_ptr
|
||||
- clang-tidy modernize fixes:
|
||||
- use make_unique, nullptr, auto, emplace_back, using
|
||||
- use default for disabled constructors and destructors,
|
||||
delete for private member functions not implemented
|
||||
- Removed explicit for constructors with more than 1 parameters
|
||||
|
||||
September 17, 2021 I. Hrivnacova (analysis-V10-07-17)
|
||||
- Fixed evaluation of result of deleting empty file
|
||||
in G4RootAnalysisManager causing wrong warnings
|
||||
|
||||
September 3, 2021 I. Hrivnacova (analysis-V10-07-16)
|
||||
- Added support for ntuple columns of string vectors via
|
||||
new public functions in G4VAnalysisManager and G4VAnalysisReader:
|
||||
G4bool SetNtupleSColumn(const G4String& columnName,
|
||||
std::vector<std::string>& vector) final;
|
||||
G4bool SetNtupleSColumn(G4int ntupleId, const G4String& columnName,
|
||||
std::vector<std::string>& vector) = 0;
|
||||
|
||||
August 31, 2021 I. Hrivnacova (analysis-V10-07-15)
|
||||
- Code clean-up:
|
||||
- Review of static data members:
|
||||
- changed static const to static constexpr where possible
|
||||
or inline static const otherwise (for G4String)
|
||||
- declares static data members inline and moved their initialization
|
||||
in header file
|
||||
- Be consistent:
|
||||
- "" for includes from g4tools
|
||||
- "fk" prefix for class constexpr data names
|
||||
- Template argument names:
|
||||
HT, NT, FT for histogram/profile, ntuple, file types
|
||||
- Removed redundant includes of "G4Threading.hh", <iostream>
|
||||
|
||||
August 26, 2021 B. Morgan (analysis-V10-07-14)
|
||||
- Remove default: in switch for GetMergeFunction
|
||||
- Prevents accidental fall through of Windows
|
||||
|
||||
August 25, 2021 I. Hrivnacova (analysis-V10-07-13)
|
||||
- Separated Hn/Pn object file handling from output specific analysis readers
|
||||
in Hn file manager classes for reading (G4XHnRFileManager)
|
||||
- Replaced the explicit Read[Hn|Pn] functions in the analysis readers
|
||||
by a common implementation in G4ToolsAnalysisReader
|
||||
using the newly introduced Hn file manager classes for reading
|
||||
- Separated ReadNtuple functions from the analysis readers in
|
||||
the RNtuple manager classes
|
||||
- Renamed G4VAnalysisReader::GetNtuple(const G4String&) in ReadNtuple
|
||||
to avoid ambiguity with GetNtuple(G4int).
|
||||
Note that this change brings backward incompatibility.
|
||||
- Using more shared pointers
|
||||
|
||||
August 18, 2021 I. Hrivnacova (analysis-V10-07-12)
|
||||
- Simplified verbosity messages
|
||||
- Plus more simplifications in Warn calls
|
||||
- Separated inline functions from G4MPIToolsManager.hh
|
||||
to new .icc
|
||||
|
||||
August 16, 2021 I. Hrivnacova (analysis-V10-07-11)
|
||||
- Simplified calls to G4Exceptions:
|
||||
- Added G4Analysis::Warn() and changed the calls to G4Exception in
|
||||
all analysis classes (except accummulables)
|
||||
- Reduced exception classification to
|
||||
Analysis_F001: Fatal exceptions - all fatal exception
|
||||
Analysis_W001: Warnings - all warnings
|
||||
- Replaced some constants with constexpr
|
||||
|
||||
August 12, 2021 I. Hrivnacova (analysis-V10-07-10)
|
||||
- Replaced the explicit Write[Hn|Pn] functions in the analysis managers
|
||||
by a common implementation in G4ToolsAnalysisManager::WriteImpl() and Merge()
|
||||
using the new Hn file manager classes introduced for the generic file manager
|
||||
last year.
|
||||
The same code is now used for writing histograms/profiles by specific analysis managers and the generic analysis manager.
|
||||
- Added new G4ToolsAnalysisManager::IsEmpty() function
|
||||
- Removed trailing whitespaces
|
||||
|
||||
August 6, 2021 I. Hrivnacova (analysis-V10-07-09)
|
||||
- Added new G4VAnalysisReader public function
|
||||
G4bool CloseFiles(G4bool reset = true);
|
||||
to be called by user before the end of program
|
||||
and its implementation for all readers.
|
||||
This prevents from errors in the Hdf5 read test
|
||||
after migration of the readers to G4ThreadLocalSingleton.
|
||||
|
||||
July 19, 2021 I. Hrivnacova (analysis-V10-07-08)
|
||||
- Migration to G4ThreadLocalSingleton:
|
||||
in all specific analysis manager and reader classes.
|
||||
After this migration the singleton instances are deletes
|
||||
by the Geant4 kernel, that's why their deleting has to be
|
||||
removed from the client code.
|
||||
- Removed isMaster argument from managers/reders constructors,
|
||||
and retrieve this info from G4Threading where needed.
|
||||
|
||||
July 15, 2021 I. Hrivnacova (analysis-V10-07-07)
|
||||
- Replaced G4Analysis::make_unique with std::make_unique
|
||||
- Using [[maybe_unused]] where appropriate
|
||||
|
||||
June 29, 2021 G. Cosmo (analysis-V10-07-06)
|
||||
- Fixed compilation errors in G4CsvAnalysisReader and G4XmlAnalysisReader
|
||||
occurring with c++20 enabled.
|
||||
|
||||
May 25, 2021 B. Morgan (analysis-V10-07-05)
|
||||
- Move fonts/ directory and install logic to g4tools external, as prime interface
|
||||
to Freetype.
|
||||
|
||||
@@ -40,16 +40,18 @@ template <typename T>
|
||||
class G4Accumulable : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
G4Accumulable(const G4String& name, T initValue,
|
||||
G4Accumulable(const G4String& name, T initValue,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4Accumulable(T initValue,
|
||||
G4Accumulable(T initValue,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4Accumulable(const G4Accumulable& rhs);
|
||||
G4Accumulable(G4Accumulable&& rhs);
|
||||
G4Accumulable() = delete;
|
||||
virtual ~G4Accumulable();
|
||||
virtual ~G4Accumulable() = default;
|
||||
|
||||
// operators
|
||||
// Operators
|
||||
G4Accumulable<T>& operator= (const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T>& operator= (G4Accumulable<T>&& rhs);
|
||||
G4Accumulable<T>& operator+=(const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T>& operator*=(const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T> operator++(int); // postfix increment
|
||||
@@ -59,16 +61,16 @@ class G4Accumulable : public G4VAccumulable
|
||||
G4Accumulable<T>& operator+=(const T& rhs);
|
||||
G4Accumulable<T>& operator*=(const T& rhs);
|
||||
|
||||
// methods
|
||||
// Methods
|
||||
virtual void Merge(const G4VAccumulable& other) final;
|
||||
virtual void Reset() final;
|
||||
|
||||
// get methods
|
||||
// Get methods
|
||||
T GetValue() const;
|
||||
G4MergeMode GetMergeMode() const;
|
||||
|
||||
private:
|
||||
// data members
|
||||
// Data members
|
||||
T fValue;
|
||||
T fInitValue;
|
||||
G4MergeMode fMergeMode;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
using namespace G4Accumulables;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name),
|
||||
fValue(initValue),
|
||||
@@ -45,7 +45,7 @@ G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode m
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(),
|
||||
fValue(initValue),
|
||||
@@ -55,7 +55,7 @@ G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
|
||||
: G4VAccumulable(rhs),
|
||||
fValue(rhs.fValue),
|
||||
@@ -65,12 +65,17 @@ G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::~G4Accumulable()
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(G4Accumulable&& rhs)
|
||||
: G4VAccumulable(rhs),
|
||||
fValue(std::move(rhs.fValue)),
|
||||
fInitValue(std::move(rhs.fInitValue)),
|
||||
fMergeMode(rhs.fMergeMode),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
@@ -90,7 +95,27 @@ G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(G4Accumulable<T>&& rhs)
|
||||
{
|
||||
// check assignment to self
|
||||
if (this == &rhs) return *this;
|
||||
|
||||
// base class assignment
|
||||
G4VAccumulable::operator=(rhs);
|
||||
|
||||
// this class data assignment
|
||||
fValue = std::move(rhs.fValue);
|
||||
fInitValue = std::move(rhs.fInitValue);
|
||||
fMergeMode = rhs.fMergeMode;
|
||||
fMergeFunction = rhs.fMergeFunction;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
@@ -100,7 +125,7 @@ G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
@@ -110,7 +135,7 @@ G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(const T& value)
|
||||
{
|
||||
@@ -120,7 +145,7 @@ G4Accumulable<T>::operator=(const T& value)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator+=(const T& value)
|
||||
{
|
||||
@@ -130,7 +155,7 @@ G4Accumulable<T>::operator+=(const T& value)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator*=(const T& value)
|
||||
{
|
||||
@@ -140,18 +165,18 @@ G4Accumulable<T>::operator*=(const T& value)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>
|
||||
G4Accumulable<T>::operator++(int)
|
||||
{
|
||||
// postfix increment
|
||||
G4Accumulable<T> temp = *this;
|
||||
fValue++;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator++()
|
||||
{
|
||||
@@ -161,7 +186,7 @@ G4Accumulable<T>::operator++()
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
void G4Accumulable<T>::Merge(const G4VAccumulable& other)
|
||||
{
|
||||
// G4cout << "Merging other: " << other.GetName() << " " << static_cast<const G4Accumulable<T>&>(other).fValue << G4endl;
|
||||
@@ -171,14 +196,14 @@ void G4Accumulable<T>::Merge(const G4VAccumulable& other)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
void G4Accumulable<T>::Reset()
|
||||
{
|
||||
fValue = fInitValue;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
T G4Accumulable<T>::GetValue() const
|
||||
{
|
||||
return fValue;
|
||||
|
||||
@@ -37,51 +37,56 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class G4AccumulableManager;
|
||||
class G4AnalysisManagerState;
|
||||
class G4VAccumulable;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4AccumulableManager
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4AccumulableManager>;
|
||||
|
||||
public:
|
||||
virtual ~G4AccumulableManager();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4AccumulableManager* Instance();
|
||||
|
||||
|
||||
// Methods
|
||||
|
||||
// Create accumulables
|
||||
//
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(const G4String& name, T value,
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(const G4String& name, T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(T value,
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Register existing accumulables
|
||||
//
|
||||
//
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4bool RegisterAccumulable(G4Accumulable<T>& accumulable);
|
||||
// user defined accumulable
|
||||
G4bool RegisterAccumulable(G4VAccumulable* accumulable);
|
||||
|
||||
// Access registered accumulables
|
||||
//
|
||||
//
|
||||
// Via name
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
|
||||
// user defined accumulable
|
||||
G4VAccumulable* GetAccumulable(const G4String& name, G4bool warn = true) const;
|
||||
|
||||
// Via id (in the order of registering)
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
// user defined accumulable
|
||||
G4VAccumulable* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
@@ -98,26 +103,25 @@ class G4AccumulableManager
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
// hide ctor requiring master/worker specification
|
||||
G4AccumulableManager(G4bool isMaster);
|
||||
// Hide singleton ctor
|
||||
G4AccumulableManager();
|
||||
|
||||
// metods
|
||||
// Methods
|
||||
// Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
|
||||
G4String GenerateName() const;
|
||||
// Check if a name is already used in a map and print a warning
|
||||
// Check if a name is already used in a map and print a warning
|
||||
G4bool CheckName(const G4String& name, const G4String& where) const;
|
||||
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
|
||||
|
||||
// constants
|
||||
// Constants
|
||||
const G4String kBaseName = "accumulable";
|
||||
|
||||
// static data members
|
||||
static G4AccumulableManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4AccumulableManager* fgInstance;
|
||||
// Static data members
|
||||
inline static G4AccumulableManager* fgMasterInstance { nullptr };
|
||||
|
||||
// data members
|
||||
// Data members
|
||||
std::vector<G4VAccumulable*> fVector;
|
||||
std::map<G4String, G4VAccumulable*> fMap;
|
||||
std::vector<G4VAccumulable*> fAccumulablesToDelete;
|
||||
|
||||
@@ -25,21 +25,21 @@
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const
|
||||
{
|
||||
// Do not check type if nullptr
|
||||
if ( ! accumulable ) return nullptr;
|
||||
|
||||
// check type
|
||||
G4Accumulable<T>* taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable);
|
||||
auto taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable);
|
||||
if ( ! taccumulable && warn ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Accumulable " << accumulable->GetName()
|
||||
description << " " << "Accumulable " << accumulable->GetName()
|
||||
<< " has different type";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable<T>",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Exception("G4AccumulableManager::GetAccumulable<T>",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) c
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::CreateAccumulable(
|
||||
const G4String& name, T value, G4MergeMode mergeMode)
|
||||
{
|
||||
// do not accept name if it is already used
|
||||
if ( ! CheckName(name, "CreateAccumulable") ) return 0;
|
||||
if ( ! CheckName(name, "CreateAccumulable") ) return 0;
|
||||
|
||||
// create accumulable
|
||||
auto accumulable = new G4Accumulable<T>(name, value, mergeMode);
|
||||
@@ -66,8 +66,8 @@ G4AccumulableManager::CreateAccumulable(
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::CreateAccumulable(
|
||||
T value, G4MergeMode mergeMode)
|
||||
{
|
||||
@@ -75,15 +75,15 @@ G4AccumulableManager::CreateAccumulable(
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4bool G4AccumulableManager::RegisterAccumulable(G4Accumulable<T>& accumulable)
|
||||
{
|
||||
return RegisterAccumulable(&accumulable);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
@@ -92,8 +92,8 @@ G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
@@ -120,14 +120,14 @@ inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End()
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
G4AccumulableManager::BeginConst() const
|
||||
{
|
||||
return fVector.begin();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
G4AccumulableManager::EndConst() const
|
||||
{
|
||||
return fVector.end();
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#define G4MergeMode_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4Exception.hh"
|
||||
|
||||
#include <functional>
|
||||
#include <cmath>
|
||||
@@ -41,7 +42,7 @@ enum class G4MergeMode {
|
||||
kMultiplication, // "And" if boolean type
|
||||
kMaximum, // "Or" if boolean type
|
||||
kMinimum // "And" if boolean type
|
||||
};
|
||||
};
|
||||
|
||||
// Generic merge function
|
||||
template <typename T>
|
||||
@@ -62,7 +63,7 @@ G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode)
|
||||
|
||||
case G4MergeMode::kMultiplication:
|
||||
return [](const T& x, const T& y) { return x * y; };
|
||||
|
||||
|
||||
case G4MergeMode::kMaximum:
|
||||
// return std::bind([](const T& x, const T& y) { return std::max(x,y);});
|
||||
return [](const T& x, const T& y) { return std::max(x,y); };
|
||||
@@ -70,10 +71,13 @@ G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode)
|
||||
case G4MergeMode::kMinimum:
|
||||
// return std::bind([](const T& x, const T& y) { return std::min(x,y);});
|
||||
return [](const T& x, const T& y) { return std::min(x,y); };
|
||||
|
||||
default:
|
||||
return [](const T&, const T&) { return 0.0; };
|
||||
}
|
||||
|
||||
// Must never get here, but we need a return to satisfy MSVC
|
||||
G4Exception("G4Accumulables::GetMergeFunction<T>",
|
||||
"Analysis_F001", FatalException,
|
||||
"Undefined merge mode");
|
||||
return [](const T&, const T&) { return T(); };
|
||||
}
|
||||
|
||||
template <G4bool>
|
||||
|
||||
@@ -41,17 +41,19 @@ class G4VAccumulable
|
||||
|
||||
public:
|
||||
G4VAccumulable(const G4String& name = "");
|
||||
G4VAccumulable(const G4VAccumulable& rhs);
|
||||
virtual ~G4VAccumulable() {}
|
||||
G4VAccumulable(const G4VAccumulable& rhs) = default;
|
||||
G4VAccumulable(G4VAccumulable&& rhs) = default;
|
||||
virtual ~G4VAccumulable() = default;
|
||||
|
||||
// operators
|
||||
G4VAccumulable& operator=(const G4VAccumulable& rhs);
|
||||
// Operators
|
||||
G4VAccumulable& operator=(const G4VAccumulable& rhs) = default;
|
||||
G4VAccumulable& operator=(G4VAccumulable&& rhs) = default;
|
||||
|
||||
// methods
|
||||
// Methods
|
||||
virtual void Merge(const G4VAccumulable& other) = 0;
|
||||
virtual void Reset() = 0;
|
||||
|
||||
// get methods
|
||||
// Get methods
|
||||
G4String GetName() const;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -29,21 +29,8 @@ inline G4VAccumulable::G4VAccumulable(const G4String& name)
|
||||
: fName(name)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable::G4VAccumulable(const G4VAccumulable& rhs)
|
||||
: fName(rhs.fName)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable& G4VAccumulable::operator=(const G4VAccumulable& rhs)
|
||||
{
|
||||
fName = rhs.fName;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4String G4VAccumulable::GetName() const
|
||||
{
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AccumulableManager.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
@@ -37,36 +38,17 @@ namespace {
|
||||
G4Mutex mergeMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4AccumulableManager* G4AccumulableManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4AccumulableManager* G4AccumulableManager::fgInstance = nullptr;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4AccumulableManager* G4AccumulableManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4AccumulableManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
static G4ThreadLocalSingleton<G4AccumulableManager> instance;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4AccumulableManager::G4AccumulableManager(G4bool isMaster)
|
||||
: fVector(),
|
||||
fMap()
|
||||
G4AccumulableManager::G4AccumulableManager()
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4AccumulableAnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4AccumulableAnalysisManager::G4AccumulableAnalysisManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -97,13 +79,13 @@ G4String G4AccumulableManager::GenerateName() const
|
||||
G4bool G4AccumulableManager::CheckName(const G4String& name, const G4String& where) const
|
||||
{
|
||||
if ( fMap.find(name) == fMap.end() ) return true;
|
||||
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Name " << name << " is already used." << G4endl;
|
||||
description << " " << "Parameter will be not created/registered.";
|
||||
description << "Name " << name << " is already used." << G4endl;
|
||||
description << "Parameter will be not created/registered.";
|
||||
G4String method("G4AccumulableManager::");
|
||||
method.append(where);
|
||||
G4Exception(method, "Analysis_W002", JustWarning, description);
|
||||
G4Exception(method, "Analysis_W001", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -115,9 +97,9 @@ G4bool G4AccumulableManager::CheckName(const G4String& name, const G4String& whe
|
||||
G4bool G4AccumulableManager::RegisterAccumulable(G4VAccumulable* accumulable)
|
||||
{
|
||||
auto name = accumulable->GetName();
|
||||
|
||||
|
||||
// do not accept name if it is already used
|
||||
if ( ! CheckName(name, "RegisterAccumulable") ) return false;
|
||||
if ( ! CheckName(name, "RegisterAccumulable") ) return false;
|
||||
|
||||
// generate name if empty
|
||||
if ( ! name.length() ) {
|
||||
@@ -131,7 +113,7 @@ G4bool G4AccumulableManager::RegisterAccumulable(G4VAccumulable* accumulable)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VAccumulable*
|
||||
G4VAccumulable*
|
||||
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
@@ -139,9 +121,9 @@ G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
if ( it == fMap.end() ) {
|
||||
if ( warn) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "accumulable " << name << " does not exist.";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
description << "Accumulable " << name << " does not exist.";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -150,16 +132,16 @@ G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VAccumulable*
|
||||
G4VAccumulable*
|
||||
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the vector
|
||||
if ( id < 0 || id >= G4int(fVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "accumulable " << id << " does not exist.";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
description << "Accumulable " << id << " does not exist.";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -168,7 +150,7 @@ G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4AccumulableManager::Merge()
|
||||
void G4AccumulableManager::Merge()
|
||||
{
|
||||
// Do nothing if there are no accumulables registered
|
||||
// or if master thread
|
||||
@@ -177,18 +159,17 @@ void G4AccumulableManager::Merge()
|
||||
// The manager on mastter must exist
|
||||
if ( ! fgMasterInstance ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "No master G4AccumulableManager instance exists."
|
||||
<< G4endl
|
||||
<< " " << "Accumulables will not be merged.";
|
||||
description
|
||||
<< "No master G4AccumulableManager instance exists." << G4endl
|
||||
<< "Accumulables will not be merged.";
|
||||
G4Exception("G4AccumulableManager::Merge()",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
// The worker manager just merges its accumulables to the master
|
||||
// This operation needs a lock
|
||||
// G4cout << "Go to merge accumulables" << G4endl;
|
||||
// G4cout << "Go to merge accumulables" << G4endl;
|
||||
G4AutoLock lock(&mergeMutex);
|
||||
|
||||
// the other manager has the vector with the "same" accumulables
|
||||
@@ -198,7 +179,7 @@ void G4AccumulableManager::Merge()
|
||||
// G4VAccumulable* accumulable = *(it++);
|
||||
// masterAccumulable->Merge(*(accumulable));
|
||||
itMaster->Merge(*(*(it++)));
|
||||
}
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@@ -206,10 +187,10 @@ void G4AccumulableManager::Merge()
|
||||
void G4AccumulableManager::Reset()
|
||||
{
|
||||
// Reset histograms and profiles
|
||||
|
||||
|
||||
for ( auto it : fVector ) {
|
||||
it->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,12 +37,12 @@ G4MergeMode GetMergeMode(const G4String& mergeModeName) {
|
||||
else if ( mergeModeName == "*" ) { return G4MergeMode::kMultiplication; }
|
||||
else {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " \"" << mergeModeName << "\" merge mode is not supported." << G4endl
|
||||
<< " " << "Addition will be applied.";
|
||||
description
|
||||
<< "\"" << mergeModeName << "\" merge mode is not supported." << G4endl
|
||||
<< "Addition will be applied.";
|
||||
G4Exception("G4Analysis::GetMergeMode",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
return G4MergeMode::kAddition;
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return G4MergeMode::kAddition;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Csv analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -38,17 +38,22 @@
|
||||
#include "tools/wcsv_ntuple"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvAnalysisManager;
|
||||
class G4CsvFileManager;
|
||||
class G4CsvNtupleFileManager;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4CsvAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4CsvAnalysisManager>;
|
||||
|
||||
public:
|
||||
explicit G4CsvAnalysisManager(G4bool isMaster = true);
|
||||
~G4CsvAnalysisManager();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4CsvAnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
@@ -61,40 +66,31 @@ class G4CsvAnalysisManager : public G4ToolsAnalysisManager
|
||||
std::vector<tools::wcsv::ntuple*>::iterator EndNtuple();
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator BeginConstNtuple() const;
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator EndConstNtuple() const;
|
||||
|
||||
|
||||
// Csv format specific option
|
||||
void SetIsCommentedHeader(G4bool isCommentedHeader);
|
||||
void SetIsHippoHeader(G4bool isHippoHeader);
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
// Virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) final;
|
||||
virtual G4bool ResetImpl() final;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
G4CsvAnalysisManager();
|
||||
|
||||
// Static data members
|
||||
//
|
||||
static G4CsvAnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4CsvAnalysisManager* fgInstance;
|
||||
|
||||
// methods
|
||||
//
|
||||
template <typename T>
|
||||
G4bool WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType);
|
||||
G4bool WriteH1();
|
||||
G4bool WriteH2();
|
||||
G4bool WriteH3();
|
||||
G4bool WriteP1();
|
||||
G4bool WriteP2();
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
std::shared_ptr<G4CsvNtupleFileManager> fNtupleFileManager;
|
||||
inline static G4CsvAnalysisManager* fgMasterInstance { nullptr };
|
||||
inline static G4ThreadLocal G4bool fgIsInstance { false };
|
||||
static constexpr std::string_view fkClass { "G4CsvAnalysisManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager { nullptr };
|
||||
std::shared_ptr<G4CsvNtupleFileManager> fNtupleFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4CsvAnalysisManager.icc"
|
||||
|
||||
@@ -27,128 +27,6 @@
|
||||
#include "G4CsvNtupleManager.hh"
|
||||
#include "G4CsvNtupleFileManager.hh"
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wcsv_histo"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
G4bool G4CsvAnalysisManager::WriteT(const std::vector<tools::histo::p1d*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
auto fileName = fFileManager->GetHnFileName(hnType, name);
|
||||
std::ofstream hnFile(fileName);
|
||||
|
||||
// Do nothing if there is no file
|
||||
if ( ! hnFile.is_open() ) return false;
|
||||
|
||||
auto result
|
||||
= tools::wcsv::pto(hnFile, ht->s_cls(), *ht);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
hnFile.close();
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
G4bool G4CsvAnalysisManager::WriteT(const std::vector<tools::histo::p2d*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
auto fileName = fFileManager->GetHnFileName(hnType, name);
|
||||
std::ofstream hnFile(fileName);
|
||||
|
||||
// Do nothing if there is no file
|
||||
if ( ! hnFile.is_open() ) return false;
|
||||
|
||||
auto result
|
||||
= tools::wcsv::pto(hnFile, ht->s_cls(), *ht);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
hnFile.close();
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4CsvAnalysisManager::WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
auto fileName = fFileManager->GetHnFileName(hnType, name);
|
||||
std::ofstream hnFile(fileName);
|
||||
|
||||
// Do nothing if there is no file
|
||||
if ( ! hnFile.is_open() ) return false;
|
||||
|
||||
auto result
|
||||
= tools::wcsv::hto(hnFile, ht->s_cls(), *ht);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
hnFile.close();
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
@@ -162,55 +40,55 @@ inline
|
||||
tools::wcsv::ntuple* G4CsvAnalysisManager::GetNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::wcsv::ntuple* G4CsvAnalysisManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple(ntupleId);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::iterator G4CsvAnalysisManager::BeginNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::iterator G4CsvAnalysisManager::EndNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
G4CsvAnalysisManager::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
G4CsvAnalysisManager::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
void G4CsvAnalysisManager::SetIsCommentedHeader(G4bool isCommentedHeader)
|
||||
{
|
||||
fNtupleFileManager->GetNtupleManager()->SetIsCommentedHeader(isCommentedHeader);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
void G4CsvAnalysisManager::SetIsHippoHeader(G4bool isHippoHeader)
|
||||
{
|
||||
fNtupleFileManager->GetNtupleManager()->SetIsHippoHeader(isHippoHeader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Csv analysis reader.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 05/09/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -35,66 +35,51 @@
|
||||
#include "G4ToolsAnalysisReader.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
#include "tools/rcsv_ntuple"
|
||||
|
||||
class G4H1ToolsManager;
|
||||
class G4H2ToolsManager;
|
||||
class G4H3ToolsManager;
|
||||
class G4P1ToolsManager;
|
||||
class G4P2ToolsManager;
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvAnalysisReader;
|
||||
class G4CsvRNtupleManager;
|
||||
class G4CsvRFileManager;
|
||||
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4CsvAnalysisReader : public G4ToolsAnalysisReader
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4CsvAnalysisReader>;
|
||||
|
||||
public:
|
||||
explicit G4CsvAnalysisReader(G4bool isMaster = true);
|
||||
virtual ~G4CsvAnalysisReader();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4CsvAnalysisReader* Instance();
|
||||
|
||||
// Access methods
|
||||
tools::rcsv::ntuple* GetNtuple() const;
|
||||
tools::rcsv::ntuple* GetNtuple(G4int ntupleId) const;
|
||||
using G4VAnalysisReader::GetNtuple;
|
||||
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
virtual G4int ReadH1Impl(const G4String& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH2Impl(const G4String& h2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH3Impl(const G4String& h3Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP1Impl(const G4String& p1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP2Impl(const G4String& p2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
// Virtual methods from base class
|
||||
virtual G4bool CloseFilesImpl(G4bool reset) final;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
static G4CsvAnalysisReader* fgMasterInstance;
|
||||
static G4ThreadLocal G4CsvAnalysisReader* fgInstance;
|
||||
G4CsvAnalysisReader();
|
||||
|
||||
// methods
|
||||
G4String GetHnFileName(const G4String& hnType,
|
||||
const G4String& hnName,
|
||||
const G4String& baseFileName,
|
||||
G4bool isUserFileName) const;
|
||||
|
||||
// Static data members
|
||||
inline static G4CsvAnalysisReader* fgMasterInstance { nullptr };
|
||||
|
||||
// Methods
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4CsvRNtupleManager* fNtupleManager;
|
||||
G4CsvRFileManager* fFileManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvAnalysisReader" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4CsvRNtupleManager> fNtupleManager { nullptr };
|
||||
std::shared_ptr<G4CsvRFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4CsvAnalysisReader.icc"
|
||||
|
||||
@@ -28,15 +28,16 @@
|
||||
|
||||
#include "G4CsvRNtupleManager.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::rcsv::ntuple* G4CsvAnalysisReader::GetNtuple() const
|
||||
{
|
||||
return fNtupleManager->GetNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::rcsv::ntuple* G4CsvAnalysisReader::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleManager->GetNtuple(ntupleId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
|
||||
#include "tools/wcsv_ntuple"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
// Type aliases
|
||||
using CsvNtupleDescription = G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>;
|
||||
|
||||
@@ -44,8 +46,9 @@ class G4CsvFileManager : public G4VTFileManager<std::ofstream>
|
||||
{
|
||||
public:
|
||||
explicit G4CsvFileManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvFileManager();
|
||||
|
||||
G4CsvFileManager() = delete;
|
||||
~G4CsvFileManager() = default;
|
||||
|
||||
using G4BaseFileManager::GetNtupleFileName;
|
||||
using G4VTFileManager<std::ofstream>::WriteFile;
|
||||
using G4VTFileManager<std::ofstream>::CloseFile;
|
||||
@@ -53,21 +56,42 @@ class G4CsvFileManager : public G4VTFileManager<std::ofstream>
|
||||
// Methods to manipulate output files
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
|
||||
virtual G4bool SetHistoDirectoryName(const G4String& dirName) final;
|
||||
virtual G4bool SetNtupleDirectoryName(const G4String& dirName) final;
|
||||
|
||||
virtual G4String GetFileType() const final { return "csv"; }
|
||||
|
||||
// Specific methods for files per objects
|
||||
G4bool CreateNtupleFile(CsvNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(CsvNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(CsvNtupleDescription* ntupleDescription);
|
||||
|
||||
G4bool IsHistoDirectory() const;
|
||||
G4bool IsNtupleDirectory() const;
|
||||
|
||||
protected:
|
||||
// Methods derived from templated base class
|
||||
virtual std::shared_ptr<std::ofstream> CreateFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
|
||||
private:
|
||||
// Utility method
|
||||
G4String GetNtupleFileName(CsvNtupleDescription* ntupleDescription);
|
||||
G4String GetNtupleFileName(CsvNtupleDescription* ntupleDescription);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvFileManager" };
|
||||
|
||||
// Data members
|
||||
G4bool fIsHistoDirectory { false };
|
||||
G4bool fIsNtupleDirectory { false };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline G4bool G4CsvFileManager::IsHistoDirectory() const
|
||||
{ return fIsHistoDirectory; }
|
||||
|
||||
inline G4bool G4CsvFileManager::IsNtupleDirectory() const
|
||||
{ return fIsNtupleDirectory; }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include "G4VTHnFileManager.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvFileManager;
|
||||
|
||||
template <typename HT>
|
||||
@@ -40,9 +42,10 @@ class G4CsvHnFileManager : public G4VTHnFileManager<HT>
|
||||
|
||||
{
|
||||
public:
|
||||
G4CsvHnFileManager(G4CsvFileManager* fileManger)
|
||||
explicit G4CsvHnFileManager(G4CsvFileManager* fileManger)
|
||||
: G4VTHnFileManager<HT>(), fFileManager(fileManger) {}
|
||||
virtual ~G4CsvHnFileManager() {}
|
||||
G4CsvHnFileManager() = delete;
|
||||
virtual ~G4CsvHnFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
virtual G4bool WriteExtra(HT* ht, const G4String& htName, const G4String& fileName) final;
|
||||
@@ -52,7 +55,10 @@ class G4CsvHnFileManager : public G4VTHnFileManager<HT>
|
||||
private:
|
||||
// Methods
|
||||
G4bool Write(std::ofstream& hnfile, HT* ht);
|
||||
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvHnFileManager" };
|
||||
|
||||
// Data members
|
||||
G4CsvFileManager* fFileManager;
|
||||
};
|
||||
|
||||
@@ -35,8 +35,6 @@
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
@@ -79,12 +77,11 @@ G4bool G4CsvHnFileManager<HT>::WriteExtra(
|
||||
auto result = Write(hnFile, ht);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << G4Analysis::GetHnType<HT>() << " " << htName << " failed";
|
||||
G4Exception("G4CsvAnalysisManager::WriteExtra()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
G4Analysis::Warn(
|
||||
"Saving " + G4Analysis::GetHnType<HT>() + " " + htName + " failed",
|
||||
fkClass, "WriteExtra");
|
||||
return false;
|
||||
}
|
||||
hnFile.close();
|
||||
return true;
|
||||
}
|
||||
@@ -107,14 +104,19 @@ G4bool G4CsvHnFileManager<HT>::Write(
|
||||
// If histogram file name was not defined per object
|
||||
// a file should be created from the provided default file name
|
||||
auto hnFileName = fFileManager->GetHnFileName(G4Analysis::GetHnType<HT>(), htName);
|
||||
|
||||
// If histo directory name is set and if this directory exists
|
||||
// add directory path to hnFileName
|
||||
if ( fFileManager->IsHistoDirectory() ) {
|
||||
hnFileName = "./" + fFileManager->GetHistoDirectoryName() + "/" + hnFileName;
|
||||
}
|
||||
|
||||
if ( ! hnFileName.empty() ) {
|
||||
hnFile = fFileManager->CreateTFile(hnFileName);
|
||||
}
|
||||
|
||||
if ( ! hnFile ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Failed to get Csv file " << fileName;
|
||||
G4Exception("G4CsvHnFileManager<HT>::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
G4Analysis::Warn("Failed to get Csv file " + fileName, fkClass, "Write");
|
||||
return false;
|
||||
} else {
|
||||
fileName = hnFileName;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// The manager class for histogram/profile reading from a Csv file.
|
||||
|
||||
// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4CsvHnRFileManager_h
|
||||
#define G4CsvHnRFileManager_h 1
|
||||
|
||||
#include "G4VTHnRFileManager.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvRFileManager;
|
||||
|
||||
template <typename HT>
|
||||
class G4CsvHnRFileManager : public G4VTHnRFileManager<HT>
|
||||
{
|
||||
public:
|
||||
explicit G4CsvHnRFileManager(G4CsvRFileManager* rfileManger)
|
||||
: G4VTHnRFileManager<HT>(), fRFileManager(rfileManger) {}
|
||||
G4CsvHnRFileManager() = delete;
|
||||
virtual ~G4CsvHnRFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
virtual HT* Read(const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
|
||||
private:
|
||||
// Methods
|
||||
G4String GetHnFileName(const G4String& hnType, const G4String& hnName,
|
||||
const G4String& baseFileName, G4bool isUserFileName) const;
|
||||
HT* ReadT(std::istream& hnFile, const G4String& fileName,
|
||||
std::string_view inFunction);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvHnRFileManager<HT>" };
|
||||
// Data members
|
||||
G4CsvRFileManager* fRFileManager;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4CsvHnRFileManager.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/rcsv_histo"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4String G4CsvHnRFileManager<HT>::GetHnFileName(
|
||||
const G4String& hnType, const G4String& hnName,
|
||||
const G4String& fileName, G4bool isUserFileName) const
|
||||
{
|
||||
if ( isUserFileName ) {
|
||||
return fRFileManager->GetFullFileName(fileName);
|
||||
}
|
||||
else {
|
||||
return fRFileManager->GetHnFileName(hnType, hnName);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
HT* G4CsvHnRFileManager<HT>::ReadT(
|
||||
std::istream& htFile, const G4String& fileName, std::string_view inFunction)
|
||||
{
|
||||
tools::rcsv::histo handler(htFile);
|
||||
std::string objectTypeInFile;
|
||||
void* object;
|
||||
auto verbose = false;
|
||||
if ( ! handler.read(G4cout, objectTypeInFile, object, verbose) ) {
|
||||
G4Analysis::Warn(
|
||||
"Cannot get " + G4Analysis::GetHnType<HT>() + " in file " + fileName,
|
||||
fkClass, inFunction);
|
||||
return nullptr;
|
||||
}
|
||||
if ( objectTypeInFile.compare(HT::s_class()) != 0 ) {
|
||||
G4Analysis::Warn(
|
||||
"Object type read in " + G4Analysis::GetHnType<HT>() +" does not match",
|
||||
fkClass, inFunction);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<HT*>(object);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
HT* G4CsvHnRFileManager<HT>::Read(
|
||||
const G4String& htName, const G4String& fileName, const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
// Get file name
|
||||
auto htFileName =
|
||||
GetHnFileName(G4Analysis::GetHnType<HT>(), htName, fileName, isUserFileName);
|
||||
|
||||
// Update directory path
|
||||
if ( ! dirName.empty() ) {
|
||||
htFileName = "./" + dirName + "/" + htFileName;
|
||||
}
|
||||
|
||||
std::ifstream htFile(htFileName);
|
||||
if ( ! htFile.is_open() ) {
|
||||
G4Analysis::Warn("Cannot open file " + htFileName, fkClass, "Read");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto ht = ReadT(htFile, htFileName, "Read");
|
||||
return ht;
|
||||
}
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvFileManager;
|
||||
class G4CsvNtupleManager;
|
||||
class G4VNtupleManager;
|
||||
@@ -45,7 +47,8 @@ class G4CsvNtupleFileManager : public G4VNtupleFileManager
|
||||
|
||||
public:
|
||||
explicit G4CsvNtupleFileManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvNtupleFileManager();
|
||||
G4CsvNtupleFileManager() = delete;
|
||||
virtual ~G4CsvNtupleFileManager() = default;
|
||||
|
||||
virtual std::shared_ptr<G4VNtupleManager> CreateNtupleManager() override;
|
||||
|
||||
@@ -53,19 +56,22 @@ class G4CsvNtupleFileManager : public G4VNtupleFileManager
|
||||
virtual G4bool ActionAtOpenFile(const G4String& fileName) override;
|
||||
virtual G4bool ActionAtWrite() override;
|
||||
virtual G4bool ActionAtCloseFile(G4bool reset) override;
|
||||
virtual G4bool Reset() override;
|
||||
virtual G4bool Reset() override;
|
||||
|
||||
void SetFileManager(std::shared_ptr<G4CsvFileManager> fileManager);
|
||||
|
||||
std::shared_ptr<G4CsvNtupleManager> GetNtupleManager() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
G4bool CloseNtupleFiles();
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
std::shared_ptr<G4CsvNtupleManager> fNtupleManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvNtupleFileManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager { nullptr };
|
||||
std::shared_ptr<G4CsvNtupleManager> fNtupleManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
@@ -37,21 +37,23 @@
|
||||
#include "tools/wcsv_ntuple"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
// Types alias
|
||||
using CsvNtupleDescription = G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>;
|
||||
|
||||
class G4CsvFileManager;
|
||||
|
||||
class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
std::ofstream>
|
||||
class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
std::ofstream>
|
||||
{
|
||||
friend class G4CsvAnalysisManager;
|
||||
friend class G4CsvNtupleFileManager;
|
||||
|
||||
public:
|
||||
explicit G4CsvNtupleManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvNtupleManager();
|
||||
G4CsvNtupleManager() = delete;
|
||||
virtual ~G4CsvNtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Functions specific to the output type
|
||||
@@ -64,7 +66,7 @@ class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
|
||||
void SetIsCommentedHeader(G4bool isCommentedHeader);
|
||||
void SetIsHippoHeader(G4bool isHippoHeader);
|
||||
|
||||
|
||||
// Methods from the templated base class
|
||||
//
|
||||
virtual void CreateTNtupleFromBooking(
|
||||
@@ -73,22 +75,25 @@ class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
virtual void FinishTNtuple(
|
||||
CsvNtupleDescription* ntupleDescription,
|
||||
G4bool fromBooking) final;
|
||||
|
||||
|
||||
G4bool WriteHeader(tools::wcsv::ntuple* ntuple) const;
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvNtupleManager" };
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
G4bool fIsCommentedHeader;
|
||||
G4bool fIsHippoHeader;
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager { nullptr };
|
||||
G4bool fIsCommentedHeader { true };
|
||||
G4bool fIsHippoHeader { false };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void
|
||||
inline void
|
||||
G4CsvNtupleManager::SetFileManager(std::shared_ptr<G4CsvFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline const std::vector<G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>*>&
|
||||
inline const std::vector<G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>*>&
|
||||
G4CsvNtupleManager::GetNtupleDescriptionVector() const
|
||||
{ return fNtupleDescriptionVector; }
|
||||
|
||||
|
||||
@@ -31,29 +31,37 @@
|
||||
#ifndef G4CsvRFileManager_h
|
||||
#define G4CsvRFileManager_h 1
|
||||
|
||||
#include "G4BaseFileManager.hh"
|
||||
#include "G4VRFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string_view>
|
||||
|
||||
class G4AnalysisManagerState;
|
||||
|
||||
class G4CsvRFileManager : public G4BaseFileManager
|
||||
class G4CsvRFileManager : public G4VRFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4CsvRFileManager(const G4AnalysisManagerState& state);
|
||||
G4CsvRFileManager() = delete;
|
||||
~G4CsvRFileManager();
|
||||
|
||||
virtual G4String GetFileType() const final { return "csv"; }
|
||||
|
||||
// Methods from base class
|
||||
virtual void CloseFiles() final {}
|
||||
|
||||
// Methods to manipulate input files
|
||||
virtual G4bool OpenRFile(const G4String& fileName);
|
||||
|
||||
// Specific methods for files per objects
|
||||
std::ifstream* GetRFile(const G4String& fileName) const;
|
||||
|
||||
|
||||
private:
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvRFileManager" };
|
||||
|
||||
// data members
|
||||
std::map<G4String, std::ifstream*> fRFiles;
|
||||
};
|
||||
|
||||
@@ -37,19 +37,38 @@
|
||||
|
||||
#include "tools/rcsv_ntuple"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvRFileManager;
|
||||
|
||||
class G4CsvRNtupleManager : public G4TRNtupleManager<tools::rcsv::ntuple>
|
||||
{
|
||||
friend class G4CsvAnalysisReader;
|
||||
|
||||
protected:
|
||||
public:
|
||||
explicit G4CsvRNtupleManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4CsvRNtupleManager();
|
||||
|
||||
G4CsvRNtupleManager() = delete;
|
||||
virtual ~G4CsvRNtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Methods from the templated base class
|
||||
//
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4CsvRFileManager> fileManager);
|
||||
|
||||
// Methods from the base class
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4bool GetTNtupleRow(G4TRNtupleDescription<tools::rcsv::ntuple>* ntupleDescription) final;
|
||||
};
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvRNtupleManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4CsvRFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
inline void
|
||||
G4CsvRNtupleManager::SetFileManager(std::shared_ptr<G4CsvRFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,20 +30,10 @@
|
||||
#define g4csv_defs_h
|
||||
|
||||
#include "tools/wcsv_ntuple"
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4CsvAnalysisReader.hh"
|
||||
#include "g4hntools_defs.hh"
|
||||
|
||||
namespace G4Csv
|
||||
{
|
||||
// Ntuple types
|
||||
using G4Ntuple = tools::wcsv::ntuple;
|
||||
using G4NtupleIterator = std::vector<tools::wcsv::ntuple*>::iterator;
|
||||
using G4NtupleConstIterator = std::vector<tools::wcsv::ntuple*>::const_iterator;
|
||||
|
||||
// Managers
|
||||
using G4AnalysisManager = G4CsvAnalysisManager;
|
||||
using G4AnalysisReader = G4CsvAnalysisReader;
|
||||
}
|
||||
// Csv output specific types
|
||||
using G4CsvNtuple = tools::wcsv::ntuple;
|
||||
using G4CsvRNtuple = tools::wcsv::ntuple;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,12 +10,13 @@ geant4_add_module(G4csv
|
||||
G4CsvFileManager.hh
|
||||
G4CsvHnFileManager.hh
|
||||
G4CsvHnFileManager.icc
|
||||
G4CsvHnRFileManager.hh
|
||||
G4CsvHnRFileManager.icc
|
||||
G4CsvNtupleFileManager.hh
|
||||
G4CsvNtupleManager.hh
|
||||
G4CsvRFileManager.hh
|
||||
G4CsvRNtupleManager.hh
|
||||
g4csv_defs.hh
|
||||
g4csv.hh
|
||||
SOURCES
|
||||
G4CsvAnalysisManager.cc
|
||||
G4CsvAnalysisReader.cc
|
||||
|
||||
@@ -29,66 +29,33 @@
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4CsvNtupleFileManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// mutex in a file scope
|
||||
|
||||
namespace {
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH2Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH3Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P1 profiles
|
||||
G4Mutex mergeP1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P2 profiles
|
||||
G4Mutex mergeP2Mutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4CsvAnalysisManager* G4CsvAnalysisManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4CsvAnalysisManager* G4CsvAnalysisManager::fgInstance = nullptr;
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager* G4CsvAnalysisManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4CsvAnalysisManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
static G4ThreadLocalSingleton<G4CsvAnalysisManager> instance;
|
||||
fgIsInstance = true;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::IsInstance()
|
||||
{
|
||||
return ( fgInstance != 0 );
|
||||
}
|
||||
return fgIsInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("Csv", isMaster),
|
||||
fFileManager(nullptr),
|
||||
fNtupleFileManager(nullptr)
|
||||
G4CsvAnalysisManager::G4CsvAnalysisManager()
|
||||
: G4ToolsAnalysisManager("Csv")
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "G4CsvAnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4CsvAnalysisManager::G4CsvAnalysisManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// File Manager
|
||||
fFileManager = std::make_shared<G4CsvFileManager>(fState);
|
||||
@@ -102,151 +69,15 @@ G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager::~G4CsvAnalysisManager()
|
||||
{
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
fgIsInstance = false;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH1()
|
||||
{
|
||||
auto h1Vector = fH1Manager->GetH1Vector();
|
||||
auto hnVector = fH1Manager->GetHnVector();
|
||||
|
||||
if ( ! h1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h1Vector, hnVector, "h1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH1(&mergeH1Mutex);
|
||||
fgMasterInstance->fH1Manager->AddH1Vector(h1Vector);
|
||||
lH1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH2()
|
||||
{
|
||||
auto h2Vector = fH2Manager->GetH2Vector();
|
||||
auto hnVector = fH2Manager->GetHnVector();
|
||||
|
||||
if ( ! h2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h2Vector, hnVector, "h2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH2(&mergeH2Mutex);
|
||||
fgMasterInstance->fH2Manager->AddH2Vector(h2Vector);
|
||||
lH2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH3()
|
||||
{
|
||||
auto h3Vector = fH3Manager->GetH3Vector();
|
||||
auto hnVector = fH3Manager->GetHnVector();
|
||||
|
||||
if ( ! h3Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h3Vector, hnVector, "h3");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH3(&mergeH3Mutex);
|
||||
fgMasterInstance->fH3Manager->AddH3Vector(h3Vector);
|
||||
lH3.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteP1()
|
||||
{
|
||||
auto p1Vector = fP1Manager->GetP1Vector();
|
||||
auto hnVector = fP1Manager->GetHnVector();
|
||||
|
||||
if ( ! p1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(p1Vector, hnVector, "p1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP1(&mergeP1Mutex);
|
||||
fgMasterInstance->fP1Manager->AddP1Vector(p1Vector);
|
||||
lP1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteP2()
|
||||
{
|
||||
auto p2Vector = fP2Manager->GetP2Vector();
|
||||
auto hnVector = fP2Manager->GetHnVector();
|
||||
|
||||
if ( ! p2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(p2Vector, hnVector, "p2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP2(&mergeP2Mutex);
|
||||
fgMasterInstance->fP2Manager->AddP2Vector(p2Vector);
|
||||
lP2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisManager::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleFileManager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
@@ -254,80 +85,43 @@ G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
// and set it to base class which takes then their ownership
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Save file name in file manager
|
||||
auto result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->OpenFile(fileName);
|
||||
|
||||
// Open ntuple files and create ntuples from bookings
|
||||
result = fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
{
|
||||
// nothing to be done for Csv file
|
||||
auto finalResult = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write", "files", "");
|
||||
auto result = true;
|
||||
|
||||
Message(kVL4, "write", "files");
|
||||
|
||||
if ( G4Threading::IsWorkerThread() ) {
|
||||
result &= G4ToolsAnalysisManager::Merge();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if ( ! fgMasterInstance &&
|
||||
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ||
|
||||
( ! fH3Manager->IsEmpty() ) || ( ! fP1Manager->IsEmpty() ) ||
|
||||
( ! fP2Manager->IsEmpty() ) ) ) {
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "No master G4CsvAnalysisManager instance exists."
|
||||
<< G4endl
|
||||
<< " " << "Histogram data will not be merged.";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
else {
|
||||
// Write all histograms/profile on master
|
||||
result &= G4ToolsAnalysisManager::WriteImpl();
|
||||
}
|
||||
|
||||
// H1
|
||||
auto result = WriteH1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H2
|
||||
result = WriteH2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H3
|
||||
result = WriteH3();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P1
|
||||
result = WriteP1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P2
|
||||
result = WriteP2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// Ntuples
|
||||
// Nothing to be done
|
||||
|
||||
// Write ASCII if activated
|
||||
// Not available
|
||||
// Not available
|
||||
//if ( IsAscii() ) {
|
||||
// result = WriteAscii();
|
||||
//}
|
||||
// result &= WriteAscii();
|
||||
//}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("write", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "write", "files", "", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -335,29 +129,38 @@ G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// close open files
|
||||
auto result = fFileManager->CloseFiles();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result &= fFileManager->CloseFiles();
|
||||
|
||||
// Histogram and profile files are created/closed indivudually for each
|
||||
// object in WriteHn{Pn] function
|
||||
|
||||
result = fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
finalResult = finalResult && result;
|
||||
// object in WriteT function
|
||||
|
||||
result &= fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
|
||||
// Reset data
|
||||
if ( reset ) {
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4CsvAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
Warn("Resetting data failed", fkClass, "CloseFileImpl");
|
||||
}
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::ResetImpl()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto result = true;
|
||||
|
||||
result &= G4ToolsAnalysisManager::ResetImpl();
|
||||
if ( fNtupleFileManager != nullptr ) {
|
||||
result &= fNtupleFileManager->Reset();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -29,98 +29,29 @@
|
||||
#include "G4CsvAnalysisReader.hh"
|
||||
#include "G4CsvRFileManager.hh"
|
||||
#include "G4CsvRNtupleManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <tools/aida_ntuple>
|
||||
#include <tools/rcsv_histo>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
G4CsvAnalysisReader* G4CsvAnalysisReader::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4CsvAnalysisReader* G4CsvAnalysisReader::fgInstance = nullptr;
|
||||
|
||||
//
|
||||
// utility functions
|
||||
//
|
||||
|
||||
namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void* ReadObject(std::istream& hnFile,
|
||||
const G4String& objectType,
|
||||
const G4String& fileName,
|
||||
const G4String& inFunction)
|
||||
{
|
||||
tools::rcsv::histo handler(hnFile);
|
||||
std::string objectTypeInFile;
|
||||
void* object;
|
||||
auto verbose = false;
|
||||
if ( ! handler.read(G4cout, objectTypeInFile, object, verbose) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Cannot get "<< objectType << " in file " << fileName;
|
||||
G4String inFunctionFull = "G4CsvAnalysisReader::";
|
||||
inFunctionFull.append(inFunction);
|
||||
G4Exception(inFunctionFull, "Analysis_WR011", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
if ( objectTypeInFile != objectType ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Object type read in "<< fileName
|
||||
<< " does not match" << G4endl;
|
||||
G4String inFunctionFull = "G4CsvAnalysisReader::";
|
||||
inFunctionFull.append(inFunction);
|
||||
G4Exception(inFunctionFull, "Analysis_WR011", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisReader* G4CsvAnalysisReader::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4CsvAnalysisReader(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
static G4ThreadLocalSingleton<G4CsvAnalysisReader> instance;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisReader::G4CsvAnalysisReader(G4bool isMaster)
|
||||
: G4ToolsAnalysisReader("Csv", isMaster),
|
||||
fNtupleManager(nullptr),
|
||||
fFileManager(nullptr)
|
||||
G4CsvAnalysisReader::G4CsvAnalysisReader()
|
||||
: G4ToolsAnalysisReader("Csv")
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4CsvAnalysisReader already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4CsvAnalysisReader::G4CsvAnalysisReader()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// Create managers
|
||||
fNtupleManager = new G4CsvRNtupleManager(fState);
|
||||
fFileManager = new G4CsvRFileManager(fState);
|
||||
// The managers will be deleted by the base class
|
||||
|
||||
fNtupleManager = std::make_shared<G4CsvRNtupleManager>(fState);
|
||||
fFileManager = std::make_shared<G4CsvRFileManager>(fState);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
|
||||
// Set managers to base class
|
||||
SetNtupleManager(fNtupleManager);
|
||||
SetFileManager(fFileManager);
|
||||
@@ -130,290 +61,43 @@ G4CsvAnalysisReader::G4CsvAnalysisReader(G4bool isMaster)
|
||||
G4CsvAnalysisReader::~G4CsvAnalysisReader()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4CsvAnalysisReader::GetHnFileName(
|
||||
const G4String& hnType,
|
||||
const G4String& hnName,
|
||||
const G4String& fileName,
|
||||
G4bool isUserFileName) const
|
||||
{
|
||||
if ( isUserFileName ) {
|
||||
return fFileManager->GetFullFileName(fileName);
|
||||
}
|
||||
else {
|
||||
return fFileManager->GetHnFileName(hnType, hnName);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisReader::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisReader::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleManager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//
|
||||
auto result = true;
|
||||
|
||||
result &= G4ToolsAnalysisReader::Reset();
|
||||
result &= fNtupleManager->Reset();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadH1Impl(const G4String& h1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
G4bool G4CsvAnalysisReader::CloseFilesImpl(G4bool reset)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("get", "h1", h1Name);
|
||||
#endif
|
||||
Message(kVL4, "close", "files");
|
||||
|
||||
// open file
|
||||
auto h1FileName = GetHnFileName("h1", h1Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(h1FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << h1FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadH1Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
auto result = true;
|
||||
|
||||
if (reset) {
|
||||
result &= Reset();
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", h1FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::h1d::s_class(), h1FileName, "ReadH1Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto h1 = static_cast<tools::histo::h1d*>(object);
|
||||
auto id = fH1Manager->AddH1(h1Name, h1);
|
||||
fFileManager->CloseFiles();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
Message(kVL2, "close", "files", "", result);
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadH2Impl(const G4String& h2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h2", h2Name);
|
||||
#endif
|
||||
|
||||
// open file
|
||||
auto h2FileName = GetHnFileName("h2", h2Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(h2FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << h2FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadH2Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", h2FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::h2d::s_class(), h2FileName, "ReadH2Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto h2 = static_cast<tools::histo::h2d*>(object);
|
||||
auto id = fH2Manager->AddH2(h2Name, h2);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadH3Impl(const G4String& h3Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h3", h3Name);
|
||||
#endif
|
||||
|
||||
// open file
|
||||
auto h3FileName = GetHnFileName("h3", h3Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(h3FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << h3FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadH3Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", h3FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::h3d::s_class(), h3FileName, "ReadH3Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto h3 = static_cast<tools::histo::h3d*>(object);
|
||||
auto id = fH3Manager->AddH3(h3Name, h3);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadP1Impl(const G4String& p1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "p1", p1Name);
|
||||
#endif
|
||||
|
||||
// open file
|
||||
G4String p1FileName = GetHnFileName("p1", p1Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(p1FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << p1FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadP1Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", p1FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::p1d::s_class(), fileName, "ReadP1Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto p1 = static_cast<tools::histo::p1d*>(object);
|
||||
auto id = fP1Manager->AddP1(p1Name, p1);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadP2Impl(const G4String& p2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "p2", p2Name);
|
||||
#endif
|
||||
|
||||
// open file
|
||||
G4String p2FileName = GetHnFileName("p2", p2Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(p2FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << p2FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadP2Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", p2FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::p2d::s_class(), p2FileName, "ReadP2Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto p2 = static_cast<tools::histo::p2d*>(object);
|
||||
auto id = fP2Manager->AddP2(p2Name, p2);
|
||||
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "ntuple", ntupleName);
|
||||
#endif
|
||||
|
||||
// Ntuples are saved per object and per thread
|
||||
// but apply the ntuple name and the thread suffixes
|
||||
// only if fileName is not provided explicitly
|
||||
G4String fullFileName = fileName;
|
||||
if ( ! isUserFileName ) {
|
||||
fullFileName = fFileManager->GetNtupleFileName(ntupleName);
|
||||
}
|
||||
|
||||
// Open file
|
||||
if ( ! fFileManager->OpenRFile(fullFileName) ) return kInvalidId;
|
||||
auto ntupleFile = fFileManager->GetRFile(fullFileName);
|
||||
|
||||
// Create ntuple
|
||||
auto rntuple = new tools::rcsv::ntuple(*ntupleFile);
|
||||
auto id = fNtupleManager->SetNtuple(new G4TRNtupleDescription<tools::rcsv::ntuple>(rntuple));
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "G4CsvHnFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4Filesystem.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
using namespace tools;
|
||||
@@ -43,14 +44,10 @@ G4CsvFileManager::G4CsvFileManager(const G4AnalysisManagerState& state)
|
||||
fH2FileManager = std::make_shared<G4CsvHnFileManager<histo::h2d>>(this);
|
||||
fH3FileManager = std::make_shared<G4CsvHnFileManager<histo::h3d>>(this);
|
||||
fP1FileManager = std::make_shared<G4CsvHnFileManager<histo::p1d>>(this);
|
||||
fP2FileManager = std::make_shared<G4CsvHnFileManager<histo::p2d>>(this);
|
||||
fP2FileManager = std::make_shared<G4CsvHnFileManager<histo::p2d>>(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvFileManager::~G4CsvFileManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -66,10 +63,15 @@ G4String G4CsvFileManager::GetNtupleFileName(CsvNtupleDescription* ntupleDescrip
|
||||
// compose ntuple file name from the default file name
|
||||
ntupleFileName = GetNtupleFileName(ntupleDescription->fNtupleBooking.name());
|
||||
}
|
||||
return ntupleFileName;
|
||||
}
|
||||
|
||||
//
|
||||
if ( IsNtupleDirectory() ) {
|
||||
ntupleFileName = "./" + GetNtupleDirectoryName() + "/" + ntupleFileName;
|
||||
}
|
||||
|
||||
return ntupleFileName;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -78,11 +80,7 @@ std::shared_ptr<std::ofstream> G4CsvFileManager::CreateFileImpl(const G4String&
|
||||
{
|
||||
std::shared_ptr<std::ofstream> file = std::make_shared<std::ofstream>(fileName);
|
||||
if ( file->fail() ) {
|
||||
file = nullptr;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot create file " << fileName;
|
||||
G4Exception("G4CsvFileManager::CreateFileImpl()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("Cannot create file " + fileName, fkClass, "CreateFileImpl");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -93,21 +91,21 @@ std::shared_ptr<std::ofstream> G4CsvFileManager::CreateFileImpl(const G4String&
|
||||
G4bool G4CsvFileManager::WriteFileImpl(std::shared_ptr<std::ofstream> /*file*/)
|
||||
{
|
||||
// Nothing to be done here
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::CloseFileImpl(std::shared_ptr<std::ofstream> file)
|
||||
G4bool G4CsvFileManager::CloseFileImpl(std::shared_ptr<std::ofstream> file)
|
||||
{
|
||||
if ( ! file ) return false;
|
||||
|
||||
// close file
|
||||
file->close();
|
||||
file->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
@@ -118,10 +116,40 @@ G4bool G4CsvFileManager::OpenFile(const G4String& fileName)
|
||||
fFileName = fileName;
|
||||
|
||||
fIsOpenFile = true;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::SetHistoDirectoryName(const G4String& dirName)
|
||||
{
|
||||
// A directory is taken into account only if it exists in file system
|
||||
if ( G4fs::is_directory(dirName.data()) ) {
|
||||
fIsHistoDirectory = G4VFileManager::SetHistoDirectoryName(dirName);
|
||||
return fIsHistoDirectory;
|
||||
}
|
||||
|
||||
G4Analysis::Warn("Directory " + dirName + " does not exists.\n"
|
||||
"Histograms will be written in the current directory.",
|
||||
fkClass, "SetHistoDirectoryName");
|
||||
return false;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::SetNtupleDirectoryName(const G4String& dirName)
|
||||
{
|
||||
// A directory is taken into account only if it exists in file system
|
||||
if ( G4fs::is_directory(dirName.data()) ) {
|
||||
fIsNtupleDirectory = G4VFileManager::SetNtupleDirectoryName(dirName);
|
||||
return fIsNtupleDirectory;
|
||||
}
|
||||
|
||||
G4Analysis::Warn("Directory " + dirName + " does not exists.\n"
|
||||
"Ntuples will be written in the current directory.",
|
||||
fkClass, "SetNtupleDirectoryName");
|
||||
return false;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::CreateNtupleFile(
|
||||
CsvNtupleDescription* ntupleDescription)
|
||||
@@ -129,11 +157,7 @@ G4bool G4CsvFileManager::CreateNtupleFile(
|
||||
// get ntuple file name per object (if defined)
|
||||
auto ntupleFileName = GetNtupleFileName(ntupleDescription);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("create", "ntuple file", ntupleFileName);
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "create", "ntuple file", ntupleFileName);
|
||||
|
||||
// update file name if it is already in use
|
||||
while ( GetTFile(ntupleFileName, false) ) {
|
||||
@@ -142,23 +166,16 @@ G4bool G4CsvFileManager::CreateNtupleFile(
|
||||
auto newName = GetBaseName(oldName) + "_bis." + GetExtension(oldName);
|
||||
ntupleDescription->fFileName = newName;
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Ntuple filename " << oldName << " is already in use." << G4endl
|
||||
<< "It will be replaced with : " << newName;
|
||||
G4Exception("G4CsvFileManager::CreateFileImpl()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("Ntuple filename " + oldName + " is already in use.\n" +
|
||||
"It will be replaced with : " + newName,
|
||||
fkClass, "CreateNtupleFile");
|
||||
|
||||
ntupleFileName = GetNtupleFileName(ntupleDescription);
|
||||
}
|
||||
|
||||
ntupleDescription->fFile = CreateTFile(ntupleFileName);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("create", "ntuple file", ntupleFileName);
|
||||
}
|
||||
#endif
|
||||
|
||||
Message(kVL2, "create", "ntuple file", ntupleFileName);
|
||||
|
||||
return (ntupleDescription->fFile != nullptr);
|
||||
}
|
||||
@@ -170,32 +187,21 @@ G4bool G4CsvFileManager::CloseNtupleFile(
|
||||
// Do nothing if there is no file
|
||||
if ( ! ntupleDescription->fFile ) return true;
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
auto ntupleFileName = GetNtupleFileName(ntupleDescription);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4() ->Message("close", "ntuple file", ntupleFileName);
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "close", "ntuple file", ntupleFileName);
|
||||
|
||||
// close file
|
||||
auto result = CloseTFile(ntupleFileName);
|
||||
finalResult = result && finalResult;
|
||||
|
||||
result &= CloseTFile(ntupleFileName);
|
||||
// Notify not empty file
|
||||
result = SetIsEmpty(ntupleFileName, ! ntupleDescription->fHasFill);
|
||||
finalResult = result && finalResult;
|
||||
result &= SetIsEmpty(ntupleFileName, ! ntupleDescription->fHasFill);
|
||||
|
||||
// Reset file info in ntuple description
|
||||
ntupleDescription->fFile.reset();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("close", "ntuple file", ntupleFileName);
|
||||
}
|
||||
#endif
|
||||
Message(kVL2, "close", "ntuple file", ntupleFileName);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -32,24 +32,14 @@
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleFileManager::G4CsvNtupleFileManager(const G4AnalysisManagerState& state)
|
||||
: G4VNtupleFileManager(state, "csv"),
|
||||
fFileManager(nullptr),
|
||||
fNtupleManager(nullptr)
|
||||
: G4VNtupleFileManager(state, "csv")
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleFileManager::~G4CsvNtupleFileManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -58,17 +48,16 @@ G4bool G4CsvNtupleFileManager::CloseNtupleFiles()
|
||||
{
|
||||
// Close ntuple files
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
|
||||
for ( auto ntupleDescription : ntupleVector) {
|
||||
auto result = fFileManager->CloseNtupleFile(ntupleDescription);
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->CloseNtupleFile(ntupleDescription);
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
@@ -79,7 +68,7 @@ std::shared_ptr<G4VNtupleManager> G4CsvNtupleFileManager::CreateNtupleManager()
|
||||
|
||||
fNtupleManager = std::make_shared<G4CsvNtupleManager>(fState);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
|
||||
|
||||
return fNtupleManager;
|
||||
}
|
||||
|
||||
@@ -88,7 +77,7 @@ G4bool G4CsvNtupleFileManager::ActionAtOpenFile(const G4String& /*fileName*/)
|
||||
{
|
||||
// G4cout << "G4CsvNtupleFileManager::ActionAtOpenFile" << G4endl;
|
||||
|
||||
// Create ntuples if they are booked
|
||||
// Create ntuples if they are booked
|
||||
// (The files will be created with creating ntuples)
|
||||
fNtupleManager->CreateNtuplesFromBooking(
|
||||
fBookingManager->GetNtupleBookingVector());
|
||||
@@ -105,29 +94,24 @@ G4bool G4CsvNtupleFileManager::ActionAtWrite()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleFileManager::ActionAtCloseFile(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// close ntuple files
|
||||
auto result = CloseNtupleFiles();
|
||||
finalResult = finalResult && result;
|
||||
result &= CloseNtupleFiles();
|
||||
|
||||
if ( ! reset ) {
|
||||
// The ntuples must be always reset when closing file)
|
||||
// The ntuples must be always reset when closing file)
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4CsvNtupleFileManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
Warn("Resetting data failed", fkClass, "ActionAtCloseFile");
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleFileManager::Reset()
|
||||
{
|
||||
return fNtupleManager->Reset(true);
|
||||
return fNtupleManager->Reset();
|
||||
}
|
||||
|
||||
@@ -31,29 +31,18 @@
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//
|
||||
//
|
||||
// utility methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleManager::G4CsvNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TNtupleManager<tools::wcsv::ntuple, std::ofstream>(state),
|
||||
fFileManager(nullptr),
|
||||
fIsCommentedHeader(true),
|
||||
fIsHippoHeader(false)
|
||||
: G4TNtupleManager<tools::wcsv::ntuple, std::ofstream>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleManager::~G4CsvNtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -87,20 +76,14 @@ void G4CsvNtupleManager::FinishTNtuple(
|
||||
|
||||
// Return if creating ntuple failed
|
||||
if ( ! ntupleDescription->fNtuple ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Creating ntuple has failed. ";
|
||||
G4Exception("G4CsvNtupleManager::FinishTNtuple()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
Warn("Creating ntuple has failed.", fkClass, "FinishTNtuple");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Write header if ntuple already exists
|
||||
if ( ! WriteHeader(ntupleDescription->fNtuple) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Writing ntuple header has failed. ";
|
||||
G4Exception("G4CsvNtupleManager::FinishTNtuple()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
Warn("Writing ntuple header has failed.", fkClass, "FinishTNtuple");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,17 +93,17 @@ G4bool G4CsvNtupleManager::WriteHeader(tools::wcsv::ntuple* ntuple) const
|
||||
// Write header if ntuple already exists and if this option is activated.
|
||||
// When both Hippo and Commented headers are selected, only Commented
|
||||
// header, which reading is supported.
|
||||
// Return false only if an error occurred.
|
||||
// Return false only if an error occurred.
|
||||
|
||||
if ( fIsCommentedHeader ) {
|
||||
return ntuple->write_commented_header(G4cout);
|
||||
}
|
||||
|
||||
|
||||
// write hippo header (if activated and if not commented header)
|
||||
if ( fIsHippoHeader ) {
|
||||
ntuple->write_hippo_header();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,73 +27,71 @@
|
||||
// Author: Ivana Hrivnacova, 21/10/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4CsvRFileManager.hh"
|
||||
#include "G4CsvHnRFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
using namespace tools;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvRFileManager::G4CsvRFileManager(const G4AnalysisManagerState& state)
|
||||
: G4BaseFileManager(state),
|
||||
fRFiles()
|
||||
: G4VRFileManager(state)
|
||||
{
|
||||
// Create helpers defined in the base class
|
||||
fH1RFileManager = std::make_shared<G4CsvHnRFileManager<histo::h1d>>(this);
|
||||
fH2RFileManager = std::make_shared<G4CsvHnRFileManager<histo::h2d>>(this);
|
||||
fH3RFileManager = std::make_shared<G4CsvHnRFileManager<histo::h3d>>(this);
|
||||
fP1RFileManager = std::make_shared<G4CsvHnRFileManager<histo::p1d>>(this);
|
||||
fP2RFileManager = std::make_shared<G4CsvHnRFileManager<histo::p2d>>(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvRFileManager::~G4CsvRFileManager()
|
||||
{
|
||||
for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
|
||||
delete fRFiles[i];
|
||||
}
|
||||
{
|
||||
for ( auto& rfile : fRFiles ) {
|
||||
delete rfile.second;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvRFileManager::OpenRFile(const G4String& fileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("open", "read analysis file", fileName);
|
||||
#endif
|
||||
Message(kVL4, "open", "read analysis file", fileName);
|
||||
|
||||
// create new file
|
||||
std::ifstream* newFile = new std::ifstream(fileName);
|
||||
auto newFile = new std::ifstream(fileName);
|
||||
if ( ! newFile->is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << fileName;
|
||||
G4Exception("G4CsvAnalysisReader::OpenRFile()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
Warn("Cannot open file " + fileName, fkClass, "OpenRFile");
|
||||
return false;
|
||||
}
|
||||
|
||||
// add file in a map and delete the previous file if it exists
|
||||
std::map<G4String, std::ifstream*>::iterator it
|
||||
= fRFiles.find(fileName);
|
||||
if ( it != fRFiles.end() ) {
|
||||
auto it = fRFiles.find(fileName);
|
||||
if ( it != fRFiles.end() ) {
|
||||
delete it->second;
|
||||
it->second = newFile;
|
||||
}
|
||||
else {
|
||||
fRFiles[fileName] = newFile;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read analysis file", fileName);
|
||||
#endif
|
||||
Message(kVL1, "open", "read analysis file", fileName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::ifstream* G4CsvRFileManager::GetRFile(const G4String& fileName) const
|
||||
{
|
||||
std::map<G4String, std::ifstream*>::const_iterator it
|
||||
= fRFiles.find(fileName);
|
||||
{
|
||||
auto it = fRFiles.find(fileName);
|
||||
if ( it != fRFiles.end() )
|
||||
return it->second;
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,21 +27,55 @@
|
||||
// Author: Ivana Hrivnacova, 25/07/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4CsvRNtupleManager.hh"
|
||||
#include "G4CsvRFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvRNtupleManager::G4CsvRNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TRNtupleManager<tools::rcsv::ntuple>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvRNtupleManager::~G4CsvRNtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvRNtupleManager::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
Message(kVL4, "read", "ntuple", ntupleName);
|
||||
|
||||
// Ntuples are saved per object and per thread
|
||||
// but apply the ntuple name and the thread suffixes
|
||||
// only if fileName is not provided explicitly
|
||||
G4String fullFileName = fileName;
|
||||
if ( ! isUserFileName ) {
|
||||
fullFileName = fFileManager->GetNtupleFileName(ntupleName);
|
||||
}
|
||||
|
||||
// Update directory path
|
||||
if ( ! dirName.empty() ) {
|
||||
fullFileName = "./" + dirName + "/" + fullFileName;
|
||||
}
|
||||
|
||||
// Open file
|
||||
if ( ! fFileManager->OpenRFile(fullFileName) ) return kInvalidId;
|
||||
auto ntupleFile = fFileManager->GetRFile(fullFileName);
|
||||
|
||||
// Create ntuple
|
||||
auto rntuple = new tools::rcsv::ntuple(*ntupleFile);
|
||||
auto id = SetNtuple(new G4TRNtupleDescription<tools::rcsv::ntuple>(rntuple));
|
||||
|
||||
Message(kVL2, "read", "ntuple", ntupleName, id > kInvalidId);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvRNtupleManager::GetTNtupleRow(
|
||||
G4TRNtupleDescription<tools::rcsv::ntuple>* ntupleDescription)
|
||||
@@ -52,12 +86,7 @@ G4bool G4CsvRNtupleManager::GetTNtupleRow(
|
||||
if ( ! isInitialized ) {
|
||||
auto ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
if ( ! ntuple->initialize(G4cout, *ntupleBinding) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple initialization failed !!";
|
||||
G4Exception("G4CsvRNtuple::GetNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
Warn("Ntuple initialization failed !!", fkClass, "GetTNtupleRow");
|
||||
return false;
|
||||
}
|
||||
ntupleDescription->fIsInitialized = true;
|
||||
@@ -67,15 +96,10 @@ G4bool G4CsvRNtupleManager::GetTNtupleRow(
|
||||
auto next = ntuple->next();
|
||||
if ( next ) {
|
||||
if ( ! ntuple->get_row() ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple get_row() failed !!";
|
||||
G4Exception("G4CsvRNtuple::GetTNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
Warn("Ntuple get_row() failed !!", fkClass, "GetTNtupleRow");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,7 @@
|
||||
|
||||
Analysis_F001: Fatal exception when trying to create a singleton manager twice
|
||||
|
||||
Analysis_F002: Fatal exception when selecting non-existing output type.
|
||||
|
||||
Analysis_W001: Cannot create file or directory for output
|
||||
|
||||
Analysis_W002: Cannot create an object for output
|
||||
|
||||
Analysis_W011: Cannot manipulate an object which does not exist
|
||||
|
||||
Analysis_W012: Cannot set an object name
|
||||
|
||||
Analysis_W013: Cannot apply an attribute to an object
|
||||
|
||||
Analysis_W014: Cannot access an attribute of an object
|
||||
|
||||
Analysis_W021: Writing or closing a file has failed
|
||||
|
||||
Analysis_W022: Writing an object on file has failed
|
||||
|
||||
Analysis_W031: Merging data has failed
|
||||
|
||||
Analysis_W041: Requested feature is not available with selected output.
|
||||
|
||||
Analysis_W051: Selected output type is not supported.
|
||||
|
||||
Analysis_WR001: Cannot open a file for reading
|
||||
|
||||
Analysis_WR011: Cannot access an object in a file
|
||||
|
||||
Analysis_WR021: Reading an object from a file has failed
|
||||
Analysis_F001: Fatal exceptions:
|
||||
When trying to create a singleton manager twice
|
||||
When selecting non-existing output type.
|
||||
|
||||
Analysis_W001: Warnings:
|
||||
All cases when a JustWarning exception is issued
|
||||
|
||||
+5
-5
@@ -24,13 +24,13 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
|
||||
// Author: Ivana Hrivnacova, 21/09/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef g4csv_h
|
||||
#define g4csv_h
|
||||
#ifndef G4AnalysisManager_h
|
||||
#define G4AnalysisManager_h
|
||||
|
||||
#include "g4csv_defs.hh"
|
||||
#include "G4GenericAnalysisManager.hh"
|
||||
|
||||
using namespace G4Csv;
|
||||
using G4AnalysisManager = G4GenericAnalysisManager;
|
||||
|
||||
#endif
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Root analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -34,24 +34,28 @@
|
||||
|
||||
#include "G4ToolsAnalysisManager.hh"
|
||||
#include "G4THnManager.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4GenericAnalysisManager;
|
||||
class G4GenericFileManager;
|
||||
class G4HnInformation;
|
||||
class G4VNtupleFileManager;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4GenericAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
friend class G4RootMpiAnalysisManager;
|
||||
friend class G4ThreadLocalSingleton<G4GenericAnalysisManager>;
|
||||
|
||||
public:
|
||||
explicit G4GenericAnalysisManager(G4bool isMaster = true);
|
||||
virtual ~G4GenericAnalysisManager();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4GenericAnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
@@ -62,51 +66,53 @@ class G4GenericAnalysisManager : public G4ToolsAnalysisManager
|
||||
virtual void SetBasketSize(unsigned int basketSize) override;
|
||||
virtual void SetBasketEntries(unsigned int basketEntries) override;
|
||||
|
||||
// new functions
|
||||
G4bool Merge();
|
||||
|
||||
// write in an extra file
|
||||
// write in an extra file
|
||||
G4bool WriteH1(G4int id, const G4String& fileName);
|
||||
G4bool WriteH2(G4int id, const G4String& fileName);
|
||||
G4bool WriteH3(G4int id, const G4String& fileName);
|
||||
G4bool WriteP1(G4int id, const G4String& fileName);
|
||||
G4bool WriteP2(G4int id, const G4String& fileName);
|
||||
|
||||
// set default output type (backward compatibility)
|
||||
// Set default output type (backward compatibility)
|
||||
// this type will be used for file names without extension
|
||||
void SetDefaultFileType(const G4String& value);
|
||||
G4String GetDefaultFileType() const;
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
// Virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) override;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset = true) override;
|
||||
virtual G4bool CloseFileImpl(G4bool reset = true) override;
|
||||
virtual G4bool ResetImpl() final;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
virtual G4bool Reset() final;
|
||||
// File manager access
|
||||
virtual std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName) final;
|
||||
|
||||
|
||||
private:
|
||||
// methods
|
||||
G4GenericAnalysisManager();
|
||||
// Methods
|
||||
void CreateNtupleFileManager(const G4String& fileName);
|
||||
|
||||
// static data members
|
||||
static G4GenericAnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4GenericAnalysisManager* fgInstance;
|
||||
// Static data members
|
||||
inline static G4GenericAnalysisManager* fgMasterInstance { nullptr };
|
||||
inline static G4ThreadLocal G4bool fgIsInstance { false };
|
||||
static constexpr std::string_view fkClass { "G4GenericAnalysisManager" };
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4GenericFileManager> fFileManager;
|
||||
// Data members
|
||||
std::shared_ptr<G4GenericFileManager> fFileManager { nullptr };
|
||||
// add G4GenericNtupleManager
|
||||
// this class will be analogic to file managers but with ntuples
|
||||
std::shared_ptr<G4VNtupleFileManager> fNtupleFileManager;
|
||||
std::shared_ptr<G4VNtupleFileManager> fNtupleFileManager { nullptr };
|
||||
|
||||
// data members
|
||||
G4bool fIsNtupleMergingSet = false;
|
||||
G4int fNofNtupleFiles = 0;
|
||||
G4bool fMergeNtuples = false;
|
||||
G4bool fNtupleRowWise = false;
|
||||
G4bool fNtupleRowMode = true;
|
||||
unsigned int fBasketSize = fgkDefaultBasketSize;
|
||||
unsigned int fBasketEntries = fgkDefaultBasketEntries;
|
||||
// Data members
|
||||
G4bool fIsNtupleMergingSet { false };
|
||||
G4int fNofNtupleFiles { 0 };
|
||||
G4bool fMergeNtuples { false };
|
||||
G4bool fNtupleRowWise { false };
|
||||
G4bool fNtupleRowMode { true };
|
||||
unsigned int fBasketSize { G4Analysis::kDefaultBasketSize };
|
||||
unsigned int fBasketEntries { G4Analysis::kDefaultBasketEntries };
|
||||
};
|
||||
|
||||
#include "G4GenericAnalysisManager.icc"
|
||||
|
||||
@@ -27,6 +27,13 @@
|
||||
#include "G4GenericFileManager.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::shared_ptr<G4VFileManager> G4GenericAnalysisManager::GetFileManager(
|
||||
const G4String& fileName)
|
||||
{
|
||||
return fFileManager->GetFileManager(fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4GenericAnalysisManager::SetNtupleMerging(
|
||||
G4bool mergeNtuples, G4int nofReducedNtupleFiles)
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4HnInformation;
|
||||
class G4VNtupleFileManager;
|
||||
@@ -52,7 +53,7 @@ class G4GenericFileManager : public G4VFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4GenericFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4GenericFileManager();
|
||||
virtual ~G4GenericFileManager() = default;
|
||||
|
||||
// Method to manipulate a default file
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
@@ -63,50 +64,58 @@ class G4GenericFileManager : public G4VFileManager
|
||||
virtual G4bool CloseFiles() final;
|
||||
virtual G4bool DeleteEmptyFiles() final;
|
||||
|
||||
// Clear all data
|
||||
virtual void Clear() final;
|
||||
|
||||
// Methods applied to file per name
|
||||
virtual G4bool CreateFile(const G4String& fileName) final;
|
||||
virtual G4bool WriteFile(const G4String& fileName) final;
|
||||
virtual G4bool CloseFile(const G4String& fileName) final;
|
||||
virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) final;
|
||||
|
||||
virtual G4bool SetHistoDirectoryName(const G4String& dirName);
|
||||
virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
|
||||
|
||||
virtual G4String GetFileType() const final { return ""; }
|
||||
|
||||
// set default output type (backward compatibility)
|
||||
// Set default output type (backward compatibility)
|
||||
// this type will be used for file names without extension
|
||||
void SetDefaultFileType(const G4String& value);
|
||||
G4String GetDefaultFileType() const;
|
||||
|
||||
template <typename T>
|
||||
G4bool WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector);
|
||||
// Get file manager for a specific output type
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName);
|
||||
|
||||
template <typename T>
|
||||
G4bool WriteTExtra(const G4String& fileName, T* ht, const G4String& htName);
|
||||
template <typename HT>
|
||||
G4bool WriteTExtra(const G4String& fileName, HT* ht, const G4String& htName);
|
||||
|
||||
// methods
|
||||
// Methods
|
||||
std::shared_ptr<G4VNtupleFileManager> CreateNtupleFileManager(G4AnalysisOutput output);
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
void CreateFileManager(G4AnalysisOutput output);
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(G4AnalysisOutput output) const;
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName);
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(G4AnalysisOutput output) const;
|
||||
|
||||
// constants
|
||||
static const G4String fgkDefaultFileType;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4GenericFileManager" };
|
||||
// inline static const G4String fgkDefaultFileType { "root" };
|
||||
// inline static const G4String fgkDefaultFileType { "undefined" };
|
||||
|
||||
// data members
|
||||
// Data members
|
||||
G4String fDefaultFileType;
|
||||
std::shared_ptr<G4VFileManager> fDefaultFileManager;
|
||||
std::vector<std::shared_ptr<G4VFileManager>> fFileManagers;
|
||||
|
||||
std::shared_ptr<G4CsvFileManager> fCsvFileManager;
|
||||
std::shared_ptr<G4VFileManager> fDefaultFileManager { nullptr };
|
||||
std::vector<std::shared_ptr<G4VFileManager>> fFileManagers {
|
||||
// Csv, Hdf5, Root, Xml
|
||||
nullptr, nullptr, nullptr, nullptr
|
||||
};
|
||||
std::shared_ptr<G4CsvFileManager> fCsvFileManager { nullptr };
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
std::shared_ptr<G4Hdf5FileManager> fHdf5FileManager;
|
||||
std::shared_ptr<G4Hdf5FileManager> fHdf5FileManager { nullptr };
|
||||
#endif
|
||||
std::shared_ptr<G4RootFileManager> fRootFileManager;
|
||||
std::shared_ptr<G4XmlFileManager> fXmlFileManager;
|
||||
G4bool fHdf5Warn;
|
||||
std::shared_ptr<G4RootFileManager> fRootFileManager { nullptr };
|
||||
std::shared_ptr<G4XmlFileManager> fXmlFileManager { nullptr };
|
||||
G4bool fHdf5Warn { true };
|
||||
};
|
||||
|
||||
#include "G4GenericFileManager.icc"
|
||||
|
||||
@@ -33,122 +33,26 @@ inline G4String G4GenericFileManager::GetDefaultFileType() const
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4GenericFileManager::WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
|
||||
auto name = info->GetName();
|
||||
auto ht = htVector[i];
|
||||
|
||||
auto fileName = info->GetFileName();
|
||||
|
||||
auto fileManager = fDefaultFileManager;
|
||||
auto fileKind = "default";
|
||||
if ( fileName == "" ) {
|
||||
fileName = fileManager->GetFileName();
|
||||
} else {
|
||||
fileManager = GetFileManager(fileName);
|
||||
fileKind = "extra";
|
||||
// skip writing if cannot get file manager (wrong file extension)
|
||||
if ( ! fileManager ) {
|
||||
if ( G4Analysis::GetExtension(fileName) != "hdf5" || fHdf5Warn ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot get file manager for " << fileKind << " file " << fileName << "." << G4endl
|
||||
<< "Writing " << G4Analysis::GetHnType<T>() << " " << name
|
||||
<< " will be skipped.";
|
||||
G4Exception("G4GenericFileManager::WriteT",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << name << " in the " << fileKind << " file " << fileName;
|
||||
fState.GetVerboseL3()
|
||||
->Message("write", G4Analysis::GetHnType<T>(), description, false);
|
||||
}
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << name << " in the " << fileKind << " file " << fileName;
|
||||
fState.GetVerboseL3()
|
||||
->Message("write", G4Analysis::GetHnType<T>(), description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto result = fileManager->GetHnFileManager<T>()->Write(ht, name, fileName);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Writing " << G4Analysis::GetHnType<T>() << " " << name
|
||||
<< " to file " << fileName << " failed.";
|
||||
G4Exception("G4GenericManager::WriteT()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
}
|
||||
finalResult = result && finalResult;
|
||||
|
||||
// notify that file has a written object
|
||||
fileManager->SetIsEmpty(fileName, false);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << name << " in the " << fileKind << " file " << fileName;
|
||||
fState.GetVerboseL3()
|
||||
->Message("write", G4Analysis::GetHnType<T>(), description, finalResult);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4GenericFileManager::WriteTExtra(
|
||||
const G4String& fileName, T* ht, const G4String& htName)
|
||||
const G4String& fileName, HT* ht, const G4String& htName)
|
||||
{
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< fileName << " with " << G4Analysis::GetHnType<T>() << " " << htName;
|
||||
fState.GetVerboseL4()->Message("write", "extra file", description);
|
||||
}
|
||||
Message(G4Analysis::kVL4, "write", "extra file",
|
||||
fileName + " with " + G4Analysis::GetHnType<HT>() + " " + htName);
|
||||
|
||||
std::shared_ptr<G4VFileManager> fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot get file manager for file " << fileName << "." << G4endl
|
||||
<< "Writing " << G4Analysis::GetHnType<T>() << " " << htName
|
||||
<< " failed.";
|
||||
G4Exception("G4GenericFileManager::WriteTExtra",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Cannot get file manager for " + fileName + " .\n" +
|
||||
"Writing " + G4Analysis::GetHnType<HT>() + " " + htName + " failed.",
|
||||
fkClass, "WriteTExtra");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto result = fileManager->GetHnFileManager<T>()->WriteExtra(ht, htName, fileName);
|
||||
auto result = fileManager->GetHnFileManager<HT>()->WriteExtra(ht, htName, fileName);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() ) {
|
||||
fState.GetVerboseL1()->Message("write", "extra file", fileName, result);
|
||||
}
|
||||
#endif
|
||||
Message(G4Analysis::kVL1, "write", "extra file", fileName, result);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@ endif()
|
||||
# Define the Geant4 Module.
|
||||
geant4_add_module(G4analysisfac
|
||||
PUBLIC_HEADERS
|
||||
g4analysis.hh
|
||||
g4analysis_defs.hh
|
||||
G4AnalysisManager.hh
|
||||
G4GenericAnalysisManager.hh
|
||||
G4GenericAnalysisManager.icc
|
||||
G4GenericFileManager.hh
|
||||
G4GenericFileManager.icc
|
||||
SOURCES
|
||||
g4analysis.cc
|
||||
G4GenericAnalysisManager.cc
|
||||
G4GenericFileManager.cc)
|
||||
|
||||
|
||||
@@ -28,85 +28,63 @@
|
||||
|
||||
#include "G4GenericAnalysisManager.hh"
|
||||
#include "G4GenericFileManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4NtupleBookingManager.hh"
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Exception.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
using std::to_string;
|
||||
|
||||
// mutex in a file scope
|
||||
|
||||
namespace {
|
||||
|
||||
//Mutex to lock master manager when merging histograms
|
||||
G4Mutex mergeHnMutex = G4MUTEX_INITIALIZER;
|
||||
|
||||
void WriteHnException(const G4String& hnType, G4int id)
|
||||
//_____________________________________________________________________________
|
||||
void WriteHnWarning(const G4String& hnType, G4int id,
|
||||
std::string_view inClass,
|
||||
std::string_view inFunction)
|
||||
{
|
||||
G4String inFunction = "G4GenericAnalysisManager::Write" + hnType;
|
||||
G4ExceptionDescription description;
|
||||
description << "Failed to get " << hnType << " id " << id << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W022", JustWarning, description);
|
||||
Warn("Failed to get " + hnType + " id " + to_string(id), inClass, inFunction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
G4GenericAnalysisManager* G4GenericAnalysisManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4GenericAnalysisManager* G4GenericAnalysisManager::fgInstance = nullptr;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericAnalysisManager* G4GenericAnalysisManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4GenericAnalysisManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
static G4ThreadLocalSingleton<G4GenericAnalysisManager> instance;
|
||||
fgIsInstance = true;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::IsInstance()
|
||||
{
|
||||
return ( fgInstance != nullptr );
|
||||
}
|
||||
return fgIsInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericAnalysisManager::G4GenericAnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("", isMaster),
|
||||
fFileManager(nullptr),
|
||||
fNtupleFileManager(nullptr)
|
||||
G4GenericAnalysisManager::G4GenericAnalysisManager()
|
||||
: G4ToolsAnalysisManager("")
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4GenericAnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4GenericAnalysisManager::G4GenericAnalysisManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// File manager
|
||||
fFileManager = std::make_shared<G4GenericFileManager>(fState);
|
||||
SetFileManager(fFileManager);
|
||||
SetFileManager(fFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericAnalysisManager::~G4GenericAnalysisManager()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
fgIsInstance = false;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -114,84 +92,70 @@ G4GenericAnalysisManager::~G4GenericAnalysisManager()
|
||||
void G4GenericAnalysisManager::CreateNtupleFileManager(const G4String& fileName)
|
||||
{
|
||||
if ( fNtupleFileManager ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "The ntuple file manager already exists.";
|
||||
G4Exception("G4GenericAnalysisManager::CreateNtupleFileManager",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
Warn("The ntuple file manager already exists.",
|
||||
fkClass, "CreateNtupleFileManager");
|
||||
return;
|
||||
}
|
||||
|
||||
auto fileType = GetExtension(fileName);
|
||||
auto output = G4Analysis::GetOutput(fileType);
|
||||
if ( output == G4AnalysisOutput::kNone ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "The file type " << fileType << "is not supported.";
|
||||
G4Exception("G4GenericAnalysisManager::CreateNtupleFileManager",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
Warn("The file type " + fileType + "is not supported.",
|
||||
fkClass, "CreateNtupleFileManager");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set file type to booked ntuples
|
||||
fNtupleBookingManager->SetFileType(fileType);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("create", "ntuple file manager", fileType);
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "create", "ntuple file manager", fileType);
|
||||
|
||||
fNtupleFileManager = fFileManager->CreateNtupleFileManager(output);
|
||||
if (fNtupleFileManager) {
|
||||
fNtupleFileManager->SetBookingManager(fNtupleBookingManager);
|
||||
|
||||
if ( fNtupleFileManager->IsNtupleMergingSupported() ) {
|
||||
// set merginng
|
||||
fNtupleFileManager->SetNtupleMerging(fMergeNtuples, fNofNtupleFiles);
|
||||
fNtupleFileManager->SetNtupleRowWise(fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleFileManager->SetBasketSize(fBasketSize);
|
||||
fNtupleFileManager->SetBasketEntries(fBasketEntries);
|
||||
}
|
||||
else if ( fIsNtupleMergingSet && fMergeNtuples ) {
|
||||
Warn("Ntuple merging is not available with " + fileType + " output.\n" +
|
||||
"Setting is ignored.",
|
||||
fkClass, "CreateNtupleFileManager");
|
||||
}
|
||||
}
|
||||
|
||||
if ( fNtupleFileManager->IsNtupleMergingSupported() ) {
|
||||
// set merginng
|
||||
fNtupleFileManager->SetNtupleMerging(fMergeNtuples, fNofNtupleFiles);
|
||||
fNtupleFileManager->SetNtupleRowWise(fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleFileManager->SetBasketSize(fBasketSize);
|
||||
fNtupleFileManager->SetBasketEntries(fBasketEntries);
|
||||
}
|
||||
else if ( fIsNtupleMergingSet && fMergeNtuples ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "Ntuple merging is not available with "
|
||||
<< fileType << " output." << G4endl
|
||||
<< " " << "Setting is ignored.";
|
||||
G4Exception("G4GenericAnalysisManager::CreateNtupleFileManager",
|
||||
"Analysis_W041", JustWarning, description);
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("create", "ntuple file manager", fileType, true);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "create", "ntuple file manager", fileType);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
Message(kVL4, "open", "file", fileName);
|
||||
|
||||
// Add file name extension, if missing
|
||||
auto fullFileName = fileName;
|
||||
if ( ! GetExtension(fileName).size() ) {
|
||||
// G4cout << "File type is not defined, using default: " << fFileManager->GetDefaultFileType() << G4endl;
|
||||
auto defaultFileType = fFileManager->GetDefaultFileType();
|
||||
// G4cout << "File type is not defined, using default: " << defaultFileType << G4endl;
|
||||
if ( ! defaultFileType.size() ) {
|
||||
G4Exception("G4GenericAnalysisManager::OpenFileImpl", "Analysis_F001",
|
||||
FatalException,
|
||||
G4String("Cannot open file \"" + fileName + "\".\n"
|
||||
"Please, use a file name with an extension or define the default file type\n"
|
||||
"via G4AnalysisManager::SetDefaultFileType()"));
|
||||
}
|
||||
|
||||
fullFileName = fileName + "." + fFileManager->GetDefaultFileType();
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("open (generic)", "file", fileName);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create ntuple file manager if there are booked ntuples
|
||||
if (! fNtupleFileManager) {
|
||||
CreateNtupleFileManager(fullFileName);
|
||||
@@ -203,202 +167,106 @@ G4bool G4GenericAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
}
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Open file for histograms/profiles
|
||||
auto result = fFileManager->OpenFile(fullFileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->OpenFile(fullFileName);
|
||||
|
||||
// Open ntuple file(s) and create ntuples from bookings
|
||||
if (fNtupleFileManager) {
|
||||
result = fNtupleFileManager->ActionAtOpenFile(fullFileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtOpenFile(fullFileName);
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("open (generic)", "file", fileName, finalResult);
|
||||
}
|
||||
#endif
|
||||
return finalResult;
|
||||
Message(kVL3, "open", "file", fileName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::WriteImpl()
|
||||
G4bool G4GenericAnalysisManager::WriteImpl()
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write (generic)", "files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "write", "files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
if ( ! fgMasterInstance &&
|
||||
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ||
|
||||
( ! fH3Manager->IsEmpty() ) || ( ! fP1Manager->IsEmpty() ) ||
|
||||
( ! fP2Manager->IsEmpty() ) ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "No master G4GenericAnalysisManager instance exists."
|
||||
<< G4endl
|
||||
<< " " << "Histogram/profile data will not be merged.";
|
||||
G4Exception("G4GenericAnalysisManager::Write()",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
}
|
||||
|
||||
if ( G4Threading::IsWorkerThread() ) {
|
||||
result = Merge();
|
||||
finalResult = finalResult && result;
|
||||
result &= G4ToolsAnalysisManager::Merge();
|
||||
}
|
||||
else {
|
||||
// GO ON
|
||||
|
||||
// Open all files registered with objects
|
||||
fFileManager->OpenFiles();
|
||||
|
||||
// Write all histograms/profile on master
|
||||
//
|
||||
result = fFileManager->WriteT(fH1Manager->GetH1Vector(), fH1Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fFileManager->WriteT(fH2Manager->GetH2Vector(), fH2Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fFileManager->WriteT(fH3Manager->GetH3Vector(), fH3Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fFileManager->WriteT(fP1Manager->GetP1Vector(), fP1Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fFileManager->WriteT(fP2Manager->GetP2Vector(), fP2Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
result &= G4ToolsAnalysisManager::WriteImpl();
|
||||
}
|
||||
|
||||
// Ntuples
|
||||
if (fNtupleFileManager) {
|
||||
result = fNtupleFileManager->ActionAtWrite();
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtWrite();
|
||||
}
|
||||
|
||||
// File
|
||||
result = fFileManager->WriteFiles();
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->WriteFiles();
|
||||
|
||||
// Write ASCII if activated
|
||||
if ( IsAscii() ) {
|
||||
result = WriteAscii(fFileManager->GetFileName());
|
||||
finalResult = finalResult && result;
|
||||
result &= WriteAscii(fFileManager->GetFileName());
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("write (generic)", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "write", "files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("close (generic)", "files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "close", "files");
|
||||
|
||||
auto result = true;
|
||||
if (fNtupleFileManager) {
|
||||
auto result = fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
}
|
||||
|
||||
// close file
|
||||
auto result = fFileManager->CloseFiles();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Closing files failed";
|
||||
G4Exception("G4GenericAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
if ( ! fFileManager->CloseFiles() ) {
|
||||
Warn("Closing files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// delete empty files
|
||||
result = fFileManager->DeleteEmptyFiles();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Deleting empty files failed";
|
||||
G4Exception("G4GenericAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
if ( ! fFileManager->DeleteEmptyFiles() ) {
|
||||
Warn("Deleting empty files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
if ( reset ) {
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4GenericAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
if ( ! Reset() ) {
|
||||
Warn("Resetting data failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("close (generic)", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "close", "files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::Reset()
|
||||
G4bool G4GenericAnalysisManager::ResetImpl()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
Message(kVL4, "reset", "");
|
||||
|
||||
auto result = G4ToolsAnalysisManager::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleFileManager->Reset();
|
||||
finalResult = result && finalResult;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::Merge()
|
||||
{
|
||||
// Nothing to be done on master
|
||||
if ( ! G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("merge (generic) on worker", "histograms", "");
|
||||
auto result = true;
|
||||
result &= G4ToolsAnalysisManager::ResetImpl();
|
||||
if ( fNtupleFileManager != nullptr ) {
|
||||
result &= fNtupleFileManager->Reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
// The worker manager just adds its histograms to the master
|
||||
fH1Manager->Merge(mergeHnMutex, fgMasterInstance->fH1Manager);
|
||||
fH2Manager->Merge(mergeHnMutex, fgMasterInstance->fH2Manager);
|
||||
fH3Manager->Merge(mergeHnMutex, fgMasterInstance->fH3Manager);
|
||||
fP1Manager->Merge(mergeHnMutex, fgMasterInstance->fP1Manager);
|
||||
fP2Manager->Merge(mergeHnMutex, fgMasterInstance->fP2Manager);
|
||||
Message(kVL3, "reset", "", "", result);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("merge (generic) on worker", "histograms", "", true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -412,9 +280,9 @@ G4bool G4GenericAnalysisManager::WriteH1(G4int id, const G4String& fileName)
|
||||
|
||||
auto h1d = GetH1(id, false);
|
||||
if ( ! h1d ) {
|
||||
WriteHnException("H1", id);
|
||||
WriteHnWarning("H1", id, fkClass, "WriteH1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto h1Name = GetH1Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::h1d>(fileName, h1d, h1Name);
|
||||
@@ -431,9 +299,9 @@ G4bool G4GenericAnalysisManager::WriteH2(G4int id, const G4String& fileName)
|
||||
|
||||
auto h2d = GetH2(id, false);
|
||||
if ( ! h2d ) {
|
||||
WriteHnException("H2", id);
|
||||
WriteHnWarning("H2", id, fkClass, "WriteH2");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto h2Name = GetH2Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::h2d>(fileName, h2d, h2Name);
|
||||
@@ -449,9 +317,9 @@ G4bool G4GenericAnalysisManager::WriteH3(G4int id, const G4String& fileName)
|
||||
|
||||
auto h3d = GetH3(id, false);
|
||||
if ( ! h3d ) {
|
||||
WriteHnException("H3", id);
|
||||
WriteHnWarning("H3", id, fkClass, "WriteH3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto h3Name = GetH3Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::h3d>(fileName, h3d, h3Name);
|
||||
@@ -468,9 +336,9 @@ G4bool G4GenericAnalysisManager::WriteP1(G4int id, const G4String& fileName)
|
||||
|
||||
auto p1d = GetP1(id, false);
|
||||
if ( ! p1d ) {
|
||||
WriteHnException("P1", id);
|
||||
WriteHnWarning("P1", id, fkClass, "WriteP1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto p1Name = GetP1Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::p1d>(fileName, p1d, p1Name);
|
||||
@@ -486,9 +354,9 @@ G4bool G4GenericAnalysisManager::WriteP2(G4int id, const G4String& fileName)
|
||||
|
||||
auto p2d = GetP2(id, false);
|
||||
if ( ! p2d ) {
|
||||
WriteHnException("P2", id);
|
||||
WriteHnWarning("P2", id, fkClass, "WriteP2");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto p2Name = GetP2Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::p2d>(fileName, p2d, p2Name);
|
||||
|
||||
@@ -40,52 +40,27 @@
|
||||
#include "G4XmlFileManager.hh"
|
||||
#include "G4XmlNtupleFileManager.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
namespace {
|
||||
|
||||
void FileManagerException(const G4String& fileName, const G4String& functionName,
|
||||
const G4String& exceptionClassification, G4bool hdf5Warn = true)
|
||||
//_____________________________________________________________________________
|
||||
void FileManagerWarning(const G4String& fileName,
|
||||
std::string_view className,
|
||||
std::string_view functionName,
|
||||
G4bool hdf5Warn = true)
|
||||
{
|
||||
if ( GetExtension(fileName) == "hdf5" && ( ! hdf5Warn ) ) return;
|
||||
|
||||
G4String where = "G4GenericFileManager::" + functionName;
|
||||
G4String what = "Analysis_" + exceptionClassification;
|
||||
G4ExceptionDescription description;
|
||||
description << "Cannot get file manager for " << fileName;
|
||||
G4Exception(where, what, JustWarning, description);
|
||||
Warn("Cannot get file manager for " + fileName,
|
||||
className, functionName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// static data
|
||||
const G4String G4GenericFileManager::fgkDefaultFileType = "root";
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericFileManager::G4GenericFileManager(const G4AnalysisManagerState& state)
|
||||
: G4VFileManager(state),
|
||||
fDefaultFileType(fgkDefaultFileType),
|
||||
fDefaultFileManager(nullptr),
|
||||
fFileManagers
|
||||
{ nullptr, // Csv
|
||||
nullptr, // Hdf5
|
||||
nullptr, // Generic
|
||||
nullptr // Xml
|
||||
},
|
||||
fCsvFileManager(nullptr),
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
fHdf5FileManager(nullptr),
|
||||
#endif
|
||||
fRootFileManager(nullptr),
|
||||
fXmlFileManager(nullptr),
|
||||
fHdf5Warn(true)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericFileManager::~G4GenericFileManager()
|
||||
: G4VFileManager(state)
|
||||
{}
|
||||
|
||||
//
|
||||
@@ -95,20 +70,13 @@ G4GenericFileManager::~G4GenericFileManager()
|
||||
//_____________________________________________________________________________
|
||||
void G4GenericFileManager::CreateFileManager(G4AnalysisOutput output)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("create", "file manager", GetOutputName(output));
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "create", "file manager", GetOutputName(output));
|
||||
|
||||
auto outputId = static_cast<size_t>(output);
|
||||
auto outputId = static_cast<size_t>(output);
|
||||
if ( fFileManagers[outputId] ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "The file manager of " << G4Analysis::GetOutputName(output) << " type already exists.";
|
||||
G4Exception("G4GenericFileManager::CreateFileManager",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
Warn("The file manager of " + G4Analysis::GetOutputName(output) +
|
||||
" type already exists.",
|
||||
fkClass, "CreateFileManager");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,16 +86,13 @@ void G4GenericFileManager::CreateFileManager(G4AnalysisOutput output)
|
||||
fCsvFileManager = std::make_shared<G4CsvFileManager>(fState);
|
||||
fFileManagers[outputId] = fCsvFileManager;
|
||||
break;
|
||||
case G4AnalysisOutput::kHdf5:
|
||||
case G4AnalysisOutput::kHdf5:
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
fHdf5FileManager = std::make_shared<G4Hdf5FileManager>(fState);
|
||||
fFileManagers[outputId] = fHdf5FileManager;
|
||||
#else
|
||||
if ( fHdf5Warn) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Hdf5 type is not available.";
|
||||
G4Exception("G4GenericFileManager::CreateFileManager",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
Warn("Hdf5 type is not available.", fkClass, "CreateFileManager");
|
||||
fHdf5Warn = false;
|
||||
}
|
||||
#endif
|
||||
@@ -141,30 +106,31 @@ void G4GenericFileManager::CreateFileManager(G4AnalysisOutput output)
|
||||
fFileManagers[outputId] = fXmlFileManager ;
|
||||
break;
|
||||
case G4AnalysisOutput::kNone:
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< G4Analysis::GetOutputName(output) << " type is not supported.";
|
||||
G4Exception("G4GenericFileManager::CreateFileManager",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
break;
|
||||
Warn(G4Analysis::GetOutputName(output) + " type is not supported.",
|
||||
fkClass, "CreateFileManager");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("create", "file manager", GetOutputName(output));
|
||||
// Pass directory names (only if set)
|
||||
if ( ! GetHistoDirectoryName().empty() ) {
|
||||
fFileManagers[outputId]->SetHistoDirectoryName(GetHistoDirectoryName());
|
||||
}
|
||||
#endif
|
||||
if ( ! GetNtupleDirectoryName().empty() ) {
|
||||
fFileManagers[outputId]->SetNtupleDirectoryName(GetNtupleDirectoryName());
|
||||
}
|
||||
|
||||
Message(kVL3, "create", "file manager", GetOutputName(output));
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4VFileManager>
|
||||
std::shared_ptr<G4VFileManager>
|
||||
G4GenericFileManager::GetFileManager(G4AnalysisOutput output) const
|
||||
{
|
||||
return fFileManagers[static_cast<size_t>(output)];
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4VFileManager>
|
||||
std::shared_ptr<G4VFileManager>
|
||||
G4GenericFileManager::GetFileManager(const G4String& fileName)
|
||||
{
|
||||
// Get file extension
|
||||
@@ -176,12 +142,8 @@ G4GenericFileManager::GetFileManager(const G4String& fileName)
|
||||
|
||||
auto output = G4Analysis::GetOutput(extension);
|
||||
if ( output == G4AnalysisOutput::kNone ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "The file extension " << extension << "is not supported.";
|
||||
G4Exception("G4GenericFileManager::GetFileManager",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
Warn("The file extension " + extension + "is not supported.",
|
||||
fkClass, "GetFileManager");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -207,45 +169,30 @@ G4bool G4GenericFileManager::OpenFile(const G4String& fileName)
|
||||
if ( fDefaultFileManager && (fDefaultFileManager != fileManager) ) {
|
||||
// Print warning if default output changed
|
||||
// (maybe be not needed?)
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Default file manager changed (old: "
|
||||
<< fDefaultFileManager->GetFileType()
|
||||
<< ", new:" << fileManager->GetFileType() << ")";
|
||||
G4Exception("G4GenericFileManager::OpenFile",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
}
|
||||
fDefaultFileManager = fileManager;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("open", "analysis file", fileName);
|
||||
Warn("Default file manager changed "
|
||||
"(old: " +fDefaultFileManager->GetFileType() +
|
||||
", new:" + fileManager->GetFileType() + ")",
|
||||
fkClass, "OpenFile");
|
||||
}
|
||||
#endif
|
||||
fDefaultFileManager = fileManager;
|
||||
fDefaultFileType = fileManager->GetFileType();
|
||||
|
||||
Message(kVL4, "open", "analysis file", fileName);
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Save the default file name
|
||||
// Save the default file name
|
||||
// both in the generic file manager and the output specific one
|
||||
result = SetFileName(fileName);
|
||||
finalResult = finalResult && result;
|
||||
result = fDefaultFileManager->SetFileName(fileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= SetFileName(fileName);
|
||||
result &= fDefaultFileManager->SetFileName(fileName);
|
||||
result &= fDefaultFileManager->OpenFile(fileName);
|
||||
|
||||
result = fDefaultFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() ) {
|
||||
fState.GetVerboseL1()->Message("open", "analysis file", fileName, finalResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
fLockDirectoryNames = true;
|
||||
LockDirectoryNames();
|
||||
fIsOpenFile = true;
|
||||
|
||||
return finalResult;
|
||||
Message(kVL1, "open", "analysis file", fileName, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -253,70 +200,46 @@ G4bool G4GenericFileManager::OpenFiles()
|
||||
{
|
||||
// Open all files regeistered with objects
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("open", "analysis files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "open", "analysis files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// process names registered in base file manager
|
||||
for ( auto fileName : GetFileNames() ) {
|
||||
for ( const auto& fileName : GetFileNames() ) {
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "OpenFiles", "W001", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "OpenFiles", fHdf5Warn);
|
||||
continue;
|
||||
}
|
||||
|
||||
result = fileManager->CreateFile(fileName);
|
||||
finalResult = result && finalResult;
|
||||
result &= fileManager->CreateFile(fileName);
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("open", "analysis files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "open", "analysis files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericFileManager::WriteFiles()
|
||||
{
|
||||
// Finish write for all files regeistered with objects
|
||||
// Finish write for all files registered with objects
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write", "files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "write", "analysis files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
for ( auto fileManager : fFileManagers ) {
|
||||
for ( const auto& fileManager : fFileManagers ) {
|
||||
if ( ! fileManager ) continue;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write", fileManager->GetFileType(), "files");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "write", fileManager->GetFileType(), "files");
|
||||
|
||||
result = fileManager->WriteFiles();
|
||||
finalResult = result && finalResult;
|
||||
result &= fileManager->WriteFiles();
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("write", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "write", "analysis files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -324,35 +247,21 @@ G4bool G4GenericFileManager::CloseFiles()
|
||||
{
|
||||
// Close all files regeistered with objects
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("close", "files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "close", "analysis files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
for ( auto fileManager : fFileManagers ) {
|
||||
for ( const auto& fileManager : fFileManagers ) {
|
||||
if ( ! fileManager ) continue;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("close", fileManager->GetFileType(), "files");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "close", fileManager->GetFileType(), "files");
|
||||
|
||||
result = fileManager->CloseFiles();
|
||||
finalResult = result && finalResult;
|
||||
result &= fileManager->CloseFiles();
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("close", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "close", "analysis files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -360,35 +269,34 @@ G4bool G4GenericFileManager::DeleteEmptyFiles()
|
||||
{
|
||||
// Close all files regeistered with objects
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("delete", "empty files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "delete", "empty files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
for ( auto fileManager : fFileManagers ) {
|
||||
for ( const auto& fileManager : fFileManagers ) {
|
||||
if ( ! fileManager ) continue;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("delete", fileManager->GetFileType(), "files");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "delete", fileManager->GetFileType(), "empty files");
|
||||
|
||||
result = fileManager->DeleteEmptyFiles();
|
||||
finalResult = result && finalResult;
|
||||
result &= fileManager->DeleteEmptyFiles();
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("delete", "empty files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "delete", "empty files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4GenericFileManager::Clear()
|
||||
{
|
||||
// Clear files data
|
||||
|
||||
for ( const auto& fileManager : fFileManagers ) {
|
||||
if ( ! fileManager ) continue;
|
||||
|
||||
fileManager->Clear();
|
||||
}
|
||||
UnlockDirectoryNames();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -398,7 +306,7 @@ G4bool G4GenericFileManager::CreateFile(const G4String& fileName)
|
||||
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "CreateFile", "W001", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "CreateFile", fHdf5Warn);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -412,7 +320,7 @@ G4bool G4GenericFileManager::WriteFile(const G4String& fileName)
|
||||
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "WriteFile", "W021", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "WriteFile", fHdf5Warn);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -426,7 +334,7 @@ G4bool G4GenericFileManager::CloseFile(const G4String& fileName)
|
||||
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "CloseFile", "W021", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "CloseFile", fHdf5Warn);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -438,25 +346,48 @@ G4bool G4GenericFileManager::SetIsEmpty(const G4String& fileName, G4bool isEmpty
|
||||
{
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "SetIsEmpty", "W021", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "SetIsEmpty", fHdf5Warn);
|
||||
return false;
|
||||
}
|
||||
|
||||
return fileManager->SetIsEmpty(fileName, isEmpty);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericFileManager::SetHistoDirectoryName(const G4String& dirName)
|
||||
{
|
||||
auto result = G4VFileManager::SetHistoDirectoryName(dirName);
|
||||
|
||||
for (auto fileManager : fFileManagers ) {
|
||||
if ( fileManager != nullptr ) {
|
||||
result &= fileManager->SetHistoDirectoryName(dirName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericFileManager::SetNtupleDirectoryName(const G4String& dirName)
|
||||
{
|
||||
auto result = G4VFileManager::SetNtupleDirectoryName(dirName);
|
||||
|
||||
for (auto fileManager : fFileManagers ) {
|
||||
if ( fileManager != nullptr ) {
|
||||
result &= fileManager->SetNtupleDirectoryName(dirName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4GenericFileManager::SetDefaultFileType(const G4String& value)
|
||||
{
|
||||
// Check if value correspond to a valid file type
|
||||
auto output = G4Analysis::GetOutput(value);
|
||||
if ( output == G4AnalysisOutput::kNone ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "The file type " << value << "is not supported." << G4endl
|
||||
<< "The default type " << fDefaultFileType << " will be used.";
|
||||
G4Exception("G4GenericFileManager::SetDeafultFileType",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
Warn("The file type " + value + "is not supported.\n" +
|
||||
"The default type " + fDefaultFileType + " will be used.",
|
||||
fkClass, "SetDeafultFileType");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -464,7 +395,7 @@ void G4GenericFileManager::SetDefaultFileType(const G4String& value)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4VNtupleFileManager>
|
||||
std::shared_ptr<G4VNtupleFileManager>
|
||||
G4GenericFileManager::CreateNtupleFileManager(G4AnalysisOutput output)
|
||||
{
|
||||
if ( ! GetFileManager(output) ) {
|
||||
@@ -480,7 +411,7 @@ G4GenericFileManager::CreateNtupleFileManager(G4AnalysisOutput output)
|
||||
ntupleFileManager->SetFileManager(fCsvFileManager);
|
||||
vNtupleFileManager = ntupleFileManager;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case G4AnalysisOutput::kHdf5: {
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
auto ntupleFileManager = std::make_shared<G4Hdf5NtupleFileManager>(fState);
|
||||
@@ -508,13 +439,9 @@ G4GenericFileManager::CreateNtupleFileManager(G4AnalysisOutput output)
|
||||
}
|
||||
|
||||
if ( ! vNtupleFileManager ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Failed to create ntuple file manager of " << G4Analysis::GetOutputName(output) << " type."
|
||||
<< failure;
|
||||
G4Exception("G4GenericFileManager::CreateNtupleFileManager",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
Warn("Failed to create ntuple file manager of " +
|
||||
G4Analysis::GetOutputName(output) + " type.\n" + failure,
|
||||
fkClass, "CreateNtupleFileManager");
|
||||
}
|
||||
|
||||
return vNtupleFileManager;
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 09/09/2019 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "g4analysis.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4RootAnalysisManager.hh"
|
||||
#include "G4XmlAnalysisManager.hh"
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
#include "G4Hdf5AnalysisManager.hh"
|
||||
#endif
|
||||
#include "G4Exception.hh"
|
||||
|
||||
namespace {
|
||||
|
||||
void DoFatalException(const G4String& outputName)
|
||||
{
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " \"" << outputName << "\" output type is not supported." << G4endl
|
||||
<< " " << "Analysis manager cannot be created.";
|
||||
G4Exception("G4Analysis::ManagerInstance",
|
||||
"Analysis_F002", FatalException, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace G4Analysis
|
||||
{
|
||||
|
||||
G4ToolsAnalysisManager* ManagerInstance(const G4String& outputName)
|
||||
{
|
||||
// Get output type
|
||||
G4AnalysisOutput outputType = GetOutput(outputName, false);
|
||||
if ( outputType == G4AnalysisOutput::kNone ) {
|
||||
DoFatalException(outputName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create the analysis manager of a selected type
|
||||
switch ( outputType ) {
|
||||
case G4AnalysisOutput::kCsv:
|
||||
return G4CsvAnalysisManager::Instance();
|
||||
break;
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
case G4AnalysisOutput::kHdf5:
|
||||
return G4Hdf5AnalysisManager::Instance();
|
||||
break;
|
||||
#endif
|
||||
case G4AnalysisOutput::kRoot:
|
||||
return G4RootAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kXml:
|
||||
return G4XmlAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kNone:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// should never reach this line
|
||||
DoFatalException(outputName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Hdf5 analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -38,17 +38,22 @@
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4Hdf5AnalysisManager;
|
||||
class G4Hdf5FileManager;
|
||||
class G4Hdf5NtupleFileManager;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4Hdf5AnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4Hdf5AnalysisManager>;
|
||||
|
||||
public:
|
||||
explicit G4Hdf5AnalysisManager(G4bool isMaster = true);
|
||||
~G4Hdf5AnalysisManager();
|
||||
|
||||
// static methods
|
||||
virtual ~G4Hdf5AnalysisManager();
|
||||
|
||||
// Static methods
|
||||
static G4Hdf5AnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
@@ -61,42 +66,26 @@ class G4Hdf5AnalysisManager : public G4ToolsAnalysisManager
|
||||
std::vector<tools::hdf5::ntuple*>::iterator EndNtuple();
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator BeginConstNtuple() const;
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator EndConstNtuple() const;
|
||||
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
// Virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) final;
|
||||
virtual G4bool ResetImpl() final;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
|
||||
private:
|
||||
// constants
|
||||
static constexpr unsigned int fgkDefaultBasketSize = 32000;
|
||||
G4Hdf5AnalysisManager();
|
||||
|
||||
// static data members
|
||||
static G4Hdf5AnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4Hdf5AnalysisManager* fgInstance;
|
||||
// Static data members
|
||||
inline static G4Hdf5AnalysisManager* fgMasterInstance { nullptr };
|
||||
inline static G4ThreadLocal G4bool fgIsInstance { false };
|
||||
static constexpr std::string_view fkClass { "G4Hdf5AnalysisManager" };
|
||||
|
||||
// methods
|
||||
template <typename T>
|
||||
G4bool WriteHn(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType);
|
||||
template <typename T>
|
||||
G4bool WritePn(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType);
|
||||
G4bool WriteDirectory();
|
||||
G4bool WriteH1();
|
||||
G4bool WriteH2();
|
||||
G4bool WriteH3();
|
||||
G4bool WriteP1();
|
||||
G4bool WriteP2();
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4Hdf5NtupleFileManager> fNtupleFileManager;
|
||||
std::shared_ptr<G4Hdf5FileManager> fFileManager;
|
||||
// Data members
|
||||
std::shared_ptr<G4Hdf5NtupleFileManager> fNtupleFileManager { nullptr };
|
||||
std::shared_ptr<G4Hdf5FileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4Hdf5AnalysisManager.icc"
|
||||
|
||||
@@ -30,84 +30,6 @@
|
||||
#include "G4Hdf5NtupleManager.hh"
|
||||
#include "G4Hdf5FileManager.hh"
|
||||
|
||||
#include "tools/hdf5/h2file"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4Hdf5AnalysisManager::WriteHn(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
// Do nothing if there is no directory
|
||||
if ( directory < 0 ) return false;
|
||||
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()->Message("write", hnType, name);
|
||||
#endif
|
||||
|
||||
G4bool result
|
||||
= tools::hdf5::write_histo(G4cout, directory, name, *ht);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4Hdf5AnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
fFileManager->LockDirectoryNames();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4Hdf5AnalysisManager::WritePn(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
// Do nothing if there is no directory
|
||||
if ( directory < 0 ) return false;
|
||||
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()->Message("write", hnType, name);
|
||||
#endif
|
||||
|
||||
G4bool result
|
||||
= tools::hdf5::write_profile(G4cout, directory, name, *ht);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4Hdf5AnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
fFileManager->LockDirectoryNames();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
G4bool G4Hdf5AnalysisManager::IsOpenFileImpl() const
|
||||
@@ -120,41 +42,41 @@ inline
|
||||
tools::hdf5::ntuple* G4Hdf5AnalysisManager::GetNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::hdf5::ntuple* G4Hdf5AnalysisManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple(ntupleId);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::hdf5::ntuple*>::iterator G4Hdf5AnalysisManager::BeginNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::hdf5::ntuple*>::iterator G4Hdf5AnalysisManager::EndNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator
|
||||
G4Hdf5AnalysisManager::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator
|
||||
G4Hdf5AnalysisManager::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Hdf5 analysis reader.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -35,68 +35,49 @@
|
||||
#include "G4ToolsAnalysisReader.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4Hdf5AnalysisReader;
|
||||
class G4Hdf5RFileManager;
|
||||
class G4H1ToolsManager;
|
||||
class G4H2ToolsManager;
|
||||
class G4H3ToolsManager;
|
||||
class G4P1ToolsManager;
|
||||
class G4P2ToolsManager;
|
||||
class G4Hdf5RNtupleManager;
|
||||
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4Hdf5AnalysisReader : public G4ToolsAnalysisReader
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4Hdf5AnalysisReader>;
|
||||
|
||||
public:
|
||||
explicit G4Hdf5AnalysisReader(G4bool isMaster = true);
|
||||
virtual ~G4Hdf5AnalysisReader();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4Hdf5AnalysisReader* Instance();
|
||||
|
||||
|
||||
// Access methods
|
||||
tools::hdf5::ntuple* GetNtuple() const;
|
||||
tools::hdf5::ntuple* GetNtuple(G4int ntupleId) const;
|
||||
using G4VAnalysisReader::GetNtuple;
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
virtual G4int ReadH1Impl(const G4String& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH2Impl(const G4String& h2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH3Impl(const G4String& h3Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP1Impl(const G4String& p1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP2Impl(const G4String& p2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
static G4Hdf5AnalysisReader* fgMasterInstance;
|
||||
static G4ThreadLocal G4Hdf5AnalysisReader* fgInstance;
|
||||
|
||||
// methods
|
||||
//
|
||||
template <typename T>
|
||||
T* ReadHnImpl(const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName);
|
||||
template <typename T>
|
||||
T* ReadPnImpl(const G4String& ptName, const G4String& fileName,
|
||||
const G4String& dirName);
|
||||
protected:
|
||||
// Virtual methods from base class
|
||||
virtual G4bool CloseFilesImpl(G4bool reset) final;
|
||||
|
||||
private:
|
||||
G4Hdf5AnalysisReader();
|
||||
|
||||
// Methods
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4Hdf5RNtupleManager* fNtupleManager;
|
||||
G4Hdf5RFileManager* fFileManager;
|
||||
// Static data members
|
||||
inline static G4Hdf5AnalysisReader* fgMasterInstance { nullptr };
|
||||
static constexpr std::string_view fkClass { "G4Hdf5AnalysisReader" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4Hdf5RNtupleManager> fNtupleManager { nullptr };
|
||||
std::shared_ptr<G4Hdf5RFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4Hdf5AnalysisReader.icc"
|
||||
|
||||
@@ -24,86 +24,18 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
#include "G4Hdf5RFileManager.hh"
|
||||
|
||||
#include <tools/hdf5/h2file>
|
||||
|
||||
// //_____________________________________________________________________________
|
||||
// inline
|
||||
// tools::hdf5::ntuple* G4Hdf5AnalysisReader::GetNtuple() const
|
||||
// {
|
||||
// return fNtupleManager->GetNtuple();
|
||||
// }
|
||||
|
||||
// //_____________________________________________________________________________
|
||||
// inline
|
||||
// tools::hdf5::ntuple* G4Hdf5AnalysisReader::GetNtuple(G4int ntupleId) const
|
||||
// {
|
||||
// return fNtupleManager->GetNtuple(ntupleId);
|
||||
// }
|
||||
#include "G4Hdf5RNtupleManager.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
T* G4Hdf5AnalysisReader::ReadHnImpl(
|
||||
const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName)
|
||||
{
|
||||
// Get directory
|
||||
auto directory = fFileManager->GetHistoRDirectory(fileName, dirName, false);
|
||||
if ( directory < 0 ) return nullptr;
|
||||
|
||||
// Read hn
|
||||
T* ht;
|
||||
auto result = tools::hdf5::read_histo(G4cout, directory, htName, ht);
|
||||
if ( ! result ) return nullptr;
|
||||
|
||||
if ( ! ht ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Streaming " << htName << " from file " << fileName << " failed.";
|
||||
G4Exception("G4Hdf5AnalysisReader::ReadHnImpl",
|
||||
"Analysis_WR011", JustWarning, description);
|
||||
|
||||
// when failure, directory and file should be closed
|
||||
// ::H5Gclose(histos);
|
||||
// ::H5Fclose(file);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ht;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
T* G4Hdf5AnalysisReader::ReadPnImpl(
|
||||
const G4String& ptName, const G4String& fileName,
|
||||
const G4String& dirName)
|
||||
inline
|
||||
tools::hdf5::ntuple* G4Hdf5AnalysisReader::GetNtuple() const
|
||||
{
|
||||
// Get directory
|
||||
auto directory = fFileManager->GetHistoRDirectory(fileName, dirName, false);
|
||||
if ( directory < 0 ) return nullptr;
|
||||
return fNtupleManager->GetNtuple();
|
||||
}
|
||||
|
||||
// Read hn
|
||||
T* pt;
|
||||
auto result = tools::hdf5::read_profile(G4cout, directory, ptName, pt);
|
||||
if ( ! result ) return nullptr;
|
||||
|
||||
if ( ! pt ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Streaming " << ptName << " from file " << fileName << " failed.";
|
||||
G4Exception("G4Hdf5AnalysisReader::ReadPnImpl",
|
||||
"Analysis_WR011", JustWarning, description);
|
||||
|
||||
// when failure, directory and file should be closed
|
||||
// ::H5Gclose(histos);
|
||||
// ::H5Fclose(file);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return pt;
|
||||
}
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::hdf5::ntuple* G4Hdf5AnalysisReader::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleManager->GetNtuple(ntupleId);
|
||||
}
|
||||
|
||||
@@ -32,12 +32,14 @@
|
||||
#define G4Hdf5FileManager_h 1
|
||||
|
||||
#include "G4VTFileManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple" // for hid_t
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <string_view>
|
||||
|
||||
using G4Hdf5File = std::tuple<hid_t, hid_t, hid_t>;
|
||||
using Hdf5NtupleDescription = G4TNtupleDescription<tools::hdf5::ntuple, G4Hdf5File>;
|
||||
@@ -46,7 +48,8 @@ class G4Hdf5FileManager : public G4VTFileManager<G4Hdf5File>
|
||||
{
|
||||
public:
|
||||
explicit G4Hdf5FileManager(const G4AnalysisManagerState& state);
|
||||
~G4Hdf5FileManager();
|
||||
G4Hdf5FileManager() = delete;
|
||||
~G4Hdf5FileManager() = default;
|
||||
|
||||
using G4BaseFileManager::GetNtupleFileName;
|
||||
using G4VTFileManager<G4Hdf5File>::WriteFile;
|
||||
@@ -59,7 +62,7 @@ class G4Hdf5FileManager : public G4VTFileManager<G4Hdf5File>
|
||||
|
||||
// Specific methods for files per objects
|
||||
G4bool CreateNtupleFile(Hdf5NtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(Hdf5NtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(Hdf5NtupleDescription* ntupleDescription);
|
||||
|
||||
// Set methods
|
||||
void SetBasketSize(unsigned int basketSize);
|
||||
@@ -67,30 +70,31 @@ class G4Hdf5FileManager : public G4VTFileManager<G4Hdf5File>
|
||||
// Get methods
|
||||
hid_t GetHistoDirectory() const;
|
||||
hid_t GetNtupleDirectory() const;
|
||||
unsigned int GetBasketSize() const;
|
||||
|
||||
unsigned int GetBasketSize() const;
|
||||
|
||||
protected:
|
||||
// // Methods derived from templated base class
|
||||
// // Methods derived from base class
|
||||
virtual std::shared_ptr<G4Hdf5File> CreateFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteFileImpl(std::shared_ptr<G4Hdf5File> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<G4Hdf5File> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<G4Hdf5File> file) final;
|
||||
|
||||
private:
|
||||
hid_t CreateDirectory(hid_t& file, const G4String& directoryName,
|
||||
hid_t CreateDirectory(hid_t& file, const G4String& directoryName,
|
||||
const G4String& objectType);
|
||||
G4String GetNtupleFileName(Hdf5NtupleDescription* ntupleDescription);
|
||||
|
||||
// constants
|
||||
static const G4String fgkDefaultDirectoryName;
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4Hdf5FileManager" };
|
||||
inline static const G4String fgkDefaultDirectoryName { "default" };
|
||||
|
||||
// data members
|
||||
unsigned int fBasketSize;
|
||||
unsigned int fBasketSize { G4Analysis::kDefaultBasketSize };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4Hdf5FileManager::SetBasketSize(unsigned int basketSize)
|
||||
inline void G4Hdf5FileManager::SetBasketSize(unsigned int basketSize)
|
||||
{ fBasketSize = basketSize; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
@@ -35,15 +35,18 @@
|
||||
|
||||
#include "tools/hdf5/ntuple" // for hid_t
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4Hdf5FileManager;
|
||||
|
||||
template <typename HT>
|
||||
class G4Hdf5HnFileManager : public G4VTHnFileManager<HT>
|
||||
{
|
||||
public:
|
||||
G4Hdf5HnFileManager(G4Hdf5FileManager* fileManger)
|
||||
: G4VTHnFileManager<HT>(), fFileManager(fileManger) {}
|
||||
virtual ~G4Hdf5HnFileManager() {}
|
||||
explicit G4Hdf5HnFileManager(G4Hdf5FileManager* fileManger)
|
||||
: G4VTHnFileManager<HT>(), fFileManager(fileManger) {}
|
||||
G4Hdf5HnFileManager() = delete;
|
||||
virtual ~G4Hdf5HnFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
// Write to a new file (the file is closed after write)
|
||||
@@ -51,11 +54,13 @@ class G4Hdf5HnFileManager : public G4VTHnFileManager<HT>
|
||||
// Write to the default file (handled with OpenFile()/CloseFile methods)
|
||||
virtual G4bool Write(HT* ht, const G4String& htName, G4String& fileName) final;
|
||||
|
||||
private:
|
||||
private:
|
||||
// Methods
|
||||
G4bool WriteImpl(hid_t hdirectory, HT* ht, const G4String& htName);
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4Hdf5HnFileManager<HT>" };
|
||||
// Data members
|
||||
G4Hdf5FileManager* fFileManager;
|
||||
G4Hdf5FileManager* fFileManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/hdf5/header"
|
||||
#include "tools/hdf5/h2file"
|
||||
#include "tools/histo/h1d"
|
||||
@@ -71,7 +73,7 @@ G4bool G4Hdf5HnFileManager<HT>::WriteExtra(
|
||||
{
|
||||
// create a new file
|
||||
// create new file
|
||||
hid_t hfile = ::H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
hid_t hfile = ::H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
// Do nothing if there is no file
|
||||
// (te error should be handled by caller)
|
||||
@@ -126,11 +128,9 @@ G4bool G4Hdf5HnFileManager<HT>::Write(
|
||||
|
||||
auto hdirectory = std::get<1>(*fFileManager->GetTFile(fileName));
|
||||
if ( hdirectory < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Failed to get Hdf5 file " << fileName << " histo directory.";
|
||||
G4Exception("G4Hdf5HnFileManager<HT>::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Failed to get Hdf5 file " + fileName + " histo directory.",
|
||||
fkClass, "Write");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+38
-7
@@ -24,15 +24,46 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
// The manager class for histogram/profile reading from a Hdf5 file.
|
||||
|
||||
#ifndef g4hdf5_h
|
||||
#define g4hdf5_h
|
||||
// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "g4hdf5_defs.hh"
|
||||
#ifndef G4Hdf5HnRFileManager_h
|
||||
#define G4Hdf5HnRFileManager_h 1
|
||||
|
||||
using namespace G4Hdf5;
|
||||
#include "G4VTHnRFileManager.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple" // for hid_t
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4Hdf5RFileManager;
|
||||
|
||||
template <typename HT>
|
||||
class G4Hdf5HnRFileManager : public G4VTHnRFileManager<HT>
|
||||
{
|
||||
public:
|
||||
explicit G4Hdf5HnRFileManager(G4Hdf5RFileManager* rfileManger)
|
||||
: G4VTHnRFileManager<HT>(), fRFileManager(rfileManger) {}
|
||||
G4Hdf5HnRFileManager() = delete;
|
||||
virtual ~G4Hdf5HnRFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
virtual HT* Read(const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
|
||||
private:
|
||||
// Methods
|
||||
G4bool ReadT(hid_t directory, const G4String& htName, HT*& ht);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4Hdf5HnRFileManager<HT>" };
|
||||
// Data members
|
||||
G4Hdf5RFileManager* fRFileManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4Hdf5HnRFileManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/hdf5/header"
|
||||
#include "tools/hdf5/h2file"
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
|
||||
#include "tools/hdf5/h2file"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4Hdf5HnRFileManager<HT>::ReadT(
|
||||
hid_t directory, const G4String& htName, HT*& ht)
|
||||
{
|
||||
return tools::hdf5::read_histo(G4cout, directory, htName, ht);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
G4bool G4Hdf5HnRFileManager<tools::histo::p1d>::ReadT(
|
||||
hid_t directory, const G4String& htName, tools::histo::p1d*& ht)
|
||||
{
|
||||
return tools::hdf5::read_profile(G4cout, directory, htName, ht);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
G4bool G4Hdf5HnRFileManager<tools::histo::p2d>::ReadT(
|
||||
hid_t directory, const G4String& htName, tools::histo::p2d*& ht)
|
||||
{
|
||||
return tools::hdf5::read_profile(G4cout, directory, htName, ht);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
HT* G4Hdf5HnRFileManager<HT>::Read(
|
||||
const G4String& htName, const G4String& fileName, const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
// Get directory
|
||||
auto directory = fRFileManager->GetHistoRDirectory(fileName, dirName, false);
|
||||
if ( directory < 0 ) return nullptr;
|
||||
|
||||
// Read hn
|
||||
HT* ht = nullptr;
|
||||
if ( ! ReadT(directory, htName, ht) ) {
|
||||
G4Analysis::Warn(
|
||||
"Streaming " + htName + " from file " + fileName + " failed.",
|
||||
fkClass, "ReadTImpl");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ht;
|
||||
}
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4Hdf5FileManager;
|
||||
class G4Hdf5NtupleManager;
|
||||
class G4VNtupleManager;
|
||||
@@ -45,7 +47,8 @@ class G4Hdf5NtupleFileManager : public G4VNtupleFileManager
|
||||
|
||||
public:
|
||||
explicit G4Hdf5NtupleFileManager(const G4AnalysisManagerState& state);
|
||||
~G4Hdf5NtupleFileManager();
|
||||
G4Hdf5NtupleFileManager() = delete;
|
||||
virtual ~G4Hdf5NtupleFileManager() = default;
|
||||
|
||||
virtual std::shared_ptr<G4VNtupleManager> CreateNtupleManager() override;
|
||||
|
||||
@@ -53,19 +56,22 @@ class G4Hdf5NtupleFileManager : public G4VNtupleFileManager
|
||||
virtual G4bool ActionAtOpenFile(const G4String& fileName) override;
|
||||
virtual G4bool ActionAtWrite() override;
|
||||
virtual G4bool ActionAtCloseFile(G4bool reset) override;
|
||||
virtual G4bool Reset() override;
|
||||
virtual G4bool Reset() override;
|
||||
|
||||
void SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager);
|
||||
|
||||
std::shared_ptr<G4Hdf5NtupleManager> GetNtupleManager() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
G4bool CloseNtupleFiles();
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4Hdf5FileManager> fFileManager;
|
||||
std::shared_ptr<G4Hdf5NtupleManager> fNtupleManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4Hdf5NtupleFileManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4Hdf5FileManager> fFileManager { nullptr };
|
||||
std::shared_ptr<G4Hdf5NtupleManager> fNtupleManager { nullptr };
|
||||
};
|
||||
|
||||
inline void G4Hdf5NtupleFileManager::SetFileManager(
|
||||
@@ -76,4 +82,3 @@ inline std::shared_ptr<G4Hdf5NtupleManager> G4Hdf5NtupleFileManager::GetNtupleMa
|
||||
{ return fNtupleManager; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Manager class for Hdf5 ntuples
|
||||
// Manager class for Hdf5 ntuples
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#define G4Hdf5NtupleManager_h 1
|
||||
|
||||
#include "G4TNtupleManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
@@ -54,23 +55,24 @@ G4bool G4TNtupleManager<tools::hdf5::ntuple, G4Hdf5File>::FillNtupleTColumn(
|
||||
|
||||
|
||||
class G4Hdf5NtupleManager : public G4TNtupleManager<tools::hdf5::ntuple,
|
||||
G4Hdf5File>
|
||||
G4Hdf5File>
|
||||
{
|
||||
friend class G4Hdf5AnalysisManager;
|
||||
friend class G4Hdf5NtupleFileManager;
|
||||
|
||||
public:
|
||||
explicit G4Hdf5NtupleManager(const G4AnalysisManagerState& state);
|
||||
~G4Hdf5NtupleManager();
|
||||
G4Hdf5NtupleManager() = delete;
|
||||
virtual ~G4Hdf5NtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager);
|
||||
|
||||
|
||||
// Access to ntuple vector (needed for Write())
|
||||
const std::vector<Hdf5NtupleDescription*>& GetNtupleDescriptionVector() const;
|
||||
|
||||
// Utility function
|
||||
// Utility function
|
||||
void CreateTNtuple(Hdf5NtupleDescription* ntupleDescription, G4bool warn);
|
||||
|
||||
// Methods from the templated base class
|
||||
@@ -82,18 +84,22 @@ class G4Hdf5NtupleManager : public G4TNtupleManager<tools::hdf5::ntuple,
|
||||
Hdf5NtupleDescription* ntupleDescription,
|
||||
G4bool fromBooking) final;
|
||||
|
||||
// data members
|
||||
//
|
||||
std::shared_ptr<G4Hdf5FileManager> fFileManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4Hdf5NtupleManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4Hdf5FileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void
|
||||
using std::to_string;
|
||||
|
||||
inline void
|
||||
G4Hdf5NtupleManager::SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline const std::vector<Hdf5NtupleDescription*>&
|
||||
inline const std::vector<Hdf5NtupleDescription*>&
|
||||
G4Hdf5NtupleManager::GetNtupleDescriptionVector() const
|
||||
{ return fNtupleDescriptionVector; }
|
||||
|
||||
@@ -103,9 +109,9 @@ inline G4bool G4TNtupleManager<tools::hdf5::ntuple, G4Hdf5File>::FillNtupleTColu
|
||||
G4int ntupleId, G4int columnId, const std::string& 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");
|
||||
@@ -114,11 +120,9 @@ inline G4bool G4TNtupleManager<tools::hdf5::ntuple, G4Hdf5File>::FillNtupleTColu
|
||||
// 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(
|
||||
"ntupleId " + to_string(ntupleId) + " columnId " + to_string(columnId) +
|
||||
" does not exist.", fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
@@ -126,26 +130,23 @@ inline G4bool G4TNtupleManager<tools::hdf5::ntuple, G4Hdf5File>::FillNtupleTColu
|
||||
// get column and check its type
|
||||
auto column = dynamic_cast<tools::hdf5::ntuple::column_string* >(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: ntupleId " + to_string(ntupleId) +
|
||||
" columnId " + to_string(columnId) + " value " + 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) +
|
||||
" columnId " + to_string(columnId) +
|
||||
" value " + G4Analysis::ToString(value));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,41 +31,50 @@
|
||||
#ifndef G4Hdf5RFileManager_h
|
||||
#define G4Hdf5RFileManager_h 1
|
||||
|
||||
#include "G4BaseFileManager.hh"
|
||||
#include "G4VRFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <string_view>
|
||||
|
||||
class G4Hdf5RFileManager : public G4BaseFileManager
|
||||
using G4Hdf5File = std::tuple<hid_t, hid_t, hid_t>;
|
||||
|
||||
class G4Hdf5RFileManager : public G4VRFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4Hdf5RFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4Hdf5RFileManager();
|
||||
G4Hdf5RFileManager() = delete;
|
||||
virtual ~G4Hdf5RFileManager() = default;
|
||||
|
||||
virtual G4String GetFileType() const final { return "hdf5"; }
|
||||
|
||||
// Methods from base class
|
||||
virtual void CloseFiles() final;
|
||||
|
||||
// Get methods
|
||||
hid_t GetRFile(const G4String& fileName, G4bool isPerThread) const;
|
||||
G4Hdf5File* GetRFile(const G4String& fileName, G4bool isPerThread);
|
||||
hid_t GetHistoRDirectory(const G4String& fileName, const G4String& dirName,
|
||||
G4bool isPerThread);
|
||||
hid_t GetNtupleRDirectory(const G4String& fileName, const G4String& dirName,
|
||||
G4bool isPerThread);
|
||||
|
||||
private:
|
||||
// constants
|
||||
static const G4String fgkDefaultDirectoryName;
|
||||
|
||||
// methods
|
||||
// Methods
|
||||
hid_t OpenRFile(const G4String& fileName, G4bool isPerThread);
|
||||
hid_t OpenDirectory(hid_t file, const G4String& directoryName);
|
||||
hid_t GetRDirectory(const G4String& directoryType,
|
||||
const G4String& fileName, const G4String& dirName,
|
||||
G4bool isPerThread);
|
||||
|
||||
// data members
|
||||
std::map<G4String, hid_t> fRFiles;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4Hdf5RFileManager" };
|
||||
inline static const G4String fgkDefaultDirectoryName { "default" };
|
||||
|
||||
// Data members
|
||||
std::map<G4String, G4Hdf5File> fRFiles;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,24 +37,40 @@
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4Hdf5RFileManager;
|
||||
|
||||
class G4Hdf5RNtupleManager : public G4TRNtupleManager<tools::hdf5::ntuple>
|
||||
{
|
||||
friend class G4Hdf5AnalysisReader;
|
||||
|
||||
protected:
|
||||
public:
|
||||
explicit G4Hdf5RNtupleManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4Hdf5RNtupleManager();
|
||||
G4Hdf5RNtupleManager() = delete;
|
||||
virtual ~G4Hdf5RNtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Methods from the templated base class
|
||||
//
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4Hdf5RFileManager> fileManager);
|
||||
|
||||
// Methods from the base class
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4bool GetTNtupleRow(G4TRNtupleDescription<tools::hdf5::ntuple>* ntupleDescription) final;
|
||||
};
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4Hdf5RNtupleManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4Hdf5RFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
// // inline functions
|
||||
|
||||
// inline G4int G4Hdf5RNtupleManager::GetNofNtuples() const
|
||||
// { return fNtupleVector.size(); }
|
||||
inline void
|
||||
G4Hdf5RNtupleManager::SetFileManager(std::shared_ptr<G4Hdf5RFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,25 +30,10 @@
|
||||
#define g4hdf5_defs_h
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
#include "G4Hdf5AnalysisManager.hh"
|
||||
#include "G4Hdf5AnalysisReader.hh"
|
||||
#include "g4hntools_defs.hh"
|
||||
|
||||
namespace G4Hdf5
|
||||
{
|
||||
// Ntuple types
|
||||
using G4Ntuple = tools::hdf5::ntuple;
|
||||
using G4NtupleIterator = std::vector<tools::hdf5::ntuple*>::iterator;
|
||||
using G4NtupleConstIterator = std::vector<tools::hdf5::ntuple*>::const_iterator;
|
||||
|
||||
// RNtuple types
|
||||
using G4RNtuple = tools::hdf5::ntuple;
|
||||
|
||||
// Managers
|
||||
using G4AnalysisManager = G4Hdf5AnalysisManager;
|
||||
using G4AnalysisReader = G4Hdf5AnalysisReader;
|
||||
}
|
||||
// Hdf5 output specific types
|
||||
using G4Hdf5Ntuple = tools::hdf5::ntuple;
|
||||
using G4Hdf5RNtuple = tools::hdf5::ntuple;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@ geant4_add_module(G4hdf5
|
||||
G4Hdf5FileManager.hh
|
||||
G4Hdf5HnFileManager.hh
|
||||
G4Hdf5HnFileManager.icc
|
||||
G4Hdf5HnRFileManager.hh
|
||||
G4Hdf5HnRFileManager.icc
|
||||
G4Hdf5NtupleManager.hh
|
||||
G4Hdf5NtupleFileManager.hh
|
||||
G4Hdf5RNtupleManager.hh
|
||||
G4Hdf5RFileManager.hh
|
||||
g4hdf5_defs.hh
|
||||
g4hdf5.hh
|
||||
SOURCES
|
||||
G4Hdf5AnalysisManager.cc
|
||||
G4Hdf5AnalysisReader.cc
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "G4Hdf5NtupleFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
@@ -41,72 +42,44 @@ using namespace G4Analysis;
|
||||
namespace {
|
||||
//Mutex to lock master manager when opening a file
|
||||
G4Mutex openFileMutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH2Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH3Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P1 profiles
|
||||
G4Mutex mergeP1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P2 profiles
|
||||
G4Mutex mergeP2Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when closing a file
|
||||
G4Mutex closeFileMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
}
|
||||
|
||||
G4Hdf5AnalysisManager* G4Hdf5AnalysisManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4Hdf5AnalysisManager* G4Hdf5AnalysisManager::fgInstance = nullptr;
|
||||
// G4Hdf5AnalysisManager* G4Hdf5AnalysisManager::fgMasterInstance = nullptr;
|
||||
// G4ThreadLocal G4bool G4Hdf5AnalysisManager::fgIsInstance = false;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisManager* G4Hdf5AnalysisManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4Hdf5AnalysisManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
static G4ThreadLocalSingleton<G4Hdf5AnalysisManager> instance;
|
||||
fgIsInstance = true;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::IsInstance()
|
||||
{
|
||||
return ( fgInstance != 0 );
|
||||
}
|
||||
return fgIsInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisManager::G4Hdf5AnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("Hdf5", isMaster),
|
||||
fNtupleFileManager(nullptr),
|
||||
fFileManager(nullptr)
|
||||
G4Hdf5AnalysisManager::G4Hdf5AnalysisManager()
|
||||
: G4ToolsAnalysisManager("Hdf5")
|
||||
{
|
||||
#ifdef G4MULTITHREADED
|
||||
#ifndef H5_HAVE_THREADSAFE
|
||||
G4ExceptionDescription message;
|
||||
message
|
||||
<< "Your HDF5 lib is not built with H5_HAVE_THREADSAFE.";
|
||||
G4Exception("G4Hdf5AnalysisManager::G4Hdf5AnalysisManager",
|
||||
"Analysis_F002", FatalException, message);
|
||||
"Analysis_F001", FatalException,
|
||||
"Your HDF5 lib is not built with H5_HAVE_THREADSAFE.");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4Hdf5AnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4Hdf5AnalysisManager::G4Hdf5AnalysisManager",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// File manager
|
||||
fFileManager = std::make_shared<G4Hdf5FileManager>(fState);
|
||||
SetFileManager(fFileManager);
|
||||
fFileManager->SetBasketSize(fgkDefaultBasketSize);
|
||||
|
||||
// Ntuple file manager
|
||||
fNtupleFileManager = std::make_shared<G4Hdf5NtupleFileManager>(fState);
|
||||
@@ -116,152 +89,12 @@ G4Hdf5AnalysisManager::G4Hdf5AnalysisManager(G4bool isMaster)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisManager::~G4Hdf5AnalysisManager()
|
||||
{
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
fgIsInstance = false;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteH1()
|
||||
{
|
||||
auto h1Vector = fH1Manager->GetH1Vector();
|
||||
auto hnVector = fH1Manager->GetHnVector();
|
||||
|
||||
if ( ! h1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteHn(h1Vector, hnVector, "h1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH1(&mergeH1Mutex);
|
||||
fgMasterInstance->fH1Manager->AddH1Vector(h1Vector);
|
||||
lH1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteH2()
|
||||
{
|
||||
auto h2Vector = fH2Manager->GetH2Vector();
|
||||
auto hnVector = fH2Manager->GetHnVector();
|
||||
|
||||
if ( ! h2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteHn(h2Vector, hnVector, "h2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH2(&mergeH2Mutex);
|
||||
fgMasterInstance->fH2Manager->AddH2Vector(h2Vector);
|
||||
lH2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteH3()
|
||||
{
|
||||
auto h3Vector = fH3Manager->GetH3Vector();
|
||||
auto hnVector = fH3Manager->GetHnVector();
|
||||
|
||||
if ( ! h3Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteHn(h3Vector, hnVector, "h3");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH3(&mergeH3Mutex);
|
||||
fgMasterInstance->fH3Manager->AddH3Vector(h3Vector);
|
||||
lH3.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteP1()
|
||||
{
|
||||
auto p1Vector = fP1Manager->GetP1Vector();
|
||||
auto hnVector = fP1Manager->GetHnVector();
|
||||
|
||||
if ( ! p1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WritePn(p1Vector, hnVector, "p1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP1(&mergeP1Mutex);
|
||||
fgMasterInstance->fP1Manager->AddP1Vector(p1Vector);
|
||||
lP1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteP2()
|
||||
{
|
||||
auto p2Vector = fP2Manager->GetP2Vector();
|
||||
auto hnVector = fP2Manager->GetHnVector();
|
||||
|
||||
if ( ! p2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WritePn(p2Vector, hnVector, "p2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP2(&mergeP2Mutex);
|
||||
fgMasterInstance->fP2Manager->AddP2Vector(p2Vector);
|
||||
lP2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisManager::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleFileManager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -272,89 +105,75 @@ G4bool G4Hdf5AnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
// and set it to base class which takes then their ownership
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
G4AutoLock lock(&openFileMutex);
|
||||
auto result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->OpenFile(fileName);
|
||||
result &= fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
lock.unlock();
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteImpl()
|
||||
G4bool G4Hdf5AnalysisManager::WriteImpl()
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write", "files", "");
|
||||
Message(kVL4, "write", "files");
|
||||
|
||||
if ( G4Threading::IsWorkerThread() ) {
|
||||
result &= G4ToolsAnalysisManager::Merge();
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
// Open all files registered with objects
|
||||
fFileManager->OpenFiles();
|
||||
|
||||
auto result = WriteH1();
|
||||
finalResult = finalResult && result;
|
||||
// Write all histograms/profile on master
|
||||
result &= G4ToolsAnalysisManager::WriteImpl();
|
||||
}
|
||||
|
||||
// H2
|
||||
result = WriteH2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H3
|
||||
result = WriteH3();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P1
|
||||
result = WriteP1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P2
|
||||
result = WriteP2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// Write ASCII if activated
|
||||
if ( IsAscii() ) {
|
||||
result = WriteAscii(fFileManager->GetFileName());
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("write", "files", "", finalResult);
|
||||
result &= WriteAscii(fFileManager->GetFileName());
|
||||
}
|
||||
#endif
|
||||
|
||||
return finalResult;
|
||||
Message(kVL3, "write", "files", "", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
G4AutoLock lock(&closeFileMutex);
|
||||
auto result = fFileManager->CloseFiles();
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->CloseFiles();
|
||||
|
||||
if ( reset ) {
|
||||
// reset data
|
||||
result = Reset();
|
||||
result = ResetImpl();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4Hdf5AnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
Warn("Resetting data failed", fkClass, "OpenDirectory");
|
||||
}
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
|
||||
lock.unlock();
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::ResetImpl()
|
||||
{
|
||||
auto result = true;
|
||||
|
||||
result &= G4ToolsAnalysisManager::ResetImpl();
|
||||
if ( fNtupleFileManager != nullptr ) {
|
||||
result &= fNtupleFileManager->Reset();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -27,52 +27,31 @@
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5AnalysisReader.hh"
|
||||
#include "G4Hdf5RFileManager.hh"
|
||||
#include "G4Hdf5RNtupleManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::fgInstance = nullptr;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4Hdf5AnalysisReader(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
static G4ThreadLocalSingleton<G4Hdf5AnalysisReader> instance;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisReader::G4Hdf5AnalysisReader(G4bool isMaster)
|
||||
: G4ToolsAnalysisReader("Hdf5", isMaster),
|
||||
fNtupleManager(nullptr),
|
||||
fFileManager(nullptr)
|
||||
G4Hdf5AnalysisReader::G4Hdf5AnalysisReader()
|
||||
: G4ToolsAnalysisReader("Hdf5")
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4Hdf5AnalysisReader already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4Hdf5AnalysisReader::G4Hdf5AnalysisReader()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// Create managers
|
||||
fNtupleManager = new G4Hdf5RNtupleManager(fState);
|
||||
fFileManager = new G4Hdf5RFileManager(fState);
|
||||
|
||||
fNtupleManager = std::make_shared<G4Hdf5RNtupleManager>(fState);
|
||||
fFileManager = std::make_shared<G4Hdf5RFileManager>(fState);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
|
||||
// Set managers to base class
|
||||
SetNtupleManager(fNtupleManager);
|
||||
SetFileManager(fFileManager);
|
||||
@@ -82,10 +61,9 @@ G4Hdf5AnalysisReader::G4Hdf5AnalysisReader(G4bool isMaster)
|
||||
G4Hdf5AnalysisReader::~G4Hdf5AnalysisReader()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -94,179 +72,32 @@ G4bool G4Hdf5AnalysisReader::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisReader::Reset();
|
||||
finalResult = finalResult && result;
|
||||
auto result = true;
|
||||
|
||||
result = fNtupleManager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//
|
||||
result &= G4ToolsAnalysisReader::Reset();
|
||||
result &= fNtupleManager->Reset();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadH1Impl(const G4String& h1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
G4bool G4Hdf5AnalysisReader::CloseFilesImpl(G4bool reset)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h1", h1Name);
|
||||
#endif
|
||||
Message(kVL4, "close", "files");
|
||||
|
||||
auto h1 = ReadHnImpl<tools::histo::h1d>(h1Name, fileName, dirName);
|
||||
|
||||
if ( ! h1 ) return kInvalidId;
|
||||
|
||||
auto id = fH1Manager->AddH1(h1Name, h1);
|
||||
auto result = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
if (reset) {
|
||||
result &= Reset();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadH2Impl(const G4String& h2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h2", h2Name);
|
||||
#endif
|
||||
fFileManager->CloseFiles();
|
||||
|
||||
auto h2 = ReadHnImpl<tools::histo::h2d>(h2Name, fileName, dirName);
|
||||
|
||||
if ( ! h2 ) return kInvalidId;
|
||||
|
||||
auto id = fH2Manager->AddH2(h2Name, h2);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
Message(kVL2, "close", "files", "", result);
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadH3Impl(const G4String& h3Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h3", h3Name);
|
||||
#endif
|
||||
|
||||
auto h3 = ReadHnImpl<tools::histo::h3d>(h3Name, fileName, dirName);
|
||||
|
||||
if ( ! h3 ) return kInvalidId;
|
||||
|
||||
auto id = fH3Manager->AddH3(h3Name, h3);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadP1Impl(const G4String& p1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "p1", p1Name);
|
||||
#endif
|
||||
|
||||
auto p1 = ReadPnImpl<tools::histo::p1d>(p1Name, fileName, dirName);
|
||||
|
||||
if ( ! p1 ) return kInvalidId;
|
||||
|
||||
auto id = fP1Manager->AddP1(p1Name, p1);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadP2Impl(const G4String& p2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "p2", p2Name);
|
||||
#endif
|
||||
|
||||
auto p2 = ReadPnImpl<tools::histo::p2d>(p2Name, fileName, dirName);
|
||||
|
||||
if ( ! p2 ) return kInvalidId;
|
||||
|
||||
auto id = fP2Manager->AddP2(p2Name, p2);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "ntuple", ntupleName);
|
||||
#endif
|
||||
|
||||
// Ntuples are saved in files per thread
|
||||
// but apply thethe thread suffix only if fileName is not provided explicitly
|
||||
G4String fullFileName = fileName;
|
||||
if ( ! isUserFileName ) {
|
||||
fullFileName = fFileManager->GetFullFileName();
|
||||
}
|
||||
|
||||
// Get directory
|
||||
auto directory = fFileManager->GetNtupleRDirectory(fullFileName, dirName, false);
|
||||
if ( directory < 0 ) return kInvalidId;
|
||||
|
||||
// Create ntuple
|
||||
auto rntuple = new tools::hdf5::ntuple(G4cout, directory, ntupleName);
|
||||
auto rntupleDescription = new G4TRNtupleDescription<tools::hdf5::ntuple>(rntuple);
|
||||
auto id = fNtupleManager->SetNtuple(rntupleDescription);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -42,29 +42,21 @@ using namespace tools;
|
||||
namespace {
|
||||
//Mutex to lock master manager when closing a file
|
||||
G4Mutex closeFileMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
const G4String G4Hdf5FileManager::fgkDefaultDirectoryName = "default";
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5FileManager::G4Hdf5FileManager(const G4AnalysisManagerState& state)
|
||||
: G4VTFileManager<G4Hdf5File>(state),
|
||||
fBasketSize(0) // TO DO: check default value !! (433 in test)
|
||||
: G4VTFileManager<G4Hdf5File>(state)
|
||||
{
|
||||
// Create helpers defined in the base class
|
||||
fH1FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h1d>>(this);
|
||||
fH2FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h2d>>(this);
|
||||
fH3FileManager = std::make_shared<G4Hdf5HnFileManager<histo::h3d>>(this);
|
||||
fP1FileManager = std::make_shared<G4Hdf5HnFileManager<histo::p1d>>(this);
|
||||
fP2FileManager = std::make_shared<G4Hdf5HnFileManager<histo::p2d>>(this);
|
||||
fP2FileManager = std::make_shared<G4Hdf5HnFileManager<histo::p2d>>(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5FileManager::~G4Hdf5FileManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -85,12 +77,7 @@ hid_t G4Hdf5FileManager::CreateDirectory(hid_t& file,
|
||||
newDirectoryName += objectType;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()
|
||||
->Message("create", "directory for " + objectType, newDirectoryName);
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "create", "directory for " + objectType, newDirectoryName);
|
||||
|
||||
auto success = true;
|
||||
|
||||
@@ -100,39 +87,29 @@ hid_t G4Hdf5FileManager::CreateDirectory(hid_t& file,
|
||||
// be the default value but 0 is what is found in examples, and in the code, if we pass 0, clearly some
|
||||
// default value is taken.
|
||||
if ( directory < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot create directory " << directoryName;
|
||||
G4Exception("G4Hdf5FileManager::CreateDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("Cannot create directory " + directoryName,
|
||||
fkClass, "CreateDirectory");
|
||||
success = false;
|
||||
}
|
||||
else {
|
||||
// write atb (header?)
|
||||
auto result = hdf5::write_atb(directory, "type", "directory");
|
||||
if ( !result) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "write_atb class failed for " << directoryName;
|
||||
G4Exception("G4Hdf5FileManager::CreateDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("Write_atb class failed for " + directoryName,
|
||||
fkClass, "CreateDirectory");
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()
|
||||
->Message("create", "directory for " + objectType, newDirectoryName, success);
|
||||
}
|
||||
#endif
|
||||
Message(kVL2, "create", "directory for " + objectType, newDirectoryName, success);
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4Hdf5FileManager::GetNtupleFileName(Hdf5NtupleDescription* ntupleDescription)
|
||||
{
|
||||
// get ntuple file name
|
||||
// get ntuple file name
|
||||
auto ntupleFileName = ntupleDescription->fFileName;
|
||||
if ( ntupleFileName.size() ) {
|
||||
// update filename per object per thread
|
||||
@@ -142,9 +119,9 @@ G4String G4Hdf5FileManager::GetNtupleFileName(Hdf5NtupleDescription* ntupleDescr
|
||||
ntupleFileName = GetFullFileName();
|
||||
}
|
||||
return ntupleFileName;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -157,19 +134,14 @@ std::shared_ptr<G4Hdf5File> G4Hdf5FileManager::CreateFileImpl(const G4String& fi
|
||||
// Do nothing if there is no file
|
||||
// (the error should be handled by caller)
|
||||
if ( file < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "::H5Fcreate failed " << fileName;
|
||||
G4Exception("G4Hdf5AnalysisManager::CreateFileImpl()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("::H5Fcreate failed " + fileName, fkClass, "CreateFileImpl");
|
||||
return std::make_shared<G4Hdf5File>(-1, -1, -1);
|
||||
}
|
||||
|
||||
// create a header with general infos
|
||||
if(!tools::hdf5::write_header(file)) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "tools::hdf5::write_header() failed for " << fileName;
|
||||
G4Exception("G4Hdf5AnalysisManager::CreateFileImpl()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("tools::hdf5::write_header() failed for " + fileName,
|
||||
fkClass, "CreateFileImpl");
|
||||
return std::make_shared<G4Hdf5File>(-1, -1, -1);
|
||||
}
|
||||
|
||||
@@ -177,7 +149,7 @@ std::shared_ptr<G4Hdf5File> G4Hdf5FileManager::CreateFileImpl(const G4String& fi
|
||||
auto hdirectory
|
||||
= CreateDirectory(file, fHistoDirectoryName, "histograms");
|
||||
if ( hdirectory < 0 ) {
|
||||
// Warnin is issued in CreateDirectory
|
||||
// Warning is issued in CreateDirectory
|
||||
return std::make_shared<G4Hdf5File>(-1, -1, -1);
|
||||
}
|
||||
|
||||
@@ -227,30 +199,23 @@ G4bool G4Hdf5FileManager::OpenFile(const G4String& fileName)
|
||||
auto name = GetFullFileName();
|
||||
|
||||
if ( fFile ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "File " << fileName << " already exists.";
|
||||
G4Exception("G4Hdf5FileManager::OpenFile()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("File " + fileName + " already exists.", fkClass, "OpenFile");
|
||||
fFile.reset();
|
||||
}
|
||||
|
||||
// create new file
|
||||
fFile = CreateTFile(name);
|
||||
if ( ! fFile ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Failed to create file " << fileName;
|
||||
G4Exception("G4Hdf5FileManager::OpenFile()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("Failed to create file " + fileName, fkClass, "OpenFile");
|
||||
return false;
|
||||
}
|
||||
|
||||
fLockDirectoryNames = true;
|
||||
LockDirectoryNames();
|
||||
fIsOpenFile = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5FileManager::CreateNtupleFile(
|
||||
Hdf5NtupleDescription* ntupleDescription)
|
||||
@@ -272,7 +237,7 @@ G4bool G4Hdf5FileManager::CloseNtupleFile(
|
||||
Hdf5NtupleDescription* ntupleDescription)
|
||||
{
|
||||
// Do nothing if there is no file
|
||||
if ( ! ntupleDescription->fFile ) return true;
|
||||
if ( ntupleDescription->fFile == nullptr ) return true;
|
||||
|
||||
// Ntuple files will be closed with CloseFiles() calls
|
||||
ntupleDescription->fFile.reset();
|
||||
|
||||
@@ -32,28 +32,18 @@
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//
|
||||
//
|
||||
// utility methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5NtupleFileManager::G4Hdf5NtupleFileManager(const G4AnalysisManagerState& state)
|
||||
: G4VNtupleFileManager(state, "hdf5"),
|
||||
fFileManager(nullptr),
|
||||
fNtupleManager(nullptr)
|
||||
: G4VNtupleFileManager(state, "hdf5")
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5NtupleFileManager::~G4Hdf5NtupleFileManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -62,14 +52,13 @@ G4bool G4Hdf5NtupleFileManager::CloseNtupleFiles()
|
||||
{
|
||||
// Close ntuple files
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
|
||||
for ( auto ntupleDescription : ntupleVector) {
|
||||
auto result = fFileManager->CloseNtupleFile(ntupleDescription);
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->CloseNtupleFile(ntupleDescription);
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -90,7 +79,7 @@ std::shared_ptr<G4VNtupleManager> G4Hdf5NtupleFileManager::CreateNtupleManager()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5NtupleFileManager::ActionAtOpenFile(const G4String& /*fileName*/)
|
||||
{
|
||||
// Create ntuples if they are booked
|
||||
// Create ntuples if they are booked
|
||||
// (The files will be created with creating ntuples)
|
||||
fNtupleManager->CreateNtuplesFromBooking(
|
||||
fBookingManager->GetNtupleBookingVector());
|
||||
@@ -101,50 +90,31 @@ G4bool G4Hdf5NtupleFileManager::ActionAtOpenFile(const G4String& /*fileName*/)
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5NtupleFileManager::ActionAtWrite()
|
||||
{
|
||||
// notify that ntuple file is not empty
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
// Notify that ntuple files are not empty
|
||||
auto ntupleVector
|
||||
= fNtupleManager->GetNtupleDescriptionVector();
|
||||
|
||||
for ( auto ntupleDescription : ntupleVector) {
|
||||
if (ntupleDescription->fFile) {
|
||||
auto result = fFileManager->SetIsEmpty(ntupleDescription->fFileName, false);
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
// Nothing to be done
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5NtupleFileManager::ActionAtCloseFile(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Close ntuple files
|
||||
auto result = CloseNtupleFiles();
|
||||
finalResult = finalResult && result;
|
||||
result &= CloseNtupleFiles();
|
||||
|
||||
if ( ! reset ) {
|
||||
// The ntuples must be always reset when closing file)
|
||||
// The ntuples must be always reset when closing file)
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4Hdf5NtupleFileManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
Warn("Resetting data failed", fkClass, "ActionAtCloseFile");
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5NtupleFileManager::Reset()
|
||||
{
|
||||
return fNtupleManager->Reset(true);
|
||||
return fNtupleManager->Reset();
|
||||
}
|
||||
|
||||
@@ -34,22 +34,14 @@
|
||||
|
||||
#include "tools/ntuple_booking"
|
||||
|
||||
#include <iostream>
|
||||
//#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5NtupleManager::G4Hdf5NtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TNtupleManager<tools::hdf5::ntuple, G4Hdf5File>(state),
|
||||
fFileManager(nullptr)
|
||||
: G4TNtupleManager<tools::hdf5::ntuple, G4Hdf5File>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5NtupleManager::~G4Hdf5NtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
//_____________________________________________________________________________
|
||||
@@ -68,11 +60,8 @@ void G4Hdf5NtupleManager::CreateTNtuple(
|
||||
// Check file
|
||||
if ( ! ntupleFile ) {
|
||||
if (warn) {
|
||||
G4String inFunction = "G4Hdf5NtupleManager::::CreateTNtuple";
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "Cannot create ntuple. Ntuple file does not exist." << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W002", JustWarning, description);
|
||||
Warn( "Cannot create ntuple. Ntuple file does not exist.",
|
||||
fkClass, "CreateTNtuple");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -88,7 +77,7 @@ void G4Hdf5NtupleManager::CreateTNtuple(
|
||||
G4cout, directory, ntupleDescription->fNtupleBooking,
|
||||
compressionLevel, basketSize);
|
||||
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
@@ -27,33 +27,30 @@
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5RFileManager.hh"
|
||||
#include "G4Hdf5HnRFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/hdf5/h2file"
|
||||
#include <tools/zlib>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include "tools/hdf5/group_exists"
|
||||
#include "tools/zlib"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
const G4String G4Hdf5RFileManager::fgkDefaultDirectoryName = "default";
|
||||
using namespace tools;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5RFileManager::G4Hdf5RFileManager(const G4AnalysisManagerState& state)
|
||||
: G4BaseFileManager(state),
|
||||
fRFiles()
|
||||
: G4VRFileManager(state)
|
||||
{
|
||||
// Create helpers defined in the base class
|
||||
fH1RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::h1d>>(this);
|
||||
fH2RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::h2d>>(this);
|
||||
fH3RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::h3d>>(this);
|
||||
fP1RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::p1d>>(this);
|
||||
fP2RFileManager = std::make_shared<G4Hdf5HnRFileManager<histo::p2d>>(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5RFileManager::~G4Hdf5RFileManager()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -64,93 +61,71 @@ hid_t G4Hdf5RFileManager::OpenRFile(const G4String& fileName,
|
||||
// Get full file name
|
||||
G4String name = GetFullFileName(fileName, isPerThread);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("open", "read analysis file", name);
|
||||
#endif
|
||||
Message(kVL4, "open", "read analysis file", name);
|
||||
|
||||
// create new file
|
||||
hid_t newFile = H5Fopen(name, H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||
if ( newFile < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << name;
|
||||
G4Exception("G4Hdf5RFileManager::OpenFile()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return false;
|
||||
Warn("Cannot open file " + name, fkClass, "OpenRFile");
|
||||
return kInvalidId;
|
||||
}
|
||||
|
||||
// newFile->add_unziper('Z',tools::decompress_buffer);
|
||||
|
||||
|
||||
// add file in a map
|
||||
std::map<G4String, hid_t>::iterator it
|
||||
= fRFiles.find(name);
|
||||
if ( it != fRFiles.end() ) {
|
||||
it->second = newFile;
|
||||
}
|
||||
else {
|
||||
fRFiles[name] = newFile;
|
||||
}
|
||||
fRFiles[name] = G4Hdf5File(newFile, kInvalidId, kInvalidId);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read analysis file", name);
|
||||
#endif
|
||||
Message(kVL1, "open", "read analysis file", name);
|
||||
|
||||
return newFile;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::OpenDirectory(hid_t file, const G4String& directoryName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("open", "read directory", directoryName);
|
||||
}
|
||||
#endif
|
||||
|
||||
Message(kVL4, "open", "read directory", directoryName);
|
||||
|
||||
auto directory = tools_H5Gopen(file, directoryName);
|
||||
if ( directory < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot open directory " << directoryName;
|
||||
G4Exception("G4Hdf5RFileManager::OpenDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
Warn("Cannot open directory " + directoryName, fkClass, "OpenDirectory");
|
||||
return kInvalidId;
|
||||
}
|
||||
else {
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("open", "read directory", directoryName);
|
||||
}
|
||||
#endif
|
||||
Message(kVL2, "open", "read directory", directoryName);
|
||||
return directory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::GetRDirectory(const G4String& directoryType,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isPerThread)
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isPerThread)
|
||||
{
|
||||
// Get or open a file
|
||||
auto rfile = GetRFile(fileName, isPerThread);
|
||||
if ( rfile < 0 ) {
|
||||
// Try to open it if not found in the map
|
||||
if ( ! OpenRFile(fileName, isPerThread) ) return kInvalidId;
|
||||
if ( ! rfile ) {
|
||||
// Try to open it if not found in the map
|
||||
if ( OpenRFile(fileName, isPerThread) < 0 ) return kInvalidId;
|
||||
rfile = GetRFile(fileName, isPerThread);
|
||||
}
|
||||
|
||||
auto isHistograms = (directoryType == "histograms");
|
||||
|
||||
// Get directory if already open
|
||||
hid_t directory = kInvalidId;
|
||||
if ( isHistograms ) {
|
||||
directory = std::get<1>(*rfile);
|
||||
} else {
|
||||
directory = std::get<2>(*rfile);
|
||||
}
|
||||
if ( directory != kInvalidId ) {
|
||||
return directory;
|
||||
}
|
||||
|
||||
// Use default directory name if not specified
|
||||
auto newDirName = dirName;
|
||||
if ( newDirName == "" ) {
|
||||
// if ( fDefaultDirectory > 0 ) {
|
||||
// // Return the default directory if the name is not set and the default directory
|
||||
// // already exists
|
||||
// directory = fDefaultDirectory;
|
||||
// return true;
|
||||
// } else {
|
||||
// Create the default directory if the name is not set and the default directory
|
||||
// does not yet exist
|
||||
newDirName = fgkDefaultDirectoryName;
|
||||
@@ -159,28 +134,35 @@ hid_t G4Hdf5RFileManager::GetRDirectory(const G4String& directoryType,
|
||||
}
|
||||
|
||||
// Open directory
|
||||
return OpenDirectory(rfile, newDirName);
|
||||
}
|
||||
directory = OpenDirectory(std::get<0>(*rfile), newDirName);
|
||||
|
||||
// Update
|
||||
if ( isHistograms ) {
|
||||
std::get<1>(*rfile) = directory;
|
||||
} else {
|
||||
std::get<2>(*rfile) = directory;
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::GetRFile(const G4String& fileName,
|
||||
G4bool isPerThread) const
|
||||
{
|
||||
G4Hdf5File* G4Hdf5RFileManager::GetRFile(const G4String& fileName,
|
||||
G4bool isPerThread)
|
||||
{
|
||||
// Get full file name
|
||||
G4String name = GetFullFileName(fileName, isPerThread);
|
||||
|
||||
std::map<G4String, hid_t>::const_iterator it
|
||||
= fRFiles.find(name);
|
||||
auto it = fRFiles.find(name);
|
||||
if ( it != fRFiles.end() )
|
||||
return it->second;
|
||||
return &(it->second);
|
||||
else {
|
||||
return kInvalidId;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -197,4 +179,19 @@ hid_t G4Hdf5RFileManager::GetNtupleRDirectory(const G4String& fileName, const G4
|
||||
return GetRDirectory("ntuples", fileName, dirName, isPerThread);
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4Hdf5RFileManager::CloseFiles()
|
||||
{
|
||||
// Close all open directories and file
|
||||
for ( auto [key, rfile] : fRFiles ) {
|
||||
if (std::get<1>(rfile) != kInvalidId) {
|
||||
::H5Gclose(std::get<1>(rfile));
|
||||
}
|
||||
if (std::get<2>(rfile) != kInvalidId) {
|
||||
::H5Gclose(std::get<2>(rfile));
|
||||
}
|
||||
if (std::get<0>(rfile) != kInvalidId) {
|
||||
::H5Fclose(std::get<0>(rfile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,20 +27,48 @@
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5RNtupleManager.hh"
|
||||
#include "G4Hdf5RFileManager.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5RNtupleManager::G4Hdf5RNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TRNtupleManager<tools::hdf5::ntuple>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5RNtupleManager::~G4Hdf5RNtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5RNtupleManager::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
Message(kVL4, "read", "ntuple", ntupleName);
|
||||
|
||||
// Ntuples are saved in files per thread
|
||||
// but apply thethe thread suffix only if fileName is not provided explicitly
|
||||
G4String fullFileName = fileName;
|
||||
if ( ! isUserFileName ) {
|
||||
fullFileName = fFileManager->GetFullFileName();
|
||||
}
|
||||
|
||||
// Get directory
|
||||
auto directory = fFileManager->GetNtupleRDirectory(fullFileName, dirName, false);
|
||||
if ( directory < 0 ) return kInvalidId;
|
||||
|
||||
// Create ntuple
|
||||
auto rntuple = new tools::hdf5::ntuple(G4cout, directory, ntupleName);
|
||||
auto rntupleDescription = new G4TRNtupleDescription<tools::hdf5::ntuple>(rntuple);
|
||||
auto id = SetNtuple(rntupleDescription);
|
||||
|
||||
Message(kVL2, "read", "ntuple", ntupleName, id > kInvalidId);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5RNtupleManager::GetTNtupleRow(
|
||||
G4TRNtupleDescription<tools::hdf5::ntuple>* ntupleDescription)
|
||||
@@ -51,26 +79,16 @@ G4bool G4Hdf5RNtupleManager::GetTNtupleRow(
|
||||
if ( ! isInitialized ) {
|
||||
auto ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
if ( ! ntuple->initialize(G4cout, *ntupleBinding) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple initialization failed !!";
|
||||
G4Exception("G4Hdf5RNtuple::GetNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
Warn("Ntuple initialization failed !!", fkClass, "GetTNtupleRow");
|
||||
return false;
|
||||
}
|
||||
ntupleDescription->fIsInitialized = true;
|
||||
}
|
||||
|
||||
if ( ! ntuple->get_row() ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple get_row() failed !!";
|
||||
G4Exception("G4Hdf5RNtuple::GetNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
Warn( "Ntuple get_row() failed !!", fkClass, "GetTNtupleRow");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ using G4ToolsBaseHisto
|
||||
= tools::histo::base_histo<double, unsigned int, unsigned int, double, double>;
|
||||
|
||||
// Access to data parameters
|
||||
//
|
||||
//
|
||||
G4int GetNbins(const G4ToolsBaseHisto& baseHisto, G4int dimension);
|
||||
G4double GetMin(const G4ToolsBaseHisto& baseHisto, G4int dimension);
|
||||
G4double GetMax(const G4ToolsBaseHisto& baseHisto, G4int dimension);
|
||||
@@ -58,7 +58,7 @@ G4bool SetAxisTitle(G4ToolsBaseHisto& baseHisto, G4int dimension, const G4String
|
||||
|
||||
// Accessors
|
||||
G4String GetTitle(const G4ToolsBaseHisto& baseHisto);
|
||||
G4String GetAxisTitle(const G4ToolsBaseHisto& baseHisto, G4int dimension,
|
||||
G4String GetAxisTitle(const G4ToolsBaseHisto& baseHisto, G4int dimension,
|
||||
const G4String& hnType);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
// Manager class for tools::histo::h1d.
|
||||
// It implements functions specific to the H1 type
|
||||
// (defined in g4tools).
|
||||
// (defined in g4tools).
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -41,10 +41,11 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
namespace tools {
|
||||
namespace histo {
|
||||
class h1d;
|
||||
namespace histo {
|
||||
class h1d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,28 +54,29 @@ class G4H1ToolsManager : public G4VH1Manager,
|
||||
{
|
||||
public:
|
||||
explicit G4H1ToolsManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4H1ToolsManager();
|
||||
G4H1ToolsManager() = delete;
|
||||
virtual ~G4H1ToolsManager() = default;
|
||||
|
||||
// Method to add histograms read from a file
|
||||
G4int AddH1(const G4String& name, tools::histo::h1d* h1d);
|
||||
// Method for merge (MT)
|
||||
void AddH1Vector(const std::vector<tools::histo::h1d*>& h1Vector);
|
||||
|
||||
|
||||
// Access methods
|
||||
//
|
||||
tools::histo::h1d* GetH1(G4int id, G4bool warn = true,
|
||||
G4bool onlyIfActive = true) const;
|
||||
|
||||
|
||||
// Iterators
|
||||
std::vector<tools::histo::h1d*>::iterator BeginH1();
|
||||
std::vector<tools::histo::h1d*>::iterator EndH1();
|
||||
std::vector<tools::histo::h1d*>::const_iterator BeginConstH1() const;
|
||||
std::vector<tools::histo::h1d*>::const_iterator EndConstH1() const;
|
||||
|
||||
|
||||
// Access to histogram vector (needed for Write())
|
||||
const std::vector<tools::histo::h1d*>& GetH1Vector() const;
|
||||
const std::vector<G4HnInformation*>& GetHnVector() const;
|
||||
|
||||
const std::vector<G4HnInformation*>& GetHnVector() const;
|
||||
|
||||
protected:
|
||||
// Virtual functions from base class
|
||||
//
|
||||
@@ -90,7 +92,7 @@ class G4H1ToolsManager : public G4VH1Manager,
|
||||
const std::vector<G4double>& edges,
|
||||
const G4String& unitName = "none",
|
||||
const G4String& fcnName = "none") final;
|
||||
|
||||
|
||||
virtual G4bool SetH1(G4int id,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
const G4String& unitName = "none",
|
||||
@@ -101,7 +103,7 @@ class G4H1ToolsManager : public G4VH1Manager,
|
||||
const G4String& unitName = "none",
|
||||
const G4String& fcnName = "none") final;
|
||||
virtual G4bool ScaleH1(G4int id, G4double factor) final;
|
||||
|
||||
|
||||
// Method to fill histograms
|
||||
//
|
||||
virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0) final;
|
||||
@@ -136,16 +138,16 @@ class G4H1ToolsManager : public G4VH1Manager,
|
||||
virtual std::shared_ptr<G4HnManager> GetHnManager() final;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
//
|
||||
void AddH1Information(const G4String& name,
|
||||
const G4String& unitName,
|
||||
void AddH1Information(const G4String& name,
|
||||
const G4String& unitName,
|
||||
const G4String& fcnName,
|
||||
G4BinScheme binScheme) const;
|
||||
|
||||
// data members
|
||||
//static constexpr G4int kDimension = 1; // not yet supported on vc12
|
||||
static const G4int kDimension;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4H1ToolsManager" };
|
||||
static constexpr G4int fkDimension = 1;
|
||||
};
|
||||
|
||||
// inline methods
|
||||
@@ -156,11 +158,11 @@ inline std::vector<tools::histo::h1d*>::iterator G4H1ToolsManager::BeginH1()
|
||||
inline std::vector<tools::histo::h1d*>::iterator G4H1ToolsManager::EndH1()
|
||||
{ return EndT(); }
|
||||
|
||||
inline std::vector<tools::histo::h1d*>::const_iterator
|
||||
inline std::vector<tools::histo::h1d*>::const_iterator
|
||||
G4H1ToolsManager::BeginConstH1() const
|
||||
{ return BeginConstT(); }
|
||||
|
||||
inline std::vector<tools::histo::h1d*>::const_iterator
|
||||
inline std::vector<tools::histo::h1d*>::const_iterator
|
||||
G4H1ToolsManager::EndConstH1() const
|
||||
{ return EndConstT(); }
|
||||
|
||||
@@ -170,7 +172,7 @@ inline const std::vector<tools::histo::h1d*>& G4H1ToolsManager::GetH1Vector() co
|
||||
inline const std::vector<G4HnInformation*>& G4H1ToolsManager::GetHnVector() const
|
||||
{ return fHnManager->GetHnVector(); }
|
||||
|
||||
inline std::shared_ptr<G4HnManager> G4H1ToolsManager::GetHnManager()
|
||||
inline std::shared_ptr<G4HnManager> G4H1ToolsManager::GetHnManager()
|
||||
{ return std::shared_ptr<G4HnManager>(fHnManager); }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
// Manager class for tools::histo::h2d.
|
||||
// It implements functions specific to the H2 type
|
||||
// (defined in g4tools).
|
||||
// (defined in g4tools).
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -41,10 +41,11 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
namespace tools {
|
||||
namespace histo {
|
||||
class h2d;
|
||||
namespace histo {
|
||||
class h2d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +54,13 @@ class G4H2ToolsManager : public G4VH2Manager,
|
||||
{
|
||||
public:
|
||||
explicit G4H2ToolsManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4H2ToolsManager();
|
||||
virtual ~G4H2ToolsManager() = default;
|
||||
|
||||
// Method to add histograms read from a file
|
||||
G4int AddH2(const G4String& name, tools::histo::h2d* h2d);
|
||||
// Method for merge (MT)
|
||||
void AddH2Vector(const std::vector<tools::histo::h2d*>& h2Vector);
|
||||
|
||||
|
||||
// Access methods
|
||||
//
|
||||
tools::histo::h2d* GetH2(G4int id, G4bool warn = true,
|
||||
@@ -69,11 +70,11 @@ class G4H2ToolsManager : public G4VH2Manager,
|
||||
std::vector<tools::histo::h2d*>::iterator EndH2();
|
||||
std::vector<tools::histo::h2d*>::const_iterator BeginConstH2() const;
|
||||
std::vector<tools::histo::h2d*>::const_iterator EndConstH2() const;
|
||||
|
||||
|
||||
// Access to histogram vector (needed for Write())
|
||||
const std::vector<tools::histo::h2d*>& GetH2Vector() const;
|
||||
const std::vector<G4HnInformation*>& GetHnVector() const;
|
||||
|
||||
|
||||
protected:
|
||||
// Virtual functions from base class
|
||||
//
|
||||
@@ -81,48 +82,48 @@ class G4H2ToolsManager : public G4VH2Manager,
|
||||
// Methods to create histograms
|
||||
//
|
||||
virtual G4int CreateH2(const G4String& name, const G4String& title,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& xbinScheme = "linear",
|
||||
const G4String& ybinScheme = "linear") final;
|
||||
|
||||
|
||||
virtual G4int CreateH2(const G4String& name, const G4String& title,
|
||||
const std::vector<G4double>& xedges,
|
||||
const std::vector<G4double>& yedges,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none") final;
|
||||
|
||||
|
||||
virtual G4bool SetH2(G4int id,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& xbinScheme = "linear",
|
||||
const G4String& ybinScheme = "linear") final;
|
||||
|
||||
|
||||
virtual G4bool SetH2(G4int id,
|
||||
const std::vector<G4double>& xedges,
|
||||
const std::vector<G4double>& yedges,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none") final;
|
||||
|
||||
virtual G4bool ScaleH2(G4int id, G4double factor) final;
|
||||
|
||||
|
||||
// Method to fill histograms
|
||||
//
|
||||
virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
|
||||
G4double weight = 1.0) final;
|
||||
|
||||
|
||||
|
||||
// Methods to manipulate histograms
|
||||
//
|
||||
@@ -139,7 +140,7 @@ class G4H2ToolsManager : public G4VH2Manager,
|
||||
virtual G4double GetH2Ymin(G4int id) const final;
|
||||
virtual G4double GetH2Ymax(G4int id) const final;
|
||||
virtual G4double GetH2YWidth(G4int id) const final;
|
||||
|
||||
|
||||
// Setters for attributes for plotting
|
||||
virtual G4bool SetH2Title(G4int id, const G4String& title) final;
|
||||
virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title) final;
|
||||
@@ -151,26 +152,25 @@ class G4H2ToolsManager : public G4VH2Manager,
|
||||
virtual G4String GetH2XAxisTitle(G4int id) const final;
|
||||
virtual G4String GetH2YAxisTitle(G4int id) const final;
|
||||
virtual G4String GetH2ZAxisTitle(G4int id) const final;
|
||||
|
||||
|
||||
// Write data on ASCII file
|
||||
virtual G4bool WriteOnAscii(std::ofstream& output) final;
|
||||
|
||||
|
||||
// Access to Hn manager
|
||||
virtual std::shared_ptr<G4HnManager> GetHnManager() final;
|
||||
|
||||
private:
|
||||
void AddH2Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
void AddH2Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
G4BinScheme xbinScheme,
|
||||
G4BinScheme ybinScheme) const;
|
||||
|
||||
// data members
|
||||
//
|
||||
// static constexpr G4int kDimension = 2; // not yet supported on vc12
|
||||
static const G4int kDimension;
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4H2ToolsManager" };
|
||||
static constexpr G4int fkDimension = 2;
|
||||
};
|
||||
// inline methods
|
||||
|
||||
@@ -180,11 +180,11 @@ inline std::vector<tools::histo::h2d*>::iterator G4H2ToolsManager::BeginH2()
|
||||
inline std::vector<tools::histo::h2d*>::iterator G4H2ToolsManager::EndH2()
|
||||
{ return EndT(); }
|
||||
|
||||
inline std::vector<tools::histo::h2d*>::const_iterator
|
||||
inline std::vector<tools::histo::h2d*>::const_iterator
|
||||
G4H2ToolsManager::BeginConstH2() const
|
||||
{ return BeginConstT(); }
|
||||
|
||||
inline std::vector<tools::histo::h2d*>::const_iterator
|
||||
inline std::vector<tools::histo::h2d*>::const_iterator
|
||||
G4H2ToolsManager::EndConstH2() const
|
||||
{ return EndConstT(); }
|
||||
|
||||
@@ -194,7 +194,7 @@ inline const std::vector<tools::histo::h2d*>& G4H2ToolsManager::GetH2Vector() co
|
||||
inline const std::vector<G4HnInformation*>& G4H2ToolsManager::GetHnVector() const
|
||||
{ return fHnManager->GetHnVector(); }
|
||||
|
||||
inline std::shared_ptr<G4HnManager> G4H2ToolsManager::GetHnManager()
|
||||
inline std::shared_ptr<G4HnManager> G4H2ToolsManager::GetHnManager()
|
||||
{ return std::shared_ptr<G4HnManager>(fHnManager); }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
// Manager class for tools::histo::h3d.
|
||||
// It implements functions specific to the H3 type
|
||||
// (defined in g4tools).
|
||||
// (defined in g4tools).
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 24/07/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -42,10 +42,11 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
namespace tools {
|
||||
namespace histo {
|
||||
class h3d;
|
||||
namespace histo {
|
||||
class h3d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +55,13 @@ class G4H3ToolsManager : public G4VH3Manager,
|
||||
{
|
||||
public:
|
||||
explicit G4H3ToolsManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4H3ToolsManager();
|
||||
virtual ~G4H3ToolsManager() = default;
|
||||
|
||||
// Method to add histograms read from a file
|
||||
G4int AddH3(const G4String& name, tools::histo::h3d* h3d);
|
||||
// Method for merge (MT)
|
||||
void AddH3Vector(const std::vector<tools::histo::h3d*>& h3Vector);
|
||||
|
||||
|
||||
// Access methods
|
||||
//
|
||||
tools::histo::h3d* GetH3(G4int id, G4bool warn = true,
|
||||
@@ -70,11 +71,11 @@ class G4H3ToolsManager : public G4VH3Manager,
|
||||
std::vector<tools::histo::h3d*>::iterator EndH3();
|
||||
std::vector<tools::histo::h3d*>::const_iterator BeginConstH3() const;
|
||||
std::vector<tools::histo::h3d*>::const_iterator EndConstH3() const;
|
||||
|
||||
|
||||
// Access to histogram vector (needed for Write())
|
||||
const std::vector<tools::histo::h3d*>& GetH3Vector() const;
|
||||
const std::vector<G4HnInformation*>& GetHnVector() const;
|
||||
|
||||
|
||||
protected:
|
||||
// Virtual functions from base class
|
||||
//
|
||||
@@ -82,63 +83,63 @@ class G4H3ToolsManager : public G4VH3Manager,
|
||||
// Methods to create histograms
|
||||
//
|
||||
virtual G4int CreateH3(const G4String& name, const G4String& title,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
G4int nzbins, G4double zmin, G4double zmax,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& zunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& zfcnName = "none",
|
||||
const G4String& xbinScheme = "linear",
|
||||
const G4String& ybinScheme = "linear",
|
||||
const G4String& zbinScheme = "linear") final;
|
||||
|
||||
|
||||
virtual G4int CreateH3(const G4String& name, const G4String& title,
|
||||
const std::vector<G4double>& xedges,
|
||||
const std::vector<G4double>& yedges,
|
||||
const std::vector<G4double>& zedges,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& zunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& zfcnName = "none") final;
|
||||
|
||||
|
||||
virtual G4bool SetH3(G4int id,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
G4int nzbins, G4double zmin, G4double zmax,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& zunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& zfcnName = "none",
|
||||
const G4String& xbinScheme = "linear",
|
||||
const G4String& ybinScheme = "linear",
|
||||
const G4String& zbinScheme = "linear") final;
|
||||
|
||||
|
||||
virtual G4bool SetH3(G4int id,
|
||||
const std::vector<G4double>& xedges,
|
||||
const std::vector<G4double>& yedges,
|
||||
const std::vector<G4double>& zedges,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& zunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& zfcnName = "none") final;
|
||||
|
||||
virtual G4bool ScaleH3(G4int id, G4double factor) final;
|
||||
|
||||
|
||||
// Method to fill histograms
|
||||
//
|
||||
virtual G4bool FillH3(G4int id,
|
||||
virtual G4bool FillH3(G4int id,
|
||||
G4double xvalue, G4double yvalue, G4double zvalue,
|
||||
G4double weight = 1.0) final;
|
||||
|
||||
|
||||
|
||||
// Methods to manipulate histograms
|
||||
//
|
||||
@@ -159,7 +160,7 @@ class G4H3ToolsManager : public G4VH3Manager,
|
||||
virtual G4double GetH3Zmin(G4int id) const final;
|
||||
virtual G4double GetH3Zmax(G4int id) const final;
|
||||
virtual G4double GetH3ZWidth(G4int id) const final;
|
||||
|
||||
|
||||
// Setters for attributes for plotting
|
||||
virtual G4bool SetH3Title(G4int id, const G4String& title) final;
|
||||
virtual G4bool SetH3XAxisTitle(G4int id, const G4String& title) final;
|
||||
@@ -171,28 +172,28 @@ class G4H3ToolsManager : public G4VH3Manager,
|
||||
virtual G4String GetH3XAxisTitle(G4int id) const final;
|
||||
virtual G4String GetH3YAxisTitle(G4int id) const final;
|
||||
virtual G4String GetH3ZAxisTitle(G4int id) const final;
|
||||
|
||||
|
||||
// Write data on ASCII file
|
||||
virtual G4bool WriteOnAscii(std::ofstream& output) final;
|
||||
|
||||
|
||||
// Access to Hn manager
|
||||
virtual std::shared_ptr<G4HnManager> GetHnManager() final;
|
||||
|
||||
private:
|
||||
void AddH3Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
void AddH3Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
G4BinScheme xbinScheme,
|
||||
G4BinScheme ybinScheme,
|
||||
G4BinScheme zbinScheme) const;
|
||||
|
||||
// data members
|
||||
// static constexpr G4int kDimension = 3; // not yet supported on vc12
|
||||
static const G4int kDimension;
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4H3ToolsManager" };
|
||||
static constexpr G4int fkDimension = 3;
|
||||
};
|
||||
// inline methods
|
||||
|
||||
@@ -202,11 +203,11 @@ inline std::vector<tools::histo::h3d*>::iterator G4H3ToolsManager::BeginH3()
|
||||
inline std::vector<tools::histo::h3d*>::iterator G4H3ToolsManager::EndH3()
|
||||
{ return EndT(); }
|
||||
|
||||
inline std::vector<tools::histo::h3d*>::const_iterator
|
||||
inline std::vector<tools::histo::h3d*>::const_iterator
|
||||
G4H3ToolsManager::BeginConstH3() const
|
||||
{ return BeginConstT(); }
|
||||
|
||||
inline std::vector<tools::histo::h3d*>::const_iterator
|
||||
inline std::vector<tools::histo::h3d*>::const_iterator
|
||||
G4H3ToolsManager::EndConstH3() const
|
||||
{ return EndConstT(); }
|
||||
|
||||
@@ -216,7 +217,7 @@ inline const std::vector<tools::histo::h3d*>& G4H3ToolsManager::GetH3Vector() co
|
||||
inline const std::vector<G4HnInformation*>& G4H3ToolsManager::GetHnVector() const
|
||||
{ return fHnManager->GetHnVector(); }
|
||||
|
||||
inline std::shared_ptr<G4HnManager> G4H3ToolsManager::GetHnManager()
|
||||
inline std::shared_ptr<G4HnManager> G4H3ToolsManager::GetHnManager()
|
||||
{ return std::shared_ptr<G4HnManager>(fHnManager); }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,10 +35,11 @@
|
||||
#include "G4HnInformation.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
#include <tools/impi_world>
|
||||
#include <tools/histo/hmpi>
|
||||
#include "tools/impi_world"
|
||||
#include "tools/histo/hmpi"
|
||||
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
class G4MPIToolsManager
|
||||
{
|
||||
@@ -46,213 +47,35 @@ class G4MPIToolsManager
|
||||
G4MPIToolsManager(const G4AnalysisManagerState& state,
|
||||
tools::histo::hmpi* hmpi)
|
||||
: fState(state), fHmpi(hmpi) {}
|
||||
virtual ~G4MPIToolsManager() {}
|
||||
|
||||
G4MPIToolsManager() = delete;
|
||||
virtual ~G4MPIToolsManager() = default;
|
||||
|
||||
public:
|
||||
// methods
|
||||
template <typename T>
|
||||
G4bool Merge(const std::vector<T*>& htVector,
|
||||
// Methods
|
||||
template <typename HT>
|
||||
G4bool Merge(const std::vector<HT*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector);
|
||||
private:
|
||||
// methods
|
||||
template <typename T>
|
||||
private:
|
||||
// Methods
|
||||
template <typename HT>
|
||||
G4bool Send(G4int nofActiveT,
|
||||
const std::vector<T*>& htVector,
|
||||
const std::vector<HT*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector);
|
||||
|
||||
template <typename T>
|
||||
template <typename HT>
|
||||
G4bool Receive(G4int nofActiveT,
|
||||
const std::vector<T*>& htVector,
|
||||
const std::vector<HT*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector);
|
||||
|
||||
// data members
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4MPIToolsManager" };
|
||||
|
||||
// Data members
|
||||
const G4AnalysisManagerState& fState;
|
||||
tools::histo::hmpi* fHmpi;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4MPIToolsManager::Send(G4int nofActiveT,
|
||||
const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
G4bool finalResult = true;
|
||||
|
||||
// send object to destination rank
|
||||
// G4cout << "Begin send for " << nofActiveT << G4endl;
|
||||
fHmpi->beg_send(nofActiveT);
|
||||
|
||||
// pack objects
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
// skip sending if activation is enabled and HT is inactivated
|
||||
auto info = hnVector[i];
|
||||
if ( ( fState.GetIsActivation() && ( ! info->GetActivation() ) ) ) continue;
|
||||
// pack histogram for sending
|
||||
// G4cout << "Packed " << i << "th T" << G4endl;
|
||||
auto ht = htVector[i];
|
||||
auto result = fHmpi->pack(*ht);
|
||||
finalResult = result && finalResult;
|
||||
}
|
||||
|
||||
//G4cout << "Go to send all " << G4endl;
|
||||
if ( ! fHmpi->send(fHmpi->rank()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Rank: " << fHmpi->rank() << " : can't send histos.";
|
||||
G4Exception("G4H1ToolsManager::Receieve",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4MPIToolsManager::Receive(G4int nofActiveT,
|
||||
const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
G4int commSize;
|
||||
G4bool result = fHmpi->comm_size(commSize);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " Failed to get MPI commander size." << G4endl
|
||||
<< " Merging will not be performed.";
|
||||
G4Exception("G4H1ToolsManager::Merge",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get objects from source ranks
|
||||
for (G4int srank = 0; srank < commSize; ++srank) {
|
||||
|
||||
// skip destination rank
|
||||
if ( srank == fHmpi->rank() ) continue;
|
||||
|
||||
// get objects from this source rank
|
||||
//G4cout << "Go to wait_histos " << rank << G4endl;
|
||||
using class_pointer = std::pair<std::string,void*>;
|
||||
std::vector<class_pointer> hs;
|
||||
if ( ! fHmpi->wait_histos(srank, hs) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " wait_histos from " << srank << " : failed.";
|
||||
G4Exception("G4H1ToolsManager::Receieve",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check that we got the right number of objects
|
||||
if ( G4int(hs.size()) != nofActiveT ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " srank: " << srank << " : got " << hs.size() << " objects, "
|
||||
<< "while " << nofActiveT << " were expected." << G4endl;
|
||||
G4Exception("G4H1ToolsManager::Receieve",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
// merge the objects to destination rank
|
||||
G4int counter = 0;
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
// skip sending if activation is enabled and HT is inactivated
|
||||
auto info = hnVector[i];
|
||||
if ( ( fState.GetIsActivation() && ( ! info->GetActivation() ) ) ) continue;
|
||||
// merge histograms
|
||||
auto ht = htVector[i];
|
||||
auto newHt = static_cast<T*>(hs[counter++].second);
|
||||
ht->add(*newHt);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline G4bool G4MPIToolsManager::Merge(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
if ( ! htVector.size() ) return true;
|
||||
|
||||
// Get number of objects to be sent
|
||||
G4int nofActiveT = 0;
|
||||
if ( fState.GetIsActivation() ) {
|
||||
// only activated histograms will be treated
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto activation = hnVector[i]->GetActivation();
|
||||
if ( activation ) ++nofActiveT;
|
||||
}
|
||||
} else {
|
||||
nofActiveT = G4int(htVector.size());
|
||||
}
|
||||
|
||||
if ( ! nofActiveT ) return true;
|
||||
|
||||
G4int commRank;
|
||||
if ( ! fHmpi->comm_rank(commRank) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " Failed to get MPI commander rank." << G4endl
|
||||
<< " Merging will not be performed.";
|
||||
G4Exception("G4H1ToolsManager::Merge",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
G4bool finalResult = true;
|
||||
|
||||
if ( commRank != fHmpi->rank() ) {
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "on rank " << commRank
|
||||
<< " destination rank: " << fHmpi->rank();
|
||||
fState.GetVerboseL4()->Message("mpi send", "Hn|Pn", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto result = Send(nofActiveT, htVector, hnVector);
|
||||
|
||||
finalResult = result && finalResult;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "on rank " << commRank
|
||||
<< " destination rank: " << fHmpi->rank();
|
||||
fState.GetVerboseL1()->Message("send", "Hn|Pn", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "on rank " << commRank
|
||||
<< " destination rank: " << fHmpi->rank();
|
||||
fState.GetVerboseL4()->Message("mpi wait_histos", "Hn|Pn", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto result = Receive(nofActiveT, htVector, hnVector);
|
||||
|
||||
finalResult = result && finalResult;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "on rank " << commRank
|
||||
<< " destination rank: " << fHmpi->rank();
|
||||
fState.GetVerboseL1()->Message("mpi wait_histos", "Hn|Pn", description);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return finalResult;
|
||||
}
|
||||
#include "G4MPIToolsManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// The manager class for MPI applications.
|
||||
|
||||
// Author: Ivana Hrivnacova, 25/06/2015 (ivana@ipno.in2p3.fr)
|
||||
|
||||
using std::to_string;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4MPIToolsManager::Send(G4int nofActiveT,
|
||||
const std::vector<HT*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
auto result = true;
|
||||
|
||||
// send object to destination rank
|
||||
// G4cout << "Begin send for " << nofActiveT << G4endl;
|
||||
fHmpi->beg_send(nofActiveT);
|
||||
|
||||
// pack objects
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
// skip sending if activation is enabled and HT is inactivated
|
||||
auto info = hnVector[i];
|
||||
if ( ( fState.GetIsActivation() && ( ! info->GetActivation() ) ) ) continue;
|
||||
// pack histogram for sending
|
||||
// G4cout << "Packed " << i << "th T" << G4endl;
|
||||
auto ht = htVector[i];
|
||||
result &= fHmpi->pack(*ht);
|
||||
}
|
||||
|
||||
//G4cout << "Go to send all " << G4endl;
|
||||
if ( ! fHmpi->send(fHmpi->rank()) ) {
|
||||
G4Analysis::Warn(
|
||||
"Rank: " + to_string(fHmpi->rank()) + " : can't send histos.",
|
||||
fkClass, "Send");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4MPIToolsManager::Receive(G4int nofActiveT,
|
||||
const std::vector<HT*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
G4int commSize;
|
||||
G4bool result = fHmpi->comm_size(commSize);
|
||||
if ( ! result ) {
|
||||
G4Analysis::Warn(
|
||||
"Failed to get MPI commander size.\nMerging will not be performed.",
|
||||
fkClass, "Receive");
|
||||
return false;
|
||||
}
|
||||
|
||||
// get objects from source ranks
|
||||
for (G4int srank = 0; srank < commSize; ++srank) {
|
||||
|
||||
// skip destination rank
|
||||
if ( srank == fHmpi->rank() ) continue;
|
||||
|
||||
// get objects from this source rank
|
||||
// G4cout << "Go to wait_histos " << srank << G4endl;
|
||||
using class_pointer = std::pair<std::string,void*>;
|
||||
std::vector<class_pointer> hs;
|
||||
if ( ! fHmpi->wait_histos(srank, hs) ) {
|
||||
G4Analysis::Warn(
|
||||
"Wait_histos from " + to_string(srank) + " : failed.",
|
||||
fkClass, "Receive");
|
||||
return false;
|
||||
}
|
||||
|
||||
// check that we got the right number of objects
|
||||
if ( G4int(hs.size()) != nofActiveT ) {
|
||||
G4Analysis::Warn(
|
||||
"srank: " + to_string(srank) + " : got " + to_string(hs.size()) +
|
||||
" objects, while " + to_string(nofActiveT) +" were expected.",
|
||||
fkClass, "Receive");
|
||||
return false;
|
||||
}
|
||||
|
||||
// merge the objects to destination rank
|
||||
G4int counter = 0;
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
// skip sending if activation is enabled and HT is inactivated
|
||||
auto info = hnVector[i];
|
||||
if ( ( fState.GetIsActivation() && ( ! info->GetActivation() ) ) ) continue;
|
||||
// merge histograms
|
||||
auto ht = htVector[i];
|
||||
auto newHt = static_cast<HT*>(hs[counter++].second);
|
||||
ht->add(*newHt);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4MPIToolsManager::Merge(const std::vector<HT*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
if ( ! htVector.size() ) return true;
|
||||
|
||||
// Get number of objects to be sent
|
||||
G4int nofActiveT = 0;
|
||||
if ( fState.GetIsActivation() ) {
|
||||
// only activated histograms will be treated
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto activation = hnVector[i]->GetActivation();
|
||||
if ( activation ) ++nofActiveT;
|
||||
}
|
||||
} else {
|
||||
nofActiveT = G4int(htVector.size());
|
||||
}
|
||||
|
||||
if ( ! nofActiveT ) return true;
|
||||
|
||||
G4int commRank;
|
||||
if ( ! fHmpi->comm_rank(commRank) ) {
|
||||
G4Analysis::Warn(
|
||||
"Failed to get MPI commander rank.\nMerging will not be performed.",
|
||||
fkClass, "Merge");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( commRank != fHmpi->rank() ) {
|
||||
fState.Message(G4Analysis::kVL3, "mpi send", "Hn|Pn",
|
||||
"on rank " + to_string(commRank) +
|
||||
" destination rank: " + to_string(fHmpi->rank()));
|
||||
|
||||
result &= Send(nofActiveT, htVector, hnVector);
|
||||
|
||||
fState.Message(G4Analysis::kVL1, "mpi send", "Hn|Pn",
|
||||
"on rank " + to_string(commRank) +
|
||||
" destination rank: " + to_string(fHmpi->rank()));
|
||||
|
||||
} else {
|
||||
fState.Message(G4Analysis::kVL3, "mpi wait_histos", "Hn|Pn",
|
||||
"on rank " + to_string(commRank) +
|
||||
" destination rank: " + to_string(fHmpi->rank()));
|
||||
|
||||
result &= Receive(nofActiveT, htVector, hnVector);
|
||||
|
||||
fState.Message(G4Analysis::kVL1, "mpi wait_histos", "Hn|Pn",
|
||||
"on rank " + to_string(commRank) +
|
||||
" destination rank: " + to_string(fHmpi->rank()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
// Manager class for tools::histo::P1d.
|
||||
// It implements functions specific to the P1 type
|
||||
// (defined in g4tools).
|
||||
// (defined in g4tools).
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 24/07/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -42,10 +42,11 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
namespace tools {
|
||||
namespace histo {
|
||||
class p1d;
|
||||
namespace histo {
|
||||
class p1d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,28 +55,29 @@ class G4P1ToolsManager : public G4VP1Manager,
|
||||
{
|
||||
public:
|
||||
explicit G4P1ToolsManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4P1ToolsManager();
|
||||
G4P1ToolsManager() = delete;
|
||||
virtual ~G4P1ToolsManager() = default;
|
||||
|
||||
// Method to add profiles read from a file
|
||||
G4int AddP1(const G4String& name, tools::histo::p1d* p1d);
|
||||
// Method for merge (MT)
|
||||
void AddP1Vector(const std::vector<tools::histo::p1d*>& p1Vector);
|
||||
|
||||
|
||||
// Access methods
|
||||
//
|
||||
tools::histo::p1d* GetP1(G4int id, G4bool warn = true,
|
||||
G4bool onlyIfActive = true) const;
|
||||
|
||||
|
||||
// Iterators
|
||||
std::vector<tools::histo::p1d*>::iterator BeginP1();
|
||||
std::vector<tools::histo::p1d*>::iterator EndP1();
|
||||
std::vector<tools::histo::p1d*>::const_iterator BeginConstP1() const;
|
||||
std::vector<tools::histo::p1d*>::const_iterator EndConstP1() const;
|
||||
|
||||
|
||||
// Access to profile vector (needed for Write())
|
||||
const std::vector<tools::histo::p1d*>& GetP1Vector() const;
|
||||
const std::vector<G4HnInformation*>& GetHnVector() const;
|
||||
|
||||
const std::vector<G4HnInformation*>& GetHnVector() const;
|
||||
|
||||
protected:
|
||||
// Virtual functions from base class
|
||||
//
|
||||
@@ -85,39 +87,39 @@ class G4P1ToolsManager : public G4VP1Manager,
|
||||
virtual G4int CreateP1(const G4String& name, const G4String& title,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
G4double ymin = 0, G4double ymax = 0,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& xbinScheme = "linear") final;
|
||||
virtual G4int CreateP1(const G4String& name, const G4String& title,
|
||||
const std::vector<G4double>& edges,
|
||||
G4double ymin = 0, G4double ymax = 0,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none") final;
|
||||
|
||||
|
||||
virtual G4bool SetP1(G4int id,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
G4double ymin = 0, G4double ymax = 0,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& xbinScheme = "linear") final;
|
||||
virtual G4bool SetP1(G4int id,
|
||||
const std::vector<G4double>& edges,
|
||||
G4double ymin = 0, G4double ymax = 0,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none") final;
|
||||
virtual G4bool ScaleP1(G4int id, G4double factor) final;
|
||||
|
||||
|
||||
// Method to fill profiles
|
||||
//
|
||||
virtual G4bool FillP1(G4int id, G4double xvalue, G4double yvalue,
|
||||
virtual G4bool FillP1(G4int id, G4double xvalue, G4double yvalue,
|
||||
G4double weight = 1.0) final;
|
||||
|
||||
// Access methods
|
||||
@@ -146,24 +148,24 @@ class G4P1ToolsManager : public G4VP1Manager,
|
||||
virtual G4String GetP1YAxisTitle(G4int id) const final;
|
||||
|
||||
// Write data on ASCII file
|
||||
//virtual G4bool WriteOnAscii(std::ofstream& output) final;
|
||||
virtual G4bool WriteOnAscii(std::ofstream& output) final;
|
||||
|
||||
// Access to Hn manager
|
||||
virtual std::shared_ptr<G4HnManager> GetHnManager() final;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
//
|
||||
void AddP1Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
void AddP1Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
G4BinScheme xbinScheme) const;
|
||||
|
||||
// data members
|
||||
//static constexpr G4int kDimension = 1; // not yet supported on vc12
|
||||
static const G4int kDimension;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4P1ToolsManager" };
|
||||
static constexpr G4int fkDimension = 2;
|
||||
};
|
||||
|
||||
// inline methods
|
||||
@@ -174,11 +176,11 @@ inline std::vector<tools::histo::p1d*>::iterator G4P1ToolsManager::BeginP1()
|
||||
inline std::vector<tools::histo::p1d*>::iterator G4P1ToolsManager::EndP1()
|
||||
{ return EndT(); }
|
||||
|
||||
inline std::vector<tools::histo::p1d*>::const_iterator
|
||||
inline std::vector<tools::histo::p1d*>::const_iterator
|
||||
G4P1ToolsManager::BeginConstP1() const
|
||||
{ return BeginConstT(); }
|
||||
|
||||
inline std::vector<tools::histo::p1d*>::const_iterator
|
||||
inline std::vector<tools::histo::p1d*>::const_iterator
|
||||
G4P1ToolsManager::EndConstP1() const
|
||||
{ return EndConstT(); }
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
// Manager class for tools::histo::p2d.
|
||||
// It implements functions specific to the P2 type
|
||||
// (defined in g4tools).
|
||||
// (defined in g4tools).
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 24/07/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -41,10 +41,11 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
namespace tools {
|
||||
namespace histo {
|
||||
class p2d;
|
||||
namespace histo {
|
||||
class p2d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +54,14 @@ class G4P2ToolsManager : public G4VP2Manager,
|
||||
{
|
||||
public:
|
||||
explicit G4P2ToolsManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4P2ToolsManager();
|
||||
G4P2ToolsManager() = delete;
|
||||
virtual ~G4P2ToolsManager() = default;
|
||||
|
||||
// Method to add histograms read from a file
|
||||
G4int AddP2(const G4String& name, tools::histo::p2d* p2d);
|
||||
// Method for merge (MT)
|
||||
void AddP2Vector(const std::vector<tools::histo::p2d*>& p2Vector);
|
||||
|
||||
|
||||
// Access methods
|
||||
//
|
||||
tools::histo::p2d* GetP2(G4int id, G4bool warn = true,
|
||||
@@ -69,11 +71,11 @@ class G4P2ToolsManager : public G4VP2Manager,
|
||||
std::vector<tools::histo::p2d*>::iterator EndP2();
|
||||
std::vector<tools::histo::p2d*>::const_iterator BeginConstP2() const;
|
||||
std::vector<tools::histo::p2d*>::const_iterator EndConstP2() const;
|
||||
|
||||
|
||||
// Access to histogram vector (needed for Write())
|
||||
const std::vector<tools::histo::p2d*>& GetP2Vector() const;
|
||||
const std::vector<G4HnInformation*>& GetHnVector() const;
|
||||
|
||||
|
||||
protected:
|
||||
// Virtual functions from base class
|
||||
//
|
||||
@@ -81,61 +83,61 @@ class G4P2ToolsManager : public G4VP2Manager,
|
||||
// Methods to create histograms
|
||||
//
|
||||
virtual G4int CreateP2(const G4String& name, const G4String& title,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
G4double zmin = 0, G4double zmax = 0,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& zunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& zfcnName = "none",
|
||||
const G4String& xbinScheme = "linear",
|
||||
const G4String& ybinScheme = "linear") final;
|
||||
|
||||
|
||||
virtual G4int CreateP2(const G4String& name, const G4String& title,
|
||||
const std::vector<G4double>& xedges,
|
||||
const std::vector<G4double>& yedges,
|
||||
G4double zmin = 0, G4double zmax = 0,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& zunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& zfcnName = "none") final;
|
||||
|
||||
|
||||
virtual G4bool SetP2(G4int id,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
G4double zmin = 0, G4double zmax = 0,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& zunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& zfcnName = "none",
|
||||
const G4String& xbinScheme = "linear",
|
||||
const G4String& ybinScheme = "linear") final;
|
||||
|
||||
|
||||
virtual G4bool SetP2(G4int id,
|
||||
const std::vector<G4double>& xedges,
|
||||
const std::vector<G4double>& yedges,
|
||||
G4double zmin = 0, G4double zmax = 0,
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& xunitName = "none",
|
||||
const G4String& yunitName = "none",
|
||||
const G4String& zunitName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& xfcnName = "none",
|
||||
const G4String& yfcnName = "none",
|
||||
const G4String& zfcnName = "none") final;
|
||||
|
||||
virtual G4bool ScaleP2(G4int id, G4double factor) final;
|
||||
|
||||
|
||||
// Method to fill histograms
|
||||
//
|
||||
virtual G4bool FillP2(G4int id,
|
||||
virtual G4bool FillP2(G4int id,
|
||||
G4double xvalue, G4double yvalue, G4double zvalue,
|
||||
G4double weight = 1.0) final;
|
||||
|
||||
|
||||
|
||||
// Methods to manipulate histograms
|
||||
//
|
||||
@@ -154,7 +156,7 @@ class G4P2ToolsManager : public G4VP2Manager,
|
||||
virtual G4double GetP2YWidth(G4int id) const final;
|
||||
virtual G4double GetP2Zmin(G4int id) const final;
|
||||
virtual G4double GetP2Zmax(G4int id) const final;
|
||||
|
||||
|
||||
// Setters for attributes for plotting
|
||||
virtual G4bool SetP2Title(G4int id, const G4String& title) final;
|
||||
virtual G4bool SetP2XAxisTitle(G4int id, const G4String& title) final;
|
||||
@@ -166,27 +168,27 @@ class G4P2ToolsManager : public G4VP2Manager,
|
||||
virtual G4String GetP2XAxisTitle(G4int id) const final;
|
||||
virtual G4String GetP2YAxisTitle(G4int id) const final;
|
||||
virtual G4String GetP2ZAxisTitle(G4int id) const final;
|
||||
|
||||
|
||||
// Write data on ASCII file
|
||||
virtual G4bool WriteOnAscii(std::ofstream& output) final;
|
||||
|
||||
|
||||
// Access to Hn manager
|
||||
virtual std::shared_ptr<G4HnManager> GetHnManager() final;
|
||||
|
||||
private:
|
||||
void AddP2Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
void AddP2Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
G4BinScheme xbinScheme,
|
||||
G4BinScheme ybinScheme) const;
|
||||
|
||||
// data members
|
||||
// static constexpr G4int kDimension = 2; // not yet supported on vc12
|
||||
static const G4int kDimension;
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4P2ToolsManager" };
|
||||
static constexpr G4int fkDimension = 3;
|
||||
};
|
||||
|
||||
// inline methods
|
||||
@@ -197,11 +199,11 @@ inline std::vector<tools::histo::p2d*>::iterator G4P2ToolsManager::BeginP2()
|
||||
inline std::vector<tools::histo::p2d*>::iterator G4P2ToolsManager::EndP2()
|
||||
{ return EndT(); }
|
||||
|
||||
inline std::vector<tools::histo::p2d*>::const_iterator
|
||||
inline std::vector<tools::histo::p2d*>::const_iterator
|
||||
G4P2ToolsManager::BeginConstP2() const
|
||||
{ return BeginConstT(); }
|
||||
|
||||
inline std::vector<tools::histo::p2d*>::const_iterator
|
||||
inline std::vector<tools::histo::p2d*>::const_iterator
|
||||
G4P2ToolsManager::EndConstP2() const
|
||||
{ return EndConstT(); }
|
||||
|
||||
@@ -211,7 +213,7 @@ inline const std::vector<tools::histo::p2d*>& G4P2ToolsManager::GetP2Vector() co
|
||||
inline const std::vector<G4HnInformation*>& G4P2ToolsManager::GetHnVector() const
|
||||
{ return fHnManager->GetHnVector(); }
|
||||
|
||||
inline std::shared_ptr<G4HnManager> G4P2ToolsManager::GetHnManager()
|
||||
inline std::shared_ptr<G4HnManager> G4P2ToolsManager::GetHnManager()
|
||||
{ return std::shared_ptr<G4HnManager>(fHnManager); }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,14 +32,16 @@
|
||||
#define G4ToolsAnalysisManager_h 1
|
||||
|
||||
#include "G4VAnalysisManager.hh"
|
||||
#include "G4ToolsAnalysisMessenger.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
#include "tools/wroot/ntuple"
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4H1ToolsManager;
|
||||
class G4H2ToolsManager;
|
||||
@@ -49,17 +51,18 @@ class G4P2ToolsManager;
|
||||
|
||||
namespace tools {
|
||||
namespace histo {
|
||||
class hmpi;
|
||||
}
|
||||
class hmpi;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class G4ToolsAnalysisManager : public G4VAnalysisManager
|
||||
{
|
||||
friend class G4ToolsAnalysisMessenger;
|
||||
|
||||
public:
|
||||
explicit G4ToolsAnalysisManager(const G4String& type, G4bool isMaster = true);
|
||||
virtual ~G4ToolsAnalysisManager();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4ToolsAnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
@@ -80,56 +83,65 @@ class G4ToolsAnalysisManager : public G4VAnalysisManager
|
||||
std::vector<tools::histo::h1d*>::iterator EndH1();
|
||||
std::vector<tools::histo::h1d*>::const_iterator BeginConstH1() const;
|
||||
std::vector<tools::histo::h1d*>::const_iterator EndConstH1() const;
|
||||
|
||||
|
||||
std::vector<tools::histo::h2d*>::iterator BeginH2();
|
||||
std::vector<tools::histo::h2d*>::iterator EndH2();
|
||||
std::vector<tools::histo::h2d*>::const_iterator BeginConstH2() const;
|
||||
std::vector<tools::histo::h2d*>::const_iterator EndConstH2() const;
|
||||
|
||||
|
||||
std::vector<tools::histo::h3d*>::iterator BeginH3();
|
||||
std::vector<tools::histo::h3d*>::iterator EndH3();
|
||||
std::vector<tools::histo::h3d*>::const_iterator BeginConstH3() const;
|
||||
std::vector<tools::histo::h3d*>::const_iterator EndConstH3() const;
|
||||
|
||||
|
||||
std::vector<tools::histo::p1d*>::iterator BeginP1();
|
||||
std::vector<tools::histo::p1d*>::iterator EndP1();
|
||||
std::vector<tools::histo::p1d*>::const_iterator BeginConstP1() const;
|
||||
std::vector<tools::histo::p1d*>::const_iterator EndConstP1() const;
|
||||
|
||||
|
||||
std::vector<tools::histo::p2d*>::iterator BeginP2();
|
||||
std::vector<tools::histo::p2d*>::iterator EndP2();
|
||||
std::vector<tools::histo::p2d*>::const_iterator BeginConstP2() const;
|
||||
std::vector<tools::histo::p2d*>::const_iterator EndConstP2() const;
|
||||
|
||||
std::vector<tools::wroot::ntuple*>::iterator BeginNtuple();
|
||||
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;
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
explicit G4ToolsAnalysisManager(const G4String& type);
|
||||
|
||||
// Virtual methods from base class
|
||||
virtual G4bool PlotImpl() final;
|
||||
virtual G4bool MergeImpl(tools::histo::hmpi* hmpi) final;
|
||||
// methods
|
||||
G4bool Reset();
|
||||
virtual G4bool WriteImpl() override;
|
||||
virtual G4bool ResetImpl() override;
|
||||
virtual void ClearImpl() override;
|
||||
|
||||
// static data members
|
||||
static G4ThreadLocal G4ToolsAnalysisManager* fgToolsInstance;
|
||||
// Methods
|
||||
G4bool Merge();
|
||||
G4bool IsEmpty();
|
||||
|
||||
// data members
|
||||
G4H1ToolsManager* fH1Manager;
|
||||
G4H2ToolsManager* fH2Manager;
|
||||
G4H3ToolsManager* fH3Manager;
|
||||
G4P1ToolsManager* fP1Manager;
|
||||
G4P2ToolsManager* fP2Manager;
|
||||
// Static data members
|
||||
inline static G4ToolsAnalysisManager* fgMasterToolsInstance { nullptr };
|
||||
inline static G4ThreadLocal G4ToolsAnalysisManager* fgToolsInstance { nullptr };
|
||||
static constexpr std::string_view fkClass { "G4ToolsAnalysisManager" };
|
||||
|
||||
// Data members
|
||||
G4H1ToolsManager* fH1Manager { nullptr };
|
||||
G4H2ToolsManager* fH2Manager { nullptr };
|
||||
G4H3ToolsManager* fH3Manager { nullptr };
|
||||
G4P1ToolsManager* fP1Manager { nullptr };
|
||||
G4P2ToolsManager* fP2Manager { nullptr };
|
||||
|
||||
private:
|
||||
// // static data members
|
||||
// static G4ThreadLocal G4ToolsAnalysisManager* fgToolsInstance;
|
||||
// // Static data members
|
||||
// Static G4ThreadLocal G4ToolsAnalysisManager* fgToolsInstance;
|
||||
// Methods
|
||||
template <typename HT>
|
||||
G4bool WriteT(const std::vector<HT*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector);
|
||||
|
||||
// Data members
|
||||
std::unique_ptr<G4ToolsAnalysisMessenger> fMessenger;
|
||||
};
|
||||
|
||||
#include "G4ToolsAnalysisManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
#include "G4HnInformation.hh"
|
||||
#include "G4H1ToolsManager.hh"
|
||||
#include "G4H2ToolsManager.hh"
|
||||
#include "G4H3ToolsManager.hh"
|
||||
@@ -31,41 +32,98 @@
|
||||
#include "G4P2ToolsManager.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4ToolsAnalysisManager::WriteT(const std::vector<HT*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
auto result = true;
|
||||
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
|
||||
auto name = info->GetName();
|
||||
auto ht = htVector[i];
|
||||
|
||||
auto fileName = info->GetFileName();
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
|
||||
// skip writing if cannot get file manager (wrong file extension)
|
||||
if ( ! fileManager ) {
|
||||
G4Analysis::Warn(
|
||||
"Cannot get file manager for file " + fileName + ".\n" +
|
||||
"Writing " + G4Analysis::GetHnType<HT>() + " " + name + " will be skipped.",
|
||||
fkClass, "WriteT");
|
||||
continue;
|
||||
}
|
||||
|
||||
auto fileKind = " in file ";
|
||||
if ( fileName != "" ) {
|
||||
fileKind = " in extra file ";
|
||||
} else {
|
||||
fileName = fileManager->GetFullFileName();
|
||||
}
|
||||
|
||||
Message(G4Analysis::kVL4, "write", G4Analysis::GetHnType<HT>(),
|
||||
name + fileKind + fileName);
|
||||
|
||||
if ( ! fileManager->GetHnFileManager<HT>()->Write(ht, name, fileName) ) {
|
||||
G4Analysis::Warn(
|
||||
"Writing " + G4Analysis::GetHnType<HT>() + " " + name +
|
||||
" to file " + fileName + " failed.",
|
||||
fkClass, "WriteT");
|
||||
result = false;
|
||||
}
|
||||
|
||||
// notify that file has a written object
|
||||
fileManager->SetIsEmpty(fileName, false);
|
||||
|
||||
Message(G4Analysis::kVL3, "write", G4Analysis::GetHnType<HT>(),
|
||||
name + " in the " + fileKind + " file " + fileName);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::histo::h1d* G4ToolsAnalysisManager::GetH1(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return fH1Manager->GetH1(id, warn, onlyIfActive);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
inline
|
||||
tools::histo::h2d* G4ToolsAnalysisManager::GetH2(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return fH2Manager->GetH2(id, warn, onlyIfActive);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
inline
|
||||
tools::histo::h3d* G4ToolsAnalysisManager::GetH3(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return fH3Manager->GetH3(id, warn, onlyIfActive);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
inline
|
||||
tools::histo::p1d* G4ToolsAnalysisManager::GetP1(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return fP1Manager->GetP1(id, warn, onlyIfActive);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
inline
|
||||
tools::histo::p2d* G4ToolsAnalysisManager::GetP2(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return fP2Manager->GetP2(id, warn, onlyIfActive);
|
||||
}
|
||||
@@ -75,148 +133,148 @@ inline
|
||||
std::vector<tools::histo::h1d*>::iterator G4ToolsAnalysisManager::BeginH1()
|
||||
{
|
||||
return fH1Manager->BeginH1();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h1d*>::iterator G4ToolsAnalysisManager::EndH1()
|
||||
{
|
||||
return fH1Manager->EndH1();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h1d*>::const_iterator
|
||||
std::vector<tools::histo::h1d*>::const_iterator
|
||||
G4ToolsAnalysisManager::BeginConstH1() const
|
||||
{
|
||||
return fH1Manager->BeginConstH1();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h1d*>::const_iterator
|
||||
std::vector<tools::histo::h1d*>::const_iterator
|
||||
G4ToolsAnalysisManager::EndConstH1() const
|
||||
{
|
||||
return fH1Manager->EndConstH1();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h2d*>::iterator G4ToolsAnalysisManager::BeginH2()
|
||||
{
|
||||
return fH2Manager->BeginH2();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h2d*>::iterator G4ToolsAnalysisManager::EndH2()
|
||||
{
|
||||
return fH2Manager->EndH2();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h2d*>::const_iterator
|
||||
std::vector<tools::histo::h2d*>::const_iterator
|
||||
G4ToolsAnalysisManager::BeginConstH2() const
|
||||
{
|
||||
return fH2Manager->BeginConstH2();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h2d*>::const_iterator
|
||||
std::vector<tools::histo::h2d*>::const_iterator
|
||||
G4ToolsAnalysisManager::EndConstH2() const
|
||||
{
|
||||
return fH2Manager->EndConstH2();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h3d*>::iterator G4ToolsAnalysisManager::BeginH3()
|
||||
{
|
||||
return fH3Manager->BeginH3();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h3d*>::iterator G4ToolsAnalysisManager::EndH3()
|
||||
{
|
||||
return fH3Manager->EndH3();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h3d*>::const_iterator
|
||||
std::vector<tools::histo::h3d*>::const_iterator
|
||||
G4ToolsAnalysisManager::BeginConstH3() const
|
||||
{
|
||||
return fH3Manager->BeginConstH3();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::h3d*>::const_iterator
|
||||
std::vector<tools::histo::h3d*>::const_iterator
|
||||
G4ToolsAnalysisManager::EndConstH3() const
|
||||
{
|
||||
return fH3Manager->EndConstH3();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::p1d*>::iterator G4ToolsAnalysisManager::BeginP1()
|
||||
{
|
||||
return fP1Manager->BeginP1();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::p1d*>::iterator G4ToolsAnalysisManager::EndP1()
|
||||
{
|
||||
return fP1Manager->EndP1();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::p1d*>::const_iterator
|
||||
std::vector<tools::histo::p1d*>::const_iterator
|
||||
G4ToolsAnalysisManager::BeginConstP1() const
|
||||
{
|
||||
return fP1Manager->BeginConstP1();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::p1d*>::const_iterator
|
||||
std::vector<tools::histo::p1d*>::const_iterator
|
||||
G4ToolsAnalysisManager::EndConstP1() const
|
||||
{
|
||||
return fP1Manager->EndConstP1();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::p2d*>::iterator G4ToolsAnalysisManager::BeginP2()
|
||||
{
|
||||
return fP2Manager->BeginP2();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::p2d*>::iterator G4ToolsAnalysisManager::EndP2()
|
||||
{
|
||||
return fP2Manager->EndP2();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::p2d*>::const_iterator
|
||||
std::vector<tools::histo::p2d*>::const_iterator
|
||||
G4ToolsAnalysisManager::BeginConstP2() const
|
||||
{
|
||||
return fP2Manager->BeginConstP2();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::histo::p2d*>::const_iterator
|
||||
std::vector<tools::histo::p2d*>::const_iterator
|
||||
G4ToolsAnalysisManager::EndConstP2() const
|
||||
{
|
||||
return fP2Manager->EndConstP2();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// The messenger class for tools objects getters.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 29/10/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4ToolsAnalysisMessenger_h
|
||||
#define G4ToolsAnalysisMessenger_h 1
|
||||
|
||||
#include "G4UImessenger.hh"
|
||||
#include "G4THnManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class G4ToolsAnalysisManager;
|
||||
class G4UIcommand;
|
||||
|
||||
class G4ToolsAnalysisMessenger : public G4UImessenger
|
||||
{
|
||||
public:
|
||||
explicit G4ToolsAnalysisMessenger(G4ToolsAnalysisManager* manager);
|
||||
virtual ~G4ToolsAnalysisMessenger();
|
||||
|
||||
// Methods
|
||||
G4String GetCurrentValue (G4UIcommand* command);
|
||||
virtual void SetNewValue(G4UIcommand* command, G4String value) final;
|
||||
|
||||
private:
|
||||
// Methods
|
||||
template <typename HT>
|
||||
G4String GetHnAddress(G4int id, G4THnManager<HT>* htManager) const;
|
||||
|
||||
// Data members
|
||||
G4ToolsAnalysisManager* fManager; ///< Associated class
|
||||
std::unique_ptr<G4UIcommand> fGetH1Cmd;
|
||||
std::unique_ptr<G4UIcommand> fGetH2Cmd;
|
||||
std::unique_ptr<G4UIcommand> fGetH3Cmd;
|
||||
std::unique_ptr<G4UIcommand> fGetP1Cmd;
|
||||
std::unique_ptr<G4UIcommand> fGetP2Cmd;
|
||||
G4String fH1Value;
|
||||
G4String fH2Value;
|
||||
G4String fH3Value;
|
||||
G4String fP1Value;
|
||||
G4String fP2Value;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
template <typename HT>
|
||||
inline
|
||||
G4String G4ToolsAnalysisMessenger::GetHnAddress(
|
||||
G4int id, G4THnManager<HT>* htManager) const
|
||||
{
|
||||
auto ht = htManager->GetT(id);
|
||||
if ( ht != nullptr ) {
|
||||
std::ostringstream os;
|
||||
os << static_cast<void*>(ht);
|
||||
return os.str();
|
||||
}
|
||||
return G4String();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -32,14 +32,14 @@
|
||||
#define G4ToolsAnalysisReader_h 1
|
||||
|
||||
#include "G4VAnalysisReader.hh"
|
||||
#include "G4THnManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
#include "tools/wroot/ntuple"
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
|
||||
class G4H1ToolsManager;
|
||||
class G4H2ToolsManager;
|
||||
@@ -49,33 +49,55 @@ class G4P2ToolsManager;
|
||||
|
||||
namespace tools {
|
||||
namespace histo {
|
||||
class hmpi;
|
||||
}
|
||||
class hmpi;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class G4ToolsAnalysisReader : public G4VAnalysisReader
|
||||
{
|
||||
public:
|
||||
explicit G4ToolsAnalysisReader(const G4String& type, G4bool isMaster = true);
|
||||
virtual ~G4ToolsAnalysisReader();
|
||||
|
||||
virtual ~G4ToolsAnalysisReader() = default;
|
||||
|
||||
// Access methods
|
||||
tools::histo::h1d* GetH1(G4int id, G4bool warn = true) const;
|
||||
tools::histo::h2d* GetH2(G4int id, G4bool warn = true) const;
|
||||
tools::histo::h3d* GetH3(G4int id, G4bool warn = true) const;
|
||||
tools::histo::p1d* GetP1(G4int id, G4bool warn = true) const;
|
||||
tools::histo::p2d* GetP2(G4int id, G4bool warn = true) const;
|
||||
|
||||
|
||||
protected:
|
||||
// methods
|
||||
explicit G4ToolsAnalysisReader(const G4String& type);
|
||||
|
||||
// Virtual methods from base class
|
||||
virtual G4int ReadH1Impl(const G4String& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH2Impl(const G4String& h2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH3Impl(const G4String& h3Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP1Impl(const G4String& p1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP2Impl(const G4String& p2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
|
||||
// Fuction specific to output type
|
||||
template <typename HT>
|
||||
G4int ReadTImpl(const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName,
|
||||
G4THnManager<HT>* htManager);
|
||||
|
||||
// Methods
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4H1ToolsManager* fH1Manager;
|
||||
G4H2ToolsManager* fH2Manager;
|
||||
G4H3ToolsManager* fH3Manager;
|
||||
G4P1ToolsManager* fP1Manager;
|
||||
G4P2ToolsManager* fP2Manager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4ToolsAnalysisReader" };
|
||||
|
||||
// Data members
|
||||
G4H1ToolsManager* fH1Manager { nullptr };
|
||||
G4H2ToolsManager* fH2Manager { nullptr };
|
||||
G4H3ToolsManager* fH3Manager { nullptr };
|
||||
G4P1ToolsManager* fP1Manager { nullptr };
|
||||
G4P2ToolsManager* fP2Manager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4ToolsAnalysisReader.icc"
|
||||
|
||||
@@ -29,38 +29,70 @@
|
||||
#include "G4H3ToolsManager.hh"
|
||||
#include "G4P1ToolsManager.hh"
|
||||
#include "G4P2ToolsManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::histo::h1d* G4ToolsAnalysisReader::GetH1(G4int id, G4bool warn) const
|
||||
template <typename HT>
|
||||
inline
|
||||
G4int G4ToolsAnalysisReader::ReadTImpl(
|
||||
const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName,
|
||||
G4THnManager<HT>* htManager)
|
||||
{
|
||||
Message(G4Analysis::kVL4, "read", G4Analysis::GetHnType<HT>(), htName);
|
||||
|
||||
// Read hn
|
||||
auto ht = fVFileManager->GetHnRFileManager<HT>()->Read(
|
||||
htName, fileName, dirName, isUserFileName);
|
||||
|
||||
if ( ! ht ) {
|
||||
G4Analysis::Warn(
|
||||
"Streaming " + htName + " from file " + fileName +
|
||||
" directory " + dirName + " failed.",
|
||||
fkClass, "ReadTImpl");
|
||||
return G4Analysis::kInvalidId;
|
||||
}
|
||||
|
||||
auto id = htManager->RegisterT(static_cast<HT*>(ht), htName);
|
||||
|
||||
Message(G4Analysis::kVL2, "read", G4Analysis::GetHnType<HT>(), htName,
|
||||
id > G4Analysis::kInvalidId);
|
||||
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::histo::h1d* G4ToolsAnalysisReader::GetH1(G4int id, G4bool warn) const
|
||||
{
|
||||
return fH1Manager->GetH1(id, warn, false);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::histo::h2d* G4ToolsAnalysisReader::GetH2(G4int id, G4bool warn) const
|
||||
inline
|
||||
tools::histo::h2d* G4ToolsAnalysisReader::GetH2(G4int id, G4bool warn) const
|
||||
{
|
||||
return fH2Manager->GetH2(id, warn, false);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::histo::h3d* G4ToolsAnalysisReader::GetH3(G4int id, G4bool warn) const
|
||||
inline
|
||||
tools::histo::h3d* G4ToolsAnalysisReader::GetH3(G4int id, G4bool warn) const
|
||||
{
|
||||
return fH3Manager->GetH3(id, warn, false);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::histo::p1d* G4ToolsAnalysisReader::GetP1(G4int id, G4bool warn) const
|
||||
inline
|
||||
tools::histo::p1d* G4ToolsAnalysisReader::GetP1(G4int id, G4bool warn) const
|
||||
{
|
||||
return fP1Manager->GetP1(id, warn, false);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::histo::p2d* G4ToolsAnalysisReader::GetP2(G4int id, G4bool warn) const
|
||||
inline
|
||||
tools::histo::p2d* G4ToolsAnalysisReader::GetP2(G4int id, G4bool warn) const
|
||||
{
|
||||
return fP2Manager->GetP2(id, warn, false);
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ using G4H1Iterator = std::vector<tools::histo::h1d*>::iterator;
|
||||
using G4H1ConstIterator = std::vector<tools::histo::h1d*>::const_iterator;
|
||||
|
||||
// H2 types
|
||||
using G4H2 = tools::histo::h2d;
|
||||
using G4H2 = tools::histo::h2d;
|
||||
using G4H2Iterator = std::vector<tools::histo::h2d*>::iterator;
|
||||
using G4H2ConstIterator = std::vector<tools::histo::h2d*>::const_iterator;
|
||||
|
||||
// H3 types
|
||||
using G4H3 = tools::histo::h3d;
|
||||
using G4H3 = tools::histo::h3d;
|
||||
using G4H3Iterator = std::vector<tools::histo::h3d*>::iterator;
|
||||
using G4H3ConstIterator = std::vector<tools::histo::h3d*>::const_iterator;
|
||||
|
||||
@@ -62,4 +62,4 @@ using G4P2ConstIterator = std::vector<tools::histo::p2d*>::const_iterator;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ geant4_add_module(G4hntools
|
||||
PUBLIC_HEADERS
|
||||
G4BaseHistoUtilities.hh
|
||||
G4MPIToolsManager.hh
|
||||
G4MPIToolsManager.icc
|
||||
G4H1ToolsManager.hh
|
||||
G4H2ToolsManager.hh
|
||||
G4H3ToolsManager.hh
|
||||
@@ -12,6 +13,7 @@ geant4_add_module(G4hntools
|
||||
G4P2ToolsManager.hh
|
||||
G4ToolsAnalysisManager.hh
|
||||
G4ToolsAnalysisManager.icc
|
||||
G4ToolsAnalysisMessenger.hh
|
||||
G4ToolsAnalysisReader.hh
|
||||
G4ToolsAnalysisReader.icc
|
||||
g4hntools_defs.hh
|
||||
@@ -23,6 +25,7 @@ geant4_add_module(G4hntools
|
||||
G4P1ToolsManager.cc
|
||||
G4P2ToolsManager.cc
|
||||
G4ToolsAnalysisManager.cc
|
||||
G4ToolsAnalysisMessenger.cc
|
||||
G4ToolsAnalysisReader.cc)
|
||||
|
||||
geant4_module_link_libraries(G4hntools PUBLIC G4analysismng G4globman G4tools)
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
#include "tools/histo/axis"
|
||||
|
||||
using std::to_string;
|
||||
|
||||
namespace G4Analysis
|
||||
{
|
||||
|
||||
@@ -38,7 +40,7 @@ namespace G4Analysis
|
||||
G4int GetNbins(const G4ToolsBaseHisto& baseHisto, G4int dimension)
|
||||
{
|
||||
return baseHisto.get_axis(dimension).bins();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double GetMin(const G4ToolsBaseHisto& baseHisto, G4int dimension)
|
||||
@@ -46,7 +48,7 @@ G4double GetMin(const G4ToolsBaseHisto& baseHisto, G4int dimension)
|
||||
// Returns min data value
|
||||
|
||||
return baseHisto.get_axis(dimension).lower_edge();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double GetMax(const G4ToolsBaseHisto& baseHisto, G4int dimension)
|
||||
@@ -54,7 +56,7 @@ G4double GetMax(const G4ToolsBaseHisto& baseHisto, G4int dimension)
|
||||
// Returns max data value
|
||||
|
||||
return baseHisto.get_axis(dimension).upper_edge();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double GetWidth(const G4ToolsBaseHisto& baseHisto, G4int dimension,
|
||||
@@ -62,79 +64,68 @@ G4double GetWidth(const G4ToolsBaseHisto& baseHisto, G4int dimension,
|
||||
{
|
||||
auto nbins = baseHisto.get_axis(dimension).bins();
|
||||
if ( ! nbins ) {
|
||||
G4String functionName = "Get";
|
||||
functionName += hnType;
|
||||
functionName += "Width";
|
||||
G4ExceptionDescription description;
|
||||
description << " nbins = 0 (for " << hnType << ").";
|
||||
G4Exception(functionName, "Analysis_W014", JustWarning, description);
|
||||
Warn("nbins = 0 ! for " + hnType, kNamespaceName, "GetWidth");
|
||||
return 0.;
|
||||
}
|
||||
|
||||
return ( baseHisto.get_axis(dimension).upper_edge()
|
||||
}
|
||||
|
||||
return ( baseHisto.get_axis(dimension).upper_edge()
|
||||
- baseHisto.get_axis(dimension).lower_edge() )/nbins;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool SetTitle(G4ToolsBaseHisto& baseHisto, const G4String& title)
|
||||
{
|
||||
return baseHisto.set_title(title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool SetAxisTitle(G4ToolsBaseHisto& baseHisto, G4int dimension,
|
||||
G4bool SetAxisTitle(G4ToolsBaseHisto& baseHisto, G4int dimension,
|
||||
const G4String& title)
|
||||
{
|
||||
if ( dimension == kX ) {
|
||||
baseHisto.add_annotation(tools::histo::key_axis_x_title(), title);
|
||||
}
|
||||
else if ( dimension == kY ) {
|
||||
else if ( dimension == kY ) {
|
||||
baseHisto.add_annotation(tools::histo::key_axis_y_title(), title);
|
||||
}
|
||||
else if ( dimension == kZ ) {
|
||||
else if ( dimension == kZ ) {
|
||||
baseHisto.add_annotation(tools::histo::key_axis_z_title(), title);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String GetTitle(const G4ToolsBaseHisto& baseHisto)
|
||||
{
|
||||
return baseHisto.title();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String GetAxisTitle(const G4ToolsBaseHisto& baseHisto, G4int dimension,
|
||||
const G4String& hnType)
|
||||
const G4String& hnType)
|
||||
{
|
||||
G4String title;
|
||||
G4bool result = false;
|
||||
if ( dimension == kX ) {
|
||||
result = baseHisto.annotation(tools::histo::key_axis_x_title(), title);
|
||||
}
|
||||
else if ( dimension == kY ) {
|
||||
}
|
||||
else if ( dimension == kY ) {
|
||||
result = baseHisto.annotation(tools::histo::key_axis_y_title(), title);
|
||||
}
|
||||
else if ( dimension == kZ ) {
|
||||
else if ( dimension == kZ ) {
|
||||
result = baseHisto.annotation(tools::histo::key_axis_z_title(), title);
|
||||
}
|
||||
|
||||
if ( ! result ) {
|
||||
G4String axes("xyz");
|
||||
G4String axis = axes(dimension, 1);
|
||||
G4String functionName = "Get";
|
||||
functionName += hnType;
|
||||
functionName += axis;
|
||||
functionName += "Title";
|
||||
G4ExceptionDescription description;
|
||||
description << " Failed to get " << axis << " axis " << hnType << " title.";
|
||||
G4Exception(functionName, "Analysis_W014", JustWarning, description);
|
||||
Warn("Got wrong dimension " + to_string(dimension) + " for " + hnType,
|
||||
kNamespaceName, "GetAxisTitle");
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,9 +36,7 @@
|
||||
#include <fstream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
// static definitions
|
||||
const G4int G4H1ToolsManager::kDimension = 1;
|
||||
using std::to_string;
|
||||
|
||||
//
|
||||
// Constructors, destructor
|
||||
@@ -50,10 +48,6 @@ G4H1ToolsManager::G4H1ToolsManager(const G4AnalysisManagerState& state)
|
||||
G4THnManager<tools::histo::h1d>(state, "H1")
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4H1ToolsManager::~G4H1ToolsManager()
|
||||
{}
|
||||
|
||||
//
|
||||
// Utility functions
|
||||
//
|
||||
@@ -63,7 +57,7 @@ namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void UpdateH1Information(G4HnInformation* hnInformation,
|
||||
const G4String& unitName,
|
||||
const G4String& unitName,
|
||||
const G4String& fcnName,
|
||||
G4BinScheme binScheme)
|
||||
{
|
||||
@@ -72,45 +66,43 @@ void UpdateH1Information(G4HnInformation* hnInformation,
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void AddH1Annotation(tools::histo::h1d* h1d,
|
||||
const G4String& unitName,
|
||||
const G4String& unitName,
|
||||
const G4String& fcnName)
|
||||
{
|
||||
{
|
||||
G4String axisTitle;
|
||||
UpdateTitle(axisTitle, unitName, fcnName);
|
||||
UpdateTitle(axisTitle, unitName, fcnName);
|
||||
h1d->add_annotation(tools::histo::key_axis_x_title(), axisTitle);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h1d* CreateToolsH1(const G4String& title,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
const G4String& unitName,
|
||||
const G4String& fcnName,
|
||||
const G4String& binSchemeName)
|
||||
const G4String& binSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto unit = GetUnitValue(unitName);
|
||||
auto fcn = GetFunction(fcnName);
|
||||
auto binScheme = GetBinScheme(binSchemeName);
|
||||
|
||||
|
||||
if ( binScheme != G4BinScheme::kLog ) {
|
||||
if ( binScheme == G4BinScheme::kUser ) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4H1ToolsManager::CreateH1",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "CreateToolsH1");
|
||||
}
|
||||
return new tools::histo::h1d(title, nbins, fcn(xmin/unit), fcn(xmax/unit));
|
||||
}
|
||||
else {
|
||||
// Compute edges
|
||||
std::vector<G4double> edges;
|
||||
ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, edges);
|
||||
return new tools::histo::h1d(title, edges);
|
||||
return new tools::histo::h1d(title, edges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h1d* CreateToolsH1(const G4String& title,
|
||||
@@ -121,19 +113,20 @@ tools::histo::h1d* CreateToolsH1(const G4String& title,
|
||||
auto unit = GetUnitValue(unitName);
|
||||
auto fcn = GetFunction(fcnName);
|
||||
|
||||
// Apply function
|
||||
// Apply function
|
||||
std::vector<G4double> newEdges;
|
||||
ComputeEdges(edges, unit, fcn, newEdges);
|
||||
|
||||
return new tools::histo::h1d(title, newEdges);
|
||||
}
|
||||
|
||||
return new tools::histo::h1d(title, newEdges);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsH1(tools::histo::h1d* h1d,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
const G4String& unitName,
|
||||
const G4String& fcnName,
|
||||
const G4String& binSchemeName)
|
||||
const G4String& binSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto unit = GetUnitValue(unitName);
|
||||
auto fcn = GetFunction(fcnName);
|
||||
@@ -143,13 +136,11 @@ void ConfigureToolsH1(tools::histo::h1d* h1d,
|
||||
if ( binScheme == G4BinScheme::kUser ) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4H1ToolsManager::SetH1",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "ConfigureToolsH1");
|
||||
|
||||
}
|
||||
h1d->configure(nbins, fcn(xmin/unit), fcn(xmax/unit));
|
||||
}
|
||||
else {
|
||||
@@ -158,7 +149,7 @@ void ConfigureToolsH1(tools::histo::h1d* h1d,
|
||||
ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, edges);
|
||||
h1d->configure(edges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsH1(tools::histo::h1d* h1d,
|
||||
@@ -177,21 +168,21 @@ void ConfigureToolsH1(tools::histo::h1d* h1d,
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4H1ToolsManager::AddH1Information(const G4String& name,
|
||||
const G4String& unitName,
|
||||
void G4H1ToolsManager::AddH1Information(const G4String& name,
|
||||
const G4String& unitName,
|
||||
const G4String& fcnName,
|
||||
G4BinScheme binScheme) const
|
||||
{
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, kDimension);
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, fkDimension);
|
||||
hnInformation->AddDimension(unitName, fcnName, binScheme);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -201,88 +192,79 @@ G4int G4H1ToolsManager::CreateH1(const G4String& name, const G4String& title,
|
||||
const G4String& unitName, const G4String& fcnName,
|
||||
const G4String& binSchemeName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "H1", name);
|
||||
#endif
|
||||
|
||||
Message(kVL4, "create", "H1", name);
|
||||
|
||||
// Create H1
|
||||
auto h1d
|
||||
= CreateToolsH1(title, nbins, xmin, xmax, unitName, fcnName, binSchemeName);
|
||||
|
||||
= CreateToolsH1(title, nbins, xmin, xmax, unitName, fcnName, binSchemeName,
|
||||
fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddH1Annotation(h1d, unitName, fcnName);
|
||||
|
||||
AddH1Annotation(h1d, unitName, fcnName);
|
||||
|
||||
// Save H1 information
|
||||
auto binScheme = GetBinScheme(binSchemeName);
|
||||
AddH1Information(name, unitName, fcnName, binScheme);
|
||||
|
||||
// Register histogram
|
||||
auto id = RegisterT(h1d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "H1", name);
|
||||
#endif
|
||||
|
||||
// Register histogram
|
||||
auto id = RegisterT(h1d, name);
|
||||
|
||||
Message(kVL2, "create", "H1", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H1ToolsManager::CreateH1(const G4String& name, const G4String& title,
|
||||
const std::vector<G4double>& edges,
|
||||
const G4String& unitName, const G4String& fcnName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "H1", name);
|
||||
#endif
|
||||
auto h1d
|
||||
Message(kVL4, "create", "H1", name);
|
||||
|
||||
auto h1d
|
||||
= CreateToolsH1(title, edges, unitName, fcnName);
|
||||
|
||||
|
||||
// Add annotation
|
||||
AddH1Annotation(h1d, unitName, fcnName);
|
||||
|
||||
AddH1Annotation(h1d, unitName, fcnName);
|
||||
|
||||
// Save H1 information
|
||||
AddH1Information(name, unitName, fcnName, G4BinScheme::kUser);
|
||||
|
||||
// Register histogram
|
||||
auto id = RegisterT(h1d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "H1", name);
|
||||
#endif
|
||||
|
||||
// Register histogram
|
||||
auto id = RegisterT(h1d, name);
|
||||
|
||||
Message(kVL2, "create", "H1", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H1ToolsManager::SetH1(G4int id,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
const G4String& unitName, const G4String& fcnName,
|
||||
const G4String& binSchemeName)
|
||||
{
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "SetH1", false, false);
|
||||
if ( ! h1d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id,"SetH1");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "H1", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "H1", info->GetName());
|
||||
|
||||
// Configure tools h1
|
||||
ConfigureToolsH1(h1d, nbins, xmin, xmax, unitName, fcnName, binSchemeName);
|
||||
ConfigureToolsH1(h1d, nbins, xmin, xmax, unitName, fcnName, binSchemeName,
|
||||
fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddH1Annotation(h1d, unitName, fcnName);
|
||||
|
||||
AddH1Annotation(h1d, unitName, fcnName);
|
||||
|
||||
// Update information
|
||||
auto binScheme = GetBinScheme(binSchemeName);
|
||||
UpdateH1Information(info, unitName, fcnName, binScheme);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -296,27 +278,25 @@ G4bool G4H1ToolsManager::SetH1(G4int id,
|
||||
if ( ! h1d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id,"SetH1");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "H1", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "H1", info->GetName());
|
||||
|
||||
// Configure tools h1
|
||||
ConfigureToolsH1(h1d, edges, unitName, fcnName);
|
||||
|
||||
// Add annotation
|
||||
AddH1Annotation(h1d, unitName, fcnName);
|
||||
|
||||
// Update information
|
||||
// Add annotation
|
||||
AddH1Annotation(h1d, unitName, fcnName);
|
||||
|
||||
// Update information
|
||||
UpdateH1Information(info, unitName, fcnName, G4BinScheme::kUser);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H1ToolsManager::ScaleH1(G4int id, G4double factor)
|
||||
{
|
||||
@@ -324,7 +304,7 @@ G4bool G4H1ToolsManager::ScaleH1(G4int id, G4double factor)
|
||||
if ( ! h1d ) return false;
|
||||
|
||||
return h1d->scale(factor);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H1ToolsManager::FillH1(G4int id, G4double value, G4double weight)
|
||||
@@ -333,22 +313,21 @@ G4bool G4H1ToolsManager::FillH1(G4int id, G4double value, G4double weight)
|
||||
if ( ! h1d ) return false;
|
||||
|
||||
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
|
||||
//G4cout << "Skipping FillH1 for " << id << G4endl;
|
||||
return false;
|
||||
}
|
||||
//G4cout << "Skipping FillH1 for " << id << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto info
|
||||
auto info
|
||||
= fHnManager->GetHnDimensionInformation(id, kX, "FillH1");
|
||||
h1d->fill(info->fFcn(value/info->fUnit), weight);
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " id " << id << " value " << value
|
||||
<< " fcn(value/unit) " << info->fFcn(value/info->fUnit)
|
||||
<< " weight " << weight;
|
||||
fState.GetVerboseL4()->Message("fill", "H1", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( IsVerbose(kVL4) ) {
|
||||
Message(kVL4, "fill", "H1",
|
||||
" id " + to_string(id) + " value " + to_string(value) +
|
||||
" fcn(value/unit) " + to_string(info->fFcn(value/info->fUnit)) +
|
||||
" weight " + to_string(weight));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -356,16 +335,16 @@ G4bool G4H1ToolsManager::FillH1(G4int id, G4double value, G4double weight)
|
||||
G4int G4H1ToolsManager::GetH1Id(const G4String& name, G4bool warn) const
|
||||
{
|
||||
return GetTId(name, warn);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H1ToolsManager::GetH1Nbins(G4int id) const
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "GetH1Nbins");
|
||||
if ( ! h1d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*h1d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H1ToolsManager::GetH1Xmin(G4int id) const
|
||||
@@ -374,82 +353,82 @@ G4double G4H1ToolsManager::GetH1Xmin(G4int id) const
|
||||
|
||||
auto h1d = GetTInFunction(id, "GetH1Xmin");
|
||||
if ( ! h1d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*h1d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H1ToolsManager::GetH1Xmax(G4int id) const
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "GetH1Xmax");
|
||||
if ( ! h1d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*h1d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H1ToolsManager::GetH1Width(G4int id) const
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "GetH1XWidth", true, false);
|
||||
if ( ! h1d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*h1d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H1ToolsManager::SetH1Title(G4int id, const G4String& title)
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "SetH1Title");
|
||||
if ( ! h1d ) return false;
|
||||
|
||||
|
||||
return SetTitle(*h1d, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H1ToolsManager::SetH1XAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "SetH1XAxisTitle");
|
||||
if ( ! h1d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*h1d, kX, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H1ToolsManager::SetH1YAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "SetH1YAxisTitle");
|
||||
if ( ! h1d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*h1d, kY, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H1ToolsManager::GetH1Title(G4int id) const
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "GetH1Title");
|
||||
if ( ! h1d ) return "";
|
||||
|
||||
|
||||
return GetTitle(*h1d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H1ToolsManager::GetH1XAxisTitle(G4int id) const
|
||||
G4String G4H1ToolsManager::GetH1XAxisTitle(G4int id) const
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "GetH1XAxisTitle");
|
||||
if ( ! h1d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*h1d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H1ToolsManager::GetH1YAxisTitle(G4int id) const
|
||||
G4String G4H1ToolsManager::GetH1YAxisTitle(G4int id) const
|
||||
{
|
||||
auto h1d = GetTInFunction(id, "GetH1YAxisTitle");
|
||||
if ( ! h1d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*h1d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H1ToolsManager::WriteOnAscii(std::ofstream& output)
|
||||
@@ -458,58 +437,53 @@ G4bool G4H1ToolsManager::WriteOnAscii(std::ofstream& output)
|
||||
// According to the implementation by Michel Maire, originally in
|
||||
// extended examples.
|
||||
|
||||
// h1 histograms
|
||||
// Do nothing if no histograms are selected
|
||||
if ( ! fHnManager->IsAscii() ) return true;
|
||||
|
||||
// Write h1 histograms
|
||||
for ( G4int i=0; i<G4int(fTVector.size()); ++i ) {
|
||||
auto id = i + fHnManager->GetFirstId();
|
||||
auto info = fHnManager->GetHnInformation(id,"WriteOnAscii");
|
||||
auto info = fHnManager->GetHnInformation(id,"WriteOnAscii");
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( ! info->GetAscii() ) continue;
|
||||
if ( ! info->GetAscii() ) continue;
|
||||
auto h1 = fTVector[i];
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()->Message("write on ascii", "h1d", info->GetName());
|
||||
#endif
|
||||
|
||||
output << "\n 1D histogram " << id << ": " << h1->title()
|
||||
<< "\n \n \t X \t\t Y" << G4endl;
|
||||
|
||||
Message(kVL3, "write on ascii", "h1d", info->GetName());
|
||||
|
||||
output << "\n 1D histogram " << id << ": " << h1->title()
|
||||
<< "\n \n \t X \t\t Bin Height" << G4endl;
|
||||
|
||||
for (G4int j=0; j< G4int(h1->axis().bins()); ++j) {
|
||||
output << " " << j << "\t"
|
||||
output << " " << j << "\t"
|
||||
<< h1->axis().bin_center(j) << "\t"
|
||||
<< h1->bin_height(j) << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
return output.good();
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H1ToolsManager::AddH1(const G4String& name, tools::histo::h1d* h1d)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("add", "H1", name);
|
||||
#endif
|
||||
|
||||
Message(kVL4, "add", "H1", name);
|
||||
|
||||
// Add annotation
|
||||
AddH1Annotation(h1d, "none", "none");
|
||||
AddH1Annotation(h1d, "none", "none");
|
||||
// Add information
|
||||
AddH1Information(name, "none", "none", G4BinScheme::kLinear);
|
||||
|
||||
// Register histogram
|
||||
auto id = RegisterT(h1d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("add", "H1", name);
|
||||
#endif
|
||||
|
||||
// Register histogram
|
||||
auto id = RegisterT(h1d, name);
|
||||
|
||||
Message(kVL2, "add", "H1", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -517,11 +491,11 @@ void G4H1ToolsManager::AddH1Vector(
|
||||
const std::vector<tools::histo::h1d*>& h1Vector)
|
||||
{
|
||||
AddTVector(h1Vector);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h1d* G4H1ToolsManager::GetH1(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return GetTInFunction(id, "GetH1", warn, onlyIfActive);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,7 @@
|
||||
#include <fstream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
// static definitions
|
||||
const G4int G4H2ToolsManager::kDimension = 2;
|
||||
using std::to_string;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4H2ToolsManager::G4H2ToolsManager(const G4AnalysisManagerState& state)
|
||||
@@ -46,10 +44,6 @@ G4H2ToolsManager::G4H2ToolsManager(const G4AnalysisManagerState& state)
|
||||
G4THnManager<tools::histo::h2d>(state, "H2")
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4H2ToolsManager::~G4H2ToolsManager()
|
||||
{}
|
||||
|
||||
//
|
||||
// Utility functions
|
||||
//
|
||||
@@ -58,8 +52,8 @@ namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void UpdateH2Information(G4HnInformation* hnInformation,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
G4BinScheme xbinScheme,
|
||||
@@ -67,23 +61,23 @@ void UpdateH2Information(G4HnInformation* hnInformation,
|
||||
{
|
||||
hnInformation->SetDimension(kX, xunitName, xfcnName, xbinScheme);
|
||||
hnInformation->SetDimension(kY, yunitName, yfcnName, ybinScheme);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void AddH2Annotation(tools::histo::h2d* h2d,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName)
|
||||
{
|
||||
{
|
||||
G4String xaxisTitle;
|
||||
G4String yaxisTitle;
|
||||
UpdateTitle(xaxisTitle, xunitName, xfcnName);
|
||||
UpdateTitle(yaxisTitle, yunitName, yfcnName);
|
||||
UpdateTitle(xaxisTitle, xunitName, xfcnName);
|
||||
UpdateTitle(yaxisTitle, yunitName, yfcnName);
|
||||
h2d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
|
||||
h2d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h2d* CreateToolsH2(
|
||||
const G4String& title,
|
||||
@@ -91,10 +85,12 @@ tools::histo::h2d* CreateToolsH2(
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName)
|
||||
const G4String& ybinSchemeName,
|
||||
std::string_view className)
|
||||
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
@@ -102,22 +98,19 @@ tools::histo::h2d* CreateToolsH2(
|
||||
auto yfcn = GetFunction(yfcnName);
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
|
||||
|
||||
if ( xbinScheme != G4BinScheme::kLog && ybinScheme != G4BinScheme::kLog) {
|
||||
if ( xbinScheme == G4BinScheme::kUser || ybinScheme == G4BinScheme::kUser) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4H2ToolsManager::CreateH2",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
return new tools::histo::h2d(title,
|
||||
nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "CreateToolsH2");
|
||||
}
|
||||
return new tools::histo::h2d(title,
|
||||
nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
nybins, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
// h2 objects are deleted in destructor and reset when
|
||||
// h2 objects are deleted in destructor and reset when
|
||||
// closing a file.
|
||||
}
|
||||
else {
|
||||
@@ -126,9 +119,9 @@ tools::histo::h2d* CreateToolsH2(
|
||||
ComputeEdges(nxbins, xmin, xmax, xunit, xfcn, xbinScheme, xedges);
|
||||
std::vector<G4double> yedges;
|
||||
ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
|
||||
return new tools::histo::h2d(title, xedges, yedges);
|
||||
return new tools::histo::h2d(title, xedges, yedges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h2d* CreateToolsH2(
|
||||
@@ -139,22 +132,22 @@ tools::histo::h2d* CreateToolsH2(
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName)
|
||||
{
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
auto xfcn = GetFunction(xfcnName);
|
||||
auto yfcn = GetFunction(yfcnName);
|
||||
|
||||
// Apply function
|
||||
// Apply function
|
||||
std::vector<G4double> xnewEdges;
|
||||
ComputeEdges(xedges, xunit, xfcn, xnewEdges);
|
||||
std::vector<G4double> ynewEdges;
|
||||
ComputeEdges(yedges, yunit, yfcn, ynewEdges);
|
||||
|
||||
return new tools::histo::h2d(title, xnewEdges, ynewEdges);
|
||||
// h2 objects are deleted in destructor and reset when
|
||||
|
||||
return new tools::histo::h2d(title, xnewEdges, ynewEdges);
|
||||
// h2 objects are deleted in destructor and reset when
|
||||
// closing a file.
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsH2(tools::histo::h2d* h2d,
|
||||
@@ -162,10 +155,11 @@ void ConfigureToolsH2(tools::histo::h2d* h2d,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName)
|
||||
const G4String& ybinSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
@@ -173,19 +167,16 @@ void ConfigureToolsH2(tools::histo::h2d* h2d,
|
||||
auto yfcn = GetFunction(yfcnName);
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
|
||||
|
||||
if ( xbinScheme != G4BinScheme::kLog && ybinScheme != G4BinScheme::kLog) {
|
||||
if ( xbinScheme == G4BinScheme::kUser || ybinScheme == G4BinScheme::kUser) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4H2ToolsManager::CreateH2",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
h2d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "ConfigureToolsH2");
|
||||
}
|
||||
h2d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
nybins, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
}
|
||||
else {
|
||||
@@ -196,7 +187,7 @@ void ConfigureToolsH2(tools::histo::h2d* h2d,
|
||||
ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
|
||||
h2d->configure(xedges, yedges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsH2(tools::histo::h2d* h2d,
|
||||
@@ -228,20 +219,20 @@ void ConfigureToolsH2(tools::histo::h2d* h2d,
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4H2ToolsManager::AddH2Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
void G4H2ToolsManager::AddH2Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
G4BinScheme xbinScheme,
|
||||
G4BinScheme ybinScheme) const
|
||||
{
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, 2);
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, fkDimension);
|
||||
hnInformation->AddDimension(xunitName, xfcnName, xbinScheme);
|
||||
hnInformation->AddDimension(yunitName, yfcnName, ybinScheme);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -251,38 +242,33 @@ G4int G4H2ToolsManager::CreateH2(const G4String& name, const G4String& title,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName)
|
||||
|
||||
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "H2", name);
|
||||
#endif
|
||||
Message(kVL4, "create", "H2", name);
|
||||
|
||||
tools::histo::h2d* h2d
|
||||
= CreateToolsH2(title, nxbins, xmin, xmax, nybins, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName,
|
||||
xbinSchemeName, ybinSchemeName);
|
||||
|
||||
= CreateToolsH2(title, nxbins, xmin, xmax, nybins, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName,
|
||||
xbinSchemeName, ybinSchemeName, fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Save H2 information
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
AddH2Information(
|
||||
name, xunitName, yunitName, xfcnName, yfcnName, xbinScheme, ybinScheme);
|
||||
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h2d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "H2", name);
|
||||
#endif
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h2d, name);
|
||||
|
||||
Message(kVL2, "create", "H2", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H2ToolsManager::CreateH2(const G4String& name, const G4String& title,
|
||||
@@ -290,60 +276,54 @@ G4int G4H2ToolsManager::CreateH2(const G4String& name, const G4String& title,
|
||||
const std::vector<G4double>& yedges,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName)
|
||||
|
||||
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "H2", name);
|
||||
#endif
|
||||
Message(kVL4, "create", "H2", name);
|
||||
|
||||
tools::histo::h2d* h2d
|
||||
= CreateToolsH2(title, xedges, yedges,
|
||||
xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
= CreateToolsH2(title, xedges, yedges,
|
||||
xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Add annotation
|
||||
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Save H2 information
|
||||
AddH2Information(
|
||||
name, xunitName, yunitName, xfcnName, yfcnName, G4BinScheme::kUser, G4BinScheme::kUser);
|
||||
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h2d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "H2", name);
|
||||
#endif
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h2d, name);
|
||||
|
||||
Message(kVL2, "create", "H2", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::SetH2(G4int id,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName)
|
||||
{
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "SetH2", false, false);
|
||||
if ( ! h2d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id, "SetH2");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "H2", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "H2", info->GetName());
|
||||
|
||||
// Configure tools h2
|
||||
ConfigureToolsH2(
|
||||
h2d, nxbins, xmin, xmax, nybins, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName, xbinSchemeName, ybinSchemeName);
|
||||
h2d, nxbins, xmin, xmax, nybins, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName, xbinSchemeName, ybinSchemeName,
|
||||
fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Update information
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
@@ -351,43 +331,41 @@ G4bool G4H2ToolsManager::SetH2(G4int id,
|
||||
info, xunitName, yunitName, xfcnName, yfcnName, xbinScheme, ybinScheme);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::SetH2(G4int id,
|
||||
const std::vector<G4double>& xedges,
|
||||
const std::vector<G4double>& yedges,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName)
|
||||
{
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "SetH2", false, false);
|
||||
if ( ! h2d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id, "SetH2");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "H2", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "H2", info->GetName());
|
||||
|
||||
// Configure tools h2
|
||||
ConfigureToolsH2(h2d, xedges, yedges, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Add annotation
|
||||
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Update information
|
||||
UpdateH2Information(
|
||||
info, xunitName, yunitName, xfcnName, yfcnName, G4BinScheme::kUser, G4BinScheme::kUser);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::ScaleH2(G4int id, G4double factor)
|
||||
{
|
||||
@@ -395,39 +373,38 @@ G4bool G4H2ToolsManager::ScaleH2(G4int id, G4double factor)
|
||||
if ( ! h2d ) return false;
|
||||
|
||||
return h2d->scale(factor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::FillH2(G4int id,
|
||||
G4double xvalue, G4double yvalue,
|
||||
G4double weight)
|
||||
G4bool G4H2ToolsManager::FillH2(G4int id,
|
||||
G4double xvalue, G4double yvalue,
|
||||
G4double weight)
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "FillH2", true, false);
|
||||
if ( ! h2d ) return false;
|
||||
|
||||
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
G4HnDimensionInformation* xInfo
|
||||
G4HnDimensionInformation* xInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kX, "FillH2");
|
||||
G4HnDimensionInformation* yInfo
|
||||
G4HnDimensionInformation* yInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kY, "FillH2");
|
||||
|
||||
h2d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
|
||||
h2d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
|
||||
yInfo->fFcn(yvalue/yInfo->fUnit), weight);
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " id " << id
|
||||
<< " xvalue " << xvalue
|
||||
<< " xfcn(xvalue/xunit) " << xInfo->fFcn(xvalue/xInfo->fUnit)
|
||||
<< " yvalue " << yvalue
|
||||
<< " yfcn(yvalue/yunit) " << yInfo->fFcn(yvalue/yInfo->fUnit)
|
||||
<< " weight " << weight;
|
||||
fState.GetVerboseL4()->Message("fill", "H2", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( IsVerbose(kVL4) ) {
|
||||
Message(kVL4, "fill", "H2",
|
||||
" id " + to_string(id) +
|
||||
" xvalue " + to_string(xvalue) +
|
||||
" xfcn(xvalue/xunit) " + to_string(xInfo->fFcn(xvalue/xInfo->fUnit)) +
|
||||
" yvalue " + to_string(yvalue) +
|
||||
" yfcn(yvalue/yunit) " + to_string(yInfo->fFcn(yvalue/yInfo->fUnit)) +
|
||||
" weight " + to_string(weight));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -435,16 +412,16 @@ G4bool G4H2ToolsManager::FillH2(G4int id,
|
||||
G4int G4H2ToolsManager::GetH2Id(const G4String& name, G4bool warn) const
|
||||
{
|
||||
return GetTId(name, warn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H2ToolsManager::GetH2Nxbins(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2NXbins");
|
||||
if ( ! h2d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*h2d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H2ToolsManager::GetH2Xmin(G4int id) const
|
||||
@@ -453,36 +430,36 @@ G4double G4H2ToolsManager::GetH2Xmin(G4int id) const
|
||||
|
||||
auto h2d = GetTInFunction(id, "GetH2Xmin");
|
||||
if ( ! h2d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*h2d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H2ToolsManager::GetH2Xmax(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2Xmax");
|
||||
if ( ! h2d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*h2d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H2ToolsManager::GetH2XWidth(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2XWidth", true, false);
|
||||
if ( ! h2d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*h2d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H2ToolsManager::GetH2Nybins(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2NYbins");
|
||||
if ( ! h2d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*h2d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H2ToolsManager::GetH2Ymin(G4int id) const
|
||||
@@ -491,148 +468,166 @@ G4double G4H2ToolsManager::GetH2Ymin(G4int id) const
|
||||
|
||||
auto h2d = GetTInFunction(id, "GetH2Ymin");
|
||||
if ( ! h2d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*h2d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H2ToolsManager::GetH2Ymax(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2Ymax");
|
||||
if ( ! h2d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*h2d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H2ToolsManager::GetH2YWidth(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2YWidth", true, false);
|
||||
if ( ! h2d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*h2d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::SetH2Title(G4int id, const G4String& title)
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "SetH2Title");
|
||||
if ( ! h2d ) return false;
|
||||
|
||||
|
||||
return SetTitle(*h2d, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::SetH2XAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "SetH2XAxisTitle");
|
||||
if ( ! h2d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*h2d, kX, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::SetH2YAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "SetH2YAxisTitle");
|
||||
if ( ! h2d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*h2d, kY, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::SetH2ZAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "SetH2ZAxisTitle");
|
||||
if ( ! h2d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*h2d, kZ, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H2ToolsManager::GetH2Title(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2Title");
|
||||
if ( ! h2d ) return "";
|
||||
|
||||
|
||||
return GetTitle(*h2d);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H2ToolsManager::GetH2XAxisTitle(G4int id) const
|
||||
G4String G4H2ToolsManager::GetH2XAxisTitle(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2XAxisTitle");
|
||||
if ( ! h2d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*h2d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H2ToolsManager::GetH2YAxisTitle(G4int id) const
|
||||
G4String G4H2ToolsManager::GetH2YAxisTitle(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2YAxisTitle");
|
||||
if ( ! h2d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*h2d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H2ToolsManager::GetH2ZAxisTitle(G4int id) const
|
||||
G4String G4H2ToolsManager::GetH2ZAxisTitle(G4int id) const
|
||||
{
|
||||
auto h2d = GetTInFunction(id, "GetH2ZAxisTitle");
|
||||
if ( ! h2d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*h2d, kZ, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H2ToolsManager::WriteOnAscii(std::ofstream& /*output*/)
|
||||
G4bool G4H2ToolsManager::WriteOnAscii(std::ofstream& output)
|
||||
{
|
||||
// Write selected objects on ASCII file
|
||||
// According to the implementation by Michel Maire, originally in
|
||||
// extended examples.
|
||||
// Not yet available for H2
|
||||
|
||||
return ! fHnManager->IsAscii();
|
||||
}
|
||||
// Do nothing if no histograms are selected
|
||||
if ( ! fHnManager->IsAscii() ) return true;
|
||||
|
||||
// Write h2 histograms
|
||||
for ( G4int i=0; i<G4int(fTVector.size()); ++i ) {
|
||||
auto id = i + fHnManager->GetFirstId();
|
||||
auto info = fHnManager->GetHnInformation(id,"WriteOnAscii");
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( ! info->GetAscii() ) continue;
|
||||
auto h2 = fTVector[i];
|
||||
|
||||
Message(kVL3, "write on ascii", "h2d", info->GetName());
|
||||
|
||||
output << "\n 2D histogram " << id << ": " << h2->title()
|
||||
<< "\n \n \t \t X \t\t Y \t\t Bin Height" << G4endl;
|
||||
|
||||
for (G4int j=0; j< G4int(h2->axis_x().bins()); ++j) {
|
||||
for (G4int k=0; k< G4int(h2->axis_y().bins()); ++k) {
|
||||
output << " " << j << "\t" << k << "\t"
|
||||
<< h2->axis_x().bin_center(j) << "\t"
|
||||
<< h2->axis_y().bin_center(k) << "\t"
|
||||
<< h2->bin_height(j, k) << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output.good();
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H2ToolsManager::AddH2(const G4String& name, tools::histo::h2d* h2d)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("add", "H2", name);
|
||||
#endif
|
||||
Message(kVL4, "add", "H2", name);
|
||||
|
||||
// Add annotation
|
||||
AddH2Annotation(h2d, "none", "none", "none", "none");
|
||||
AddH2Annotation(h2d, "none", "none", "none", "none");
|
||||
// Add information
|
||||
AddH2Information(name, "none", "none", "none", "none",
|
||||
AddH2Information(name, "none", "none", "none", "none",
|
||||
G4BinScheme::kLinear, G4BinScheme::kLinear);
|
||||
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h2d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("add", "H2", name);
|
||||
#endif
|
||||
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h2d, name);
|
||||
|
||||
Message(kVL2, "add", "H2", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4H2ToolsManager::AddH2Vector(
|
||||
const std::vector<tools::histo::h2d*>& h2Vector)
|
||||
{
|
||||
AddTVector(h2Vector);
|
||||
}
|
||||
}
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h2d* G4H2ToolsManager::GetH2(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return GetTInFunction(id, "GetH2", warn, onlyIfActive);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,7 @@
|
||||
#include <fstream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
// static definitions
|
||||
const G4int G4H3ToolsManager::kDimension = 3;
|
||||
using std::to_string;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4H3ToolsManager::G4H3ToolsManager(const G4AnalysisManagerState& state)
|
||||
@@ -46,10 +44,6 @@ G4H3ToolsManager::G4H3ToolsManager(const G4AnalysisManagerState& state)
|
||||
G4THnManager<tools::histo::h3d>(state, "H3")
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4H3ToolsManager::~G4H3ToolsManager()
|
||||
{}
|
||||
|
||||
//
|
||||
// Utility functions
|
||||
//
|
||||
@@ -58,9 +52,9 @@ namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void UpdateH3Information(G4HnInformation* hnInformation,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
@@ -71,28 +65,28 @@ void UpdateH3Information(G4HnInformation* hnInformation,
|
||||
hnInformation->SetDimension(kX, xunitName, xfcnName, xbinScheme);
|
||||
hnInformation->SetDimension(kY, yunitName, yfcnName, ybinScheme);
|
||||
hnInformation->SetDimension(kZ, zunitName, zfcnName, zbinScheme);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void AddH3Annotation(tools::histo::h3d* h3d,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName)
|
||||
{
|
||||
{
|
||||
G4String xaxisTitle;
|
||||
G4String yaxisTitle;
|
||||
G4String zaxisTitle;
|
||||
UpdateTitle(xaxisTitle, xunitName, xfcnName);
|
||||
UpdateTitle(yaxisTitle, yunitName, yfcnName);
|
||||
UpdateTitle(zaxisTitle, zunitName, zfcnName);
|
||||
UpdateTitle(xaxisTitle, xunitName, xfcnName);
|
||||
UpdateTitle(yaxisTitle, yunitName, yfcnName);
|
||||
UpdateTitle(zaxisTitle, zunitName, zfcnName);
|
||||
h3d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
|
||||
h3d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
|
||||
h3d->add_annotation(tools::histo::key_axis_z_title(), zaxisTitle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h3d* CreateToolsH3(
|
||||
const G4String& title,
|
||||
@@ -102,12 +96,13 @@ tools::histo::h3d* CreateToolsH3(
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName,
|
||||
const G4String& zbinSchemeName)
|
||||
const G4String& zbinSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
@@ -118,23 +113,20 @@ tools::histo::h3d* CreateToolsH3(
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
auto zbinScheme = GetBinScheme(zbinSchemeName);
|
||||
|
||||
|
||||
if ( xbinScheme != G4BinScheme::kLog && ybinScheme != G4BinScheme::kLog && zbinScheme != G4BinScheme::kLog) {
|
||||
if ( xbinScheme == G4BinScheme::kUser || ybinScheme == G4BinScheme::kUser || zbinScheme == G4BinScheme::kUser) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4H3ToolsManager::CreateH3",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
return new tools::histo::h3d(title,
|
||||
nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "CreateToolsH3");
|
||||
}
|
||||
return new tools::histo::h3d(title,
|
||||
nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
nybins, yfcn(ymin/yunit), yfcn(ymax/yunit),
|
||||
nzbins, zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
// h3 objects are deleted in destructor and reset when
|
||||
// h3 objects are deleted in destructor and reset when
|
||||
// closing a file.
|
||||
}
|
||||
else {
|
||||
@@ -145,9 +137,9 @@ tools::histo::h3d* CreateToolsH3(
|
||||
ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
|
||||
std::vector<G4double> zedges;
|
||||
ComputeEdges(nzbins, zmin, zmax, zunit, zfcn, zbinScheme, zedges);
|
||||
return new tools::histo::h3d(title, xedges, yedges, zedges);
|
||||
return new tools::histo::h3d(title, xedges, yedges, zedges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h3d* CreateToolsH3(
|
||||
@@ -161,7 +153,7 @@ tools::histo::h3d* CreateToolsH3(
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName)
|
||||
{
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
auto zunit = GetUnitValue(zunitName);
|
||||
@@ -169,18 +161,18 @@ tools::histo::h3d* CreateToolsH3(
|
||||
auto yfcn = GetFunction(yfcnName);
|
||||
auto zfcn = GetFunction(zfcnName);
|
||||
|
||||
// Apply function
|
||||
// Apply function
|
||||
std::vector<G4double> xnewEdges;
|
||||
ComputeEdges(xedges, xunit, xfcn, xnewEdges);
|
||||
std::vector<G4double> ynewEdges;
|
||||
ComputeEdges(yedges, yunit, yfcn, ynewEdges);
|
||||
std::vector<G4double> znewEdges;
|
||||
ComputeEdges(zedges, zunit, zfcn, znewEdges);
|
||||
|
||||
return new tools::histo::h3d(title, xnewEdges, ynewEdges, znewEdges);
|
||||
// h3 objects are deleted in destructor and reset when
|
||||
|
||||
return new tools::histo::h3d(title, xnewEdges, ynewEdges, znewEdges);
|
||||
// h3 objects are deleted in destructor and reset when
|
||||
// closing a file.
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsH3(tools::histo::h3d* h3d,
|
||||
@@ -190,12 +182,13 @@ void ConfigureToolsH3(tools::histo::h3d* h3d,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName,
|
||||
const G4String& zbinSchemeName)
|
||||
const G4String& zbinSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
@@ -206,19 +199,16 @@ void ConfigureToolsH3(tools::histo::h3d* h3d,
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
auto zbinScheme = GetBinScheme(zbinSchemeName);
|
||||
|
||||
|
||||
if ( xbinScheme != G4BinScheme::kLog && ybinScheme != G4BinScheme::kLog && zbinScheme != G4BinScheme::kLog) {
|
||||
if ( xbinScheme == G4BinScheme::kUser || ybinScheme == G4BinScheme::kUser || zbinScheme == G4BinScheme::kUser) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4H3ToolsManager::CreateH3",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
h3d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "ConfigureToolsH3");
|
||||
}
|
||||
h3d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
nybins, yfcn(ymin/yunit), yfcn(ymax/yunit),
|
||||
nzbins, zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
}
|
||||
@@ -232,7 +222,7 @@ void ConfigureToolsH3(tools::histo::h3d* h3d,
|
||||
ComputeEdges(nzbins, zmin, zmax, zunit, zfcn, zbinScheme, zedges);
|
||||
h3d->configure(xedges, yedges, zedges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsH3(tools::histo::h3d* h3d,
|
||||
@@ -272,10 +262,10 @@ void ConfigureToolsH3(tools::histo::h3d* h3d,
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4H3ToolsManager::AddH3Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
void G4H3ToolsManager::AddH3Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
@@ -283,13 +273,13 @@ void G4H3ToolsManager::AddH3Information(const G4String& name,
|
||||
G4BinScheme ybinScheme,
|
||||
G4BinScheme zbinScheme) const
|
||||
{
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, 3);
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, fkDimension);
|
||||
hnInformation->AddDimension(xunitName, xfcnName, xbinScheme);
|
||||
hnInformation->AddDimension(yunitName, yfcnName, ybinScheme);
|
||||
hnInformation->AddDimension(zunitName, zfcnName, zbinScheme);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -298,48 +288,43 @@ G4int G4H3ToolsManager::CreateH3(const G4String& name, const G4String& title,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
G4int nzbins, G4double zmin, G4double zmax,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName,
|
||||
const G4String& zbinSchemeName)
|
||||
|
||||
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "H3", name);
|
||||
#endif
|
||||
Message(kVL4, "create", "H3", name);
|
||||
|
||||
tools::histo::h3d* h3d
|
||||
= CreateToolsH3(title,
|
||||
= CreateToolsH3(title,
|
||||
nxbins, xmin, xmax, nybins, ymin, ymax, nzbins, zmin, zmax,
|
||||
xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName,
|
||||
xbinSchemeName, ybinSchemeName, zbinSchemeName);
|
||||
|
||||
xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName,
|
||||
xbinSchemeName, ybinSchemeName, zbinSchemeName, fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddH3Annotation(h3d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Save H3 information
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
auto zbinScheme = GetBinScheme(zbinSchemeName);
|
||||
AddH3Information(
|
||||
name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
xbinScheme, ybinScheme, zbinScheme);
|
||||
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h3d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "H3", name);
|
||||
#endif
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h3d, name);
|
||||
|
||||
Message(kVL2, "create", "H3", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H3ToolsManager::CreateH3(const G4String& name, const G4String& title,
|
||||
@@ -350,68 +335,61 @@ G4int G4H3ToolsManager::CreateH3(const G4String& name, const G4String& title,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& zfcnName)
|
||||
|
||||
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "H3", name);
|
||||
#endif
|
||||
Message(kVL4, "create", "H3", name);
|
||||
|
||||
tools::histo::h3d* h3d
|
||||
= CreateToolsH3(title, xedges, yedges, zedges,
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
|
||||
|
||||
= CreateToolsH3(title, xedges, yedges, zedges,
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Add annotation
|
||||
AddH3Annotation(h3d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
AddH3Annotation(h3d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Save H3 information
|
||||
AddH3Information(
|
||||
name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
G4BinScheme::kUser, G4BinScheme::kUser, G4BinScheme::kUser);
|
||||
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h3d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "H3", name);
|
||||
#endif
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h3d, name);
|
||||
|
||||
Message(kVL2, "create", "H3", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::SetH3(G4int id,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
G4int nzbins, G4double zmin, G4double zmax,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName,
|
||||
const G4String& zbinSchemeName)
|
||||
{
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "SetH3", false, false);
|
||||
if ( ! h3d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id, "SetH3");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "H3", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "H3", info->GetName());
|
||||
|
||||
// Configure tools h3
|
||||
ConfigureToolsH3(
|
||||
h3d, nxbins, xmin, xmax, nybins, ymin, ymax, nzbins, zmin, zmax,
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
xbinSchemeName, ybinSchemeName, zbinSchemeName);
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
xbinSchemeName, ybinSchemeName, zbinSchemeName, fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddH3Annotation(h3d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
AddH3Annotation(h3d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Update information
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
@@ -421,11 +399,11 @@ G4bool G4H3ToolsManager::SetH3(G4int id,
|
||||
xbinScheme, ybinScheme, zbinScheme);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::SetH3(G4int id,
|
||||
const std::vector<G4double>& xedges,
|
||||
@@ -435,35 +413,33 @@ G4bool G4H3ToolsManager::SetH3(G4int id,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& zfcnName)
|
||||
{
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "SetH3", false, false);
|
||||
if ( ! h3d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id, "SetH3");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "H3", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "H3", info->GetName());
|
||||
|
||||
// Configure tools h3
|
||||
ConfigureToolsH3(h3d, xedges, yedges, zedges,
|
||||
ConfigureToolsH3(h3d, xedges, yedges, zedges,
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Add annotation
|
||||
AddH3Annotation(h3d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
AddH3Annotation(h3d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Update information
|
||||
UpdateH3Information(
|
||||
info, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
G4BinScheme::kUser, G4BinScheme::kUser, G4BinScheme::kUser);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::ScaleH3(G4int id, G4double factor)
|
||||
{
|
||||
@@ -471,10 +447,10 @@ G4bool G4H3ToolsManager::ScaleH3(G4int id, G4double factor)
|
||||
if ( ! h3d ) return false;
|
||||
|
||||
return h3d->scale(factor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::FillH3(G4int id,
|
||||
G4bool G4H3ToolsManager::FillH3(G4int id,
|
||||
G4double xvalue, G4double yvalue, G4double zvalue,
|
||||
G4double weight)
|
||||
{
|
||||
@@ -482,33 +458,32 @@ G4bool G4H3ToolsManager::FillH3(G4int id,
|
||||
if ( ! h3d ) return false;
|
||||
|
||||
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
G4HnDimensionInformation* xInfo
|
||||
G4HnDimensionInformation* xInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kX, "FillH3");
|
||||
G4HnDimensionInformation* yInfo
|
||||
G4HnDimensionInformation* yInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kY, "FillH3");
|
||||
G4HnDimensionInformation* zInfo
|
||||
G4HnDimensionInformation* zInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kZ, "FillH3");
|
||||
|
||||
h3d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
|
||||
yInfo->fFcn(yvalue/yInfo->fUnit),
|
||||
h3d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
|
||||
yInfo->fFcn(yvalue/yInfo->fUnit),
|
||||
zInfo->fFcn(zvalue/zInfo->fUnit), weight);
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " id " << id
|
||||
<< " xvalue " << xvalue
|
||||
<< " xfcn(xvalue/xunit) " << xInfo->fFcn(xvalue/xInfo->fUnit)
|
||||
<< " yvalue " << yvalue
|
||||
<< " yfcn(yvalue/yunit) " << yInfo->fFcn(yvalue/yInfo->fUnit)
|
||||
<< " zvalue " << zvalue
|
||||
<< " zfcn(zvalue/zunit) " << zInfo->fFcn(zvalue/zInfo->fUnit)
|
||||
<< " weight " << weight;
|
||||
fState.GetVerboseL4()->Message("fill", "H3", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( IsVerbose(kVL4) ) {
|
||||
Message(kVL4, "fill", "H3",
|
||||
" id " + to_string(id) +
|
||||
" xvalue " + to_string(xvalue) +
|
||||
" xfcn(xvalue/xunit) " + to_string(xInfo->fFcn(xvalue/xInfo->fUnit)) +
|
||||
" yvalue " + to_string(yvalue) +
|
||||
" yfcn(yvalue/yunit) " + to_string(yInfo->fFcn(yvalue/yInfo->fUnit)) +
|
||||
" zvalue " + to_string(zvalue) +
|
||||
" zfcn(zvalue/zunit) " + to_string(zInfo->fFcn(zvalue/zInfo->fUnit)) +
|
||||
" weight " + to_string(weight));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -516,16 +491,16 @@ G4bool G4H3ToolsManager::FillH3(G4int id,
|
||||
G4int G4H3ToolsManager::GetH3Id(const G4String& name, G4bool warn) const
|
||||
{
|
||||
return GetTId(name, warn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H3ToolsManager::GetH3Nxbins(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3NXbins");
|
||||
if ( ! h3d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*h3d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3Xmin(G4int id) const
|
||||
@@ -534,36 +509,36 @@ G4double G4H3ToolsManager::GetH3Xmin(G4int id) const
|
||||
|
||||
auto h3d = GetTInFunction(id, "GetH3Xmin");
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*h3d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3Xmax(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3Xmax");
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*h3d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3XWidth(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3XWidth", true, false);
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*h3d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H3ToolsManager::GetH3Nybins(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3NYbins");
|
||||
if ( ! h3d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*h3d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3Ymin(G4int id) const
|
||||
@@ -572,36 +547,36 @@ G4double G4H3ToolsManager::GetH3Ymin(G4int id) const
|
||||
|
||||
auto h3d = GetTInFunction(id, "GetH3Ymin");
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*h3d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3Ymax(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3Ymax");
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*h3d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3YWidth(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3YWidth", true, false);
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*h3d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H3ToolsManager::GetH3Nzbins(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3NZbins");
|
||||
if ( ! h3d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*h3d, kZ);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3Zmin(G4int id) const
|
||||
@@ -610,149 +585,170 @@ G4double G4H3ToolsManager::GetH3Zmin(G4int id) const
|
||||
|
||||
auto h3d = GetTInFunction(id, "GetH3Zmin");
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*h3d, kZ);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3Zmax(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3Zmax");
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*h3d, kZ);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4H3ToolsManager::GetH3ZWidth(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3ZWidth", true, false);
|
||||
if ( ! h3d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*h3d, kZ, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::SetH3Title(G4int id, const G4String& title)
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "SetH3Title");
|
||||
if ( ! h3d ) return false;
|
||||
|
||||
|
||||
return SetTitle(*h3d, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::SetH3XAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "SetH3XAxisTitle");
|
||||
if ( ! h3d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*h3d, kX, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::SetH3YAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "SetH3YAxisTitle");
|
||||
if ( ! h3d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*h3d, kY, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::SetH3ZAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "SetH3ZAxisTitle");
|
||||
if ( ! h3d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*h3d, kZ, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H3ToolsManager::GetH3Title(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3Title");
|
||||
if ( ! h3d ) return "";
|
||||
|
||||
|
||||
return GetTitle(*h3d);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H3ToolsManager::GetH3XAxisTitle(G4int id) const
|
||||
G4String G4H3ToolsManager::GetH3XAxisTitle(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3XAxisTitle");
|
||||
if ( ! h3d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*h3d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H3ToolsManager::GetH3YAxisTitle(G4int id) const
|
||||
G4String G4H3ToolsManager::GetH3YAxisTitle(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3YAxisTitle");
|
||||
if ( ! h3d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*h3d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4H3ToolsManager::GetH3ZAxisTitle(G4int id) const
|
||||
G4String G4H3ToolsManager::GetH3ZAxisTitle(G4int id) const
|
||||
{
|
||||
auto h3d = GetTInFunction(id, "GetH3ZAxisTitle");
|
||||
if ( ! h3d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*h3d, kZ, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4H3ToolsManager::WriteOnAscii(std::ofstream& /*output*/)
|
||||
G4bool G4H3ToolsManager::WriteOnAscii(std::ofstream& output)
|
||||
{
|
||||
// Write selected objects on ASCII file
|
||||
// According to the implementation by Michel Maire, originally in
|
||||
// extended examples.
|
||||
// Not yet available for H3
|
||||
|
||||
return ! fHnManager->IsAscii();
|
||||
}
|
||||
// Do nothing if no histograms are selected
|
||||
if ( ! fHnManager->IsAscii() ) return true;
|
||||
|
||||
// Write h3 histograms
|
||||
for ( G4int i=0; i<G4int(fTVector.size()); ++i ) {
|
||||
auto id = i + fHnManager->GetFirstId();
|
||||
auto info = fHnManager->GetHnInformation(id,"WriteOnAscii");
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( ! info->GetAscii() ) continue;
|
||||
auto h3 = fTVector[i];
|
||||
|
||||
Message(kVL3, "write on ascii", "h3d", info->GetName());
|
||||
|
||||
output << "\n 3D histogram " << id << ": " << h3->title()
|
||||
<< "\n \n \t \t \t X \t\t Y \t\t Z \t\t Bin Height" << G4endl;
|
||||
|
||||
for (G4int j=0; j< G4int(h3->axis_x().bins()); ++j) {
|
||||
for (G4int k=0; k< G4int(h3->axis_y().bins()); ++k) {
|
||||
for (G4int l=0; l< G4int(h3->axis_y().bins()); ++l) {
|
||||
output << " " << j << "\t" << k << "\t" << l << "\t"
|
||||
<< h3->axis_x().bin_center(j) << "\t"
|
||||
<< h3->axis_y().bin_center(k) << "\t"
|
||||
<< h3->axis_y().bin_center(l) << "\t"
|
||||
<< h3->bin_height(j, k, l) << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output.good();
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4H3ToolsManager::AddH3(const G4String& name, tools::histo::h3d* h3d)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("add", "H3", name);
|
||||
#endif
|
||||
Message(kVL4, "add", "H3", name);
|
||||
|
||||
// Add annotation
|
||||
AddH3Annotation(h3d, "none", "none", "none", "none", "none", "none");
|
||||
AddH3Annotation(h3d, "none", "none", "none", "none", "none", "none");
|
||||
// Add information
|
||||
AddH3Information(name, "none", "none", "none", "none", "none", "none",
|
||||
AddH3Information(name, "none", "none", "none", "none", "none", "none",
|
||||
G4BinScheme::kLinear, G4BinScheme::kLinear, G4BinScheme::kLinear);
|
||||
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h3d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("add", "H3", name);
|
||||
#endif
|
||||
|
||||
// Register histogram
|
||||
G4int id = RegisterT(h3d, name);
|
||||
|
||||
Message(kVL2, "add", "H3", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4H3ToolsManager::AddH3Vector(
|
||||
const std::vector<tools::histo::h3d*>& h3Vector)
|
||||
{
|
||||
AddTVector(h3Vector);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::h3d* G4H3ToolsManager::GetH3(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return GetTInFunction(id, "GetH3", warn, onlyIfActive);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,7 @@
|
||||
#include <fstream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
// static definitions
|
||||
const G4int G4P1ToolsManager::kDimension = 1;
|
||||
using std::to_string;
|
||||
|
||||
//
|
||||
// Constructors, destructor
|
||||
@@ -50,10 +48,6 @@ G4P1ToolsManager::G4P1ToolsManager(const G4AnalysisManagerState& state)
|
||||
G4THnManager<tools::histo::p1d>(state, "P1")
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4P1ToolsManager::~G4P1ToolsManager()
|
||||
{}
|
||||
|
||||
//
|
||||
// Utility functions
|
||||
//
|
||||
@@ -62,64 +56,62 @@ namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void UpdateP1Information(G4HnInformation* hnInformation,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
G4BinScheme xbinScheme)
|
||||
{
|
||||
hnInformation->SetDimension(kX, xunitName, xfcnName, xbinScheme);
|
||||
hnInformation->SetDimension(kY, yunitName, yfcnName, G4BinScheme::kLinear);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void AddP1Annotation(tools::histo::p1d* p1d,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName)
|
||||
{
|
||||
{
|
||||
G4String xaxisTitle;
|
||||
G4String yaxisTitle;
|
||||
UpdateTitle(xaxisTitle, xunitName, xfcnName);
|
||||
UpdateTitle(yaxisTitle, yunitName, yfcnName);
|
||||
UpdateTitle(xaxisTitle, xunitName, xfcnName);
|
||||
UpdateTitle(yaxisTitle, yunitName, yfcnName);
|
||||
p1d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
|
||||
p1d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::p1d* CreateToolsP1(const G4String& title,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
G4double ymin, G4double ymax,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName)
|
||||
const G4String& xbinSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
auto xfcn = GetFunction(xfcnName);
|
||||
auto yfcn = GetFunction(yfcnName);
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
|
||||
|
||||
if ( xbinScheme != G4BinScheme::kLog ) {
|
||||
if ( xbinScheme == G4BinScheme::kUser ) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4P1ToolsManager::CreateP1",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
if ( ymin == 0. && ymax == 0.) {
|
||||
return new tools::histo::p1d(title,
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "CreateToolsP1");
|
||||
}
|
||||
if ( ymin == 0. && ymax == 0.) {
|
||||
return new tools::histo::p1d(title,
|
||||
nbins, xfcn(xmin/xunit), xfcn(xmax/xunit));
|
||||
} else {
|
||||
return new tools::histo::p1d(title,
|
||||
nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
} else {
|
||||
return new tools::histo::p1d(title,
|
||||
nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
}
|
||||
}
|
||||
@@ -127,13 +119,13 @@ tools::histo::p1d* CreateToolsP1(const G4String& title,
|
||||
// Compute edges
|
||||
std::vector<G4double> edges;
|
||||
ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, edges);
|
||||
if ( ymin == 0. && ymax == 0.) {
|
||||
if ( ymin == 0. && ymax == 0.) {
|
||||
return new tools::histo::p1d(title, edges);
|
||||
} else {
|
||||
return new tools::histo::p1d(title, edges, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
return new tools::histo::p1d(title, edges, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::p1d* CreateToolsP1(const G4String& title,
|
||||
@@ -149,22 +141,23 @@ tools::histo::p1d* CreateToolsP1(const G4String& title,
|
||||
auto xfcn = GetFunction(xfcnName);
|
||||
auto yfcn = GetFunction(yfcnName);
|
||||
|
||||
// Apply function
|
||||
// Apply function
|
||||
std::vector<G4double> newEdges;
|
||||
ComputeEdges(edges, xunit, xfcn, newEdges);
|
||||
|
||||
return new tools::histo::p1d(title, newEdges, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
}
|
||||
|
||||
return new tools::histo::p1d(title, newEdges, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsP1(tools::histo::p1d* p1d,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
G4double ymin, G4double ymax,
|
||||
G4int nbins, G4double xmin, G4double xmax,
|
||||
G4double ymin, G4double ymax,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName)
|
||||
const G4String& xbinSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
@@ -176,17 +169,14 @@ void ConfigureToolsP1(tools::histo::p1d* p1d,
|
||||
if ( xbinScheme == G4BinScheme::kUser ) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4P1ToolsManager::SetP1",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "ConfigureToolsP1");
|
||||
}
|
||||
if ( ymin == 0. && ymax == 0. ) {
|
||||
p1d->configure(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit));
|
||||
} else {
|
||||
p1d->configure(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
} else {
|
||||
p1d->configure(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
}
|
||||
}
|
||||
@@ -196,16 +186,16 @@ void ConfigureToolsP1(tools::histo::p1d* p1d,
|
||||
ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, edges);
|
||||
if ( ymin == 0. && ymax == 0. ) {
|
||||
p1d->configure(edges);
|
||||
} else {
|
||||
} else {
|
||||
p1d->configure(edges, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsP1(tools::histo::p1d* p1d,
|
||||
const std::vector<G4double>& edges,
|
||||
G4double ymin, G4double ymax,
|
||||
G4double ymin, G4double ymax,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
@@ -228,24 +218,24 @@ void ConfigureToolsP1(tools::histo::p1d* p1d,
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4P1ToolsManager::AddP1Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
void G4P1ToolsManager::AddP1Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
G4BinScheme xbinScheme) const
|
||||
{
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, 2);
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, fkDimension);
|
||||
hnInformation->AddDimension(xunitName, xfcnName, xbinScheme);
|
||||
hnInformation->AddDimension(yunitName, yfcnName, G4BinScheme::kLinear);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -257,32 +247,28 @@ G4int G4P1ToolsManager::CreateP1(const G4String& name, const G4String& title,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "P1", name);
|
||||
#endif
|
||||
Message(kVL4, "create", "P1", name);
|
||||
|
||||
tools::histo::p1d* p1d
|
||||
= CreateToolsP1(title, nbins, xmin, xmax, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName,
|
||||
xbinSchemeName);
|
||||
|
||||
= CreateToolsP1(title, nbins, xmin, xmax, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName,
|
||||
xbinSchemeName, fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddP1Annotation(p1d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
AddP1Annotation(p1d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Save P1 information
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
AddP1Information(
|
||||
name, xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
|
||||
|
||||
// Register profile
|
||||
G4int id = RegisterT(p1d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "P1", name);
|
||||
#endif
|
||||
|
||||
// Register profile
|
||||
G4int id = RegisterT(p1d, name);
|
||||
|
||||
Message(kVL2, "create", "P1", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4P1ToolsManager::CreateP1(const G4String& name, const G4String& title,
|
||||
@@ -291,30 +277,26 @@ G4int G4P1ToolsManager::CreateP1(const G4String& name, const G4String& title,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "P1", name);
|
||||
#endif
|
||||
tools::histo::p1d* p1d
|
||||
= CreateToolsP1(title, edges, ymin, ymax,
|
||||
Message(kVL4, "create", "P1", name);
|
||||
|
||||
tools::histo::p1d* p1d
|
||||
= CreateToolsP1(title, edges, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
|
||||
// Add annotation
|
||||
AddP1Annotation(p1d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
AddP1Annotation(p1d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Save P1 information
|
||||
AddP1Information(
|
||||
name, xunitName, yunitName, xfcnName, yfcnName, G4BinScheme::kUser);
|
||||
|
||||
// Register profile
|
||||
G4int id = RegisterT(p1d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "P1", name);
|
||||
#endif
|
||||
|
||||
// Register profile
|
||||
G4int id = RegisterT(p1d, name);
|
||||
|
||||
Message(kVL2, "create", "P1", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P1ToolsManager::SetP1(G4int id,
|
||||
@@ -323,32 +305,30 @@ G4bool G4P1ToolsManager::SetP1(G4int id,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName)
|
||||
{
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "SetP1", false, false);
|
||||
if ( ! p1d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id,"SetP1");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "P1", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "P1", info->GetName());
|
||||
|
||||
// Configure tools p1
|
||||
ConfigureToolsP1(
|
||||
p1d, nbins, xmin, xmax, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName, xbinSchemeName);
|
||||
p1d, nbins, xmin, xmax, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName, xbinSchemeName, fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddP1Annotation(p1d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
AddP1Annotation(p1d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Update information
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
UpdateP1Information(
|
||||
info, xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -363,29 +343,27 @@ G4bool G4P1ToolsManager::SetP1(G4int id,
|
||||
if ( ! p1d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id,"SetP1");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "P1", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "P1", info->GetName());
|
||||
|
||||
// Configure tools p1
|
||||
ConfigureToolsP1(p1d, edges, ymin, ymax,
|
||||
ConfigureToolsP1(p1d, edges, ymin, ymax,
|
||||
xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Add annotation
|
||||
AddP1Annotation(p1d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Update information
|
||||
// Add annotation
|
||||
AddP1Annotation(p1d, xunitName, yunitName, xfcnName, yfcnName);
|
||||
|
||||
// Update information
|
||||
UpdateP1Information(
|
||||
info, xunitName, yunitName, xfcnName, yfcnName, G4BinScheme::kUser);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P1ToolsManager::ScaleP1(G4int id, G4double factor)
|
||||
{
|
||||
@@ -393,40 +371,38 @@ G4bool G4P1ToolsManager::ScaleP1(G4int id, G4double factor)
|
||||
if ( ! p1d ) return false;
|
||||
|
||||
return p1d->scale(factor);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P1ToolsManager::FillP1(G4int id, G4double xvalue, G4double yvalue,
|
||||
G4bool G4P1ToolsManager::FillP1(G4int id, G4double xvalue, G4double yvalue,
|
||||
G4double weight)
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "FillP1", true, false);
|
||||
if ( ! p1d ) return false;
|
||||
|
||||
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
|
||||
//G4cout << "Skipping FillP1 for " << id << G4endl;
|
||||
return false;
|
||||
}
|
||||
//G4cout << "Skipping FillP1 for " << id << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto xInfo
|
||||
auto xInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kX, "FillP1");
|
||||
auto yInfo
|
||||
auto yInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kY, "FillP1");
|
||||
|
||||
p1d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
|
||||
p1d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
|
||||
yInfo->fFcn(yvalue/yInfo->fUnit), weight);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " id " << id
|
||||
<< " xvalue " << xvalue
|
||||
<< " xfcn(xvalue/xunit) " << xInfo->fFcn(xvalue/xInfo->fUnit)
|
||||
<< " yvalue " << yvalue
|
||||
<< " yfcn(yvalue/yunit) " << yInfo->fFcn(yvalue/yInfo->fUnit)
|
||||
<< " weight " << weight;
|
||||
fState.GetVerboseL4()->Message("fill", "P1", description);
|
||||
}
|
||||
#endif
|
||||
if ( IsVerbose(kVL4) ) {
|
||||
Message(kVL4, "fill", "P1",
|
||||
" id " + to_string(id) +
|
||||
" xvalue " + to_string(xvalue) +
|
||||
" xfcn(xvalue/xunit) " + to_string(xInfo->fFcn(xvalue/xInfo->fUnit)) +
|
||||
" yvalue " + to_string(yvalue) +
|
||||
" yfcn(yvalue/yunit) " + to_string(yInfo->fFcn(yvalue/yInfo->fUnit)) +
|
||||
" weight " + to_string(weight));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -434,16 +410,16 @@ G4bool G4P1ToolsManager::FillP1(G4int id, G4double xvalue, G4double yvalue,
|
||||
G4int G4P1ToolsManager::GetP1Id(const G4String& name, G4bool warn) const
|
||||
{
|
||||
return GetTId(name, warn);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4P1ToolsManager::GetP1Nbins(G4int id) const
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "GetP1Nbins");
|
||||
if ( ! p1d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*p1d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P1ToolsManager::GetP1Xmin(G4int id) const
|
||||
@@ -452,27 +428,27 @@ G4double G4P1ToolsManager::GetP1Xmin(G4int id) const
|
||||
|
||||
auto p1d = GetTInFunction(id, "GetP1Xmin");
|
||||
if ( ! p1d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*p1d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P1ToolsManager::GetP1Xmax(G4int id) const
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "GetP1Xmax");
|
||||
if ( ! p1d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*p1d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P1ToolsManager::GetP1XWidth(G4int id) const
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "GetP1XWidth", true, false);
|
||||
if ( ! p1d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*p1d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P1ToolsManager::GetP1Ymin(G4int id) const
|
||||
@@ -481,111 +457,140 @@ G4double G4P1ToolsManager::GetP1Ymin(G4int id) const
|
||||
|
||||
auto p1d = GetTInFunction(id, "GetP1Ymin");
|
||||
if ( ! p1d ) return 0.;
|
||||
|
||||
|
||||
return p1d->min_v();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P1ToolsManager::GetP1Ymax(G4int id) const
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "GetP1Ymax");
|
||||
if ( ! p1d ) return 0.;
|
||||
|
||||
|
||||
return p1d->max_v();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P1ToolsManager::SetP1Title(G4int id, const G4String& title)
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "SetP1Title");
|
||||
if ( ! p1d ) return false;
|
||||
|
||||
|
||||
return SetTitle(*p1d, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P1ToolsManager::SetP1XAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "SetP1XAxisTitle");
|
||||
if ( ! p1d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*p1d, kX, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P1ToolsManager::SetP1YAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "SetP1YAxisTitle");
|
||||
if ( ! p1d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*p1d, kY, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4P1ToolsManager::GetP1Title(G4int id) const
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "GetP1Title");
|
||||
if ( ! p1d ) return "";
|
||||
|
||||
|
||||
return GetTitle(*p1d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4P1ToolsManager::GetP1XAxisTitle(G4int id) const
|
||||
G4String G4P1ToolsManager::GetP1XAxisTitle(G4int id) const
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "GetP1XAxisTitle");
|
||||
if ( ! p1d ) return "";
|
||||
|
||||
return GetAxisTitle(*p1d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4P1ToolsManager::GetP1YAxisTitle(G4int id) const
|
||||
G4String G4P1ToolsManager::GetP1YAxisTitle(G4int id) const
|
||||
{
|
||||
auto p1d = GetTInFunction(id, "GetP1YAxisTitle");
|
||||
if ( ! p1d ) return "";
|
||||
|
||||
return GetAxisTitle(*p1d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
|
||||
//
|
||||
return GetAxisTitle(*p1d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P1ToolsManager::WriteOnAscii(std::ofstream& output)
|
||||
{
|
||||
// Write selected objects on ASCII file
|
||||
|
||||
// Do nothing if no histograms are selected
|
||||
if ( ! fHnManager->IsAscii() ) return true;
|
||||
|
||||
// Write p1 histograms
|
||||
for ( G4int i=0; i<G4int(fTVector.size()); ++i ) {
|
||||
auto id = i + fHnManager->GetFirstId();
|
||||
auto info = fHnManager->GetHnInformation(id,"WriteOnAscii");
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( ! info->GetAscii() ) continue;
|
||||
auto p1 = fTVector[i];
|
||||
|
||||
Message(kVL3, "write on ascii", "p1d", info->GetName());
|
||||
|
||||
output << "\n 1D profile " << id << ": " << p1->title()
|
||||
<< "\n \n \t X \t\t MeanY" << G4endl;
|
||||
|
||||
for (G4int j=0; j< G4int(p1->axis().bins()); ++j) {
|
||||
auto sw = p1->bin_Sw(j);
|
||||
auto svw = p1->bin_Svw(j);
|
||||
auto mean = ( sw != 0. ) ? (svw / sw) : 0.;
|
||||
output << " " << j << "\t"
|
||||
<< p1->axis().bin_center(j) << "\t"
|
||||
<< mean << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
return output.good();
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4P1ToolsManager::AddP1(const G4String& name, tools::histo::p1d* p1d)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("add", "P1", name);
|
||||
#endif
|
||||
|
||||
Message(kVL4, "add", "P1", name);
|
||||
|
||||
// Add annotation
|
||||
AddP1Annotation(p1d, "none", "none", "none", "none");
|
||||
AddP1Annotation(p1d, "none", "none", "none", "none");
|
||||
// Add information
|
||||
AddP1Information(name, "none", "none", "none", "none", G4BinScheme::kLinear);
|
||||
|
||||
// Register profile
|
||||
auto id = RegisterT(p1d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("add", "P1", name);
|
||||
#endif
|
||||
|
||||
// Register profile
|
||||
auto id = RegisterT(p1d, name);
|
||||
|
||||
Message(kVL2, "add", "P1", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4P1ToolsManager::AddP1Vector(
|
||||
const std::vector<tools::histo::p1d*>& p1Vector)
|
||||
{
|
||||
AddTVector(p1Vector);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::p1d* G4P1ToolsManager::GetP1(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return GetTInFunction(id, "GetP1", warn, onlyIfActive);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,7 @@
|
||||
#include <fstream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
// static definitions
|
||||
const G4int G4P2ToolsManager::kDimension = 2;
|
||||
using std::to_string;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4P2ToolsManager::G4P2ToolsManager(const G4AnalysisManagerState& state)
|
||||
@@ -46,10 +44,6 @@ G4P2ToolsManager::G4P2ToolsManager(const G4AnalysisManagerState& state)
|
||||
G4THnManager<tools::histo::p2d>(state, "P2")
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4P2ToolsManager::~G4P2ToolsManager()
|
||||
{}
|
||||
|
||||
//
|
||||
// Utility functions
|
||||
//
|
||||
@@ -58,9 +52,9 @@ namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void UpdateP2Information(G4HnInformation* hnInformation,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
@@ -70,28 +64,28 @@ void UpdateP2Information(G4HnInformation* hnInformation,
|
||||
hnInformation->SetDimension(kX, xunitName, xfcnName, xbinScheme);
|
||||
hnInformation->SetDimension(kY, yunitName, yfcnName, ybinScheme);
|
||||
hnInformation->SetDimension(kZ, zunitName, zfcnName, G4BinScheme::kLinear);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void AddP2Annotation(tools::histo::p2d* p2d,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName)
|
||||
{
|
||||
{
|
||||
G4String xaxisTitle;
|
||||
G4String yaxisTitle;
|
||||
G4String zaxisTitle;
|
||||
UpdateTitle(xaxisTitle, xunitName, xfcnName);
|
||||
UpdateTitle(yaxisTitle, yunitName, yfcnName);
|
||||
UpdateTitle(zaxisTitle, zunitName, zfcnName);
|
||||
UpdateTitle(xaxisTitle, xunitName, xfcnName);
|
||||
UpdateTitle(yaxisTitle, yunitName, yfcnName);
|
||||
UpdateTitle(zaxisTitle, zunitName, zfcnName);
|
||||
p2d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
|
||||
p2d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
|
||||
p2d->add_annotation(tools::histo::key_axis_z_title(), zaxisTitle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::p2d* CreateToolsP2(
|
||||
const G4String& title,
|
||||
@@ -101,11 +95,12 @@ tools::histo::p2d* CreateToolsP2(
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName)
|
||||
const G4String& ybinSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
@@ -115,30 +110,27 @@ tools::histo::p2d* CreateToolsP2(
|
||||
auto zfcn = GetFunction(zfcnName);
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
|
||||
|
||||
if ( xbinScheme != G4BinScheme::kLog && ybinScheme != G4BinScheme::kLog) {
|
||||
if ( xbinScheme == G4BinScheme::kUser || ybinScheme == G4BinScheme::kUser ) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4P2ToolsManager::CreateP2",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
if ( zmin == 0. && zmax == 0.) {
|
||||
return new tools::histo::p2d(title,
|
||||
nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "CreateToolsP2");
|
||||
}
|
||||
if ( zmin == 0. && zmax == 0.) {
|
||||
return new tools::histo::p2d(title,
|
||||
nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
nybins, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
// p2 objects are deleted in destructor and reset when
|
||||
// p2 objects are deleted in destructor and reset when
|
||||
// closing a file.
|
||||
} else {
|
||||
return new tools::histo::p2d(title,
|
||||
nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
return new tools::histo::p2d(title,
|
||||
nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
nybins, yfcn(ymin/yunit), yfcn(ymax/yunit),
|
||||
zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
// p2 objects are deleted in destructor and reset when
|
||||
// p2 objects are deleted in destructor and reset when
|
||||
// closing a file.
|
||||
}
|
||||
}
|
||||
@@ -148,14 +140,14 @@ tools::histo::p2d* CreateToolsP2(
|
||||
ComputeEdges(nxbins, xmin, xmax, xunit, xfcn, xbinScheme, xedges);
|
||||
std::vector<G4double> yedges;
|
||||
ComputeEdges(nybins, ymin, ymax, yunit, yfcn, ybinScheme, yedges);
|
||||
if ( zmin == 0. && zmax == 0.) {
|
||||
return new tools::histo::p2d(title, xedges, yedges);
|
||||
if ( zmin == 0. && zmax == 0.) {
|
||||
return new tools::histo::p2d(title, xedges, yedges);
|
||||
} else {
|
||||
return new tools::histo::p2d(title, xedges, yedges,
|
||||
zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
return new tools::histo::p2d(title, xedges, yedges,
|
||||
zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::p2d* CreateToolsP2(
|
||||
@@ -169,7 +161,7 @@ tools::histo::p2d* CreateToolsP2(
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName)
|
||||
{
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
auto zunit = GetUnitValue(zunitName);
|
||||
@@ -177,23 +169,23 @@ tools::histo::p2d* CreateToolsP2(
|
||||
auto yfcn = GetFunction(yfcnName);
|
||||
auto zfcn = GetFunction(zfcnName);
|
||||
|
||||
// Apply function
|
||||
// Apply function
|
||||
std::vector<G4double> xnewEdges;
|
||||
ComputeEdges(xedges, xunit, xfcn, xnewEdges);
|
||||
std::vector<G4double> ynewEdges;
|
||||
ComputeEdges(yedges, yunit, yfcn, ynewEdges);
|
||||
|
||||
if ( zmin == 0. && zmax == 0.) {
|
||||
return new tools::histo::p2d(title, xnewEdges, ynewEdges);
|
||||
// p2 objects are deleted in destructor and reset when
|
||||
|
||||
if ( zmin == 0. && zmax == 0.) {
|
||||
return new tools::histo::p2d(title, xnewEdges, ynewEdges);
|
||||
// p2 objects are deleted in destructor and reset when
|
||||
// closing a file.
|
||||
} else {
|
||||
return new tools::histo::p2d(title, xnewEdges, ynewEdges,
|
||||
zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
// p2 objects are deleted in destructor and reset when
|
||||
return new tools::histo::p2d(title, xnewEdges, ynewEdges,
|
||||
zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
// p2 objects are deleted in destructor and reset when
|
||||
// closing a file.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsP2(tools::histo::p2d* p2d,
|
||||
@@ -203,11 +195,12 @@ void ConfigureToolsP2(tools::histo::p2d* p2d,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName)
|
||||
const G4String& ybinSchemeName,
|
||||
std::string_view className)
|
||||
{
|
||||
auto xunit = GetUnitValue(xunitName);
|
||||
auto yunit = GetUnitValue(yunitName);
|
||||
@@ -217,23 +210,20 @@ void ConfigureToolsP2(tools::histo::p2d* p2d,
|
||||
auto zfcn = GetFunction(zfcnName);
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
|
||||
|
||||
if ( xbinScheme != G4BinScheme::kLog && ybinScheme != G4BinScheme::kLog) {
|
||||
if ( xbinScheme == G4BinScheme::kUser || ybinScheme == G4BinScheme::kUser) {
|
||||
// This should never happen, but let's make sure about it
|
||||
// by issuing a warning
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " User binning scheme setting was ignored." << G4endl
|
||||
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
|
||||
G4Exception("G4P2ToolsManager::CreateP2",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
Warn("User binning scheme setting was ignored.\n"
|
||||
"Linear binning will be applied with given (nbins, xmin, xmax) values.",
|
||||
className, "ConfigureToolsP2");
|
||||
}
|
||||
if ( zmin == 0. && zmax == 0. ) {
|
||||
p2d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
p2d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
nybins, yfcn(ymin/yunit), yfcn(ymax/yunit));
|
||||
} else {
|
||||
p2d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
p2d->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
|
||||
nybins, yfcn(ymin/yunit), yfcn(ymax/yunit),
|
||||
zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
}
|
||||
@@ -248,9 +238,9 @@ void ConfigureToolsP2(tools::histo::p2d* p2d,
|
||||
p2d->configure(xedges, yedges);
|
||||
} else {
|
||||
p2d->configure(xedges, yedges, zfcn(zmin/zunit), zfcn(zmax/zunit));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void ConfigureToolsP2(tools::histo::p2d* p2d,
|
||||
@@ -292,23 +282,23 @@ void ConfigureToolsP2(tools::histo::p2d* p2d,
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4P2ToolsManager::AddP2Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
void G4P2ToolsManager::AddP2Information(const G4String& name,
|
||||
const G4String& xunitName,
|
||||
const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName,
|
||||
const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
G4BinScheme xbinScheme,
|
||||
G4BinScheme ybinScheme) const
|
||||
{
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, 3);
|
||||
auto hnInformation = fHnManager->AddHnInformation(name, fkDimension);
|
||||
hnInformation->AddDimension(xunitName, xfcnName, xbinScheme);
|
||||
hnInformation->AddDimension(yunitName, yfcnName, ybinScheme);
|
||||
hnInformation->AddDimension(zunitName, zfcnName, G4BinScheme::kLinear);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -317,46 +307,41 @@ G4int G4P2ToolsManager::CreateP2(const G4String& name, const G4String& title,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
G4double zmin, G4double zmax,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName)
|
||||
|
||||
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "P2", name);
|
||||
#endif
|
||||
Message(kVL4, "create", "P2", name);
|
||||
|
||||
tools::histo::p2d* p2d
|
||||
= CreateToolsP2(title,
|
||||
= CreateToolsP2(title,
|
||||
nxbins, xmin, xmax, nybins, ymin, ymax, zmin, zmax,
|
||||
xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName,
|
||||
xbinSchemeName, ybinSchemeName);
|
||||
|
||||
xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName,
|
||||
xbinSchemeName, ybinSchemeName, fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddP2Annotation(p2d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Save P2 information
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
AddP2Information(
|
||||
name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
xbinScheme, ybinScheme);
|
||||
|
||||
// Register profile
|
||||
G4int id = RegisterT(p2d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "P2", name);
|
||||
#endif
|
||||
// Register profile
|
||||
G4int id = RegisterT(p2d, name);
|
||||
|
||||
Message(kVL2, "create", "P2", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4P2ToolsManager::CreateP2(const G4String& name, const G4String& title,
|
||||
@@ -367,67 +352,60 @@ G4int G4P2ToolsManager::CreateP2(const G4String& name, const G4String& title,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& zfcnName)
|
||||
|
||||
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "P2", name);
|
||||
#endif
|
||||
Message(kVL4, "create", "P2", name);
|
||||
|
||||
tools::histo::p2d* p2d
|
||||
= CreateToolsP2(title, xedges, yedges, zmin, zmax,
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
|
||||
|
||||
= CreateToolsP2(title, xedges, yedges, zmin, zmax,
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Add annotation
|
||||
AddP2Annotation(
|
||||
p2d, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
|
||||
|
||||
p2d, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Save P2 information
|
||||
AddP2Information(
|
||||
name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
name, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
G4BinScheme::kUser, G4BinScheme::kUser);
|
||||
|
||||
// Register profile
|
||||
G4int id = RegisterT(p2d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("create", "P2", name);
|
||||
#endif
|
||||
// Register profile
|
||||
G4int id = RegisterT(p2d, name);
|
||||
|
||||
Message(kVL2, "create", "P2", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::SetP2(G4int id,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nxbins, G4double xmin, G4double xmax,
|
||||
G4int nybins, G4double ymin, G4double ymax,
|
||||
G4double zmin, G4double zmax,
|
||||
const G4String& xunitName, const G4String& yunitName,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& zfcnName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& xbinSchemeName,
|
||||
const G4String& ybinSchemeName)
|
||||
{
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "SetP2", false, false);
|
||||
if ( ! p2d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id, "SetP2");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "P2", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "P2", info->GetName());
|
||||
|
||||
// Configure tools p2
|
||||
ConfigureToolsP2(
|
||||
p2d, nxbins, xmin, xmax, nybins, ymin, ymax, zmin, zmax,
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
xbinSchemeName, ybinSchemeName);
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
xbinSchemeName, ybinSchemeName, fkClass);
|
||||
|
||||
// Add annotation
|
||||
AddP2Annotation(p2d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
AddP2Annotation(p2d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Update information
|
||||
auto xbinScheme = GetBinScheme(xbinSchemeName);
|
||||
auto ybinScheme = GetBinScheme(ybinSchemeName);
|
||||
@@ -436,11 +414,11 @@ G4bool G4P2ToolsManager::SetP2(G4int id,
|
||||
xbinScheme, ybinScheme);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::SetP2(G4int id,
|
||||
const std::vector<G4double>& xedges,
|
||||
@@ -450,35 +428,33 @@ G4bool G4P2ToolsManager::SetP2(G4int id,
|
||||
const G4String& zunitName,
|
||||
const G4String& xfcnName, const G4String& yfcnName,
|
||||
const G4String& zfcnName)
|
||||
{
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "SetP2", false, false);
|
||||
if ( ! p2d ) return false;
|
||||
|
||||
auto info = fHnManager->GetHnInformation(id, "SetP2");
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("configure", "P2", info->GetName());
|
||||
#endif
|
||||
|
||||
Message(kVL4, "configure", "P2", info->GetName());
|
||||
|
||||
// Configure tools p2
|
||||
ConfigureToolsP2(p2d, xedges, yedges, zmin, zmax,
|
||||
ConfigureToolsP2(p2d, xedges, yedges, zmin, zmax,
|
||||
xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Add annotation
|
||||
AddP2Annotation(p2d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
AddP2Annotation(p2d, xunitName, yunitName, zunitName,
|
||||
xfcnName, yfcnName, zfcnName);
|
||||
|
||||
// Update information
|
||||
UpdateP2Information(
|
||||
info, xunitName, yunitName, zunitName, xfcnName, yfcnName, zfcnName,
|
||||
G4BinScheme::kUser, G4BinScheme::kUser);
|
||||
|
||||
// Set activation
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
fHnManager->SetActivation(id, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::ScaleP2(G4int id, G4double factor)
|
||||
{
|
||||
@@ -486,10 +462,10 @@ G4bool G4P2ToolsManager::ScaleP2(G4int id, G4double factor)
|
||||
if ( ! p2d ) return false;
|
||||
|
||||
return p2d->scale(factor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::FillP2(G4int id,
|
||||
G4bool G4P2ToolsManager::FillP2(G4int id,
|
||||
G4double xvalue, G4double yvalue, G4double zvalue,
|
||||
G4double weight)
|
||||
{
|
||||
@@ -497,35 +473,32 @@ G4bool G4P2ToolsManager::FillP2(G4int id,
|
||||
if ( ! p2d ) return false;
|
||||
|
||||
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
auto xInfo
|
||||
auto xInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kX, "FillP2");
|
||||
auto yInfo
|
||||
auto yInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kY, "FillP2");
|
||||
auto zInfo
|
||||
auto zInfo
|
||||
= fHnManager->GetHnDimensionInformation(id, kZ, "FillP2");
|
||||
|
||||
p2d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
|
||||
yInfo->fFcn(yvalue/yInfo->fUnit),
|
||||
p2d->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
|
||||
yInfo->fFcn(yvalue/yInfo->fUnit),
|
||||
zInfo->fFcn(zvalue/zInfo->fUnit), weight);
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
//description << " id " << id
|
||||
// << " xvalue " << xvalue << " yvalue " << yvalue << " zvalue " << zvalue;
|
||||
description << " id " << id
|
||||
<< " xvalue " << xvalue
|
||||
<< " xfcn(xvalue/xunit) " << xInfo->fFcn(xvalue/xInfo->fUnit)
|
||||
<< " yvalue " << yvalue
|
||||
<< " yfcn(yvalue/yunit) " << yInfo->fFcn(yvalue/yInfo->fUnit)
|
||||
<< " zvalue " << zvalue
|
||||
<< " zfcn(zvalue/zunit) " << zInfo->fFcn(zvalue/zInfo->fUnit)
|
||||
<< " weight " << weight;
|
||||
fState.GetVerboseL4()->Message("fill", "P2", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( IsVerbose(kVL4) ) {
|
||||
Message(kVL4, "fill", "P2",
|
||||
" id " + to_string(id) +
|
||||
" xvalue " + to_string(xvalue) +
|
||||
" xfcn(xvalue/xunit) " + to_string(xInfo->fFcn(xvalue/xInfo->fUnit)) +
|
||||
" yvalue " + to_string(yvalue) +
|
||||
" yfcn(yvalue/yunit) " + to_string(yInfo->fFcn(yvalue/yInfo->fUnit)) +
|
||||
" zvalue " + to_string(zvalue) +
|
||||
" zfcn(zvalue/zunit) " + to_string(zInfo->fFcn(zvalue/zInfo->fUnit)) +
|
||||
" weight " + to_string(weight));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -533,16 +506,16 @@ G4bool G4P2ToolsManager::FillP2(G4int id,
|
||||
G4int G4P2ToolsManager::GetP2Id(const G4String& name, G4bool warn) const
|
||||
{
|
||||
return GetTId(name, warn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4P2ToolsManager::GetP2Nxbins(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2NXbins");
|
||||
if ( ! p2d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*p2d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P2ToolsManager::GetP2Xmin(G4int id) const
|
||||
@@ -553,34 +526,34 @@ G4double G4P2ToolsManager::GetP2Xmin(G4int id) const
|
||||
if ( ! p2d ) return 0.;
|
||||
|
||||
return GetMin(*p2d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P2ToolsManager::GetP2Xmax(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2Xmax");
|
||||
if ( ! p2d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*p2d, kX);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P2ToolsManager::GetP2XWidth(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2XWidth", true, false);
|
||||
if ( ! p2d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*p2d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4P2ToolsManager::GetP2Nybins(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2NYbins");
|
||||
if ( ! p2d ) return 0;
|
||||
|
||||
|
||||
return GetNbins(*p2d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P2ToolsManager::GetP2Ymin(G4int id) const
|
||||
@@ -589,27 +562,27 @@ G4double G4P2ToolsManager::GetP2Ymin(G4int id) const
|
||||
|
||||
auto p2d = GetTInFunction(id, "GetP2Ymin");
|
||||
if ( ! p2d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*p2d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P2ToolsManager::GetP2Ymax(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2Ymax");
|
||||
if ( ! p2d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*p2d, kY);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P2ToolsManager::GetP2YWidth(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2YWidth", true, false);
|
||||
if ( ! p2d ) return 0.;
|
||||
|
||||
|
||||
return GetWidth(*p2d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P2ToolsManager::GetP2Zmin(G4int id) const
|
||||
@@ -618,140 +591,161 @@ G4double G4P2ToolsManager::GetP2Zmin(G4int id) const
|
||||
|
||||
auto p2d = GetTInFunction(id, "GetP2Zmin");
|
||||
if ( ! p2d ) return 0.;
|
||||
|
||||
|
||||
return GetMin(*p2d, kZ);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4double G4P2ToolsManager::GetP2Zmax(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2Zmax");
|
||||
if ( ! p2d ) return 0.;
|
||||
|
||||
|
||||
return GetMax(*p2d, kZ);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::SetP2Title(G4int id, const G4String& title)
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "SetP2Title");
|
||||
if ( ! p2d ) return false;
|
||||
|
||||
|
||||
return SetTitle(*p2d, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::SetP2XAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "SetP2XAxisTitle");
|
||||
if ( ! p2d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*p2d, kX, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::SetP2YAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "SetP2YAxisTitle");
|
||||
if ( ! p2d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*p2d, kY, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::SetP2ZAxisTitle(G4int id, const G4String& title)
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "SetP2ZAxisTitle");
|
||||
if ( ! p2d ) return false;
|
||||
|
||||
|
||||
return SetAxisTitle(*p2d, kZ, title);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4P2ToolsManager::GetP2Title(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2Title");
|
||||
if ( ! p2d ) return "";
|
||||
|
||||
|
||||
return GetTitle(*p2d);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4P2ToolsManager::GetP2XAxisTitle(G4int id) const
|
||||
G4String G4P2ToolsManager::GetP2XAxisTitle(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2XAxisTitle");
|
||||
if ( ! p2d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*p2d, kX, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4P2ToolsManager::GetP2YAxisTitle(G4int id) const
|
||||
G4String G4P2ToolsManager::GetP2YAxisTitle(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2YAxisTitle");
|
||||
if ( ! p2d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*p2d, kY, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4P2ToolsManager::GetP2ZAxisTitle(G4int id) const
|
||||
G4String G4P2ToolsManager::GetP2ZAxisTitle(G4int id) const
|
||||
{
|
||||
auto p2d = GetTInFunction(id, "GetP2ZAxisTitle");
|
||||
if ( ! p2d ) return "";
|
||||
|
||||
|
||||
return GetAxisTitle(*p2d, kZ, fHnManager->GetHnType());
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4P2ToolsManager::WriteOnAscii(std::ofstream& /*output*/)
|
||||
G4bool G4P2ToolsManager::WriteOnAscii(std::ofstream& output)
|
||||
{
|
||||
// Write selected objects on ASCII file
|
||||
// According to the implementation by Michel Maire, originally in
|
||||
// extended examples.
|
||||
// Not yet available for P2
|
||||
|
||||
return ! fHnManager->IsAscii();
|
||||
}
|
||||
// Do nothing if no histograms are selected
|
||||
if ( ! fHnManager->IsAscii() ) return true;
|
||||
|
||||
// Write p2 histograms
|
||||
for ( G4int i=0; i<G4int(fTVector.size()); ++i ) {
|
||||
auto id = i + fHnManager->GetFirstId();
|
||||
auto info = fHnManager->GetHnInformation(id,"WriteOnAscii");
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( ! info->GetAscii() ) continue;
|
||||
auto p2 = fTVector[i];
|
||||
|
||||
Message(kVL3, "write on ascii", "p2d", info->GetName());
|
||||
|
||||
output << "\n 2D profile " << id << ": " << p2->title()
|
||||
<< "\n \n \t \t X \t\t Y \t\t MeanZ" << G4endl;
|
||||
|
||||
for (G4int j=0; j< G4int(p2->axis_x().bins()); ++j) {
|
||||
for (G4int k=0; k< G4int(p2->axis_y().bins()); ++k) {
|
||||
auto sw = p2->bin_Sw(j, k);
|
||||
auto svw = p2->bin_Svw(j, k);
|
||||
auto mean = ( sw != 0. ) ? (svw / sw) : 0.;
|
||||
output << " " << j << "\t" << k << "\t"
|
||||
<< p2->axis_x().bin_center(j) << "\t"
|
||||
<< p2->axis_y().bin_center(k) << "\t"
|
||||
<< mean << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output.good();
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4P2ToolsManager::AddP2(const G4String& name, tools::histo::p2d* p2d)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("add", "P2", name);
|
||||
#endif
|
||||
Message(kVL4, "add", "P2", name);
|
||||
|
||||
// Add annotation
|
||||
AddP2Annotation(p2d, "none", "none", "none", "none", "none", "none");
|
||||
AddP2Annotation(p2d, "none", "none", "none", "none", "none", "none");
|
||||
// Add information
|
||||
AddP2Information(name, "none", "none", "none", "none", "none", "none",
|
||||
AddP2Information(name, "none", "none", "none", "none", "none", "none",
|
||||
G4BinScheme::kLinear, G4BinScheme::kLinear);
|
||||
|
||||
// Register profile
|
||||
G4int id = RegisterT(p2d, name);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("add", "P2", name);
|
||||
#endif
|
||||
|
||||
// Register profile
|
||||
G4int id = RegisterT(p2d, name);
|
||||
|
||||
Message(kVL2, "add", "P2", name);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4P2ToolsManager::AddP2Vector(
|
||||
const std::vector<tools::histo::p2d*>& p2Vector)
|
||||
{
|
||||
AddTVector(p2Vector);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::histo::p2d* G4P2ToolsManager::GetP2(G4int id, G4bool warn,
|
||||
G4bool onlyIfActive) const
|
||||
G4bool onlyIfActive) const
|
||||
{
|
||||
return GetTInFunction(id, "GetP2", warn, onlyIfActive);
|
||||
}
|
||||
|
||||
@@ -35,31 +35,34 @@
|
||||
#include "G4PlotManager.hh"
|
||||
#include "G4MPIToolsManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
G4ThreadLocal G4ToolsAnalysisManager* G4ToolsAnalysisManager::fgToolsInstance = nullptr;
|
||||
using namespace G4Analysis;
|
||||
|
||||
namespace {
|
||||
//Mutex to lock master manager when merging histograms
|
||||
G4Mutex mergeHnMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ToolsAnalysisManager* G4ToolsAnalysisManager::Instance()
|
||||
{
|
||||
return fgToolsInstance;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ToolsAnalysisManager::IsInstance()
|
||||
{
|
||||
return ( fgToolsInstance != 0 );
|
||||
}
|
||||
return ( fgToolsInstance != nullptr );
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ToolsAnalysisManager::G4ToolsAnalysisManager(const G4String& type, G4bool isMaster)
|
||||
: G4VAnalysisManager(type, isMaster),
|
||||
fH1Manager(nullptr),
|
||||
fH2Manager(nullptr),
|
||||
fH3Manager(nullptr),
|
||||
fP1Manager(nullptr),
|
||||
fP2Manager(nullptr)
|
||||
G4ToolsAnalysisManager::G4ToolsAnalysisManager(const G4String& type)
|
||||
: G4VAnalysisManager(type)
|
||||
{
|
||||
// Set instance pointer
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterToolsInstance = this;
|
||||
fgToolsInstance = this;
|
||||
|
||||
// Create managers
|
||||
@@ -69,7 +72,7 @@ G4ToolsAnalysisManager::G4ToolsAnalysisManager(const G4String& type, G4bool isMa
|
||||
fP1Manager = new G4P1ToolsManager(fState);
|
||||
fP2Manager = new G4P2ToolsManager(fState);
|
||||
// The managers will be deleted by the base class
|
||||
|
||||
|
||||
// Set managers to base class which takes then their ownership
|
||||
SetH1Manager(fH1Manager);
|
||||
SetH2Manager(fH2Manager);
|
||||
@@ -79,11 +82,15 @@ G4ToolsAnalysisManager::G4ToolsAnalysisManager(const G4String& type, G4bool isMa
|
||||
|
||||
// Plot manager
|
||||
SetPlotManager(std::make_shared<G4PlotManager>(fState));
|
||||
|
||||
// Messenger
|
||||
fMessenger = std::make_unique<G4ToolsAnalysisMessenger>(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ToolsAnalysisManager::~G4ToolsAnalysisManager()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterToolsInstance = nullptr;
|
||||
fgToolsInstance = nullptr;
|
||||
}
|
||||
|
||||
@@ -92,115 +99,164 @@ G4ToolsAnalysisManager::~G4ToolsAnalysisManager()
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ToolsAnalysisManager::PlotImpl()
|
||||
G4bool G4ToolsAnalysisManager::PlotImpl()
|
||||
{
|
||||
|
||||
// Only master thread performs plotting
|
||||
if ( G4Threading::IsWorkerThread() ) return true;
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Open output file
|
||||
fPlotManager->OpenFile(fVFileManager->GetPlotFileName());
|
||||
|
||||
// H1
|
||||
auto result
|
||||
= fPlotManager->PlotAndWrite<tools::histo::h1d>(fH1Manager->GetH1Vector(),
|
||||
result
|
||||
&= fPlotManager->PlotAndWrite<tools::histo::h1d>(fH1Manager->GetH1Vector(),
|
||||
fH1Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H2
|
||||
result
|
||||
= fPlotManager->PlotAndWrite<tools::histo::h2d>(fH2Manager->GetH2Vector(),
|
||||
result
|
||||
&= fPlotManager->PlotAndWrite<tools::histo::h2d>(fH2Manager->GetH2Vector(),
|
||||
fH2Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H3
|
||||
// not yet available in tools
|
||||
|
||||
// P1
|
||||
result
|
||||
= fPlotManager->PlotAndWrite<tools::histo::p1d>(fP1Manager->GetP1Vector(),
|
||||
result
|
||||
&= fPlotManager->PlotAndWrite<tools::histo::p1d>(fP1Manager->GetP1Vector(),
|
||||
fP1Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P2
|
||||
// not yet available in tools
|
||||
|
||||
// Close output file
|
||||
result = fPlotManager->CloseFile();
|
||||
finalResult = finalResult && result;
|
||||
result &= fPlotManager->CloseFile();
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ToolsAnalysisManager::MergeImpl(tools::histo::hmpi* hmpi)
|
||||
G4bool G4ToolsAnalysisManager::MergeImpl(tools::histo::hmpi* hmpi)
|
||||
{
|
||||
|
||||
// if ( G4Threading::IsWorkerThread() ) return true;
|
||||
|
||||
if ( ! hmpi ) return false;
|
||||
|
||||
G4bool finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Create MPI manager
|
||||
G4MPIToolsManager mpiToolsManager(fState, hmpi);
|
||||
|
||||
// H1
|
||||
G4bool result
|
||||
= mpiToolsManager.Merge<tools::histo::h1d>(fH1Manager->GetH1Vector(),
|
||||
result
|
||||
&= mpiToolsManager.Merge<tools::histo::h1d>(fH1Manager->GetH1Vector(),
|
||||
fH1Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H2
|
||||
result
|
||||
= mpiToolsManager.Merge<tools::histo::h2d>(fH2Manager->GetH2Vector(),
|
||||
result
|
||||
&= mpiToolsManager.Merge<tools::histo::h2d>(fH2Manager->GetH2Vector(),
|
||||
fH2Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H3
|
||||
result
|
||||
= mpiToolsManager.Merge<tools::histo::h3d>(fH3Manager->GetH3Vector(),
|
||||
result
|
||||
&= mpiToolsManager.Merge<tools::histo::h3d>(fH3Manager->GetH3Vector(),
|
||||
fH3Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P1
|
||||
result
|
||||
= mpiToolsManager.Merge<tools::histo::p1d>(fP1Manager->GetP1Vector(),
|
||||
result
|
||||
&= mpiToolsManager.Merge<tools::histo::p1d>(fP1Manager->GetP1Vector(),
|
||||
fP1Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P2
|
||||
result
|
||||
= mpiToolsManager.Merge<tools::histo::p2d>(fP2Manager->GetP2Vector(),
|
||||
result
|
||||
&= mpiToolsManager.Merge<tools::histo::p2d>(fP2Manager->GetP2Vector(),
|
||||
fP2Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ToolsAnalysisManager::Reset()
|
||||
G4bool G4ToolsAnalysisManager::WriteImpl()
|
||||
{
|
||||
// Nothing to be done on worker
|
||||
if ( G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
auto result = true;
|
||||
|
||||
// Write all histograms/profile on master
|
||||
result &=WriteT(fH1Manager->GetH1Vector(), fH1Manager->GetHnVector());
|
||||
result &=WriteT(fH2Manager->GetH2Vector(), fH2Manager->GetHnVector());
|
||||
result &=WriteT(fH3Manager->GetH3Vector(), fH3Manager->GetHnVector());
|
||||
result &=WriteT(fP1Manager->GetP1Vector(), fP1Manager->GetHnVector());
|
||||
result &=WriteT(fP2Manager->GetP2Vector(), fP2Manager->GetHnVector());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ToolsAnalysisManager::ResetImpl()
|
||||
{
|
||||
// Reset histograms and profiles
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = fH1Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
auto result = true;
|
||||
|
||||
result = fH2Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fH3Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fP1Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fP2Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
result &= fH1Manager->Reset();
|
||||
result &= fH2Manager->Reset();
|
||||
result &= fH3Manager->Reset();
|
||||
result &= fP1Manager->Reset();
|
||||
result &= fP2Manager->Reset();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ToolsAnalysisManager::ClearImpl()
|
||||
{
|
||||
// Reset histograms and profiles
|
||||
|
||||
fH1Manager->ClearData();
|
||||
fH2Manager->ClearData();
|
||||
fH3Manager->ClearData();
|
||||
fP1Manager->ClearData();
|
||||
fP2Manager->ClearData();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ToolsAnalysisManager::Merge()
|
||||
{
|
||||
// Nothing to be done on master
|
||||
if ( ! G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
if ( ! fgMasterToolsInstance ) {
|
||||
if (! IsEmpty() ) {
|
||||
Warn("No master G4AnalysisManager instance exists.\n"
|
||||
"Histogram/profile data will not be merged.",
|
||||
fkClass, "Merge");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Message(kVL4, "merge on worker", "histograms");
|
||||
|
||||
// The worker manager just adds its histograms to the master
|
||||
fH1Manager->Merge(mergeHnMutex, fgMasterToolsInstance->fH1Manager);
|
||||
fH2Manager->Merge(mergeHnMutex, fgMasterToolsInstance->fH2Manager);
|
||||
fH3Manager->Merge(mergeHnMutex, fgMasterToolsInstance->fH3Manager);
|
||||
fP1Manager->Merge(mergeHnMutex, fgMasterToolsInstance->fP1Manager);
|
||||
fP2Manager->Merge(mergeHnMutex, fgMasterToolsInstance->fP2Manager);
|
||||
|
||||
Message(kVL3, "merge on worker", "histograms");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ToolsAnalysisManager::IsEmpty()
|
||||
{
|
||||
return fH1Manager->IsEmpty() && fH2Manager->IsEmpty() && fH3Manager->IsEmpty() &&
|
||||
fP1Manager->IsEmpty() && fP2Manager->IsEmpty();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 29/10/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4ToolsAnalysisMessenger.hh"
|
||||
#include "G4ToolsAnalysisManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4AnalysisMessengerHelper.hh"
|
||||
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UIparameter.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ToolsAnalysisMessenger::G4ToolsAnalysisMessenger(G4ToolsAnalysisManager* manager)
|
||||
: G4UImessenger(),
|
||||
fManager(manager)
|
||||
{
|
||||
// Create get commands
|
||||
G4AnalysisMessengerHelper helper("h1");
|
||||
fGetH1Cmd = helper.CreateGetCommand(this);
|
||||
|
||||
helper.SetHnType("h2");
|
||||
fGetH2Cmd = helper.CreateGetCommand(this);
|
||||
|
||||
helper.SetHnType("h3");
|
||||
fGetH3Cmd = helper.CreateGetCommand(this);
|
||||
|
||||
helper.SetHnType("p1");
|
||||
fGetP1Cmd = helper.CreateGetCommand(this);
|
||||
|
||||
helper.SetHnType("p2");
|
||||
fGetP2Cmd = helper.CreateGetCommand(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ToolsAnalysisMessenger::~G4ToolsAnalysisMessenger() = default;
|
||||
|
||||
///
|
||||
// public functions
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4ToolsAnalysisMessenger::GetCurrentValue (G4UIcommand* command)
|
||||
{
|
||||
if ( command == fGetH1Cmd.get() ) return fH1Value;
|
||||
if ( command == fGetH2Cmd.get() ) return fH2Value;
|
||||
if ( command == fGetH3Cmd.get() ) return fH3Value;
|
||||
if ( command == fGetP1Cmd.get() ) return fP1Value;
|
||||
if ( command == fGetP2Cmd.get() ) return fP2Value;
|
||||
return "";
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4ToolsAnalysisMessenger::SetNewValue(G4UIcommand* command, G4String value)
|
||||
{
|
||||
auto id = G4UIcommand::ConvertToInt(value);
|
||||
if ( command == fGetH1Cmd.get() ) {
|
||||
fH1Value = GetHnAddress(id, fManager->fH1Manager);
|
||||
}
|
||||
else if ( command == fGetH2Cmd.get() ) {
|
||||
fH2Value = GetHnAddress(id, fManager->fH2Manager);
|
||||
}
|
||||
else if ( command == fGetH3Cmd.get() ) {
|
||||
fH3Value = GetHnAddress(id, fManager->fH3Manager);
|
||||
}
|
||||
else if ( command == fGetP1Cmd.get() ) {
|
||||
fP1Value = GetHnAddress(id, fManager->fP1Manager);
|
||||
}
|
||||
else if ( command == fGetP2Cmd.get() ) {
|
||||
fP2Value = GetHnAddress(id, fManager->fP2Manager);
|
||||
}
|
||||
}
|
||||
@@ -32,16 +32,10 @@
|
||||
#include "G4H3ToolsManager.hh"
|
||||
#include "G4P1ToolsManager.hh"
|
||||
#include "G4P2ToolsManager.hh"
|
||||
#include "G4MPIToolsManager.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ToolsAnalysisReader::G4ToolsAnalysisReader(const G4String& type, G4bool isMaster)
|
||||
: G4VAnalysisReader(type, isMaster),
|
||||
fH1Manager(nullptr),
|
||||
fH2Manager(nullptr),
|
||||
fH3Manager(nullptr),
|
||||
fP1Manager(nullptr),
|
||||
fP2Manager(nullptr)
|
||||
G4ToolsAnalysisReader::G4ToolsAnalysisReader(const G4String& type)
|
||||
: G4VAnalysisReader(type)
|
||||
{
|
||||
// Create managers
|
||||
fH1Manager = new G4H1ToolsManager(fState);
|
||||
@@ -50,7 +44,7 @@ G4ToolsAnalysisReader::G4ToolsAnalysisReader(const G4String& type, G4bool isMast
|
||||
fP1Manager = new G4P1ToolsManager(fState);
|
||||
fP2Manager = new G4P2ToolsManager(fState);
|
||||
// The managers will be deleted by the base class
|
||||
|
||||
|
||||
// Set managers to base class which takes then their ownership
|
||||
SetH1Manager(fH1Manager);
|
||||
SetH2Manager(fH2Manager);
|
||||
@@ -59,35 +53,72 @@ G4ToolsAnalysisReader::G4ToolsAnalysisReader(const G4String& type, G4bool isMast
|
||||
SetP2Manager(fP2Manager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4ToolsAnalysisReader::~G4ToolsAnalysisReader()
|
||||
{}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4ToolsAnalysisReader::ReadH1Impl(const G4String& h1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
return ReadTImpl<tools::histo::h1d>(
|
||||
h1Name, fileName, dirName, isUserFileName, fH1Manager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4ToolsAnalysisReader::ReadH2Impl(const G4String& h2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
return ReadTImpl<tools::histo::h2d>(
|
||||
h2Name, fileName, dirName, isUserFileName, fH2Manager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4ToolsAnalysisReader::ReadH3Impl(const G4String& h3Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
return ReadTImpl<tools::histo::h3d>(
|
||||
h3Name, fileName, dirName, isUserFileName, fH3Manager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4ToolsAnalysisReader::ReadP1Impl(const G4String& p1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
return ReadTImpl<tools::histo::p1d>(
|
||||
p1Name, fileName, dirName, isUserFileName, fP1Manager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4ToolsAnalysisReader::ReadP2Impl(const G4String& p2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
return ReadTImpl<tools::histo::p2d>(
|
||||
p2Name, fileName, dirName, isUserFileName, fP2Manager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4ToolsAnalysisReader::Reset()
|
||||
{
|
||||
// Reset histograms and profiles
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = fH1Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
auto result = true;
|
||||
|
||||
result = fH2Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fH3Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fP1Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fP2Manager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
result &= fH1Manager->Reset();
|
||||
result &= fH2Manager->Reset();
|
||||
result &= fH3Manager->Reset();
|
||||
result &= fP1Manager->Reset();
|
||||
result &= fP2Manager->Reset();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -31,9 +31,10 @@
|
||||
#ifndef G4AnalysisManagerState_h
|
||||
#define G4AnalysisManagerState_h 1
|
||||
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "globals.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4AnalysisManagerState
|
||||
{
|
||||
@@ -42,46 +43,45 @@ class G4AnalysisManagerState
|
||||
friend class G4VAnalysisReader;
|
||||
friend class G4ParameterManager;
|
||||
|
||||
public:
|
||||
public:
|
||||
G4AnalysisManagerState(const G4String& type, G4bool isMaster);
|
||||
// disabled constructors, operators
|
||||
G4AnalysisManagerState() = delete;
|
||||
G4AnalysisManagerState(const G4AnalysisManagerState&) = delete;
|
||||
G4AnalysisManagerState& operator=(const G4AnalysisManagerState&) = delete;
|
||||
|
||||
// Methods
|
||||
void Message([[maybe_unused]] G4int level,
|
||||
[[maybe_unused]] const G4String& action,
|
||||
[[maybe_unused]] const G4String& objectType,
|
||||
[[maybe_unused]] const G4String& objectName = "",
|
||||
[[maybe_unused]] G4bool success = true) const;
|
||||
|
||||
// get methods
|
||||
G4String GetType() const;
|
||||
G4bool GetIsMaster() const;
|
||||
G4bool GetIsActivation() const;
|
||||
G4int GetVerboseLevel() const;
|
||||
const G4AnalysisVerbose* GetVerboseL1() const;
|
||||
const G4AnalysisVerbose* GetVerboseL2() const;
|
||||
const G4AnalysisVerbose* GetVerboseL3() const;
|
||||
const G4AnalysisVerbose* GetVerboseL4() const;
|
||||
G4bool IsVerbose(G4int verboseLevel) const;
|
||||
G4int GetCompressionLevel() const;
|
||||
|
||||
private:
|
||||
// disabled constructors, operators
|
||||
G4AnalysisManagerState();
|
||||
G4AnalysisManagerState(const G4AnalysisManagerState&);
|
||||
G4AnalysisManagerState& operator=(const G4AnalysisManagerState&);
|
||||
|
||||
// set methods
|
||||
// (hidden from all clients except for G4VAnalysisManager friend)
|
||||
void SetIsActivation(G4bool isActivation);
|
||||
void SetVerboseLevel(G4int verboseLevel);
|
||||
void SetCompressionLevel(G4int level);
|
||||
|
||||
// data members
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4AnalysisManagerState" };
|
||||
|
||||
// Data members
|
||||
G4String fType;
|
||||
G4bool fIsMaster;
|
||||
G4bool fIsActivation;
|
||||
G4int fVerboseLevel;
|
||||
G4int fCompressionLevel;
|
||||
G4AnalysisVerbose fVerboseL1;
|
||||
G4AnalysisVerbose fVerboseL2;
|
||||
G4AnalysisVerbose fVerboseL3;
|
||||
G4AnalysisVerbose fVerboseL4;
|
||||
G4AnalysisVerbose* fpVerboseL1;
|
||||
G4AnalysisVerbose* fpVerboseL2;
|
||||
G4AnalysisVerbose* fpVerboseL3;
|
||||
G4AnalysisVerbose* fpVerboseL4;
|
||||
G4bool fIsActivation { false };
|
||||
G4int fVerboseLevel { 0 };
|
||||
G4int fCompressionLevel { 1 };
|
||||
G4AnalysisVerbose fVerbose;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
@@ -104,17 +104,8 @@ inline G4bool G4AnalysisManagerState::GetIsActivation() const
|
||||
inline G4int G4AnalysisManagerState::GetVerboseLevel() const
|
||||
{ return fVerboseLevel; }
|
||||
|
||||
inline const G4AnalysisVerbose* G4AnalysisManagerState::GetVerboseL1() const
|
||||
{ return fpVerboseL1; }
|
||||
|
||||
inline const G4AnalysisVerbose* G4AnalysisManagerState::GetVerboseL2() const
|
||||
{ return fpVerboseL2; }
|
||||
|
||||
inline const G4AnalysisVerbose* G4AnalysisManagerState::GetVerboseL3() const
|
||||
{ return fpVerboseL3; }
|
||||
|
||||
inline const G4AnalysisVerbose* G4AnalysisManagerState::GetVerboseL4() const
|
||||
{ return fpVerboseL4; }
|
||||
inline G4bool G4AnalysisManagerState::IsVerbose(G4int verboseLevel) const
|
||||
{ return fVerboseLevel == verboseLevel; }
|
||||
|
||||
inline G4int G4AnalysisManagerState::GetCompressionLevel() const
|
||||
{ return fCompressionLevel; }
|
||||
|
||||
@@ -58,21 +58,22 @@ class G4AnalysisMessenger : public G4UImessenger
|
||||
{
|
||||
public:
|
||||
explicit G4AnalysisMessenger(G4VAnalysisManager* manager);
|
||||
G4AnalysisMessenger() = delete;
|
||||
virtual ~G4AnalysisMessenger();
|
||||
|
||||
// methods
|
||||
|
||||
// Methods
|
||||
void SetH1HnManager(G4HnManager& h1HnManager);
|
||||
void SetH2HnManager(G4HnManager& h2HnManager);
|
||||
void SetH3HnManager(G4HnManager& h3HnManager);
|
||||
void SetP1HnManager(G4HnManager& p1HnManager);
|
||||
void SetP2HnManager(G4HnManager& p2HnManager);
|
||||
|
||||
// methods
|
||||
// Methods
|
||||
virtual void SetNewValue(G4UIcommand* command, G4String value) final;
|
||||
|
||||
private:
|
||||
// data members
|
||||
G4VAnalysisManager* fManager; ///< Associated class
|
||||
// Data members
|
||||
G4VAnalysisManager* fManager { nullptr }; ///< Associated class
|
||||
std::unique_ptr<G4FileMessenger> fFileMessenger;
|
||||
std::unique_ptr<G4H1Messenger> fH1Messenger;
|
||||
std::unique_ptr<G4H2Messenger> fH2Messenger;
|
||||
@@ -85,12 +86,12 @@ class G4AnalysisMessenger : public G4UImessenger
|
||||
std::unique_ptr<G4HnMessenger> fH3HnMessenger;
|
||||
std::unique_ptr<G4HnMessenger> fP1HnMessenger;
|
||||
std::unique_ptr<G4HnMessenger> fP2HnMessenger;
|
||||
|
||||
std::unique_ptr<G4UIdirectory> fAnalysisDir;
|
||||
std::unique_ptr<G4UIcmdWithABool> fSetActivationCmd;
|
||||
std::unique_ptr<G4UIcmdWithAnInteger> fVerboseCmd;
|
||||
std::unique_ptr<G4UIcmdWithAnInteger> fCompressionCmd;
|
||||
|
||||
std::unique_ptr<G4UIdirectory> fAnalysisDir;
|
||||
std::unique_ptr<G4UIcmdWithABool> fSetActivationCmd;
|
||||
std::unique_ptr<G4UIcmdWithAnInteger> fVerboseCmd;
|
||||
std::unique_ptr<G4UIcmdWithAnInteger> fCompressionCmd;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "globals.hh"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4VAnalysisManager;
|
||||
class G4UIdirectory;
|
||||
@@ -46,43 +47,37 @@ class G4AnalysisMessengerHelper
|
||||
public:
|
||||
// types
|
||||
struct BinData {
|
||||
BinData() :
|
||||
fNbins(0),
|
||||
fVmin(0.),
|
||||
fVmax(0.),
|
||||
fSunit(""),
|
||||
fSfcn(""),
|
||||
fSbinScheme("") {}
|
||||
G4int fNbins;
|
||||
G4double fVmin;
|
||||
G4double fVmax;
|
||||
BinData() {}
|
||||
G4int fNbins { 0 };
|
||||
G4double fVmin { 0. };
|
||||
G4double fVmax { 0. };
|
||||
G4String fSunit;
|
||||
G4String fSfcn;
|
||||
G4String fSbinScheme;
|
||||
};
|
||||
// types
|
||||
struct ValueData {
|
||||
ValueData() :
|
||||
fVmin(0.),
|
||||
fVmax(0.),
|
||||
fSunit(""),
|
||||
fSfcn("") {}
|
||||
G4double fVmin;
|
||||
G4double fVmax;
|
||||
ValueData() {}
|
||||
G4double fVmin { 0. };
|
||||
G4double fVmax { 0. };
|
||||
G4String fSunit;
|
||||
G4String fSfcn;
|
||||
};
|
||||
|
||||
public:
|
||||
// Make available utility Update method
|
||||
// Make available utility Update method
|
||||
friend class G4HnMessenger;
|
||||
|
||||
public:
|
||||
explicit G4AnalysisMessengerHelper(const G4String& hnType);
|
||||
~G4AnalysisMessengerHelper();
|
||||
|
||||
// methods to create commands
|
||||
std::unique_ptr<G4UIdirectory> CreateHnDirectory() const;
|
||||
G4AnalysisMessengerHelper() = delete;
|
||||
~G4AnalysisMessengerHelper() = default;
|
||||
|
||||
// Methods to create commands
|
||||
std::unique_ptr<G4UIdirectory> CreateHnDirectory() const;
|
||||
|
||||
std::unique_ptr<G4UIcommand> CreateGetCommand(
|
||||
G4UImessenger* messenger) const;
|
||||
|
||||
std::unique_ptr<G4UIcommand> CreateSetTitleCommand(
|
||||
G4UImessenger* messenger) const;
|
||||
@@ -95,23 +90,34 @@ class G4AnalysisMessengerHelper
|
||||
std::unique_ptr<G4UIcommand> CreateSetAxisLogCommand(const G4String& axis,
|
||||
G4UImessenger* messenger) const;
|
||||
|
||||
// methods to read command paremeters
|
||||
void GetBinData(BinData& data, std::vector<G4String>& parameters,
|
||||
// Methods to read command paremeters
|
||||
void GetBinData(BinData& data, std::vector<G4String>& parameters,
|
||||
G4int& counter) const;
|
||||
void GetValueData(ValueData& data, std::vector<G4String>& parameters,
|
||||
void GetValueData(ValueData& data, std::vector<G4String>& parameters,
|
||||
G4int& counter) const;
|
||||
|
||||
// Set methods
|
||||
void SetHnType(const G4String& hnType);
|
||||
|
||||
// warnings
|
||||
void WarnAboutParameters(G4UIcommand* command, G4int nofParameters) const;
|
||||
void WarnAboutSetCommands() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
G4String Update(const G4String& str, const G4String& axis = "") const;
|
||||
|
||||
// data members
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4AnalysisMessengerHelper" };
|
||||
|
||||
// Data members
|
||||
G4String fHnType;
|
||||
};
|
||||
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void G4AnalysisMessengerHelper::SetHnType(const G4String& hnType)
|
||||
{ fHnType = hnType; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -29,10 +29,12 @@
|
||||
#ifndef G4AnalysisUtilities_h
|
||||
#define G4AnalysisUtilities_h 1
|
||||
|
||||
#include "G4Exception.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
// Enumeration for definition of available output types
|
||||
|
||||
@@ -42,26 +44,34 @@ enum class G4AnalysisOutput {
|
||||
kRoot,
|
||||
kXml,
|
||||
kNone
|
||||
};
|
||||
};
|
||||
|
||||
namespace G4Analysis
|
||||
namespace G4Analysis
|
||||
{
|
||||
|
||||
// Constant expressions
|
||||
//
|
||||
// constexpr G4int kX = 0; // not yet supported on vc12
|
||||
// constexpr G4int kY = 1; // not yet supported on vc12
|
||||
// constexpr G4int kZ = 2; // not yet supported on vc12
|
||||
const G4int kX = 0; // not yet supported on vc12
|
||||
const G4int kY = 1; // not yet supported on vc12
|
||||
const G4int kZ = 2; // not yet supported on vc12
|
||||
//
|
||||
constexpr G4int kX { 0 };
|
||||
constexpr G4int kY { 1 };
|
||||
constexpr G4int kZ { 2 };
|
||||
constexpr G4int kInvalidId { -1 };
|
||||
constexpr G4int kVL0 { 0 };
|
||||
constexpr G4int kVL1 { 1 };
|
||||
constexpr G4int kVL2 { 2 };
|
||||
constexpr G4int kVL3 { 3 };
|
||||
constexpr G4int kVL4 { 4 };
|
||||
constexpr unsigned int kDefaultBasketSize = 32000;
|
||||
constexpr unsigned int kDefaultBasketEntries = 4000;
|
||||
constexpr std::string_view kNamespaceName { "G4Analysis" };
|
||||
|
||||
// Invalid object Id
|
||||
//
|
||||
// constexpr G4int kInvalidId = -1; // not yet supported on vc12
|
||||
const G4int kInvalidId = -1; // not yet supported on vc12
|
||||
// Warning
|
||||
//
|
||||
void Warn(const G4String& message,
|
||||
const std::string_view inClass,
|
||||
const std::string_view inFunction);
|
||||
|
||||
// Utility functions for checking input parameters
|
||||
//
|
||||
G4bool CheckNbins(G4int nbins);
|
||||
G4bool CheckMinMax(G4double xmin, G4double xmax,
|
||||
const G4String& fcnName = "none",
|
||||
@@ -69,29 +79,22 @@ G4bool CheckMinMax(G4double xmin, G4double xmax,
|
||||
G4bool CheckEdges(const std::vector<G4double>& edges);
|
||||
G4bool CheckName(const G4String& name, const G4String& objectType);
|
||||
|
||||
// Get unit value with added handling of "none"
|
||||
// Get unit value with added handling of "none"
|
||||
G4double GetUnitValue(const G4String& unit);
|
||||
|
||||
// Add unit & fcn to the title
|
||||
void UpdateTitle(G4String& title,
|
||||
void UpdateTitle(G4String& title,
|
||||
const G4String& unitName, const G4String& fcnName);
|
||||
|
||||
// Tokenizer with taking into account composed strings within ""
|
||||
|
||||
// Tokenizer with taking into account composed strings within ""
|
||||
void Tokenize(const G4String& line, std::vector<G4String>& tokens);
|
||||
|
||||
// make-unique utility, not yet availabla in C++11
|
||||
template<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args&&... args)
|
||||
{
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
// get output type from name
|
||||
// Get output type from name
|
||||
G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn = true);
|
||||
size_t GetOutputId(const G4String& outputName, G4bool warn = true);
|
||||
G4String GetOutputName(G4AnalysisOutput outputType);
|
||||
|
||||
// get short hnType from the tools object
|
||||
// Get short hnType from the tools object
|
||||
template <typename HT>
|
||||
G4String GetHnType()
|
||||
{
|
||||
@@ -102,6 +105,27 @@ G4String GetHnType()
|
||||
return hnTypeLong.substr(14, 2);
|
||||
}
|
||||
|
||||
// template <typename HT>
|
||||
// G4bool IsProfile()
|
||||
// {
|
||||
// // tools::histo::h1d etc.
|
||||
// G4String hnTypeLong = HT::s_class();
|
||||
|
||||
// // tools::histo::h1d -> h1 etc.
|
||||
// return (hnTypeLong.substr(14, 1) == "p");
|
||||
// }
|
||||
|
||||
// String conversion
|
||||
template <typename T>
|
||||
inline
|
||||
std::string ToString(const T& value)
|
||||
{ return std::to_string(value); }
|
||||
|
||||
template <>
|
||||
inline
|
||||
std::string ToString<std::string>(const std::string& value)
|
||||
{ return value; }
|
||||
|
||||
// File names utilities
|
||||
|
||||
// Get file base name (without dot)
|
||||
@@ -116,8 +140,8 @@ G4String GetExtension(const G4String& fileName,
|
||||
// - add file extension if not present
|
||||
G4String GetHnFileName(
|
||||
const G4String& fileName,
|
||||
const G4String& fileType,
|
||||
const G4String& hnType,
|
||||
const G4String& fileType,
|
||||
const G4String& hnType,
|
||||
const G4String& hnName);
|
||||
|
||||
// Compose and return the ntuple specific file name:
|
||||
@@ -126,7 +150,7 @@ G4String GetHnFileName(
|
||||
// - add file extension if not present
|
||||
G4String GetNtupleFileName(
|
||||
const G4String& fileName,
|
||||
const G4String& fileType,
|
||||
const G4String& fileType,
|
||||
const G4String& ntupleName);
|
||||
|
||||
// Compose and return the ntuple specific file name:
|
||||
@@ -135,7 +159,7 @@ G4String GetNtupleFileName(
|
||||
// - add file extension if not present
|
||||
G4String GetNtupleFileName(
|
||||
const G4String& fileName,
|
||||
const G4String& fileType,
|
||||
const G4String& fileType,
|
||||
G4int ntupleFileNumber);
|
||||
|
||||
// Update file base name with the thread suffix:
|
||||
|
||||
@@ -33,29 +33,31 @@
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <array>
|
||||
|
||||
class G4AnalysisVerbose
|
||||
{
|
||||
public:
|
||||
G4AnalysisVerbose(G4int verboseLevel);
|
||||
~G4AnalysisVerbose();
|
||||
G4AnalysisVerbose();
|
||||
~G4AnalysisVerbose() = default;
|
||||
|
||||
void Message(const G4String& action,
|
||||
const G4String& object,
|
||||
void Message(G4int verboseLevel,
|
||||
const G4String& action,
|
||||
const G4String& object,
|
||||
const G4String& objectName,
|
||||
G4bool success = true) const;
|
||||
|
||||
void Message(const G4String& action,
|
||||
const G4String& object,
|
||||
G4ExceptionDescription& description,
|
||||
G4bool success = true) const;
|
||||
|
||||
private:
|
||||
// data members
|
||||
//
|
||||
G4String fToBeDoneText;
|
||||
G4String fDoneText;
|
||||
G4String fFailureText;
|
||||
// Static data members
|
||||
static constexpr int fkMaxLevel = 4;
|
||||
|
||||
// Data members
|
||||
std::array<G4String, fkMaxLevel> fDoneText
|
||||
{ G4String("- done"), G4String("- done"), G4String(), G4String() };
|
||||
std::array<G4String, fkMaxLevel> fToBeDoneText
|
||||
{ G4String(), G4String(), G4String("done "), G4String("going to ") };
|
||||
G4String fFailureText
|
||||
{ "has failed" };
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -38,13 +38,14 @@
|
||||
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4BaseAnalysisManager
|
||||
{
|
||||
public:
|
||||
explicit G4BaseAnalysisManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4BaseAnalysisManager();
|
||||
|
||||
// methods
|
||||
G4BaseAnalysisManager() = delete;
|
||||
virtual ~G4BaseAnalysisManager() = default;
|
||||
|
||||
// The ids of objects are generated automatically
|
||||
// starting from 0; with the following function it is possible to
|
||||
@@ -56,21 +57,43 @@ class G4BaseAnalysisManager
|
||||
G4int GetFirstId() const;
|
||||
|
||||
protected:
|
||||
// data members
|
||||
// Methods for verbose
|
||||
G4bool IsVerbose(G4int verboseLevel) const;
|
||||
void Message(G4int level,
|
||||
const G4String& action,
|
||||
const G4String& objectType,
|
||||
const G4String& objectName = "",
|
||||
G4bool success = true) const;
|
||||
|
||||
// Data members
|
||||
const G4AnalysisManagerState& fState;
|
||||
G4int fFirstId;
|
||||
G4bool fLockFirstId;
|
||||
G4int fFirstId { 0 };
|
||||
G4bool fLockFirstId { false };
|
||||
|
||||
private:
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4BaseAnalysisManager" };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline G4bool G4BaseAnalysisManager::IsVerbose(G4int verboseLevel) const
|
||||
{ return fState.IsVerbose(verboseLevel); }
|
||||
|
||||
inline void G4BaseAnalysisManager::Message(
|
||||
G4int level, const G4String& action, const G4String& objectType,
|
||||
const G4String& objectName, G4bool success) const
|
||||
{
|
||||
fState.Message(level, action, objectType, objectName, success);
|
||||
}
|
||||
|
||||
inline void G4BaseAnalysisManager::SetLockFirstId(G4bool lockFirstId) {
|
||||
fLockFirstId = lockFirstId;
|
||||
}
|
||||
}
|
||||
|
||||
inline G4int G4BaseAnalysisManager::GetFirstId() const {
|
||||
return fFirstId;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ class G4BaseFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4BaseFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4BaseFileManager();
|
||||
G4BaseFileManager() = delete;
|
||||
virtual ~G4BaseFileManager() = default;
|
||||
|
||||
virtual G4bool SetFileName(const G4String& fileName);
|
||||
// Set the base file name (without extension)
|
||||
@@ -50,7 +51,7 @@ class G4BaseFileManager
|
||||
void AddFileName(const G4String& fileName);
|
||||
// For handling multiple files
|
||||
// Save file name in a vector if not yet present
|
||||
|
||||
|
||||
G4String GetFileName() const;
|
||||
// Return the base file name (without extension)
|
||||
G4String GetFullFileName(const G4String& baseFileName = "",
|
||||
@@ -61,7 +62,7 @@ class G4BaseFileManager
|
||||
const std::vector<G4String>& GetFileNames() const;
|
||||
// Return the file names vector
|
||||
|
||||
G4String GetHnFileName(const G4String& hnType,
|
||||
G4String GetHnFileName(const G4String& hnType,
|
||||
const G4String& hnName) const;
|
||||
// Compose and return the histogram or profile specific file name:
|
||||
// - add _hn_hnName suffix to the file base name
|
||||
@@ -72,17 +73,24 @@ class G4BaseFileManager
|
||||
// - add _nt_ntupleName suffix to the file base name
|
||||
// - add _tN suffix if called on thread worker
|
||||
// - add file extension if not present
|
||||
|
||||
|
||||
G4String GetNtupleFileName(G4int ntupleFileNumber) const;
|
||||
// Compose and return the ntuple specific file name:
|
||||
// - add _mN suffix to the file base name
|
||||
// - add _mN suffix to the file base name
|
||||
// - add file extension if not present
|
||||
|
||||
|
||||
G4String GetPlotFileName() const;
|
||||
// Return the file name for batch plotting output
|
||||
|
||||
protected:
|
||||
// data members
|
||||
// Methods for verbose
|
||||
void Message(G4int level,
|
||||
const G4String& action,
|
||||
const G4String& objectType,
|
||||
const G4String& objectName = "",
|
||||
G4bool success = true) const;
|
||||
|
||||
// Data members
|
||||
const G4AnalysisManagerState& fState;
|
||||
G4String fFileName; // to be changed in fDefaultFileName
|
||||
std::vector<G4String> fFileNames;
|
||||
@@ -92,7 +100,7 @@ inline G4bool G4BaseFileManager::SetFileName(const G4String& fileName) {
|
||||
// CHECK if still needed in this base class
|
||||
fFileName = fileName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
inline G4String G4BaseFileManager::GetFileName() const {
|
||||
return fFileName;
|
||||
@@ -102,4 +110,11 @@ inline const std::vector<G4String>& G4BaseFileManager::GetFileNames() const {
|
||||
return fFileNames;
|
||||
}
|
||||
|
||||
inline void G4BaseFileManager::Message(
|
||||
G4int level, const G4String& action, const G4String& objectType,
|
||||
const G4String& objectName, G4bool success) const
|
||||
{
|
||||
fState.Message(level, action, objectType, objectName, success);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// The base class for Ntuple managers.
|
||||
// It implements common functions independent from the output type.
|
||||
// The base class for Ntuple managers.
|
||||
// It implements common functions independent from the output type.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -39,7 +39,8 @@ class G4BaseNtupleManager : public G4VNtupleManager
|
||||
{
|
||||
public:
|
||||
explicit G4BaseNtupleManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4BaseNtupleManager();
|
||||
G4BaseNtupleManager() = delete;
|
||||
virtual ~G4BaseNtupleManager() = default;
|
||||
|
||||
// deleted copy constructor & assignment operator
|
||||
G4BaseNtupleManager(const G4BaseNtupleManager& rhs) = delete;
|
||||
@@ -50,18 +51,18 @@ class G4BaseNtupleManager : public G4VNtupleManager
|
||||
virtual G4int CreateNtuple(G4NtupleBooking* booking) = 0;
|
||||
|
||||
// Methods to fill ntuples
|
||||
// Methods for ntuple with id = FirstNtupleId
|
||||
// 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)
|
||||
// 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,
|
||||
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
|
||||
const G4String& value) = 0;
|
||||
virtual G4bool AddNtupleRow(G4int ntupleId) = 0;
|
||||
|
||||
@@ -69,7 +70,7 @@ class G4BaseNtupleManager : public G4VNtupleManager
|
||||
virtual G4bool SetFirstNtupleColumnId(G4int firstId) final;
|
||||
|
||||
protected:
|
||||
G4int fFirstNtupleColumnId;
|
||||
G4int fFirstNtupleColumnId { 0 };
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// The base class for read Ntuple manager.
|
||||
// It defines functions independent from the output type.
|
||||
// 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)
|
||||
|
||||
@@ -45,57 +45,61 @@ class G4BaseRNtupleManager : public G4VRNtupleManager
|
||||
|
||||
public:
|
||||
explicit G4BaseRNtupleManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4BaseRNtupleManager();
|
||||
virtual ~G4BaseRNtupleManager() = default;
|
||||
|
||||
// deleted copy constructor & assignment operator
|
||||
// deleted default © constructors & assignment operator
|
||||
G4BaseRNtupleManager() = delete;
|
||||
G4BaseRNtupleManager(const G4BaseRNtupleManager& rhs) = delete;
|
||||
G4BaseRNtupleManager& operator=(const G4BaseRNtupleManager& rhs) = delete;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
// Methods to read ntuple from a file
|
||||
// Methods for ntuple with id = FirstNtupleId
|
||||
virtual G4bool SetNtupleIColumn(const G4String& columnName,
|
||||
// Methods for ntuple with id = FirstNtupleId
|
||||
virtual G4bool SetNtupleIColumn(const G4String& columnName,
|
||||
G4int& value) final;
|
||||
virtual G4bool SetNtupleFColumn(const G4String& columnName,
|
||||
virtual G4bool SetNtupleFColumn(const G4String& columnName,
|
||||
G4float& value) final;
|
||||
virtual G4bool SetNtupleDColumn(const G4String& columnName,
|
||||
virtual G4bool SetNtupleDColumn(const G4String& columnName,
|
||||
G4double& value) final;
|
||||
virtual G4bool SetNtupleSColumn(const G4String& columnName,
|
||||
virtual G4bool SetNtupleSColumn(const G4String& columnName,
|
||||
G4String& value) final;
|
||||
// Methods for ntuple with id > FirstNtupleId
|
||||
virtual G4bool SetNtupleIColumn(G4int ntupleId,
|
||||
// Methods for ntuple with id > FirstNtupleId
|
||||
virtual G4bool SetNtupleIColumn(G4int ntupleId,
|
||||
const G4String& columnName, G4int& value)= 0;
|
||||
virtual G4bool SetNtupleFColumn(G4int ntupleId,
|
||||
virtual G4bool SetNtupleFColumn(G4int ntupleId,
|
||||
const G4String& columnName, G4float& value)= 0;
|
||||
virtual G4bool SetNtupleDColumn(G4int ntupleId,
|
||||
virtual G4bool SetNtupleDColumn(G4int ntupleId,
|
||||
const G4String& columnName, G4double& value)= 0;
|
||||
virtual G4bool SetNtupleSColumn(G4int ntupleId,
|
||||
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,
|
||||
// Methods for ntuple with id = FirstNtupleId
|
||||
virtual G4bool SetNtupleIColumn(const G4String& columnName,
|
||||
std::vector<G4int>& vector) final;
|
||||
virtual G4bool SetNtupleFColumn(const G4String& columnName,
|
||||
virtual G4bool SetNtupleFColumn(const G4String& columnName,
|
||||
std::vector<G4float>& vector) final;
|
||||
virtual G4bool SetNtupleDColumn(const G4String& columnName,
|
||||
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,
|
||||
virtual G4bool SetNtupleSColumn(const G4String& columnName,
|
||||
std::vector<std::string>& 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,
|
||||
virtual G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName,
|
||||
std::vector<G4float>& vector) = 0;
|
||||
virtual G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
|
||||
virtual G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
|
||||
std::vector<G4double>& vector) = 0;
|
||||
virtual G4bool SetNtupleSColumn(G4int ntupleId, const G4String& columnName,
|
||||
std::vector<std::string>& vector) = 0;
|
||||
virtual G4bool GetNtupleRow() final;
|
||||
virtual G4bool GetNtupleRow(G4int ntupleId) = 0;
|
||||
|
||||
|
||||
// Access methods
|
||||
virtual G4int GetNofNtuples() const = 0;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
G4int GetCurrentNtupleId() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,20 +40,20 @@ enum class G4BinScheme {
|
||||
kLinear,
|
||||
kLog,
|
||||
kUser
|
||||
};
|
||||
};
|
||||
|
||||
// Utility function
|
||||
namespace G4Analysis {
|
||||
|
||||
G4BinScheme GetBinScheme(const G4String& binSchemeName);
|
||||
|
||||
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax,
|
||||
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax,
|
||||
G4double unit, G4Fcn fcn, G4BinScheme,
|
||||
std::vector<G4double>& edges);
|
||||
|
||||
void ComputeEdges(const std::vector<G4double>& edges,
|
||||
G4double unit, G4Fcn fcn,
|
||||
void ComputeEdges(const std::vector<G4double>& edges,
|
||||
G4double unit, G4Fcn fcn,
|
||||
std::vector<G4double>& newEdges);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -42,4 +42,4 @@ namespace G4Analysis {
|
||||
G4Fcn GetFunction(const G4String& fcnName);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user