Import Geant4 11.2.0 source tree

This commit is contained in:
Gabriele Cosmo
2023-12-08 10:43:34 +01:00
parent dd1f179cda
commit 860a2b92bf
3962 changed files with 139318 additions and 164259 deletions
+76
View File
@@ -6,6 +6,82 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2023-11-03 Ben Morgan (analysis-V11-01-10)
- Use "G4" prefixed version of EXPAT/ZLIB CMake variables
## 2023-09-20 I. Hrivnacova (analysis-V11-01-09)
- Updated GetNofNtuples implementation to take into account
new 'onlyIfExists' parameter:
- Moved 'GetNofNtuples' and 'List' functions in G4NtupleBookingManager
where the info about deleted ntuples (fFeeeIds) is available
## 2023-08-29 I. Hrivnacova (analysis-V11-01-08)
- Adding new G4AnalysisManager functions for deleting selected
ntuples:
G4bool DeleteNtuple(G4int id, G4bool clear = false);
and UI commands:
/analysis/ntuple/delete id [keepSetting]
- Added GetNtuple() functions in G4GenericAnalysisManager:
tools::ntuple_booking* GetNtuple(...) const
that, in difference from output specific managers, return
ntuple_booking, that is common to all output types
- Added UI commands for creating ntuple:
/analysis/ntuple/create name title
/analysis/ntuple/create[I|F|D|S]Column name
/analysis/ntuple/finish
- Changed verbosity level for "merge" information from 1 to 2
## 2023-08-29 I. Hrivnacova (analysis-V11-01-07)
- Fixed Coverity in G4RootHnFileManager
## 2023-08-14 I. Hrivnacova (analysis-V11-01-06)
- Updates & fixes in files handling:
- Moved Set/GetDefaultFileType methods and UI command in
G4VAnalysisManager and G4AnalysisMessenger
(from G4GenericAnalysisManager/Messenger)
- This allows to support omitting file extension also when
setting file names to histograms/profiles
- Removed G4GenericAnalysisMessenger
- Added clearing of file data in 'DeleteEmptyFiles'
- this prevent from deleting non-empty files created/filled in previous
runs but not used in new runs
- Supressed warning from 'CreateTFile' when file is already
existing
## 2023-08-02 I. Hrivnacova (analysis-V11-01-05)
- Adding new G4AnalysisManager functions for deleting selected
histograms/profiles:
G4bool Delete[Hn|Pn](G4int id, G4bool clear = false);
and UI commands:
/analysis/[hn|pn]/delete id [keepSetting]
## 2023-07-21 I. Hrivnacova (analysis-V11-01-04)
- Fixed implementation of set commands per dimension:
/analysis/hn|pn/setX|Y|Z
(Addressing a problem report in Geant4 forum.)
## 2023-07-20 I. Hrivnacova (analysis-V11-01-03)
- Moved kDimN constants from G4VAnalysisManger in G4AnalysisUtilities
and replaced all hard-wired literals '1', '2' and '3' with these
## 2023-07-19 I. Hrivnacova (analysis-V11-01-02)
- Addressed "TO DO" comments left in the code, improvements & a fix:
- Moved 'CompressionLevel' data/functions members from G4AnalysisManagerState
to G4BaseFileManager to make it available in helper classes
which do not have access to state
- Compression level (default 1) is now used also when writing a Root histogram
in an extra file and writing Hdf5 ntuples
- Postpone creating G4HnMessenger after G4THnMessenger to get
better command ordering in the 'help' tree
- Moved setAxisLog command from G4THnMessenger to G4HnMessenger
as it applies to function defined in its associated class
- Moved 'kMaxDim' constant from G4THnMessenger in G4AnalysisUtilities
as needed also at other places
- Fix: Do not create 'setAxis*'' commands for idim = 4
- Added warnings about failure in *HnFileManager::WriteExtra where
missing
- Use forward declarations for templated classes where suitable
## 2023-06-09 I. Hrivnacova (analysis-V11-01-01)
- Fixed creating histograms with user defined bins
- bug report #2541
@@ -57,7 +57,6 @@ void G4CsvNtupleManager::CreateTNtupleFromBooking(
ntupleDescription->SetNtuple(
new tools::wcsv::ntuple(
*(ntupleDescription->GetFile()), G4cerr, ntupleDescription->GetNtupleBooking()));
fNtupleVector.push_back(ntupleDescription->GetNtuple());
}
//_____________________________________________________________________________
@@ -39,15 +39,19 @@
#include <memory>
#include <string_view>
#include <vector>
class G4GenericAnalysisManager;
class G4GenericAnalysisMessenger;
class G4GenericFileManager;
class G4HnInformation;
class G4VNtupleFileManager;
template <class T>
class G4ThreadLocalSingleton;
namespace tools {
class ntuple_bookig;
}
class G4GenericAnalysisManager : public G4ToolsAnalysisManager
{
friend class G4RootMpiAnalysisManager;
@@ -73,14 +77,20 @@ class G4GenericAnalysisManager : public G4ToolsAnalysisManager
G4bool WriteP1(G4int id, const G4String& fileName);
G4bool WriteP2(G4int id, const G4String& fileName);
// Set default output type (backward compatibility)
// this type will be used for file names without extension
void SetDefaultFileType(const G4String& value);
G4String GetDefaultFileType() const;
// Access methods
// In difference from output specific managers, generic manager
// provides access only to ntuple_booking
tools::ntuple_booking* GetNtuple(G4bool warn = true,
G4bool onlyIfActive = true) const;
tools::ntuple_booking* GetNtuple(G4int ntupleId, G4bool warn = true,
G4bool onlyIfActive = true) const;
protected:
// Virtual methods from base class
G4bool OpenFileImpl(const G4String& fileName) override;
void SetDefaultFileTypeImpl(const G4String& value) override;
G4String GetDefaultFileTypeImpl() const override;
// File manager access
std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName) final;
@@ -95,7 +105,6 @@ class G4GenericAnalysisManager : public G4ToolsAnalysisManager
static constexpr std::string_view fkClass { "G4GenericAnalysisManager" };
// Data members
std::unique_ptr<G4GenericAnalysisMessenger> fMessenger;
std::shared_ptr<G4GenericFileManager> fFileManager { nullptr };
// add G4GenericNtupleManager
// this class will be analogic to file managers but with ntuples
@@ -66,13 +66,7 @@ inline void G4GenericAnalysisManager::SetBasketEntries(
}
//_____________________________________________________________________________
inline void G4GenericAnalysisManager::SetDefaultFileType(const G4String& value)
{
fFileManager->SetDefaultFileType(value);
}
//_____________________________________________________________________________
inline G4String G4GenericAnalysisManager::GetDefaultFileType() const
inline G4String G4GenericAnalysisManager::GetDefaultFileTypeImpl() const
{
return fFileManager->GetDefaultFileType();
}
@@ -1,80 +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. *
// ********************************************************************
//
// The messenger class for G4GenericAnalysisManager.
// It implements command:
// - /analysis/setDefaultFileType
//
// Author: Ivana Hrivnacova, 18/10/2022 (ivana@ipno.in2p3.fr)
#ifndef G4GenericAnalysisMessenger_h
#define G4GenericAnalysisMessenger_h 1
#include "G4UImessenger.hh"
#include "globals.hh"
#include <memory>
class G4GenericAnalysisManager;
class G4UIcmdWithAString;
class G4GenericAnalysisMessenger : public G4UImessenger
{
public:
explicit G4GenericAnalysisMessenger(G4GenericAnalysisManager* manager);
G4GenericAnalysisMessenger() = delete;
~G4GenericAnalysisMessenger() override;
// Methods
void SetNewValue(G4UIcommand* command, G4String value) final;
private:
template <typename CMD>
std::unique_ptr<CMD> CreateCommand(
G4String name, G4String guidance, G4String paremeterName,
G4bool ommitable = false);
// Data members
G4GenericAnalysisManager* fManager { nullptr }; ///< Associated class
std::unique_ptr<G4UIcmdWithAString> fSetDefaultFileTypeCmd;
};
//_____________________________________________________________________________
template <typename CMD>
std::unique_ptr<CMD> G4GenericAnalysisMessenger::CreateCommand(
G4String name, G4String guidance, G4String paremeterName, G4bool ommitable)
{
G4String fullName = "/analysis/" + name;
auto command = std::make_unique<CMD>(fullName, this);
command->SetGuidance(guidance.c_str());
command->SetParameterName(paremeterName.c_str(), ommitable);
command->AvailableForStates(G4State_PreInit, G4State_Idle);
return command;
}
#endif
+1 -3
View File
@@ -6,16 +6,14 @@ geant4_add_module(G4analysisfac
G4AnalysisManager.hh
G4GenericAnalysisManager.hh
G4GenericAnalysisManager.icc
G4GenericAnalysisMessenger.hh
G4GenericFileManager.hh
G4GenericFileManager.icc
SOURCES
G4GenericAnalysisManager.cc
G4GenericAnalysisMessenger.cc
G4GenericFileManager.cc)
geant4_module_link_libraries(G4analysisfac
PUBLIC G4analysismng G4hntools G4globman G4intercoms
PUBLIC G4analysismng G4hntools G4globman
PRIVATE G4csv G4root G4xml)
# HDF5, if enabled
@@ -27,7 +27,6 @@
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4GenericAnalysisManager.hh"
#include "G4GenericAnalysisMessenger.hh"
#include "G4GenericFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
@@ -71,8 +70,6 @@ G4bool G4GenericAnalysisManager::IsInstance()
G4GenericAnalysisManager::G4GenericAnalysisManager()
: G4ToolsAnalysisManager("")
{
fMessenger = std::make_unique<G4GenericAnalysisMessenger>(this);
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
// File manager
@@ -179,6 +176,14 @@ G4bool G4GenericAnalysisManager::OpenFileImpl(const G4String& fileName)
return result;
}
//_____________________________________________________________________________
void G4GenericAnalysisManager::SetDefaultFileTypeImpl(const G4String& value)
{
G4VAnalysisManager::SetDefaultFileTypeImpl(value);
fFileManager->SetDefaultFileType(value);
}
//_____________________________________________________________________________
G4bool G4GenericAnalysisManager::WriteH1(G4int id, const G4String& fileName)
{
@@ -253,6 +258,7 @@ G4bool G4GenericAnalysisManager::WriteP1(G4int id, const G4String& fileName)
auto p1Name = GetP1Name(id);
return fFileManager->WriteTExtra<tools::histo::p1d>(fileName, p1d, p1Name);
}
//_____________________________________________________________________________
G4bool G4GenericAnalysisManager::WriteP2(G4int id, const G4String& fileName)
{
@@ -271,3 +277,17 @@ G4bool G4GenericAnalysisManager::WriteP2(G4int id, const G4String& fileName)
auto p2Name = GetP2Name(id);
return fFileManager->WriteTExtra<tools::histo::p2d>(fileName, p2d, p2Name);
}
//_____________________________________________________________________________
tools::ntuple_booking* G4GenericAnalysisManager::GetNtuple(
G4bool warn, G4bool onlyIfActive) const
{
return fNtupleBookingManager->GetNtuple(warn, onlyIfActive);
}
//_____________________________________________________________________________
tools::ntuple_booking* G4GenericAnalysisManager::GetNtuple(
G4int ntupleId, G4bool warn, G4bool onlyIfActive) const
{
return fNtupleBookingManager->GetNtuple(ntupleId, warn, onlyIfActive);
}
@@ -1,62 +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, 18/10/2022 (ivana@ipno.in2p3.fr)
#include "G4GenericAnalysisMessenger.hh"
#include "G4GenericAnalysisManager.hh"
#include "G4UIcmdWithAString.hh"
//_____________________________________________________________________________
G4GenericAnalysisMessenger::G4GenericAnalysisMessenger(G4GenericAnalysisManager* manager)
: fManager(manager)
{
fSetDefaultFileTypeCmd = CreateCommand<G4UIcmdWithAString>(
"setDefaultFileType", "Set default output file type", "DefaultFileType", false);
#ifdef TOOLS_USE_HDF5
fSetDefaultFileTypeCmd->SetCandidates("csv hdf5 root xml");
#else
fSetDefaultFileTypeCmd->SetCandidates("csv root xml");
#endif
}
//_____________________________________________________________________________
G4GenericAnalysisMessenger::~G4GenericAnalysisMessenger() = default;
//
//
// public functions
//
//_____________________________________________________________________________
void G4GenericAnalysisMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
{
if ( command == fSetDefaultFileTypeCmd.get() ) {
fManager->SetDefaultFileType(newValues);
return;
}
}
@@ -289,6 +289,9 @@ G4bool G4GenericFileManager::DeleteEmptyFiles()
result &= fileManager->DeleteEmptyFiles();
}
// Clear all saved file names in base file manager
G4BaseFileManager::ClearData();
Message(kVL3, "delete", "empty files", "", result);
return result;
@@ -68,8 +68,7 @@ void G4Hdf5NtupleManager::CreateTNtuple(
auto directory = std::get<2>(*ntupleFile);
auto basketSize = fFileManager->GetBasketSize();
// auto compressionLevel = fState.GetCompressionLevel();
auto compressionLevel = 0;
auto compressionLevel = fFileManager->GetCompressionLevel();
// Update ntuple name if cycle >0
auto ntupleBooking = ntupleDescription->GetNtupleBooking();
@@ -84,8 +83,6 @@ void G4Hdf5NtupleManager::CreateTNtuple(
ntupleDescription->SetNtuple(
new toolx::hdf5::ntuple(
G4cout, directory, ntupleBooking, compressionLevel, basketSize));
fNtupleVector.push_back(ntupleDescription->GetNtuple());
}
//_____________________________________________________________________________
@@ -45,7 +45,9 @@ G4bool G4MPIToolsManager::Send(
// pack objects
for (const auto& [ht, info] : hnVector) {
// skip sending if activation is enabled and HT is inactivated
if ( ( fState.GetIsActivation() && ( ! info->GetActivation() ) ) ) continue;
// or if histogram was deleted
if ( ( fState.GetIsActivation() && ( ! info->GetActivation() ) ) ||
( info->GetDeleted() ) ) continue;
// pack histogram for sending
// G4cout << "Packed " << i << "th T" << G4endl;
result &= fHmpi->pack(*ht);
@@ -102,8 +102,10 @@ inline G4bool G4PlotManager::PlotAndWrite(
G4String name = info->GetName();
// skip plotting if not selected for plotting or
// if activation is enabled and HT is inactivated
// or HT is delted
if ( ( ! plotting ) ||
( fState.GetIsActivation() && ( ! activation ) ) ) continue;
( fState.GetIsActivation() && ( ! activation ) ) ||
( info->GetDeleted() ) ) continue;
// plot this object
fViewer->plot(*ht);
@@ -35,28 +35,28 @@
//_____________________________________________________________________________
template <>
tools::histo::h1d* G4THnToolsManager<1, tools::histo::h1d>::CreateToolsHT(
tools::histo::h1d* G4THnToolsManager<kDim1, tools::histo::h1d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 1>& bins,
const std::array<G4HnDimensionInformation, 1>& hnInfo);
const std::array<G4HnDimension, kDim1>& bins,
const std::array<G4HnDimensionInformation, kDim1>& hnInfo);
//_____________________________________________________________________________
template <>
void G4THnToolsManager<1, tools::histo::h1d>::ConfigureToolsHT(
void G4THnToolsManager<kDim1, tools::histo::h1d>::ConfigureToolsHT(
tools::histo::h1d* ht,
const std::array<G4HnDimension, 1>& bins,
const std::array<G4HnDimensionInformation, 1>& hnInfo);
const std::array<G4HnDimension, kDim1>& bins,
const std::array<G4HnDimensionInformation, kDim1>& hnInfo);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<1, tools::histo::h1d>::FillHT(
G4bool G4THnToolsManager<kDim1, tools::histo::h1d>::FillHT(
tools::histo::h1d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 1>& value, G4double weight);
std::array<G4double, kDim1>& value, G4double weight);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<1, tools::histo::h1d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim1, tools::histo::h1d>::WriteOnAscii(
std::ofstream& output);
#endif
@@ -35,28 +35,28 @@
//_____________________________________________________________________________
template <>
tools::histo::h2d* G4THnToolsManager<2, tools::histo::h2d>::CreateToolsHT(
tools::histo::h2d* G4THnToolsManager<kDim2, tools::histo::h2d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 2>& bins,
const std::array<G4HnDimensionInformation, 2>& hnInfo);
const std::array<G4HnDimension, kDim2>& bins,
const std::array<G4HnDimensionInformation, kDim2>& hnInfo);
//_____________________________________________________________________________
template <>
void G4THnToolsManager<2, tools::histo::h2d>::ConfigureToolsHT(
void G4THnToolsManager<kDim2, tools::histo::h2d>::ConfigureToolsHT(
tools::histo::h2d* ht,
const std::array<G4HnDimension, 2>& bins,
const std::array<G4HnDimensionInformation, 2>& hnInfo);
const std::array<G4HnDimension, kDim2>& bins,
const std::array<G4HnDimensionInformation, kDim2>& hnInfo);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<2, tools::histo::h2d>::FillHT(
G4bool G4THnToolsManager<kDim2, tools::histo::h2d>::FillHT(
tools::histo::h2d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 2>& value, G4double weight);
std::array<G4double, kDim2>& value, G4double weight);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<2, tools::histo::h2d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim2, tools::histo::h2d>::WriteOnAscii(
std::ofstream& output);
#endif
@@ -35,28 +35,28 @@
//_____________________________________________________________________________
template <>
tools::histo::h3d* G4THnToolsManager<3, tools::histo::h3d>::CreateToolsHT(
tools::histo::h3d* G4THnToolsManager<kDim3, tools::histo::h3d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 3>& bins,
const std::array<G4HnDimensionInformation, 3>& hnInfo);
const std::array<G4HnDimension, kDim3>& bins,
const std::array<G4HnDimensionInformation, kDim3>& hnInfo);
//_____________________________________________________________________________
template <>
void G4THnToolsManager<3, tools::histo::h3d>::ConfigureToolsHT(
void G4THnToolsManager<kDim3, tools::histo::h3d>::ConfigureToolsHT(
tools::histo::h3d* ht,
const std::array<G4HnDimension, 3>& bins,
const std::array<G4HnDimensionInformation, 3>& hnInfo);
const std::array<G4HnDimension, kDim3>& bins,
const std::array<G4HnDimensionInformation, kDim3>& hnInfo);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<3, tools::histo::h3d>::FillHT(
G4bool G4THnToolsManager<kDim3, tools::histo::h3d>::FillHT(
tools::histo::h3d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 3>& value, G4double weight);
std::array<G4double, kDim3>& value, G4double weight);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<3, tools::histo::h3d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim3, tools::histo::h3d>::WriteOnAscii(
std::ofstream& output);
#endif
@@ -35,28 +35,28 @@
//_____________________________________________________________________________
template <>
tools::histo::p1d* G4THnToolsManager<2, tools::histo::p1d>::CreateToolsHT(
tools::histo::p1d* G4THnToolsManager<kDim2, tools::histo::p1d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 2>& bins,
const std::array<G4HnDimensionInformation, 2>& hnInfo);
const std::array<G4HnDimension, kDim2>& bins,
const std::array<G4HnDimensionInformation, kDim2>& hnInfo);
//_____________________________________________________________________________
template <>
void G4THnToolsManager<2, tools::histo::p1d>::ConfigureToolsHT(
void G4THnToolsManager<kDim2, tools::histo::p1d>::ConfigureToolsHT(
tools::histo::p1d* ht,
const std::array<G4HnDimension, 2>& bins,
const std::array<G4HnDimensionInformation, 2>& hnInfo);
const std::array<G4HnDimension, kDim2>& bins,
const std::array<G4HnDimensionInformation, kDim2>& hnInfo);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<2, tools::histo::p1d>::FillHT(
G4bool G4THnToolsManager<kDim2, tools::histo::p1d>::FillHT(
tools::histo::p1d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 2>& value, G4double weight);
std::array<G4double, kDim2>& value, G4double weight);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<2, tools::histo::p1d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim2, tools::histo::p1d>::WriteOnAscii(
std::ofstream& output);
#endif
@@ -35,30 +35,30 @@
//_____________________________________________________________________________
template <>
tools::histo::p2d* G4THnToolsManager<3, tools::histo::p2d>::CreateToolsHT(
tools::histo::p2d* G4THnToolsManager<kDim3, tools::histo::p2d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 3>& bins,
const std::array<G4HnDimensionInformation, 3>& hnInfo,
const std::array<G4HnDimension, kDim3>& bins,
const std::array<G4HnDimensionInformation, kDim3>& hnInfo,
std::string_view className);
//_____________________________________________________________________________
template <>
void G4THnToolsManager<3, tools::histo::p2d>::ConfigureToolsHT(
void G4THnToolsManager<kDim3, tools::histo::p2d>::ConfigureToolsHT(
tools::histo::p2d* ht,
const std::array<G4HnDimension, 3>& bins,
const std::array<G4HnDimensionInformation, 3>& hnInfo,
const std::array<G4HnDimension, kDim3>& bins,
const std::array<G4HnDimensionInformation, kDim3>& hnInfo,
std::string_view className);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<3, tools::histo::p2d>::FillHT(
G4bool G4THnToolsManager<kDim3, tools::histo::p2d>::FillHT(
tools::histo::p2d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 3>& value, G4double weight);
std::array<G4double, kDim3>& value, G4double weight);
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<3, tools::histo::p2d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim3, tools::histo::p2d>::WriteOnAscii(
std::ofstream& output);
#endif
@@ -39,8 +39,6 @@
#include "G4TP2ToolsManager.hh"
#include "globals.hh"
#include "G4THnToolsManager.hh" // make forward declaration if possible
#include "tools/histo/h1d"
#include "tools/histo/h2d"
#include "tools/histo/h3d"
@@ -51,6 +49,9 @@
class G4PlotManager;
template <unsigned int DIM, typename HT>
class G4THnToolsManager;
namespace tools {
namespace histo {
class hmpi;
@@ -26,6 +26,8 @@
#include "G4HnInformation.hh"
#include "G4THnToolsManager.hh"
//_____________________________________________________________________________
template <typename HT>
inline
@@ -38,7 +40,9 @@ G4bool G4ToolsAnalysisManager::WriteT(
auto activation = info->GetActivation();
// skip writing if activation is enabled and H1 is inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
// or if histogram was deleted
if ( ( fState.GetIsActivation() && ( ! activation ) ) ||
( info->GetDeleted() ) ) continue;
auto name = info->GetName();
auto fileName = info->GetFileName();
@@ -35,15 +35,14 @@
#include "G4THnManager.hh"
#include "globals.hh"
#include "G4THnToolsManager.hh" // TO DO: make forward declaration if possible
#include "tools/histo/h1d"
#include "tools/histo/h2d"
#include "tools/histo/h3d"
#include "tools/histo/p1d"
#include "tools/histo/p2d"
class G4P2ToolsManager;
template <unsigned int DIM, typename HT>
class G4THnToolsManager;
namespace tools {
namespace histo {
@@ -91,11 +90,11 @@ class G4ToolsAnalysisReader : public G4VAnalysisReader
static constexpr std::string_view fkClass { "G4ToolsAnalysisReader" };
// Data members
G4THnToolsManager<1, tools::histo::h1d>* fH1Manager { nullptr };
G4THnToolsManager<2, tools::histo::h2d>* fH2Manager { nullptr };
G4THnToolsManager<3, tools::histo::h3d>* fH3Manager { nullptr };
G4THnToolsManager<2, tools::histo::p1d>* fP1Manager { nullptr };
G4THnToolsManager<3, tools::histo::p2d>* fP2Manager { nullptr };
G4THnToolsManager<kDim1, tools::histo::h1d>* fH1Manager { nullptr };
G4THnToolsManager<kDim2, tools::histo::h2d>* fH2Manager { nullptr };
G4THnToolsManager<kDim3, tools::histo::h3d>* fH3Manager { nullptr };
G4THnToolsManager<kDim2, tools::histo::p1d>* fP1Manager { nullptr };
G4THnToolsManager<kDim3, tools::histo::p2d>* fP2Manager { nullptr };
};
#include "G4ToolsAnalysisReader.icc"
@@ -26,6 +26,8 @@
#include "G4AnalysisUtilities.hh"
#include "G4THnToolsManager.hh"
//_____________________________________________________________________________
template <typename HT>
inline
@@ -39,10 +39,10 @@ using namespace G4Analysis;
//_____________________________________________________________________________
template <>
tools::histo::h1d* G4THnToolsManager<1, tools::histo::h1d>::CreateToolsHT(
tools::histo::h1d* G4THnToolsManager<kDim1, tools::histo::h1d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 1>& bins,
const std::array<G4HnDimensionInformation, 1>& hnInfo)
const std::array<G4HnDimension, kDim1>& bins,
const std::array<G4HnDimensionInformation, kDim1>& hnInfo)
{
// Apply hn information to bins
auto newBins(bins[kX]);
@@ -57,10 +57,10 @@ tools::histo::h1d* G4THnToolsManager<1, tools::histo::h1d>::CreateToolsHT(
//_____________________________________________________________________________
template <>
void G4THnToolsManager<1, tools::histo::h1d>::ConfigureToolsHT(
void G4THnToolsManager<kDim1, tools::histo::h1d>::ConfigureToolsHT(
tools::histo::h1d* ht,
const std::array<G4HnDimension, 1>& bins,
const std::array<G4HnDimensionInformation, 1>& hnInfo)
const std::array<G4HnDimension, kDim1>& bins,
const std::array<G4HnDimensionInformation, kDim1>& hnInfo)
{
// Apply hn information to bins
auto newBins(bins[kX]);
@@ -76,9 +76,9 @@ void G4THnToolsManager<1, tools::histo::h1d>::ConfigureToolsHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<1, tools::histo::h1d>::FillHT(
G4bool G4THnToolsManager<kDim1, tools::histo::h1d>::FillHT(
tools::histo::h1d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 1>& value, G4double weight)
std::array<G4double, kDim1>& value, G4double weight)
{
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
@@ -93,7 +93,7 @@ G4bool G4THnToolsManager<1, tools::histo::h1d>::FillHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<1, tools::histo::h1d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim1, tools::histo::h1d>::WriteOnAscii(
std::ofstream& output)
{
// Write selected objects on ASCII file
@@ -107,8 +107,9 @@ G4bool G4THnToolsManager<1, tools::histo::h1d>::WriteOnAscii(
auto id = GetHnManager()->GetFirstId();
for (const auto& [h1, info] : *GetTHnVector()) {
if ( ! info->GetAscii() ) {
// skip writing if activation is enabled and H1 is inactivated
if ( (h1 == nullptr) || (! info->GetAscii()) ) {
// skip writing
// if h1 was deleted or writing ascii is not selected
id++;
continue;
}
@@ -39,10 +39,10 @@ using namespace G4Analysis;
//_____________________________________________________________________________
template <>
tools::histo::h2d* G4THnToolsManager<2, tools::histo::h2d>::CreateToolsHT(
tools::histo::h2d* G4THnToolsManager<kDim2, tools::histo::h2d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 2>& bins,
const std::array<G4HnDimensionInformation, 2>& hnInfo)
const std::array<G4HnDimension, kDim2>& bins,
const std::array<G4HnDimensionInformation, kDim2>& hnInfo)
{
// Apply hn information to bins
auto newXBins(bins[kX]);
@@ -62,10 +62,10 @@ tools::histo::h2d* G4THnToolsManager<2, tools::histo::h2d>::CreateToolsHT(
//_____________________________________________________________________________
template <>
void G4THnToolsManager<2, tools::histo::h2d>::ConfigureToolsHT(
void G4THnToolsManager<kDim2, tools::histo::h2d>::ConfigureToolsHT(
tools::histo::h2d* ht,
const std::array<G4HnDimension, 2>& bins,
const std::array<G4HnDimensionInformation, 2>& hnInfo)
const std::array<G4HnDimension, kDim2>& bins,
const std::array<G4HnDimensionInformation, kDim2>& hnInfo)
{
// Apply hn information to bins
auto newXBins(bins[kX]);
@@ -86,9 +86,9 @@ void G4THnToolsManager<2, tools::histo::h2d>::ConfigureToolsHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<2, tools::histo::h2d>::FillHT(
G4bool G4THnToolsManager<kDim2, tools::histo::h2d>::FillHT(
tools::histo::h2d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 2>& value, G4double weight)
std::array<G4double, kDim2>& value, G4double weight)
{
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
auto yInfo = hnInformation.GetHnDimensionInformation(kY);
@@ -105,7 +105,7 @@ G4bool G4THnToolsManager<2, tools::histo::h2d>::FillHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<2, tools::histo::h2d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim2, tools::histo::h2d>::WriteOnAscii(
std::ofstream& output)
{
// Write selected objects on ASCII file
@@ -119,8 +119,9 @@ G4bool G4THnToolsManager<2, tools::histo::h2d>::WriteOnAscii(
auto id = GetHnManager()->GetFirstId();
for (const auto& [h2, info] : *GetTHnVector()) {
if ( ! info->GetAscii() ) {
// skip writing if activation is enabled and H1 is inactivated
if ( (h2 == nullptr) || (! info->GetAscii()) ) {
// skip writing
// if h2 was deleted or writing ascii is not selected
id++;
continue;
}
@@ -39,10 +39,10 @@ using namespace G4Analysis;
//_____________________________________________________________________________
template <>
tools::histo::h3d* G4THnToolsManager<3, tools::histo::h3d>::CreateToolsHT(
tools::histo::h3d* G4THnToolsManager<kDim3, tools::histo::h3d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 3>& bins,
const std::array<G4HnDimensionInformation, 3>& hnInfo)
const std::array<G4HnDimension, kDim3>& bins,
const std::array<G4HnDimensionInformation, kDim3>& hnInfo)
{
// Apply hn information to bins
auto newXBins(bins[kX]);
@@ -67,10 +67,10 @@ tools::histo::h3d* G4THnToolsManager<3, tools::histo::h3d>::CreateToolsHT(
//_____________________________________________________________________________
template <>
void G4THnToolsManager<3, tools::histo::h3d>::ConfigureToolsHT(
void G4THnToolsManager<kDim3, tools::histo::h3d>::ConfigureToolsHT(
tools::histo::h3d* ht,
const std::array<G4HnDimension, 3>& bins,
const std::array<G4HnDimensionInformation, 3>& hnInfo)
const std::array<G4HnDimension, kDim3>& bins,
const std::array<G4HnDimensionInformation, kDim3>& hnInfo)
{
// Apply hn information to bins
auto newXBins(bins[kX]);
@@ -95,9 +95,9 @@ void G4THnToolsManager<3, tools::histo::h3d>::ConfigureToolsHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<3, tools::histo::h3d>::FillHT(
G4bool G4THnToolsManager<kDim3, tools::histo::h3d>::FillHT(
tools::histo::h3d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 3>& value, G4double weight)
std::array<G4double, kDim3>& value, G4double weight)
{
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
auto yInfo = hnInformation.GetHnDimensionInformation(kY);
@@ -116,7 +116,7 @@ G4bool G4THnToolsManager<3, tools::histo::h3d>::FillHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<3, tools::histo::h3d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim3, tools::histo::h3d>::WriteOnAscii(
std::ofstream& output)
{
// Write selected objects on ASCII file
@@ -130,8 +130,9 @@ G4bool G4THnToolsManager<3, tools::histo::h3d>::WriteOnAscii(
auto id = GetHnManager()->GetFirstId();
for (const auto& [h3, info] : *GetTHnVector()) {
if ( ! info->GetAscii() ) {
// skip writing if activation is enabled and H1 is inactivated
if ( (h3 == nullptr) || (! info->GetAscii()) ) {
// skip writing
// if h3 was deleted or writing ascii is not selected
id++;
continue;
}
@@ -39,10 +39,10 @@ using namespace G4Analysis;
//_____________________________________________________________________________
template <>
tools::histo::p1d* G4THnToolsManager<2, tools::histo::p1d>::CreateToolsHT(
tools::histo::p1d* G4THnToolsManager<kDim2, tools::histo::p1d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 2>& bins,
const std::array<G4HnDimensionInformation, 2>& hnInfo)
const std::array<G4HnDimension, kDim2>& bins,
const std::array<G4HnDimensionInformation, kDim2>& hnInfo)
{
// Apply hn information to bins
auto newXBins(bins[kX]);
@@ -70,10 +70,10 @@ tools::histo::p1d* G4THnToolsManager<2, tools::histo::p1d>::CreateToolsHT(
//_____________________________________________________________________________
template <>
void G4THnToolsManager<2, tools::histo::p1d>::ConfigureToolsHT(
void G4THnToolsManager<kDim2, tools::histo::p1d>::ConfigureToolsHT(
tools::histo::p1d* ht,
const std::array<G4HnDimension, 2>& bins,
const std::array<G4HnDimensionInformation, 2>& hnInfo)
const std::array<G4HnDimension, kDim2>& bins,
const std::array<G4HnDimensionInformation, kDim2>& hnInfo)
{
// Apply hn information to bins
auto newXBins(bins[kX]);
@@ -103,9 +103,9 @@ void G4THnToolsManager<2, tools::histo::p1d>::ConfigureToolsHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<2, tools::histo::p1d>::FillHT(
G4bool G4THnToolsManager<kDim2, tools::histo::p1d>::FillHT(
tools::histo::p1d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 2>& value, G4double weight)
std::array<G4double, kDim2>& value, G4double weight)
{
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
auto yInfo = hnInformation.GetHnDimensionInformation(kY);
@@ -122,7 +122,7 @@ G4bool G4THnToolsManager<2, tools::histo::p1d>::FillHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<2, tools::histo::p1d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim2, tools::histo::p1d>::WriteOnAscii(
std::ofstream& output)
{
// Write selected objects on ASCII file
@@ -134,8 +134,9 @@ G4bool G4THnToolsManager<2, tools::histo::p1d>::WriteOnAscii(
auto id = GetHnManager()->GetFirstId();
for (const auto& [p1, info] : *GetTHnVector()) {
if ( ! info->GetAscii() ) {
// skip writing if activation is enabled and H1 is inactivated
if ( (p1 == nullptr) || (! info->GetAscii()) ) {
// skip writing
// if p1 was deleted or writing ascii is not selected
id++;
continue;
}
@@ -39,10 +39,10 @@ using namespace G4Analysis;
//_____________________________________________________________________________
template <>
tools::histo::p2d* G4THnToolsManager<3, tools::histo::p2d>::CreateToolsHT(
tools::histo::p2d* G4THnToolsManager<kDim3, tools::histo::p2d>::CreateToolsHT(
const G4String& title,
const std::array<G4HnDimension, 3>& bins,
const std::array<G4HnDimensionInformation, 3>& hnInfo)
const std::array<G4HnDimension, kDim3>& bins,
const std::array<G4HnDimensionInformation, kDim3>& hnInfo)
{
// Apply hn information to bins
auto newXBins(bins[kX]);
@@ -74,10 +74,10 @@ tools::histo::p2d* G4THnToolsManager<3, tools::histo::p2d>::CreateToolsHT(
//_____________________________________________________________________________
template <>
void G4THnToolsManager<3, tools::histo::p2d>::ConfigureToolsHT(
void G4THnToolsManager<kDim3, tools::histo::p2d>::ConfigureToolsHT(
tools::histo::p2d* ht,
const std::array<G4HnDimension, 3>& bins,
const std::array<G4HnDimensionInformation, 3>& hnInfo)
const std::array<G4HnDimension, kDim3>& bins,
const std::array<G4HnDimensionInformation, kDim3>& hnInfo)
{
// Apply hn information to bins
auto newXBins(bins[kX]);
@@ -113,9 +113,9 @@ void G4THnToolsManager<3, tools::histo::p2d>::ConfigureToolsHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<3, tools::histo::p2d>::FillHT(
G4bool G4THnToolsManager<kDim3, tools::histo::p2d>::FillHT(
tools::histo::p2d* ht, const G4HnInformation& hnInformation,
std::array<G4double, 3>& value, G4double weight)
std::array<G4double, kDim3>& value, G4double weight)
{
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
auto yInfo = hnInformation.GetHnDimensionInformation(kY);
@@ -134,7 +134,7 @@ G4bool G4THnToolsManager<3, tools::histo::p2d>::FillHT(
//_____________________________________________________________________________
template <>
G4bool G4THnToolsManager<3, tools::histo::p2d>::WriteOnAscii(
G4bool G4THnToolsManager<kDim3, tools::histo::p2d>::WriteOnAscii(
std::ofstream& output)
{
// Write selected objects on ASCII file
@@ -146,8 +146,9 @@ G4bool G4THnToolsManager<3, tools::histo::p2d>::WriteOnAscii(
auto id = GetHnManager()->GetFirstId();
for (const auto& [p2, info] : *GetTHnVector()) {
if ( ! info->GetAscii() ) {
// skip writing if activation is enabled and H1 is inactivated
if ( (p2 == nullptr) || (! info->GetAscii()) ) {
// skip writing
// if p2 was deleted or writing ascii is not selected
id++;
continue;
}
@@ -33,11 +33,11 @@ G4ToolsAnalysisReader::G4ToolsAnalysisReader(const G4String& type)
: G4VAnalysisReader(type)
{
// Create managers
fH1Manager = new G4THnToolsManager<1, tools::histo::h1d>(fState);
fH2Manager = new G4THnToolsManager<2, tools::histo::h2d>(fState);
fH3Manager = new G4THnToolsManager<3, tools::histo::h3d>(fState);
fP1Manager = new G4THnToolsManager<2, tools::histo::p1d>(fState);
fP2Manager = new G4THnToolsManager<3, tools::histo::p2d>(fState);
fH1Manager = new G4THnToolsManager<kDim1, tools::histo::h1d>(fState);
fH2Manager = new G4THnToolsManager<kDim2, tools::histo::h2d>(fState);
fH3Manager = new G4THnToolsManager<kDim3, tools::histo::h3d>(fState);
fP1Manager = new G4THnToolsManager<kDim2, tools::histo::p1d>(fState);
fP2Manager = new G4THnToolsManager<kDim3, tools::histo::p2d>(fState);
// The managers will be deleted by the base class
// Set managers to base class which takes then their ownership
@@ -62,12 +62,12 @@ class G4AnalysisManagerState
// get methods
G4String GetType() const;
G4String GetFileType() const;
G4bool GetIsMaster() const;
G4int GetThreadId() const;
G4bool GetIsActivation() const;
G4int GetVerboseLevel() const;
G4bool IsVerbose(G4int verboseLevel) const;
G4int GetCompressionLevel() const;
G4int GetCycle() const;
private:
@@ -75,7 +75,6 @@ class G4AnalysisManagerState
// (hidden from all clients except for G4VAnalysisManager friend)
void SetIsActivation(G4bool isActivation);
void SetVerboseLevel(G4int verboseLevel);
void SetCompressionLevel(G4int level);
// Static data members
static constexpr std::string_view fkClass { "G4AnalysisManagerState" };
@@ -86,7 +85,6 @@ class G4AnalysisManagerState
G4int fThreadId { G4Threading::SEQUENTIAL_ID };
G4bool fIsActivation { false };
G4int fVerboseLevel { 0 };
G4int fCompressionLevel { 1 };
G4int fCycle { 0 };
G4AnalysisVerbose fVerbose;
};
@@ -96,9 +94,6 @@ class G4AnalysisManagerState
inline void G4AnalysisManagerState::SetIsActivation(G4bool isActivation)
{ fIsActivation = isActivation; }
inline void G4AnalysisManagerState::SetCompressionLevel(G4int level)
{ fCompressionLevel = level; }
inline void G4AnalysisManagerState::IncrementCycle()
{ ++fCycle; }
@@ -108,6 +103,9 @@ inline void G4AnalysisManagerState::ResetCycle()
inline G4String G4AnalysisManagerState::GetType() const
{ return fType; }
inline G4String G4AnalysisManagerState::GetFileType() const
{ return G4StrUtil::to_lower_copy(fType); }
inline G4bool G4AnalysisManagerState::GetIsMaster() const
{ return fIsMaster; }
@@ -123,9 +121,6 @@ inline G4int G4AnalysisManagerState::GetVerboseLevel() const
inline G4bool G4AnalysisManagerState::IsVerbose(G4int verboseLevel) const
{ return fVerboseLevel == verboseLevel; }
inline G4int G4AnalysisManagerState::GetCompressionLevel() const
{ return fCompressionLevel; }
inline G4int G4AnalysisManagerState::GetCycle() const
{ return fCycle; }
@@ -87,6 +87,7 @@ class G4AnalysisMessenger : public G4UImessenger
// To be investigated
std::unique_ptr<G4UIcmdWithABool> fCloseFileCmd;
std::unique_ptr<G4UIcmdWithABool> fListCmd;
std::unique_ptr<G4UIcmdWithAString> fSetDefaultFileTypeCmd;
std::unique_ptr<G4UIcmdWithABool> fSetActivationCmd;
std::unique_ptr<G4UIcmdWithAnInteger> fVerboseCmd;
std::unique_ptr<G4UIcmdWithAnInteger> fCompressionCmd;
@@ -60,8 +60,12 @@ 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 unsigned int kDim1 { 1 };
constexpr unsigned int kDim2 { 2 };
constexpr unsigned int kDim3 { 3 };
constexpr unsigned int kMaxDim { kDim3 };
constexpr unsigned int kDefaultBasketSize { 32000 };
constexpr unsigned int kDefaultBasketEntries {4000 };
constexpr std::string_view kNamespaceName { "G4Analysis" };
// Warning
@@ -43,6 +43,8 @@ class G4BaseFileManager
G4BaseFileManager() = delete;
virtual ~G4BaseFileManager() = default;
void SetCompressionLevel(G4int level);
// Set the compression level
virtual G4bool SetFileName(const G4String& fileName);
// Set the base file name (without extension)
virtual G4String GetFileType() const;
@@ -56,6 +58,8 @@ class G4BaseFileManager
// For handling multiple files
// Save file name in a vector if not yet present
G4int GetCompressionLevel() const;
// Return the compression level
G4String GetFileName() const;
// Return the base file name (without extension)
G4String GetFullFileName(const G4String& baseFileName = "",
@@ -103,12 +107,19 @@ class G4BaseFileManager
const G4String& objectName = "",
G4bool success = true) const;
// Clear data
void ClearData();
// Data members
const G4AnalysisManagerState& fState;
G4int fCompressionLevel { 1 };
G4String fFileName; // to be changed in fDefaultFileName
std::vector<G4String> fFileNames;
};
inline void G4BaseFileManager::SetCompressionLevel(G4int level)
{ fCompressionLevel = level; }
inline G4bool G4BaseFileManager::SetFileName(const G4String& fileName) {
// CHECK if still needed in this base class
fFileName = fileName;
@@ -119,6 +130,9 @@ inline G4bool G4BaseFileManager::HasCycles() const {
return false;
}
inline G4int G4BaseFileManager::GetCompressionLevel() const
{ return fCompressionLevel; }
inline G4String G4BaseFileManager::GetFileName() const {
return fFileName;
}
@@ -134,4 +148,8 @@ inline void G4BaseFileManager::Message(
fState.Message(level, action, objectType, objectName, success);
}
inline void G4BaseFileManager::ClearData() {
fFileNames.clear();
}
#endif
@@ -113,6 +113,18 @@ class G4HnInformation
// Deleted default constructor
G4HnInformation() = delete;
// Clear all data
void Update(const G4HnInformation& other) {
// Update all information except name and fHnDimensionInformations
for (G4int i = 0; i < (G4int)fHnDimensionInformations.size(); ++i) {
SetIsLogAxis(i, other.GetIsLogAxis(i));
}
fActivation = other.GetActivation();
fAscii = other.GetAscii();
fPlotting = other.GetPlotting();
fFileName = other.GetFileName();
}
// Set methods
void AddDimension(const G4HnDimensionInformation& hnDimensionInformation);
void SetDimension(G4int dimension, const G4HnDimensionInformation& hnDimensionInformation);
@@ -121,6 +133,7 @@ class G4HnInformation
void SetActivation(G4bool activation);
void SetAscii(G4bool ascii);
void SetPlotting(G4bool plotting);
void SetDeleted(G4bool deleted, G4bool keepSetting);
void SetFileName(const G4String& fileName);
// Get methods
@@ -131,6 +144,8 @@ class G4HnInformation
G4bool GetActivation() const;
G4bool GetAscii() const;
G4bool GetPlotting() const;
G4bool GetDeleted() const;
std::pair<G4bool, G4bool> GetDeletedPair() const;
G4String GetFileName() const;
private:
@@ -141,6 +156,7 @@ class G4HnInformation
G4bool fActivation { true };
G4bool fAscii { false };
G4bool fPlotting { false };
std::pair<G4bool, G4bool> fDeleted { false, false };
G4String fFileName;
};
@@ -190,6 +206,9 @@ inline void G4HnInformation::SetAscii(G4bool ascii)
inline void G4HnInformation::SetPlotting(G4bool plotting)
{ fPlotting = plotting; }
inline void G4HnInformation::SetDeleted(G4bool deleted, G4bool keepSetting)
{ fDeleted = std::make_pair(deleted, keepSetting); }
inline void G4HnInformation::SetFileName(const G4String& fileName)
{ fFileName = fileName; }
@@ -214,6 +233,12 @@ inline G4bool G4HnInformation::GetAscii() const
inline G4bool G4HnInformation::GetPlotting() const
{ return fPlotting; }
inline G4bool G4HnInformation::GetDeleted() const
{ return fDeleted.first; }
inline std::pair<G4bool, G4bool> G4HnInformation::GetDeletedPair() const
{ return fDeleted; }
inline G4String G4HnInformation::GetFileName() const
{ return fFileName; }
@@ -37,6 +37,7 @@
#include "G4HnInformation.hh"
#include "globals.hh"
#include <set>
#include <string_view>
#include <utility>
#include <vector>
@@ -51,10 +52,13 @@ class G4HnManager : public G4BaseAnalysisManager
G4HnManager() = delete;
~G4HnManager() override;
void CreateMessenger();
// Methods to manipulate additional information
void AddHnInformation(G4HnInformation* info);
void AddHnInformation(G4HnInformation* info, G4int index);
G4HnInformation* AddHnInformation(const G4String& name, G4int nofDimensions);
void SetHnDeleted(G4HnInformation* info, G4bool keepSetting);
void ClearData();
// Access methofd
@@ -68,7 +72,6 @@ class G4HnManager : public G4BaseAnalysisManager
G4bool warn = true) const;
const std::vector<G4HnInformation*>& GetHnVector() const;
G4int GetNofHns() const;
G4int GetNofActiveHns() const;
G4String GetHnType() const;
@@ -115,6 +118,7 @@ class G4HnManager : public G4BaseAnalysisManager
G4String GetFileName(G4int id) const;
void SetFileManager(std::shared_ptr<G4VFileManager> fileManager);
void SetDefaultFileType(const G4String& fileType);
private:
// Methods
@@ -127,6 +131,7 @@ class G4HnManager : public G4BaseAnalysisManager
// Data members
G4String fHnType;
G4String fDefaultFileType;
G4int fNofActiveObjects { 0 };
G4int fNofAsciiObjects { 0 };
G4int fNofPlottingObjects { 0 };
@@ -134,15 +139,13 @@ class G4HnManager : public G4BaseAnalysisManager
// Additional histograms/ntuple properties not included in tools
std::vector<G4HnInformation*> fHnVector;
std::set<G4int> fFreeIds;
std::shared_ptr<G4VFileManager> fFileManager { nullptr };
// Messenger
std::unique_ptr<G4HnMessenger> fMessenger;
};
inline G4int G4HnManager::GetNofHns() const
{ return G4int(fHnVector.size()); }
inline G4int G4HnManager::GetNofActiveHns() const
{ return fNofActiveObjects; }
@@ -157,5 +160,9 @@ inline void G4HnManager::SetFileManager(std::shared_ptr<G4VFileManager> fileMana
fFileManager = std::move(fileManager);
}
#endif
inline void G4HnManager::SetDefaultFileType(const G4String& fileType)
{
fDefaultFileType = fileType;
}
#endif
@@ -67,6 +67,7 @@ class G4HnMessenger : public G4UImessenger
void SetHnPlottingToAllCmd();
void SetHnFileNameCmd();
void SetHnFileNameToAllCmd();
std::unique_ptr<G4UIcommand> CreateSetAxisLogCommand(unsigned int ibin);
// constants
static constexpr std::string_view fkClass { "G4HnMessenger" };
@@ -74,6 +75,7 @@ class G4HnMessenger : public G4UImessenger
// Data members
G4HnManager& fManager; ///< Associated class
G4String fHnType;
unsigned int fHnDimension;
std::unique_ptr<G4UIcommand> fSetAsciiCmd;
std::unique_ptr<G4UIcommand> fSetActivationCmd;
std::unique_ptr<G4UIcmdWithABool> fSetActivationAllCmd;
@@ -81,6 +83,7 @@ class G4HnMessenger : public G4UImessenger
std::unique_ptr<G4UIcmdWithABool> fSetPlottingAllCmd;
std::unique_ptr<G4UIcommand> fSetFileNameCmd;
std::unique_ptr<G4UIcmdWithAString> fSetFileNameAllCmd;
std::vector<std::unique_ptr<G4UIcommand>> fSetAxisLogCmd;
};
//_____________________________________________________________________________
@@ -37,18 +37,35 @@
#include "tools/ntuple_booking"
#include <vector>
#include <set>
#include <string_view>
#include <vector>
struct G4NtupleBooking
{
G4NtupleBooking() = default;
~G4NtupleBooking() = default;
void SetDeleted(G4bool deleted, G4bool keepSetting) {
fDeleted = std::make_pair(deleted, keepSetting);
}
G4bool GetDeleted() const {
return fDeleted.first;
}
void Reset() {
if (! fDeleted.second) {
// Reset information unless "keepSetting" option is true
fFileName.clear();
fActivation = true;
}
SetDeleted(false, false);
}
tools::ntuple_booking fNtupleBooking;
G4int fNtupleId { G4Analysis::kInvalidId };
G4String fFileName;
G4bool fActivation { true };
std::pair<G4bool, G4bool> fDeleted { false, false };
};
class G4NtupleBookingManager : public G4BaseAnalysisManager
@@ -70,6 +87,12 @@ class G4NtupleBookingManager : public G4BaseAnalysisManager
G4String GetFileType() const;
G4bool IsEmpty() const;
// Access methods
tools::ntuple_booking* GetNtuple(G4bool warn,
G4bool onlyIfActive) const;
tools::ntuple_booking* GetNtuple(G4int ntupleId, G4bool warn,
G4bool onlyIfActive) const;
protected:
// Methods to create ntuples
//
@@ -116,14 +139,20 @@ class G4NtupleBookingManager : public G4BaseAnalysisManager
G4String GetFileName(G4int id) const;
// Access methods
G4int GetNofNtupleBookings() const;
// G4int GetNofNtuples() const;
G4int GetNofNtuples(G4bool onlyIfExist = false) const;
// Clear data
void ClearData();
// Method to delete selected ntuples
G4bool Delete(G4int id, G4bool keepSetting);
// List ntuples
G4bool List(std::ostream& output, G4bool onlyIfActive = true);
// Data members
std::vector<G4NtupleBooking*> fNtupleBookingVector;
std::set<G4int> fFreeIds;
private:
// Methods
@@ -146,6 +175,7 @@ class G4NtupleBookingManager : public G4BaseAnalysisManager
G4String fFileType;
G4int fFirstNtupleColumnId { 0 };
G4bool fLockFirstNtupleColumnId { false };
G4int fCurrentNtupleId { G4Analysis::kInvalidId };
};
#include "G4NtupleBookingManager.icc"
@@ -66,15 +66,16 @@ G4int G4NtupleBookingManager::CreateNtupleTColumn(
}
//_____________________________________________________________________________
inline G4int G4NtupleBookingManager::GetNofNtupleBookings() const
inline G4int G4NtupleBookingManager::GetNofNtuples(G4bool onlyIfExist) const
{
return G4int(fNtupleBookingVector.size());
return (onlyIfExist) ? G4int(fNtupleBookingVector.size() - fFreeIds.size())
: G4int(fNtupleBookingVector.size());
}
//_____________________________________________________________________________
inline G4int G4NtupleBookingManager::GetCurrentNtupleId() const
{
return GetNofNtupleBookings() + fFirstId - 1;
return fCurrentNtupleId;
}
//
@@ -34,9 +34,11 @@
#ifndef G4NtupleMessenger_h
#define G4NtupleMessenger_h 1
#include "G4AnalysisUtilities.hh"
#include "G4UImessenger.hh"
#include "globals.hh"
#include <map>
#include <memory>
#include <string_view>
@@ -61,6 +63,10 @@ class G4NtupleMessenger : public G4UImessenger
std::unique_ptr<CMD> CreateCommand(G4String name, G4String guidance);
void AddIdParameter(G4UIcommand& command);
void CreateCmd();
void CreateColumnCmds();
void FinishCmd();
void DeleteCmd();
void SetActivationCmd();
void SetActivationToAllCmd();
void SetFileNameCmd();
@@ -74,11 +80,16 @@ class G4NtupleMessenger : public G4UImessenger
G4VAnalysisManager* fManager { nullptr }; ///< Associated class
std::unique_ptr<G4UIdirectory> fNtupleDir;
std::unique_ptr<G4UIcommand> fCreateCmd;
std::map<char, std::unique_ptr<G4UIcommand>> fCreateColumnCmds;
std::unique_ptr<G4UIcommand> fFinishCmd;
std::unique_ptr<G4UIcommand> fDeleteCmd;
std::unique_ptr<G4UIcommand> fSetActivationCmd;
std::unique_ptr<G4UIcmdWithABool> fSetActivationAllCmd;
std::unique_ptr<G4UIcommand> fSetFileNameCmd;
std::unique_ptr<G4UIcmdWithAString> fSetFileNameAllCmd;
std::unique_ptr<G4UIcommand> fListCmd;
G4int fTmpNtupleId { G4Analysis::kInvalidId };
};
//_____________________________________________________________________________
@@ -168,19 +168,11 @@ template <typename FT>
inline
std::shared_ptr<FT> G4TFileManager<FT>::CreateTFile(const G4String& fileName)
{
// Check if file already exists
if ( GetFileInFunction(fileName, "CreateTFile", false) ) {
// Do not issue the warning if cycle > 0
if (fAMState.GetCycle() == 0) {
G4Analysis::Warn("File " + fileName + " already exists.",
fkClass, "CreateTFile");
return nullptr;
}
else {
return GetFileInFunction(fileName, "CreateTFile", false);
// should we also update fileInformation ??
}
// Just return the file if it already exists
if ( auto file = GetFileInFunction(fileName, "CreateTFile", false);
file != nullptr ) {
return file;
// should we also update fileInformation ??
}
auto fileInformation = GetFileInfoInFunction(fileName, "CreateTFile", false);
@@ -39,6 +39,7 @@
#include <vector>
#include <map>
#include <memory>
#include <set>
#include <string_view>
class G4AnalysisManagerState;
@@ -61,6 +62,9 @@ class G4THnManager
// Clear data
void ClearData();
// Delete selected object
G4bool DeleteT(G4int id, G4bool keepSetting);
// Return true if the H1 vector is empty
G4bool IsEmpty() const;
@@ -79,6 +83,7 @@ class G4THnManager
const std::vector<HT*>& GetTVectorRef() const;
std::vector<std::pair<HT*, G4HnInformation*>>* GetTHnVector();
const std::vector<std::pair<HT*, G4HnInformation*>>& GetTHnVectorRef() const;
G4int GetNofHns(G4bool onlyIfExist) const;
// Methods to list/print histograms
G4bool List(std::ostream& output, G4bool onlyIfActive) const;
@@ -117,6 +122,7 @@ class G4THnManager
const G4AnalysisManagerState& fState;
std::vector<HT*> fTVector;
std::vector<std::pair<HT*, G4HnInformation*>> fTHnVector;
std::set<G4int> fFreeIds;
std::map<G4String, G4int> fNameIdMap;
std::shared_ptr<G4HnManager> fHnManager { nullptr };
};
@@ -130,11 +130,16 @@ void G4THnManager<HT>::AddTVector(const std::vector<HT*>& tVector)
// }
auto itw = tVector.begin();
for ( auto t : fTVector ) {
// skip deleted histograms
if (t == nullptr) {
itw++;
continue;
}
t->add(*(*itw));
(*itw++)->reset();
}
Message(G4Analysis::kVL1, "merge", "all " + fHnManager->GetHnType());
Message(G4Analysis::kVL2, "merge", "all " + fHnManager->GetHnType());
}
//_____________________________________________________________________________
@@ -183,9 +188,29 @@ typename std::vector<HT*>::const_iterator G4THnManager<HT>::EndConstT() const
template <typename HT>
G4int G4THnManager<HT>::RegisterT(const G4String& name, HT* ht, G4HnInformation* info)
{
G4int index = (G4int)fTVector.size();
fTVector.push_back(ht);
fTHnVector.push_back({ht, info});
G4int index = 0;
if (fFreeIds.empty()) {
index = (G4int)fTVector.size();
fTVector.push_back(ht);
fTHnVector.push_back({ht, info});
fHnManager->AddHnInformation(info);
}
else {
// Get the first freed Id
index = *(fFreeIds.begin()) - fHnManager->GetFirstId();
// Update vectors at the first freed Id position
fTVector[index] = ht;
// Register new information at the freed Id position
fHnManager->AddHnInformation(info, index);
// Register new histo & inforrmation at the freed Id position
fTHnVector[index] = {ht, info};
// Remove the id from the set
fFreeIds.erase(fFreeIds.begin());
}
fHnManager->SetLockFirstId(true);
fNameIdMap[name] = index + fHnManager->GetFirstId();
@@ -201,6 +226,8 @@ G4bool G4THnManager<HT>::Reset()
auto result = true;
for ( auto t : fTVector ) {
// skip deleted histograms
if ( t == nullptr) continue;
result &= t->reset();
}
@@ -227,6 +254,30 @@ G4THnManager<HT>::ClearData()
Message(G4Analysis::kVL2, "clear", G4Analysis::GetHnType<HT>());
}
//_____________________________________________________________________________
template <typename HT>
G4bool
G4THnManager<HT>::DeleteT(G4int id, G4bool keepSetting)
{
auto [ht, info] = GetTHnInFunction(id, "Delete", true, false);
if (ht == nullptr) return false;
// Delete histogram and update vectors
delete ht;
auto index = id - fHnManager->GetFirstId();
fTVector[index] = nullptr;
fTHnVector[index] = std::make_pair(nullptr, info);
// Update information
fHnManager->SetHnDeleted(info, keepSetting);
// Register freed Id
fFreeIds.insert(id);
return true;
}
//_____________________________________________________________________________
template <typename HT>
G4bool G4THnManager<HT>::IsEmpty() const
@@ -269,6 +320,15 @@ const std::vector<std::pair<HT*, G4HnInformation*>>& G4THnManager<HT>::GetTHnVec
return fTHnVector;
}
//_____________________________________________________________________________
template <typename HT>
G4int G4THnManager<HT>::GetNofHns(G4bool onlyIfExist) const
{
return (onlyIfExist) ? G4int(fTVector.size() - fFreeIds.size())
: G4int(fTVector.size());
}
//_____________________________________________________________________________
template <typename HT>
G4bool G4THnManager<HT>::List(std::ostream& output, G4bool onlyIfActive) const
@@ -279,7 +339,7 @@ G4bool G4THnManager<HT>::List(std::ostream& output, G4bool onlyIfActive) const
// List general info
output << fHnManager->GetHnType() << ": " << fHnManager->GetNofActiveHns() << " active ";
if (! onlyIfActive) {
output << " of " << fHnManager->GetNofHns() << " defined ";
output << " of " << GetNofHns(true) << " defined ";
}
output << G4endl;
@@ -288,6 +348,8 @@ G4bool G4THnManager<HT>::List(std::ostream& output, G4bool onlyIfActive) const
size_t maxTitleLength = 0;
size_t maxEntries = 0;
for ( const auto& [ht, hnInfo] : fTHnVector) {
// skip deleletd objects
if (ht == nullptr) continue;
if (hnInfo->GetName().length() > maxNameLength) {
maxNameLength = hnInfo->GetName().length();
}
@@ -307,9 +369,9 @@ G4bool G4THnManager<HT>::List(std::ostream& output, G4bool onlyIfActive) const
// List objects
auto id = fHnManager->GetFirstId();
for (const auto& [ht, hnInfo] : fTHnVector) {
// skip inactivated objects
if (fState.GetIsActivation() && onlyIfActive && (! hnInfo->GetActivation())) {
// skip deleted or inactivated objects
if ( (fState.GetIsActivation() && onlyIfActive && (! hnInfo->GetActivation())) ||
(hnInfo->GetDeleted()) ) {
id++;
continue;
}
@@ -33,9 +33,6 @@
#define G4THnMessenger_h 1
#include "G4UImessenger.hh"
// #include "G4THnToolsManager.hh"
// to avoid include recursion this messenger header is included in G4THnToolsManager.hh
// after the G4THnToolsManager class definition
#include "globals.hh"
#include <memory>
@@ -49,6 +46,9 @@ class G4UIcommand;
struct G4HnDimension;
struct G4HnDimensionInformation;
template <unsigned int DIM, typename HT>
class G4THnToolsManager;
template <unsigned int DIM, typename HT>
class G4THnMessenger : public G4UImessenger
{
@@ -76,10 +76,10 @@ class G4THnMessenger : public G4UImessenger
void CreateDirectory() const;
void CreateCmd();
void SetCmd();
void DeleteCmd();
std::unique_ptr<G4UIcommand> CreateSetBinsCommand(unsigned int ibin);
void CreateSetTitleCommand();
std::unique_ptr<G4UIcommand> CreateSetAxisCommand(unsigned int ibin);
std::unique_ptr<G4UIcommand> CreateSetAxisLogCommand(unsigned int ibin);
void CreateListCommand();
void CreateGetCommand();
void CreateGetVectorCommand();
@@ -95,18 +95,17 @@ class G4THnMessenger : public G4UImessenger
std::array<G4HnDimensionInformation, DIM>& info) const;
// constants
static constexpr unsigned int kMaxDim{3};
static constexpr std::string_view fkClass { "G4THnMessenger" };
// Data members
G4THnToolsManager<DIM,HT>* fManager { nullptr }; ///< TO DO Associated class
G4THnToolsManager<DIM,HT>* fManager { nullptr }; ///< Associated class
std::unique_ptr<G4UIcommand> fCreateCmd;
std::unique_ptr<G4UIcommand> fSetCmd;
std::unique_ptr<G4UIcommand> fDeleteCmd;
std::array<std::unique_ptr<G4UIcommand>, DIM> fSetDimensionCmd;
std::unique_ptr<G4UIcommand> fSetTitleCmd;
std::array<std::unique_ptr<G4UIcommand>, DIM+1> fSetAxisCmd;
std::array<std::unique_ptr<G4UIcommand>, DIM+1> fSetAxisLogCmd;
std::unique_ptr<G4UIcommand> fListCmd;
std::unique_ptr<G4UIcommand> fGetTCmd;
std::unique_ptr<G4UIcommand> fGetTVectorCmd;
@@ -50,11 +50,13 @@ G4THnMessenger<DIM, HT>::G4THnMessenger(G4THnToolsManager<DIM, HT>* manager)
fSetDimensionCmd[idim] = CreateSetBinsCommand(idim);
}
DeleteCmd();
CreateSetTitleCommand();
for (unsigned int idim = 0; idim < DIM + 1; ++idim) {
auto maxDim = (DIM < kMaxDim) ? DIM + 1 : kMaxDim;
for (unsigned int idim = 0; idim < maxDim; ++idim) {
fSetAxisCmd[idim] = CreateSetAxisCommand(idim);
fSetAxisLogCmd[idim] = CreateSetAxisLogCommand(idim);
}
CreateListCommand();
@@ -181,12 +183,6 @@ void G4THnMessenger<DIM, HT>::CreateDimensionParameters(
template <unsigned int DIM, typename HT>
void G4THnMessenger<DIM, HT>::AddIdParameter(G4UIcommand& command)
{
// update guidance
// // TO DO: this will add a new guidance as a new line !!
// auto guidance = command.GetGuidanceLine(0);
// guidance += " of given id";
// command.SetGuidance(guidance);
// add parameter
auto htId = new G4UIparameter("id", 'i', false);
htId->SetGuidance("Histogram id");
@@ -281,6 +277,25 @@ void G4THnMessenger<DIM, HT>::SetCmd()
}
}
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
void G4THnMessenger<DIM, HT>::DeleteCmd()
{
fDeleteCmd = CreateCommand("delete", "Delete ");
fDeleteCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
// Add Id parameter
AddIdParameter(*fDeleteCmd);
auto parKeepSetting = new G4UIparameter("keepSetting", 'b', true);
G4String guidance =
"If set true, activation, plotting, etc. options will be kept\n"
"and applied when a new object with the same id is created.";
parKeepSetting->SetGuidance(guidance.c_str());
parKeepSetting->SetDefaultValue("false");
fDeleteCmd->SetParameter(parKeepSetting);
}
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
std::unique_ptr<G4UIcommand>
@@ -358,31 +373,6 @@ G4THnMessenger<DIM, HT>::CreateSetAxisCommand(unsigned int idim)
return command;
}
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
std::unique_ptr<G4UIcommand>
G4THnMessenger<DIM, HT>::CreateSetAxisLogCommand(unsigned int idim)
{
G4String xyz{"XYZ"};
auto axis = xyz.substr(idim, 1);
G4String commandName = "set" + axis + "axisLog";
G4String guidance = "Activate " + axis + "-axis log scale for plotting of the ";
auto command = CreateCommand(commandName, guidance);
command->AvailableForStates(G4State_PreInit, G4State_Idle);
// Add Id parameter
AddIdParameter(*command);
auto parAxisLog = new G4UIparameter("axis", 'b', false);
guidance = GetObjectType() + " " + axis + "-axis log scale";
parAxisLog->SetGuidance(guidance.c_str());
command->SetParameter(parAxisLog);
return command;
}
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
void G4THnMessenger<DIM, HT>::CreateListCommand()
@@ -522,6 +512,14 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
return;
}
if ( command == fDeleteCmd.get() ) {
auto counter = 0;
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
auto keepSetting = G4UIcommand::ConvertToBool(parameters[counter++]);
fManager->Delete(id, keepSetting);
return;
}
if ( command == fSetTitleCmd.get() ) {
auto counter = 0;
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
@@ -547,7 +545,7 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
}
if ( idim == DIM - 1) {
// Apply parameters when all dimensions are set
fManager->Set(fTmpId[idim], bins, info);
fManager->Set(fTmpId[idim], fTmpBins, fTmpInfo);
return;
}
}
@@ -570,14 +568,6 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
fManager->SetAxisTitle(idim, id, axisTitle);
return;
}
if ( command == fSetAxisLogCmd[idim].get() ) {
// TO DO: this should go in HnMessenger
auto counter = 0;
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
auto axisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
fManager->GetHnManager()->SetAxisIsLog(idim, id, axisLog);
return;
}
}
if ( command == fListCmd.get() ) {
@@ -31,6 +31,7 @@
#ifndef G4THnToolsManager_h
#define G4THnToolsManager_h 1
#include "G4AnalysisUtilities.hh"
#include "G4VTBaseHnManager.hh"
#include "G4THnManager.hh"
#include "globals.hh"
@@ -70,6 +71,7 @@ class G4THnToolsManager : public G4VTBaseHnManager<DIM>,
const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
virtual G4bool Scale(G4int id, G4double factor) override;
virtual G4int GetNofHns(G4bool onlyIfExist) const override;
// Methods to fill histograms
virtual G4bool Fill(G4int id, std::array<G4double, DIM> value, G4double weight = 1.0) override;
@@ -96,6 +98,9 @@ class G4THnToolsManager : public G4VTBaseHnManager<DIM>,
// Function with specialization per histo type
virtual G4bool List(std::ostream& output, G4bool onlyIfActive = true) override;
// Methods to delete selected histograms
virtual G4bool Delete(G4int id, G4bool keepSetting) override;
// // Access to Hn manager
virtual std::shared_ptr<G4HnManager> GetHnManager() override;
virtual const std::shared_ptr<G4HnManager> GetHnManager() const override;
@@ -115,7 +120,7 @@ class G4THnToolsManager : public G4VTBaseHnManager<DIM>,
void UpdateInformation(G4HnInformation* hnInformation,
const std::array<G4HnDimensionInformation, DIM>& hnInfo);
G4HnInformation* AddInformation(const G4String& name,
G4HnInformation* CreateInformation(const G4String& name,
const std::array<G4HnDimensionInformation, DIM>& hnInfo);
void AddAnnotation(HT* ht,
@@ -138,7 +143,7 @@ class G4THnToolsManager : public G4VTBaseHnManager<DIM>,
G4double weight = 1.0);
// redefine tools::histo::key_axis_x_title() - not available via upper types
static const std::array<std::string, 3> fkKeyAxisTitle;
static const std::array<std::string, G4Analysis::kMaxDim> fkKeyAxisTitle;
std::unique_ptr<G4UImessenger> fMessenger;
};
@@ -31,6 +31,7 @@
using G4Analysis::kX;
using G4Analysis::kY;
using G4Analysis::kZ;
using G4Analysis::kMaxDim;
using G4Analysis::CheckDimensions;
using G4Analysis::GetHnType;
using G4Analysis::IsProfile;
@@ -38,7 +39,7 @@ using G4Analysis::Warn;
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
const std::array<std::string, 3> G4THnToolsManager<DIM, HT>::fkKeyAxisTitle =
const std::array<std::string, kMaxDim> G4THnToolsManager<DIM, HT>::fkKeyAxisTitle =
{ "axis_x.title", "axis_y.title", "axis_z.title" };
//_____________________________________________________________________________
@@ -47,6 +48,7 @@ G4THnToolsManager<DIM, HT>::G4THnToolsManager(const G4AnalysisManagerState& stat
: G4THnManager<HT>(state)
{
fMessenger = std::make_unique<G4THnMessenger<DIM, HT>>(this);
GetHnManager()->CreateMessenger();
}
//_____________________________________________________________________________
@@ -61,10 +63,10 @@ void G4THnToolsManager<DIM, HT>::UpdateInformation(G4HnInformation* hnInformatio
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
G4HnInformation* G4THnToolsManager<DIM, HT>::AddInformation(const G4String& name,
G4HnInformation* G4THnToolsManager<DIM, HT>::CreateInformation(const G4String& name,
const std::array<G4HnDimensionInformation, DIM>& hnInfo)
{
auto hnInformation = GetHnManager()->AddHnInformation(name, DIM);
auto hnInformation = new G4HnInformation(name, DIM);
for (unsigned int idim = 0; idim < DIM; ++idim) {
hnInformation->AddDimension(hnInfo[idim]);
}
@@ -117,10 +119,10 @@ G4int G4THnToolsManager<DIM, HT>::Create(
// Add annotation
AddAnnotation(ht, hnInfo);
// Save hn information
auto info = AddInformation(name, hnInfo);
// Create Hn information
auto info = CreateInformation(name, hnInfo);
// Register histogram
// Register histogram & info
auto id = RegisterT(name, ht, info);
Message(G4Analysis::kVL2, "create", GetHnType<HT>(), name);
@@ -175,7 +177,12 @@ G4bool G4THnToolsManager<DIM, HT>::Fill(G4int id,
std::array<G4double, DIM> value, G4double weight)
{
auto [ht, info] = GetTHnInFunction(id, "Fill"+ GetHnType<HT>(), true, false);
if (ht == nullptr) return false;
if (ht == nullptr) {
Warn("Failed to fill " + GetHnType<HT>() + " id " + std::to_string(id) +
". Histogram does not exist.", fkClass, "Fill");
return false;
}
if ( G4THnManager<HT>::fState.GetIsActivation() && ( ! info->GetActivation() ) ) {
return false;
@@ -209,6 +216,12 @@ G4int G4THnToolsManager<DIM, HT>::GetId(const G4String& name, G4bool warn) cons
return GetTId(name, warn);
}
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
G4int G4THnToolsManager<DIM, HT>::GetNofHns(G4bool onlyIfExist) const
{
return G4THnManager<HT>::GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
@@ -317,6 +330,20 @@ G4bool G4THnToolsManager<DIM, HT>::List(std::ostream& output, G4bool onlyIfActiv
return G4THnManager<HT>::List(output, onlyIfActive);
}
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
G4bool G4THnToolsManager<DIM, HT>::Delete(G4int id, G4bool keepSetting)
{
G4String message = " id " + to_string(id);
Message(G4Analysis::kVL4, "delete", GetHnType<HT>(), message);
auto result = G4THnManager<HT>::DeleteT(id, keepSetting);
Message(G4Analysis::kVL2, "delete", GetHnType<HT>(), message, result);
return result;
}
//_____________________________________________________________________________
template <unsigned int DIM, typename HT>
std::shared_ptr<G4HnManager> G4THnToolsManager<DIM, HT>::GetHnManager() {
@@ -35,8 +35,6 @@
#include "G4NtupleBookingManager.hh"
#include "globals.hh"
#include "tools/ntuple_booking"
#include <fstream>
template <typename NT, typename FT>
@@ -44,9 +42,7 @@ class G4TNtupleDescription
{
public:
G4TNtupleDescription(G4NtupleBooking* g4NtupleBooking)
: fNtupleBooking(g4NtupleBooking->fNtupleBooking),
fFileName(g4NtupleBooking->fFileName),
fActivation(g4NtupleBooking->fActivation)
: fG4NtupleBooking(g4NtupleBooking)
{}
G4TNtupleDescription() = delete;
@@ -67,7 +63,9 @@ class G4TNtupleDescription
// Get methods
std::shared_ptr<FT> GetFile() const;
NT* GetNtuple() const;
G4NtupleBooking* GetG4NtupleBooking() const;
const tools::ntuple_booking& GetNtupleBooking() const;
G4String GetFileName() const;
G4bool GetActivation() const;
G4bool GetIsNtupleOwner() const;
@@ -76,9 +74,7 @@ class G4TNtupleDescription
private:
std::shared_ptr<FT> fFile { nullptr };
NT* fNtuple { nullptr };
tools::ntuple_booking fNtupleBooking;
G4String fFileName;
G4bool fActivation { true };
G4NtupleBooking* fG4NtupleBooking { nullptr };
G4bool fIsNtupleOwner { true };
G4bool fHasFill { false };
};
@@ -95,11 +91,11 @@ void G4TNtupleDescription<NT, FT>::SetNtuple(NT* ntuple)
template <typename NT, typename FT>
void G4TNtupleDescription<NT, FT>::SetFileName(const G4String& fileName)
{ fFileName = fileName; }
{ fG4NtupleBooking->fFileName = fileName; }
template <typename NT, typename FT>
void G4TNtupleDescription<NT, FT>::SetActivation(G4bool activation)
{ fActivation = activation; }
{ fG4NtupleBooking->fActivation = activation; }
template <typename NT, typename FT>
void G4TNtupleDescription<NT, FT>::SetIsNtupleOwner(G4bool isNtupleOwner)
@@ -124,18 +120,23 @@ template <typename NT, typename FT>
NT* G4TNtupleDescription<NT, FT>::GetNtuple() const
{ return fNtuple; }
template <typename NT, typename FT>
G4NtupleBooking*
G4TNtupleDescription<NT, FT>::GetG4NtupleBooking() const
{ return fG4NtupleBooking; }
template <typename NT, typename FT>
const tools::ntuple_booking&
G4TNtupleDescription<NT, FT>::GetNtupleBooking() const
{ return fNtupleBooking; }
{ return fG4NtupleBooking->fNtupleBooking; }
template <typename NT, typename FT>
G4String G4TNtupleDescription<NT, FT>::GetFileName() const
{ return fFileName; }
{ return fG4NtupleBooking->fFileName; }
template <typename NT, typename FT>
G4bool G4TNtupleDescription<NT, FT>::GetActivation() const
{ return fActivation; }
{ return fG4NtupleBooking->fActivation; }
template <typename NT, typename FT>
G4bool G4TNtupleDescription<NT, FT>::GetIsNtupleOwner() const
@@ -57,6 +57,9 @@ class G4TNtupleManager : public G4BaseNtupleManager {
virtual G4bool Reset();
void Clear() override;
// Method to delete selected ntuple
G4bool Delete(G4int id) override;
// Methods to create ntuples
// are implemented in G4NtupleBookingManager base class
@@ -87,10 +90,6 @@ class G4TNtupleManager : public G4BaseNtupleManager {
// Access methods
NT* GetNtuple() const;
NT* GetNtuple(G4int ntupleId) const;
G4int GetNofNtuples() const final;
// List ntuples
G4bool List(std::ostream& output, G4bool onlyIfActive = true) final;
// Iterators
typename std::vector<NT*>::iterator BeginNtuple();
@@ -92,7 +92,7 @@ template <typename T>
G4bool G4TNtupleManager<NT, FT>::FillNtupleTColumn(
G4int ntupleId, G4int columnId, const T& value)
{
if (fNewCycle && fNtupleVector.empty()) {
if (fNewCycle) {
CreateNtuplesFromBooking(*fNtupleBookingVector);
fNewCycle = false;
}
@@ -168,20 +168,28 @@ G4int G4TNtupleManager<NT, FT>::CreateNtuple(G4NtupleBooking* ntupleBooking)
}
// Do not create ntuple if it is inactivated
if ( fState.GetIsActivation() &&
( ! ntupleDescription->GetActivation() ) ) return G4Analysis::kInvalidId;
// or if it was deleted
if ( ( ntupleBooking->GetDeleted() ) ||
( fState.GetIsActivation() &&
( ! ntupleDescription->GetActivation() ) ) ) return G4Analysis::kInvalidId;
// Do not create ntuple if it already exists
if ( ntupleDescription->GetNtuple() != nullptr ) {
G4Analysis::Warn(
"Ntuple " + to_string(ntupleBooking->fNtupleId) +
" already exists.", fkClass, "CreateNtuple");
return ntupleBooking->fNtupleId;
}
// create ntuple
// Create ntuple
CreateTNtupleFromBooking(ntupleDescription);
// Update ntuple vector if ntuple was created
if ( ntupleDescription->GetNtuple() != nullptr ) {
// Allocate the ntuple vector element(s) if needed
while ( index >= G4int(fNtupleVector.size()) ) {
fNtupleVector.push_back(nullptr);
}
fNtupleVector[index] = ntupleDescription->GetNtuple();
}
// finish created ntuple
auto fromBooking = true;
FinishTNtuple(ntupleDescription, fromBooking);
@@ -243,6 +251,38 @@ G4TNtupleManager<NT, FT>::Clear()
Message(G4Analysis::kVL2, "clear", "ntuples");
}
//_____________________________________________________________________________
template <typename NT, typename FT>
G4bool
G4TNtupleManager<NT, FT>::Delete(G4int id)
{
if ( IsVerbose(G4Analysis::kVL4) ) {
Message(G4Analysis::kVL4, "delete", "ntuple ntupleId " + to_string(id));
}
auto ntupleDescription = GetNtupleDescriptionInFunction(id, "Delete", true);
if (ntupleDescription == nullptr) return false;
// Delete ntuple and update ntuple description
delete ntupleDescription->GetNtuple();
ntupleDescription->SetNtuple(nullptr);
// ntupleDescription->SetDeleted(true, keepSetting);
// Update ntuple vector
if (! fNtupleVector.empty()) {
auto index = id - GetFirstId();
fNtupleVector[index] = nullptr;
}
// Register freed Id
// fFreeIds.insert(id);
Message(G4Analysis::kVL2, "delete", "ntuple ntupleId " + to_string(id));
return true;
}
//_____________________________________________________________________________
template <typename NT, typename FT>
G4bool G4TNtupleManager<NT, FT>::FillNtupleIColumn(
@@ -408,76 +448,3 @@ G4TNtupleManager<NT, FT>::EndConstNtuple() const
{
return fNtupleVector.end();
}
//_____________________________________________________________________________
template <typename NT, typename FT>
G4int G4TNtupleManager<NT, FT>::GetNofNtuples() const
{
return G4int(fNtupleVector.size());
}
//_____________________________________________________________________________
template <typename NT, typename FT>
G4bool G4TNtupleManager<NT, FT>::List(std::ostream& output, G4bool onlyIfActive)
{
// Save current output stream formatting
std::ios_base::fmtflags outputFlags(output.flags() );
// Define optimal field widths
size_t maxNameLength = 0;
size_t maxTitleLength = 0;
// size_t maxEntries = 0;
size_t nofActive = 0;
for (size_t i = 0; i < fNtupleDescriptionVector.size(); ++i) {
// auto ntuple = fNtupleVector[i];
const auto& ntupleBooking = fNtupleDescriptionVector[i]->GetNtupleBooking();
if (ntupleBooking.name().length() > maxNameLength) {
maxNameLength = ntupleBooking.name().length();
}
if (ntupleBooking.title().length() > maxTitleLength) {
maxTitleLength = ntupleBooking.title().length();
}
// if (ntuple->entries() > maxEntries) {
// maxEntries = ntuple->entries();
// }
if (fNtupleDescriptionVector[i]->GetActivation()) {
++nofActive;
}
}
size_t maxIdWidth = std::to_string(fNtupleVector.size() + GetFirstId()).length();
// size_t maxEntriesWidth = std::to_string(maxEntries).length();
// update string width for adde double quotas
maxNameLength += 2;
maxTitleLength += 2;
// List general info
output << "Ntuple: " << nofActive << " active ";
if (! onlyIfActive) {
output << " of " << GetNofNtuples() << " defined ";
}
output << G4endl;
// List objects
for (size_t i = 0; i < fNtupleDescriptionVector.size(); ++i) {
// auto ntuple = fNtupleVector[i];
const auto& ntupleBooking = fNtupleDescriptionVector[i]->GetNtupleBooking();
// skip inactivated objcets
if (fState.GetIsActivation() && onlyIfActive && (! fNtupleDescriptionVector[i]->GetActivation())) continue;
// print selected info
output << " id: " << std::setw((G4int)maxIdWidth) << GetFirstId() + i
<< " name: \"" << std::setw((G4int)maxNameLength) << std::left << ntupleBooking.name() + "\""
<< " title: \"" << std::setw((G4int)maxTitleLength) << std::left << ntupleBooking.title() + "\"";
// << " entries: " << std::setw((G4int)maxEntriesWidth) << ntuple->entries();
if (! onlyIfActive) {
output << " active: " << std::boolalpha << fNtupleDescriptionVector[i]->GetActivation();
}
output << G4endl;
}
// Restore the output stream formatting
output.flags(outputFlags);
return output.good();
}
@@ -38,6 +38,7 @@
#define G4VAnalysisManager_h 1
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
#include "globals.hh"
#include <vector>
@@ -60,6 +61,10 @@ class hmpi;
}
}
using G4Analysis::kDim1;
using G4Analysis::kDim2;
using G4Analysis::kDim3;
class G4VAnalysisManager
{
friend class G4AnalysisMessenger;
@@ -77,6 +82,10 @@ class G4VAnalysisManager
G4bool Plot();
G4bool IsOpenFile() const;
// Method for handling default file type
void SetDefaultFileType(const G4String& value);
G4String GetDefaultFileType() const;
// Methods for handling files and directories names
G4bool SetFileName(const G4String& fileName);
G4bool SetHistoDirectoryName(const G4String& dirName);
@@ -405,12 +414,12 @@ class G4VAnalysisManager
G4int GetFirstNtupleId() const;
G4int GetFirstNtupleColumnId() const;
G4int GetNofH1s() const;
G4int GetNofH2s() const;
G4int GetNofH3s() const;
G4int GetNofP1s() const;
G4int GetNofP2s() const;
G4int GetNofNtuples() const;
G4int GetNofH1s(G4bool onlyIfExist = false) const;
G4int GetNofH2s(G4bool onlyIfExist = false) const;
G4int GetNofH3s(G4bool onlyIfExist = false) const;
G4int GetNofP1s(G4bool onlyIfExist = false) const;
G4int GetNofP2s(G4bool onlyIfExist = false) const;
G4int GetNofNtuples(G4bool onlyIfExist = false) const;
// Access methods via names
G4int GetH1Id(const G4String& name, G4bool warn = true) const;
@@ -631,6 +640,15 @@ class G4VAnalysisManager
G4bool GetP2YAxisIsLog(G4int id) const;
G4bool GetP2ZAxisIsLog(G4int id) const;
// New methods for deleting selected objects
//
G4bool DeleteH1(G4int id, G4bool keepSetting = false);
G4bool DeleteH2(G4int id, G4bool keepSetting = false);
G4bool DeleteH3(G4int id, G4bool keepSetting = false);
G4bool DeleteP1(G4int id, G4bool keepSetting = false);
G4bool DeleteP2(G4int id, G4bool keepSetting = false);
G4bool DeleteNtuple(G4int id, G4bool clear = false);
// Verbosity
void SetVerboseLevel(G4int verboseLevel);
G4int GetVerboseLevel() const;
@@ -653,6 +671,10 @@ class G4VAnalysisManager
virtual G4bool PlotImpl() = 0;
virtual G4bool MergeImpl(tools::histo::hmpi* hmpi) = 0;
virtual G4bool IsOpenFileImpl() const = 0;
// Set default output type (backward compatibility)
// this type will be used for file names without extension
virtual void SetDefaultFileTypeImpl(const G4String& value);
virtual G4String GetDefaultFileTypeImpl() const;
// Methods
void Message(G4int level,
@@ -662,11 +684,11 @@ class G4VAnalysisManager
G4bool success = true) const;
// Methods
void SetH1Manager(G4VTBaseHnManager<1>* h1Manager);
void SetH2Manager(G4VTBaseHnManager<2>* h2Manager);
void SetH3Manager(G4VTBaseHnManager<3>* h3Manager);
void SetP1Manager(G4VTBaseHnManager<2>* p1Manager);
void SetP2Manager(G4VTBaseHnManager<3>* p2Manager);
void SetH1Manager(G4VTBaseHnManager<kDim1>* h1Manager);
void SetH2Manager(G4VTBaseHnManager<kDim2>* h2Manager);
void SetH3Manager(G4VTBaseHnManager<kDim3>* h3Manager);
void SetP1Manager(G4VTBaseHnManager<kDim2>* p1Manager);
void SetP2Manager(G4VTBaseHnManager<kDim3>* p2Manager);
void SetNtupleManager(std::shared_ptr<G4VNtupleManager> ntupleManager);
void SetNtupleFileManager(std::shared_ptr<G4VNtupleFileManager> ntupleFileManager);
void SetFileManager(std::shared_ptr<G4VFileManager> fileManager);
@@ -677,11 +699,6 @@ class G4VAnalysisManager
// File manager access
virtual std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName);
// Static data members
static constexpr unsigned int kDim1 { 1 };
static constexpr unsigned int kDim2 { 2 };
static constexpr unsigned int kDim3 { 3 };
// Data members
G4AnalysisManagerState fState;
std::shared_ptr<G4VFileManager> fVFileManager { nullptr };
@@ -1177,5 +1177,5 @@ G4String G4VAnalysisManager::GetType() const
inline
G4String G4VAnalysisManager::GetFileType() const
{
return fVFileManager->GetFileType();
return fState.GetFileType();
}
@@ -38,6 +38,7 @@
#define G4VAnalysisReader_h 1
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
#include "globals.hh"
#include "G4VTBaseHnManager.hh" // make forward declaration if possible
@@ -50,6 +51,10 @@ class G4HnManager;
class G4VRNtupleManager;
class G4VRFileManager;
using G4Analysis::kDim1;
using G4Analysis::kDim2;
using G4Analysis::kDim3;
class G4VAnalysisReader
{
public:
@@ -128,11 +133,11 @@ class G4VAnalysisReader
G4bool IsAscii() const;
// Access methods
G4int GetNofH1s() const;
G4int GetNofH2s() const;
G4int GetNofH3s() const;
G4int GetNofP1s() const;
G4int GetNofP2s() const;
G4int GetNofH1s(G4bool onlyIfExist = false) const;
G4int GetNofH2s(G4bool onlyIfExist = false) const;
G4int GetNofH3s(G4bool onlyIfExist = false) const;
G4int GetNofP1s(G4bool onlyIfExist = false) const;
G4int GetNofP2s(G4bool onlyIfExist = false) const;
G4int GetNofNtuples() const;
// Access methods via names
@@ -247,11 +252,11 @@ class G4VAnalysisReader
G4bool success = true) const;
// Methods
void SetH1Manager(G4VTBaseHnManager<1>* h1Manager);
void SetH2Manager(G4VTBaseHnManager<2>* h2Manager);
void SetH3Manager(G4VTBaseHnManager<3>* h3Manager);
void SetP1Manager(G4VTBaseHnManager<2>* p1Manager);
void SetP2Manager(G4VTBaseHnManager<3>* p2Manager);
void SetH1Manager(G4VTBaseHnManager<kDim1>* h1Manager);
void SetH2Manager(G4VTBaseHnManager<kDim2>* h2Manager);
void SetH3Manager(G4VTBaseHnManager<kDim3>* h3Manager);
void SetP1Manager(G4VTBaseHnManager<kDim2>* p1Manager);
void SetP2Manager(G4VTBaseHnManager<kDim3>* p2Manager);
void SetNtupleManager(std::shared_ptr<G4VRNtupleManager> ntupleManager);
void SetFileManager(std::shared_ptr<G4VRFileManager> fileManager);
@@ -266,11 +271,11 @@ class G4VAnalysisReader
static constexpr std::string_view fkClass { "G4VAnalysisReader" };
// Data members
std::unique_ptr<G4VTBaseHnManager<1>> fVH1Manager;
std::unique_ptr<G4VTBaseHnManager<2>> fVH2Manager;
std::unique_ptr<G4VTBaseHnManager<3>> fVH3Manager;
std::unique_ptr<G4VTBaseHnManager<2>> fVP1Manager;
std::unique_ptr<G4VTBaseHnManager<3>> fVP2Manager;
std::unique_ptr<G4VTBaseHnManager<kDim1>> fVH1Manager;
std::unique_ptr<G4VTBaseHnManager<kDim2>> fVH2Manager;
std::unique_ptr<G4VTBaseHnManager<kDim3>> fVH3Manager;
std::unique_ptr<G4VTBaseHnManager<kDim2>> fVP1Manager;
std::unique_ptr<G4VTBaseHnManager<kDim3>> fVP2Manager;
std::shared_ptr<G4VRNtupleManager> fVNtupleManager { nullptr };
};
@@ -84,18 +84,14 @@ class G4VNtupleManager : public G4BaseAnalysisManager
virtual void SetNewCycle(G4bool value) = 0;
virtual G4bool GetNewCycle() const = 0;
// Access methods
virtual G4int GetNofNtuples() const = 0;
// virtual G4int GetNofNtupleBookings() const = 0;
// Set first column Id
virtual G4bool SetFirstNtupleColumnId(G4int firstId) = 0;
// Clear all date
virtual void Clear() = 0;
// List ntuples
virtual G4bool List(std::ostream& output, G4bool onlyIfActive = true) = 0;
// Methods to delete selected ntuples
virtual G4bool Delete(G4int id) = 0;
};
#endif
@@ -79,6 +79,7 @@ class G4VTBaseHnManager
// Access methods
virtual G4int GetId(const G4String& name, G4bool warn = true) const = 0;
virtual G4int GetNofHns(G4bool onlyExisting) const = 0;
// Access to bins parameters
virtual G4int GetNbins(unsigned int idim, G4int id) const = 0;
@@ -98,6 +99,9 @@ class G4VTBaseHnManager
virtual G4bool WriteOnAscii(std::ofstream& output) = 0;
virtual G4bool List(std::ostream& output, G4bool onlyIfActive = true) = 0;
// Methods to delete selected histograms
virtual G4bool Delete(G4int id, G4bool keepSetting) = 0;
virtual std::shared_ptr<G4HnManager> GetHnManager() = 0;
virtual const std::shared_ptr<G4HnManager> GetHnManager() const = 0;
};
@@ -140,7 +140,12 @@ template <typename FT>
inline
G4bool G4VTFileManager<FT>::DeleteEmptyFiles()
{
return G4TFileManager<FT>::DeleteEmptyFiles();
auto result = G4TFileManager<FT>::DeleteEmptyFiles();
// clean-up also all stored information about file names
Clear();
return result;
}
//_____________________________________________________________________________
@@ -149,6 +154,7 @@ inline
void G4VTFileManager<FT>::Clear()
{
G4TFileManager<FT>::ClearData();
G4BaseFileManager::ClearData();
UnlockDirectoryNames();
}
@@ -67,6 +67,14 @@ G4AnalysisMessenger::G4AnalysisMessenger(G4VAnalysisManager* manager)
"list", "List all/activate analysis objects.", "OnlyIfActive", true);
fListCmd->SetDefaultValue(true);
fSetDefaultFileTypeCmd = CreateCommand<G4UIcmdWithAString>(
"setDefaultFileType", "Set default output file type", "DefaultFileType", false);
#ifdef TOOLS_USE_HDF5
fSetDefaultFileTypeCmd->SetCandidates("csv hdf5 root xml");
#else
fSetDefaultFileTypeCmd->SetCandidates("csv root xml");
#endif
fSetActivationCmd = CreateCommand<G4UIcmdWithABool>(
"setActivation",
"Set activation. \n"
@@ -150,6 +158,11 @@ void G4AnalysisMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
return;
}
if ( command == fSetDefaultFileTypeCmd.get() ) {
fManager->SetDefaultFileType(newValues);
return;
}
if ( command == fSetActivationCmd.get() ) {
fManager->SetActivation(fSetActivationCmd->GetNewBoolValue(newValues));
return;
@@ -56,7 +56,7 @@ void G4BaseFileManager::AddFileName(const G4String& fileName)
//_____________________________________________________________________________
G4String G4BaseFileManager::GetFileType() const
{
return G4StrUtil::to_lower_copy(fState.GetType());
return fState.GetFileType();
}
//_____________________________________________________________________________
+62 -9
View File
@@ -40,9 +40,7 @@ using std::to_string;
//_____________________________________________________________________________
G4HnManager::G4HnManager(G4String hnType, const G4AnalysisManagerState& state)
: G4BaseAnalysisManager(state), fHnType(std::move(hnType))
{
fMessenger = std::make_unique<G4HnMessenger>(*this);
}
{}
//_____________________________________________________________________________
G4HnManager::~G4HnManager()
@@ -96,10 +94,28 @@ void G4HnManager::SetFileName(G4HnInformation* info, const G4String& fileName)
// Do nothing if file name does not change
if ( info->GetFileName() == fileName ) return;
auto hnFileName = fileName;
auto extension = GetExtension(fileName);
if (extension.size() != 0u) {
// Check if valid extension (if present)
auto output = G4Analysis::GetOutput(extension);
if ( output == G4AnalysisOutput::kNone ) {
Warn("The file extension " + extension + " is not supported.",
fkClass, "SetFileName");
return;
}
}
else {
if (fDefaultFileType.size() != 0u) {
//add extension if missing and file type is defined
hnFileName = fileName + "." + fDefaultFileType;
}
}
// Save the info and account a new file name if file manager
info->SetFileName(fileName);
info->SetFileName(hnFileName);
if (fFileManager) {
fFileManager->AddFileName(fileName);
fFileManager->AddFileName(hnFileName);
} else {
Warn("Failed to set fileName " + fileName +
" for object " + info->GetName() + ".\nFile manager is not set.",
@@ -107,7 +123,7 @@ void G4HnManager::SetFileName(G4HnInformation* info, const G4String& fileName)
return;
}
if ( fileName != "" ) {
if ( hnFileName != "" ) {
fNofFileNameObjects++;
} else {
fNofFileNameObjects--;
@@ -119,13 +135,50 @@ void G4HnManager::SetFileName(G4HnInformation* info, const G4String& fileName)
//
//_____________________________________________________________________________
G4HnInformation* G4HnManager::AddHnInformation(const G4String& name, G4int nofDimensions)
void G4HnManager::CreateMessenger()
{
auto info = new G4HnInformation(name, nofDimensions);
fMessenger = std::make_unique<G4HnMessenger>(*this);
}
//_____________________________________________________________________________
void G4HnManager::AddHnInformation(G4HnInformation* info)
{
// Add new information
fHnVector.push_back(info);
++fNofActiveObjects;
}
return info;
//_____________________________________________________________________________
void G4HnManager::AddHnInformation(G4HnInformation* info, G4int index)
{
// Replace the information at 'index' position with new one.
// Update new information with the previous one settings if the
// previous histogram was deleted with 'keepSetting' set true.
auto previousInfo = fHnVector[index];
if (previousInfo->GetDeletedPair().second) {
info->Update(*previousInfo);
}
delete previousInfo;
fHnVector[index] = info;
if (info->GetActivation()) { ++fNofActiveObjects; }
if (info->GetAscii()) { ++fNofAsciiObjects; }
if (info->GetPlotting()) { ++fNofPlottingObjects; }
if (! info->GetFileName().empty()) { ++fNofFileNameObjects; }
}
//_____________________________________________________________________________
void G4HnManager::SetHnDeleted(G4HnInformation* info, G4bool keepSetting)
{
info->SetDeleted(true, keepSetting);
if (info->GetActivation()) { --fNofActiveObjects; }
if (info->GetAscii()) { --fNofAsciiObjects; }
if (info->GetPlotting()) { --fNofPlottingObjects; }
if (! info->GetFileName().empty()) { --fNofFileNameObjects; }
}
//_____________________________________________________________________________
@@ -28,16 +28,20 @@
#include "G4HnMessenger.hh"
#include "G4HnManager.hh"
#include "G4AnalysisUtilities.hh"
#include "G4UIcommand.hh"
#include "G4UIparameter.hh"
#include "G4UIcmdWithABool.hh"
#include "G4UIcmdWithAString.hh"
using namespace G4Analysis;
//_____________________________________________________________________________
G4HnMessenger::G4HnMessenger(G4HnManager& manager)
: fManager(manager),
fHnType(manager.GetHnType())
fHnType(manager.GetHnType()),
fHnDimension(std::stoi(manager.GetHnType().substr(1,1)))
{
SetHnAsciiCmd();
SetHnActivationCmd();
@@ -46,6 +50,11 @@ G4HnMessenger::G4HnMessenger(G4HnManager& manager)
SetHnPlottingToAllCmd();
SetHnFileNameCmd();
SetHnFileNameToAllCmd();
auto maxDim = (fHnDimension < kMaxDim) ? fHnDimension + 1 : kMaxDim;
for (unsigned int idim = 0; idim < maxDim; ++idim) {
fSetAxisLogCmd.push_back(CreateSetAxisLogCommand(idim));
}
}
//_____________________________________________________________________________
@@ -154,6 +163,30 @@ void G4HnMessenger::SetHnFileNameToAllCmd()
fSetFileNameAllCmd->SetParameterName("FileName", false);
}
//_____________________________________________________________________________
std::unique_ptr<G4UIcommand>
G4HnMessenger::CreateSetAxisLogCommand(unsigned int idim)
{
G4String xyz{"XYZ"};
auto axis = xyz.substr(idim, 1);
G4String commandName = "set" + axis + "axisLog";
G4String guidance = "Activate " + axis + "-axis log scale for plotting of the ";
auto command = CreateCommand<G4UIcommand>(commandName, guidance);
command->AvailableForStates(G4State_PreInit, G4State_Idle);
// Add Id parameter
AddIdParameter(*command);
auto parAxisLog = new G4UIparameter("axis", 'b', false);
guidance = GetObjectType() + " " + axis + "-axis log scale";
parAxisLog->SetGuidance(guidance.c_str());
command->SetParameter(parAxisLog);
return command;
}
//
// public methods
//
@@ -213,4 +246,13 @@ void G4HnMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
fManager.SetFileName(id, parameters[counter++]);
return;
}
auto maxDim = (fHnDimension < kMaxDim) ? fHnDimension + 1 : kMaxDim;
for (unsigned int idim = 0; idim < maxDim; ++idim) {
if ( command == fSetAxisLogCmd[idim].get() ) {
auto axisLog = G4UIcommand::ConvertToBool(parameters[counter++]);
fManager.SetAxisIsLog(idim, id, axisLog);
return;
}
}
}
@@ -98,23 +98,37 @@ G4int G4NtupleBookingManager::CreateNtuple(
Message(kVL4, "create", "ntuple booking", name);
// Create ntuple description
auto index = fNtupleBookingVector.size();
auto ntupleBooking = new G4NtupleBooking();
fNtupleBookingVector.push_back(ntupleBooking);
G4int index = 0;
G4NtupleBooking* ntupleBooking = nullptr;
if (fFreeIds.empty()) {
index = (G4int)fNtupleBookingVector.size();
ntupleBooking = new G4NtupleBooking();
fNtupleBookingVector.push_back(ntupleBooking);
ntupleBooking->fNtupleId = G4int(index + fFirstId);
}
else {
// Get the first freed Id
index = *(fFreeIds.begin()) - GetFirstId();
ntupleBooking = fNtupleBookingVector[index];
ntupleBooking->fNtupleBooking = tools::ntuple_booking();
ntupleBooking->Reset();
// Remove the id from the set
fFreeIds.erase(fFreeIds.begin());
}
// Save name & title in ntuple booking
ntupleBooking->fNtupleBooking.set_name(name);
ntupleBooking->fNtupleBooking.set_title(title);
ntupleBooking->fNtupleId = G4int(index + fFirstId);
// Create ntuple
// Update related data
fLockFirstId = true;
fCurrentNtupleId = ntupleBooking->fNtupleId;
Message(kVL2, "create", "ntuple booking",
name + " ntupleId " + to_string(ntupleBooking->fNtupleId));
return ntupleBooking->fNtupleId;
return fCurrentNtupleId;
}
//_____________________________________________________________________________
@@ -298,6 +312,89 @@ void G4NtupleBookingManager::ClearData()
Message(G4Analysis::kVL2, "clear", "ntupleBookings");
}
//_____________________________________________________________________________
G4bool G4NtupleBookingManager::Delete(G4int id, G4bool keepSetting)
{
Message(kVL4, "delete", "ntuple booking ntupleId " + to_string(id));
auto ntupleBooking = GetNtupleBookingInFunction(id, "Delete", true);
if (ntupleBooking == nullptr) return false;
// Update ntuple booking
ntupleBooking->SetDeleted(true, keepSetting);
// Register freed Id
fFreeIds.insert(id);
Message(G4Analysis::kVL2, "delete", "ntuple booking ntupleId " + to_string(id));
return true;
}
//_____________________________________________________________________________
G4bool G4NtupleBookingManager::List(std::ostream& output, G4bool onlyIfActive)
{
// Save current output stream formatting
std::ios_base::fmtflags outputFlags(output.flags() );
// Define optimal field widths
size_t maxNameLength = 0;
size_t maxTitleLength = 0;
// size_t maxEntries = 0;
size_t nofActive = 0;
for (auto g4NtupleBooking : fNtupleBookingVector) {
const auto& ntupleBooking = g4NtupleBooking->fNtupleBooking;
if (ntupleBooking.name().length() > maxNameLength) {
maxNameLength = ntupleBooking.name().length();
}
if (ntupleBooking.title().length() > maxTitleLength) {
maxTitleLength = ntupleBooking.title().length();
}
// if (ntuple->entries() > maxEntries) {
// maxEntries = ntuple->entries();
// }
if (g4NtupleBooking->fActivation) {
++nofActive;
}
}
size_t maxIdWidth = std::to_string(fNtupleBookingVector.size() + GetFirstId()).length();
// update strings width for added double quotas
maxNameLength += 2;
maxTitleLength += 2;
// List general info
output << "Ntuple: " << nofActive << " active ";
if (! onlyIfActive) {
output << " of " << GetNofNtuples(true) << " defined ";
}
output << G4endl;
// List objects
G4int counter = 0;
for (auto g4NtupleBooking : fNtupleBookingVector) {
const auto& ntupleBooking = g4NtupleBooking->fNtupleBooking;
// skip inactivated objcets
if (fState.GetIsActivation() && onlyIfActive && (! g4NtupleBooking->fActivation)) continue;
// print selected info
output << " id: " << std::setw((G4int)maxIdWidth) << GetFirstId() + counter++
<< " name: \"" << std::setw((G4int)maxNameLength) << std::left << ntupleBooking.name() + "\""
<< " title: \"" << std::setw((G4int)maxTitleLength) << std::left << ntupleBooking.title() + "\"";
// << " entries: " << std::setw((G4int)maxEntriesWidth) << ntuple->entries();
if (! onlyIfActive) {
output << " active: " << std::boolalpha << g4NtupleBooking->fActivation;
}
output << G4endl;
}
// Restore the output stream formatting
output.flags(outputFlags);
return output.good();
}
//
// public methods
//
@@ -332,3 +429,24 @@ void G4NtupleBookingManager::SetFileType(const G4String& fileType)
ntupleBooking->fFileName = ntupleFileName;
}
}
//_____________________________________________________________________________
tools::ntuple_booking* G4NtupleBookingManager::GetNtuple(
G4bool warn, G4bool onlyIfActive) const
{
return GetNtuple(fFirstId, warn, onlyIfActive);
}
//_____________________________________________________________________________
tools::ntuple_booking* G4NtupleBookingManager::GetNtuple(
G4int ntupleId, G4bool warn, G4bool onlyIfActive) const
{
auto g4Booking = GetNtupleBookingInFunction(ntupleId, "GetNtuple", warn);
if (g4Booking == nullptr) return nullptr;
if ( ( g4Booking->GetDeleted() ) ||
( onlyIfActive && (! g4Booking->fActivation) ) ) return nullptr;
return &(g4Booking->fNtupleBooking);
}
@@ -34,6 +34,7 @@
#include "G4UIparameter.hh"
#include "G4UIcmdWithABool.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithoutParameter.hh"
using namespace G4Analysis;
using std::to_string;
@@ -45,6 +46,10 @@ G4NtupleMessenger::G4NtupleMessenger(G4VAnalysisManager* manager)
fNtupleDir = std::make_unique<G4UIdirectory>("/analysis/ntuple/");
fNtupleDir->SetGuidance("ntuple control");
CreateCmd();
CreateColumnCmds();
FinishCmd();
DeleteCmd();
SetActivationCmd();
SetActivationToAllCmd();
SetFileNameCmd();
@@ -69,11 +74,65 @@ void G4NtupleMessenger::AddIdParameter(G4UIcommand& command)
command.SetParameter(ntupleId);
}
//_____________________________________________________________________________
void G4NtupleMessenger::CreateCmd()
{
fCreateCmd = CreateCommand<G4UIcommand>("create", "Create ntuple");
auto ntName = new G4UIparameter("name", 's', false);
ntName->SetGuidance("Ntuple name");
fCreateCmd->SetParameter(ntName);
auto ntTitle = new G4UIparameter("title", 's', false);
ntTitle->SetGuidance("Ntuple title");
fCreateCmd->SetParameter(ntTitle);
}
//_____________________________________________________________________________
void G4NtupleMessenger::CreateColumnCmds()
{
std::vector<char> colTypes = {'I', 'F', 'D', 'S'};
for (auto colType : colTypes ) {
G4String name = "createColumn";
G4String guidance = "Create ntuple column";
name.insert(6, 1, colType);
guidance.insert(7, 1, colType);
auto cmd = CreateCommand<G4UIcmdWithAString>(name, guidance);
fCreateColumnCmds[colType] = std::move(cmd);
}
}
//_____________________________________________________________________________
void G4NtupleMessenger::FinishCmd()
{
fFinishCmd = CreateCommand<G4UIcmdWithoutParameter>(
"finish", "Finish creating ntuple");
}
//_____________________________________________________________________________
void G4NtupleMessenger::DeleteCmd()
{
fDeleteCmd = CreateCommand<G4UIcommand>(
"delete", "Delete ntuple with given id");
// Add Id parameter
AddIdParameter(*fDeleteCmd);
auto parKeepSetting = new G4UIparameter("keepSetting", 'b', true);
G4String guidance =
"If set true, activation, file name, etc. options will be kept\n"
"and applied when a new object with the same id is created.";
parKeepSetting->SetGuidance(guidance.c_str());
parKeepSetting->SetDefaultValue("false");
fDeleteCmd->SetParameter(parKeepSetting);
}
//_____________________________________________________________________________
void G4NtupleMessenger::SetActivationCmd()
{
fSetActivationCmd = CreateCommand<G4UIcommand>(
"setActivation", "Set activation for the ntuple");
"setActivation", "Set activation for the ntuple with given id");
AddIdParameter(*fSetActivationCmd);
@@ -95,7 +154,7 @@ void G4NtupleMessenger::SetActivationToAllCmd()
void G4NtupleMessenger::SetFileNameCmd()
{
fSetFileNameCmd = CreateCommand<G4UIcommand>(
"setFileName", "Set file name for the ntuple");
"setFileName", "Set file name for the ntuple with given id");
AddIdParameter(*fSetFileNameCmd);
@@ -158,8 +217,54 @@ void G4NtupleMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
}
auto counter = 0;
// commands without Id parameter
if ( command == fCreateCmd.get() ) {
auto name = parameters[counter++];
auto title = parameters[counter++];
fTmpNtupleId = fManager->CreateNtuple(name, title);
return;
}
for (const auto& [colType, checkCommand] : fCreateColumnCmds) {
if ( command == checkCommand.get() ) {
auto name = parameters[counter++];
switch (colType) {
case 'I':
fManager->CreateNtupleIColumn(fTmpNtupleId, name);
return;
case 'F':
fManager->CreateNtupleFColumn(fTmpNtupleId, name);
return;
case 'D':
fManager->CreateNtupleDColumn(fTmpNtupleId, name);
return;
case 'S':
fManager->CreateNtupleSColumn(fTmpNtupleId, name);
return;
default:
return;
}
}
}
if ( command == fFinishCmd.get() ) {
fManager->FinishNtuple(fTmpNtupleId);
fTmpNtupleId = G4Analysis::kInvalidId;
return;
}
// commands with Id parameter
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
if ( command == fDeleteCmd.get() ) {
auto keepSetting = G4UIcommand::ConvertToBool(parameters[counter++]);
fManager->DeleteNtuple(id, keepSetting);
return;
}
if ( command == fSetActivationCmd.get() ) {
fManager->SetNtupleActivation(id, G4UIcommand::ConvertToBool(parameters[counter++]));
return;
@@ -28,7 +28,6 @@
#include "G4VAnalysisManager.hh"
#include "G4AnalysisMessenger.hh"
#include "G4AnalysisUtilities.hh"
#include "G4HnManager.hh"
#include "G4VNtupleManager.hh"
#include "G4VNtupleFileManager.hh"
@@ -175,12 +174,38 @@ G4bool G4VAnalysisManager::ResetFromUI()
// protected methods
//
//_____________________________________________________________________________
void G4VAnalysisManager::SetDefaultFileTypeImpl(const G4String& value)
{
if ( (! GetType().empty()) && (GetFileType() != value) ) {
// If not generic analysis manager (which does not define FileType)
// the file type cannot be different from the analysis manager type
Warn("Cannot set default file type " + value +
" different than the analysis manager type " + GetType(),
fkClass, "SetDefault");
return;
}
fH1HnManager->SetDefaultFileType(value);
fH2HnManager->SetDefaultFileType(value);
fH3HnManager->SetDefaultFileType(value);
fP1HnManager->SetDefaultFileType(value);
fP2HnManager->SetDefaultFileType(value);
}
//_____________________________________________________________________________
G4String G4VAnalysisManager::GetDefaultFileTypeImpl() const
{
return GetFileType();
}
//_____________________________________________________________________________
void G4VAnalysisManager::SetH1Manager(G4VTBaseHnManager<kDim1>* h1Manager)
{
fVH1Manager.reset(h1Manager);
fH1HnManager = h1Manager->GetHnManager();
if (fVFileManager != nullptr ) fH1HnManager->SetFileManager(fVFileManager);
if (! GetFileType().empty() ) fH1HnManager->SetDefaultFileType(GetFileType());
}
//_____________________________________________________________________________
@@ -189,6 +214,7 @@ void G4VAnalysisManager::SetH2Manager(G4VTBaseHnManager<kDim2>* h2Manager)
fVH2Manager.reset(h2Manager);
fH2HnManager = h2Manager->GetHnManager();
if (fVFileManager != nullptr ) fH2HnManager->SetFileManager(fVFileManager);
if (! GetFileType().empty() ) fH2HnManager->SetDefaultFileType(GetFileType());
}
//_____________________________________________________________________________
@@ -197,6 +223,7 @@ void G4VAnalysisManager::SetH3Manager(G4VTBaseHnManager<kDim3>* h3Manager)
fVH3Manager.reset(h3Manager);
fH3HnManager = h3Manager->GetHnManager();
if (fVFileManager != nullptr ) fH3HnManager->SetFileManager(fVFileManager);
if (! GetFileType().empty() ) fH3HnManager->SetDefaultFileType(GetFileType());
}
//_____________________________________________________________________________
@@ -205,6 +232,7 @@ void G4VAnalysisManager::SetP1Manager(G4VTBaseHnManager<kDim2>* p1Manager)
fVP1Manager.reset(p1Manager);
fP1HnManager = p1Manager->GetHnManager();
if (fVFileManager != nullptr ) fP1HnManager->SetFileManager(fVFileManager);
if (! GetFileType().empty() ) fP1HnManager->SetDefaultFileType(GetFileType());
}
//_____________________________________________________________________________
@@ -213,6 +241,7 @@ void G4VAnalysisManager::SetP2Manager(G4VTBaseHnManager<kDim3>* p2Manager)
fVP2Manager.reset(p2Manager);
fP2HnManager = p2Manager->GetHnManager();
if (fVFileManager != nullptr ) fP2HnManager->SetFileManager(fVFileManager);
if (! GetFileType().empty() ) fP2HnManager->SetDefaultFileType(GetFileType());
}
//_____________________________________________________________________________
@@ -394,6 +423,18 @@ G4bool G4VAnalysisManager::IsOpenFile() const
return IsOpenFileImpl();
}
//_____________________________________________________________________________
void G4VAnalysisManager::SetDefaultFileType(const G4String& value)
{
SetDefaultFileTypeImpl(value);
}
//_____________________________________________________________________________
G4String G4VAnalysisManager::GetDefaultFileType() const
{
return GetDefaultFileTypeImpl();
}
//_____________________________________________________________________________
G4bool G4VAnalysisManager::SetFileName(const G4String& fileName)
{
@@ -415,7 +456,7 @@ G4bool G4VAnalysisManager::SetNtupleDirectoryName(const G4String& dirName)
//_____________________________________________________________________________
void G4VAnalysisManager::SetCompressionLevel(G4int level)
{
fState.SetCompressionLevel(level);
fVFileManager->SetCompressionLevel(level);
}
//_____________________________________________________________________________
@@ -439,7 +480,7 @@ G4String G4VAnalysisManager::GetNtupleDirectoryName() const
//_____________________________________________________________________________
G4int G4VAnalysisManager::GetCompressionLevel() const
{
return fState.GetCompressionLevel();
return fVFileManager->GetCompressionLevel();
}
//_____________________________________________________________________________
@@ -1210,43 +1251,39 @@ G4int G4VAnalysisManager::GetFirstNtupleColumnId() const
}
//_____________________________________________________________________________
G4int G4VAnalysisManager::GetNofH1s() const
G4int G4VAnalysisManager::GetNofH1s(G4bool onlyIfExist) const
{
return fH1HnManager->GetNofHns();
return fVH1Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisManager::GetNofH2s() const
G4int G4VAnalysisManager::GetNofH2s(G4bool onlyIfExist) const
{
return fH2HnManager->GetNofHns();
return fVH2Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisManager::GetNofH3s() const
G4int G4VAnalysisManager::GetNofH3s(G4bool onlyIfExist) const
{
return fH3HnManager->GetNofHns();
return fVH3Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisManager::GetNofP1s() const
G4int G4VAnalysisManager::GetNofP1s(G4bool onlyIfExist) const
{
return fP1HnManager->GetNofHns();
return fVP1Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisManager::GetNofP2s() const
G4int G4VAnalysisManager::GetNofP2s(G4bool onlyIfExist) const
{
return fP2HnManager->GetNofHns();
return fVP2Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisManager::GetNofNtuples() const
G4int G4VAnalysisManager::GetNofNtuples(G4bool onlyIfExist) const
{
if (fVNtupleManager != nullptr) {
return fVNtupleManager->GetNofNtuples();
}
return 0;
return fNtupleBookingManager->GetNofNtuples(onlyIfExist);
}
// GetH1Id(), GetH2Id in .icc
@@ -1284,10 +1321,7 @@ G4bool G4VAnalysisManager::ListP2(G4bool onlyIfActive) const
//_____________________________________________________________________________
G4bool G4VAnalysisManager::ListNtuple(G4bool onlyIfActive) const
{
if (fVNtupleManager != nullptr) {
return fVNtupleManager->List(G4cout, onlyIfActive);
}
return false;
return fNtupleBookingManager->List(G4cout, onlyIfActive);
}
//_____________________________________________________________________________
@@ -1512,6 +1546,48 @@ void G4VAnalysisManager::SetNtupleFileName(const G4String& fileName)
fNtupleBookingManager->SetFileName(fileName);
}
//_____________________________________________________________________________
G4bool G4VAnalysisManager::DeleteH1(G4int id, G4bool keepSetting)
{
return fVH1Manager->Delete(id, keepSetting);
}
//_____________________________________________________________________________
G4bool G4VAnalysisManager::DeleteH2(G4int id, G4bool keepSetting)
{
return fVH2Manager->Delete(id, keepSetting);
}
//_____________________________________________________________________________
G4bool G4VAnalysisManager::DeleteH3(G4int id, G4bool keepSetting)
{
return fVH3Manager->Delete(id, keepSetting);
}
//_____________________________________________________________________________
G4bool G4VAnalysisManager::DeleteP1(G4int id, G4bool keepSetting)
{
return fVP1Manager->Delete(id, keepSetting);
}
//_____________________________________________________________________________
G4bool G4VAnalysisManager::DeleteP2(G4int id, G4bool keepSetting)
{
return fVP2Manager->Delete(id, keepSetting);
}
//_____________________________________________________________________________
G4bool G4VAnalysisManager::DeleteNtuple(G4int id, G4bool keepSetting)
{
auto result = fNtupleBookingManager->Delete(id, keepSetting);
if (fVNtupleManager != nullptr) {
result &= fVNtupleManager->Delete(id);
}
return result;
}
// Access methods in .icc
//_____________________________________________________________________________
@@ -48,31 +48,31 @@ G4VAnalysisReader::~G4VAnalysisReader() = default;
//
//_____________________________________________________________________________
void G4VAnalysisReader::SetH1Manager(G4VTBaseHnManager<1>* h1Manager)
void G4VAnalysisReader::SetH1Manager(G4VTBaseHnManager<kDim1>* h1Manager)
{
fVH1Manager.reset(h1Manager);
}
//_____________________________________________________________________________
void G4VAnalysisReader::SetH2Manager(G4VTBaseHnManager<2>* h2Manager)
void G4VAnalysisReader::SetH2Manager(G4VTBaseHnManager<kDim2>* h2Manager)
{
fVH2Manager.reset(h2Manager);
}
//_____________________________________________________________________________
void G4VAnalysisReader::SetH3Manager(G4VTBaseHnManager<3>* h3Manager)
void G4VAnalysisReader::SetH3Manager(G4VTBaseHnManager<kDim3>* h3Manager)
{
fVH3Manager.reset(h3Manager);
}
//_____________________________________________________________________________
void G4VAnalysisReader::SetP1Manager(G4VTBaseHnManager<2>* p1Manager)
void G4VAnalysisReader::SetP1Manager(G4VTBaseHnManager<kDim2>* p1Manager)
{
fVP1Manager.reset(p1Manager);
}
//_____________________________________________________________________________
void G4VAnalysisReader::SetP2Manager(G4VTBaseHnManager<3>* p2Manager)
void G4VAnalysisReader::SetP2Manager(G4VTBaseHnManager<kDim3>* p2Manager)
{
fVP2Manager.reset(p2Manager);
}
@@ -396,33 +396,33 @@ G4bool G4VAnalysisReader::GetNtupleRow(G4int ntupleId)
}
//_____________________________________________________________________________
G4int G4VAnalysisReader::GetNofH1s() const
G4int G4VAnalysisReader::GetNofH1s(G4bool onlyIfExist) const
{
return fVH1Manager->GetHnManager()->GetNofHns();
return fVH1Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisReader::GetNofH2s() const
G4int G4VAnalysisReader::GetNofH2s(G4bool onlyIfExist) const
{
return fVH2Manager->GetHnManager()->GetNofHns();
return fVH2Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisReader::GetNofH3s() const
G4int G4VAnalysisReader::GetNofH3s(G4bool onlyIfExist) const
{
return fVH3Manager->GetHnManager()->GetNofHns();
return fVH3Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisReader::GetNofP1s() const
G4int G4VAnalysisReader::GetNofP1s(G4bool onlyIfExist) const
{
return fVP1Manager->GetHnManager()->GetNofHns();
return fVP1Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
G4int G4VAnalysisReader::GetNofP2s() const
G4int G4VAnalysisReader::GetNofP2s(G4bool onlyIfExist) const
{
return fVP2Manager->GetHnManager()->GetNofHns();
return fVP2Manager->GetNofHns(onlyIfExist);
}
//_____________________________________________________________________________
@@ -48,13 +48,16 @@ G4bool G4RootHnFileManager<HT>::WriteExtra(
{
auto result = true;
// // create a new file
// create a new file
auto rfile = new tools::wroot::file(G4cout, fileName);
// TO DO
// rfile->add_ziper('Z', toolx::compress_buffer);
// rfile->set_compression(fState.GetCompressionLevel());
// return if creating file failed
if (rfile == nullptr) return false;
// add compression
rfile->add_ziper('Z', toolx::compress_buffer);
rfile->set_compression(fFileManager->GetCompressionLevel());
// no directory supported in this mode
auto hdirectory = &(rfile->dir());
if (hdirectory == nullptr) return false;
@@ -65,11 +68,16 @@ G4bool G4RootHnFileManager<HT>::WriteExtra(
// write file
unsigned int n;
result &= rfile->write(n);
if ( ! result) {
G4Analysis::Warn(
"Saving " + G4Analysis::GetHnType<HT>() + " " + htName + " failed",
fkClass, "WriteExtra");
return false;
}
// close file
rfile->close();
return result;
return true;
}
//_____________________________________________________________________________
@@ -75,6 +75,7 @@ class G4RootMainNtupleManager : public G4BaseAnalysisManager
protected:
// Methods to manipulate ntuples
void CreateNtuple(RootNtupleDescription* ntupleDescription, G4bool warn = true);
G4bool Delete(G4int id);
G4bool Merge();
G4bool Reset();
void ClearData();
@@ -97,6 +98,10 @@ class G4RootMainNtupleManager : public G4BaseAnalysisManager
// Static data members
static constexpr std::string_view fkClass { "G4RootMainNtupleManager" };
// Methods
G4int CreateNtupleFromBooking(G4NtupleBooking* ntupleBooking,
std::shared_ptr<G4RootFile> ntupleFile);
// Data members
G4RootNtupleManager* fNtupleBuilder { nullptr };
std::shared_ptr<G4NtupleBookingManager> fBookingManager { nullptr };
@@ -78,6 +78,7 @@ class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple,
void FinishTNtuple(RootNtupleDescription* ntupleDescription, G4bool fromBooking) final;
G4bool Reset() final;
void Clear() final;
G4bool Delete(G4int id) final;
virtual G4bool Merge();
// Set functions
@@ -125,6 +125,9 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
virtual G4bool Reset();
void Clear() final;
// Method to delete selected ntuple
G4bool Delete(G4int id) final;
// Activation option
//
void SetActivation(G4bool activation) final;
@@ -135,15 +138,9 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
void SetNewCycle(G4bool value) final;
G4bool GetNewCycle() const final;
// Access methods
G4int GetNofNtuples() const final;
// Set methods
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
// List ntuples
G4bool List(std::ostream& output, G4bool onlyIfActive = true) final;
private:
G4RootPNtupleDescription*
GetNtupleDescriptionInFunction(G4int id, std::string_view function, G4bool warn = true) const;
+1 -1
View File
@@ -37,4 +37,4 @@ geant4_add_module(G4root
# Depends on ZLIB PUBLICally because of inclusion of tools/zlib in G4RootHnFileManager.icc
# (No, it't not obvious!)
geant4_module_link_libraries(G4root PUBLIC G4analysismng G4hntools G4globman G4tools ${ZLIB_LIBRARIES})
geant4_module_link_libraries(G4root PUBLIC G4analysismng G4hntools G4globman G4tools ${G4ZLIB_LIBRARIES})
@@ -118,7 +118,7 @@ G4RootFileManager::CreateFileImpl(const G4String& fileName)
// create file
std::shared_ptr<wroot::file> file = std::make_shared<wroot::file>(G4cout, fileName);
file->add_ziper('Z',toolx::compress_buffer);
file->set_compression(fState.GetCompressionLevel());
file->set_compression(GetCompressionLevel());
if ( ! file->is_open() ) {
Warn("Cannot create file " + fileName, fkClass, "CreateFileImpl");
@@ -50,6 +50,53 @@ G4RootMainNtupleManager::G4RootMainNtupleManager(
fFileNumber(fileNumber)
{}
//
// private functions
//
//_____________________________________________________________________________
G4int G4RootMainNtupleManager::CreateNtupleFromBooking(
G4NtupleBooking* g4NtupleBooking, std::shared_ptr<G4RootFile> ntupleFile)
{
// Do not create ntuple if it was deleted
if ( g4NtupleBooking->GetDeleted()) {
// G4cout << "Ntuple " << g4NtupleBooking->fNtupleId << " was deleted" << G4endl;
return G4Analysis::kInvalidId;
}
// The ntuple index
auto index = g4NtupleBooking->fNtupleId - fFirstId;
// Do not create ntuple if it already exists
if ( (index < G4int(fNtupleVector.size())) && (fNtupleVector[index] != nullptr) ) {
// G4cout << "Ntuple " << g4NtupleBooking->fNtupleId << " already exists" << G4endl;
return G4Analysis::kInvalidId;
}
// Get ntuple booking
const auto& ntupleBooking = g4NtupleBooking->fNtupleBooking;
Message(kVL4, "create", "main ntuple", ntupleBooking.name());
// Allocate the ntuple vector element(s) if needed
while ( index >= G4int(fNtupleVector.size()) ) {
fNtupleVector.push_back(nullptr);
}
// Create ntuple
auto ntuple = new tools::wroot::ntuple(*std::get<2>(*ntupleFile), ntupleBooking, fRowWise);
// ntuple object is deleted automatically when closing a file
auto basketSize = fNtupleBuilder->GetBasketSize();
ntuple->set_basket_size(basketSize);
// Save ntuple & ntuple description pair in vectors
fNtupleVector[index] = ntuple;
Message(kVL3, "create", "main ntuple", ntupleBooking.name());
return index;
}
//
// protected functions
//
@@ -71,21 +118,49 @@ void G4RootMainNtupleManager::CreateNtuple(RootNtupleDescription* ntupleDescript
return;
}
// Get ntuple booking
const auto& ntupleBooking = ntupleDescription->GetNtupleBooking();
// Create ntuple from g4 booking
auto g4NtupleBooking = ntupleDescription->GetG4NtupleBooking();
auto index = CreateNtupleFromBooking(g4NtupleBooking, ntupleFile);
Message(kVL4, "create", "main ntuple", ntupleBooking.name());
// Return if ntuple was not created
if (index == G4Analysis::kInvalidId) return;
// Create ntuple
auto ntuple = new tools::wroot::ntuple(*std::get<2>(*ntupleFile), ntupleBooking, fRowWise);
// ntuple object is deleted automatically when closing a file
auto basketSize = fNtupleBuilder->GetBasketSize();
ntuple->set_basket_size(basketSize);
// Allocate the ntuple description pair vector element(s) if needed
while ( index >= G4int(fNtupleDescriptionVector.size()) ) {
fNtupleDescriptionVector.push_back(std::make_pair(nullptr, nullptr));
}
fNtupleVector.push_back(ntuple);
fNtupleDescriptionVector.push_back(std::make_pair(ntupleDescription, ntupleFile));
// Save ntuple description pair in vectors
fNtupleDescriptionVector[index] = std::make_pair(ntupleDescription, ntupleFile);
}
Message(kVL3, "create", "main ntuple", ntupleBooking.name());
//_____________________________________________________________________________
G4bool G4RootMainNtupleManager::Delete(G4int id)
{
if (fNtupleVector.empty()) {
// Main ntuples are delete with each new cycle
return true;
}
// Proceed with deleting if vector is not empty
Message(kVL4, "delete", "main ntuple ntupleId: " + to_string(id));
// Get ntuple description
auto index = id - fFirstId;
if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
G4Analysis::Warn("Main ntuple " + to_string(id) + " does not exist.",
fkClass, "Delete");
return false;
}
// Delete main ntuple and update ntuple vector
delete fNtupleVector[index];
fNtupleVector[index] = nullptr;
Message(kVL3, "delete", "main ntuple ntupleId: " + to_string(id));
return true;
}
//_____________________________________________________________________________
@@ -94,6 +169,9 @@ G4bool G4RootMainNtupleManager::Merge()
std::size_t counter = 0;
for ( auto ntuple : fNtupleVector ) {
// skip deleted ntuples
if (ntuple == nullptr) continue;
ntuple->merge_number_of_entries();
// Notify ntuple description that file is not empty
@@ -142,25 +220,11 @@ G4RootMainNtupleManager::GetNtupleFile(RootNtupleDescription* ntupleDescription)
//_____________________________________________________________________________
void G4RootMainNtupleManager::CreateNtuplesFromBooking()
{
// Create ntuples from booking.
// Create ntuples from booking (without creating ntuple description)
// This function is triggered from workers at new cycle.
for (auto [ntupleDescription, ntupleFile] : fNtupleDescriptionVector) {
// Get ntuple booking
const auto& ntupleBooking = ntupleDescription->GetNtupleBooking();
Message(kVL4, "create", "main ntuple", ntupleBooking.name());
// Create ntuple
auto ntuple = new tools::wroot::ntuple(*std::get<2>(*ntupleFile), ntupleBooking, fRowWise);
// ntuple object is deleted automatically when closing a file
auto basketSize = fNtupleBuilder->GetBasketSize();
ntuple->set_basket_size(basketSize);
fNtupleVector.push_back(ntuple);
Message(kVL3, "create", "main ntuple", ntupleBooking.name());
CreateNtupleFromBooking(ntupleDescription->GetG4NtupleBooking(), ntupleFile);
}
SetNewCycle(false);
@@ -341,7 +341,7 @@ G4bool G4RootNtupleFileManager::ActionAtWrite()
result &= fSlaveNtupleManager->Merge();
}
Message(kVL1, "merge", ntupleType, "", result);
Message(kVL2, "merge", ntupleType, "", result);
return result;
}
@@ -89,14 +89,13 @@ void G4RootNtupleManager::CreateTNtupleFromBooking(
auto basketSize = fFileManager->GetBasketSize();
ntupleDescription->GetNtuple()->set_basket_size(basketSize);
ntupleDescription->SetIsNtupleOwner(false);
// ntuple object is deleted automatically when closing a file
fNtupleVector.push_back(ntupleDescription->GetNtuple());
}
else {
// Merging activated
for ( const auto& manager : fMainNtupleManagers ) {
manager->SetFirstId(fFirstId);
manager->CreateNtuple(ntupleDescription);
}
}
@@ -135,6 +134,18 @@ void G4RootNtupleManager::Clear()
}
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::Delete(G4int id)
{
auto result = G4TNtupleManager<tools::wroot::ntuple, G4RootFile> ::Delete(id);
for ( const auto& manager : fMainNtupleManagers ) {
result &= manager->Delete(id);
}
return result;
}
//_____________________________________________________________________________
G4bool G4RootNtupleManager::Merge()
{
@@ -140,6 +140,13 @@ void G4RootPNtupleManager::CreateNtupleFromMain(
G4RootPNtupleDescription* ntupleDescription,
tools::wroot::ntuple* mainNtuple)
{
// Do not create pntuple if ntuple was deleted
if (mainNtuple == nullptr) {
ntupleDescription->SetNtuple(nullptr);
ntupleDescription->SetBasePNtuple(nullptr);
return;
}
Message(kVL4, "create from main", "pntuple", mainNtuple->name());
auto file = fMainNtupleManager->GetNtupleFile(&ntupleDescription->GetDescription());
@@ -426,6 +433,32 @@ void G4RootPNtupleManager::Clear()
Message(kVL2, "clear", "pntuples");
}
//_____________________________________________________________________________
G4bool G4RootPNtupleManager::Delete(G4int id)
{
if ( IsVerbose(G4Analysis::kVL4) ) {
Message(G4Analysis::kVL4, "delete", "pntuple ntupleId " + to_string(id));
}
auto ntupleDescription = GetNtupleDescriptionInFunction(id, "Delete", true);
if (ntupleDescription == nullptr) return false;
// Delete/clear ntuple data
delete ntupleDescription->GetNtuple();
ntupleDescription->SetNtuple(nullptr);
ntupleDescription->SetBasePNtuple(nullptr);
ntupleDescription->GetMainBranches().clear();
// Update ntuple vector
auto index = id - GetFirstId();
fNtupleVector[index] = nullptr;
Message(G4Analysis::kVL2, "delete", "pntuple ntupleId " + to_string(id));
return true;
}
//_____________________________________________________________________________
void G4RootPNtupleManager::SetActivation(
@@ -469,22 +502,9 @@ G4bool G4RootPNtupleManager::GetNewCycle() const
return fNewCycle;
}
//_____________________________________________________________________________
G4int G4RootPNtupleManager::GetNofNtuples() const
{
return (G4int)fNtupleVector.size();
}
//_____________________________________________________________________________
void G4RootPNtupleManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
{
fRowWise = rowWise;
fRowMode = rowMode;
}
//_____________________________________________________________________________
G4bool G4RootPNtupleManager::List(std::ostream& /*output*/, G4bool /*onlyIfActive*/)
{
Warn("Not implemented.", fkClass, "List");
return false;
}
@@ -51,7 +51,9 @@ G4bool G4XmlHnFileManager<HT>::WriteExtra(
// write histo
auto result = tools::waxml::write(hnFile, *ht, path, htName);
if ( ! result) {
// TO DO: give an exception about failure
G4Analysis::Warn(
"Saving " + G4Analysis::GetHnType<HT>() + " " + htName + " failed",
fkClass, "WriteExtra");
return false;
}
+1 -1
View File
@@ -29,4 +29,4 @@ geant4_add_module(G4xml
# EXPAT is a PUBLIC dependency by virtue of inclusion of tools/raxml
# (No, it's not obvious!) and exposure of that in G4Xml{RFileManager/AnalysisReader}
geant4_module_link_libraries(G4xml PUBLIC G4analysismng G4hntools G4globman G4tools ${EXPAT_LIBRARIES})
geant4_module_link_libraries(G4xml PUBLIC G4analysismng G4hntools G4globman G4tools ${G4EXPAT_LIBRARIES})
@@ -57,7 +57,6 @@ void G4XmlNtupleManager::CreateTNtupleFromBooking(
new tools::waxml::ntuple(
*(ntupleDescription->GetFile()), G4cerr,
ntupleDescription->GetNtupleBooking()));
fNtupleVector.push_back(ntupleDescription->GetNtuple());
}
//_____________________________________________________________________________