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
|
||||
|
||||
@@ -10,12 +10,13 @@ geant4_add_module(G4csv
|
||||
G4CsvFileManager.hh
|
||||
G4CsvHnFileManager.hh
|
||||
G4CsvHnFileManager.icc
|
||||
G4CsvHnRFileManager.hh
|
||||
G4CsvHnRFileManager.icc
|
||||
G4CsvNtupleFileManager.hh
|
||||
G4CsvNtupleManager.hh
|
||||
G4CsvRFileManager.hh
|
||||
G4CsvRNtupleManager.hh
|
||||
g4csv_defs.hh
|
||||
g4csv.hh
|
||||
SOURCES
|
||||
G4CsvAnalysisManager.cc
|
||||
G4CsvAnalysisReader.cc
|
||||
|
||||
@@ -29,66 +29,33 @@
|
||||
#include "G4CsvAnalysisManager.hh"
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4CsvNtupleFileManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// mutex in a file scope
|
||||
|
||||
namespace {
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH2Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH3Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P1 profiles
|
||||
G4Mutex mergeP1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P2 profiles
|
||||
G4Mutex mergeP2Mutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4CsvAnalysisManager* G4CsvAnalysisManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4CsvAnalysisManager* G4CsvAnalysisManager::fgInstance = nullptr;
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager* G4CsvAnalysisManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4CsvAnalysisManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
static G4ThreadLocalSingleton<G4CsvAnalysisManager> instance;
|
||||
fgIsInstance = true;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::IsInstance()
|
||||
{
|
||||
return ( fgInstance != 0 );
|
||||
}
|
||||
return fgIsInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("Csv", isMaster),
|
||||
fFileManager(nullptr),
|
||||
fNtupleFileManager(nullptr)
|
||||
G4CsvAnalysisManager::G4CsvAnalysisManager()
|
||||
: G4ToolsAnalysisManager("Csv")
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "G4CsvAnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4CsvAnalysisManager::G4CsvAnalysisManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// File Manager
|
||||
fFileManager = std::make_shared<G4CsvFileManager>(fState);
|
||||
@@ -102,151 +69,15 @@ G4CsvAnalysisManager::G4CsvAnalysisManager(G4bool isMaster)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisManager::~G4CsvAnalysisManager()
|
||||
{
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
fgIsInstance = false;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH1()
|
||||
{
|
||||
auto h1Vector = fH1Manager->GetH1Vector();
|
||||
auto hnVector = fH1Manager->GetHnVector();
|
||||
|
||||
if ( ! h1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h1Vector, hnVector, "h1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH1(&mergeH1Mutex);
|
||||
fgMasterInstance->fH1Manager->AddH1Vector(h1Vector);
|
||||
lH1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH2()
|
||||
{
|
||||
auto h2Vector = fH2Manager->GetH2Vector();
|
||||
auto hnVector = fH2Manager->GetHnVector();
|
||||
|
||||
if ( ! h2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h2Vector, hnVector, "h2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH2(&mergeH2Mutex);
|
||||
fgMasterInstance->fH2Manager->AddH2Vector(h2Vector);
|
||||
lH2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteH3()
|
||||
{
|
||||
auto h3Vector = fH3Manager->GetH3Vector();
|
||||
auto hnVector = fH3Manager->GetHnVector();
|
||||
|
||||
if ( ! h3Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(h3Vector, hnVector, "h3");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH3(&mergeH3Mutex);
|
||||
fgMasterInstance->fH3Manager->AddH3Vector(h3Vector);
|
||||
lH3.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteP1()
|
||||
{
|
||||
auto p1Vector = fP1Manager->GetP1Vector();
|
||||
auto hnVector = fP1Manager->GetHnVector();
|
||||
|
||||
if ( ! p1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(p1Vector, hnVector, "p1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP1(&mergeP1Mutex);
|
||||
fgMasterInstance->fP1Manager->AddP1Vector(p1Vector);
|
||||
lP1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteP2()
|
||||
{
|
||||
auto p2Vector = fP2Manager->GetP2Vector();
|
||||
auto hnVector = fP2Manager->GetHnVector();
|
||||
|
||||
if ( ! p2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
result = WriteT(p2Vector, hnVector, "p2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP2(&mergeP2Mutex);
|
||||
fgMasterInstance->fP2Manager->AddP2Vector(p2Vector);
|
||||
lP2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisManager::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleFileManager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
@@ -254,80 +85,43 @@ G4bool G4CsvAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
// and set it to base class which takes then their ownership
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// Save file name in file manager
|
||||
auto result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->OpenFile(fileName);
|
||||
|
||||
// Open ntuple files and create ntuples from bookings
|
||||
result = fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
finalResult = finalResult && result;
|
||||
result &= fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
{
|
||||
// nothing to be done for Csv file
|
||||
auto finalResult = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("write", "files", "");
|
||||
auto result = true;
|
||||
|
||||
Message(kVL4, "write", "files");
|
||||
|
||||
if ( G4Threading::IsWorkerThread() ) {
|
||||
result &= G4ToolsAnalysisManager::Merge();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if ( ! fgMasterInstance &&
|
||||
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ||
|
||||
( ! fH3Manager->IsEmpty() ) || ( ! fP1Manager->IsEmpty() ) ||
|
||||
( ! fP2Manager->IsEmpty() ) ) ) {
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "No master G4CsvAnalysisManager instance exists."
|
||||
<< G4endl
|
||||
<< " " << "Histogram data will not be merged.";
|
||||
G4Exception("G4CsvAnalysisManager::Write()",
|
||||
"Analysis_W031", JustWarning, description);
|
||||
else {
|
||||
// Write all histograms/profile on master
|
||||
result &= G4ToolsAnalysisManager::WriteImpl();
|
||||
}
|
||||
|
||||
// H1
|
||||
auto result = WriteH1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H2
|
||||
result = WriteH2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H3
|
||||
result = WriteH3();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P1
|
||||
result = WriteP1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P2
|
||||
result = WriteP2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// Ntuples
|
||||
// Nothing to be done
|
||||
|
||||
// Write ASCII if activated
|
||||
// Not available
|
||||
// Not available
|
||||
//if ( IsAscii() ) {
|
||||
// result = WriteAscii();
|
||||
//}
|
||||
// result &= WriteAscii();
|
||||
//}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("write", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
Message(kVL3, "write", "files", "", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -335,29 +129,38 @@ G4bool G4CsvAnalysisManager::WriteImpl()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// close open files
|
||||
auto result = fFileManager->CloseFiles();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result &= fFileManager->CloseFiles();
|
||||
|
||||
// Histogram and profile files are created/closed indivudually for each
|
||||
// object in WriteHn{Pn] function
|
||||
|
||||
result = fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
finalResult = finalResult && result;
|
||||
// object in WriteT function
|
||||
|
||||
result &= fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
|
||||
// Reset data
|
||||
if ( reset ) {
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4CsvAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
Warn("Resetting data failed", fkClass, "CloseFileImpl");
|
||||
}
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisManager::ResetImpl()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto result = true;
|
||||
|
||||
result &= G4ToolsAnalysisManager::ResetImpl();
|
||||
if ( fNtupleFileManager != nullptr ) {
|
||||
result &= fNtupleFileManager->Reset();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -29,98 +29,29 @@
|
||||
#include "G4CsvAnalysisReader.hh"
|
||||
#include "G4CsvRFileManager.hh"
|
||||
#include "G4CsvRNtupleManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <tools/aida_ntuple>
|
||||
#include <tools/rcsv_histo>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
G4CsvAnalysisReader* G4CsvAnalysisReader::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4CsvAnalysisReader* G4CsvAnalysisReader::fgInstance = nullptr;
|
||||
|
||||
//
|
||||
// utility functions
|
||||
//
|
||||
|
||||
namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void* ReadObject(std::istream& hnFile,
|
||||
const G4String& objectType,
|
||||
const G4String& fileName,
|
||||
const G4String& inFunction)
|
||||
{
|
||||
tools::rcsv::histo handler(hnFile);
|
||||
std::string objectTypeInFile;
|
||||
void* object;
|
||||
auto verbose = false;
|
||||
if ( ! handler.read(G4cout, objectTypeInFile, object, verbose) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Cannot get "<< objectType << " in file " << fileName;
|
||||
G4String inFunctionFull = "G4CsvAnalysisReader::";
|
||||
inFunctionFull.append(inFunction);
|
||||
G4Exception(inFunctionFull, "Analysis_WR011", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
if ( objectTypeInFile != objectType ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Object type read in "<< fileName
|
||||
<< " does not match" << G4endl;
|
||||
G4String inFunctionFull = "G4CsvAnalysisReader::";
|
||||
inFunctionFull.append(inFunction);
|
||||
G4Exception(inFunctionFull, "Analysis_WR011", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisReader* G4CsvAnalysisReader::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4CsvAnalysisReader(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
static G4ThreadLocalSingleton<G4CsvAnalysisReader> instance;
|
||||
return instance.Instance();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvAnalysisReader::G4CsvAnalysisReader(G4bool isMaster)
|
||||
: G4ToolsAnalysisReader("Csv", isMaster),
|
||||
fNtupleManager(nullptr),
|
||||
fFileManager(nullptr)
|
||||
G4CsvAnalysisReader::G4CsvAnalysisReader()
|
||||
: G4ToolsAnalysisReader("Csv")
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4CsvAnalysisReader already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4CsvAnalysisReader::G4CsvAnalysisReader()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
|
||||
// Create managers
|
||||
fNtupleManager = new G4CsvRNtupleManager(fState);
|
||||
fFileManager = new G4CsvRFileManager(fState);
|
||||
// The managers will be deleted by the base class
|
||||
|
||||
fNtupleManager = std::make_shared<G4CsvRNtupleManager>(fState);
|
||||
fFileManager = std::make_shared<G4CsvRFileManager>(fState);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
|
||||
// Set managers to base class
|
||||
SetNtupleManager(fNtupleManager);
|
||||
SetFileManager(fFileManager);
|
||||
@@ -130,290 +61,43 @@ G4CsvAnalysisReader::G4CsvAnalysisReader(G4bool isMaster)
|
||||
G4CsvAnalysisReader::~G4CsvAnalysisReader()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4CsvAnalysisReader::GetHnFileName(
|
||||
const G4String& hnType,
|
||||
const G4String& hnName,
|
||||
const G4String& fileName,
|
||||
G4bool isUserFileName) const
|
||||
{
|
||||
if ( isUserFileName ) {
|
||||
return fFileManager->GetFullFileName(fileName);
|
||||
}
|
||||
else {
|
||||
return fFileManager->GetHnFileName(hnType, hnName);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvAnalysisReader::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisReader::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleManager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//
|
||||
auto result = true;
|
||||
|
||||
result &= G4ToolsAnalysisReader::Reset();
|
||||
result &= fNtupleManager->Reset();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadH1Impl(const G4String& h1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
G4bool G4CsvAnalysisReader::CloseFilesImpl(G4bool reset)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("get", "h1", h1Name);
|
||||
#endif
|
||||
Message(kVL4, "close", "files");
|
||||
|
||||
// open file
|
||||
auto h1FileName = GetHnFileName("h1", h1Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(h1FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << h1FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadH1Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
auto result = true;
|
||||
|
||||
if (reset) {
|
||||
result &= Reset();
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", h1FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::h1d::s_class(), h1FileName, "ReadH1Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto h1 = static_cast<tools::histo::h1d*>(object);
|
||||
auto id = fH1Manager->AddH1(h1Name, h1);
|
||||
fFileManager->CloseFiles();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
Message(kVL2, "close", "files", "", result);
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadH2Impl(const G4String& h2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h2", h2Name);
|
||||
#endif
|
||||
|
||||
// open file
|
||||
auto h2FileName = GetHnFileName("h2", h2Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(h2FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << h2FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadH2Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", h2FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::h2d::s_class(), h2FileName, "ReadH2Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto h2 = static_cast<tools::histo::h2d*>(object);
|
||||
auto id = fH2Manager->AddH2(h2Name, h2);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadH3Impl(const G4String& h3Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h3", h3Name);
|
||||
#endif
|
||||
|
||||
// open file
|
||||
auto h3FileName = GetHnFileName("h3", h3Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(h3FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << h3FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadH3Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", h3FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::h3d::s_class(), h3FileName, "ReadH3Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto h3 = static_cast<tools::histo::h3d*>(object);
|
||||
auto id = fH3Manager->AddH3(h3Name, h3);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadP1Impl(const G4String& p1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "p1", p1Name);
|
||||
#endif
|
||||
|
||||
// open file
|
||||
G4String p1FileName = GetHnFileName("p1", p1Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(p1FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << p1FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadP1Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", p1FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::p1d::s_class(), fileName, "ReadP1Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto p1 = static_cast<tools::histo::p1d*>(object);
|
||||
auto id = fP1Manager->AddP1(p1Name, p1);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadP2Impl(const G4String& p2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "p2", p2Name);
|
||||
#endif
|
||||
|
||||
// open file
|
||||
G4String p2FileName = GetHnFileName("p2", p2Name, fileName, isUserFileName);
|
||||
std::ifstream hnFile(p2FileName);
|
||||
if ( ! hnFile.is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << p2FileName;
|
||||
G4Exception("G4CsvAnalysisReader::ReadP2Impl()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read file", p2FileName);
|
||||
#endif
|
||||
|
||||
void* object
|
||||
= ReadObject(hnFile, tools::histo::p2d::s_class(), p2FileName, "ReadP2Impl");
|
||||
if ( ! object ) return kInvalidId;
|
||||
|
||||
auto p2 = static_cast<tools::histo::p2d*>(object);
|
||||
auto id = fP2Manager->AddP2(p2Name, p2);
|
||||
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvAnalysisReader::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "ntuple", ntupleName);
|
||||
#endif
|
||||
|
||||
// Ntuples are saved per object and per thread
|
||||
// but apply the ntuple name and the thread suffixes
|
||||
// only if fileName is not provided explicitly
|
||||
G4String fullFileName = fileName;
|
||||
if ( ! isUserFileName ) {
|
||||
fullFileName = fFileManager->GetNtupleFileName(ntupleName);
|
||||
}
|
||||
|
||||
// Open file
|
||||
if ( ! fFileManager->OpenRFile(fullFileName) ) return kInvalidId;
|
||||
auto ntupleFile = fFileManager->GetRFile(fullFileName);
|
||||
|
||||
// Create ntuple
|
||||
auto rntuple = new tools::rcsv::ntuple(*ntupleFile);
|
||||
auto id = fNtupleManager->SetNtuple(new G4TRNtupleDescription<tools::rcsv::ntuple>(rntuple));
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "G4CsvHnFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4Filesystem.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
using namespace tools;
|
||||
@@ -43,14 +44,10 @@ G4CsvFileManager::G4CsvFileManager(const G4AnalysisManagerState& state)
|
||||
fH2FileManager = std::make_shared<G4CsvHnFileManager<histo::h2d>>(this);
|
||||
fH3FileManager = std::make_shared<G4CsvHnFileManager<histo::h3d>>(this);
|
||||
fP1FileManager = std::make_shared<G4CsvHnFileManager<histo::p1d>>(this);
|
||||
fP2FileManager = std::make_shared<G4CsvHnFileManager<histo::p2d>>(this);
|
||||
fP2FileManager = std::make_shared<G4CsvHnFileManager<histo::p2d>>(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvFileManager::~G4CsvFileManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -66,10 +63,15 @@ G4String G4CsvFileManager::GetNtupleFileName(CsvNtupleDescription* ntupleDescrip
|
||||
// compose ntuple file name from the default file name
|
||||
ntupleFileName = GetNtupleFileName(ntupleDescription->fNtupleBooking.name());
|
||||
}
|
||||
return ntupleFileName;
|
||||
}
|
||||
|
||||
//
|
||||
if ( IsNtupleDirectory() ) {
|
||||
ntupleFileName = "./" + GetNtupleDirectoryName() + "/" + ntupleFileName;
|
||||
}
|
||||
|
||||
return ntupleFileName;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
@@ -78,11 +80,7 @@ std::shared_ptr<std::ofstream> G4CsvFileManager::CreateFileImpl(const G4String&
|
||||
{
|
||||
std::shared_ptr<std::ofstream> file = std::make_shared<std::ofstream>(fileName);
|
||||
if ( file->fail() ) {
|
||||
file = nullptr;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot create file " << fileName;
|
||||
G4Exception("G4CsvFileManager::CreateFileImpl()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("Cannot create file " + fileName, fkClass, "CreateFileImpl");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -93,21 +91,21 @@ std::shared_ptr<std::ofstream> G4CsvFileManager::CreateFileImpl(const G4String&
|
||||
G4bool G4CsvFileManager::WriteFileImpl(std::shared_ptr<std::ofstream> /*file*/)
|
||||
{
|
||||
// Nothing to be done here
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::CloseFileImpl(std::shared_ptr<std::ofstream> file)
|
||||
G4bool G4CsvFileManager::CloseFileImpl(std::shared_ptr<std::ofstream> file)
|
||||
{
|
||||
if ( ! file ) return false;
|
||||
|
||||
// close file
|
||||
file->close();
|
||||
file->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
@@ -118,10 +116,40 @@ G4bool G4CsvFileManager::OpenFile(const G4String& fileName)
|
||||
fFileName = fileName;
|
||||
|
||||
fIsOpenFile = true;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::SetHistoDirectoryName(const G4String& dirName)
|
||||
{
|
||||
// A directory is taken into account only if it exists in file system
|
||||
if ( G4fs::is_directory(dirName.data()) ) {
|
||||
fIsHistoDirectory = G4VFileManager::SetHistoDirectoryName(dirName);
|
||||
return fIsHistoDirectory;
|
||||
}
|
||||
|
||||
G4Analysis::Warn("Directory " + dirName + " does not exists.\n"
|
||||
"Histograms will be written in the current directory.",
|
||||
fkClass, "SetHistoDirectoryName");
|
||||
return false;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::SetNtupleDirectoryName(const G4String& dirName)
|
||||
{
|
||||
// A directory is taken into account only if it exists in file system
|
||||
if ( G4fs::is_directory(dirName.data()) ) {
|
||||
fIsNtupleDirectory = G4VFileManager::SetNtupleDirectoryName(dirName);
|
||||
return fIsNtupleDirectory;
|
||||
}
|
||||
|
||||
G4Analysis::Warn("Directory " + dirName + " does not exists.\n"
|
||||
"Ntuples will be written in the current directory.",
|
||||
fkClass, "SetNtupleDirectoryName");
|
||||
return false;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvFileManager::CreateNtupleFile(
|
||||
CsvNtupleDescription* ntupleDescription)
|
||||
@@ -129,11 +157,7 @@ G4bool G4CsvFileManager::CreateNtupleFile(
|
||||
// get ntuple file name per object (if defined)
|
||||
auto ntupleFileName = GetNtupleFileName(ntupleDescription);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("create", "ntuple file", ntupleFileName);
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "create", "ntuple file", ntupleFileName);
|
||||
|
||||
// update file name if it is already in use
|
||||
while ( GetTFile(ntupleFileName, false) ) {
|
||||
@@ -142,23 +166,16 @@ G4bool G4CsvFileManager::CreateNtupleFile(
|
||||
auto newName = GetBaseName(oldName) + "_bis." + GetExtension(oldName);
|
||||
ntupleDescription->fFileName = newName;
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Ntuple filename " << oldName << " is already in use." << G4endl
|
||||
<< "It will be replaced with : " << newName;
|
||||
G4Exception("G4CsvFileManager::CreateFileImpl()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
Warn("Ntuple filename " + oldName + " is already in use.\n" +
|
||||
"It will be replaced with : " + newName,
|
||||
fkClass, "CreateNtupleFile");
|
||||
|
||||
ntupleFileName = GetNtupleFileName(ntupleDescription);
|
||||
}
|
||||
|
||||
ntupleDescription->fFile = CreateTFile(ntupleFileName);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("create", "ntuple file", ntupleFileName);
|
||||
}
|
||||
#endif
|
||||
|
||||
Message(kVL2, "create", "ntuple file", ntupleFileName);
|
||||
|
||||
return (ntupleDescription->fFile != nullptr);
|
||||
}
|
||||
@@ -170,32 +187,21 @@ G4bool G4CsvFileManager::CloseNtupleFile(
|
||||
// Do nothing if there is no file
|
||||
if ( ! ntupleDescription->fFile ) return true;
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
auto ntupleFileName = GetNtupleFileName(ntupleDescription);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4() ->Message("close", "ntuple file", ntupleFileName);
|
||||
}
|
||||
#endif
|
||||
Message(kVL4, "close", "ntuple file", ntupleFileName);
|
||||
|
||||
// close file
|
||||
auto result = CloseTFile(ntupleFileName);
|
||||
finalResult = result && finalResult;
|
||||
|
||||
result &= CloseTFile(ntupleFileName);
|
||||
// Notify not empty file
|
||||
result = SetIsEmpty(ntupleFileName, ! ntupleDescription->fHasFill);
|
||||
finalResult = result && finalResult;
|
||||
result &= SetIsEmpty(ntupleFileName, ! ntupleDescription->fHasFill);
|
||||
|
||||
// Reset file info in ntuple description
|
||||
ntupleDescription->fFile.reset();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("close", "ntuple file", ntupleFileName);
|
||||
}
|
||||
#endif
|
||||
Message(kVL2, "close", "ntuple file", ntupleFileName);
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -32,24 +32,14 @@
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleFileManager::G4CsvNtupleFileManager(const G4AnalysisManagerState& state)
|
||||
: G4VNtupleFileManager(state, "csv"),
|
||||
fFileManager(nullptr),
|
||||
fNtupleManager(nullptr)
|
||||
: G4VNtupleFileManager(state, "csv")
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleFileManager::~G4CsvNtupleFileManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -58,17 +48,16 @@ G4bool G4CsvNtupleFileManager::CloseNtupleFiles()
|
||||
{
|
||||
// Close ntuple files
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
|
||||
for ( auto ntupleDescription : ntupleVector) {
|
||||
auto result = fFileManager->CloseNtupleFile(ntupleDescription);
|
||||
finalResult = finalResult && result;
|
||||
result &= fFileManager->CloseNtupleFile(ntupleDescription);
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
@@ -79,7 +68,7 @@ std::shared_ptr<G4VNtupleManager> G4CsvNtupleFileManager::CreateNtupleManager()
|
||||
|
||||
fNtupleManager = std::make_shared<G4CsvNtupleManager>(fState);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
|
||||
|
||||
return fNtupleManager;
|
||||
}
|
||||
|
||||
@@ -88,7 +77,7 @@ G4bool G4CsvNtupleFileManager::ActionAtOpenFile(const G4String& /*fileName*/)
|
||||
{
|
||||
// G4cout << "G4CsvNtupleFileManager::ActionAtOpenFile" << G4endl;
|
||||
|
||||
// Create ntuples if they are booked
|
||||
// Create ntuples if they are booked
|
||||
// (The files will be created with creating ntuples)
|
||||
fNtupleManager->CreateNtuplesFromBooking(
|
||||
fBookingManager->GetNtupleBookingVector());
|
||||
@@ -105,29 +94,24 @@ G4bool G4CsvNtupleFileManager::ActionAtWrite()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleFileManager::ActionAtCloseFile(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// close ntuple files
|
||||
auto result = CloseNtupleFiles();
|
||||
finalResult = finalResult && result;
|
||||
result &= CloseNtupleFiles();
|
||||
|
||||
if ( ! reset ) {
|
||||
// The ntuples must be always reset when closing file)
|
||||
// The ntuples must be always reset when closing file)
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4CsvNtupleFileManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
Warn("Resetting data failed", fkClass, "ActionAtCloseFile");
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvNtupleFileManager::Reset()
|
||||
{
|
||||
return fNtupleManager->Reset(true);
|
||||
return fNtupleManager->Reset();
|
||||
}
|
||||
|
||||
@@ -31,29 +31,18 @@
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//
|
||||
//
|
||||
// utility methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleManager::G4CsvNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TNtupleManager<tools::wcsv::ntuple, std::ofstream>(state),
|
||||
fFileManager(nullptr),
|
||||
fIsCommentedHeader(true),
|
||||
fIsHippoHeader(false)
|
||||
: G4TNtupleManager<tools::wcsv::ntuple, std::ofstream>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvNtupleManager::~G4CsvNtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
@@ -87,20 +76,14 @@ void G4CsvNtupleManager::FinishTNtuple(
|
||||
|
||||
// Return if creating ntuple failed
|
||||
if ( ! ntupleDescription->fNtuple ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Creating ntuple has failed. ";
|
||||
G4Exception("G4CsvNtupleManager::FinishTNtuple()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
Warn("Creating ntuple has failed.", fkClass, "FinishTNtuple");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Write header if ntuple already exists
|
||||
if ( ! WriteHeader(ntupleDescription->fNtuple) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Writing ntuple header has failed. ";
|
||||
G4Exception("G4CsvNtupleManager::FinishTNtuple()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
Warn("Writing ntuple header has failed.", fkClass, "FinishTNtuple");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,17 +93,17 @@ G4bool G4CsvNtupleManager::WriteHeader(tools::wcsv::ntuple* ntuple) const
|
||||
// Write header if ntuple already exists and if this option is activated.
|
||||
// When both Hippo and Commented headers are selected, only Commented
|
||||
// header, which reading is supported.
|
||||
// Return false only if an error occurred.
|
||||
// Return false only if an error occurred.
|
||||
|
||||
if ( fIsCommentedHeader ) {
|
||||
return ntuple->write_commented_header(G4cout);
|
||||
}
|
||||
|
||||
|
||||
// write hippo header (if activated and if not commented header)
|
||||
if ( fIsHippoHeader ) {
|
||||
ntuple->write_hippo_header();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,73 +27,71 @@
|
||||
// Author: Ivana Hrivnacova, 21/10/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4CsvRFileManager.hh"
|
||||
#include "G4CsvHnRFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
using namespace tools;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvRFileManager::G4CsvRFileManager(const G4AnalysisManagerState& state)
|
||||
: G4BaseFileManager(state),
|
||||
fRFiles()
|
||||
: G4VRFileManager(state)
|
||||
{
|
||||
// Create helpers defined in the base class
|
||||
fH1RFileManager = std::make_shared<G4CsvHnRFileManager<histo::h1d>>(this);
|
||||
fH2RFileManager = std::make_shared<G4CsvHnRFileManager<histo::h2d>>(this);
|
||||
fH3RFileManager = std::make_shared<G4CsvHnRFileManager<histo::h3d>>(this);
|
||||
fP1RFileManager = std::make_shared<G4CsvHnRFileManager<histo::p1d>>(this);
|
||||
fP2RFileManager = std::make_shared<G4CsvHnRFileManager<histo::p2d>>(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvRFileManager::~G4CsvRFileManager()
|
||||
{
|
||||
for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
|
||||
delete fRFiles[i];
|
||||
}
|
||||
{
|
||||
for ( auto& rfile : fRFiles ) {
|
||||
delete rfile.second;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvRFileManager::OpenRFile(const G4String& fileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("open", "read analysis file", fileName);
|
||||
#endif
|
||||
Message(kVL4, "open", "read analysis file", fileName);
|
||||
|
||||
// create new file
|
||||
std::ifstream* newFile = new std::ifstream(fileName);
|
||||
auto newFile = new std::ifstream(fileName);
|
||||
if ( ! newFile->is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << fileName;
|
||||
G4Exception("G4CsvAnalysisReader::OpenRFile()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
Warn("Cannot open file " + fileName, fkClass, "OpenRFile");
|
||||
return false;
|
||||
}
|
||||
|
||||
// add file in a map and delete the previous file if it exists
|
||||
std::map<G4String, std::ifstream*>::iterator it
|
||||
= fRFiles.find(fileName);
|
||||
if ( it != fRFiles.end() ) {
|
||||
auto it = fRFiles.find(fileName);
|
||||
if ( it != fRFiles.end() ) {
|
||||
delete it->second;
|
||||
it->second = newFile;
|
||||
}
|
||||
else {
|
||||
fRFiles[fileName] = newFile;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read analysis file", fileName);
|
||||
#endif
|
||||
Message(kVL1, "open", "read analysis file", fileName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::ifstream* G4CsvRFileManager::GetRFile(const G4String& fileName) const
|
||||
{
|
||||
std::map<G4String, std::ifstream*>::const_iterator it
|
||||
= fRFiles.find(fileName);
|
||||
{
|
||||
auto it = fRFiles.find(fileName);
|
||||
if ( it != fRFiles.end() )
|
||||
return it->second;
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,21 +27,55 @@
|
||||
// Author: Ivana Hrivnacova, 25/07/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4CsvRNtupleManager.hh"
|
||||
#include "G4CsvRFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvRNtupleManager::G4CsvRNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TRNtupleManager<tools::rcsv::ntuple>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4CsvRNtupleManager::~G4CsvRNtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4CsvRNtupleManager::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
Message(kVL4, "read", "ntuple", ntupleName);
|
||||
|
||||
// Ntuples are saved per object and per thread
|
||||
// but apply the ntuple name and the thread suffixes
|
||||
// only if fileName is not provided explicitly
|
||||
G4String fullFileName = fileName;
|
||||
if ( ! isUserFileName ) {
|
||||
fullFileName = fFileManager->GetNtupleFileName(ntupleName);
|
||||
}
|
||||
|
||||
// Update directory path
|
||||
if ( ! dirName.empty() ) {
|
||||
fullFileName = "./" + dirName + "/" + fullFileName;
|
||||
}
|
||||
|
||||
// Open file
|
||||
if ( ! fFileManager->OpenRFile(fullFileName) ) return kInvalidId;
|
||||
auto ntupleFile = fFileManager->GetRFile(fullFileName);
|
||||
|
||||
// Create ntuple
|
||||
auto rntuple = new tools::rcsv::ntuple(*ntupleFile);
|
||||
auto id = SetNtuple(new G4TRNtupleDescription<tools::rcsv::ntuple>(rntuple));
|
||||
|
||||
Message(kVL2, "read", "ntuple", ntupleName, id > kInvalidId);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4CsvRNtupleManager::GetTNtupleRow(
|
||||
G4TRNtupleDescription<tools::rcsv::ntuple>* ntupleDescription)
|
||||
@@ -52,12 +86,7 @@ G4bool G4CsvRNtupleManager::GetTNtupleRow(
|
||||
if ( ! isInitialized ) {
|
||||
auto ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
if ( ! ntuple->initialize(G4cout, *ntupleBinding) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple initialization failed !!";
|
||||
G4Exception("G4CsvRNtuple::GetNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
Warn("Ntuple initialization failed !!", fkClass, "GetTNtupleRow");
|
||||
return false;
|
||||
}
|
||||
ntupleDescription->fIsInitialized = true;
|
||||
@@ -67,15 +96,10 @@ G4bool G4CsvRNtupleManager::GetTNtupleRow(
|
||||
auto next = ntuple->next();
|
||||
if ( next ) {
|
||||
if ( ! ntuple->get_row() ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple get_row() failed !!";
|
||||
G4Exception("G4CsvRNtuple::GetTNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
Warn("Ntuple get_row() failed !!", fkClass, "GetTNtupleRow");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user