Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Csv analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -38,17 +38,22 @@
|
||||
#include "tools/wcsv_ntuple"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvAnalysisManager;
|
||||
class G4CsvFileManager;
|
||||
class G4CsvNtupleFileManager;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4CsvAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4CsvAnalysisManager>;
|
||||
|
||||
public:
|
||||
explicit G4CsvAnalysisManager(G4bool isMaster = true);
|
||||
~G4CsvAnalysisManager();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4CsvAnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
@@ -61,40 +66,31 @@ class G4CsvAnalysisManager : public G4ToolsAnalysisManager
|
||||
std::vector<tools::wcsv::ntuple*>::iterator EndNtuple();
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator BeginConstNtuple() const;
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator EndConstNtuple() const;
|
||||
|
||||
|
||||
// Csv format specific option
|
||||
void SetIsCommentedHeader(G4bool isCommentedHeader);
|
||||
void SetIsHippoHeader(G4bool isHippoHeader);
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
// Virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) final;
|
||||
virtual G4bool ResetImpl() final;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
G4CsvAnalysisManager();
|
||||
|
||||
// Static data members
|
||||
//
|
||||
static G4CsvAnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4CsvAnalysisManager* fgInstance;
|
||||
|
||||
// methods
|
||||
//
|
||||
template <typename T>
|
||||
G4bool WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType);
|
||||
G4bool WriteH1();
|
||||
G4bool WriteH2();
|
||||
G4bool WriteH3();
|
||||
G4bool WriteP1();
|
||||
G4bool WriteP2();
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
std::shared_ptr<G4CsvNtupleFileManager> fNtupleFileManager;
|
||||
inline static G4CsvAnalysisManager* fgMasterInstance { nullptr };
|
||||
inline static G4ThreadLocal G4bool fgIsInstance { false };
|
||||
static constexpr std::string_view fkClass { "G4CsvAnalysisManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager { nullptr };
|
||||
std::shared_ptr<G4CsvNtupleFileManager> fNtupleFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4CsvAnalysisManager.icc"
|
||||
|
||||
@@ -27,128 +27,6 @@
|
||||
#include "G4CsvNtupleManager.hh"
|
||||
#include "G4CsvNtupleFileManager.hh"
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wcsv_histo"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
G4bool G4CsvAnalysisManager::WriteT(const std::vector<tools::histo::p1d*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
auto fileName = fFileManager->GetHnFileName(hnType, name);
|
||||
std::ofstream hnFile(fileName);
|
||||
|
||||
// Do nothing if there is no file
|
||||
if ( ! hnFile.is_open() ) return false;
|
||||
|
||||
auto result
|
||||
= tools::wcsv::pto(hnFile, ht->s_cls(), *ht);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
hnFile.close();
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
G4bool G4CsvAnalysisManager::WriteT(const std::vector<tools::histo::p2d*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
auto fileName = fFileManager->GetHnFileName(hnType, name);
|
||||
std::ofstream hnFile(fileName);
|
||||
|
||||
// Do nothing if there is no file
|
||||
if ( ! hnFile.is_open() ) return false;
|
||||
|
||||
auto result
|
||||
= tools::wcsv::pto(hnFile, ht->s_cls(), *ht);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
hnFile.close();
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4CsvAnalysisManager::WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
auto fileName = fFileManager->GetHnFileName(hnType, name);
|
||||
std::ofstream hnFile(fileName);
|
||||
|
||||
// Do nothing if there is no file
|
||||
if ( ! hnFile.is_open() ) return false;
|
||||
|
||||
auto result
|
||||
= tools::wcsv::hto(hnFile, ht->s_cls(), *ht);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
hnFile.close();
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
@@ -162,55 +40,55 @@ inline
|
||||
tools::wcsv::ntuple* G4CsvAnalysisManager::GetNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::wcsv::ntuple* G4CsvAnalysisManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple(ntupleId);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::iterator G4CsvAnalysisManager::BeginNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::iterator G4CsvAnalysisManager::EndNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
G4CsvAnalysisManager::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
G4CsvAnalysisManager::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
void G4CsvAnalysisManager::SetIsCommentedHeader(G4bool isCommentedHeader)
|
||||
{
|
||||
fNtupleFileManager->GetNtupleManager()->SetIsCommentedHeader(isCommentedHeader);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
void G4CsvAnalysisManager::SetIsHippoHeader(G4bool isHippoHeader)
|
||||
{
|
||||
fNtupleFileManager->GetNtupleManager()->SetIsHippoHeader(isHippoHeader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Csv analysis reader.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 05/09/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -35,66 +35,51 @@
|
||||
#include "G4ToolsAnalysisReader.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
#include "tools/rcsv_ntuple"
|
||||
|
||||
class G4H1ToolsManager;
|
||||
class G4H2ToolsManager;
|
||||
class G4H3ToolsManager;
|
||||
class G4P1ToolsManager;
|
||||
class G4P2ToolsManager;
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvAnalysisReader;
|
||||
class G4CsvRNtupleManager;
|
||||
class G4CsvRFileManager;
|
||||
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4CsvAnalysisReader : public G4ToolsAnalysisReader
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4CsvAnalysisReader>;
|
||||
|
||||
public:
|
||||
explicit G4CsvAnalysisReader(G4bool isMaster = true);
|
||||
virtual ~G4CsvAnalysisReader();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4CsvAnalysisReader* Instance();
|
||||
|
||||
// Access methods
|
||||
tools::rcsv::ntuple* GetNtuple() const;
|
||||
tools::rcsv::ntuple* GetNtuple(G4int ntupleId) const;
|
||||
using G4VAnalysisReader::GetNtuple;
|
||||
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
virtual G4int ReadH1Impl(const G4String& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH2Impl(const G4String& h2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH3Impl(const G4String& h3Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP1Impl(const G4String& p1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP2Impl(const G4String& p2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
// Virtual methods from base class
|
||||
virtual G4bool CloseFilesImpl(G4bool reset) final;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
static G4CsvAnalysisReader* fgMasterInstance;
|
||||
static G4ThreadLocal G4CsvAnalysisReader* fgInstance;
|
||||
G4CsvAnalysisReader();
|
||||
|
||||
// methods
|
||||
G4String GetHnFileName(const G4String& hnType,
|
||||
const G4String& hnName,
|
||||
const G4String& baseFileName,
|
||||
G4bool isUserFileName) const;
|
||||
|
||||
// Static data members
|
||||
inline static G4CsvAnalysisReader* fgMasterInstance { nullptr };
|
||||
|
||||
// Methods
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4CsvRNtupleManager* fNtupleManager;
|
||||
G4CsvRFileManager* fFileManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvAnalysisReader" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4CsvRNtupleManager> fNtupleManager { nullptr };
|
||||
std::shared_ptr<G4CsvRFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4CsvAnalysisReader.icc"
|
||||
|
||||
@@ -28,15 +28,16 @@
|
||||
|
||||
#include "G4CsvRNtupleManager.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::rcsv::ntuple* G4CsvAnalysisReader::GetNtuple() const
|
||||
{
|
||||
return fNtupleManager->GetNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::rcsv::ntuple* G4CsvAnalysisReader::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleManager->GetNtuple(ntupleId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
|
||||
#include "tools/wcsv_ntuple"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
// Type aliases
|
||||
using CsvNtupleDescription = G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>;
|
||||
|
||||
@@ -44,8 +46,9 @@ class G4CsvFileManager : public G4VTFileManager<std::ofstream>
|
||||
{
|
||||
public:
|
||||
explicit G4CsvFileManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvFileManager();
|
||||
|
||||
G4CsvFileManager() = delete;
|
||||
~G4CsvFileManager() = default;
|
||||
|
||||
using G4BaseFileManager::GetNtupleFileName;
|
||||
using G4VTFileManager<std::ofstream>::WriteFile;
|
||||
using G4VTFileManager<std::ofstream>::CloseFile;
|
||||
@@ -53,21 +56,42 @@ class G4CsvFileManager : public G4VTFileManager<std::ofstream>
|
||||
// Methods to manipulate output files
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
|
||||
virtual G4bool SetHistoDirectoryName(const G4String& dirName) final;
|
||||
virtual G4bool SetNtupleDirectoryName(const G4String& dirName) final;
|
||||
|
||||
virtual G4String GetFileType() const final { return "csv"; }
|
||||
|
||||
// Specific methods for files per objects
|
||||
G4bool CreateNtupleFile(CsvNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(CsvNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(CsvNtupleDescription* ntupleDescription);
|
||||
|
||||
G4bool IsHistoDirectory() const;
|
||||
G4bool IsNtupleDirectory() const;
|
||||
|
||||
protected:
|
||||
// Methods derived from templated base class
|
||||
virtual std::shared_ptr<std::ofstream> CreateFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
|
||||
private:
|
||||
// Utility method
|
||||
G4String GetNtupleFileName(CsvNtupleDescription* ntupleDescription);
|
||||
G4String GetNtupleFileName(CsvNtupleDescription* ntupleDescription);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvFileManager" };
|
||||
|
||||
// Data members
|
||||
G4bool fIsHistoDirectory { false };
|
||||
G4bool fIsNtupleDirectory { false };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline G4bool G4CsvFileManager::IsHistoDirectory() const
|
||||
{ return fIsHistoDirectory; }
|
||||
|
||||
inline G4bool G4CsvFileManager::IsNtupleDirectory() const
|
||||
{ return fIsNtupleDirectory; }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include "G4VTHnFileManager.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvFileManager;
|
||||
|
||||
template <typename HT>
|
||||
@@ -40,9 +42,10 @@ class G4CsvHnFileManager : public G4VTHnFileManager<HT>
|
||||
|
||||
{
|
||||
public:
|
||||
G4CsvHnFileManager(G4CsvFileManager* fileManger)
|
||||
explicit G4CsvHnFileManager(G4CsvFileManager* fileManger)
|
||||
: G4VTHnFileManager<HT>(), fFileManager(fileManger) {}
|
||||
virtual ~G4CsvHnFileManager() {}
|
||||
G4CsvHnFileManager() = delete;
|
||||
virtual ~G4CsvHnFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
virtual G4bool WriteExtra(HT* ht, const G4String& htName, const G4String& fileName) final;
|
||||
@@ -52,7 +55,10 @@ class G4CsvHnFileManager : public G4VTHnFileManager<HT>
|
||||
private:
|
||||
// Methods
|
||||
G4bool Write(std::ofstream& hnfile, HT* ht);
|
||||
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvHnFileManager" };
|
||||
|
||||
// Data members
|
||||
G4CsvFileManager* fFileManager;
|
||||
};
|
||||
|
||||
@@ -35,8 +35,6 @@
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
@@ -79,12 +77,11 @@ G4bool G4CsvHnFileManager<HT>::WriteExtra(
|
||||
auto result = Write(hnFile, ht);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << G4Analysis::GetHnType<HT>() << " " << htName << " failed";
|
||||
G4Exception("G4CsvAnalysisManager::WriteExtra()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
G4Analysis::Warn(
|
||||
"Saving " + G4Analysis::GetHnType<HT>() + " " + htName + " failed",
|
||||
fkClass, "WriteExtra");
|
||||
return false;
|
||||
}
|
||||
hnFile.close();
|
||||
return true;
|
||||
}
|
||||
@@ -107,14 +104,19 @@ G4bool G4CsvHnFileManager<HT>::Write(
|
||||
// If histogram file name was not defined per object
|
||||
// a file should be created from the provided default file name
|
||||
auto hnFileName = fFileManager->GetHnFileName(G4Analysis::GetHnType<HT>(), htName);
|
||||
|
||||
// If histo directory name is set and if this directory exists
|
||||
// add directory path to hnFileName
|
||||
if ( fFileManager->IsHistoDirectory() ) {
|
||||
hnFileName = "./" + fFileManager->GetHistoDirectoryName() + "/" + hnFileName;
|
||||
}
|
||||
|
||||
if ( ! hnFileName.empty() ) {
|
||||
hnFile = fFileManager->CreateTFile(hnFileName);
|
||||
}
|
||||
|
||||
if ( ! hnFile ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Failed to get Csv file " << fileName;
|
||||
G4Exception("G4CsvHnFileManager<HT>::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
G4Analysis::Warn("Failed to get Csv file " + fileName, fkClass, "Write");
|
||||
return false;
|
||||
} else {
|
||||
fileName = hnFileName;
|
||||
|
||||
+39
-5
@@ -24,13 +24,47 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
|
||||
// The manager class for histogram/profile reading from a Csv file.
|
||||
|
||||
#ifndef g4csv_h
|
||||
#define g4csv_h
|
||||
// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "g4csv_defs.hh"
|
||||
#ifndef G4CsvHnRFileManager_h
|
||||
#define G4CsvHnRFileManager_h 1
|
||||
|
||||
using namespace G4Csv;
|
||||
#include "G4VTHnRFileManager.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvRFileManager;
|
||||
|
||||
template <typename HT>
|
||||
class G4CsvHnRFileManager : public G4VTHnRFileManager<HT>
|
||||
{
|
||||
public:
|
||||
explicit G4CsvHnRFileManager(G4CsvRFileManager* rfileManger)
|
||||
: G4VTHnRFileManager<HT>(), fRFileManager(rfileManger) {}
|
||||
G4CsvHnRFileManager() = delete;
|
||||
virtual ~G4CsvHnRFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
virtual HT* Read(const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
|
||||
private:
|
||||
// Methods
|
||||
G4String GetHnFileName(const G4String& hnType, const G4String& hnName,
|
||||
const G4String& baseFileName, G4bool isUserFileName) const;
|
||||
HT* ReadT(std::istream& hnFile, const G4String& fileName,
|
||||
std::string_view inFunction);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvHnRFileManager<HT>" };
|
||||
// Data members
|
||||
G4CsvRFileManager* fRFileManager;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4CsvHnRFileManager.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/rcsv_histo"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4String G4CsvHnRFileManager<HT>::GetHnFileName(
|
||||
const G4String& hnType, const G4String& hnName,
|
||||
const G4String& fileName, G4bool isUserFileName) const
|
||||
{
|
||||
if ( isUserFileName ) {
|
||||
return fRFileManager->GetFullFileName(fileName);
|
||||
}
|
||||
else {
|
||||
return fRFileManager->GetHnFileName(hnType, hnName);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
HT* G4CsvHnRFileManager<HT>::ReadT(
|
||||
std::istream& htFile, const G4String& fileName, std::string_view inFunction)
|
||||
{
|
||||
tools::rcsv::histo handler(htFile);
|
||||
std::string objectTypeInFile;
|
||||
void* object;
|
||||
auto verbose = false;
|
||||
if ( ! handler.read(G4cout, objectTypeInFile, object, verbose) ) {
|
||||
G4Analysis::Warn(
|
||||
"Cannot get " + G4Analysis::GetHnType<HT>() + " in file " + fileName,
|
||||
fkClass, inFunction);
|
||||
return nullptr;
|
||||
}
|
||||
if ( objectTypeInFile.compare(HT::s_class()) != 0 ) {
|
||||
G4Analysis::Warn(
|
||||
"Object type read in " + G4Analysis::GetHnType<HT>() +" does not match",
|
||||
fkClass, inFunction);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<HT*>(object);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
HT* G4CsvHnRFileManager<HT>::Read(
|
||||
const G4String& htName, const G4String& fileName, const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
// Get file name
|
||||
auto htFileName =
|
||||
GetHnFileName(G4Analysis::GetHnType<HT>(), htName, fileName, isUserFileName);
|
||||
|
||||
// Update directory path
|
||||
if ( ! dirName.empty() ) {
|
||||
htFileName = "./" + dirName + "/" + htFileName;
|
||||
}
|
||||
|
||||
std::ifstream htFile(htFileName);
|
||||
if ( ! htFile.is_open() ) {
|
||||
G4Analysis::Warn("Cannot open file " + htFileName, fkClass, "Read");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto ht = ReadT(htFile, htFileName, "Read");
|
||||
return ht;
|
||||
}
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvFileManager;
|
||||
class G4CsvNtupleManager;
|
||||
class G4VNtupleManager;
|
||||
@@ -45,7 +47,8 @@ class G4CsvNtupleFileManager : public G4VNtupleFileManager
|
||||
|
||||
public:
|
||||
explicit G4CsvNtupleFileManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvNtupleFileManager();
|
||||
G4CsvNtupleFileManager() = delete;
|
||||
virtual ~G4CsvNtupleFileManager() = default;
|
||||
|
||||
virtual std::shared_ptr<G4VNtupleManager> CreateNtupleManager() override;
|
||||
|
||||
@@ -53,19 +56,22 @@ class G4CsvNtupleFileManager : public G4VNtupleFileManager
|
||||
virtual G4bool ActionAtOpenFile(const G4String& fileName) override;
|
||||
virtual G4bool ActionAtWrite() override;
|
||||
virtual G4bool ActionAtCloseFile(G4bool reset) override;
|
||||
virtual G4bool Reset() override;
|
||||
virtual G4bool Reset() override;
|
||||
|
||||
void SetFileManager(std::shared_ptr<G4CsvFileManager> fileManager);
|
||||
|
||||
std::shared_ptr<G4CsvNtupleManager> GetNtupleManager() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
G4bool CloseNtupleFiles();
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
std::shared_ptr<G4CsvNtupleManager> fNtupleManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvNtupleFileManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager { nullptr };
|
||||
std::shared_ptr<G4CsvNtupleManager> fNtupleManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
@@ -37,21 +37,23 @@
|
||||
#include "tools/wcsv_ntuple"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
// Types alias
|
||||
using CsvNtupleDescription = G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>;
|
||||
|
||||
class G4CsvFileManager;
|
||||
|
||||
class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
std::ofstream>
|
||||
class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
std::ofstream>
|
||||
{
|
||||
friend class G4CsvAnalysisManager;
|
||||
friend class G4CsvNtupleFileManager;
|
||||
|
||||
public:
|
||||
explicit G4CsvNtupleManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvNtupleManager();
|
||||
G4CsvNtupleManager() = delete;
|
||||
virtual ~G4CsvNtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Functions specific to the output type
|
||||
@@ -64,7 +66,7 @@ class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
|
||||
void SetIsCommentedHeader(G4bool isCommentedHeader);
|
||||
void SetIsHippoHeader(G4bool isHippoHeader);
|
||||
|
||||
|
||||
// Methods from the templated base class
|
||||
//
|
||||
virtual void CreateTNtupleFromBooking(
|
||||
@@ -73,22 +75,25 @@ class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
virtual void FinishTNtuple(
|
||||
CsvNtupleDescription* ntupleDescription,
|
||||
G4bool fromBooking) final;
|
||||
|
||||
|
||||
G4bool WriteHeader(tools::wcsv::ntuple* ntuple) const;
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvNtupleManager" };
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
G4bool fIsCommentedHeader;
|
||||
G4bool fIsHippoHeader;
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager { nullptr };
|
||||
G4bool fIsCommentedHeader { true };
|
||||
G4bool fIsHippoHeader { false };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void
|
||||
inline void
|
||||
G4CsvNtupleManager::SetFileManager(std::shared_ptr<G4CsvFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline const std::vector<G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>*>&
|
||||
inline const std::vector<G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>*>&
|
||||
G4CsvNtupleManager::GetNtupleDescriptionVector() const
|
||||
{ return fNtupleDescriptionVector; }
|
||||
|
||||
|
||||
@@ -31,29 +31,37 @@
|
||||
#ifndef G4CsvRFileManager_h
|
||||
#define G4CsvRFileManager_h 1
|
||||
|
||||
#include "G4BaseFileManager.hh"
|
||||
#include "G4VRFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string_view>
|
||||
|
||||
class G4AnalysisManagerState;
|
||||
|
||||
class G4CsvRFileManager : public G4BaseFileManager
|
||||
class G4CsvRFileManager : public G4VRFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4CsvRFileManager(const G4AnalysisManagerState& state);
|
||||
G4CsvRFileManager() = delete;
|
||||
~G4CsvRFileManager();
|
||||
|
||||
virtual G4String GetFileType() const final { return "csv"; }
|
||||
|
||||
// Methods from base class
|
||||
virtual void CloseFiles() final {}
|
||||
|
||||
// Methods to manipulate input files
|
||||
virtual G4bool OpenRFile(const G4String& fileName);
|
||||
|
||||
// Specific methods for files per objects
|
||||
std::ifstream* GetRFile(const G4String& fileName) const;
|
||||
|
||||
|
||||
private:
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvRFileManager" };
|
||||
|
||||
// data members
|
||||
std::map<G4String, std::ifstream*> fRFiles;
|
||||
};
|
||||
|
||||
@@ -37,19 +37,38 @@
|
||||
|
||||
#include "tools/rcsv_ntuple"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4CsvRFileManager;
|
||||
|
||||
class G4CsvRNtupleManager : public G4TRNtupleManager<tools::rcsv::ntuple>
|
||||
{
|
||||
friend class G4CsvAnalysisReader;
|
||||
|
||||
protected:
|
||||
public:
|
||||
explicit G4CsvRNtupleManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4CsvRNtupleManager();
|
||||
|
||||
G4CsvRNtupleManager() = delete;
|
||||
virtual ~G4CsvRNtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Methods from the templated base class
|
||||
//
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4CsvRFileManager> fileManager);
|
||||
|
||||
// Methods from the base class
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4bool GetTNtupleRow(G4TRNtupleDescription<tools::rcsv::ntuple>* ntupleDescription) final;
|
||||
};
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4CsvRNtupleManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4CsvRFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
inline void
|
||||
G4CsvRNtupleManager::SetFileManager(std::shared_ptr<G4CsvRFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,20 +30,10 @@
|
||||
#define g4csv_defs_h
|
||||
|
||||
#include "tools/wcsv_ntuple"
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4CsvAnalysisReader.hh"
|
||||
#include "g4hntools_defs.hh"
|
||||
|
||||
namespace G4Csv
|
||||
{
|
||||
// Ntuple types
|
||||
using G4Ntuple = tools::wcsv::ntuple;
|
||||
using G4NtupleIterator = std::vector<tools::wcsv::ntuple*>::iterator;
|
||||
using G4NtupleConstIterator = std::vector<tools::wcsv::ntuple*>::const_iterator;
|
||||
|
||||
// Managers
|
||||
using G4AnalysisManager = G4CsvAnalysisManager;
|
||||
using G4AnalysisReader = G4CsvAnalysisReader;
|
||||
}
|
||||
// Csv output specific types
|
||||
using G4CsvNtuple = tools::wcsv::ntuple;
|
||||
using G4CsvRNtuple = tools::wcsv::ntuple;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user