Import Geant4 11.1.0 source tree
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include <string_view>
|
||||
|
||||
class G4GenericAnalysisManager;
|
||||
class G4GenericAnalysisMessenger;
|
||||
class G4GenericFileManager;
|
||||
class G4HnInformation;
|
||||
class G4VNtupleFileManager;
|
||||
@@ -53,18 +54,17 @@ class G4GenericAnalysisManager : public G4ToolsAnalysisManager
|
||||
friend class G4ThreadLocalSingleton<G4GenericAnalysisManager>;
|
||||
|
||||
public:
|
||||
virtual ~G4GenericAnalysisManager();
|
||||
~G4GenericAnalysisManager() override;
|
||||
|
||||
// Static methods
|
||||
static G4GenericAnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
// MT/MPI
|
||||
virtual void SetNtupleMerging(G4bool mergeNtuples,
|
||||
G4int nofReducedNtupleFiles = 0) override;
|
||||
virtual void SetNtupleRowWise(G4bool rowWise, G4bool rowMode = true) override;
|
||||
virtual void SetBasketSize(unsigned int basketSize) override;
|
||||
virtual void SetBasketEntries(unsigned int basketEntries) override;
|
||||
void SetNtupleMerging(G4bool mergeNtuples, G4int nofReducedNtupleFiles = 0) override;
|
||||
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode = true) override;
|
||||
void SetBasketSize(unsigned int basketSize) override;
|
||||
void SetBasketEntries(unsigned int basketEntries) override;
|
||||
|
||||
// write in an extra file
|
||||
G4bool WriteH1(G4int id, const G4String& fileName);
|
||||
@@ -80,14 +80,9 @@ class G4GenericAnalysisManager : public G4ToolsAnalysisManager
|
||||
|
||||
protected:
|
||||
// Virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) override;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset = true) override;
|
||||
virtual G4bool ResetImpl() final;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
G4bool OpenFileImpl(const G4String& fileName) override;
|
||||
// File manager access
|
||||
virtual std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName) final;
|
||||
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName) final;
|
||||
|
||||
private:
|
||||
G4GenericAnalysisManager();
|
||||
@@ -100,6 +95,7 @@ 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
|
||||
|
||||
@@ -76,10 +76,3 @@ inline G4String G4GenericAnalysisManager::GetDefaultFileType() const
|
||||
{
|
||||
return fFileManager->GetDefaultFileType();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
G4bool G4GenericAnalysisManager::IsOpenFileImpl() const
|
||||
{
|
||||
return fFileManager->IsOpenFile();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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
|
||||
@@ -53,30 +53,30 @@ class G4GenericFileManager : public G4VFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4GenericFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4GenericFileManager() = default;
|
||||
~G4GenericFileManager() override = default;
|
||||
|
||||
// Method to manipulate a default file
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
G4bool OpenFile(const G4String& fileName) final;
|
||||
|
||||
// Methods applied to all registered files
|
||||
virtual G4bool OpenFiles() final;
|
||||
virtual G4bool WriteFiles() final;
|
||||
virtual G4bool CloseFiles() final;
|
||||
virtual G4bool DeleteEmptyFiles() final;
|
||||
G4bool WriteFiles() final;
|
||||
G4bool CloseFiles() final;
|
||||
G4bool DeleteEmptyFiles() final;
|
||||
|
||||
// Clear all data
|
||||
virtual void Clear() final;
|
||||
void Clear() final;
|
||||
|
||||
// Methods applied to file per name
|
||||
virtual G4bool CreateFile(const G4String& fileName) final;
|
||||
virtual G4bool WriteFile(const G4String& fileName) final;
|
||||
virtual G4bool CloseFile(const G4String& fileName) final;
|
||||
virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) final;
|
||||
G4bool CreateFile(const G4String& fileName) final;
|
||||
G4bool WriteFile(const G4String& fileName) final;
|
||||
G4bool CloseFile(const G4String& fileName) final;
|
||||
G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) final;
|
||||
|
||||
virtual G4bool SetHistoDirectoryName(const G4String& dirName);
|
||||
virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
|
||||
G4bool SetHistoDirectoryName(const G4String& dirName) override;
|
||||
G4bool SetNtupleDirectoryName(const G4String& dirName) override;
|
||||
|
||||
virtual G4String GetFileType() const final { return ""; }
|
||||
G4String GetFileType() const final { return ""; }
|
||||
|
||||
// Set default output type (backward compatibility)
|
||||
// this type will be used for file names without extension
|
||||
|
||||
@@ -6,14 +6,16 @@ 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
|
||||
PUBLIC G4analysismng G4hntools G4globman G4intercoms
|
||||
PRIVATE G4csv G4root G4xml)
|
||||
|
||||
# HDF5, if enabled
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
// 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"
|
||||
@@ -70,6 +71,8 @@ G4bool G4GenericAnalysisManager::IsInstance()
|
||||
G4GenericAnalysisManager::G4GenericAnalysisManager()
|
||||
: G4ToolsAnalysisManager("")
|
||||
{
|
||||
fMessenger = std::make_unique<G4GenericAnalysisMessenger>(this);
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// File manager
|
||||
@@ -112,6 +115,7 @@ void G4GenericAnalysisManager::CreateNtupleFileManager(const G4String& fileName)
|
||||
|
||||
fNtupleFileManager = fFileManager->CreateNtupleFileManager(output);
|
||||
if (fNtupleFileManager) {
|
||||
SetNtupleFileManager(fNtupleFileManager);
|
||||
fNtupleFileManager->SetBookingManager(fNtupleBookingManager);
|
||||
|
||||
if ( fNtupleFileManager->IsNtupleMergingSupported() ) {
|
||||
@@ -142,10 +146,10 @@ G4bool G4GenericAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
|
||||
// Add file name extension, if missing
|
||||
auto fullFileName = fileName;
|
||||
if ( ! GetExtension(fileName).size() ) {
|
||||
if (GetExtension(fileName).size() == 0u) {
|
||||
auto defaultFileType = fFileManager->GetDefaultFileType();
|
||||
// G4cout << "File type is not defined, using default: " << defaultFileType << G4endl;
|
||||
if ( ! defaultFileType.size() ) {
|
||||
if (defaultFileType.size() == 0u) {
|
||||
G4Exception("G4GenericAnalysisManager::OpenFileImpl", "Analysis_F001",
|
||||
FatalException,
|
||||
G4String("Cannot open file \"" + fileName + "\".\n"
|
||||
@@ -161,110 +165,16 @@ G4bool G4GenericAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
CreateNtupleFileManager(fullFileName);
|
||||
}
|
||||
|
||||
// Create ntuple manager
|
||||
// and set it to base class which takes then its ownership
|
||||
if (fNtupleFileManager) {
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
}
|
||||
|
||||
auto result = true;
|
||||
|
||||
// Open file for histograms/profiles
|
||||
result &= fFileManager->OpenFile(fullFileName);
|
||||
|
||||
// Open ntuple file(s) and create ntuples from bookings
|
||||
if (fNtupleFileManager) {
|
||||
result &= fNtupleFileManager->ActionAtOpenFile(fullFileName);
|
||||
}
|
||||
|
||||
Message(kVL3, "open", "file", fileName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::WriteImpl()
|
||||
{
|
||||
Message(kVL4, "write", "files");
|
||||
|
||||
auto result = true;
|
||||
if ( G4Threading::IsWorkerThread() ) {
|
||||
result &= G4ToolsAnalysisManager::Merge();
|
||||
result &= G4ToolsAnalysisManager::OpenFileImpl(fullFileName);
|
||||
}
|
||||
else {
|
||||
// Open all files registered with objects
|
||||
fFileManager->OpenFiles();
|
||||
|
||||
// Write all histograms/profile on master
|
||||
result &= G4ToolsAnalysisManager::WriteImpl();
|
||||
// no ntuples (check if this mode is supported)
|
||||
result &= fFileManager->OpenFile(fullFileName);
|
||||
}
|
||||
|
||||
// Ntuples
|
||||
if (fNtupleFileManager) {
|
||||
result &= fNtupleFileManager->ActionAtWrite();
|
||||
}
|
||||
|
||||
// File
|
||||
result &= fFileManager->WriteFiles();
|
||||
|
||||
// Write ASCII if activated
|
||||
if ( IsAscii() ) {
|
||||
result &= WriteAscii(fFileManager->GetFileName());
|
||||
}
|
||||
|
||||
Message(kVL3, "write", "files", "", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
Message(kVL4, "close", "files");
|
||||
|
||||
auto result = true;
|
||||
if (fNtupleFileManager) {
|
||||
result &= fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
}
|
||||
|
||||
// close file
|
||||
if ( ! fFileManager->CloseFiles() ) {
|
||||
Warn("Closing files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
|
||||
// delete empty files
|
||||
if ( ! fFileManager->DeleteEmptyFiles() ) {
|
||||
Warn("Deleting empty files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
|
||||
if ( reset ) {
|
||||
if ( ! Reset() ) {
|
||||
Warn("Resetting data failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
Message(kVL3, "close", "files", "", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::ResetImpl()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
Message(kVL4, "reset", "");
|
||||
|
||||
auto result = true;
|
||||
result &= G4ToolsAnalysisManager::ResetImpl();
|
||||
if ( fNtupleFileManager != nullptr ) {
|
||||
result &= fNtupleFileManager->Reset();
|
||||
}
|
||||
|
||||
Message(kVL3, "reset", "", "", result);
|
||||
Message(kVL3, "open", "file", fileName, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -279,7 +189,7 @@ G4bool G4GenericAnalysisManager::WriteH1(G4int id, const G4String& fileName)
|
||||
if ( G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
auto h1d = GetH1(id, false);
|
||||
if ( ! h1d ) {
|
||||
if (h1d == nullptr) {
|
||||
WriteHnWarning("H1", id, fkClass, "WriteH1");
|
||||
return false;
|
||||
}
|
||||
@@ -298,7 +208,7 @@ G4bool G4GenericAnalysisManager::WriteH2(G4int id, const G4String& fileName)
|
||||
if ( G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
auto h2d = GetH2(id, false);
|
||||
if ( ! h2d ) {
|
||||
if (h2d == nullptr) {
|
||||
WriteHnWarning("H2", id, fkClass, "WriteH2");
|
||||
return false;
|
||||
}
|
||||
@@ -316,7 +226,7 @@ G4bool G4GenericAnalysisManager::WriteH3(G4int id, const G4String& fileName)
|
||||
if ( G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
auto h3d = GetH3(id, false);
|
||||
if ( ! h3d ) {
|
||||
if (h3d == nullptr) {
|
||||
WriteHnWarning("H3", id, fkClass, "WriteH3");
|
||||
return false;
|
||||
}
|
||||
@@ -335,7 +245,7 @@ G4bool G4GenericAnalysisManager::WriteP1(G4int id, const G4String& fileName)
|
||||
if ( G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
auto p1d = GetP1(id, false);
|
||||
if ( ! p1d ) {
|
||||
if (p1d == nullptr) {
|
||||
WriteHnWarning("P1", id, fkClass, "WriteP1");
|
||||
return false;
|
||||
}
|
||||
@@ -353,7 +263,7 @@ G4bool G4GenericAnalysisManager::WriteP2(G4int id, const G4String& fileName)
|
||||
if ( G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
auto p2d = GetP2(id, false);
|
||||
if ( ! p2d ) {
|
||||
if (p2d == nullptr) {
|
||||
WriteHnWarning("P2", id, fkClass, "WriteP2");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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;
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ G4GenericFileManager::GetFileManager(const G4String& fileName)
|
||||
{
|
||||
// Get file extension
|
||||
G4String extension = GetExtension(fileName);
|
||||
if ( ! extension.size() ) {
|
||||
if (extension.size() == 0u) {
|
||||
// use the default
|
||||
extension = fDefaultFileType;
|
||||
}
|
||||
@@ -212,7 +212,13 @@ G4bool G4GenericFileManager::OpenFiles()
|
||||
continue;
|
||||
}
|
||||
|
||||
result &= fileManager->CreateFile(fileName);
|
||||
// filenames for csv need to be updated
|
||||
auto newFileName = fileName;
|
||||
if (fileManager == fCsvFileManager) {
|
||||
newFileName = fileManager->GetHnFileName(fileName, GetCycle());
|
||||
}
|
||||
|
||||
result &= fileManager->CreateFile(newFileName);
|
||||
}
|
||||
|
||||
Message(kVL3, "open", "analysis files", "", result);
|
||||
@@ -360,7 +366,7 @@ G4bool G4GenericFileManager::SetHistoDirectoryName(const G4String& dirName)
|
||||
{
|
||||
auto result = G4VFileManager::SetHistoDirectoryName(dirName);
|
||||
|
||||
for (auto fileManager : fFileManagers ) {
|
||||
for (auto& fileManager : fFileManagers ) {
|
||||
if ( fileManager != nullptr ) {
|
||||
result &= fileManager->SetHistoDirectoryName(dirName);
|
||||
}
|
||||
@@ -373,7 +379,7 @@ G4bool G4GenericFileManager::SetNtupleDirectoryName(const G4String& dirName)
|
||||
{
|
||||
auto result = G4VFileManager::SetNtupleDirectoryName(dirName);
|
||||
|
||||
for (auto fileManager : fFileManagers ) {
|
||||
for (auto& fileManager : fFileManagers ) {
|
||||
if ( fileManager != nullptr ) {
|
||||
result &= fileManager->SetNtupleDirectoryName(dirName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user