Import Geant4 10.7.0 source tree

This commit is contained in:
Gabriele Cosmo
2020-12-04 12:30:43 +01:00
parent 67ba86d073
commit dab42d2018
3770 changed files with 226369 additions and 286486 deletions
@@ -119,5 +119,4 @@ inline const G4AnalysisVerbose* G4AnalysisManagerState::GetVerboseL4() const
inline G4int G4AnalysisManagerState::GetCompressionLevel() const
{ return fCompressionLevel; }
#endif
#endif
@@ -63,9 +63,9 @@ class G4AnalysisMessenger : public G4UImessenger
// methods
void SetH1HnManager(G4HnManager& h1HnManager);
void SetH2HnManager(G4HnManager& h2HnManager);
void SetH3HnManager(G4HnManager& h2HnManager);
void SetP1HnManager(G4HnManager& h1HnManager);
void SetP2HnManager(G4HnManager& h2HnManager);
void SetH3HnManager(G4HnManager& h3HnManager);
void SetP1HnManager(G4HnManager& p1HnManager);
void SetP2HnManager(G4HnManager& p2HnManager);
// methods
virtual void SetNewValue(G4UIcommand* command, G4String value) final;
@@ -38,9 +38,7 @@
enum class G4AnalysisOutput {
kCsv,
#ifdef TOOLS_USE_HDF5
kHdf5,
#endif
kRoot,
kXml,
kNone
@@ -90,8 +88,68 @@ std::unique_ptr<T> make_unique(Args&&... args)
// get output type from name
G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn = true);
size_t GetOutputId(const G4String& outputName, G4bool warn = true);
G4String GetOutputName(G4AnalysisOutput outputType);
// get short hnType from the tools object
template <typename HT>
G4String GetHnType()
{
// tools::histo::h1d etc.
G4String hnTypeLong = HT::s_class();
// tools::histo::h1d -> h1 etc.
return hnTypeLong.substr(14, 2);
}
// File names utilities
// Get file base name (without dot)
G4String GetBaseName(const G4String& fileName);
// Get file base extension (without dot)
G4String GetExtension(const G4String& fileName,
const G4String& defaultExtension = "");
// Compose and return the histogram or profile specific file name:
// - add _hn_hnName suffix to the file base name
// - add file extension if not present
G4String GetHnFileName(
const G4String& fileName,
const G4String& fileType,
const G4String& hnType,
const G4String& hnName);
// Compose and return the ntuple specific file name:
// - add _nt_ntupleName suffix to the file base name
// - add _tN suffix if called on thread worker
// - add file extension if not present
G4String GetNtupleFileName(
const G4String& fileName,
const G4String& fileType,
const G4String& ntupleName);
// Compose and return the ntuple specific file name:
// - add _nt_ntupleName suffix to the file base name
// - add _tN suffix if called on thread worker
// - add file extension if not present
G4String GetNtupleFileName(
const G4String& fileName,
const G4String& fileType,
G4int ntupleFileNumber);
// Update file base name with the thread suffix:
// - add _tN suffix if called on thread worker
// - add file extension if not present
G4String GetTnFileName(
const G4String& fileName,
const G4String& fileType);
// Generate plot file name for an output file name
G4String GetPlotFileName(const G4String& fileName);
}
/*
// make possible to print enumerators in class enum as integer
template <typename Enumeration>
@@ -102,10 +160,5 @@ auto as_integer(Enumeration const value)
}
*/
}
#endif
@@ -36,7 +36,7 @@
class G4AnalysisVerbose
{
public:
G4AnalysisVerbose(const G4String& type, G4int verboseLevel);
G4AnalysisVerbose(G4int verboseLevel);
~G4AnalysisVerbose();
void Message(const G4String& action,
@@ -52,7 +52,6 @@ class G4AnalysisVerbose
private:
// data members
//
G4String fType;
G4String fToBeDoneText;
G4String fDoneText;
G4String fFailureText;
@@ -34,6 +34,8 @@
#include "G4AnalysisManagerState.hh"
#include "globals.hh"
#include <vector>
class G4BaseFileManager
{
public:
@@ -42,17 +44,22 @@ class G4BaseFileManager
virtual G4bool SetFileName(const G4String& fileName);
// Set the base file name (without extension)
// If the current file name is already in use
// setting is not performed and false is returned
virtual G4String GetFileType() const;
// Return the manager type (starts with a lowercase letter)
void AddFileName(const G4String& fileName);
// For handling multiple files
// Save file name in a vector if not yet present
G4String GetFileName() const;
// Return the base file name (without extension)
G4String GetFullFileName(const G4String& baseFileName = "",
G4bool isPerThread = true) const;
// Compose and return the full file name:
// - add _tN suffix to the file base name if isPerThread
// - add file extension if not present
// - add file extension if not present and available in state
const std::vector<G4String>& GetFileNames() const;
// Return the file names vector
G4String GetHnFileName(const G4String& hnType,
const G4String& hnName) const;
@@ -74,26 +81,25 @@ class G4BaseFileManager
G4String GetPlotFileName() const;
// Return the file name for batch plotting output
G4String GetFileType() const;
// Return the manager file type (starts with a lowercase letter)
protected:
// utility function
G4String TakeOffExtension(G4String& name) const;
// data members
const G4AnalysisManagerState& fState;
G4String fFileName;
G4String fFileName; // to be changed in fDefaultFileName
std::vector<G4String> fFileNames;
};
inline G4bool G4BaseFileManager::SetFileName(const G4String& fileName) {
// CHECK if still needed in this base class
fFileName = fileName;
return true;
}
inline G4String G4BaseFileManager::GetFileName() const {
return fFileName;
}
#endif
}
inline const std::vector<G4String>& G4BaseFileManager::GetFileNames() const {
return fFileNames;
}
#endif
@@ -25,7 +25,7 @@
//
// The base class for Ntuple managers.
// It implements commen functions independent from the output type.
// It implements common functions independent from the output type.
//
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
@@ -47,33 +47,7 @@ class G4BaseNtupleManager : public G4VNtupleManager
protected:
// Methods for handling ntuples
virtual G4int CreateNtuple(const G4String& name, const G4String& title) = 0;
// Create columns in the last created ntuple
virtual G4int CreateNtupleIColumn(const G4String& name,
std::vector<int>* vector) final;
virtual G4int CreateNtupleFColumn(const G4String& name,
std::vector<float>* vector) final;
virtual G4int CreateNtupleDColumn(const G4String& name,
std::vector<double>* vector) final;
virtual G4int CreateNtupleSColumn(const G4String& name);
virtual void FinishNtuple() final;
// Create columns in the ntuple with given id
virtual G4int CreateNtupleIColumn(G4int ntupleId, const G4String& name,
std::vector<int>* vector) = 0;
virtual G4int CreateNtupleFColumn(G4int ntupleId, const G4String& name,
std::vector<float>* vector) = 0;
virtual G4int CreateNtupleDColumn(G4int ntupleId, const G4String& name,
std::vector<double>* vector) = 0;
virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) = 0;
virtual void FinishNtuple(G4int ntupleId) = 0;
// The ntuple column ids are generated automatically starting from 0;
// with the following function it is possible to change it
// to start from another value
virtual G4bool SetFirstNtupleColumnId(G4int firstId) final;
G4int GetFirstNtupleColumnId() const final;
virtual G4int CreateNtuple(G4NtupleBooking* booking) = 0;
// Methods to fill ntuples
// Methods for ntuple with id = FirstNtupleId
@@ -90,20 +64,13 @@ class G4BaseNtupleManager : public G4VNtupleManager
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
const G4String& value) = 0;
virtual G4bool AddNtupleRow(G4int ntupleId) = 0;
// Fisrt column id
virtual G4bool SetFirstNtupleColumnId(G4int firstId) final;
protected:
G4int fFirstNtupleColumnId;
G4bool fLockFirstNtupleColumnId;
private:
// methods
G4int GetCurrentNtupleId() const;
};
// inline functions
inline G4int G4BaseNtupleManager::GetFirstNtupleColumnId() const {
return fFirstNtupleColumnId;
}
#endif
@@ -100,7 +100,8 @@ class G4HnInformation
fIsLogAxis({ false, false, false }),
fActivation(true),
fAscii(false),
fPlotting(false) { fHnDimensionInformations.reserve(nofDimensions); }
fPlotting(false),
fFileName("") { fHnDimensionInformations.reserve(nofDimensions); }
// Deleted default constructor
G4HnInformation() = delete;
@@ -116,6 +117,7 @@ class G4HnInformation
void SetActivation(G4bool activation);
void SetAscii(G4bool ascii);
void SetPlotting(G4bool plotting);
void SetFileName(G4String fileName);
// Get methods
G4String GetName() const;
@@ -124,6 +126,7 @@ class G4HnInformation
G4bool GetActivation() const;
G4bool GetAscii() const;
G4bool GetPlotting() const;
G4String GetFileName() const;
private:
// Data members
@@ -133,6 +136,7 @@ class G4HnInformation
G4bool fActivation;
G4bool fAscii;
G4bool fPlotting;
G4String fFileName;
};
// inline functions
@@ -175,6 +179,9 @@ inline void G4HnInformation::SetAscii(G4bool ascii)
inline void G4HnInformation::SetPlotting(G4bool plotting)
{ fPlotting = plotting; }
inline void G4HnInformation::SetFileName(G4String fileName)
{ fFileName = fileName; }
inline G4String G4HnInformation::GetName() const
{ return fName; }
@@ -193,4 +200,7 @@ inline G4bool G4HnInformation::GetAscii() const
inline G4bool G4HnInformation::GetPlotting() const
{ return fPlotting; }
#endif
inline G4String G4HnInformation::GetFileName() const
{ return fFileName; }
#endif
@@ -39,6 +39,8 @@
#include <vector>
class G4VFileManager;
class G4HnManager : public G4BaseAnalysisManager
{
public:
@@ -82,13 +84,18 @@ class G4HnManager : public G4BaseAnalysisManager
// return true otherwise
G4bool IsPlotting() const;
// Return false if there is no object with a specific file name
G4bool IsFileName() const;
// Function implementing public analysis manager interface
//
void SetActivation(G4bool activation);
void SetActivation(G4int id, G4bool activation);
void SetAscii(G4int id, G4bool ascii);
void SetPlotting(G4bool plotting);
void SetPlotting(G4int id, G4bool plotting);
void SetPlotting(G4bool plotting);
void SetFileName(G4int id, const G4String& fileName);
void SetFileName(const G4String& fileName);
G4bool SetXAxisIsLog(G4int id, G4bool isLogAxis);
G4bool SetYAxisIsLog(G4int id, G4bool isLogAxis);
G4bool SetZAxisIsLog(G4int id, G4bool isLogAxis);
@@ -105,16 +112,26 @@ class G4HnManager : public G4BaseAnalysisManager
G4bool GetActivation(G4int id) const;
G4bool GetAscii(G4int id) const;
G4bool GetPlotting(G4int id) const;
G4String GetFileName(G4int id) const;
void SetFileManager(std::shared_ptr<G4VFileManager> fileManager);
private:
// Methods
void SetActivation(G4HnInformation* info, G4bool activation);
void SetPlotting(G4HnInformation* info, G4bool plotting);
void SetFileName(G4HnInformation* info, const G4String& fileName);
// Data members
G4String fHnType;
G4int fNofActiveObjects;
G4int fNofAsciiObjects;
G4int fNofPlottingObjects;
G4int fNofFileNameObjects;
// Additional histograms/ntuple properties not included in tools
std::vector<G4HnInformation*> fHnVector;
std::shared_ptr<G4VFileManager> fFileManager;
};
inline G4int G4HnManager::GetNofHns() const
@@ -126,5 +143,8 @@ inline G4String G4HnManager::GetHnType() const
inline const std::vector<G4HnInformation*>& G4HnManager::GetHnVector() const
{ return fHnVector; }
inline void G4HnManager::SetFileManager(std::shared_ptr<G4VFileManager> fileManager)
{ fFileManager = fileManager; }
#endif
@@ -42,6 +42,7 @@ class G4AnalysisMessengerHelper;
class G4UIcommand;
class G4UIcmdWithABool;
class G4UIcmdWithAnInteger;
class G4UIcmdWithAString;
class G4HnMessenger : public G4UImessenger
{
@@ -58,16 +59,20 @@ class G4HnMessenger : public G4UImessenger
void SetHnActivationToAllCmd();
void SetHnPlottingCmd();
void SetHnPlottingToAllCmd();
void SetHnFileNameCmd();
void SetHnFileNameToAllCmd();
G4HnManager& fManager; ///< Associated class
std::unique_ptr<G4AnalysisMessengerHelper> fHelper;
std::unique_ptr<G4UIcmdWithAnInteger> fSetHnAsciiCmd;
std::unique_ptr<G4UIcommand> fSetHnActivationCmd;
std::unique_ptr<G4UIcmdWithABool> fSetHnActivationAllCmd;
std::unique_ptr<G4UIcommand> fSetHnPlottingCmd;
std::unique_ptr<G4UIcmdWithABool> fSetHnPlottingAllCmd;
std::unique_ptr<G4UIcmdWithAnInteger> fSetHnAsciiCmd;
std::unique_ptr<G4UIcommand> fSetHnActivationCmd;
std::unique_ptr<G4UIcmdWithABool> fSetHnActivationAllCmd;
std::unique_ptr<G4UIcommand> fSetHnPlottingCmd;
std::unique_ptr<G4UIcmdWithABool> fSetHnPlottingAllCmd;
std::unique_ptr<G4UIcommand> fSetHnFileNameCmd;
std::unique_ptr<G4UIcmdWithAString> fSetHnFileNameAllCmd;
};
#endif
@@ -0,0 +1,143 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// Class template for ntuple managers for all output types.
//
// Author: Ivana Hrivnacova, 19/06/2015 (ivana@ipno.in2p3.fr)
#ifndef G4NtupleBookingManager_h
#define G4NtupleBookingManager_h 1
#include "G4BaseAnalysisManager.hh"
#include "globals.hh"
#include "tools/ntuple_booking"
#include <vector>
struct G4NtupleBooking
{
G4NtupleBooking()
: fNtupleBooking(),
fFileName(),
fActivation(true) {}
~G4NtupleBooking() {}
tools::ntuple_booking fNtupleBooking;
G4String fFileName;
G4bool fActivation;
};
class G4NtupleBookingManager : public G4BaseAnalysisManager
{
// Disable using the object managers outside G4VAnalysisManager and
// its messenger
friend class G4VAnalysisManager;
public:
explicit G4NtupleBookingManager(const G4AnalysisManagerState& state);
~G4NtupleBookingManager();
const std::vector<G4NtupleBooking*>& GetNtupleBookingVector() const;
// File type
// (only one output file type allowed for ntuples)
void SetFileType(const G4String& fileType);
G4String GetFileType() const;
G4bool IsEmpty() const;
protected:
// Methods to create ntuples
//
G4int CreateNtuple(const G4String& name, const G4String& title);
// Create columns in the last created ntuple (from base class)
// Create columns in the last created ntuple
G4int CreateNtupleIColumn(const G4String& name,
std::vector<int>* vector);
G4int CreateNtupleFColumn(const G4String& name,
std::vector<float>* vector) ;
G4int CreateNtupleDColumn(const G4String& name,
std::vector<double>* vector);
G4int CreateNtupleSColumn(const G4String& name);
G4NtupleBooking* FinishNtuple() ;
// Create columns in the ntuple with given id
G4int CreateNtupleIColumn(G4int ntupleId,
const G4String& name, std::vector<int>* vector);
G4int CreateNtupleFColumn(G4int ntupleId,
const G4String& name, std::vector<float>* vector);
G4int CreateNtupleDColumn(G4int ntupleId,
const G4String& name, std::vector<double>* vector);
G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name);
G4NtupleBooking* FinishNtuple(G4int ntupleId);
// The ntuple column ids are generated automatically starting from 0;
// with the following function it is possible to change it
// to start from another value
G4bool SetFirstNtupleColumnId(G4int firstId);
G4int GetFirstNtupleColumnId() const;
// Activation option
//
void SetActivation(G4bool activation);
void SetActivation(G4int ntupleId, G4bool activation);
G4bool GetActivation(G4int ntupleId) const;
// // File name option
void SetFileName(const G4String& fileName);
void SetFileName(G4int id, const G4String& fileName);
G4String GetFileName(G4int id) const;
// Access methods
G4int GetNofNtupleBookings() const;
// G4int GetNofNtuples() const;
// Data members
std::vector<G4NtupleBooking*> fNtupleBookingVector;
private:
// methods
// Common implementation
G4NtupleBooking* GetNtupleBookingInFunction(
G4int id,
G4String function,
G4bool warn = true) const;
template <typename T>
G4int CreateNtupleTColumn(G4int ntupleId,
const G4String& name, std::vector<T>* vector);
G4int GetCurrentNtupleId() const;
// data members
G4String fFileType;
G4int fFirstNtupleColumnId;
G4bool fLockFirstNtupleColumnId;
};
#include "G4NtupleBookingManager.icc"
#endif
@@ -0,0 +1,106 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
//
// private functions
//
//_____________________________________________________________________________
template <typename T>
G4int G4NtupleBookingManager::CreateNtupleTColumn(
G4int ntupleId, const G4String& name, std::vector<T>* vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("create", "ntuple T column", description);
}
#endif
auto g4NtupleBooking
= GetNtupleBookingInFunction(ntupleId, "CreateNtupleTColumn");
if ( ! g4NtupleBooking ) return G4Analysis::kInvalidId;
// Save column info in booking
auto& ntupleBooking = g4NtupleBooking->fNtupleBooking;
auto index = ntupleBooking.columns().size();
if ( ! vector )
ntupleBooking.template add_column<T>(name);
else
ntupleBooking.template add_column<T>(name, *vector);
// Create column if ntuple already exists
// CreateTColumnInNtuple<T>(ntupleBooking, name, vector);
fLockFirstNtupleColumnId = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("create", "ntuple T column", description);
}
#endif
return G4int(index + fFirstNtupleColumnId);
}
//_____________________________________________________________________________
inline G4int G4NtupleBookingManager::GetNofNtupleBookings() const
{
return G4int(fNtupleBookingVector.size());
}
//_____________________________________________________________________________
inline G4int G4NtupleBookingManager::GetCurrentNtupleId() const
{
return GetNofNtupleBookings() + fFirstId - 1;
}
//
// public functions
//
//_____________________________________________________________________________
inline const std::vector<G4NtupleBooking*>&
G4NtupleBookingManager::GetNtupleBookingVector() const
{
return fNtupleBookingVector;
}
//_____________________________________________________________________________
inline G4int G4NtupleBookingManager::GetFirstNtupleColumnId() const {
return fFirstNtupleColumnId;
}
//_____________________________________________________________________________
inline G4String G4NtupleBookingManager::GetFileType() const
{
return fFileType;
}
@@ -40,6 +40,7 @@
class G4VAnalysisManager;
class G4UIcommand;
class G4UIcmdWithABool;
class G4UIcmdWithAString;
class G4NtupleMessenger : public G4UImessenger
{
@@ -53,13 +54,17 @@ class G4NtupleMessenger : public G4UImessenger
private:
void SetActivationCmd();
void SetActivationToAllCmd();
void SetFileNameCmd();
void SetFileNameToAllCmd();
G4VAnalysisManager* fManager; ///< Associated class
std::unique_ptr<G4UIdirectory> fNtupleDir;
std::unique_ptr<G4UIcommand> fSetActivationCmd;
std::unique_ptr<G4UIcmdWithABool> fSetActivationAllCmd;
std::unique_ptr<G4UIdirectory> fNtupleDir;
std::unique_ptr<G4UIcommand> fSetActivationCmd;
std::unique_ptr<G4UIcmdWithABool> fSetActivationAllCmd;
std::unique_ptr<G4UIcommand> fSetFileNameCmd;
std::unique_ptr<G4UIcmdWithAString> fSetFileNameAllCmd;
};
#endif
@@ -24,15 +24,36 @@
// ********************************************************************
//
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
// Structure templated containing the information related to an ntuple
// for all output types.
//
// Author: Ivana Hrivnacova, 19/06/2015 (ivana@ipno.in2p3.fr)
#ifndef g4analysis_defs_h
#define g4analysis_defs_h
#ifndef G4TFileInformation_h
#define G4TFileInformation_h 1
#include "g4csv_defs.hh"
#include "g4xml_defs.hh"
#include "g4root_defs.hh"
#include "globals.hh"
#include <memory>
template <typename FT>
struct G4TFileInformation
{
G4TFileInformation(const G4String fileName)
: fFileName(fileName),
fFile(nullptr),
fIsOpen(false),
fIsEmpty(true),
fIsDeleted(false) {}
~G4TFileInformation()
{}
G4String fFileName;
std::shared_ptr<FT> fFile;
G4bool fIsOpen;
G4bool fIsEmpty;
G4bool fIsDeleted;
};
#endif
@@ -0,0 +1,85 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4TFileManager_h
#define G4TFileManager_h 1
#include "G4TFileInformation.hh"
#include <vector>
#include <memory>
template <typename FT>
class G4TFileManager
{
public:
explicit G4TFileManager(const G4AnalysisManagerState& state);
virtual ~G4TFileManager();
// Per file methods
// (implements all tests and warnings, fills the map)
std::shared_ptr<FT> CreateTFile(const G4String& fileName);
G4bool WriteTFile(const G4String& fileName);
G4bool CloseTFile(const G4String& fileName);
G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty);
//
std::shared_ptr<FT> GetTFile(const G4String& fileName, G4bool warn = true) const;
// Methods applied to all registered files
G4bool OpenFiles();
G4bool WriteFiles();
G4bool CloseFiles();
G4bool DeleteEmptyFiles();
protected:
// Methods to be implemented per file type manipulate file
virtual std::shared_ptr<FT> CreateFileImpl(const G4String& fileName) = 0;
virtual G4bool WriteFileImpl(std::shared_ptr<FT> file) = 0;
virtual G4bool CloseFileImpl(std::shared_ptr<FT> file) = 0;
private:
// Methods
void FileNotFoundException(const G4String& fileName,
const G4String& functionName) const;
G4TFileInformation<FT>* GetFileInfoInFunction(const G4String& fileName,
G4String functionName, G4bool warn = true) const;
std::shared_ptr<FT> GetFileInFunction(const G4String& fileName,
G4String functionName, G4bool warn = true) const;
G4bool WriteTFile(std::shared_ptr<FT> file, const G4String& fileName);
G4bool CloseTFile(std::shared_ptr<FT> file, const G4String& fileName);
G4bool DeleteEmptyFile(const G4String& fileName);
// Data members
const G4AnalysisManagerState& fAMState;
std::map<G4String, G4TFileInformation<FT>*> fFileMap;
};
#include "G4TFileManager.icc"
#endif
@@ -0,0 +1,410 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
//_____________________________________________________________________________
template <typename FT>
inline
G4TFileManager<FT>::G4TFileManager(const G4AnalysisManagerState& state)
: fAMState(state)
{}
//_____________________________________________________________________________
template <typename FT>
inline
G4TFileManager<FT>::~G4TFileManager()
{
for ( auto mapElement : fFileMap ) {
delete mapElement.second;
}
}
//
// private functions
//
//_____________________________________________________________________________
template <typename FT>
inline
void
G4TFileManager<FT>::FileNotFoundException(const G4String& fileName,
const G4String& functionName) const
{
G4ExceptionDescription description;
description
<< "Failed to get file " << fileName;
G4Exception(functionName, "Analysis_W011", JustWarning, description);
}
//_____________________________________________________________________________
template <typename FT>
inline
G4TFileInformation<FT>*
G4TFileManager<FT>::GetFileInfoInFunction(const G4String& fileName,
G4String functionName, G4bool warn ) const
{
// Find the file information in the map
auto it = fFileMap.find(fileName);
if ( it == fFileMap.end() ) {
if (warn) {
FileNotFoundException(fileName, functionName);
}
return nullptr;
}
return it->second;
}
//_____________________________________________________________________________
template <typename FT>
inline
std::shared_ptr<FT>
G4TFileManager<FT>::GetFileInFunction(const G4String& fileName,
G4String functionName, G4bool warn) const
{
// Find the file information in the map
auto fileInfo = GetFileInfoInFunction(fileName, functionName, warn);
if (! fileInfo) return nullptr;
// Check if the file is open
if ( ! fileInfo->fFile ) {
if (warn) {
FileNotFoundException(fileName, functionName);
}
return nullptr;
}
return fileInfo->fFile;
}
//_____________________________________________________________________________
template <typename FT>
inline
#ifdef G4VERBOSE
G4bool G4TFileManager<FT>::WriteTFile(std::shared_ptr<FT> file, const G4String& fileName)
#else
G4bool G4TFileManager<FT>::WriteTFile(std::shared_ptr<FT> file, const G4String& /*fileName*/)
#endif
{
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL4() )
fAMState.GetVerboseL4()->Message("write", "file", fileName);
#endif
// Write the found file
auto result = WriteFileImpl(file);
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL1() )
fAMState.GetVerboseL1()->Message("write", "file", fileName);
#endif
return result;
}
//_____________________________________________________________________________
template <typename FT>
inline
#ifdef G4VERBOSE
G4bool G4TFileManager<FT>::CloseTFile(std::shared_ptr<FT> file, const G4String& fileName)
#else
G4bool G4TFileManager<FT>::CloseTFile(std::shared_ptr<FT> file, const G4String& /*fileName*/)
#endif
{
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL4() )
fAMState.GetVerboseL4()->Message("close", "file", fileName);
#endif
// Close the found file
auto result = CloseFileImpl(file);
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL1() )
fAMState.GetVerboseL1()->Message("close", "file", fileName);
#endif
return result;
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4TFileManager<FT>::DeleteEmptyFile(const G4String& fileName)
{
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL4() ) {
fAMState.GetVerboseL4()->Message("delete", "empty file", fileName);
}
#endif
auto result = ! std::remove(fileName);
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL1() ) {
fAMState.GetVerboseL1()->Message("delete", "empty file", fileName, result);
}
#endif
return result;
}
//
// public functions
//
//_____________________________________________________________________________
template <typename FT>
inline
std::shared_ptr<FT> G4TFileManager<FT>::CreateTFile(const G4String& fileName)
{
// Check if file already exists
if ( GetFileInFunction(fileName, "CreateTFile", false) ) {
G4ExceptionDescription description;
description
<< "File " << fileName << " already exists.";
G4Exception("G4TFileManager<FT>::CreateTFile",
"Analysis_W001", JustWarning, description);
// return it->second->fFile;
return nullptr;
}
auto fileInformation = GetFileInfoInFunction(fileName, "CreateTFile", false);
if ( ! fileInformation ) {
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL4() ) {
fAMState.GetVerboseL4()->Message("create", "fileInformation", fileName);
}
#endif
// Create file information and save it in the map
fileInformation = new G4TFileInformation<FT>(fileName);
fFileMap[fileName] = fileInformation;
}
// Create file and save it in fileInformation
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL4() ) {
fAMState.GetVerboseL4()->Message("create", "file", fileName);
}
#endif
// Let concrete class create a file
auto file = CreateFileImpl(fileName);
if ( ! file ) {
G4ExceptionDescription description;
description
<< "Failed to create file " << fileName;
G4Exception("G4TFileManager<FT>::CreateTFile",
"Analysis_W001", JustWarning, description);
return nullptr;
}
// Save file in fileInformation
fileInformation->fFile = file;
fileInformation->fIsOpen = true;
fileInformation->fIsEmpty = true;
fileInformation->fIsDeleted = false;
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL1() ) {
fAMState.GetVerboseL1()->Message("create", "file", fileName);
}
#endif
// Return created file
return file;
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4TFileManager<FT>::WriteTFile(const G4String& fileName)
{
// Find the file in the map
auto file = GetFileInFunction(fileName, "WriteTFile");
// Warning is issued in GetFileInfoFunction
if (! file) return false;
return WriteTFile(file, fileName);
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4TFileManager<FT>::CloseTFile(const G4String& fileName)
{
// Find the file information in the map
auto fileInfo = GetFileInfoInFunction(fileName, "CloseTFile");
// Warning is issued in GetFileInfoFunction
if ( ! fileInfo ) return false;
// Do nothing if file is not open
if ( ! fileInfo->fIsOpen ) return false;
// Get file from the file information
auto file = fileInfo->fFile;
if ( ! file ) {
FileNotFoundException(fileName, "CloseTFile");
return false;
}
auto result = CloseTFile(file, fileName);
// Update the file information
fileInfo->fFile.reset();
fileInfo->fIsOpen = false;
return result;
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4TFileManager<FT>::SetIsEmpty(const G4String& fileName, G4bool isEmpty)
{
// Find the file information in the map
auto fileInfo = GetFileInfoInFunction(fileName, "SetIsEmpty");
// Warning is issued in GetFileFunction
if ( ! fileInfo ) return false;
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL4() ) {
fAMState.GetVerboseL4()->Message("notify not empty", "file", fileName);
}
#endif
// Set notification to file information
if ( fileInfo->fIsEmpty ) {
// do not revert information if file is not empty
fileInfo->fIsEmpty = isEmpty;
}
#ifdef G4VERBOSE
if ( fAMState.GetVerboseL2() ) {
fAMState.GetVerboseL2()->Message("notify not empty", "file", fileName);
}
#endif
return true;
}
//_____________________________________________________________________________
template <typename FT>
inline
std::shared_ptr<FT> G4TFileManager<FT>::GetTFile(
const G4String& fileName, G4bool warn) const
{
// Find the file information in the map
return GetFileInFunction(fileName, "GetTFile", warn);
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4TFileManager<FT>::OpenFiles()
{
bool finalResult = true;
for ( auto mapElement : fFileMap ) {
auto fileInformation = mapElement.second;
// Do nothing if file was open by user explicitly
if ( fileInformation->fFile ) {
G4cout << " ... skipping open file for " << fileInformation->fFileName << G4endl;
continue;
}
auto result = CreateTFile(fileInformation->fFileName);
finalResult = result && finalResult;
}
return finalResult;
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4TFileManager<FT>::WriteFiles()
{
bool finalResult = true;
for ( auto mapElement : fFileMap ) {
auto fileInformation = mapElement.second;
if ( ! fileInformation->fIsOpen ) {
// G4cout << "skipping write for file " << fileInformation->fFileName << G4endl;
continue;
}
auto result = WriteTFile(fileInformation->fFile, fileInformation->fFileName);
finalResult = result && finalResult;
}
return finalResult;
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4TFileManager<FT>::CloseFiles()
{
bool finalResult = true;
for ( auto mapElement : fFileMap ) {
auto fileInformation = mapElement.second;
if ( ! fileInformation->fIsOpen ) {
// G4cout << "skipping close for file " << fileInformation->fFileName << G4endl;
continue;
}
auto result = CloseTFile(fileInformation->fFile, fileInformation->fFileName);
finalResult = result && finalResult;
// Update file information
fileInformation->fFile.reset();
fileInformation->fIsOpen = false;
}
// As the files were set to nullptr, clear should not be needed
// fFileMap.clear();
return finalResult;
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4TFileManager<FT>::DeleteEmptyFiles()
{
bool finalResult = true;
for ( auto mapElement : fFileMap ) {
auto fileInformation = mapElement.second;
if ( (! fileInformation->fIsEmpty) || fileInformation->fIsDeleted ) {
// G4cout << "skipping delete for file " << fileInformation->fFileName << G4endl;
continue;
}
auto result = DeleteEmptyFile(fileInformation->fFileName);
finalResult = result && finalResult;
// Update file information
fileInformation->fIsDeleted = true;
}
return finalResult;
}
@@ -31,6 +31,7 @@
#ifndef G4THnManager_h
#define G4THnManager_h 1
#include "G4Threading.hh"
#include "G4Fcn.hh"
#include "G4BinScheme.hh"
#include "globals.hh"
@@ -55,11 +56,13 @@ class G4THnManager
// Return true if the H1 vector is empty
G4bool IsEmpty() const;
protected:
// Method for merge (MT)
void AddTVector(const std::vector<T*>& tVector);
// New method for merge
void Merge(G4Mutex& mergeMutex, G4THnManager<T>* masterInstance);
protected:
// Iterators
typename std::vector<T*>::iterator BeginT();
typename std::vector<T*>::iterator EndT();
@@ -29,6 +29,7 @@
#include "G4AnalysisManagerState.hh"
#include "G4HnManager.hh"
#include "G4AnalysisUtilities.hh"
#include "G4AutoLock.hh"
#include <iostream>
@@ -135,6 +136,16 @@ void G4THnManager<T>::AddTVector(const std::vector<T*>& tVector)
#endif
}
//_____________________________________________________________________________
template <typename T>
void G4THnManager<T>::Merge(
G4Mutex& mergeMutex, G4THnManager<T>* masterInstance)
{
G4AutoLock lH1(&mergeMutex);
masterInstance->AddTVector(fTVector);
lH1.unlock();
}
//_____________________________________________________________________________
template <typename T>
typename std::vector<T*>::iterator G4THnManager<T>::BeginT()
@@ -32,32 +32,37 @@
#ifndef G4TNtupleDescription_h
#define G4TNtupleDescription_h 1
#include "G4NtupleBookingManager.hh"
#include "globals.hh"
#include "tools/ntuple_booking"
#include <fstream>
template <typename TNTUPLE>
template <typename TN, typename TF>
struct G4TNtupleDescription
{
G4TNtupleDescription()
G4TNtupleDescription(G4NtupleBooking* g4NtupleBooking)
: fFile(nullptr),
fNtuple(nullptr),
fNtupleBooking(),
fActivation(true),
fIsNtupleOwner(true) {}
fNtupleBooking(g4NtupleBooking->fNtupleBooking),
fFileName(g4NtupleBooking->fFileName),
fActivation(g4NtupleBooking->fActivation),
fIsNtupleOwner(true),
fHasFill(false) {}
~G4TNtupleDescription()
{ delete fFile;
if ( fIsNtupleOwner ) delete fNtuple;
{
if ( fIsNtupleOwner ) delete fNtuple;
}
std::ofstream* fFile;
TNTUPLE* fNtuple;
std::shared_ptr<TF> fFile;
TN* fNtuple;
tools::ntuple_booking fNtupleBooking;
G4String fFileName;
G4bool fActivation;
G4bool fIsNtupleOwner;
G4bool fHasFill;
};
#endif
@@ -37,7 +37,8 @@
#include <vector>
template <typename TNTUPLE>
// TN - ntuple type, TF - file type
template <typename TN, typename TF>
class G4TNtupleManager : public G4BaseNtupleManager {
public:
@@ -46,29 +47,15 @@ class G4TNtupleManager : public G4BaseNtupleManager {
protected:
// Methods to manipulate ntuples
virtual void CreateNtuplesFromBooking();
G4bool IsEmpty() const;
virtual G4int CreateNtuple(G4NtupleBooking* ntupleBooking) override;
virtual void CreateNtuplesFromBooking(
const std::vector<G4NtupleBooking*>& ntupleBookings);
// virtual void CreateNtuplesFromBooking();
virtual G4bool Reset(G4bool deleteNtuple);
// Methods to create ntuples
//
virtual G4int CreateNtuple(const G4String& name, const G4String& title) override;
// Create columns in the last created ntuple (from base class)
using G4BaseNtupleManager::CreateNtupleIColumn;
using G4BaseNtupleManager::CreateNtupleFColumn;
using G4BaseNtupleManager::CreateNtupleDColumn;
using G4BaseNtupleManager::CreateNtupleSColumn;
using G4BaseNtupleManager::FinishNtuple;
// Create columns in the ntuple with given id
virtual G4int CreateNtupleIColumn(G4int ntupleId,
const G4String& name, std::vector<int>* vector) final;
virtual G4int CreateNtupleFColumn(G4int ntupleId,
const G4String& name, std::vector<float>* vector) final;
virtual G4int CreateNtupleDColumn(G4int ntupleId,
const G4String& name, std::vector<double>* vector) final;
virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) final;
virtual void FinishNtuple(G4int ntupleId) final;
// are implemented in G4NtupleBookingManager base class
// Methods to fill ntuples
// Methods for ntuple with id = FirstNtupleId (from base class)
@@ -92,49 +79,43 @@ class G4TNtupleManager : public G4BaseNtupleManager {
virtual G4bool GetActivation(G4int ntupleId) const final;
// Access methods
TNTUPLE* GetNtuple() const;
TNTUPLE* GetNtuple(G4int ntupleId) const;
TN* GetNtuple() const;
TN* GetNtuple(G4int ntupleId) const;
virtual G4int GetNofNtuples() const final;
virtual G4int GetNofNtupleBookings() const override;
// Iterators
typename std::vector<TNTUPLE*>::iterator BeginNtuple();
typename std::vector<TNTUPLE*>::iterator EndNtuple();
typename std::vector<TNTUPLE*>::const_iterator BeginConstNtuple() const;
typename std::vector<TNTUPLE*>::const_iterator EndConstNtuple() const;
typename std::vector<TN*>::iterator BeginNtuple();
typename std::vector<TN*>::iterator EndNtuple();
typename std::vector<TN*>::const_iterator BeginConstNtuple() const;
typename std::vector<TN*>::const_iterator EndConstNtuple() const;
// Data members
std::vector<G4TNtupleDescription<TNTUPLE>*> fNtupleDescriptionVector;
std::vector<TNTUPLE*> fNtupleVector;
std::vector<G4TNtupleDescription<TN, TF>*> fNtupleDescriptionVector;
std::vector<TN*> fNtupleVector;
private:
// methods
// Fuctions which are specific to output type
//
virtual void CreateTNtupleFromBooking(
G4TNtupleDescription<TNTUPLE>* ntupleDescription) = 0;
G4TNtupleDescription<TN, TF>* ntupleDescription) = 0;
virtual void FinishTNtuple(
G4TNtupleDescription<TNTUPLE>* ntupleDescription,
G4TNtupleDescription<TN, TF>* ntupleDescription,
G4bool fromBooking) = 0;
// Common implementation
//
G4TNtupleDescription<TNTUPLE>* GetNtupleDescriptionInFunction(G4int id,
G4TNtupleDescription<TN, TF>* GetNtupleDescriptionInFunction(G4int id,
G4String function,
G4bool warn = true) const;
TNTUPLE* GetNtupleInFunction(G4int id,
G4String function,
G4bool warn = true) const;
// template functions for creating/filling ntuple columns
template <typename T>
G4int CreateNtupleTColumn(G4int ntupleId,
const G4String& name, std::vector<T>* vector);
TN* GetNtupleInFunction(G4int id,
G4String function,
G4bool warn = true) const;
// template functions for filling ntuple columns
template <typename T>
G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
};
@@ -32,8 +32,8 @@
//
//_____________________________________________________________________________
template <typename TNTUPLE>
G4TNtupleManager<TNTUPLE>::G4TNtupleManager(
template <typename TN, typename TF>
G4TNtupleManager<TN, TF>::G4TNtupleManager(
const G4AnalysisManagerState& state)
: G4BaseNtupleManager(state),
fNtupleDescriptionVector(),
@@ -41,8 +41,8 @@ G4TNtupleManager<TNTUPLE>::G4TNtupleManager(
{}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4TNtupleManager<TNTUPLE>::~G4TNtupleManager()
template <typename TN, typename TF>
G4TNtupleManager<TN, TF>::~G4TNtupleManager()
{
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
delete ntupleDescription;
@@ -50,11 +50,11 @@ G4TNtupleManager<TNTUPLE>::~G4TNtupleManager()
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4TNtupleDescription<TNTUPLE>*
G4TNtupleManager<TNTUPLE>::GetNtupleDescriptionInFunction(
template <typename TN, typename TF>
G4TNtupleDescription<TN, TF>*
G4TNtupleManager<TN, TF>::GetNtupleDescriptionInFunction(
G4int id, G4String functionName, G4bool warn) const
{
{
auto index = id - fFirstId;
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
if ( warn) {
@@ -66,14 +66,13 @@ G4TNtupleManager<TNTUPLE>::GetNtupleDescriptionInFunction(
}
return nullptr;
}
return fNtupleDescriptionVector[index];
}
//_____________________________________________________________________________
template <typename TNTUPLE>
TNTUPLE*
G4TNtupleManager<TNTUPLE>::GetNtupleInFunction(
template <typename TN, typename TF>
TN* G4TNtupleManager<TN, TF>::GetNtupleInFunction(
G4int id, G4String functionName, G4bool warn) const
{
auto ntupleDescription = GetNtupleDescriptionInFunction(id, functionName);
@@ -94,50 +93,9 @@ G4TNtupleManager<TNTUPLE>::GetNtupleInFunction(
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename TN, typename TF>
template <typename T>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleTColumn(
G4int ntupleId, const G4String& name, std::vector<T>* vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("create", "ntuple T column", description);
}
#endif
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "CreateNtupleTColumn");
if ( ! ntupleDescription ) return G4Analysis::kInvalidId;
// Save column info in booking
auto& ntupleBooking = ntupleDescription->fNtupleBooking;
auto index = ntupleBooking.columns().size();
if ( ! vector )
ntupleBooking.template add_column<T>(name);
else
ntupleBooking.template add_column<T>(name, *vector);
// Create column if ntuple already exists
// CreateTColumnInNtuple<T>(ntupleDescription, name, vector);
fLockFirstNtupleColumnId = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("create", "ntuple T column", description);
}
#endif
return G4int(index + fFirstNtupleColumnId);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
template <typename T>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleTColumn(
G4bool G4TNtupleManager<TN, TF>::FillNtupleTColumn(
G4int ntupleId, G4int columnId, const T& value)
{
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
@@ -162,7 +120,7 @@ G4bool G4TNtupleManager<TNTUPLE>::FillNtupleTColumn(
auto icolumn = ntuple->columns()[index];
// get column and check its type
auto column = dynamic_cast<typename TNTUPLE::template column<T>* >(icolumn);
auto column = dynamic_cast<typename TN::template column<T>* >(icolumn);
if ( ! column ) {
G4ExceptionDescription description;
description << " Column type does not match: "
@@ -191,201 +149,121 @@ G4bool G4TNtupleManager<TNTUPLE>::FillNtupleTColumn(
//
//_____________________________________________________________________________
template <typename TNTUPLE>
void G4TNtupleManager<TNTUPLE>::CreateNtuplesFromBooking()
template <typename TN, typename TF>
G4int G4TNtupleManager<TN, TF>::CreateNtuple(G4NtupleBooking* ntupleBooking)
{
// Create ntuple from ntuple_booking.
// This ntuple id
auto ntupleId = G4int(fNtupleDescriptionVector.size()) + fFirstId;
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
// Create ntuple description from ntuple booking.
auto ntupleDescription = new G4TNtupleDescription<TN, TF>(ntupleBooking);
fNtupleDescriptionVector.push_back(ntupleDescription);
// Do not create ntuple if it is inactivated
if ( fState.GetIsActivation() && ( ! ntupleDescription->fActivation ) ) continue;
// Do not create ntuple if it is inactivated
if ( fState.GetIsActivation() &&
( ! ntupleDescription->fActivation ) ) return G4Analysis::kInvalidId;
// Do not create ntuple if it already exists
if ( ntupleDescription->fNtuple ) continue;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("create from booking", "ntuple",
ntupleDescription->fNtupleBooking.name());
#endif
// create ntuple
CreateTNtupleFromBooking(ntupleDescription);
// finish created ntuple
auto fromBooking = true;
FinishTNtuple(ntupleDescription, fromBooking);
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()
->Message("create from booking", "ntuple",
ntupleDescription->fNtupleBooking.name());
#endif
}
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TNtupleManager<TNTUPLE>::IsEmpty() const
{
return ! fNtupleDescriptionVector.size();
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool
G4TNtupleManager<TNTUPLE>::Reset(G4bool deleteNtuple)
{
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
if ( deleteNtuple ) {
delete ntupleDescription->fNtuple;
}
ntupleDescription->fNtuple = 0;
// Do not create ntuple if it already exists
if ( ntupleDescription->fNtuple ) {
G4ExceptionDescription description;
description
<< "Ntuple " << ntupleId << " already exists.";
G4Exception("G4TNtupleManager::CreateNtuple",
"Analysis_W002", JustWarning, description);
return ntupleId;
}
fNtupleVector.clear();
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("create from booking", "ntuple",
ntupleDescription->fNtupleBooking.name());
#endif
// create ntuple
CreateTNtupleFromBooking(ntupleDescription);
// finish created ntuple
auto fromBooking = true;
FinishTNtuple(ntupleDescription, fromBooking);
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()
->Message("create from booking", "ntuple",
ntupleDescription->fNtupleBooking.name());
#endif
return ntupleId;
}
//_____________________________________________________________________________
template <typename TN, typename TF>
void G4TNtupleManager<TN, TF>::CreateNtuplesFromBooking(
const std::vector<G4NtupleBooking*>& ntupleBookings)
{
// Create ntuple from ntuple bookings.
// Create ntuple descriptions from ntuple booking.
for ( auto ntupleBooking : ntupleBookings ) {
CreateNtuple(ntupleBooking);
}
}
//_____________________________________________________________________________
template <typename TN, typename TF>
G4bool
G4TNtupleManager<TN, TF>::Reset(G4bool /*deleteNtuple*/)
{
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
// if ( deleteNtuple ) {
// delete ntupleDescription->fNtuple;
// }
// ntupleDescription->fNtuple = 0;
delete ntupleDescription;
}
fNtupleDescriptionVector.clear();
fNtupleVector.clear();
return true;
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtuple(
const G4String& name, const G4String& title)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "ntuple", name);
#endif
// Create ntuple description
auto index = fNtupleDescriptionVector.size();
auto ntupleDescription = new G4TNtupleDescription<TNTUPLE>();
fNtupleDescriptionVector.push_back(ntupleDescription);
// Save name & title in ntuple booking
ntupleDescription->fNtupleBooking.set_name(name);
ntupleDescription->fNtupleBooking.set_title(title);
// Create ntuple
// CreateTNtuple(ntupleDescription, name, title);
fLockFirstId = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << index + fFirstId;
fState.GetVerboseL2()->Message("create", "ntuple", description);
}
#endif
return G4int(index + fFirstId);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleIColumn(
G4int ntupleId, const G4String& name, std::vector<int>* vector)
{
return CreateNtupleTColumn<int>(ntupleId, name, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleFColumn(
G4int ntupleId, const G4String& name, std::vector<float>* vector)
{
return CreateNtupleTColumn<float>(ntupleId, name, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleDColumn(
G4int ntupleId, const G4String& name, std::vector<double>* vector)
{
return CreateNtupleTColumn<double>(ntupleId, name, vector);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::CreateNtupleSColumn(
G4int ntupleId, const G4String& name)
{
return CreateNtupleTColumn<std::string>(ntupleId, name, nullptr);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
void G4TNtupleManager<TNTUPLE>::FinishNtuple(
G4int ntupleId)
{
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "FinishNtuple");
if ( ! ntupleDescription ) return;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << ntupleDescription->fNtupleBooking.name() << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("finish", "ntuple", description);
}
#endif
// check that ntuple was really created
// auto ntuple = GetNtupleInFunction(ntupleId, "FinishNtuple", false);
// if ( ! ntuple ) return;
// The test has to be now done in the FinishTNtuple implementations
auto fromBooking = false;
FinishTNtuple(ntupleDescription, fromBooking);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << ntupleDescription->fNtupleBooking.name() << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("finish", "ntuple", description);
}
#endif
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleIColumn(
template <typename TN, typename TF>
G4bool G4TNtupleManager<TN, TF>::FillNtupleIColumn(
G4int ntupleId, G4int columnId, G4int value)
{
return FillNtupleTColumn<int>(ntupleId, columnId, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleFColumn(
template <typename TN, typename TF>
G4bool G4TNtupleManager<TN, TF>::FillNtupleFColumn(
G4int ntupleId, G4int columnId, G4float value)
{
return FillNtupleTColumn<float>(ntupleId, columnId, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleDColumn(
template <typename TN, typename TF>
G4bool G4TNtupleManager<TN, TF>::FillNtupleDColumn(
G4int ntupleId, G4int columnId, G4double value)
{
return FillNtupleTColumn<double>(ntupleId, columnId, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::FillNtupleSColumn(
template <typename TN, typename TF>
G4bool G4TNtupleManager<TN, TF>::FillNtupleSColumn(
G4int ntupleId, G4int columnId, const G4String& value)
{
return FillNtupleTColumn<std::string>(ntupleId, columnId, value);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::AddNtupleRow(
template <typename TN, typename TF>
G4bool G4TNtupleManager<TN, TF>::AddNtupleRow(
G4int ntupleId)
{
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
@@ -401,7 +279,10 @@ G4bool G4TNtupleManager<TNTUPLE>::AddNtupleRow(
}
#endif
auto ntuple = GetNtupleInFunction(ntupleId, "AddNtupleRow");
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "AddNtupleRow");
if ( ! ntupleDescription ) return false;
auto ntuple = ntupleDescription->fNtuple;
if ( ! ntuple ) return false;
auto result = ntuple->add_row();
@@ -413,11 +294,13 @@ G4bool G4TNtupleManager<TNTUPLE>::AddNtupleRow(
"Analysis_W002", JustWarning, description);
}
ntupleDescription->fHasFill = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("add", "ntuple row", description);
fState.GetVerboseL4()->Message("add", "ntuple row", description);
}
#endif
@@ -425,8 +308,8 @@ G4bool G4TNtupleManager<TNTUPLE>::AddNtupleRow(
}
//_____________________________________________________________________________
template <typename TNTUPLE>
void G4TNtupleManager<TNTUPLE>::SetActivation(
template <typename TN, typename TF>
void G4TNtupleManager<TN, TF>::SetActivation(
G4bool activation)
{
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
@@ -435,8 +318,8 @@ void G4TNtupleManager<TNTUPLE>::SetActivation(
}
//_____________________________________________________________________________
template <typename TNTUPLE>
void G4TNtupleManager<TNTUPLE>::SetActivation(
template <typename TN, typename TF>
void G4TNtupleManager<TN, TF>::SetActivation(
G4int ntupleId, G4bool activation)
{
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetActivation");
@@ -446,8 +329,8 @@ void G4TNtupleManager<TNTUPLE>::SetActivation(
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4bool G4TNtupleManager<TNTUPLE>::GetActivation(
template <typename TN, typename TF>
G4bool G4TNtupleManager<TN, TF>::GetActivation(
G4int ntupleId) const
{
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetActivation");
@@ -457,17 +340,17 @@ G4bool G4TNtupleManager<TNTUPLE>::GetActivation(
}
//_____________________________________________________________________________
template <typename TNTUPLE>
TNTUPLE*
G4TNtupleManager<TNTUPLE>::GetNtuple() const
template <typename TN, typename TF>
TN*
G4TNtupleManager<TN, TF>::GetNtuple() const
{
return GetNtuple(fFirstId);
}
//_____________________________________________________________________________
template <typename TNTUPLE>
TNTUPLE*
G4TNtupleManager<TNTUPLE>::GetNtuple(G4int ntupleId) const
template <typename TN, typename TF>
TN*
G4TNtupleManager<TN, TF>::GetNtuple(G4int ntupleId) const
{
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetNtuple");
if ( ! ntupleDescription ) return nullptr;
@@ -476,47 +359,40 @@ G4TNtupleManager<TNTUPLE>::GetNtuple(G4int ntupleId) const
}
//_____________________________________________________________________________
template <typename TNTUPLE>
typename std::vector<TNTUPLE*>::iterator
G4TNtupleManager<TNTUPLE>::BeginNtuple()
template <typename TN, typename TF>
typename std::vector<TN*>::iterator
G4TNtupleManager<TN, TF>::BeginNtuple()
{
return fNtupleVector.begin();
}
//_____________________________________________________________________________
template <typename TNTUPLE>
typename std::vector<TNTUPLE*>::iterator
G4TNtupleManager<TNTUPLE>::EndNtuple()
template <typename TN, typename TF>
typename std::vector<TN*>::iterator
G4TNtupleManager<TN, TF>::EndNtuple()
{
return fNtupleVector.end();
}
//_____________________________________________________________________________
template <typename TNTUPLE>
typename std::vector<TNTUPLE*>::const_iterator
G4TNtupleManager<TNTUPLE>::BeginConstNtuple() const
template <typename TN, typename TF>
typename std::vector<TN*>::const_iterator
G4TNtupleManager<TN, TF>::BeginConstNtuple() const
{
return fNtupleVector.begin();
}
//_____________________________________________________________________________
template <typename TNTUPLE>
typename std::vector<TNTUPLE*>::const_iterator
G4TNtupleManager<TNTUPLE>::EndConstNtuple() const
template <typename TN, typename TF>
typename std::vector<TN*>::const_iterator
G4TNtupleManager<TN, TF>::EndConstNtuple() const
{
return fNtupleVector.end();
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::GetNofNtuples() const
template <typename TN, typename TF>
G4int G4TNtupleManager<TN, TF>::GetNofNtuples() const
{
return G4int(fNtupleVector.size());
}
//_____________________________________________________________________________
template <typename TNTUPLE>
G4int G4TNtupleManager<TNTUPLE>::GetNofNtupleBookings() const
{
return G4int(fNtupleDescriptionVector.size());
}
@@ -46,6 +46,7 @@
class G4AnalysisMessenger;
class G4NtupleBookingManager;
class G4HnManager;
class G4VH1Manager;
class G4VH2Manager;
@@ -71,8 +72,8 @@ class G4VAnalysisManager
// Methods for handling files
G4bool OpenFile(const G4String& fileName = "");
G4bool Write();
G4bool CloseFile(G4bool reset = true);
G4bool Merge(tools::histo::hmpi* hmpi);
G4bool CloseFile(G4bool reset = true);
G4bool Merge(tools::histo::hmpi* hmpi);
G4bool Plot();
G4bool IsOpenFile() const;
@@ -420,29 +421,36 @@ class G4VAnalysisManager
void SetH1Activation(G4int id, G4bool activation);
void SetH1Ascii(G4int id, G4bool ascii);
void SetH1Plotting(G4int id, G4bool plotting);
void SetH1FileName(G4int id, const G4String& fileName);
//
void SetH2Activation(G4bool activation);
void SetH2Activation(G4int id, G4bool activation);
void SetH2Ascii(G4int id, G4bool ascii);
void SetH2Plotting(G4int id, G4bool plotting);
void SetH2FileName(G4int id, const G4String& fileName);
//
void SetH3Activation(G4bool activation);
void SetH3Activation(G4int id, G4bool activation);
void SetH3Ascii(G4int id, G4bool ascii);
void SetH3Plotting(G4int id, G4bool plotting);
void SetH3FileName(G4int id, const G4String& fileName);
//
void SetP1Activation(G4bool activation);
void SetP1Activation(G4int id, G4bool activation);
void SetP1Ascii(G4int id, G4bool ascii);
void SetP1Plotting(G4int id, G4bool plotting);
void SetP1FileName(G4int id, const G4String& fileName);
//
void SetP2Activation(G4bool activation);
void SetP2Activation(G4int id, G4bool activation);
void SetP2Ascii(G4int id, G4bool ascii);
void SetP2Plotting(G4int id, G4bool plotting);
void SetP2FileName(G4int id, const G4String& fileName);
//
void SetNtupleActivation(G4bool activation);
void SetNtupleActivation(G4int id, G4bool activation);
void SetNtupleFileName(const G4String& fileName);
void SetNtupleFileName(G4int id, const G4String& fileName);
// Access to histogram & profiles parameters
@@ -499,6 +507,7 @@ class G4VAnalysisManager
G4bool GetH1Activation(G4int id) const;
G4bool GetH1Ascii(G4int id) const;
G4bool GetH1Plotting(G4int id) const;
G4String GetH1FileName(G4int id) const;
//
G4String GetH2Name(G4int id) const;
G4double GetH2XUnit(G4int id) const;
@@ -531,7 +540,8 @@ class G4VAnalysisManager
G4bool GetP2Plotting(G4int id) const;
//
G4bool GetNtupleActivation(G4int id) const;
G4String GetNtupleFileName(G4int id) const;
// Setters for histogram & profiles attributes for plotting
//
G4bool SetH1Title(G4int id, const G4String& title);
@@ -632,7 +642,7 @@ class G4VAnalysisManager
void SetH3Manager(G4VH3Manager* h3Manager);
void SetP1Manager(G4VP1Manager* p1Manager);
void SetP2Manager(G4VP2Manager* p2Manager);
void SetNtupleManager(G4VNtupleManager* ntupleManager);
void SetNtupleManager(std::shared_ptr<G4VNtupleManager> ntupleManager);
void SetFileManager(std::shared_ptr<G4VFileManager> fileManager);
void SetPlotManager(std::shared_ptr<G4PlotManager> plotManager);
@@ -647,10 +657,12 @@ class G4VAnalysisManager
G4AnalysisManagerState fState;
std::shared_ptr<G4VFileManager> fVFileManager;
std::shared_ptr<G4PlotManager> fPlotManager;
std::shared_ptr<G4NtupleBookingManager> fNtupleBookingManager;
std::shared_ptr<G4VNtupleManager> fVNtupleManager;
private:
// data members
std::unique_ptr<G4AnalysisMessenger> fMessenger;
std::unique_ptr<G4AnalysisMessenger> fMessenger;
std::shared_ptr<G4HnManager> fH1HnManager;
std::shared_ptr<G4HnManager> fH2HnManager;
std::shared_ptr<G4HnManager> fH3HnManager;
@@ -661,8 +673,6 @@ class G4VAnalysisManager
std::unique_ptr<G4VH3Manager> fVH3Manager;
std::unique_ptr<G4VP1Manager> fVP1Manager;
std::unique_ptr<G4VP2Manager> fVP2Manager;
// std::shared_ptr<G4VNtupleManager> fVNtupleManager;
G4VNtupleManager* fVNtupleManager;
};
// inline functions
@@ -25,6 +25,7 @@
//
#include "G4HnManager.hh"
#include "G4NtupleBookingManager.hh"
#include "G4VH1Manager.hh"
#include "G4VH2Manager.hh"
#include "G4VH3Manager.hh"
@@ -713,8 +714,13 @@ G4bool G4VAnalysisManager::GetP2Plotting(G4int id) const
inline
G4bool G4VAnalysisManager::GetNtupleActivation(G4int id) const
{
return fVNtupleManager->GetActivation(id);
}
if ( fVNtupleManager ) {
return fVNtupleManager->GetActivation(id);
} else {
return fNtupleBookingManager->GetActivation(id);
}
}
//_____________________________________________________________________________
inline
@@ -508,7 +508,7 @@ G4int G4VAnalysisReader::GetVerboseLevel() const
inline
G4String G4VAnalysisReader::GetType() const
{
return fState.GetType();
return fFileManager->GetFileType();
}
//_____________________________________________________________________________
@@ -32,61 +32,111 @@
#define G4VFileManager_h 1
#include "G4BaseFileManager.hh"
#include "G4VTHnFileManager.hh"
#include "globals.hh"
namespace tools {
namespace histo {
class h1d;
class h2d;
class h3d;
class p1d;
class p2d;
}
}
class G4VFileManager : public G4BaseFileManager
{
public:
explicit G4VFileManager(const G4AnalysisManagerState& state);
virtual ~G4VFileManager();
// Methods to manipulate files
// Method to open default file
virtual G4bool OpenFile(const G4String& fileName) = 0;
virtual G4bool WriteFile() = 0;
virtual G4bool CloseFile() = 0;
// Methods for handling files and directories names
//
virtual G4bool SetFileName(const G4String& fileName) final;
void LockHistoDirectoryName();
void LockNtupleDirectoryName();
// Methods applied to file per name
virtual G4bool CreateFile(const G4String& fileName) = 0;
virtual G4bool WriteFile(const G4String& fileName) = 0;
virtual G4bool CloseFile(const G4String& fileName) = 0;
virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) = 0;
// Methods applied to all registered files
virtual G4bool WriteFiles() = 0;
virtual G4bool CloseFiles() = 0;
virtual G4bool DeleteEmptyFiles() = 0;
// Methods for handling files and directories names
virtual G4bool SetFileName(const G4String& fileName) final;
G4bool SetHistoDirectoryName(const G4String& dirName);
G4bool SetNtupleDirectoryName(const G4String& dirName);
G4bool SetNtupleDirectoryName(const G4String& dirName);
void LockDirectoryNames();
G4bool IsOpenFile() const;
G4String GetHistoDirectoryName() const;
G4String GetNtupleDirectoryName() const;
// Access to helpers
template <typename HT>
std::shared_ptr<G4VTHnFileManager<HT>> GetHnFileManager() const;
protected:
// data members
G4bool fIsOpenFile;
G4String fHistoDirectoryName;
G4String fNtupleDirectoryName;
G4bool fLockFileName;
G4bool fLockHistoDirectoryName;
G4bool fLockNtupleDirectoryName;
G4bool fIsOpenFile;
G4bool fLockDirectoryNames;
// FileManagers per object type
std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>> fH1FileManager;
std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>> fH2FileManager;
std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>> fH3FileManager;
std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>> fP1FileManager;
std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>> fP2FileManager;
};
// inline functions
inline void G4VFileManager::LockDirectoryNames()
{ fLockDirectoryNames = true; }
inline G4bool G4VFileManager::IsOpenFile() const
{ return fIsOpenFile; }
inline void G4VFileManager::LockHistoDirectoryName()
{ fLockHistoDirectoryName = true; }
inline G4String G4VFileManager::GetHistoDirectoryName() const
{ return fHistoDirectoryName; }
inline void G4VFileManager::LockNtupleDirectoryName()
{ fLockNtupleDirectoryName = true; }
inline G4String G4VFileManager::GetNtupleDirectoryName() const
{ return fNtupleDirectoryName; }
template <>
inline
std::shared_ptr<G4VTHnFileManager<tools::histo::h1d>>
G4VFileManager::GetHnFileManager<tools::histo::h1d>() const
{ return fH1FileManager; }
inline G4String G4VFileManager::GetHistoDirectoryName() const {
return fHistoDirectoryName;
}
template <>
inline
std::shared_ptr<G4VTHnFileManager<tools::histo::h2d>>
G4VFileManager::GetHnFileManager<tools::histo::h2d>() const
{ return fH2FileManager; }
template <>
inline
std::shared_ptr<G4VTHnFileManager<tools::histo::h3d>>
G4VFileManager::GetHnFileManager<tools::histo::h3d>() const
{ return fH3FileManager; }
template <>
inline
std::shared_ptr<G4VTHnFileManager<tools::histo::p1d>>
G4VFileManager::GetHnFileManager<tools::histo::p1d>() const
{ return fP1FileManager; }
template <>
inline
std::shared_ptr<G4VTHnFileManager<tools::histo::p2d>>
G4VFileManager::GetHnFileManager<tools::histo::p2d>() const
{ return fP2FileManager; }
inline G4String G4VFileManager::GetNtupleDirectoryName() const {
return fNtupleDirectoryName;
}
#endif
@@ -0,0 +1,96 @@
//
// ********************************************************************
// * 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 abstract base class for ntuple file output.
//
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
#ifndef G4VNtupleFileManager_h
#define G4VNtupleFileManager_h 1
#include "G4AnalysisManagerState.hh"
#include "globals.hh"
class G4VNtupleManager;
class G4NtupleBookingManager;
class G4VNtupleFileManager
{
// Disable using the object managers outside G4VAnalysisManager and
// its messenger
friend class G4VAnalysisManager;
public:
explicit G4VNtupleFileManager(const G4AnalysisManagerState& state,
const G4String& fileType);
virtual ~G4VNtupleFileManager();
// deleted copy constructor & assignment operator
G4VNtupleFileManager(const G4VNtupleFileManager& rhs) = delete;
G4VNtupleFileManager& operator=(const G4VNtupleFileManager& rhs) = delete;
// MT/MPI
virtual void SetNtupleMerging(G4bool mergeNtuples,
G4int nofReducedNtupleFiles = 0);
virtual void SetNtupleRowWise(G4bool rowWise, G4bool rowMode = true);
virtual void SetBasketSize(unsigned int basketSize);
virtual void SetBasketEntries(unsigned int basketEntries);
virtual std::shared_ptr<G4VNtupleManager> CreateNtupleManager() = 0;
virtual void SetBookingManager(std::shared_ptr<G4NtupleBookingManager> bookingManager);
// Methods to be performed at file management
virtual G4bool ActionAtOpenFile(const G4String& /*fileName*/) = 0;
virtual G4bool ActionAtWrite() = 0;
virtual G4bool ActionAtCloseFile(G4bool /*reset*/) = 0;
virtual G4bool Reset() = 0;
virtual G4bool IsNtupleMergingSupported() const;
// Get methods
G4String GetFileType() const;
protected:
// static data members
const G4AnalysisManagerState& fState;
G4String fFileType;
std::shared_ptr<G4NtupleBookingManager> fBookingManager;
};
// inline functions
inline void G4VNtupleFileManager::SetBookingManager(
std::shared_ptr<G4NtupleBookingManager> bookingManager)
{ fBookingManager = bookingManager; }
inline G4bool G4VNtupleFileManager::IsNtupleMergingSupported() const {
return false;
}
inline G4String G4VNtupleFileManager::GetFileType() const {
return fFileType;
}
#endif
@@ -37,6 +37,8 @@
#include <vector>
struct G4NtupleBooking;
class G4VNtupleManager : public G4BaseAnalysisManager
{
// Disable using the object managers outside G4VAnalysisManager and
@@ -54,33 +56,33 @@ class G4VNtupleManager : public G4BaseAnalysisManager
protected:
// Methods for handling ntuples
virtual G4int CreateNtuple(const G4String& name, const G4String& title) = 0;
virtual G4int CreateNtuple(G4NtupleBooking* booking) = 0;
// Create columns in the last created ntuple
virtual G4int CreateNtupleIColumn(const G4String& name,
std::vector<int>* vector) = 0;
virtual G4int CreateNtupleFColumn(const G4String& name,
std::vector<float>* vector) = 0;
virtual G4int CreateNtupleDColumn(const G4String& name,
std::vector<double>* vector) = 0;
virtual G4int CreateNtupleSColumn(const G4String& name) = 0;
virtual void FinishNtuple() = 0;
// // Create columns in the last created ntuple
// virtual G4int CreateNtupleIColumn(const G4String& name,
// std::vector<int>* vector) = 0;
// virtual G4int CreateNtupleFColumn(const G4String& name,
// std::vector<float>* vector) = 0;
// virtual G4int CreateNtupleDColumn(const G4String& name,
// std::vector<double>* vector) = 0;
// virtual G4int CreateNtupleSColumn(const G4String& name) = 0;
// virtual void FinishNtuple() = 0;
// Create columns in the ntuple with given id
virtual G4int CreateNtupleIColumn(G4int ntupleId, const G4String& name,
std::vector<int>* vector) = 0;
virtual G4int CreateNtupleFColumn(G4int ntupleId, const G4String& name,
std::vector<float>* vector) = 0;
virtual G4int CreateNtupleDColumn(G4int ntupleId, const G4String& name,
std::vector<double>* vector) = 0;
virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) = 0;
virtual void FinishNtuple(G4int ntupleId) = 0;
// // Create columns in the ntuple with given id
// virtual G4int CreateNtupleIColumn(G4int ntupleId, const G4String& name,
// std::vector<int>* vector) = 0;
// virtual G4int CreateNtupleFColumn(G4int ntupleId, const G4String& name,
// std::vector<float>* vector) = 0;
// virtual G4int CreateNtupleDColumn(G4int ntupleId, const G4String& name,
// std::vector<double>* vector) = 0;
// virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) = 0;
// virtual void FinishNtuple(G4int ntupleId) = 0;
// The ntuple column ids are generated automatically starting from 0;
// with the following function it is possible to change it
// to start from another value
virtual G4bool SetFirstNtupleColumnId(G4int firstId) = 0;
virtual G4int GetFirstNtupleColumnId() const = 0;
// virtual void SetFirstNtupleColumnId(G4int firstId) = 0;
// virtual G4int GetFirstNtupleColumnId() const = 0;
// Methods to fill ntuples
// Methods for ntuple with id = FirstNtupleId
@@ -103,9 +105,17 @@ class G4VNtupleManager : public G4BaseAnalysisManager
virtual void SetActivation(G4int id, G4bool activation) = 0;
virtual G4bool GetActivation(G4int id) const = 0;
// // File name option
// virtual void SetFileName(const G4String& fileName) = 0;
// virtual void SetFileName(G4int id, const G4String& fileName) = 0;
// virtual G4String GetFileName(G4int id) const = 0;
// Access methods
virtual G4int GetNofNtuples() const = 0;
virtual G4int GetNofNtupleBookings() const = 0;
// virtual G4int GetNofNtupleBookings() const = 0;
// Set first column Id
virtual G4bool SetFirstNtupleColumnId(G4int firstId) = 0;
};
#endif
@@ -0,0 +1,141 @@
//
// ********************************************************************
// * 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 common implementaion of G4VFileManager functions via G4TFileManager.
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4VTFileManager_h
#define G4VTFileManager_h 1
#include "G4VFileManager.hh"
#include "G4TNtupleDescription.hh"
#include "G4TFileManager.hh"
#include "globals.hh"
#include "tools/wcsv_ntuple"
template <typename FT>
class G4VTFileManager : public G4VFileManager,
public G4TFileManager<FT>
{
public:
explicit G4VTFileManager(const G4AnalysisManagerState& state)
: G4VFileManager(state), G4TFileManager<FT>(state), fFile(nullptr) {}
~G4VTFileManager() {}
using G4VFileManager::WriteFile;
using G4VFileManager::CloseFile;
// Methods applied to file per name
virtual G4bool CreateFile(const G4String& fileName) final;
virtual G4bool WriteFile(const G4String& fileName) final;
virtual G4bool CloseFile(const G4String& fileName) final;
virtual G4bool SetIsEmpty(const G4String& fileName, G4bool isEmpty) final;
// Methods applied to all registered files
virtual G4bool WriteFiles() final;
virtual G4bool CloseFiles() final;
virtual G4bool DeleteEmptyFiles() final;
// Get method
std::shared_ptr<FT> GetFile() const;
protected:
// Data members
// Default file - created at OpenFile call
std::shared_ptr<FT> fFile;
};
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4VTFileManager<FT>::CreateFile(const G4String& fileName)
{
return (G4TFileManager<FT>::CreateTFile(fileName) != nullptr);
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4VTFileManager<FT>::WriteFile(const G4String& fileName)
{
return G4TFileManager<FT>::WriteTFile(fileName);
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4VTFileManager<FT>::CloseFile(const G4String& fileName)
{
return G4TFileManager<FT>::CloseTFile(fileName);
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4VTFileManager<FT>::SetIsEmpty(const G4String& fileName, G4bool isEmpty)
{
return G4TFileManager<FT>::SetIsEmpty(fileName, isEmpty);
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4VTFileManager<FT>::WriteFiles()
{
return G4TFileManager<FT>::WriteFiles();
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4VTFileManager<FT>::CloseFiles()
{
auto result = G4TFileManager<FT>::CloseFiles();
fIsOpenFile = false;
fFile.reset();
return result;
}
//_____________________________________________________________________________
template <typename FT>
inline
G4bool G4VTFileManager<FT>::DeleteEmptyFiles()
{
return G4TFileManager<FT>::DeleteEmptyFiles();
}
//_____________________________________________________________________________
template <typename FT>
inline std::shared_ptr<FT> G4VTFileManager<FT>::GetFile() const
{
return fFile;
}
#endif
@@ -0,0 +1,53 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// Templated base class for histogram/profile file output.
//
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
#ifndef G4VTHnFileManager_h
#define G4VTHnFileManager_h 1
#include "G4BaseFileManager.hh"
#include "globals.hh"
class G4AnalysisManagerState;
template <typename HT>
class G4VTHnFileManager
{
public:
G4VTHnFileManager() {}
virtual ~G4VTHnFileManager() {}
// Methods for writing objects
// Write a single object to an extra file (the file is closed after write)
virtual G4bool WriteExtra(HT* ht, const G4String& htName, const G4String& fileName) = 0;
// Write to an open file (handled with OpenFile()/CloseFile methods)
virtual G4bool Write(HT* ht, const G4String& htName, G4String& fileName) = 0;
};
#endif