Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
+5
-10
@@ -24,18 +24,13 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 10/09/2019 (ivana@ipno.in2p3.fr)
|
||||
// Author: Ivana Hrivnacova, 21/09/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef g4analysis_defs_h
|
||||
#define g4analysis_defs_h 1
|
||||
#ifndef G4AnalysisManager_h
|
||||
#define G4AnalysisManager_h
|
||||
|
||||
#include "g4hntools_defs.hh"
|
||||
#include "G4ToolsAnalysisManager.hh"
|
||||
#include "G4GenericAnalysisManager.hh"
|
||||
|
||||
using G4AnalysisManager = G4ToolsAnalysisManager;
|
||||
using G4AnalysisManager = G4GenericAnalysisManager;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Root analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -34,24 +34,28 @@
|
||||
|
||||
#include "G4ToolsAnalysisManager.hh"
|
||||
#include "G4THnManager.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4GenericAnalysisManager;
|
||||
class G4GenericFileManager;
|
||||
class G4HnInformation;
|
||||
class G4VNtupleFileManager;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4GenericAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
friend class G4RootMpiAnalysisManager;
|
||||
friend class G4ThreadLocalSingleton<G4GenericAnalysisManager>;
|
||||
|
||||
public:
|
||||
explicit G4GenericAnalysisManager(G4bool isMaster = true);
|
||||
virtual ~G4GenericAnalysisManager();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4GenericAnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
@@ -62,51 +66,53 @@ class G4GenericAnalysisManager : public G4ToolsAnalysisManager
|
||||
virtual void SetBasketSize(unsigned int basketSize) override;
|
||||
virtual void SetBasketEntries(unsigned int basketEntries) override;
|
||||
|
||||
// new functions
|
||||
G4bool Merge();
|
||||
|
||||
// write in an extra file
|
||||
// write in an extra file
|
||||
G4bool WriteH1(G4int id, const G4String& fileName);
|
||||
G4bool WriteH2(G4int id, const G4String& fileName);
|
||||
G4bool WriteH3(G4int id, const G4String& fileName);
|
||||
G4bool WriteP1(G4int id, const G4String& fileName);
|
||||
G4bool WriteP2(G4int id, const G4String& fileName);
|
||||
|
||||
// set default output type (backward compatibility)
|
||||
// Set default output type (backward compatibility)
|
||||
// this type will be used for file names without extension
|
||||
void SetDefaultFileType(const G4String& value);
|
||||
G4String GetDefaultFileType() const;
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
// Virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) override;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset = true) override;
|
||||
virtual G4bool CloseFileImpl(G4bool reset = true) override;
|
||||
virtual G4bool ResetImpl() final;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
virtual G4bool Reset() final;
|
||||
// File manager access
|
||||
virtual std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName) final;
|
||||
|
||||
|
||||
private:
|
||||
// methods
|
||||
G4GenericAnalysisManager();
|
||||
// Methods
|
||||
void CreateNtupleFileManager(const G4String& fileName);
|
||||
|
||||
// static data members
|
||||
static G4GenericAnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4GenericAnalysisManager* fgInstance;
|
||||
// Static data members
|
||||
inline static G4GenericAnalysisManager* fgMasterInstance { nullptr };
|
||||
inline static G4ThreadLocal G4bool fgIsInstance { false };
|
||||
static constexpr std::string_view fkClass { "G4GenericAnalysisManager" };
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4GenericFileManager> fFileManager;
|
||||
// Data members
|
||||
std::shared_ptr<G4GenericFileManager> fFileManager { nullptr };
|
||||
// add G4GenericNtupleManager
|
||||
// this class will be analogic to file managers but with ntuples
|
||||
std::shared_ptr<G4VNtupleFileManager> fNtupleFileManager;
|
||||
std::shared_ptr<G4VNtupleFileManager> fNtupleFileManager { nullptr };
|
||||
|
||||
// data members
|
||||
G4bool fIsNtupleMergingSet = false;
|
||||
G4int fNofNtupleFiles = 0;
|
||||
G4bool fMergeNtuples = false;
|
||||
G4bool fNtupleRowWise = false;
|
||||
G4bool fNtupleRowMode = true;
|
||||
unsigned int fBasketSize = fgkDefaultBasketSize;
|
||||
unsigned int fBasketEntries = fgkDefaultBasketEntries;
|
||||
// Data members
|
||||
G4bool fIsNtupleMergingSet { false };
|
||||
G4int fNofNtupleFiles { 0 };
|
||||
G4bool fMergeNtuples { false };
|
||||
G4bool fNtupleRowWise { false };
|
||||
G4bool fNtupleRowMode { true };
|
||||
unsigned int fBasketSize { G4Analysis::kDefaultBasketSize };
|
||||
unsigned int fBasketEntries { G4Analysis::kDefaultBasketEntries };
|
||||
};
|
||||
|
||||
#include "G4GenericAnalysisManager.icc"
|
||||
|
||||
@@ -27,6 +27,13 @@
|
||||
#include "G4GenericFileManager.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::shared_ptr<G4VFileManager> G4GenericAnalysisManager::GetFileManager(
|
||||
const G4String& fileName)
|
||||
{
|
||||
return fFileManager->GetFileManager(fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4GenericAnalysisManager::SetNtupleMerging(
|
||||
G4bool mergeNtuples, G4int nofReducedNtupleFiles)
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4HnInformation;
|
||||
class G4VNtupleFileManager;
|
||||
@@ -52,7 +53,7 @@ class G4GenericFileManager : public G4VFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4GenericFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4GenericFileManager();
|
||||
virtual ~G4GenericFileManager() = default;
|
||||
|
||||
// Method to manipulate a default file
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
@@ -63,50 +64,58 @@ class G4GenericFileManager : public G4VFileManager
|
||||
virtual G4bool CloseFiles() final;
|
||||
virtual G4bool DeleteEmptyFiles() final;
|
||||
|
||||
// Clear all data
|
||||
virtual void Clear() final;
|
||||
|
||||
// Methods applied to file per name
|
||||
virtual G4bool CreateFile(const G4String& fileName) final;
|
||||
virtual G4bool WriteFile(const G4String& fileName) final;
|
||||
virtual G4bool CloseFile(const G4String& fileName) final;
|
||||
virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) final;
|
||||
|
||||
virtual G4bool SetHistoDirectoryName(const G4String& dirName);
|
||||
virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
|
||||
|
||||
virtual G4String GetFileType() const final { return ""; }
|
||||
|
||||
// set default output type (backward compatibility)
|
||||
// Set default output type (backward compatibility)
|
||||
// this type will be used for file names without extension
|
||||
void SetDefaultFileType(const G4String& value);
|
||||
G4String GetDefaultFileType() const;
|
||||
|
||||
template <typename T>
|
||||
G4bool WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector);
|
||||
// Get file manager for a specific output type
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName);
|
||||
|
||||
template <typename T>
|
||||
G4bool WriteTExtra(const G4String& fileName, T* ht, const G4String& htName);
|
||||
template <typename HT>
|
||||
G4bool WriteTExtra(const G4String& fileName, HT* ht, const G4String& htName);
|
||||
|
||||
// methods
|
||||
// Methods
|
||||
std::shared_ptr<G4VNtupleFileManager> CreateNtupleFileManager(G4AnalysisOutput output);
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
void CreateFileManager(G4AnalysisOutput output);
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(G4AnalysisOutput output) const;
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(const G4String& fileName);
|
||||
std::shared_ptr<G4VFileManager> GetFileManager(G4AnalysisOutput output) const;
|
||||
|
||||
// constants
|
||||
static const G4String fgkDefaultFileType;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4GenericFileManager" };
|
||||
// inline static const G4String fgkDefaultFileType { "root" };
|
||||
// inline static const G4String fgkDefaultFileType { "undefined" };
|
||||
|
||||
// data members
|
||||
// Data members
|
||||
G4String fDefaultFileType;
|
||||
std::shared_ptr<G4VFileManager> fDefaultFileManager;
|
||||
std::vector<std::shared_ptr<G4VFileManager>> fFileManagers;
|
||||
|
||||
std::shared_ptr<G4CsvFileManager> fCsvFileManager;
|
||||
std::shared_ptr<G4VFileManager> fDefaultFileManager { nullptr };
|
||||
std::vector<std::shared_ptr<G4VFileManager>> fFileManagers {
|
||||
// Csv, Hdf5, Root, Xml
|
||||
nullptr, nullptr, nullptr, nullptr
|
||||
};
|
||||
std::shared_ptr<G4CsvFileManager> fCsvFileManager { nullptr };
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
std::shared_ptr<G4Hdf5FileManager> fHdf5FileManager;
|
||||
std::shared_ptr<G4Hdf5FileManager> fHdf5FileManager { nullptr };
|
||||
#endif
|
||||
std::shared_ptr<G4RootFileManager> fRootFileManager;
|
||||
std::shared_ptr<G4XmlFileManager> fXmlFileManager;
|
||||
G4bool fHdf5Warn;
|
||||
std::shared_ptr<G4RootFileManager> fRootFileManager { nullptr };
|
||||
std::shared_ptr<G4XmlFileManager> fXmlFileManager { nullptr };
|
||||
G4bool fHdf5Warn { true };
|
||||
};
|
||||
|
||||
#include "G4GenericFileManager.icc"
|
||||
|
||||
@@ -33,122 +33,26 @@ inline G4String G4GenericFileManager::GetDefaultFileType() const
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4GenericFileManager::WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector)
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
|
||||
auto name = info->GetName();
|
||||
auto ht = htVector[i];
|
||||
|
||||
auto fileName = info->GetFileName();
|
||||
|
||||
auto fileManager = fDefaultFileManager;
|
||||
auto fileKind = "default";
|
||||
if ( fileName == "" ) {
|
||||
fileName = fileManager->GetFileName();
|
||||
} else {
|
||||
fileManager = GetFileManager(fileName);
|
||||
fileKind = "extra";
|
||||
// skip writing if cannot get file manager (wrong file extension)
|
||||
if ( ! fileManager ) {
|
||||
if ( G4Analysis::GetExtension(fileName) != "hdf5" || fHdf5Warn ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot get file manager for " << fileKind << " file " << fileName << "." << G4endl
|
||||
<< "Writing " << G4Analysis::GetHnType<T>() << " " << name
|
||||
<< " will be skipped.";
|
||||
G4Exception("G4GenericFileManager::WriteT",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << name << " in the " << fileKind << " file " << fileName;
|
||||
fState.GetVerboseL3()
|
||||
->Message("write", G4Analysis::GetHnType<T>(), description, false);
|
||||
}
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << name << " in the " << fileKind << " file " << fileName;
|
||||
fState.GetVerboseL3()
|
||||
->Message("write", G4Analysis::GetHnType<T>(), description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto result = fileManager->GetHnFileManager<T>()->Write(ht, name, fileName);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Writing " << G4Analysis::GetHnType<T>() << " " << name
|
||||
<< " to file " << fileName << " failed.";
|
||||
G4Exception("G4GenericManager::WriteT()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
}
|
||||
finalResult = result && finalResult;
|
||||
|
||||
// notify that file has a written object
|
||||
fileManager->SetIsEmpty(fileName, false);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << name << " in the " << fileKind << " file " << fileName;
|
||||
fState.GetVerboseL3()
|
||||
->Message("write", G4Analysis::GetHnType<T>(), description, finalResult);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4GenericFileManager::WriteTExtra(
|
||||
const G4String& fileName, T* ht, const G4String& htName)
|
||||
const G4String& fileName, HT* ht, const G4String& htName)
|
||||
{
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< fileName << " with " << G4Analysis::GetHnType<T>() << " " << htName;
|
||||
fState.GetVerboseL4()->Message("write", "extra file", description);
|
||||
}
|
||||
Message(G4Analysis::kVL4, "write", "extra file",
|
||||
fileName + " with " + G4Analysis::GetHnType<HT>() + " " + htName);
|
||||
|
||||
std::shared_ptr<G4VFileManager> fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot get file manager for file " << fileName << "." << G4endl
|
||||
<< "Writing " << G4Analysis::GetHnType<T>() << " " << htName
|
||||
<< " failed.";
|
||||
G4Exception("G4GenericFileManager::WriteTExtra",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Cannot get file manager for " + fileName + " .\n" +
|
||||
"Writing " + G4Analysis::GetHnType<HT>() + " " + htName + " failed.",
|
||||
fkClass, "WriteTExtra");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto result = fileManager->GetHnFileManager<T>()->WriteExtra(ht, htName, fileName);
|
||||
auto result = fileManager->GetHnFileManager<HT>()->WriteExtra(ht, htName, fileName);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() ) {
|
||||
fState.GetVerboseL1()->Message("write", "extra file", fileName, result);
|
||||
}
|
||||
#endif
|
||||
Message(G4Analysis::kVL1, "write", "extra file", fileName, result);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,46 +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, 10/09/2019 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef g4analysis_h
|
||||
#define g4analysis_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "g4analysis_defs.hh"
|
||||
|
||||
namespace G4Analysis
|
||||
{
|
||||
|
||||
G4ToolsAnalysisManager* ManagerInstance(const G4String& outputType);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,14 +8,12 @@ endif()
|
||||
# Define the Geant4 Module.
|
||||
geant4_add_module(G4analysisfac
|
||||
PUBLIC_HEADERS
|
||||
g4analysis.hh
|
||||
g4analysis_defs.hh
|
||||
G4AnalysisManager.hh
|
||||
G4GenericAnalysisManager.hh
|
||||
G4GenericAnalysisManager.icc
|
||||
G4GenericFileManager.hh
|
||||
G4GenericFileManager.icc
|
||||
SOURCES
|
||||
g4analysis.cc
|
||||
G4GenericAnalysisManager.cc
|
||||
G4GenericFileManager.cc)
|
||||
|
||||
|
||||
@@ -28,85 +28,63 @@
|
||||
|
||||
#include "G4GenericAnalysisManager.hh"
|
||||
#include "G4GenericFileManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4NtupleBookingManager.hh"
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Exception.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
using std::to_string;
|
||||
|
||||
// mutex in a file scope
|
||||
|
||||
namespace {
|
||||
|
||||
//Mutex to lock master manager when merging histograms
|
||||
G4Mutex mergeHnMutex = G4MUTEX_INITIALIZER;
|
||||
|
||||
void WriteHnException(const G4String& hnType, G4int id)
|
||||
//_____________________________________________________________________________
|
||||
void WriteHnWarning(const G4String& hnType, G4int id,
|
||||
std::string_view inClass,
|
||||
std::string_view inFunction)
|
||||
{
|
||||
G4String inFunction = "G4GenericAnalysisManager::Write" + hnType;
|
||||
G4ExceptionDescription description;
|
||||
description << "Failed to get " << hnType << " id " << id << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W022", JustWarning, description);
|
||||
Warn("Failed to get " + hnType + " id " + to_string(id), inClass, inFunction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
G4GenericAnalysisManager* G4GenericAnalysisManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4GenericAnalysisManager* G4GenericAnalysisManager::fgInstance = nullptr;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericAnalysisManager* G4GenericAnalysisManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4GenericAnalysisManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
static G4ThreadLocalSingleton<G4GenericAnalysisManager> instance;
|
||||
fgIsInstance = true;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::IsInstance()
|
||||
{
|
||||
return ( fgInstance != nullptr );
|
||||
}
|
||||
return fgIsInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericAnalysisManager::G4GenericAnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("", isMaster),
|
||||
fFileManager(nullptr),
|
||||
fNtupleFileManager(nullptr)
|
||||
G4GenericAnalysisManager::G4GenericAnalysisManager()
|
||||
: G4ToolsAnalysisManager("")
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4GenericAnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4GenericAnalysisManager::G4GenericAnalysisManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// File manager
|
||||
fFileManager = std::make_shared<G4GenericFileManager>(fState);
|
||||
SetFileManager(fFileManager);
|
||||
SetFileManager(fFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericAnalysisManager::~G4GenericAnalysisManager()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
fgIsInstance = false;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -114,84 +92,70 @@ G4GenericAnalysisManager::~G4GenericAnalysisManager()
|
||||
void G4GenericAnalysisManager::CreateNtupleFileManager(const G4String& fileName)
|
||||
{
|
||||
if ( fNtupleFileManager ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "The ntuple file manager already exists.";
|
||||
G4Exception("G4GenericAnalysisManager::CreateNtupleFileManager",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
Warn("The ntuple file manager already exists.",
|
||||
fkClass, "CreateNtupleFileManager");
|
||||
return;
|
||||
}
|
||||
|
||||
auto fileType = GetExtension(fileName);
|
||||
auto output = G4Analysis::GetOutput(fileType);
|
||||
if ( output == G4AnalysisOutput::kNone ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "The file type " << fileType << "is not supported.";
|
||||
G4Exception("G4GenericAnalysisManager::CreateNtupleFileManager",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
Warn("The file type " + fileType + "is not supported.",
|
||||
fkClass, "CreateNtupleFileManager");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set file type to booked ntuples
|
||||
fNtupleBookingManager->SetFileType(fileType);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("create", "ntuple file manager", fileType);
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "create", "ntuple file manager", fileType);
|
||||
|
||||
fNtupleFileManager = fFileManager->CreateNtupleFileManager(output);
|
||||
if (fNtupleFileManager) {
|
||||
fNtupleFileManager->SetBookingManager(fNtupleBookingManager);
|
||||
|
||||
if ( fNtupleFileManager->IsNtupleMergingSupported() ) {
|
||||
// set merginng
|
||||
fNtupleFileManager->SetNtupleMerging(fMergeNtuples, fNofNtupleFiles);
|
||||
fNtupleFileManager->SetNtupleRowWise(fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleFileManager->SetBasketSize(fBasketSize);
|
||||
fNtupleFileManager->SetBasketEntries(fBasketEntries);
|
||||
}
|
||||
else if ( fIsNtupleMergingSet && fMergeNtuples ) {
|
||||
Warn("Ntuple merging is not available with " + fileType + " output.\n" +
|
||||
"Setting is ignored.",
|
||||
fkClass, "CreateNtupleFileManager");
|
||||
}
|
||||
}
|
||||
|
||||
if ( fNtupleFileManager->IsNtupleMergingSupported() ) {
|
||||
// set merginng
|
||||
fNtupleFileManager->SetNtupleMerging(fMergeNtuples, fNofNtupleFiles);
|
||||
fNtupleFileManager->SetNtupleRowWise(fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleFileManager->SetBasketSize(fBasketSize);
|
||||
fNtupleFileManager->SetBasketEntries(fBasketEntries);
|
||||
}
|
||||
else if ( fIsNtupleMergingSet && fMergeNtuples ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "Ntuple merging is not available with "
|
||||
<< fileType << " output." << G4endl
|
||||
<< " " << "Setting is ignored.";
|
||||
G4Exception("G4GenericAnalysisManager::CreateNtupleFileManager",
|
||||
"Analysis_W041", JustWarning, description);
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("create", "ntuple file manager", fileType, true);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "create", "ntuple file manager", fileType);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
Message(kVL4, "open", "file", fileName);
|
||||
|
||||
// Add file name extension, if missing
|
||||
auto fullFileName = fileName;
|
||||
if ( ! GetExtension(fileName).size() ) {
|
||||
// G4cout << "File type is not defined, using default: " << fFileManager->GetDefaultFileType() << G4endl;
|
||||
auto defaultFileType = fFileManager->GetDefaultFileType();
|
||||
// G4cout << "File type is not defined, using default: " << defaultFileType << G4endl;
|
||||
if ( ! defaultFileType.size() ) {
|
||||
G4Exception("G4GenericAnalysisManager::OpenFileImpl", "Analysis_F001",
|
||||
FatalException,
|
||||
G4String("Cannot open file \"" + fileName + "\".\n"
|
||||
"Please, use a file name with an extension or define the default file type\n"
|
||||
"via G4AnalysisManager::SetDefaultFileType()"));
|
||||
}
|
||||
|
||||
fullFileName = fileName + "." + fFileManager->GetDefaultFileType();
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("open (generic)", "file", fileName);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create ntuple file manager if there are booked ntuples
|
||||
if (! fNtupleFileManager) {
|
||||
CreateNtupleFileManager(fullFileName);
|
||||
@@ -203,202 +167,106 @@ G4bool G4GenericAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
}
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Open file for histograms/profiles
|
||||
auto result = fFileManager->OpenFile(fullFileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->OpenFile(fullFileName);
|
||||
|
||||
// Open ntuple file(s) and create ntuples from bookings
|
||||
if (fNtupleFileManager) {
|
||||
result = fNtupleFileManager->ActionAtOpenFile(fullFileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtOpenFile(fullFileName);
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("open (generic)", "file", fileName, finalResult);
|
||||
}
|
||||
#endif
|
||||
return finalResult;
|
||||
Message(kVL3, "open", "file", fileName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::WriteImpl()
|
||||
G4bool G4GenericAnalysisManager::WriteImpl()
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write (generic)", "files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "write", "files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
if ( ! fgMasterInstance &&
|
||||
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ||
|
||||
( ! fH3Manager->IsEmpty() ) || ( ! fP1Manager->IsEmpty() ) ||
|
||||
( ! fP2Manager->IsEmpty() ) ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "No master G4GenericAnalysisManager instance exists."
|
||||
<< G4endl
|
||||
<< " " << "Histogram/profile data will not be merged.";
|
||||
G4Exception("G4GenericAnalysisManager::Write()",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
}
|
||||
|
||||
if ( G4Threading::IsWorkerThread() ) {
|
||||
result = Merge();
|
||||
finalResult = finalResult && result;
|
||||
result &= G4ToolsAnalysisManager::Merge();
|
||||
}
|
||||
else {
|
||||
// GO ON
|
||||
|
||||
// Open all files registered with objects
|
||||
fFileManager->OpenFiles();
|
||||
|
||||
// Write all histograms/profile on master
|
||||
//
|
||||
result = fFileManager->WriteT(fH1Manager->GetH1Vector(), fH1Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fFileManager->WriteT(fH2Manager->GetH2Vector(), fH2Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fFileManager->WriteT(fH3Manager->GetH3Vector(), fH3Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fFileManager->WriteT(fP1Manager->GetP1Vector(), fP1Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fFileManager->WriteT(fP2Manager->GetP2Vector(), fP2Manager->GetHnVector());
|
||||
finalResult = finalResult && result;
|
||||
result &= G4ToolsAnalysisManager::WriteImpl();
|
||||
}
|
||||
|
||||
// Ntuples
|
||||
if (fNtupleFileManager) {
|
||||
result = fNtupleFileManager->ActionAtWrite();
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtWrite();
|
||||
}
|
||||
|
||||
// File
|
||||
result = fFileManager->WriteFiles();
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->WriteFiles();
|
||||
|
||||
// Write ASCII if activated
|
||||
if ( IsAscii() ) {
|
||||
result = WriteAscii(fFileManager->GetFileName());
|
||||
finalResult = finalResult && result;
|
||||
result &= WriteAscii(fFileManager->GetFileName());
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("write (generic)", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "write", "files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("close (generic)", "files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "close", "files");
|
||||
|
||||
auto result = true;
|
||||
if (fNtupleFileManager) {
|
||||
auto result = fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
}
|
||||
|
||||
// close file
|
||||
auto result = fFileManager->CloseFiles();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Closing files failed";
|
||||
G4Exception("G4GenericAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
if ( ! fFileManager->CloseFiles() ) {
|
||||
Warn("Closing files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// delete empty files
|
||||
result = fFileManager->DeleteEmptyFiles();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Deleting empty files failed";
|
||||
G4Exception("G4GenericAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
if ( ! fFileManager->DeleteEmptyFiles() ) {
|
||||
Warn("Deleting empty files failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
if ( reset ) {
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4GenericAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
if ( ! Reset() ) {
|
||||
Warn("Resetting data failed", fkClass, "CloseFileImpl");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("close (generic)", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "close", "files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::Reset()
|
||||
G4bool G4GenericAnalysisManager::ResetImpl()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
Message(kVL4, "reset", "");
|
||||
|
||||
auto result = G4ToolsAnalysisManager::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleFileManager->Reset();
|
||||
finalResult = result && finalResult;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericAnalysisManager::Merge()
|
||||
{
|
||||
// Nothing to be done on master
|
||||
if ( ! G4Threading::IsWorkerThread() ) return false;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("merge (generic) on worker", "histograms", "");
|
||||
auto result = true;
|
||||
result &= G4ToolsAnalysisManager::ResetImpl();
|
||||
if ( fNtupleFileManager != nullptr ) {
|
||||
result &= fNtupleFileManager->Reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
// The worker manager just adds its histograms to the master
|
||||
fH1Manager->Merge(mergeHnMutex, fgMasterInstance->fH1Manager);
|
||||
fH2Manager->Merge(mergeHnMutex, fgMasterInstance->fH2Manager);
|
||||
fH3Manager->Merge(mergeHnMutex, fgMasterInstance->fH3Manager);
|
||||
fP1Manager->Merge(mergeHnMutex, fgMasterInstance->fP1Manager);
|
||||
fP2Manager->Merge(mergeHnMutex, fgMasterInstance->fP2Manager);
|
||||
Message(kVL3, "reset", "", "", result);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("merge (generic) on worker", "histograms", "", true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -412,9 +280,9 @@ G4bool G4GenericAnalysisManager::WriteH1(G4int id, const G4String& fileName)
|
||||
|
||||
auto h1d = GetH1(id, false);
|
||||
if ( ! h1d ) {
|
||||
WriteHnException("H1", id);
|
||||
WriteHnWarning("H1", id, fkClass, "WriteH1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto h1Name = GetH1Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::h1d>(fileName, h1d, h1Name);
|
||||
@@ -431,9 +299,9 @@ G4bool G4GenericAnalysisManager::WriteH2(G4int id, const G4String& fileName)
|
||||
|
||||
auto h2d = GetH2(id, false);
|
||||
if ( ! h2d ) {
|
||||
WriteHnException("H2", id);
|
||||
WriteHnWarning("H2", id, fkClass, "WriteH2");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto h2Name = GetH2Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::h2d>(fileName, h2d, h2Name);
|
||||
@@ -449,9 +317,9 @@ G4bool G4GenericAnalysisManager::WriteH3(G4int id, const G4String& fileName)
|
||||
|
||||
auto h3d = GetH3(id, false);
|
||||
if ( ! h3d ) {
|
||||
WriteHnException("H3", id);
|
||||
WriteHnWarning("H3", id, fkClass, "WriteH3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto h3Name = GetH3Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::h3d>(fileName, h3d, h3Name);
|
||||
@@ -468,9 +336,9 @@ G4bool G4GenericAnalysisManager::WriteP1(G4int id, const G4String& fileName)
|
||||
|
||||
auto p1d = GetP1(id, false);
|
||||
if ( ! p1d ) {
|
||||
WriteHnException("P1", id);
|
||||
WriteHnWarning("P1", id, fkClass, "WriteP1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto p1Name = GetP1Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::p1d>(fileName, p1d, p1Name);
|
||||
@@ -486,9 +354,9 @@ G4bool G4GenericAnalysisManager::WriteP2(G4int id, const G4String& fileName)
|
||||
|
||||
auto p2d = GetP2(id, false);
|
||||
if ( ! p2d ) {
|
||||
WriteHnException("P2", id);
|
||||
WriteHnWarning("P2", id, fkClass, "WriteP2");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto p2Name = GetP2Name(id);
|
||||
return fFileManager->WriteTExtra<tools::histo::p2d>(fileName, p2d, p2Name);
|
||||
|
||||
@@ -40,52 +40,27 @@
|
||||
#include "G4XmlFileManager.hh"
|
||||
#include "G4XmlNtupleFileManager.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
namespace {
|
||||
|
||||
void FileManagerException(const G4String& fileName, const G4String& functionName,
|
||||
const G4String& exceptionClassification, G4bool hdf5Warn = true)
|
||||
//_____________________________________________________________________________
|
||||
void FileManagerWarning(const G4String& fileName,
|
||||
std::string_view className,
|
||||
std::string_view functionName,
|
||||
G4bool hdf5Warn = true)
|
||||
{
|
||||
if ( GetExtension(fileName) == "hdf5" && ( ! hdf5Warn ) ) return;
|
||||
|
||||
G4String where = "G4GenericFileManager::" + functionName;
|
||||
G4String what = "Analysis_" + exceptionClassification;
|
||||
G4ExceptionDescription description;
|
||||
description << "Cannot get file manager for " << fileName;
|
||||
G4Exception(where, what, JustWarning, description);
|
||||
Warn("Cannot get file manager for " + fileName,
|
||||
className, functionName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// static data
|
||||
const G4String G4GenericFileManager::fgkDefaultFileType = "root";
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericFileManager::G4GenericFileManager(const G4AnalysisManagerState& state)
|
||||
: G4VFileManager(state),
|
||||
fDefaultFileType(fgkDefaultFileType),
|
||||
fDefaultFileManager(nullptr),
|
||||
fFileManagers
|
||||
{ nullptr, // Csv
|
||||
nullptr, // Hdf5
|
||||
nullptr, // Generic
|
||||
nullptr // Xml
|
||||
},
|
||||
fCsvFileManager(nullptr),
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
fHdf5FileManager(nullptr),
|
||||
#endif
|
||||
fRootFileManager(nullptr),
|
||||
fXmlFileManager(nullptr),
|
||||
fHdf5Warn(true)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4GenericFileManager::~G4GenericFileManager()
|
||||
: G4VFileManager(state)
|
||||
{}
|
||||
|
||||
//
|
||||
@@ -95,20 +70,13 @@ G4GenericFileManager::~G4GenericFileManager()
|
||||
//_____________________________________________________________________________
|
||||
void G4GenericFileManager::CreateFileManager(G4AnalysisOutput output)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("create", "file manager", GetOutputName(output));
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "create", "file manager", GetOutputName(output));
|
||||
|
||||
auto outputId = static_cast<size_t>(output);
|
||||
auto outputId = static_cast<size_t>(output);
|
||||
if ( fFileManagers[outputId] ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "The file manager of " << G4Analysis::GetOutputName(output) << " type already exists.";
|
||||
G4Exception("G4GenericFileManager::CreateFileManager",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
Warn("The file manager of " + G4Analysis::GetOutputName(output) +
|
||||
" type already exists.",
|
||||
fkClass, "CreateFileManager");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,16 +86,13 @@ void G4GenericFileManager::CreateFileManager(G4AnalysisOutput output)
|
||||
fCsvFileManager = std::make_shared<G4CsvFileManager>(fState);
|
||||
fFileManagers[outputId] = fCsvFileManager;
|
||||
break;
|
||||
case G4AnalysisOutput::kHdf5:
|
||||
case G4AnalysisOutput::kHdf5:
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
fHdf5FileManager = std::make_shared<G4Hdf5FileManager>(fState);
|
||||
fFileManagers[outputId] = fHdf5FileManager;
|
||||
#else
|
||||
if ( fHdf5Warn) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Hdf5 type is not available.";
|
||||
G4Exception("G4GenericFileManager::CreateFileManager",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
Warn("Hdf5 type is not available.", fkClass, "CreateFileManager");
|
||||
fHdf5Warn = false;
|
||||
}
|
||||
#endif
|
||||
@@ -141,30 +106,31 @@ void G4GenericFileManager::CreateFileManager(G4AnalysisOutput output)
|
||||
fFileManagers[outputId] = fXmlFileManager ;
|
||||
break;
|
||||
case G4AnalysisOutput::kNone:
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< G4Analysis::GetOutputName(output) << " type is not supported.";
|
||||
G4Exception("G4GenericFileManager::CreateFileManager",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
break;
|
||||
Warn(G4Analysis::GetOutputName(output) + " type is not supported.",
|
||||
fkClass, "CreateFileManager");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("create", "file manager", GetOutputName(output));
|
||||
// Pass directory names (only if set)
|
||||
if ( ! GetHistoDirectoryName().empty() ) {
|
||||
fFileManagers[outputId]->SetHistoDirectoryName(GetHistoDirectoryName());
|
||||
}
|
||||
#endif
|
||||
if ( ! GetNtupleDirectoryName().empty() ) {
|
||||
fFileManagers[outputId]->SetNtupleDirectoryName(GetNtupleDirectoryName());
|
||||
}
|
||||
|
||||
Message(kVL3, "create", "file manager", GetOutputName(output));
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4VFileManager>
|
||||
std::shared_ptr<G4VFileManager>
|
||||
G4GenericFileManager::GetFileManager(G4AnalysisOutput output) const
|
||||
{
|
||||
return fFileManagers[static_cast<size_t>(output)];
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4VFileManager>
|
||||
std::shared_ptr<G4VFileManager>
|
||||
G4GenericFileManager::GetFileManager(const G4String& fileName)
|
||||
{
|
||||
// Get file extension
|
||||
@@ -176,12 +142,8 @@ G4GenericFileManager::GetFileManager(const G4String& fileName)
|
||||
|
||||
auto output = G4Analysis::GetOutput(extension);
|
||||
if ( output == G4AnalysisOutput::kNone ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "The file extension " << extension << "is not supported.";
|
||||
G4Exception("G4GenericFileManager::GetFileManager",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
Warn("The file extension " + extension + "is not supported.",
|
||||
fkClass, "GetFileManager");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -207,45 +169,30 @@ G4bool G4GenericFileManager::OpenFile(const G4String& fileName)
|
||||
if ( fDefaultFileManager && (fDefaultFileManager != fileManager) ) {
|
||||
// Print warning if default output changed
|
||||
// (maybe be not needed?)
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Default file manager changed (old: "
|
||||
<< fDefaultFileManager->GetFileType()
|
||||
<< ", new:" << fileManager->GetFileType() << ")";
|
||||
G4Exception("G4GenericFileManager::OpenFile",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
}
|
||||
fDefaultFileManager = fileManager;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("open", "analysis file", fileName);
|
||||
Warn("Default file manager changed "
|
||||
"(old: " +fDefaultFileManager->GetFileType() +
|
||||
", new:" + fileManager->GetFileType() + ")",
|
||||
fkClass, "OpenFile");
|
||||
}
|
||||
#endif
|
||||
fDefaultFileManager = fileManager;
|
||||
fDefaultFileType = fileManager->GetFileType();
|
||||
|
||||
Message(kVL4, "open", "analysis file", fileName);
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Save the default file name
|
||||
// Save the default file name
|
||||
// both in the generic file manager and the output specific one
|
||||
result = SetFileName(fileName);
|
||||
finalResult = finalResult && result;
|
||||
result = fDefaultFileManager->SetFileName(fileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= SetFileName(fileName);
|
||||
result &= fDefaultFileManager->SetFileName(fileName);
|
||||
result &= fDefaultFileManager->OpenFile(fileName);
|
||||
|
||||
result = fDefaultFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() ) {
|
||||
fState.GetVerboseL1()->Message("open", "analysis file", fileName, finalResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
fLockDirectoryNames = true;
|
||||
LockDirectoryNames();
|
||||
fIsOpenFile = true;
|
||||
|
||||
return finalResult;
|
||||
Message(kVL1, "open", "analysis file", fileName, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -253,70 +200,46 @@ G4bool G4GenericFileManager::OpenFiles()
|
||||
{
|
||||
// Open all files regeistered with objects
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("open", "analysis files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "open", "analysis files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// process names registered in base file manager
|
||||
for ( auto fileName : GetFileNames() ) {
|
||||
for ( const auto& fileName : GetFileNames() ) {
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "OpenFiles", "W001", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "OpenFiles", fHdf5Warn);
|
||||
continue;
|
||||
}
|
||||
|
||||
result = fileManager->CreateFile(fileName);
|
||||
finalResult = result && finalResult;
|
||||
result &= fileManager->CreateFile(fileName);
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("open", "analysis files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "open", "analysis files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericFileManager::WriteFiles()
|
||||
{
|
||||
// Finish write for all files regeistered with objects
|
||||
// Finish write for all files registered with objects
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write", "files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "write", "analysis files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
for ( auto fileManager : fFileManagers ) {
|
||||
for ( const auto& fileManager : fFileManagers ) {
|
||||
if ( ! fileManager ) continue;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write", fileManager->GetFileType(), "files");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "write", fileManager->GetFileType(), "files");
|
||||
|
||||
result = fileManager->WriteFiles();
|
||||
finalResult = result && finalResult;
|
||||
result &= fileManager->WriteFiles();
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("write", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "write", "analysis files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -324,35 +247,21 @@ G4bool G4GenericFileManager::CloseFiles()
|
||||
{
|
||||
// Close all files regeistered with objects
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("close", "files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "close", "analysis files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
for ( auto fileManager : fFileManagers ) {
|
||||
for ( const auto& fileManager : fFileManagers ) {
|
||||
if ( ! fileManager ) continue;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("close", fileManager->GetFileType(), "files");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "close", fileManager->GetFileType(), "files");
|
||||
|
||||
result = fileManager->CloseFiles();
|
||||
finalResult = result && finalResult;
|
||||
result &= fileManager->CloseFiles();
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("close", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "close", "analysis files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -360,35 +269,34 @@ G4bool G4GenericFileManager::DeleteEmptyFiles()
|
||||
{
|
||||
// Close all files regeistered with objects
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("delete", "empty files", "");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "delete", "empty files");
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
for ( auto fileManager : fFileManagers ) {
|
||||
for ( const auto& fileManager : fFileManagers ) {
|
||||
if ( ! fileManager ) continue;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("delete", fileManager->GetFileType(), "files");
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "delete", fileManager->GetFileType(), "empty files");
|
||||
|
||||
result = fileManager->DeleteEmptyFiles();
|
||||
finalResult = result && finalResult;
|
||||
result &= fileManager->DeleteEmptyFiles();
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()->Message("delete", "empty files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "delete", "empty files", "", result);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4GenericFileManager::Clear()
|
||||
{
|
||||
// Clear files data
|
||||
|
||||
for ( const auto& fileManager : fFileManagers ) {
|
||||
if ( ! fileManager ) continue;
|
||||
|
||||
fileManager->Clear();
|
||||
}
|
||||
UnlockDirectoryNames();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -398,7 +306,7 @@ G4bool G4GenericFileManager::CreateFile(const G4String& fileName)
|
||||
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "CreateFile", "W001", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "CreateFile", fHdf5Warn);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -412,7 +320,7 @@ G4bool G4GenericFileManager::WriteFile(const G4String& fileName)
|
||||
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "WriteFile", "W021", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "WriteFile", fHdf5Warn);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -426,7 +334,7 @@ G4bool G4GenericFileManager::CloseFile(const G4String& fileName)
|
||||
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "CloseFile", "W021", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "CloseFile", fHdf5Warn);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -438,25 +346,48 @@ G4bool G4GenericFileManager::SetIsEmpty(const G4String& fileName, G4bool isEmpty
|
||||
{
|
||||
auto fileManager = GetFileManager(fileName);
|
||||
if ( ! fileManager ) {
|
||||
FileManagerException(fileName, "SetIsEmpty", "W021", fHdf5Warn);
|
||||
FileManagerWarning(fileName, fkClass, "SetIsEmpty", fHdf5Warn);
|
||||
return false;
|
||||
}
|
||||
|
||||
return fileManager->SetIsEmpty(fileName, isEmpty);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericFileManager::SetHistoDirectoryName(const G4String& dirName)
|
||||
{
|
||||
auto result = G4VFileManager::SetHistoDirectoryName(dirName);
|
||||
|
||||
for (auto fileManager : fFileManagers ) {
|
||||
if ( fileManager != nullptr ) {
|
||||
result &= fileManager->SetHistoDirectoryName(dirName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4GenericFileManager::SetNtupleDirectoryName(const G4String& dirName)
|
||||
{
|
||||
auto result = G4VFileManager::SetNtupleDirectoryName(dirName);
|
||||
|
||||
for (auto fileManager : fFileManagers ) {
|
||||
if ( fileManager != nullptr ) {
|
||||
result &= fileManager->SetNtupleDirectoryName(dirName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4GenericFileManager::SetDefaultFileType(const G4String& value)
|
||||
{
|
||||
// Check if value correspond to a valid file type
|
||||
auto output = G4Analysis::GetOutput(value);
|
||||
if ( output == G4AnalysisOutput::kNone ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "The file type " << value << "is not supported." << G4endl
|
||||
<< "The default type " << fDefaultFileType << " will be used.";
|
||||
G4Exception("G4GenericFileManager::SetDeafultFileType",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
Warn("The file type " + value + "is not supported.\n" +
|
||||
"The default type " + fDefaultFileType + " will be used.",
|
||||
fkClass, "SetDeafultFileType");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -464,7 +395,7 @@ void G4GenericFileManager::SetDefaultFileType(const G4String& value)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4VNtupleFileManager>
|
||||
std::shared_ptr<G4VNtupleFileManager>
|
||||
G4GenericFileManager::CreateNtupleFileManager(G4AnalysisOutput output)
|
||||
{
|
||||
if ( ! GetFileManager(output) ) {
|
||||
@@ -480,7 +411,7 @@ G4GenericFileManager::CreateNtupleFileManager(G4AnalysisOutput output)
|
||||
ntupleFileManager->SetFileManager(fCsvFileManager);
|
||||
vNtupleFileManager = ntupleFileManager;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case G4AnalysisOutput::kHdf5: {
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
auto ntupleFileManager = std::make_shared<G4Hdf5NtupleFileManager>(fState);
|
||||
@@ -508,13 +439,9 @@ G4GenericFileManager::CreateNtupleFileManager(G4AnalysisOutput output)
|
||||
}
|
||||
|
||||
if ( ! vNtupleFileManager ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Failed to create ntuple file manager of " << G4Analysis::GetOutputName(output) << " type."
|
||||
<< failure;
|
||||
G4Exception("G4GenericFileManager::CreateNtupleFileManager",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
Warn("Failed to create ntuple file manager of " +
|
||||
G4Analysis::GetOutputName(output) + " type.\n" + failure,
|
||||
fkClass, "CreateNtupleFileManager");
|
||||
}
|
||||
|
||||
return vNtupleFileManager;
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 09/09/2019 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "g4analysis.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4RootAnalysisManager.hh"
|
||||
#include "G4XmlAnalysisManager.hh"
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
#include "G4Hdf5AnalysisManager.hh"
|
||||
#endif
|
||||
#include "G4Exception.hh"
|
||||
|
||||
namespace {
|
||||
|
||||
void DoFatalException(const G4String& outputName)
|
||||
{
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " \"" << outputName << "\" output type is not supported." << G4endl
|
||||
<< " " << "Analysis manager cannot be created.";
|
||||
G4Exception("G4Analysis::ManagerInstance",
|
||||
"Analysis_F002", FatalException, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace G4Analysis
|
||||
{
|
||||
|
||||
G4ToolsAnalysisManager* ManagerInstance(const G4String& outputName)
|
||||
{
|
||||
// Get output type
|
||||
G4AnalysisOutput outputType = GetOutput(outputName, false);
|
||||
if ( outputType == G4AnalysisOutput::kNone ) {
|
||||
DoFatalException(outputName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create the analysis manager of a selected type
|
||||
switch ( outputType ) {
|
||||
case G4AnalysisOutput::kCsv:
|
||||
return G4CsvAnalysisManager::Instance();
|
||||
break;
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
case G4AnalysisOutput::kHdf5:
|
||||
return G4Hdf5AnalysisManager::Instance();
|
||||
break;
|
||||
#endif
|
||||
case G4AnalysisOutput::kRoot:
|
||||
return G4RootAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kXml:
|
||||
return G4XmlAnalysisManager::Instance();
|
||||
break;
|
||||
case G4AnalysisOutput::kNone:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// should never reach this line
|
||||
DoFatalException(outputName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user