Import Geant4 10.7.0 source tree
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
#include <memory>
|
||||
|
||||
class G4CsvFileManager;
|
||||
class G4CsvNtupleManager;
|
||||
class G4CsvNtupleFileManager;
|
||||
|
||||
class G4CsvAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
@@ -90,12 +90,11 @@ class G4CsvAnalysisManager : public G4ToolsAnalysisManager
|
||||
G4bool WriteH3();
|
||||
G4bool WriteP1();
|
||||
G4bool WriteP2();
|
||||
G4bool CloseNtupleFiles();
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4CsvNtupleManager* fNtupleManager;
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
std::shared_ptr<G4CsvNtupleFileManager> fNtupleFileManager;
|
||||
};
|
||||
|
||||
#include "G4CsvAnalysisManager.icc"
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
//
|
||||
|
||||
#include "G4CsvNtupleManager.hh"
|
||||
#include "G4CsvNtupleFileManager.hh"
|
||||
#include "G4CsvFileManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wcsv_histo"
|
||||
|
||||
@@ -64,7 +66,6 @@ G4bool G4CsvAnalysisManager::WriteT(const std::vector<tools::histo::p1d*>& htVec
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
fFileManager->LockHistoDirectoryName();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -105,7 +106,6 @@ G4bool G4CsvAnalysisManager::WriteT(const std::vector<tools::histo::p2d*>& htVec
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
fFileManager->LockHistoDirectoryName();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -145,7 +145,6 @@ G4bool G4CsvAnalysisManager::WriteT(const std::vector<T*>& htVector,
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName);
|
||||
#endif
|
||||
fFileManager->LockHistoDirectoryName();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -162,28 +161,28 @@ G4bool G4CsvAnalysisManager::IsOpenFileImpl() const
|
||||
inline
|
||||
tools::wcsv::ntuple* G4CsvAnalysisManager::GetNtuple() const
|
||||
{
|
||||
return fNtupleManager->GetNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::wcsv::ntuple* G4CsvAnalysisManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleManager->GetNtuple(ntupleId);
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple(ntupleId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::iterator G4CsvAnalysisManager::BeginNtuple()
|
||||
{
|
||||
return fNtupleManager->BeginNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wcsv::ntuple*>::iterator G4CsvAnalysisManager::EndNtuple()
|
||||
{
|
||||
return fNtupleManager->EndNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->EndNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -191,7 +190,7 @@ inline
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
G4CsvAnalysisManager::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleManager->BeginConstNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginConstNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -199,19 +198,19 @@ inline
|
||||
std::vector<tools::wcsv::ntuple*>::const_iterator
|
||||
G4CsvAnalysisManager::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleManager->EndConstNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->EndConstNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
void G4CsvAnalysisManager::SetIsCommentedHeader(G4bool isCommentedHeader)
|
||||
{
|
||||
fNtupleManager->SetIsCommentedHeader(isCommentedHeader);
|
||||
fNtupleFileManager->GetNtupleManager()->SetIsCommentedHeader(isCommentedHeader);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
void G4CsvAnalysisManager::SetIsHippoHeader(G4bool isHippoHeader)
|
||||
{
|
||||
fNtupleManager->SetIsHippoHeader(isHippoHeader);
|
||||
fNtupleFileManager->GetNtupleManager()->SetIsHippoHeader(isHippoHeader);
|
||||
}
|
||||
|
||||
@@ -31,31 +31,43 @@
|
||||
#ifndef G4CsvFileManager_h
|
||||
#define G4CsvFileManager_h 1
|
||||
|
||||
#include "G4VFileManager.hh"
|
||||
#include "G4VTFileManager.hh"
|
||||
#include "G4TNtupleDescription.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/wcsv_ntuple"
|
||||
|
||||
class G4CsvFileManager : public G4VFileManager
|
||||
// Type aliases
|
||||
using CsvNtupleDescription = G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>;
|
||||
|
||||
class G4CsvFileManager : public G4VTFileManager<std::ofstream>
|
||||
{
|
||||
public:
|
||||
explicit G4CsvFileManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvFileManager();
|
||||
|
||||
// Type aliases
|
||||
using NtupleType = tools::wcsv::ntuple;
|
||||
using NtupleDescriptionType = G4TNtupleDescription<NtupleType>;
|
||||
|
||||
// Methods to manipulate files
|
||||
using G4BaseFileManager::GetNtupleFileName;
|
||||
using G4VTFileManager<std::ofstream>::WriteFile;
|
||||
using G4VTFileManager<std::ofstream>::CloseFile;
|
||||
|
||||
// Methods to manipulate output files
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
virtual G4bool WriteFile() final;
|
||||
virtual G4bool CloseFile() final;
|
||||
|
||||
virtual G4String GetFileType() const final { return "csv"; }
|
||||
|
||||
// Specific methods for files per objects
|
||||
G4bool CreateNtupleFile(NtupleDescriptionType* ntupleDescription);
|
||||
G4bool CloseNtupleFile(NtupleDescriptionType* ntupleDescription);
|
||||
G4bool CreateNtupleFile(CsvNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(CsvNtupleDescription* ntupleDescription);
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
// Utility method
|
||||
G4String GetNtupleFileName(CsvNtupleDescription* ntupleDescription);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// The manager for histogram/profile Csv file output.
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4CsvHnFileManager_h
|
||||
#define G4CsvHnFileManager_h 1
|
||||
|
||||
#include "G4VTHnFileManager.hh"
|
||||
|
||||
class G4CsvFileManager;
|
||||
|
||||
template <typename HT>
|
||||
class G4CsvHnFileManager : public G4VTHnFileManager<HT>
|
||||
|
||||
{
|
||||
public:
|
||||
G4CsvHnFileManager(G4CsvFileManager* fileManger)
|
||||
: G4VTHnFileManager<HT>(), fFileManager(fileManger) {}
|
||||
virtual ~G4CsvHnFileManager() {}
|
||||
|
||||
// Methods for writing objects
|
||||
virtual G4bool WriteExtra(HT* ht, const G4String& htName, const G4String& fileName) final;
|
||||
// Write to the default file (handled with OpenFile()/CloseFile methods)
|
||||
virtual G4bool Write(HT* ht, const G4String& htName, G4String& fileName) final;
|
||||
|
||||
private:
|
||||
// Methods
|
||||
G4bool Write(std::ofstream& hnfile, HT* ht);
|
||||
|
||||
// Data members
|
||||
G4CsvFileManager* fFileManager;
|
||||
};
|
||||
|
||||
#include "G4CsvHnFileManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wcsv_histo"
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
G4bool G4CsvHnFileManager<tools::histo::p1d>::Write(
|
||||
std::ofstream& hnfile, tools::histo::p1d* ht)
|
||||
{
|
||||
return tools::wcsv::pto(hnfile, ht->s_cls(), *ht);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
G4bool G4CsvHnFileManager<tools::histo::p2d>::Write(
|
||||
std::ofstream& hnfile, tools::histo::p2d* ht)
|
||||
{
|
||||
return tools::wcsv::pto(hnfile, ht->s_cls(), *ht);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4CsvHnFileManager<HT>::Write(
|
||||
std::ofstream& hnfile, HT* ht)
|
||||
{
|
||||
return tools::wcsv::hto(hnfile, ht->s_cls(), *ht);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4CsvHnFileManager<HT>::WriteExtra(
|
||||
HT* ht, const G4String& htName, const G4String& fileName)
|
||||
{
|
||||
// create a new file
|
||||
std::ofstream hnFile(fileName);
|
||||
|
||||
// Do nothing if there is no file
|
||||
if ( ! hnFile.is_open() ) return false;
|
||||
|
||||
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;
|
||||
}
|
||||
hnFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
G4bool G4CsvHnFileManager<HT>::Write(
|
||||
HT* ht, const G4String& htName, G4String& fileName)
|
||||
{
|
||||
if ( fileName.empty() ) {
|
||||
// should not happen
|
||||
G4cerr << "!!! Csv file name not defined." << G4endl;
|
||||
G4cerr << "!!! Write " << htName << " failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hnFile = fFileManager->GetTFile(fileName, false);
|
||||
if ( ! hnFile ) {
|
||||
// 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 ( ! 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);
|
||||
return false;
|
||||
} else {
|
||||
fileName = hnFileName;
|
||||
}
|
||||
}
|
||||
|
||||
return Write(*hnFile, ht);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Manager class for ntuple Csv file output.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4CsvNtupleFileManager_h
|
||||
#define G4CsvNtupleFileManager_h 1
|
||||
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4CsvFileManager;
|
||||
class G4CsvNtupleManager;
|
||||
class G4VNtupleManager;
|
||||
class G4NtupleBookingManager;
|
||||
|
||||
class G4CsvNtupleFileManager : public G4VNtupleFileManager
|
||||
{
|
||||
friend class G4CsvAnalysisManager;
|
||||
|
||||
public:
|
||||
explicit G4CsvNtupleFileManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvNtupleFileManager();
|
||||
|
||||
virtual std::shared_ptr<G4VNtupleManager> CreateNtupleManager() override;
|
||||
|
||||
// Methods to be performed at file management
|
||||
virtual G4bool ActionAtOpenFile(const G4String& fileName) override;
|
||||
virtual G4bool ActionAtWrite() override;
|
||||
virtual G4bool ActionAtCloseFile(G4bool reset) override;
|
||||
virtual G4bool Reset() override;
|
||||
|
||||
void SetFileManager(std::shared_ptr<G4CsvFileManager> fileManager);
|
||||
|
||||
std::shared_ptr<G4CsvNtupleManager> GetNtupleManager() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
G4bool CloseNtupleFiles();
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
std::shared_ptr<G4CsvNtupleManager> fNtupleManager;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void G4CsvNtupleFileManager::SetFileManager(
|
||||
std::shared_ptr<G4CsvFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline std::shared_ptr<G4CsvNtupleManager> G4CsvNtupleFileManager::GetNtupleManager() const
|
||||
{ return fNtupleManager; }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,45 +38,43 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
// Types alias
|
||||
using CsvNtupleDescription = G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>;
|
||||
|
||||
class G4CsvFileManager;
|
||||
|
||||
class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple>
|
||||
class G4CsvNtupleManager : public G4TNtupleManager<tools::wcsv::ntuple,
|
||||
std::ofstream>
|
||||
{
|
||||
friend class G4CsvAnalysisManager;
|
||||
friend class G4CsvNtupleFileManager;
|
||||
|
||||
public:
|
||||
explicit G4CsvNtupleManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvNtupleManager();
|
||||
|
||||
private:
|
||||
// Types alias
|
||||
using NtupleType = tools::wcsv::ntuple;
|
||||
using NtupleDescriptionType = G4TNtupleDescription<NtupleType>;
|
||||
|
||||
// Functions specific to the output type
|
||||
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4CsvFileManager> fileManager);
|
||||
|
||||
// Access to ntuple vector (needed for Write())
|
||||
const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector() const;
|
||||
const std::vector<CsvNtupleDescription*>& GetNtupleDescriptionVector() const;
|
||||
|
||||
void SetIsCommentedHeader(G4bool isCommentedHeader);
|
||||
void SetIsHippoHeader(G4bool isHippoHeader);
|
||||
|
||||
// Methods from the templated base class
|
||||
//
|
||||
virtual void CreateTNtuple(
|
||||
NtupleDescriptionType* ntupleDescription,
|
||||
const G4String& name, const G4String& title) final;
|
||||
virtual void CreateTNtupleFromBooking(
|
||||
NtupleDescriptionType* ntupleDescription) final;
|
||||
CsvNtupleDescription* ntupleDescription) final;
|
||||
|
||||
virtual void FinishTNtuple(
|
||||
NtupleDescriptionType* ntupleDescription,
|
||||
CsvNtupleDescription* ntupleDescription,
|
||||
G4bool fromBooking) final;
|
||||
|
||||
G4bool WriteHeader(NtupleType* ntuple) const;
|
||||
G4bool WriteHeader(tools::wcsv::ntuple* ntuple) const;
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4CsvFileManager> fFileManager;
|
||||
@@ -90,7 +88,7 @@ inline void
|
||||
G4CsvNtupleManager::SetFileManager(std::shared_ptr<G4CsvFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline const std::vector<G4TNtupleDescription<tools::wcsv::ntuple>*>&
|
||||
inline const std::vector<G4TNtupleDescription<tools::wcsv::ntuple, std::ofstream>*>&
|
||||
G4CsvNtupleManager::GetNtupleDescriptionVector() const
|
||||
{ return fNtupleDescriptionVector; }
|
||||
|
||||
@@ -101,4 +99,3 @@ inline void G4CsvNtupleManager::SetIsHippoHeader(G4bool isHippoHeader)
|
||||
{ fIsHippoHeader = isHippoHeader; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ class G4CsvRFileManager : public G4BaseFileManager
|
||||
explicit G4CsvRFileManager(const G4AnalysisManagerState& state);
|
||||
~G4CsvRFileManager();
|
||||
|
||||
virtual G4String GetFileType() const final { return "csv"; }
|
||||
|
||||
// Methods to manipulate input files
|
||||
virtual G4bool OpenRFile(const G4String& fileName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user