Import Geant4 10.7.0 source tree
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+29
-8
@@ -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
|
||||
@@ -29,6 +29,8 @@ geant4_define_module(NAME G4analysismng
|
||||
G4H3Messenger.hh
|
||||
G4P1Messenger.hh
|
||||
G4P2Messenger.hh
|
||||
G4NtupleBookingManager.hh
|
||||
G4NtupleBookingManager.icc
|
||||
G4NtupleMessenger.hh
|
||||
G4HnInformation.hh
|
||||
G4HnManager.hh
|
||||
@@ -36,6 +38,9 @@ geant4_define_module(NAME G4analysismng
|
||||
G4PlotManager.hh
|
||||
G4PlotMessenger.hh
|
||||
G4PlotParameters.hh
|
||||
G4TFileInformation.hh
|
||||
G4TFileManager.hh
|
||||
G4TFileManager.icc
|
||||
G4THnManager.hh
|
||||
G4THnManager.icc
|
||||
G4TNtupleDescription.hh
|
||||
@@ -52,10 +57,13 @@ geant4_define_module(NAME G4analysismng
|
||||
G4VH1Manager.hh
|
||||
G4VH2Manager.hh
|
||||
G4VH3Manager.hh
|
||||
G4VNtupleFileManager.hh
|
||||
G4VNtupleManager.hh
|
||||
G4VP1Manager.hh
|
||||
G4VP2Manager.hh
|
||||
G4VRNtupleManager.hh
|
||||
G4VTFileManager.hh
|
||||
G4VTHnFileManager.hh
|
||||
SOURCES
|
||||
G4AnalysisVerbose.cc
|
||||
G4AnalysisManagerState.cc
|
||||
@@ -74,6 +82,7 @@ geant4_define_module(NAME G4analysismng
|
||||
G4H3Messenger.cc
|
||||
G4P1Messenger.cc
|
||||
G4P2Messenger.cc
|
||||
G4NtupleBookingManager.cc
|
||||
G4NtupleMessenger.cc
|
||||
G4HnManager.cc
|
||||
G4HnMessenger.cc
|
||||
@@ -83,6 +92,7 @@ geant4_define_module(NAME G4analysismng
|
||||
G4VAnalysisManager.cc
|
||||
G4VAnalysisReader.cc
|
||||
G4VFileManager.cc
|
||||
G4VNtupleFileManager.cc
|
||||
GRANULAR_DEPENDENCIES
|
||||
G4globman
|
||||
G4intercoms
|
||||
|
||||
@@ -39,10 +39,10 @@ G4AnalysisManagerState::G4AnalysisManagerState(
|
||||
fIsActivation(false),
|
||||
fVerboseLevel(0),
|
||||
fCompressionLevel(1),
|
||||
fVerboseL1(type,1),
|
||||
fVerboseL2(type,2),
|
||||
fVerboseL3(type,3),
|
||||
fVerboseL4(type,4),
|
||||
fVerboseL1(1),
|
||||
fVerboseL2(2),
|
||||
fVerboseL3(3),
|
||||
fVerboseL4(4),
|
||||
fpVerboseL1(0),
|
||||
fpVerboseL2(0),
|
||||
fpVerboseL3(0),
|
||||
@@ -62,34 +62,33 @@ void G4AnalysisManagerState::SetVerboseLevel(G4int verboseLevel)
|
||||
fVerboseLevel = verboseLevel;
|
||||
|
||||
if ( verboseLevel == 0 ) {
|
||||
fpVerboseL1 = 0;
|
||||
fpVerboseL2 = 0;
|
||||
fpVerboseL3 = 0;
|
||||
fpVerboseL4 = 0;
|
||||
fpVerboseL1 = nullptr;
|
||||
fpVerboseL2 = nullptr;
|
||||
fpVerboseL3 = nullptr;
|
||||
fpVerboseL4 = nullptr;
|
||||
}
|
||||
else if ( verboseLevel == 1 ) {
|
||||
fpVerboseL1 = &fVerboseL1;
|
||||
fpVerboseL2 = 0;
|
||||
fpVerboseL3 = 0;
|
||||
fpVerboseL4 = 0;
|
||||
fpVerboseL2 = nullptr;
|
||||
fpVerboseL3 = nullptr;
|
||||
fpVerboseL4 = nullptr;
|
||||
}
|
||||
else if ( verboseLevel == 2 ) {
|
||||
fpVerboseL1 = &fVerboseL1;
|
||||
fpVerboseL2 = &fVerboseL2;
|
||||
fpVerboseL3 = 0;
|
||||
fpVerboseL4 = 0;
|
||||
fpVerboseL3 = nullptr;
|
||||
fpVerboseL4 = nullptr;
|
||||
}
|
||||
else if ( verboseLevel == 3 ) {
|
||||
fpVerboseL1 = &fVerboseL1;
|
||||
fpVerboseL2 = &fVerboseL2;
|
||||
fpVerboseL3 = &fVerboseL3;
|
||||
fpVerboseL4 = 0;
|
||||
fpVerboseL4 = nullptr;
|
||||
}
|
||||
else {
|
||||
else if ( verboseLevel > 3 ) {
|
||||
fpVerboseL1 = &fVerboseL1;
|
||||
fpVerboseL2 = &fVerboseL2;
|
||||
fpVerboseL3 = &fVerboseL3;
|
||||
fpVerboseL4 = &fVerboseL4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -115,9 +115,9 @@ void G4AnalysisMessenger::SetH2HnManager(G4HnManager& h2HnManager)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4AnalysisMessenger::SetH3HnManager(G4HnManager& h2HnManager)
|
||||
void G4AnalysisMessenger::SetH3HnManager(G4HnManager& h3HnManager)
|
||||
{
|
||||
fH2HnMessenger = G4Analysis::make_unique<G4HnMessenger>(h2HnManager);
|
||||
fH3HnMessenger = G4Analysis::make_unique<G4HnMessenger>(h3HnManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
@@ -348,7 +348,7 @@ void G4AnalysisMessengerHelper::WarnAboutSetCommands() const
|
||||
{
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Command setX, setY, setZ must be called sucessively in this order. " << G4endl
|
||||
<< "Command setX, setY, setZ must be called successively in this order. " << G4endl
|
||||
<< "Command was ignored." << G4endl;
|
||||
G4String methodName(Update("G4UHNTYPE_Messenger::SetNewValue"));
|
||||
G4Exception(methodName,
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "G4BinScheme.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4String.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -190,9 +191,7 @@ void Tokenize(const G4String& line, std::vector<G4String>& tokens)
|
||||
//_____________________________________________________________________________
|
||||
G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn) {
|
||||
if ( outputName == "csv" ) { return G4AnalysisOutput::kCsv; }
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
else if ( outputName == "hdf5" ) { return G4AnalysisOutput::kHdf5; }
|
||||
#endif
|
||||
else if ( outputName == "root" ) { return G4AnalysisOutput::kRoot; }
|
||||
else if ( outputName == "xml" ) { return G4AnalysisOutput::kXml; }
|
||||
else if ( outputName == "none" ) { return G4AnalysisOutput::kNone; }
|
||||
@@ -202,7 +201,7 @@ G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn) {
|
||||
description
|
||||
<< " \"" << outputName << "\" output type is not supported." << G4endl;
|
||||
G4Exception("G4Analysis::GetOutputType",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
"Analysis_W051", JustWarning, description);
|
||||
}
|
||||
return G4AnalysisOutput::kNone;
|
||||
}
|
||||
@@ -214,11 +213,9 @@ G4String GetOutputName(G4AnalysisOutput output) {
|
||||
case G4AnalysisOutput::kCsv:
|
||||
return "csv";
|
||||
break;
|
||||
#ifdef TOOLS_USE_HDF5
|
||||
case G4AnalysisOutput::kHdf5:
|
||||
return "hdf5";
|
||||
break;
|
||||
#endif
|
||||
case G4AnalysisOutput::kRoot:
|
||||
return "root";
|
||||
break;
|
||||
@@ -235,8 +232,171 @@ G4String GetOutputName(G4AnalysisOutput output) {
|
||||
<< " \"" << static_cast<int>(output) << "\" is not handled." << G4endl
|
||||
<< " " << "none type will be used.";
|
||||
G4Exception("G4Analysis::GetOutputName",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
"Analysis_W051", JustWarning, description);
|
||||
return "none";
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String GetBaseName(const G4String& fileName)
|
||||
{
|
||||
// Get file base name (without dot)
|
||||
|
||||
G4String name = fileName;
|
||||
if ( name.rfind(".") != std::string::npos ) {
|
||||
name = name.substr(0, name.rfind("."));
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String GetExtension(const G4String& fileName,
|
||||
const G4String& defaultExtension)
|
||||
{
|
||||
// Get file base extension (without dot)
|
||||
// If fileName is provided without extension, return defaultExtension
|
||||
|
||||
G4String extension;
|
||||
if ( fileName.rfind(".") != std::string::npos ) {
|
||||
extension = fileName.substr(fileName.rfind(".") + 1);
|
||||
}
|
||||
if ( ! extension.size() ) {
|
||||
extension = defaultExtension;
|
||||
}
|
||||
return extension;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String GetHnFileName(
|
||||
const G4String& fileName,
|
||||
const G4String& fileType,
|
||||
const G4String& hnType,
|
||||
const G4String& hnName)
|
||||
{
|
||||
// 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
|
||||
|
||||
auto name = GetBaseName(fileName);
|
||||
|
||||
// Add _hnType_hnName
|
||||
name.append("_");
|
||||
name.append(hnType);
|
||||
name.append("_");
|
||||
name.append(hnName);
|
||||
|
||||
// Add file extension
|
||||
auto extension = GetExtension(fileName, fileType);
|
||||
if ( extension.size() ) {
|
||||
name.append(".");
|
||||
name.append(extension);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
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
|
||||
|
||||
auto name = GetBaseName(fileName);
|
||||
|
||||
// Add ntupleName
|
||||
name.append("_nt_");
|
||||
name.append(ntupleName);
|
||||
|
||||
// Add thread Id to a file name if MT processing
|
||||
if ( ! G4Threading::IsMasterThread() ) {
|
||||
std::ostringstream os;
|
||||
os << G4Threading::G4GetThreadId();
|
||||
name.append("_t");
|
||||
name.append(os.str());
|
||||
}
|
||||
|
||||
// Add file extension
|
||||
auto extension = GetExtension(fileName, fileType);
|
||||
if ( extension.size() ) {
|
||||
name.append(".");
|
||||
name.append(extension);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String GetNtupleFileName(
|
||||
const G4String& fileName,
|
||||
const G4String& fileType,
|
||||
G4int ntupleFileNumber)
|
||||
{
|
||||
// Compose and return the ntuple specific file name:
|
||||
// - add _mFN suffix to the file base name where FN = ntupleFileNumber
|
||||
// - add file extension if not present
|
||||
|
||||
auto name = GetBaseName(fileName);
|
||||
|
||||
// Add _M followed by ntupleFileNumber
|
||||
std::ostringstream os;
|
||||
os << ntupleFileNumber;
|
||||
name.append("_m");
|
||||
name.append(os.str());
|
||||
|
||||
// Add file extension
|
||||
auto extension = GetExtension(fileName, fileType);
|
||||
if ( extension.size() ) {
|
||||
name.append(".");
|
||||
name.append(extension);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String GetTnFileName(
|
||||
const G4String& fileName,
|
||||
const G4String& fileType)
|
||||
{
|
||||
// Update file base name with the thread suffix:
|
||||
// - add _tN suffix if called on thread worker
|
||||
// - add file extension if not present
|
||||
|
||||
auto name = GetBaseName(fileName);
|
||||
|
||||
// Add thread Id to a file name if MT processing
|
||||
if ( ! G4Threading::IsMasterThread() ) {
|
||||
std::ostringstream os;
|
||||
os << G4Threading::G4GetThreadId();
|
||||
name.append("_t");
|
||||
name.append(os.str());
|
||||
}
|
||||
|
||||
// Add file extension
|
||||
auto extension = GetExtension(fileName, fileType);
|
||||
if ( extension.size() ) {
|
||||
name.append(".");
|
||||
name.append(extension);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String GetPlotFileName(const G4String& fileName)
|
||||
{
|
||||
// Generate plot file name for an output file name
|
||||
|
||||
auto name = GetBaseName(fileName);
|
||||
|
||||
// Add .ps extension
|
||||
name.append(".ps");
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,9 +32,8 @@
|
||||
#include <iostream>
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4AnalysisVerbose::G4AnalysisVerbose(const G4String& type, G4int verboseLevel)
|
||||
: fType(type),
|
||||
fToBeDoneText(),
|
||||
G4AnalysisVerbose::G4AnalysisVerbose(G4int verboseLevel)
|
||||
: fToBeDoneText(),
|
||||
fDoneText(),
|
||||
fFailureText()
|
||||
{
|
||||
@@ -64,17 +63,17 @@ void G4AnalysisVerbose::Message(const G4String& action,
|
||||
<< fToBeDoneText
|
||||
<< action
|
||||
<< " "
|
||||
<< fType
|
||||
<< " "
|
||||
<< object
|
||||
<< object;
|
||||
if ( objectName.size() ) {
|
||||
G4cout
|
||||
<< " : "
|
||||
<< objectName
|
||||
<< " ";
|
||||
<< objectName;
|
||||
}
|
||||
|
||||
if ( success )
|
||||
G4cout << fDoneText;
|
||||
G4cout << " " << fDoneText;
|
||||
else
|
||||
G4cout << fFailureText;
|
||||
G4cout << " " << fFailureText;
|
||||
|
||||
G4cout << G4endl;
|
||||
}
|
||||
@@ -89,9 +88,7 @@ void G4AnalysisVerbose::Message(const G4String& action,
|
||||
<< fToBeDoneText
|
||||
<< action
|
||||
<< " "
|
||||
<< fType
|
||||
<< " "
|
||||
<< object
|
||||
<< object
|
||||
<< " : "
|
||||
<< description.str()
|
||||
<< " ";
|
||||
@@ -103,4 +100,3 @@ void G4AnalysisVerbose::Message(const G4String& action,
|
||||
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +27,15 @@
|
||||
// Author: Ivana Hrivnacova, 10/09/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4BaseFileManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4BaseFileManager::G4BaseFileManager(const G4AnalysisManagerState& state)
|
||||
: fState(state),
|
||||
fFileName("")
|
||||
fFileName(""),
|
||||
fFileNames()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,132 +44,21 @@ G4BaseFileManager::~G4BaseFileManager()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::TakeOffExtension(G4String& name) const
|
||||
{
|
||||
G4String extension;
|
||||
if ( name.rfind(".") != std::string::npos ) {
|
||||
extension = name.substr(name.rfind("."));
|
||||
name = name.substr(0, name.rfind("."));
|
||||
}
|
||||
else {
|
||||
extension = ".";
|
||||
extension.append(GetFileType());
|
||||
}
|
||||
return extension;
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetFullFileName(const G4String& baseFileName,
|
||||
G4bool isPerThread) const
|
||||
{
|
||||
G4String name(baseFileName);
|
||||
if ( name == "" ) name = fFileName;
|
||||
|
||||
// Take out file extension
|
||||
G4String extension = TakeOffExtension(name);
|
||||
|
||||
// Add thread Id to a file name if MT processing
|
||||
if ( isPerThread && ! fState.GetIsMaster() ) {
|
||||
std::ostringstream os;
|
||||
os << G4Threading::G4GetThreadId();
|
||||
name.append("_t");
|
||||
name.append(os.str());
|
||||
}
|
||||
|
||||
// Add (back if it was present) file extension
|
||||
name.append(extension);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetNtupleFileName(const G4String& ntupleName) const
|
||||
{
|
||||
G4String name(fFileName);
|
||||
|
||||
// Take out file extension
|
||||
auto extension = TakeOffExtension(name);
|
||||
|
||||
// Add ntupleName
|
||||
name.append("_nt_");
|
||||
name.append(ntupleName);
|
||||
|
||||
// Add thread Id to a file name if MT processing
|
||||
if ( ! fState.GetIsMaster() ) {
|
||||
std::ostringstream os;
|
||||
os << G4Threading::G4GetThreadId();
|
||||
name.append("_t");
|
||||
name.append(os.str());
|
||||
}
|
||||
|
||||
// Add (back if it was present) file extension
|
||||
name.append(extension);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetNtupleFileName(G4int ntupleFileNumber) const
|
||||
{
|
||||
G4String name(fFileName);
|
||||
|
||||
// Take out file extension
|
||||
auto extension = TakeOffExtension(name);
|
||||
|
||||
// Add _M followed by ntupleFileNumber
|
||||
std::ostringstream os;
|
||||
os << ntupleFileNumber;
|
||||
name.append("_m");
|
||||
name.append(os.str());
|
||||
|
||||
// Add (back if it was present) file extension
|
||||
name.append(extension);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetHnFileName(const G4String& hnType,
|
||||
const G4String& hnName) const
|
||||
void G4BaseFileManager::AddFileName(const G4String& fileName)
|
||||
{
|
||||
G4String name(fFileName);
|
||||
// G4cout << "registering " << fileName << " in manager of " << GetFileType() << G4endl;
|
||||
|
||||
// Take out file extension
|
||||
auto extension = TakeOffExtension(name);
|
||||
|
||||
// Add _hnType_hnName
|
||||
name.append("_");
|
||||
name.append(hnType);
|
||||
name.append("_");
|
||||
name.append(hnName);
|
||||
// Do nothing in file name is already present
|
||||
for ( auto name : fFileNames ) {
|
||||
if ( name == fileName ) return;
|
||||
}
|
||||
|
||||
// Add (back if it was present) file extension
|
||||
name.append(extension);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetPlotFileName() const
|
||||
{
|
||||
G4String name(fFileName);
|
||||
|
||||
// Take out file extension
|
||||
auto extension = TakeOffExtension(name);
|
||||
|
||||
// Add .ps extension
|
||||
name.append(".ps");
|
||||
|
||||
return name;
|
||||
fFileNames.push_back(fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -176,6 +67,59 @@ G4String G4BaseFileManager::GetFileType() const
|
||||
G4String fileType = fState.GetType();
|
||||
fileType.toLower();
|
||||
return fileType;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetFullFileName(const G4String& baseFileName,
|
||||
G4bool isPerThread) const
|
||||
{
|
||||
G4String fileName(baseFileName);
|
||||
if ( fileName == "" ) fileName = fFileName;
|
||||
|
||||
// Take out file extension
|
||||
auto name = G4Analysis::GetBaseName(fileName);
|
||||
|
||||
// Add thread Id to a file name if MT processing
|
||||
if ( isPerThread && ! fState.GetIsMaster() ) {
|
||||
std::ostringstream os;
|
||||
os << G4Threading::G4GetThreadId();
|
||||
name.append("_t");
|
||||
name.append(os.str());
|
||||
}
|
||||
|
||||
// Add (back if it was present or is defined) file extension
|
||||
auto extension = G4Analysis::GetExtension(fileName, GetFileType());
|
||||
if ( extension.size() ) {
|
||||
name.append(".");
|
||||
name.append(extension);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetHnFileName(const G4String& hnType,
|
||||
const G4String& hnName) const
|
||||
{
|
||||
return G4Analysis::GetHnFileName(fFileName, GetFileType(), hnType, hnName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetNtupleFileName(const G4String& ntupleName) const
|
||||
{
|
||||
return G4Analysis::GetNtupleFileName(fFileName, GetFileType(), ntupleName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetNtupleFileName(G4int ntupleFileNumber) const
|
||||
{
|
||||
return G4Analysis::GetNtupleFileName(fFileName, GetFileType(), ntupleFileNumber);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4BaseFileManager::GetPlotFileName() const
|
||||
{
|
||||
return G4Analysis::GetPlotFileName(fFileName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
//_____________________________________________________________________________
|
||||
G4BaseNtupleManager::G4BaseNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4VNtupleManager(state),
|
||||
fFirstNtupleColumnId(0),
|
||||
fLockFirstNtupleColumnId(false)
|
||||
fFirstNtupleColumnId(0)
|
||||
// fLockFirstNtupleColumnId(false)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -40,53 +40,6 @@ G4BaseNtupleManager::~G4BaseNtupleManager()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4BaseNtupleManager::GetCurrentNtupleId() const
|
||||
{
|
||||
return GetNofNtupleBookings() + fFirstId - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4BaseNtupleManager::CreateNtupleIColumn(const G4String& name,
|
||||
std::vector<int>* vector)
|
||||
{
|
||||
return CreateNtupleIColumn(GetCurrentNtupleId(), name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4BaseNtupleManager::CreateNtupleFColumn(const G4String& name,
|
||||
std::vector<float>* vector)
|
||||
{
|
||||
return CreateNtupleFColumn(GetCurrentNtupleId(), name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4BaseNtupleManager::CreateNtupleDColumn(const G4String& name,
|
||||
std::vector<double>* vector)
|
||||
{
|
||||
return CreateNtupleDColumn(GetCurrentNtupleId(), name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4BaseNtupleManager::CreateNtupleSColumn(const G4String& name)
|
||||
{
|
||||
return CreateNtupleSColumn(GetCurrentNtupleId(), name);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4BaseNtupleManager::FinishNtuple()
|
||||
{
|
||||
return FinishNtuple(GetCurrentNtupleId());
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4BaseNtupleManager::FillNtupleIColumn(G4int id, G4int value)
|
||||
{
|
||||
@@ -118,18 +71,8 @@ G4bool G4BaseNtupleManager::AddNtupleRow()
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4BaseNtupleManager::SetFirstNtupleColumnId(G4int firstId)
|
||||
{
|
||||
if ( fLockFirstNtupleColumnId ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot set FirstNtupleColumnId as its value was already used.";
|
||||
G4Exception("G4BaseNtupleManager::SetFirstNtupleColumnId()",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
fFirstNtupleColumnId = firstId;
|
||||
G4bool G4BaseNtupleManager::SetFirstNtupleColumnId(G4int firstId)
|
||||
{
|
||||
fFirstNtupleColumnId = firstId;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4HnManager.hh"
|
||||
#include "G4VFileManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
@@ -39,15 +40,78 @@ G4HnManager::G4HnManager(const G4String& hnType,
|
||||
fNofActiveObjects(0),
|
||||
fNofAsciiObjects(0),
|
||||
fNofPlottingObjects(0),
|
||||
fHnVector()
|
||||
fNofFileNameObjects(0),
|
||||
fHnVector(),
|
||||
fFileManager(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4HnManager::~G4HnManager()
|
||||
{
|
||||
for ( auto hnInformation : fHnVector ) {
|
||||
delete hnInformation;
|
||||
for ( auto info : fHnVector ) {
|
||||
delete info;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnManager::SetActivation(G4HnInformation* info, G4bool activation)
|
||||
{
|
||||
// Set activation to a given object
|
||||
|
||||
// Do nothing if activation does not change
|
||||
if ( info->GetActivation() == activation ) return;
|
||||
|
||||
// Change activation and account it in fNofActiveObjects
|
||||
info->SetActivation(activation);
|
||||
if ( activation )
|
||||
fNofActiveObjects++;
|
||||
else
|
||||
fNofActiveObjects--;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnManager::SetPlotting(G4HnInformation* info, G4bool plotting)
|
||||
{
|
||||
// Do nothing if ascii does not change
|
||||
if ( info->GetPlotting() == plotting ) return;
|
||||
|
||||
// Change Plotting and account it in fNofPlottingObjects
|
||||
info->SetPlotting(plotting);
|
||||
if ( plotting )
|
||||
fNofPlottingObjects++;
|
||||
else
|
||||
fNofPlottingObjects--;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnManager::SetFileName(G4HnInformation* info, const G4String& fileName)
|
||||
{
|
||||
// Do nothing if file name does not change
|
||||
if ( info->GetFileName() == fileName ) return;
|
||||
|
||||
// Save the info and account a new file name if file manager
|
||||
info->SetFileName(fileName);
|
||||
if (fFileManager) {
|
||||
fFileManager->AddFileName(fileName);
|
||||
} else {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Failed to set fileName " << fileName << " for object " << info->GetName() << G4endl
|
||||
<< "File manager is not set.";
|
||||
G4Exception("G4HnManager::SetFileName",
|
||||
"Analysis_W012", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( fileName != "" ) {
|
||||
fNofFileNameObjects++;
|
||||
} else {
|
||||
fNofFileNameObjects--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +122,11 @@ G4HnManager::~G4HnManager()
|
||||
//_____________________________________________________________________________
|
||||
G4HnInformation* G4HnManager::AddHnInformation(const G4String& name, G4int nofDimensions)
|
||||
{
|
||||
auto hnInformation = new G4HnInformation(name, nofDimensions);
|
||||
fHnVector.push_back(hnInformation);
|
||||
auto info = new G4HnInformation(name, nofDimensions);
|
||||
fHnVector.push_back(info);
|
||||
++fNofActiveObjects;
|
||||
|
||||
return hnInformation;
|
||||
return info;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -92,11 +156,11 @@ G4HnDimensionInformation* G4HnManager::GetHnDimensionInformation(G4int id,
|
||||
G4int dimension,
|
||||
G4String functionName, G4bool warn) const
|
||||
{
|
||||
auto hnInformation = GetHnInformation(id, functionName, warn);
|
||||
if ( ! hnInformation ) return nullptr;
|
||||
auto info = GetHnInformation(id, functionName, warn);
|
||||
if ( ! info ) return nullptr;
|
||||
|
||||
return hnInformation->GetHnDimensionInformation(dimension);
|
||||
}
|
||||
return info->GetHnDimensionInformation(dimension);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4HnManager::IsActive() const
|
||||
@@ -116,6 +180,12 @@ G4bool G4HnManager::IsPlotting() const
|
||||
return ( fNofPlottingObjects > 0 );
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4HnManager::IsFileName() const
|
||||
{
|
||||
return ( fNofFileNameObjects > 0 );
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnManager::SetActivation(G4int id, G4bool activation)
|
||||
{
|
||||
@@ -125,15 +195,7 @@ void G4HnManager::SetActivation(G4int id, G4bool activation)
|
||||
|
||||
if ( ! info ) return;
|
||||
|
||||
// Do nothing if activation does not change
|
||||
if ( info->GetActivation() == activation ) return;
|
||||
|
||||
// Change activation and account it in fNofActiveObjects
|
||||
info->SetActivation(activation);
|
||||
if ( activation )
|
||||
fNofActiveObjects++;
|
||||
else
|
||||
fNofActiveObjects--;
|
||||
SetActivation(info, activation);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -146,18 +208,9 @@ void G4HnManager::SetActivation(G4bool activation)
|
||||
// G4HnInformation* info = *it;
|
||||
|
||||
for ( auto info : fHnVector ) {
|
||||
|
||||
// Do nothing if activation does not change
|
||||
if ( info->GetActivation() == activation ) continue;
|
||||
|
||||
// Change activation and account it in fNofActiveObjects
|
||||
info->SetActivation(activation);
|
||||
if ( activation )
|
||||
fNofActiveObjects++;
|
||||
else
|
||||
fNofActiveObjects--;
|
||||
}
|
||||
}
|
||||
SetActivation(info, activation);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnManager::SetAscii(G4int id, G4bool ascii)
|
||||
@@ -184,16 +237,8 @@ void G4HnManager::SetPlotting(G4int id, G4bool plotting)
|
||||
|
||||
if ( ! info ) return;
|
||||
|
||||
// Do nothing if ascii does not change
|
||||
if ( info->GetPlotting() == plotting ) return;
|
||||
|
||||
// Change Plotting and account it in fNofPlottingObjects
|
||||
info->SetPlotting(plotting);
|
||||
if ( plotting )
|
||||
fNofPlottingObjects++;
|
||||
else
|
||||
fNofPlottingObjects--;
|
||||
}
|
||||
SetPlotting(info, plotting);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnManager::SetPlotting(G4bool plotting)
|
||||
@@ -201,17 +246,28 @@ void G4HnManager::SetPlotting(G4bool plotting)
|
||||
// Set plotting to all objects of the given type
|
||||
|
||||
for ( auto info : fHnVector ) {
|
||||
SetPlotting(info, plotting);
|
||||
}
|
||||
}
|
||||
|
||||
// Do nothing if plotting does not change
|
||||
if ( info->GetPlotting() == plotting ) continue;
|
||||
|
||||
// Change plotting and account it in fNofActiveObjects
|
||||
info->SetPlotting(plotting);
|
||||
if ( plotting )
|
||||
fNofPlottingObjects++;
|
||||
else
|
||||
fNofPlottingObjects--;
|
||||
}
|
||||
//_____________________________________________________________________________
|
||||
void G4HnManager::SetFileName(G4int id, const G4String& fileName)
|
||||
{
|
||||
auto info = GetHnInformation(id, "SetFileName");
|
||||
|
||||
if ( ! info ) return;
|
||||
|
||||
SetFileName(info, fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnManager::SetFileName(const G4String& fileName)
|
||||
{
|
||||
// Set plotting to all objects of the given type
|
||||
|
||||
for ( auto info : fHnVector ) {
|
||||
SetFileName(info, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -345,4 +401,14 @@ G4bool G4HnManager::GetPlotting(G4int id) const
|
||||
if ( ! info ) return false;
|
||||
|
||||
return info->GetPlotting();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4HnManager::GetFileName(G4int id) const
|
||||
{
|
||||
auto info = GetHnInformation(id, "GetFileName");
|
||||
|
||||
if ( ! info ) return "";
|
||||
|
||||
return info->GetFileName();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "G4UIparameter.hh"
|
||||
#include "G4UIcmdWithAnInteger.hh"
|
||||
#include "G4UIcmdWithABool.hh"
|
||||
#include "G4UIcmdWithAString.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
@@ -48,7 +49,9 @@ G4HnMessenger::G4HnMessenger(G4HnManager& manager)
|
||||
fSetHnActivationCmd(nullptr),
|
||||
fSetHnActivationAllCmd(nullptr),
|
||||
fSetHnPlottingCmd(nullptr),
|
||||
fSetHnPlottingAllCmd(nullptr)
|
||||
fSetHnPlottingAllCmd(nullptr),
|
||||
fSetHnFileNameCmd(nullptr),
|
||||
fSetHnFileNameAllCmd(nullptr)
|
||||
{
|
||||
G4String hnType = fManager.GetHnType();
|
||||
hnType.toLower();
|
||||
@@ -59,6 +62,8 @@ G4HnMessenger::G4HnMessenger(G4HnManager& manager)
|
||||
SetHnActivationToAllCmd();
|
||||
SetHnPlottingCmd();
|
||||
SetHnPlottingToAllCmd();
|
||||
SetHnFileNameCmd();
|
||||
SetHnFileNameToAllCmd();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -142,6 +147,36 @@ void G4HnMessenger::SetHnPlottingToAllCmd()
|
||||
fSetHnPlottingAllCmd->SetParameterName("Plotting",false);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnMessenger::SetHnFileNameCmd()
|
||||
{
|
||||
auto hnId = new G4UIparameter("id", 'i', false);
|
||||
hnId->SetGuidance(fHelper->Update("OBJECT id"));
|
||||
hnId->SetParameterRange("id>=0");
|
||||
|
||||
auto hnFileName = new G4UIparameter("hnFileName", 's', true);
|
||||
hnFileName->SetGuidance(fHelper->Update("OBJECT output file name"));
|
||||
hnFileName->SetDefaultValue("none");
|
||||
|
||||
fSetHnFileNameCmd
|
||||
= G4Analysis::make_unique<G4UIcommand>(fHelper->Update("/analysis/HNTYPE_/setFileName"), this);
|
||||
fSetHnFileNameCmd->SetGuidance(
|
||||
fHelper->Update("Set the NDIM_D LOBJECT of given id output file name"));
|
||||
fSetHnFileNameCmd->SetParameter(hnId);
|
||||
fSetHnFileNameCmd->SetParameter(hnFileName);
|
||||
fSetHnFileNameCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4HnMessenger::SetHnFileNameToAllCmd()
|
||||
{
|
||||
fSetHnFileNameAllCmd
|
||||
= G4Analysis::make_unique<G4UIcmdWithAString>(fHelper->Update("/analysis/HNTYPE_/setFileNameToAll"), this);
|
||||
fSetHnFileNameAllCmd->SetGuidance(
|
||||
fHelper->Update("Set output file name for all NDIM_D LOBJECTs"));
|
||||
fSetHnFileNameAllCmd->SetParameterName("FileName",false);
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
@@ -149,11 +184,11 @@ void G4HnMessenger::SetHnPlottingToAllCmd()
|
||||
//_____________________________________________________________________________
|
||||
void G4HnMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
|
||||
{
|
||||
if ( command == fSetHnAsciiCmd.get() ) {
|
||||
if ( command == fSetHnAsciiCmd.get() ) {
|
||||
auto id = fSetHnAsciiCmd->GetNewIntValue(newValues);
|
||||
fManager.SetAscii(id, true);
|
||||
}
|
||||
else if ( command == fSetHnActivationCmd.get() ) {
|
||||
fManager.SetAscii(id, true);
|
||||
}
|
||||
else if ( command == fSetHnActivationCmd.get() ) {
|
||||
// tokenize parameters in a vector
|
||||
std::vector<G4String> parameters;
|
||||
G4Analysis::Tokenize(newValues, parameters);
|
||||
@@ -162,18 +197,18 @@ void G4HnMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
|
||||
fManager.SetActivation(id, activation);
|
||||
fManager.SetActivation(id, activation);
|
||||
}
|
||||
else {
|
||||
// Should never happen but let's check anyway for consistency
|
||||
fHelper->WarnAboutParameters(command, parameters.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( command == fSetHnActivationAllCmd.get() ) {
|
||||
else if ( command == fSetHnActivationAllCmd.get() ) {
|
||||
auto activation = fSetHnActivationAllCmd->GetNewBoolValue(newValues);
|
||||
fManager.SetActivation(activation);
|
||||
}
|
||||
else if ( command == fSetHnPlottingCmd.get() ) {
|
||||
}
|
||||
else if ( command == fSetHnPlottingCmd.get() ) {
|
||||
// tokenize parameters in a vector
|
||||
std::vector<G4String> parameters;
|
||||
G4Analysis::Tokenize(newValues, parameters);
|
||||
@@ -182,15 +217,35 @@ void G4HnMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
auto activation = G4UIcommand::ConvertToBool(parameters[counter++]);
|
||||
fManager.SetPlotting(id, activation);
|
||||
fManager.SetPlotting(id, activation);
|
||||
}
|
||||
else {
|
||||
// Should never happen but let's check anyway for consistency
|
||||
fHelper->WarnAboutParameters(command, parameters.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( command == fSetHnPlottingAllCmd.get() ) {
|
||||
auto activation = fSetHnPlottingAllCmd->GetNewBoolValue(newValues);
|
||||
fManager.SetPlotting(activation);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( command == fSetHnFileNameCmd.get() ) {
|
||||
// tokenize parameters in a vector
|
||||
std::vector<G4String> parameters;
|
||||
G4Analysis::Tokenize(newValues, parameters);
|
||||
// check consistency
|
||||
if ( parameters.size() == command->GetParameterEntries() ) {
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
auto fileName = parameters[counter++];
|
||||
fManager.SetFileName(id, fileName);
|
||||
}
|
||||
else {
|
||||
// Should never happen but let's check anyway for consistency
|
||||
fHelper->WarnAboutParameters(command, parameters.size());
|
||||
}
|
||||
}
|
||||
else if ( command == fSetHnFileNameAllCmd.get() ) {
|
||||
auto fileName = newValues;
|
||||
fManager.SetFileName(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,332 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 01/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4NtupleBookingManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//
|
||||
// private template functions
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4NtupleBookingManager::G4NtupleBookingManager(
|
||||
const G4AnalysisManagerState& state)
|
||||
: G4BaseAnalysisManager(state),
|
||||
fNtupleBookingVector(),
|
||||
fFileType(),
|
||||
fFirstNtupleColumnId(0),
|
||||
fLockFirstNtupleColumnId(false)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4NtupleBookingManager::~G4NtupleBookingManager()
|
||||
{
|
||||
for ( auto ntupleBooking : fNtupleBookingVector ) {
|
||||
delete ntupleBooking;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4NtupleBooking*
|
||||
G4NtupleBookingManager::GetNtupleBookingInFunction(
|
||||
G4int id, G4String functionName, G4bool warn) const
|
||||
{
|
||||
auto index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(fNtupleBookingVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4String inFunction = "G4NtupleBookingManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntuple booking " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fNtupleBookingVector[index];
|
||||
}
|
||||
|
||||
//
|
||||
// protected functions
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4NtupleBookingManager::IsEmpty() const
|
||||
{
|
||||
return ! fNtupleBookingVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtuple(
|
||||
const G4String& name, const G4String& title)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "ntuple booking", name);
|
||||
#endif
|
||||
|
||||
// Create ntuple description
|
||||
auto index = fNtupleBookingVector.size();
|
||||
auto ntupleBooking = new G4NtupleBooking();
|
||||
fNtupleBookingVector.push_back(ntupleBooking);
|
||||
|
||||
// Save name & title in ntuple booking
|
||||
ntupleBooking->fNtupleBooking.set_name(name);
|
||||
ntupleBooking->fNtupleBooking.set_title(title);
|
||||
|
||||
// Create ntuple
|
||||
fLockFirstId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << index + fFirstId;
|
||||
fState.GetVerboseL2()->Message("create", "ntuple booking", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return G4int(index + fFirstId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtupleIColumn(const G4String& name,
|
||||
std::vector<int>* vector)
|
||||
{
|
||||
return CreateNtupleIColumn(GetCurrentNtupleId(), name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtupleFColumn(const G4String& name,
|
||||
std::vector<float>* vector)
|
||||
{
|
||||
return CreateNtupleFColumn(GetCurrentNtupleId(), name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtupleDColumn(const G4String& name,
|
||||
std::vector<double>* vector)
|
||||
{
|
||||
return CreateNtupleDColumn(GetCurrentNtupleId(), name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtupleSColumn(const G4String& name)
|
||||
{
|
||||
return CreateNtupleSColumn(GetCurrentNtupleId(), name);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4NtupleBooking* G4NtupleBookingManager::FinishNtuple()
|
||||
{
|
||||
return FinishNtuple(GetCurrentNtupleId());
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtupleIColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<int>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<int>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtupleFColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<float>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<float>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtupleDColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<double>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<double>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4NtupleBookingManager::CreateNtupleSColumn(
|
||||
G4int ntupleId, const G4String& name)
|
||||
{
|
||||
return CreateNtupleTColumn<std::string>(ntupleId, name, nullptr);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4NtupleBooking* G4NtupleBookingManager::FinishNtuple(
|
||||
G4int ntupleId)
|
||||
{
|
||||
// Nothing to be done for booking,
|
||||
return GetNtupleBookingInFunction(ntupleId, "FinishNtuple");
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4NtupleBookingManager::SetFirstNtupleColumnId(G4int firstId)
|
||||
{
|
||||
if ( fLockFirstNtupleColumnId ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot set FirstNtupleColumnId as its value was already used.";
|
||||
G4Exception("G4BaseNtupleManager::SetFirstNtupleColumnId()",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
fFirstNtupleColumnId = firstId;
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4NtupleBookingManager::SetActivation(
|
||||
G4bool activation)
|
||||
{
|
||||
for ( auto ntupleBooking : fNtupleBookingVector ) {
|
||||
ntupleBooking->fActivation = activation;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4NtupleBookingManager::SetActivation(
|
||||
G4int ntupleId, G4bool activation)
|
||||
{
|
||||
auto ntupleBooking
|
||||
= GetNtupleBookingInFunction(ntupleId, "SetActivation");
|
||||
if ( ! ntupleBooking ) return;
|
||||
|
||||
ntupleBooking->fActivation = activation;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4NtupleBookingManager::GetActivation(
|
||||
G4int ntupleId) const
|
||||
{
|
||||
auto ntupleBooking
|
||||
= GetNtupleBookingInFunction(ntupleId, "GetActivation");
|
||||
if ( ! ntupleBooking ) return false;
|
||||
|
||||
return ntupleBooking->fActivation;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4NtupleBookingManager::SetFileName(
|
||||
const G4String& fileName)
|
||||
{
|
||||
for ( auto ntupleBooking : fNtupleBookingVector ) {
|
||||
ntupleBooking->fFileName = fileName;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4NtupleBookingManager::SetFileName(
|
||||
G4int ntupleId, const G4String& fileName)
|
||||
{
|
||||
auto ntupleBooking
|
||||
= GetNtupleBookingInFunction(ntupleId, "SetFileName");
|
||||
if ( ! ntupleBooking ) return;
|
||||
|
||||
// Do nothing if file name does not change
|
||||
if ( ntupleBooking->fFileName == fileName ) return;
|
||||
|
||||
auto ntupleFileName = fileName;
|
||||
auto extension = GetExtension(fileName);
|
||||
if ( extension.size() ) {
|
||||
// Check if valid extension (if present)
|
||||
auto output = G4Analysis::GetOutput(extension);
|
||||
if ( output == G4AnalysisOutput::kNone ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "The file extension " << extension << "is not supported.";
|
||||
G4Exception("G4NtupleBookingManager::SetFileName",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( fFileType.size() ) {
|
||||
//add extension if missing and file type is defined
|
||||
ntupleFileName = fileName + "." + fFileType;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the fileName in booking
|
||||
// If extension is still missing (possible with generic manager),
|
||||
// it will be completed with the default one at OpenFile
|
||||
ntupleBooking->fFileName = ntupleFileName;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4NtupleBookingManager::GetFileName(
|
||||
G4int ntupleId) const
|
||||
{
|
||||
auto ntupleBooking
|
||||
= GetNtupleBookingInFunction(ntupleId, "GetFileName");
|
||||
if ( ! ntupleBooking ) return "";
|
||||
|
||||
return ntupleBooking->fFileName;
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4NtupleBookingManager::SetFileType(const G4String& fileType)
|
||||
{
|
||||
// do nothing if file type is defined and is same
|
||||
if ( fFileType == fileType ) return;
|
||||
|
||||
// save the type
|
||||
fFileType = fileType;
|
||||
|
||||
// Give warning and redefine file extension in bookings
|
||||
// with file name of different fileTypes
|
||||
for ( auto ntupleBooking : fNtupleBookingVector ) {
|
||||
|
||||
if ( ! (ntupleBooking->fFileName).size() ) continue;
|
||||
|
||||
auto extension = GetExtension(ntupleBooking->fFileName);
|
||||
if ( fFileType == extension ) continue;
|
||||
|
||||
// multiple file types are not suported
|
||||
auto baseFileName = GetBaseName(ntupleBooking->fFileName);
|
||||
auto ntupleFileName = baseFileName + "." + fFileType;
|
||||
if ( extension.size()) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Writing ntuples in files of different output types "
|
||||
<< fFileType << ", " << extension << " is not supported." << G4endl
|
||||
<< "Ntuple " << ntupleBooking->fNtupleBooking.name()
|
||||
<< " will be written in " << ntupleFileName;
|
||||
G4Exception("G4NtupleBookingManager::SetFileType",
|
||||
"Analysis_W051", JustWarning, description);
|
||||
}
|
||||
|
||||
// Save the info in ntuple description
|
||||
ntupleBooking->fFileName = ntupleFileName;
|
||||
}
|
||||
}
|
||||
@@ -33,23 +33,44 @@
|
||||
#include "G4UIcommand.hh"
|
||||
#include "G4UIparameter.hh"
|
||||
#include "G4UIcmdWithABool.hh"
|
||||
#include "G4UIcmdWithAString.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
namespace {
|
||||
|
||||
void WrongParametersException(
|
||||
const G4String& commandName, std::size_t got, std::size_t expected)
|
||||
{
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Got wrong number of \"" << commandName
|
||||
<< "\" parameters: " << got << " instead of " << expected
|
||||
<< " expected" << G4endl;
|
||||
G4Exception("G4NtupleMessenger::SetNewValue",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4NtupleMessenger::G4NtupleMessenger(G4VAnalysisManager* manager)
|
||||
: G4UImessenger(),
|
||||
fManager(manager),
|
||||
fSetActivationCmd(nullptr),
|
||||
fSetActivationAllCmd(nullptr)
|
||||
fSetActivationAllCmd(nullptr),
|
||||
fSetFileNameCmd(nullptr),
|
||||
fSetFileNameAllCmd(nullptr)
|
||||
{
|
||||
fNtupleDir = G4Analysis::make_unique<G4UIdirectory>("/analysis/ntuple/");
|
||||
fNtupleDir->SetGuidance("ntuple control");
|
||||
|
||||
SetActivationCmd();
|
||||
SetActivationToAllCmd();
|
||||
SetFileNameCmd();
|
||||
SetFileNameToAllCmd();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -91,6 +112,36 @@ void G4NtupleMessenger::SetActivationToAllCmd()
|
||||
fSetActivationAllCmd->SetParameterName("AllNtupleActivation",false);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4NtupleMessenger::SetFileNameCmd()
|
||||
{
|
||||
auto ntupleId = new G4UIparameter("NtupleId", 'i', false);
|
||||
ntupleId->SetGuidance("Ntuple id");
|
||||
ntupleId->SetParameterRange("NtupleId>=0");
|
||||
|
||||
auto ntupleFileName = new G4UIparameter("NtupleFileName", 's', true);
|
||||
ntupleFileName->SetGuidance("Ntuple file name");
|
||||
ntupleFileName->SetDefaultValue("none");
|
||||
|
||||
fSetFileNameCmd = G4Analysis::make_unique<G4UIcommand>("/analysis/ntuple/setFileName", this);
|
||||
G4String guidance("Set file name for the ntuple of given id");
|
||||
|
||||
fSetFileNameCmd->SetGuidance(guidance);
|
||||
fSetFileNameCmd->SetParameter(ntupleId);
|
||||
fSetFileNameCmd->SetParameter(ntupleFileName);
|
||||
fSetFileNameCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4NtupleMessenger::SetFileNameToAllCmd()
|
||||
{
|
||||
fSetFileNameAllCmd
|
||||
= G4Analysis::make_unique<G4UIcmdWithAString>("/analysis/ntuple/setFileNameToAll", this);
|
||||
G4String guidance("Set file name to all ntuples");
|
||||
fSetFileNameAllCmd->SetGuidance(guidance);
|
||||
fSetFileNameAllCmd->SetParameterName("AllNtupleFileName",false);
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
@@ -111,18 +162,33 @@ void G4NtupleMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
|
||||
}
|
||||
else {
|
||||
// Should never happen but let's check anyway for consistency
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Got wrong number of \"" << command->GetCommandName()
|
||||
<< "\" parameters: " << parameters.size()
|
||||
<< " instead of " << command->GetParameterEntries()
|
||||
<< " expected" << G4endl;
|
||||
G4Exception("G4NtupleMessenger::SetNewValue",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
WrongParametersException(command->GetCommandName(),
|
||||
parameters.size(),command->GetParameterEntries());
|
||||
}
|
||||
}
|
||||
else if ( command == fSetActivationAllCmd.get() ) {
|
||||
auto activation = fSetActivationAllCmd->GetNewBoolValue(newValues);
|
||||
fManager->SetNtupleActivation(activation);
|
||||
}
|
||||
}
|
||||
else if ( command == fSetFileNameCmd.get() ) {
|
||||
// tokenize parameters in a vector
|
||||
std::vector<G4String> parameters;
|
||||
G4Analysis::Tokenize(newValues, parameters);
|
||||
// check consistency
|
||||
if ( parameters.size() == command->GetParameterEntries() ) {
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
auto fileName = parameters[counter++];
|
||||
fManager->SetNtupleFileName(id, fileName);
|
||||
}
|
||||
else {
|
||||
// Should never happen but let's check anyway for consistency
|
||||
WrongParametersException(command->GetCommandName(),
|
||||
parameters.size(),command->GetParameterEntries());
|
||||
}
|
||||
}
|
||||
else if ( command == fSetFileNameAllCmd.get() ) {
|
||||
auto fileName = newValues;
|
||||
fManager->SetNtupleFileName(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ G4P1Messenger::G4P1Messenger(G4VAnalysisManager* manager)
|
||||
fSetP1TitleCmd(nullptr),
|
||||
fSetP1XAxisCmd(nullptr),
|
||||
fSetP1YAxisCmd(nullptr),
|
||||
fXId(-1),
|
||||
fXData()
|
||||
{
|
||||
fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("p1");
|
||||
|
||||
@@ -51,7 +51,11 @@ G4P2Messenger::G4P2Messenger(G4VAnalysisManager* manager)
|
||||
fSetP2ZCmd(nullptr),
|
||||
fSetP2TitleCmd(nullptr),
|
||||
fSetP2XAxisCmd(nullptr),
|
||||
fSetP2YAxisCmd(nullptr)
|
||||
fSetP2YAxisCmd(nullptr),
|
||||
fXId(-1),
|
||||
fYId(-1),
|
||||
fXData(),
|
||||
fYData()
|
||||
{
|
||||
fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("p2");
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#if defined(TOOLS_USE_FREETYPE)
|
||||
#include <tools/sg/text_freetype>
|
||||
#include <tools/xml/xml_style>
|
||||
#include <tools/xml/wrap_viewplot_style>
|
||||
#include <tools/xml/wrap_viewplot_fonts_google_style>
|
||||
//inlib/xml/viewplot.style file embeded in an inline function.
|
||||
|
||||
namespace {
|
||||
@@ -127,7 +127,7 @@ void regions_style(tools::sg::plots& a_plots,float a_plotter_scale = 1) {
|
||||
bool load_embeded_styles(tools::xml::styles& a_styles) {
|
||||
std::string ss;
|
||||
unsigned int linen;
|
||||
const char** lines = viewplot_style(linen);
|
||||
const char** lines = viewplot_fonts_google_style(linen);
|
||||
for(unsigned int index=0;index<linen;index++) {
|
||||
std::string s = lines[index];
|
||||
tools::replace(s,"@@double_quote@@","\"");
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "G4VP2Manager.hh"
|
||||
#include "G4VNtupleManager.hh"
|
||||
#include "G4VFileManager.hh"
|
||||
#include "G4NtupleBookingManager.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -44,6 +45,7 @@ using namespace G4Analysis;
|
||||
|
||||
namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void NtupleMergingWarning(const G4String& functionName,
|
||||
const G4String& outputType)
|
||||
{
|
||||
@@ -62,6 +64,8 @@ G4VAnalysisManager::G4VAnalysisManager(const G4String& type, G4bool isMaster)
|
||||
: fState(type, isMaster),
|
||||
fVFileManager(nullptr),
|
||||
fPlotManager(nullptr),
|
||||
fNtupleBookingManager(nullptr),
|
||||
fVNtupleManager(nullptr),
|
||||
fMessenger(G4Analysis::make_unique<G4AnalysisMessenger>(this)),
|
||||
fH1HnManager(nullptr),
|
||||
fH2HnManager(nullptr),
|
||||
@@ -72,16 +76,15 @@ G4VAnalysisManager::G4VAnalysisManager(const G4String& type, G4bool isMaster)
|
||||
fVH2Manager(nullptr),
|
||||
fVH3Manager(nullptr),
|
||||
fVP1Manager(nullptr),
|
||||
fVP2Manager(nullptr),
|
||||
fVNtupleManager(nullptr)
|
||||
fVP2Manager(nullptr)
|
||||
{
|
||||
//fMessenger = G4Analysis::make_unique<G4AnalysisMessenger>(this);
|
||||
fNtupleBookingManager = std::make_shared<G4NtupleBookingManager>(fState);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VAnalysisManager::~G4VAnalysisManager()
|
||||
{
|
||||
delete fVNtupleManager;
|
||||
// delete fVNtupleManager;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -94,7 +97,8 @@ void G4VAnalysisManager::SetH1Manager(G4VH1Manager* h1Manager)
|
||||
fVH1Manager.reset(h1Manager);
|
||||
fH1HnManager = h1Manager->GetHnManager();
|
||||
fMessenger->SetH1HnManager(*fH1HnManager);
|
||||
}
|
||||
if (fVFileManager != nullptr ) fH1HnManager->SetFileManager(fVFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetH2Manager(G4VH2Manager* h2Manager)
|
||||
@@ -102,7 +106,8 @@ void G4VAnalysisManager::SetH2Manager(G4VH2Manager* h2Manager)
|
||||
fVH2Manager.reset(h2Manager);
|
||||
fH2HnManager = h2Manager->GetHnManager();
|
||||
fMessenger->SetH2HnManager(*fH2HnManager);
|
||||
}
|
||||
if (fVFileManager != nullptr ) fH2HnManager->SetFileManager(fVFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetH3Manager(G4VH3Manager* h3Manager)
|
||||
@@ -110,7 +115,8 @@ void G4VAnalysisManager::SetH3Manager(G4VH3Manager* h3Manager)
|
||||
fVH3Manager.reset(h3Manager);
|
||||
fH3HnManager = h3Manager->GetHnManager();
|
||||
fMessenger->SetH3HnManager(*fH3HnManager);
|
||||
}
|
||||
if (fVFileManager != nullptr ) fH3HnManager->SetFileManager(fVFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetP1Manager(G4VP1Manager* p1Manager)
|
||||
@@ -118,7 +124,8 @@ void G4VAnalysisManager::SetP1Manager(G4VP1Manager* p1Manager)
|
||||
fVP1Manager.reset(p1Manager);
|
||||
fP1HnManager = p1Manager->GetHnManager();
|
||||
fMessenger->SetP1HnManager(*fP1HnManager);
|
||||
}
|
||||
if (fVFileManager != nullptr ) fP1HnManager->SetFileManager(fVFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetP2Manager(G4VP2Manager* p2Manager)
|
||||
@@ -126,19 +133,27 @@ void G4VAnalysisManager::SetP2Manager(G4VP2Manager* p2Manager)
|
||||
fVP2Manager.reset(p2Manager);
|
||||
fP2HnManager = p2Manager->GetHnManager();
|
||||
fMessenger->SetP2HnManager(*fP2HnManager);
|
||||
}
|
||||
if (fVFileManager != nullptr ) fP2HnManager->SetFileManager(fVFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetNtupleManager(G4VNtupleManager* ntupleManager)
|
||||
void G4VAnalysisManager::SetNtupleManager(std::shared_ptr<G4VNtupleManager> ntupleManager)
|
||||
{
|
||||
// fVNtupleManager.reset(ntupleManager);
|
||||
fVNtupleManager = ntupleManager;
|
||||
}
|
||||
fVNtupleManager->SetFirstId(fNtupleBookingManager->GetFirstId());
|
||||
fVNtupleManager->SetFirstNtupleColumnId(fNtupleBookingManager->GetFirstNtupleColumnId());
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetFileManager(std::shared_ptr<G4VFileManager> fileManager)
|
||||
{
|
||||
fVFileManager = fileManager;
|
||||
|
||||
if ( fH1HnManager != nullptr ) fH1HnManager->SetFileManager(fileManager);
|
||||
if ( fH2HnManager != nullptr ) fH2HnManager->SetFileManager(fileManager);
|
||||
if ( fH3HnManager != nullptr ) fH3HnManager->SetFileManager(fileManager);
|
||||
if ( fP1HnManager != nullptr ) fP1HnManager->SetFileManager(fileManager);
|
||||
if ( fP2HnManager != nullptr ) fP2HnManager->SetFileManager(fileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -218,7 +233,7 @@ G4bool G4VAnalysisManager::OpenFile(const G4String& fileName)
|
||||
return false;
|
||||
}
|
||||
return OpenFileImpl(fVFileManager->GetFileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -753,7 +768,7 @@ G4int G4VAnalysisManager::CreateNtuple(const G4String& name,
|
||||
{
|
||||
if ( ! CheckName(name, "Ntuple") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtuple(name, title);
|
||||
return fNtupleBookingManager->CreateNtuple(name, title);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -761,7 +776,7 @@ G4int G4VAnalysisManager::CreateNtupleIColumn(const G4String& name)
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleIColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleIColumn(name, 0);
|
||||
return fNtupleBookingManager->CreateNtupleIColumn(name, 0);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -769,7 +784,7 @@ G4int G4VAnalysisManager::CreateNtupleFColumn(const G4String& name)
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleFColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleFColumn(name, 0);
|
||||
return fNtupleBookingManager->CreateNtupleFColumn(name, 0);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -777,7 +792,7 @@ G4int G4VAnalysisManager::CreateNtupleDColumn(const G4String& name)
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleDColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleDColumn(name, 0);
|
||||
return fNtupleBookingManager->CreateNtupleDColumn(name, 0);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -785,7 +800,7 @@ G4int G4VAnalysisManager::CreateNtupleSColumn(const G4String& name)
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleSColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleSColumn(name);
|
||||
return fNtupleBookingManager->CreateNtupleSColumn(name);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -794,7 +809,7 @@ G4int G4VAnalysisManager::CreateNtupleIColumn(const G4String& name,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleIColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleIColumn(name, &vector);
|
||||
return fNtupleBookingManager->CreateNtupleIColumn(name, &vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -803,7 +818,7 @@ G4int G4VAnalysisManager::CreateNtupleFColumn(const G4String& name,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleFColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleFColumn(name, &vector);
|
||||
return fNtupleBookingManager->CreateNtupleFColumn(name, &vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -812,13 +827,17 @@ G4int G4VAnalysisManager::CreateNtupleDColumn(const G4String& name,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleDColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleDColumn(name, &vector);
|
||||
return fNtupleBookingManager->CreateNtupleDColumn(name, &vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::FinishNtuple()
|
||||
{
|
||||
return fVNtupleManager->FinishNtuple();
|
||||
auto ntupleBooking = fNtupleBookingManager->FinishNtuple();
|
||||
|
||||
if ( fVNtupleManager ) {
|
||||
fVNtupleManager->CreateNtuple(ntupleBooking);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -865,7 +884,7 @@ G4int G4VAnalysisManager::CreateNtupleIColumn(G4int ntupleId,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleIColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleIColumn(ntupleId, name, 0);
|
||||
return fNtupleBookingManager->CreateNtupleIColumn(ntupleId, name, 0);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -874,7 +893,7 @@ G4int G4VAnalysisManager::CreateNtupleFColumn(G4int ntupleId,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleFColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleFColumn(ntupleId, name, 0);
|
||||
return fNtupleBookingManager->CreateNtupleFColumn(ntupleId, name, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -884,7 +903,7 @@ G4int G4VAnalysisManager::CreateNtupleDColumn(G4int ntupleId,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleDColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleDColumn(ntupleId, name, 0);
|
||||
return fNtupleBookingManager->CreateNtupleDColumn(ntupleId, name, 0);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -893,7 +912,7 @@ G4int G4VAnalysisManager::CreateNtupleSColumn(G4int ntupleId,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleSColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleSColumn(ntupleId, name);
|
||||
return fNtupleBookingManager->CreateNtupleSColumn(ntupleId, name);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -903,7 +922,7 @@ G4int G4VAnalysisManager::CreateNtupleIColumn(G4int ntupleId,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleIColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleIColumn(ntupleId, name, &vector);
|
||||
return fNtupleBookingManager->CreateNtupleIColumn(ntupleId, name, &vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -913,7 +932,7 @@ G4int G4VAnalysisManager::CreateNtupleFColumn(G4int ntupleId,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleFColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleFColumn(ntupleId, name, &vector);
|
||||
return fNtupleBookingManager->CreateNtupleFColumn(ntupleId, name, &vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -923,13 +942,17 @@ G4int G4VAnalysisManager::CreateNtupleDColumn(G4int ntupleId,
|
||||
{
|
||||
if ( ! CheckName(name, "NtupleDColumn") ) return kInvalidId;
|
||||
|
||||
return fVNtupleManager->CreateNtupleDColumn(ntupleId, name, &vector);
|
||||
return fNtupleBookingManager->CreateNtupleDColumn(ntupleId, name, &vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::FinishNtuple(G4int ntupleId)
|
||||
{
|
||||
return fVNtupleManager->FinishNtuple(ntupleId);
|
||||
auto ntupleBooking = fNtupleBookingManager->FinishNtuple(ntupleId);
|
||||
|
||||
if ( fVNtupleManager ) {
|
||||
fVNtupleManager->CreateNtuple(ntupleBooking);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -996,13 +1019,33 @@ G4bool G4VAnalysisManager::SetFirstP2Id(G4int firstId)
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4VAnalysisManager::SetFirstNtupleId(G4int firstId)
|
||||
{
|
||||
return fVNtupleManager->SetFirstId(firstId);
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = fNtupleBookingManager->SetFirstId(firstId);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
if ( fVNtupleManager ) {
|
||||
result = fVNtupleManager->SetFirstId(firstId);
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4VAnalysisManager::SetFirstNtupleColumnId(G4int firstId)
|
||||
{
|
||||
return fVNtupleManager->SetFirstNtupleColumnId(firstId);
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = fNtupleBookingManager->SetFirstNtupleColumnId(firstId);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
if ( fVNtupleManager ) {
|
||||
result = fVNtupleManager->SetFirstNtupleColumnId(firstId);
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
// Fill methods in .icc
|
||||
@@ -1098,7 +1141,7 @@ G4int G4VAnalysisManager::GetFirstNtupleId() const
|
||||
{
|
||||
// Return first Ntuple id
|
||||
|
||||
return fVNtupleManager->GetFirstId();
|
||||
return fNtupleBookingManager->GetFirstId();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -1106,7 +1149,7 @@ G4int G4VAnalysisManager::GetFirstNtupleColumnId() const
|
||||
{
|
||||
// Return first Ntuple column id
|
||||
|
||||
return fVNtupleManager->GetFirstNtupleColumnId();
|
||||
return fNtupleBookingManager->GetFirstNtupleColumnId();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -1175,6 +1218,12 @@ void G4VAnalysisManager::SetH1Plotting(G4int id, G4bool plotting)
|
||||
fH1HnManager->SetPlotting(id, plotting);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetH1FileName(G4int id, const G4String& fileName)
|
||||
{
|
||||
fH1HnManager->SetFileName(id, fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetH2Activation(G4int id, G4bool activation)
|
||||
{
|
||||
@@ -1203,6 +1252,12 @@ void G4VAnalysisManager::SetH2Plotting(G4int id, G4bool plotting)
|
||||
fH2HnManager->SetPlotting(id, plotting);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetH2FileName(G4int id, const G4String& fileName)
|
||||
{
|
||||
fH2HnManager->SetFileName(id, fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetH3Activation(G4int id, G4bool activation)
|
||||
{
|
||||
@@ -1231,6 +1286,12 @@ void G4VAnalysisManager::SetH3Plotting(G4int id, G4bool plotting)
|
||||
fH3HnManager->SetPlotting(id, plotting);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetH3FileName(G4int id, const G4String& fileName)
|
||||
{
|
||||
fH3HnManager->SetFileName(id, fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetP1Activation(G4int id, G4bool activation)
|
||||
{
|
||||
@@ -1259,6 +1320,12 @@ void G4VAnalysisManager::SetP1Plotting(G4int id, G4bool plotting)
|
||||
fP1HnManager->SetPlotting(id, plotting);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetP1FileName(G4int id, const G4String& fileName)
|
||||
{
|
||||
fP1HnManager->SetFileName(id, fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetP2Activation(G4int id, G4bool activation)
|
||||
{
|
||||
@@ -1287,21 +1354,49 @@ void G4VAnalysisManager::SetP2Plotting(G4int id, G4bool plotting)
|
||||
fP2HnManager->SetPlotting(id, plotting);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetP2FileName(G4int id, const G4String& fileName)
|
||||
{
|
||||
fP2HnManager->SetFileName(id, fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetNtupleActivation(G4int id, G4bool activation)
|
||||
{
|
||||
// Set activation to a given P2 object
|
||||
// Set activation to a given ntuple object
|
||||
|
||||
fVNtupleManager->SetActivation(id, activation);
|
||||
}
|
||||
fNtupleBookingManager->SetActivation(id, activation);
|
||||
if ( fVNtupleManager ) {
|
||||
fVNtupleManager->SetActivation(id, activation);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetNtupleActivation(G4bool activation)
|
||||
{
|
||||
// Set activation to all ntuple objects
|
||||
|
||||
fNtupleBookingManager->SetActivation(activation);
|
||||
if ( fVNtupleManager ) {
|
||||
fVNtupleManager->SetActivation(activation);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetNtupleFileName(G4int id, const G4String& fileName)
|
||||
{
|
||||
// Set activation to a given P2 object
|
||||
|
||||
fNtupleBookingManager->SetFileName(id, fileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VAnalysisManager::SetNtupleFileName(const G4String& fileName)
|
||||
{
|
||||
// Set activation to all P2 objects
|
||||
|
||||
fVNtupleManager->SetActivation(activation);
|
||||
}
|
||||
fNtupleBookingManager->SetFileName(fileName);
|
||||
}
|
||||
|
||||
// Access methods in .icc
|
||||
|
||||
|
||||
@@ -28,18 +28,22 @@
|
||||
|
||||
#include "G4VFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VFileManager::G4VFileManager(const G4AnalysisManagerState& state)
|
||||
: G4BaseFileManager(state),
|
||||
fIsOpenFile(false),
|
||||
fHistoDirectoryName(""),
|
||||
fNtupleDirectoryName(""),
|
||||
fLockFileName(false),
|
||||
fLockHistoDirectoryName(false),
|
||||
fLockNtupleDirectoryName(false)
|
||||
fIsOpenFile(false),
|
||||
fLockDirectoryNames(false),
|
||||
fH1FileManager(nullptr),
|
||||
fH2FileManager(nullptr),
|
||||
fH3FileManager(nullptr),
|
||||
fP1FileManager(nullptr),
|
||||
fP2FileManager(nullptr)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -53,22 +57,28 @@ G4VFileManager::~G4VFileManager()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4VFileManager::SetFileName(const G4String& fileName)
|
||||
{
|
||||
if ( fLockFileName ) {
|
||||
// Check extension
|
||||
auto name = fileName;
|
||||
auto extension = G4Analysis::GetExtension(fileName);
|
||||
if ( extension.size() && GetFileType().size() && extension != GetFileType() ) {
|
||||
// replace extension
|
||||
name = G4Analysis::GetBaseName(fileName) + "." + GetFileType();
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot set File name as its value was already used.";
|
||||
<< fileName << " file extension is not valid for "
|
||||
<< GetFileType() << " output." << G4endl
|
||||
<< name << " will be used.";
|
||||
G4Exception("G4VFileManager::SetFileName()",
|
||||
"Analysis_W012", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return G4BaseFileManager::SetFileName(fileName);
|
||||
}
|
||||
return G4BaseFileManager::SetFileName(name);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4VFileManager::SetHistoDirectoryName(const G4String& dirName)
|
||||
{
|
||||
if ( fLockHistoDirectoryName ) {
|
||||
if ( fLockDirectoryNames ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot set Histo directory name as its value was already used.";
|
||||
@@ -84,7 +94,7 @@ G4bool G4VFileManager::SetHistoDirectoryName(const G4String& dirName)
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4VFileManager::SetNtupleDirectoryName(const G4String& dirName)
|
||||
{
|
||||
if ( fLockNtupleDirectoryName ) {
|
||||
if ( fLockDirectoryNames ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot set Ntuple directory name as its value was already used.";
|
||||
@@ -95,4 +105,4 @@ G4bool G4VFileManager::SetNtupleDirectoryName(const G4String& dirName)
|
||||
|
||||
fNtupleDirectoryName = dirName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void NtupleMergingWarning(const G4String& functionName,
|
||||
const G4String& outputType)
|
||||
{
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "Ntuple merging is not available with "
|
||||
<< outputType << " output." << G4endl
|
||||
<< " " << "Setting is ignored.";
|
||||
G4Exception(functionName, "Analysis_W041", JustWarning, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VNtupleFileManager::G4VNtupleFileManager(const G4AnalysisManagerState& state,
|
||||
const G4String& fileType)
|
||||
: fState(state),
|
||||
fFileType(fileType),
|
||||
fBookingManager(nullptr)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VNtupleFileManager::~G4VNtupleFileManager()
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VNtupleFileManager::SetNtupleMerging(G4bool /*mergeNtuples*/,
|
||||
G4int /*nofReducedNtupleFiles*/)
|
||||
{
|
||||
// The function is overridden in the managers which supports ntuple merging
|
||||
// Here we give just a warning that the feature is not available.
|
||||
|
||||
NtupleMergingWarning("G4VNtupleFileManager::SetNtupleMerging", fFileType);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VNtupleFileManager::SetNtupleRowWise(G4bool /*rowWise*/,
|
||||
G4bool /*rowMode*/)
|
||||
{
|
||||
// The function is overridden in the managers which supports ntuple merging
|
||||
// Here we give just a warning that the feature is not available.
|
||||
|
||||
NtupleMergingWarning("G4VNtupleFileManager::SetNtupleRowWise", fFileType);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VNtupleFileManager::SetBasketSize(unsigned int /*basketSize*/)
|
||||
{
|
||||
// The function is overridden in the managers which supports ntuple merging
|
||||
// Here we give just a warning that the feature is not available.
|
||||
|
||||
NtupleMergingWarning("G4VNtupleFileManager::SetBasketSize", fFileType);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4VNtupleFileManager::SetBasketEntries(unsigned int /*basketEntries*/)
|
||||
{
|
||||
// The function is overridden in the managers which supports ntuple merging
|
||||
// Here we give just a warning that the feature is not available.
|
||||
|
||||
NtupleMergingWarning("G4VNtupleFileManager::SetBasketEntries", fFileType);
|
||||
}
|
||||
Reference in New Issue
Block a user