Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Root analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -39,25 +39,29 @@
|
||||
#include "tools/histo/hmpi"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4RootAnalysisManager;
|
||||
class G4RootFileManager;
|
||||
class G4RootNtupleFileManager;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class directory;
|
||||
class directory;
|
||||
}
|
||||
}
|
||||
|
||||
class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
friend class G4RootMpiAnalysisManager;
|
||||
friend class G4ThreadLocalSingleton<G4RootAnalysisManager>;
|
||||
|
||||
public:
|
||||
explicit G4RootAnalysisManager(G4bool isMaster = true);
|
||||
virtual ~G4RootAnalysisManager();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4RootAnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
@@ -72,7 +76,7 @@ class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator EndConstNtuple() const;
|
||||
|
||||
// MT/MPI
|
||||
virtual void SetNtupleMerging(G4bool mergeNtuples,
|
||||
virtual void SetNtupleMerging(G4bool mergeNtuples,
|
||||
G4int nofReducedNtupleFiles = 0) override;
|
||||
virtual void SetNtupleRowWise(G4bool rowWise, G4bool rowMode = true) override;
|
||||
virtual void SetBasketSize(unsigned int basketSize) override;
|
||||
@@ -82,31 +86,21 @@ class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
// virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) override;
|
||||
virtual G4bool WriteImpl() override;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) override;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) override;
|
||||
virtual G4bool ResetImpl() override;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
|
||||
// virtual functions (overriden in MPI implementation)
|
||||
virtual G4bool Reset();
|
||||
|
||||
private:
|
||||
// static data members
|
||||
static G4RootAnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4RootAnalysisManager* fgInstance;
|
||||
G4RootAnalysisManager();
|
||||
|
||||
// methods
|
||||
template <typename T>
|
||||
G4bool WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType);
|
||||
G4bool WriteH1();
|
||||
G4bool WriteH2();
|
||||
G4bool WriteH3();
|
||||
G4bool WriteP1();
|
||||
G4bool WriteP2();
|
||||
// Static data members
|
||||
inline static G4RootAnalysisManager* fgMasterInstance { nullptr };
|
||||
inline static G4ThreadLocal G4bool fgIsInstance { false };
|
||||
static constexpr std::string_view fkClass { "G4RootAnalysisManager" };
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
std::shared_ptr<G4RootNtupleFileManager> fNtupleFileManager;
|
||||
// data members
|
||||
std::shared_ptr<G4RootFileManager> fFileManager { nullptr };
|
||||
std::shared_ptr<G4RootNtupleFileManager> fNtupleFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4RootAnalysisManager.icc"
|
||||
|
||||
@@ -28,46 +28,6 @@
|
||||
#include "G4RootNtupleFileManager.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
|
||||
#include "tools/wroot/to"
|
||||
#include "tools/wroot/file"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4RootAnalysisManager::WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& hnType)
|
||||
{
|
||||
// Do nothing if there is no file
|
||||
if ( ! fFileManager->GetFile() ) return true;
|
||||
|
||||
auto directory = std::get<1>(*fFileManager->GetFile());
|
||||
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if activation is enabled and H1 is inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()->Message("write", hnType, name);
|
||||
#endif
|
||||
G4bool result
|
||||
= to(*directory, *ht, name);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4RootAnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
G4bool G4RootAnalysisManager::IsOpenFileImpl() const
|
||||
@@ -80,41 +40,41 @@ inline
|
||||
tools::wroot::ntuple* G4RootAnalysisManager::GetNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::wroot::ntuple* G4RootAnalysisManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple(ntupleId);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wroot::ntuple*>::iterator G4RootAnalysisManager::BeginNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wroot::ntuple*>::iterator G4RootAnalysisManager::EndNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator
|
||||
G4RootAnalysisManager::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator
|
||||
G4RootAnalysisManager::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Root analysis reader.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 09/04/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -35,66 +35,51 @@
|
||||
#include "G4ToolsAnalysisReader.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
#include "tools/rroot/ntuple"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4RootAnalysisReader;
|
||||
class G4RootRFileManager;
|
||||
class G4H1ToolsManager;
|
||||
class G4H2ToolsManager;
|
||||
class G4H3ToolsManager;
|
||||
class G4P1ToolsManager;
|
||||
class G4P2ToolsManager;
|
||||
class G4RootRNtupleManager;
|
||||
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4RootAnalysisReader : public G4ToolsAnalysisReader
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4RootAnalysisReader>;
|
||||
|
||||
public:
|
||||
explicit G4RootAnalysisReader(G4bool isMaster = true);
|
||||
virtual ~G4RootAnalysisReader();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4RootAnalysisReader* Instance();
|
||||
|
||||
|
||||
// Access methods
|
||||
tools::rroot::ntuple* GetNtuple() const;
|
||||
tools::rroot::ntuple* GetNtuple(G4int ntupleId) const;
|
||||
using G4VAnalysisReader::GetNtuple;
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
virtual G4int ReadH1Impl(const G4String& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH2Impl(const G4String& h2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH3Impl(const G4String& h3Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP1Impl(const G4String& p1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP2Impl(const G4String& p2Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
static G4RootAnalysisReader* fgMasterInstance;
|
||||
static G4ThreadLocal G4RootAnalysisReader* fgInstance;
|
||||
|
||||
// methods
|
||||
//
|
||||
tools::rroot::buffer* GetBuffer(
|
||||
const G4String& fileName,
|
||||
const G4String& name,
|
||||
const G4String& inFunction);
|
||||
protected:
|
||||
G4RootAnalysisReader();
|
||||
|
||||
// // Virtual methods from base class
|
||||
virtual G4bool CloseFilesImpl(G4bool reset) final;
|
||||
|
||||
private:
|
||||
// Static data members
|
||||
inline static G4RootAnalysisReader* fgMasterInstance { nullptr };
|
||||
|
||||
// Methods
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4RootRNtupleManager* fNtupleManager;
|
||||
G4RootRFileManager* fFileManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootAnalysisReader" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4RootRNtupleManager> fNtupleManager { nullptr };
|
||||
std::shared_ptr<G4RootRFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4RootAnalysisReader.icc"
|
||||
|
||||
@@ -31,11 +31,11 @@ inline
|
||||
tools::rroot::ntuple* G4RootAnalysisReader::GetNtuple() const
|
||||
{
|
||||
return fNtupleManager->GetNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::rroot::ntuple* G4RootAnalysisReader::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleManager->GetNtuple(ntupleId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,16 +33,18 @@
|
||||
|
||||
#include "G4VTFileManager.hh"
|
||||
#include "G4RootFileDef.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <string_view>
|
||||
|
||||
namespace tools {
|
||||
namespace wroot{
|
||||
class ntuple;
|
||||
}
|
||||
class ntuple;
|
||||
}
|
||||
}
|
||||
|
||||
// Types alias
|
||||
@@ -52,7 +54,8 @@ class G4RootFileManager : public G4VTFileManager<G4RootFile>
|
||||
{
|
||||
public:
|
||||
explicit G4RootFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4RootFileManager();
|
||||
G4RootFileManager() = delete;
|
||||
virtual ~G4RootFileManager() = default;
|
||||
|
||||
using G4BaseFileManager::GetNtupleFileName;
|
||||
using G4VTFileManager<G4RootFile>::WriteFile;
|
||||
@@ -64,13 +67,13 @@ class G4RootFileManager : public G4VTFileManager<G4RootFile>
|
||||
virtual G4String GetFileType() const final { return "root"; }
|
||||
|
||||
// Specific methods for files per objects
|
||||
std::shared_ptr<G4RootFile> CreateNtupleFile(RootNtupleDescription* ntupleDescription,
|
||||
std::shared_ptr<G4RootFile> CreateNtupleFile(RootNtupleDescription* ntupleDescription,
|
||||
G4int mainNumber = -1);
|
||||
std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription,
|
||||
std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription,
|
||||
G4bool perThread = true,
|
||||
G4int mainNumber = -1) const;
|
||||
G4bool WriteNtupleFile(RootNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(RootNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(RootNtupleDescription* ntupleDescription);
|
||||
|
||||
// Set methods
|
||||
void SetBasketSize(unsigned int basketSize);
|
||||
@@ -84,32 +87,35 @@ class G4RootFileManager : public G4VTFileManager<G4RootFile>
|
||||
// Methods derived from templated base class
|
||||
virtual std::shared_ptr<G4RootFile> CreateFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteFileImpl(std::shared_ptr<G4RootFile> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<G4RootFile> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<G4RootFile> file) final;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
tools::wroot::directory* CreateDirectory(
|
||||
std::shared_ptr<tools::wroot::file> rfile,
|
||||
const G4String& directoryName,
|
||||
tools::wroot::file* rfile,
|
||||
const G4String& directoryName,
|
||||
const G4String& objectType) const;
|
||||
G4String GetNtupleFileName(
|
||||
RootNtupleDescription* ntupleDescription,
|
||||
RootNtupleDescription* ntupleDescription,
|
||||
G4bool perThread = true,
|
||||
G4int mainNumber = -1) const;
|
||||
|
||||
// data members
|
||||
unsigned int fBasketSize;
|
||||
unsigned int fBasketEntries;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootFileManager" };
|
||||
|
||||
// Data members
|
||||
unsigned int fBasketSize { G4Analysis::kDefaultBasketSize };
|
||||
unsigned int fBasketEntries { G4Analysis::kDefaultBasketEntries };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4RootFileManager::SetBasketSize(unsigned int basketSize)
|
||||
inline void G4RootFileManager::SetBasketSize(unsigned int basketSize)
|
||||
{ fBasketSize = basketSize; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4RootFileManager::SetBasketEntries(unsigned int basketEntries)
|
||||
inline void G4RootFileManager::SetBasketEntries(unsigned int basketEntries)
|
||||
{ fBasketEntries = basketEntries; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
@@ -34,15 +34,18 @@
|
||||
#include "G4VTHnFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4RootFileManager;
|
||||
|
||||
template <typename HT>
|
||||
class G4RootHnFileManager : public G4VTHnFileManager<HT>
|
||||
{
|
||||
public:
|
||||
G4RootHnFileManager(G4RootFileManager* fileManger)
|
||||
explicit G4RootHnFileManager(G4RootFileManager* fileManger)
|
||||
: G4VTHnFileManager<HT>(), fFileManager(fileManger) {}
|
||||
virtual ~G4RootHnFileManager() {}
|
||||
G4RootHnFileManager() = delete;
|
||||
virtual ~G4RootHnFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
// Write to a new file (the file is closed after write)
|
||||
@@ -50,12 +53,15 @@ class G4RootHnFileManager : public G4VTHnFileManager<HT>
|
||||
// Write to the default file (handled with OpenFile()/CloseFile methods)
|
||||
virtual G4bool Write(HT* ht, const G4String& htName, G4String& fileName) final;
|
||||
|
||||
private:
|
||||
private:
|
||||
// Methods
|
||||
G4bool Write(tools::wroot::directory* directory, HT* ht, const G4String& htName);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootHnFileManager<HT>" };
|
||||
|
||||
// Data members
|
||||
G4RootFileManager* fFileManager;
|
||||
G4RootFileManager* fFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4RootHnFileManager.icc"
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wroot/to"
|
||||
#include "tools/wroot/file"
|
||||
#include "tools/zlib"
|
||||
@@ -44,11 +46,10 @@ template <typename HT>
|
||||
G4bool G4RootHnFileManager<HT>::WriteExtra(
|
||||
HT* ht, const G4String& htName, const G4String& fileName)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// // create a new file
|
||||
tools::wroot::file* rfile = new tools::wroot::file(G4cout, fileName);
|
||||
auto rfile = new tools::wroot::file(G4cout, fileName);
|
||||
// TO DO
|
||||
// rfile->add_ziper('Z', tools::compress_buffer);
|
||||
// rfile->set_compression(fState.GetCompressionLevel());
|
||||
@@ -59,18 +60,16 @@ G4bool G4RootHnFileManager<HT>::WriteExtra(
|
||||
if ( ! hdirectory ) return false;
|
||||
|
||||
// write histo
|
||||
result = Write(hdirectory, ht, htName);
|
||||
finalResult = result && finalResult;
|
||||
result &= Write(hdirectory, ht, htName);
|
||||
|
||||
// write file
|
||||
unsigned int n;
|
||||
result = rfile->write(n);
|
||||
finalResult = result && finalResult;
|
||||
result &= rfile->write(n);
|
||||
|
||||
// close file
|
||||
rfile->close();
|
||||
|
||||
return finalResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -87,11 +86,9 @@ G4bool G4RootHnFileManager<HT>::Write(
|
||||
|
||||
auto hdirectory = std::get<1>(*fFileManager->GetTFile(fileName));
|
||||
if ( hdirectory == nullptr ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Failed to get Root file " << fileName << " histo directory.";
|
||||
G4Exception("G4RootHnFileManager<HT>::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Failed to get Root file " + fileName + " histo directory.",
|
||||
fkClass, "Write");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+48
-7
@@ -24,15 +24,56 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
|
||||
// The manager class for histogram/profile reading from a Root file.
|
||||
|
||||
#ifndef g4root_h
|
||||
#define g4root_h
|
||||
// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "g4root_defs.hh"
|
||||
#ifndef G4RootHnRFileManager_h
|
||||
#define G4RootHnRFileManager_h 1
|
||||
|
||||
using namespace G4Root;
|
||||
#include "G4VTHnRFileManager.hh"
|
||||
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
|
||||
class G4RootRFileManager;
|
||||
|
||||
namespace tools {
|
||||
namespace rroot {
|
||||
class buffer;
|
||||
class TDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename HT>
|
||||
class G4RootHnRFileManager : public G4VTHnRFileManager<HT>
|
||||
{
|
||||
public:
|
||||
explicit G4RootHnRFileManager(G4RootRFileManager* rfileManger)
|
||||
: G4VTHnRFileManager<HT>(), fRFileManager(rfileManger) {}
|
||||
G4RootHnRFileManager() = delete;
|
||||
virtual ~G4RootHnRFileManager() = default;
|
||||
|
||||
// Methods for reading objects
|
||||
virtual HT* Read(const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
|
||||
private:
|
||||
// Methods
|
||||
std::tuple<tools::rroot::buffer*, tools::rroot::TDirectory*> GetBuffer(
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
const G4String& name);
|
||||
HT* ReadT(tools::rroot::buffer* buffer);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootHnRFileManager<HT>" };
|
||||
// Data members
|
||||
G4RootRFileManager* fRFileManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4RootHnRFileManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/rroot/file"
|
||||
#include "tools/rroot/rall"
|
||||
#include "tools/rroot/streamers"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
std::tuple<tools::rroot::buffer*, tools::rroot::TDirectory*>
|
||||
G4RootHnRFileManager<HT>::GetBuffer(
|
||||
const G4String& fileName, const G4String& dirName, const G4String& objectName)
|
||||
{
|
||||
// Get buffer for reading histogram or profile specified by objectNmae
|
||||
// for a file specified by fileName;
|
||||
// Open the file if it was not yet open
|
||||
|
||||
// Histograms and profiles are not saved per thread
|
||||
G4bool isPerThread = false;
|
||||
|
||||
// Get or open a file
|
||||
auto rfile = fRFileManager->GetRFile(fileName, isPerThread);
|
||||
if ( ! rfile ) {
|
||||
if ( ! fRFileManager->OpenRFile(fileName, isPerThread) ) {
|
||||
return std::tuple(nullptr, nullptr);
|
||||
}
|
||||
rfile = fRFileManager->GetRFile(fileName, isPerThread);
|
||||
}
|
||||
|
||||
// Get key
|
||||
tools::rroot::key* key = nullptr;
|
||||
tools::rroot::TDirectory* newDir = nullptr;
|
||||
if ( ! dirName.empty() ) {
|
||||
newDir = tools::rroot::find_dir(rfile->dir(), dirName);
|
||||
if ( newDir ) {
|
||||
key = newDir->find_key(objectName);
|
||||
}
|
||||
else {
|
||||
G4Analysis::Warn(
|
||||
"Directory " + dirName + " not found in file " + fileName + ".",
|
||||
fkClass, "GetBuffer");
|
||||
return std::tuple(nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
else {
|
||||
key = rfile->dir().find_key(objectName);
|
||||
}
|
||||
|
||||
if ( ! key ) {
|
||||
G4Analysis::Warn(
|
||||
"Key " + objectName + " for Histogram/Profile not found in file " +
|
||||
fileName + ", directory " + dirName, fkClass, "GetBuffer");
|
||||
return std::tuple(nullptr, newDir);
|
||||
}
|
||||
|
||||
unsigned int size;
|
||||
char* charBuffer = key->get_object_buffer(*rfile, size);
|
||||
|
||||
if ( ! charBuffer ) {
|
||||
G4Analysis::Warn(
|
||||
"Cannot get " + objectName + " in file " + fileName,
|
||||
fkClass, "GetBuffer");
|
||||
return std::tuple(nullptr, newDir);
|
||||
}
|
||||
|
||||
auto verbose = false;
|
||||
return std::tuple(new tools::rroot::buffer(G4cout, rfile->byte_swap(), size, charBuffer,
|
||||
key->key_length(), verbose), newDir);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
tools::histo::h1d* G4RootHnRFileManager<tools::histo::h1d>::ReadT(
|
||||
tools::rroot::buffer* buffer)
|
||||
{
|
||||
return tools::rroot::TH1D_stream(*buffer);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
tools::histo::h2d* G4RootHnRFileManager<tools::histo::h2d>::ReadT(
|
||||
tools::rroot::buffer* buffer)
|
||||
{
|
||||
return tools::rroot::TH2D_stream(*buffer);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
tools::histo::h3d* G4RootHnRFileManager<tools::histo::h3d>::ReadT(
|
||||
tools::rroot::buffer* buffer)
|
||||
{
|
||||
return tools::rroot::TH3D_stream(*buffer);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
tools::histo::p1d* G4RootHnRFileManager<tools::histo::p1d>::ReadT(
|
||||
tools::rroot::buffer* buffer)
|
||||
{
|
||||
return tools::rroot::TProfile_stream(*buffer);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline
|
||||
tools::histo::p2d* G4RootHnRFileManager<tools::histo::p2d>::ReadT(
|
||||
tools::rroot::buffer* buffer)
|
||||
{
|
||||
return tools::rroot::TProfile2D_stream(*buffer);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
HT* G4RootHnRFileManager<HT>::Read(
|
||||
const G4String& htName, const G4String& fileName, const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
auto [buffer, newDir] = GetBuffer(fileName, dirName, htName);
|
||||
if ( ! buffer ) {
|
||||
delete newDir;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto ht = ReadT(buffer);
|
||||
delete buffer;
|
||||
delete newDir;
|
||||
|
||||
if ( ! ht ) {
|
||||
G4Analysis::Warn(
|
||||
"Streaming " + htName + " in file " + fileName + " failed.",
|
||||
fkClass, "Read");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ht;
|
||||
}
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
class G4RootFileManager;
|
||||
class G4RootNtupleManager;
|
||||
@@ -59,18 +60,20 @@ class G4RootMainNtupleManager : public G4BaseAnalysisManager
|
||||
friend class G4RootNtupleManager;
|
||||
|
||||
public:
|
||||
explicit G4RootMainNtupleManager(
|
||||
G4RootMainNtupleManager(
|
||||
G4RootNtupleManager* ntupleBuilder,
|
||||
G4NtupleBookingManager* bookingManager,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManager,
|
||||
G4bool rowWise, G4int fileNumber,
|
||||
const G4AnalysisManagerState& state);
|
||||
~G4RootMainNtupleManager();
|
||||
G4RootMainNtupleManager() = delete;
|
||||
virtual ~G4RootMainNtupleManager() = default;
|
||||
|
||||
protected:
|
||||
// Methods to manipulate ntuples
|
||||
// Methods to manipulate ntuples
|
||||
void CreateNtuple(RootNtupleDescription* ntupleDescription, G4bool warn = true);
|
||||
G4bool Merge();
|
||||
G4bool Reset(G4bool deleteNtuple);
|
||||
G4bool Reset();
|
||||
void ClearData();
|
||||
|
||||
// Set/get methods
|
||||
void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
|
||||
@@ -78,15 +81,18 @@ class G4RootMainNtupleManager : public G4BaseAnalysisManager
|
||||
std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription) const;
|
||||
|
||||
// Access functions
|
||||
const std::vector<tools::wroot::ntuple*>& GetNtupleVector()
|
||||
const std::vector<tools::wroot::ntuple*>& GetNtupleVector()
|
||||
{ return fNtupleVector; }
|
||||
unsigned int GetBasketEntries() const;
|
||||
|
||||
private:
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootMainNtupleManager" };
|
||||
|
||||
// Data members
|
||||
G4RootNtupleManager* fNtupleBuilder;
|
||||
G4NtupleBookingManager* fBookingManager;
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
G4RootNtupleManager* fNtupleBuilder { nullptr };
|
||||
std::shared_ptr<G4NtupleBookingManager> fBookingManager { nullptr };
|
||||
std::shared_ptr<G4RootFileManager> fFileManager { nullptr };
|
||||
G4bool fRowWise;
|
||||
G4int fFileNumber;
|
||||
std::vector<tools::wroot::ntuple*> fNtupleVector;
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4RootFileManager;
|
||||
class G4RootNtupleManager;
|
||||
class G4RootPNtupleManager;
|
||||
@@ -52,10 +54,11 @@ class G4RootNtupleFileManager : public G4VNtupleFileManager
|
||||
|
||||
public:
|
||||
explicit G4RootNtupleFileManager(const G4AnalysisManagerState& state);
|
||||
G4RootNtupleFileManager() = delete;
|
||||
virtual ~G4RootNtupleFileManager();
|
||||
|
||||
// MT/MPI
|
||||
virtual void SetNtupleMerging(G4bool mergeNtuples,
|
||||
virtual void SetNtupleMerging(G4bool mergeNtuples,
|
||||
G4int nofReducedNtupleFiles = 0) override;
|
||||
virtual void SetNtupleRowWise(G4bool rowWise, G4bool rowMode = true) override;
|
||||
virtual void SetBasketSize(unsigned int basketSize) override;
|
||||
@@ -64,10 +67,10 @@ class G4RootNtupleFileManager : public G4VNtupleFileManager
|
||||
// virtual methods from base class
|
||||
virtual G4bool ActionAtOpenFile(const G4String& fileName) override;
|
||||
virtual G4bool ActionAtWrite() override;
|
||||
virtual G4bool ActionAtCloseFile(G4bool reset) override;
|
||||
virtual G4bool ActionAtCloseFile(G4bool reset) override;
|
||||
virtual G4bool Reset() override;
|
||||
virtual G4bool IsNtupleMergingSupported() const override;
|
||||
|
||||
|
||||
virtual std::shared_ptr<G4VNtupleManager> CreateNtupleManager() override;
|
||||
|
||||
void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
|
||||
@@ -76,23 +79,25 @@ class G4RootNtupleFileManager : public G4VNtupleFileManager
|
||||
std::shared_ptr<G4RootNtupleManager> GetNtupleManager() const;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
// Static data members
|
||||
static G4RootNtupleFileManager* fgMasterInstance;
|
||||
|
||||
void SetNtupleMergingMode(G4bool mergeNtuples, G4int nofNtupleFiles);
|
||||
G4int GetNtupleFileNumber();
|
||||
G4bool CloseNtupleFiles();
|
||||
|
||||
// data members
|
||||
G4bool fIsInitialized;
|
||||
G4int fNofNtupleFiles;
|
||||
G4bool fNtupleRowWise;
|
||||
G4bool fNtupleRowMode;
|
||||
G4NtupleMergeMode fNtupleMergeMode;
|
||||
std::shared_ptr<G4RootNtupleManager> fNtupleManager;
|
||||
std::shared_ptr<G4RootPNtupleManager> fSlaveNtupleManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootNtupleFileManager" };
|
||||
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
// data members
|
||||
G4bool fIsInitialized { false };
|
||||
G4int fNofNtupleFiles { 0 };
|
||||
G4bool fNtupleRowWise { false };
|
||||
G4bool fNtupleRowMode { true };
|
||||
G4NtupleMergeMode fNtupleMergeMode { G4NtupleMergeMode::kNone };
|
||||
std::shared_ptr<G4RootNtupleManager> fNtupleManager { nullptr };
|
||||
std::shared_ptr<G4RootPNtupleManager> fSlaveNtupleManager { nullptr };
|
||||
std::shared_ptr<G4RootFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
inline void G4RootNtupleFileManager::SetFileManager(
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
#include "tools/wroot/ntuple"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4RootMainNtupleManager;
|
||||
class G4NtupleBookingManager;
|
||||
class G4RootFileManager;
|
||||
@@ -54,7 +56,7 @@ G4bool G4TNtupleManager<tools::wroot::ntuple, G4RootFile>::FillNtupleTColumn(
|
||||
|
||||
|
||||
class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple,
|
||||
G4RootFile>
|
||||
G4RootFile>
|
||||
{
|
||||
friend class G4RootAnalysisManager;
|
||||
friend class G4RootMainNtupleManager;
|
||||
@@ -63,11 +65,12 @@ class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple,
|
||||
friend class G4RootMpiNtupleManager;
|
||||
|
||||
public:
|
||||
explicit G4RootNtupleManager(const G4AnalysisManagerState& state,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManger,
|
||||
G4RootNtupleManager(const G4AnalysisManagerState& state,
|
||||
const std::shared_ptr<G4NtupleBookingManager>& bookingManger,
|
||||
G4int nofMainManagers, G4int nofReducedFiles,
|
||||
G4bool rowWise, G4bool rowMode);
|
||||
virtual ~G4RootNtupleManager();
|
||||
G4RootNtupleManager() = delete;
|
||||
virtual ~G4RootNtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Methods from the templated base class
|
||||
@@ -76,11 +79,12 @@ class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple,
|
||||
virtual void FinishTNtuple(
|
||||
RootNtupleDescription* ntupleDescription,
|
||||
G4bool fromBooking) final;
|
||||
virtual G4bool Reset(G4bool deleteNtuple) final;
|
||||
virtual G4bool Reset() final;
|
||||
virtual void Clear() final;
|
||||
virtual G4bool Merge();
|
||||
|
||||
// Set functions
|
||||
void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
|
||||
void SetFileManager(const std::shared_ptr<G4RootFileManager>& fileManager);
|
||||
void SetNtupleFile(std::shared_ptr<G4RootFile> file);
|
||||
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
|
||||
|
||||
@@ -90,14 +94,16 @@ class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple,
|
||||
unsigned int GetBasketSize() const;
|
||||
unsigned int GetBasketEntries() const;
|
||||
|
||||
// data members
|
||||
//
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootNtupleManager" };
|
||||
|
||||
// Rata members
|
||||
std::shared_ptr<G4RootFileManager> fFileManager { nullptr };
|
||||
std::vector<std::shared_ptr<G4RootMainNtupleManager>> fMainNtupleManagers;
|
||||
std::shared_ptr<G4RootFile> fNtupleFile;
|
||||
std::shared_ptr<G4RootFile> fNtupleFile { nullptr };
|
||||
G4bool fRowWise;
|
||||
G4bool fRowMode;
|
||||
};
|
||||
};
|
||||
|
||||
#include "G4RootNtupleManager.icc"
|
||||
|
||||
|
||||
@@ -26,15 +26,19 @@
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
using std::to_string;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4RootNtupleManager::SetNtupleFile(std::shared_ptr<G4RootFile> file)
|
||||
inline void G4RootNtupleManager::SetNtupleFile(std::shared_ptr<G4RootFile> file)
|
||||
{
|
||||
fNtupleFile = file;
|
||||
fNtupleFile = std::move(file);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline const
|
||||
std::vector<G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>* >&
|
||||
inline const
|
||||
std::vector<G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>* >&
|
||||
G4RootNtupleManager::GetNtupleDescriptionVector() const
|
||||
{
|
||||
return fNtupleDescriptionVector;
|
||||
@@ -47,44 +51,38 @@ inline G4bool G4TNtupleManager<tools::wroot::ntuple, G4RootFile>::FillNtupleTCol
|
||||
G4int ntupleId, G4int columnId, const std::string& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
//G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
//G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4RootNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"ntupleId " + to_string(ntupleId) + " columnId " + to_string(columnId) +
|
||||
" does not exist.",
|
||||
fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
auto column = dynamic_cast<tools::wroot::ntuple::column_string* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4RootNtupleManager:FillNtupleColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"Column type does not match: ntupleId " + to_string(ntupleId) +
|
||||
" columnId " + to_string(columnId) + " value " + value,
|
||||
fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "ntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "fill", "ntuple T column",
|
||||
" ntupleId " + to_string(ntupleId) + " columnId " + to_string(columnId) +
|
||||
" value " + value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,21 +52,18 @@ using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootF
|
||||
|
||||
struct G4RootPNtupleDescription
|
||||
{
|
||||
G4RootPNtupleDescription(G4NtupleBooking* g4NtupleBooking)
|
||||
: fDescription(g4NtupleBooking),
|
||||
fNtuple(nullptr),
|
||||
fBasePNtuple(nullptr),
|
||||
fMainBranches() {}
|
||||
G4RootPNtupleDescription(G4NtupleBooking* g4NtupleBooking)
|
||||
: fDescription(g4NtupleBooking) {}
|
||||
|
||||
~G4RootPNtupleDescription()
|
||||
{
|
||||
if ( fDescription.fIsNtupleOwner ) delete fNtuple;
|
||||
}
|
||||
}
|
||||
|
||||
RootNtupleDescription fDescription;
|
||||
tools::wroot::imt_ntuple* fNtuple;
|
||||
tools::wroot::base_pntuple* fBasePNtuple;
|
||||
std::vector<tools::wroot::branch*> fMainBranches;
|
||||
tools::wroot::imt_ntuple* fNtuple { nullptr };
|
||||
tools::wroot::base_pntuple* fBasePNtuple { nullptr };
|
||||
std::vector<tools::wroot::branch*> fMainBranches;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
class G4RootMainNtupleManager;
|
||||
|
||||
@@ -54,20 +55,20 @@ class imt_ntuple;
|
||||
// with replacement tools::mutex -> G4Mutex
|
||||
|
||||
class mutex : public virtual tools::wroot::imutex {
|
||||
typedef tools::wroot::imutex parent;
|
||||
using parent = tools::wroot::imutex;
|
||||
public:
|
||||
virtual bool lock() {
|
||||
// G4cout << "!!! Mutex lock" << G4endl;
|
||||
m_mutex.lock();
|
||||
m_mutex.lock();
|
||||
return true;}
|
||||
virtual bool unlock() {
|
||||
m_mutex.unlock();
|
||||
m_mutex.unlock();
|
||||
// G4cout << "!!! Mutex unlock" << G4endl;
|
||||
return true; }
|
||||
//virtual bool trylock() {return m_mutex.trylock();}
|
||||
public:
|
||||
mutex(G4AutoLock& a_mutex):m_mutex(a_mutex){}
|
||||
virtual ~mutex(){}
|
||||
virtual ~mutex() = default;
|
||||
protected:
|
||||
mutex(const mutex& a_from):parent(a_from),m_mutex(a_from.m_mutex){}
|
||||
mutex& operator=(const mutex&){return *this;}
|
||||
@@ -81,11 +82,12 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
friend class G4RootNtupleFileManager;
|
||||
|
||||
public:
|
||||
explicit G4RootPNtupleManager(const G4AnalysisManagerState& state,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManger,
|
||||
std::shared_ptr<G4RootMainNtupleManager> main,
|
||||
G4bool rowWise, G4bool rowMode);
|
||||
~G4RootPNtupleManager();
|
||||
G4RootPNtupleManager(const G4AnalysisManagerState& state,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManger,
|
||||
std::shared_ptr<G4RootMainNtupleManager> main,
|
||||
G4bool rowWise, G4bool rowMode);
|
||||
G4RootPNtupleManager() = delete;
|
||||
virtual ~G4RootPNtupleManager();
|
||||
|
||||
private:
|
||||
// Methods to manipulate ntuples
|
||||
@@ -100,23 +102,23 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
virtual G4int CreateNtuple(G4NtupleBooking* booking) final;
|
||||
|
||||
// Methods to fill ntuples
|
||||
// Methods for ntuple with id = FirstNtupleId (from base class)
|
||||
// Methods for ntuple with id = FirstNtupleId (from base class)
|
||||
using G4BaseNtupleManager::FillNtupleIColumn;
|
||||
using G4BaseNtupleManager::FillNtupleFColumn;
|
||||
using G4BaseNtupleManager::FillNtupleDColumn;
|
||||
using G4BaseNtupleManager::FillNtupleSColumn;
|
||||
using G4BaseNtupleManager::AddNtupleRow;
|
||||
// Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
|
||||
// Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
|
||||
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final;
|
||||
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final;
|
||||
virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final;
|
||||
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
|
||||
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId,
|
||||
const G4String& value) final;
|
||||
virtual G4bool AddNtupleRow(G4int ntupleId) final;
|
||||
virtual G4bool Merge() final;
|
||||
|
||||
// Reset
|
||||
virtual G4bool Reset(G4bool deleteNtuple) final;
|
||||
// Clear all data
|
||||
virtual void Clear() final;
|
||||
|
||||
// Activation option
|
||||
//
|
||||
@@ -131,19 +133,22 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
|
||||
|
||||
private:
|
||||
G4RootPNtupleDescription*
|
||||
GetNtupleDescriptionInFunction(G4int id, G4String function, G4bool warn = true) const;
|
||||
tools::wroot::base_pntuple*
|
||||
GetNtupleInFunction(G4int id, G4String function, G4bool warn = true) const;
|
||||
tools::wroot::ntuple*
|
||||
GetMainNtupleInFunction(G4int id, G4String function, G4bool warn = true) const;
|
||||
G4RootPNtupleDescription*
|
||||
GetNtupleDescriptionInFunction(G4int id, std::string_view function, G4bool warn = true) const;
|
||||
tools::wroot::base_pntuple*
|
||||
GetNtupleInFunction(G4int id, std::string_view function, G4bool warn = true) const;
|
||||
tools::wroot::ntuple*
|
||||
GetMainNtupleInFunction(G4int id, std::string_view function, G4bool warn = true) const;
|
||||
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
|
||||
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4bool FillNtupleTColumn(G4int columnId, const T& value);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootPNtupleManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4NtupleBookingManager> fBookingManager;
|
||||
std::shared_ptr<G4RootMainNtupleManager> fMainNtupleManager;
|
||||
@@ -151,7 +156,7 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
std::vector<tools::wroot::imt_ntuple*> fNtupleVector;
|
||||
G4bool fRowWise;
|
||||
G4bool fRowMode;
|
||||
G4bool fCreateNtuples;
|
||||
G4bool fCreateNtuples { true };
|
||||
};
|
||||
|
||||
#include "G4RootPNtupleManager.icc"
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
|
||||
|
||||
using std::to_string;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
@@ -36,55 +38,48 @@ inline G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
}
|
||||
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "fill", "pntuple T column",
|
||||
" ntupleId " + to_string(ntupleId) + " columnId " + to_string(columnId) +
|
||||
" value " + G4Analysis::ToString(value));
|
||||
}
|
||||
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4RootNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"ntupleId " + to_string(ntupleId) + " columnId " + to_string(columnId) +
|
||||
" does not exist.",
|
||||
fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
auto column = dynamic_cast<tools::wroot::base_pntuple::column_string* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4RootNtupleManager:FillNtupleColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
" Column type does not match: ntupleId " + to_string(ntupleId) +
|
||||
" columnId " + to_string(columnId) + " value " + value,
|
||||
fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("done fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "done fill", "pntuple T column",
|
||||
" ntupleId " + to_string(ntupleId) +
|
||||
" columnId " + to_string(columnId) +
|
||||
" value " + value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -97,18 +92,16 @@ G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
}
|
||||
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "fill", "pntuple T column",
|
||||
" ntupleId " + to_string(ntupleId) +
|
||||
" columnId " + to_string(columnId) +
|
||||
" value " + G4Analysis::ToString(value));
|
||||
}
|
||||
|
||||
// get ntuple
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
@@ -117,11 +110,10 @@ G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
// get generic column
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4TNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
"ntupleId " + to_string(ntupleId) + " columnId " + to_string(columnId) +
|
||||
" does not exist.",
|
||||
fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
@@ -129,30 +121,27 @@ G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
// get column and check its type
|
||||
auto column = dynamic_cast<tools::wroot::base_pntuple::column<T>* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4TNtupleManager:FillNtupleTColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Analysis::Warn(
|
||||
" Column type does not match: ntupleId " + to_string(ntupleId) +
|
||||
" columnId " + to_string(columnId) + " value " + G4Analysis::ToString(value),
|
||||
fkClass, "FillNtupleTColumn");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("done fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
if ( IsVerbose(G4Analysis::kVL4) ) {
|
||||
Message(G4Analysis::kVL4, "done fill", "pntuple T column",
|
||||
" ntupleId " + to_string(ntupleId) +
|
||||
" columnId " + to_string(columnId) +
|
||||
" value " + G4Analysis::ToString(value));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4bool G4RootPNtupleManager::FillNtupleTColumn(G4int columnId, const T& value) {
|
||||
return FillNtupleTColumn(0, columnId, value);
|
||||
}
|
||||
|
||||
@@ -31,35 +31,43 @@
|
||||
#ifndef G4RootRFileManager_h
|
||||
#define G4RootRFileManager_h 1
|
||||
|
||||
#include "G4BaseFileManager.hh"
|
||||
#include "G4VRFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <map>
|
||||
#include <string_view>
|
||||
|
||||
namespace tools {
|
||||
namespace rroot {
|
||||
class file;
|
||||
namespace rroot {
|
||||
class file;
|
||||
//class directory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class G4RootRFileManager : public G4BaseFileManager
|
||||
class G4RootRFileManager : public G4VRFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4RootRFileManager(const G4AnalysisManagerState& state);
|
||||
G4RootRFileManager() = delete;
|
||||
virtual ~G4RootRFileManager();
|
||||
|
||||
virtual G4String GetFileType() const final { return "Root"; }
|
||||
|
||||
// Methods from base class
|
||||
virtual void CloseFiles() final {}
|
||||
|
||||
// Methods to manipulate input files
|
||||
virtual G4bool OpenRFile(const G4String& fileName,
|
||||
G4bool isPerThread);
|
||||
|
||||
|
||||
// Get methods
|
||||
tools::rroot::file* GetRFile(const G4String& fileName,
|
||||
tools::rroot::file* GetRFile(const G4String& fileName,
|
||||
G4bool isPerThread) const;
|
||||
|
||||
private:
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootRFileManager" };
|
||||
|
||||
// data members
|
||||
std::map<G4String, tools::rroot::file*> fRFiles;
|
||||
};
|
||||
|
||||
@@ -37,23 +37,39 @@
|
||||
|
||||
#include "tools/rroot/ntuple"
|
||||
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
class G4RootRFileManager;
|
||||
struct G4RootRNtupleDescription;
|
||||
|
||||
class G4RootRNtupleManager : public G4TRNtupleManager<tools::rroot::ntuple>
|
||||
{
|
||||
friend class G4RootAnalysisReader;
|
||||
|
||||
protected:
|
||||
public:
|
||||
explicit G4RootRNtupleManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4RootRNtupleManager();
|
||||
|
||||
G4RootRNtupleManager() = delete;
|
||||
virtual ~G4RootRNtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Methods from the templated base class
|
||||
//
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4RootRFileManager> fileManager);
|
||||
|
||||
// Methods from the base class
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4bool GetTNtupleRow(G4TRNtupleDescription<tools::rroot::ntuple>* ntupleDescription) final;
|
||||
};
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4RootPNtupleManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4RootRFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
inline void
|
||||
G4RootRNtupleManager::SetFileManager(std::shared_ptr<G4RootRFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -31,25 +31,11 @@
|
||||
|
||||
#include "tools/wroot/ntuple"
|
||||
#include "tools/rroot/ntuple"
|
||||
#include "G4RootAnalysisManager.hh"
|
||||
#include "G4RootAnalysisReader.hh"
|
||||
#include "g4hntools_defs.hh"
|
||||
|
||||
namespace G4Root
|
||||
{
|
||||
// Ntuple types
|
||||
using G4Ntuple = tools::wroot::ntuple;
|
||||
using G4NtupleIterator = std::vector<tools::wroot::ntuple*>::iterator;
|
||||
using G4NtupleConstIterator = std::vector<tools::wroot::ntuple*>::const_iterator;
|
||||
|
||||
// RNtuple types
|
||||
using G4RNtuple = tools::rroot::ntuple;
|
||||
|
||||
// Managers
|
||||
using G4AnalysisManager = G4RootAnalysisManager;
|
||||
using G4AnalysisReader = G4RootAnalysisReader;
|
||||
}
|
||||
// Root output specific types
|
||||
using G4RootNtuple = tools::wroot::ntuple;
|
||||
using G4RootRNtuple = tools::rroot::ntuple;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user