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
@@ -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();
}