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 Xml analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -38,17 +38,22 @@
|
||||
#include "tools/waxml/ntuple"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4XmlAnalysisManager;
|
||||
class G4XmlFileManager;
|
||||
class G4XmlNtupleFileManager;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4XmlAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4XmlAnalysisManager>;
|
||||
|
||||
public:
|
||||
explicit G4XmlAnalysisManager(G4bool isMaster = true);
|
||||
~G4XmlAnalysisManager();
|
||||
|
||||
// static methods
|
||||
virtual ~G4XmlAnalysisManager();
|
||||
|
||||
// Static methods
|
||||
static G4XmlAnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
@@ -61,37 +66,26 @@ class G4XmlAnalysisManager : public G4ToolsAnalysisManager
|
||||
std::vector<tools::waxml::ntuple*>::iterator EndNtuple();
|
||||
std::vector<tools::waxml::ntuple*>::const_iterator BeginConstNtuple() const;
|
||||
std::vector<tools::waxml::ntuple*>::const_iterator EndConstNtuple() const;
|
||||
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
// Virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) final;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) final;
|
||||
virtual G4bool ResetImpl() final;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
static G4XmlAnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4XmlAnalysisManager* fgInstance;
|
||||
G4XmlAnalysisManager();
|
||||
|
||||
// methods
|
||||
template <typename T>
|
||||
G4bool WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& directoryName,
|
||||
const G4String& hnType);
|
||||
G4bool WriteH1();
|
||||
G4bool WriteH2();
|
||||
G4bool WriteH3();
|
||||
G4bool WriteP1();
|
||||
G4bool WriteP2();
|
||||
G4bool WriteNtuple();
|
||||
G4bool CloseNtupleFiles();
|
||||
G4bool Reset();
|
||||
// Static data members
|
||||
inline static G4XmlAnalysisManager* fgMasterInstance { nullptr };
|
||||
inline static G4ThreadLocal G4bool fgIsInstance { false };
|
||||
static constexpr std::string_view fkClass { "G4XmlAnalysisManager" };
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4XmlFileManager> fFileManager;
|
||||
std::shared_ptr<G4XmlNtupleFileManager> fNtupleFileManager;
|
||||
// Data members
|
||||
std::shared_ptr<G4XmlFileManager> fFileManager { nullptr };
|
||||
std::shared_ptr<G4XmlNtupleFileManager> fNtupleFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4XmlAnalysisManager.icc"
|
||||
|
||||
@@ -28,48 +28,6 @@
|
||||
#include "G4XmlNtupleManager.hh"
|
||||
#include "G4XmlFileManager.hh"
|
||||
|
||||
#include "tools/waxml/histos"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4XmlAnalysisManager::WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& directoryName,
|
||||
const G4String& hnType)
|
||||
{
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
auto name = info->GetName();
|
||||
// skip writing if inactivated
|
||||
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
|
||||
auto ht = htVector[i];
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()->Message("write", hnType, name);
|
||||
#endif
|
||||
G4String path = "/";
|
||||
path.append(directoryName);
|
||||
std::shared_ptr<std::ofstream> hnFile = fFileManager->GetFile();
|
||||
// Do nothing if there is no file
|
||||
if ( ! hnFile.get() ) return false;
|
||||
|
||||
G4bool result
|
||||
= tools::waxml::write(*hnFile, *ht, path, name);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4XmlAnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
fFileManager->LockDirectoryNames();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
G4bool G4XmlAnalysisManager::IsOpenFileImpl() const
|
||||
@@ -82,41 +40,41 @@ inline
|
||||
tools::waxml::ntuple* G4XmlAnalysisManager::GetNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::waxml::ntuple* G4XmlAnalysisManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple(ntupleId);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::waxml::ntuple*>::iterator G4XmlAnalysisManager::BeginNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::waxml::ntuple*>::iterator G4XmlAnalysisManager::EndNtuple()
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::waxml::ntuple*>::const_iterator
|
||||
std::vector<tools::waxml::ntuple*>::const_iterator
|
||||
G4XmlAnalysisManager::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::waxml::ntuple*>::const_iterator
|
||||
std::vector<tools::waxml::ntuple*>::const_iterator
|
||||
G4XmlAnalysisManager::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleFileManager->GetNtupleManager()->EndConstNtuple();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// The main manager for Xml 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, 25/07/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/raxml"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
class G4XmlAnalysisReader;
|
||||
class G4XmlRFileManager;
|
||||
class G4H1ToolsManager;
|
||||
class G4H2ToolsManager;
|
||||
class G4H3ToolsManager;
|
||||
class G4P1ToolsManager;
|
||||
class G4P2ToolsManager;
|
||||
class G4XmlRNtupleManager;
|
||||
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4XmlAnalysisReader : public G4ToolsAnalysisReader
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4XmlAnalysisReader>;
|
||||
|
||||
public:
|
||||
explicit G4XmlAnalysisReader(G4bool isMaster = true);
|
||||
virtual ~G4XmlAnalysisReader();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4XmlAnalysisReader* Instance();
|
||||
|
||||
// Access methods
|
||||
tools::aida::ntuple* GetNtuple() const;
|
||||
tools::aida::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& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadH3Impl(const G4String& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP1Impl(const G4String& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadP2Impl(const G4String& h1Name, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
virtual G4int ReadNtupleImpl(const G4String& ntupleName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
G4XmlAnalysisReader();
|
||||
|
||||
// Virtual methods from base class
|
||||
virtual G4bool CloseFilesImpl(G4bool reset) final;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
static G4XmlAnalysisReader* fgMasterInstance;
|
||||
static G4ThreadLocal G4XmlAnalysisReader* fgInstance;
|
||||
// Static data members
|
||||
inline static G4XmlAnalysisReader* fgMasterInstance { nullptr };
|
||||
|
||||
// methods
|
||||
tools::raxml_out* GetHandler(
|
||||
const G4String& fileName,
|
||||
const G4String& objectName,
|
||||
const G4String& objectType,
|
||||
const G4String& inFunction);
|
||||
// Methods
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4XmlRNtupleManager* fNtupleManager;
|
||||
G4XmlRFileManager* fFileManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4XmlAnalysisReader" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4XmlRNtupleManager> fNtupleManager { nullptr };
|
||||
std::shared_ptr<G4XmlRFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
#include "G4XmlAnalysisReader.icc"
|
||||
|
||||
@@ -26,20 +26,18 @@
|
||||
|
||||
// Author: Ivana Hrivnacova, 25/07/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
//#include "G4XmlRNtupleManager.hh"
|
||||
#include "G4XmlRNtupleManager.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::aida::ntuple* G4XmlAnalysisReader::GetNtuple() const
|
||||
{
|
||||
//return fNtupleManager->GetNtuple();
|
||||
return nullptr;
|
||||
}
|
||||
return fNtupleManager->GetNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::aida::ntuple* G4XmlAnalysisReader::GetNtuple(G4int /*ntupleId*/) const
|
||||
tools::aida::ntuple* G4XmlAnalysisReader::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
//return fNtupleManager->GetNtuple(ntupleId);
|
||||
return nullptr;
|
||||
}
|
||||
return fNtupleManager->GetNtuple(ntupleId);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
// Type aliases
|
||||
using XmlNtupleDescription = G4TNtupleDescription<tools::waxml::ntuple, std::ofstream>;
|
||||
@@ -50,7 +51,8 @@ class G4XmlFileManager : public G4VTFileManager<std::ofstream>
|
||||
{
|
||||
public:
|
||||
explicit G4XmlFileManager(const G4AnalysisManagerState& state);
|
||||
~G4XmlFileManager();
|
||||
G4XmlFileManager() = delete;
|
||||
virtual ~G4XmlFileManager() = default;
|
||||
|
||||
using G4BaseFileManager::GetNtupleFileName;
|
||||
using G4VTFileManager<std::ofstream>::WriteFile;
|
||||
@@ -63,17 +65,20 @@ class G4XmlFileManager : public G4VTFileManager<std::ofstream>
|
||||
|
||||
// Specific methods for files per objects
|
||||
G4bool CreateNtupleFile(XmlNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(XmlNtupleDescription* ntupleDescription);
|
||||
|
||||
G4bool CloseNtupleFile(XmlNtupleDescription* ntupleDescription);
|
||||
|
||||
protected:
|
||||
// Methods derived from templated base class
|
||||
virtual std::shared_ptr<std::ofstream> CreateFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<std::ofstream> file) final;
|
||||
|
||||
private:
|
||||
// utility method
|
||||
// Utility method
|
||||
G4String GetNtupleFileName(XmlNtupleDescription* ntupleDescription);
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4XmlFileManager" };
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include "G4VTHnFileManager.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4XmlFileManager;
|
||||
|
||||
template <typename HT>
|
||||
@@ -41,7 +43,8 @@ class G4XmlHnFileManager : public G4VTHnFileManager<HT>
|
||||
public:
|
||||
G4XmlHnFileManager(G4XmlFileManager* fileManger)
|
||||
: G4VTHnFileManager<HT>(), fFileManager(fileManger) {}
|
||||
virtual ~G4XmlHnFileManager() {}
|
||||
G4XmlHnFileManager() = delete;
|
||||
virtual ~G4XmlHnFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
// Write to a new file (the file is closed after write)
|
||||
@@ -49,9 +52,11 @@ class G4XmlHnFileManager : 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:
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4XmlHnFileManager" };
|
||||
// Data members
|
||||
G4XmlFileManager* fFileManager;
|
||||
G4XmlFileManager* fFileManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/waxml/histos"
|
||||
#include "tools/waxml/begend"
|
||||
|
||||
@@ -63,7 +65,7 @@ G4bool G4XmlHnFileManager<HT>::WriteExtra(
|
||||
template <typename HT>
|
||||
G4bool G4XmlHnFileManager<HT>::Write(
|
||||
HT* ht, const G4String& htName, G4String& fileName)
|
||||
{
|
||||
{
|
||||
if ( fileName.empty()) {
|
||||
// should not happen
|
||||
G4cerr << "!!! Xml file name not defined." << G4endl;
|
||||
@@ -73,13 +75,9 @@ G4bool G4XmlHnFileManager<HT>::Write(
|
||||
|
||||
auto hnFile = fFileManager->GetTFile(fileName);
|
||||
if ( hnFile == nullptr ) {
|
||||
// TO DO: give an exception,
|
||||
// this prototype can be used only with OpenFile() mode
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Failed to get Xml file " << fileName;
|
||||
G4Exception("G4XmlHnFileManager<HT>::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
// This prototype can be used only with OpenFile() mode
|
||||
G4Analysis::Warn(
|
||||
G4String("Failed to get Xml file ") + fileName, fkClass, "Write");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// The manager class for histogram/profile reading from a Xml file.
|
||||
|
||||
// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4XmlHnRFileManager_h
|
||||
#define G4XmlHnRFileManager_h 1
|
||||
|
||||
#include "G4VTHnRFileManager.hh"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class G4XmlRFileManager;
|
||||
|
||||
template <typename HT>
|
||||
class G4XmlHnRFileManager : public G4VTHnRFileManager<HT>
|
||||
{
|
||||
public:
|
||||
G4XmlHnRFileManager(G4XmlRFileManager* rfileManger)
|
||||
: G4VTHnRFileManager<HT>(), fRFileManager(rfileManger) {}
|
||||
G4XmlHnRFileManager() = delete;
|
||||
virtual ~G4XmlHnRFileManager() = default;
|
||||
|
||||
// Methods for writing objects
|
||||
virtual HT* Read(const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName, G4bool isUserFileName) final;
|
||||
|
||||
private:
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4XmlHnRFileManager<HT>" };
|
||||
// Data members
|
||||
G4XmlRFileManager* fRFileManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4XmlHnRFileManager.icc"
|
||||
|
||||
#endif
|
||||
+14
-10
@@ -23,16 +23,20 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 26/08/2021 (ivana@ipno.in2p3.fr)
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
|
||||
#include "tools/raxml"
|
||||
|
||||
#ifndef g4xml_h
|
||||
#define g4xml_h
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
HT* G4XmlHnRFileManager<HT>::Read(
|
||||
const G4String& htName, const G4String& fileName, const G4String& /*dirName*/,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
auto handler = fRFileManager->GetHandler<HT>(fileName, htName, "Read");
|
||||
if ( ! handler ) return nullptr;
|
||||
|
||||
#include "g4xml_defs.hh"
|
||||
|
||||
using namespace G4Xml;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
return static_cast<HT*>(handler->object());
|
||||
}
|
||||
@@ -45,27 +45,31 @@ class G4XmlNtupleFileManager : public G4VNtupleFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4XmlNtupleFileManager(const G4AnalysisManagerState& state);
|
||||
~G4XmlNtupleFileManager();
|
||||
|
||||
G4XmlNtupleFileManager() = delete;
|
||||
virtual ~G4XmlNtupleFileManager() = default;
|
||||
|
||||
virtual std::shared_ptr<G4VNtupleManager> CreateNtupleManager() override;
|
||||
|
||||
// Methods to be performed at file management
|
||||
virtual G4bool ActionAtOpenFile(const G4String& fileName) override;
|
||||
virtual G4bool ActionAtWrite() override;
|
||||
virtual G4bool ActionAtCloseFile(G4bool reset) override;
|
||||
virtual G4bool Reset() override;
|
||||
virtual G4bool Reset() override;
|
||||
|
||||
void SetFileManager(std::shared_ptr<G4XmlFileManager> fileManager);
|
||||
|
||||
std::shared_ptr<G4XmlNtupleManager> GetNtupleManager() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
// Methods
|
||||
G4bool CloseNtupleFiles();
|
||||
|
||||
// data members
|
||||
std::shared_ptr<G4XmlFileManager> fFileManager;
|
||||
std::shared_ptr<G4XmlNtupleManager> fNtupleManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4XmlNtupleFileManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4XmlFileManager> fFileManager { nullptr };
|
||||
std::shared_ptr<G4XmlNtupleManager> fNtupleManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Manager class for Xml ntuples
|
||||
// Manager class for Xml ntuples
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
// Types alias
|
||||
using XmlNtupleDescription = G4TNtupleDescription<tools::waxml::ntuple, std::ofstream>;
|
||||
@@ -45,14 +46,15 @@ using XmlNtupleDescription = G4TNtupleDescription<tools::waxml::ntuple, std::ofs
|
||||
class G4XmlFileManager;
|
||||
|
||||
class G4XmlNtupleManager : public G4TNtupleManager<tools::waxml::ntuple,
|
||||
std::ofstream>
|
||||
std::ofstream>
|
||||
{
|
||||
friend class G4XmlAnalysisManager;
|
||||
friend class G4XmlNtupleFileManager;
|
||||
|
||||
public:
|
||||
explicit G4XmlNtupleManager(const G4AnalysisManagerState& state);
|
||||
~G4XmlNtupleManager();
|
||||
G4XmlNtupleManager() = delete;
|
||||
virtual ~G4XmlNtupleManager() = default;
|
||||
|
||||
private:
|
||||
// Functions specific to the output type
|
||||
@@ -60,7 +62,7 @@ class G4XmlNtupleManager : public G4TNtupleManager<tools::waxml::ntuple,
|
||||
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4XmlFileManager> fileManager);
|
||||
|
||||
|
||||
// Access to ntuple vector (needed for Write())
|
||||
const std::vector<XmlNtupleDescription*>& GetNtupleDescriptionVector() const;
|
||||
|
||||
@@ -73,18 +75,20 @@ class G4XmlNtupleManager : public G4TNtupleManager<tools::waxml::ntuple,
|
||||
XmlNtupleDescription* ntupleDescription,
|
||||
G4bool fromBooking) final;
|
||||
|
||||
// data members
|
||||
//
|
||||
std::shared_ptr<G4XmlFileManager> fFileManager;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4XmNtupleManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4XmlFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void
|
||||
inline void
|
||||
G4XmlNtupleManager::SetFileManager(std::shared_ptr<G4XmlFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline const std::vector<G4TNtupleDescription<tools::waxml::ntuple, std::ofstream>*>&
|
||||
inline const std::vector<G4TNtupleDescription<tools::waxml::ntuple, std::ofstream>*>&
|
||||
G4XmlNtupleManager::GetNtupleDescriptionVector() const
|
||||
{ return fNtupleDescriptionVector; }
|
||||
|
||||
|
||||
@@ -31,33 +31,48 @@
|
||||
#ifndef G4XmlRFileManager_h
|
||||
#define G4XmlRFileManager_h 1
|
||||
|
||||
#include "G4BaseFileManager.hh"
|
||||
#include "G4VRFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <tools/raxml>
|
||||
#include "tools/raxml"
|
||||
|
||||
#include <fstream>
|
||||
#include <string_view>
|
||||
|
||||
class G4AnalysisManagerState;
|
||||
|
||||
class G4XmlRFileManager : public G4BaseFileManager
|
||||
class G4XmlRFileManager : public G4VRFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4XmlRFileManager(const G4AnalysisManagerState& state);
|
||||
~G4XmlRFileManager();
|
||||
G4XmlRFileManager() = delete;
|
||||
virtual ~G4XmlRFileManager();
|
||||
|
||||
virtual G4String GetFileType() const final { return "xml"; }
|
||||
|
||||
// Methods from base class
|
||||
virtual void CloseFiles() final {}
|
||||
|
||||
// Methods to manipulate input files
|
||||
virtual G4bool OpenRFile(const G4String& fileName);
|
||||
|
||||
// Specific methods for files per objects
|
||||
tools::raxml* GetRFile(const G4String& fileName) const;
|
||||
|
||||
|
||||
// Helper method
|
||||
template <typename HT>
|
||||
tools::raxml_out* GetHandler(const G4String& fileName,
|
||||
const G4String& objectName,
|
||||
std::string_view inFunction);
|
||||
|
||||
private:
|
||||
// data members
|
||||
tools::xml::default_factory* fReadFactory;
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4XmRFileManager" };
|
||||
|
||||
// Data members
|
||||
tools::xml::default_factory* fReadFactory { nullptr };
|
||||
std::map<G4String, tools::raxml*> fRFiles;
|
||||
};
|
||||
|
||||
#include "G4XmlRFileManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
inline
|
||||
tools::raxml_out* G4XmlRFileManager::GetHandler(
|
||||
const G4String& fileName, const G4String& objectName,
|
||||
std::string_view inFunction)
|
||||
{
|
||||
// Get buffer for reading object specified by objectName and objectType
|
||||
// for a file specified by fileName;
|
||||
// open the file if it was not yet open
|
||||
|
||||
// Histograms and profiles are not saved per thread
|
||||
// and ntuple file name is already updated
|
||||
auto rfile = GetRFile(fileName);
|
||||
if ( ! rfile ) {
|
||||
if ( ! OpenRFile(fileName) ) return nullptr;
|
||||
rfile = GetRFile(fileName);
|
||||
}
|
||||
|
||||
tools::raxml_out* handler = nullptr;
|
||||
if ( rfile ) {
|
||||
std::vector<tools::raxml_out>& objects = rfile->objects();
|
||||
std::vector<tools::raxml_out>::iterator it;
|
||||
for (it = objects.begin(); it!=objects.end(); ++it) {
|
||||
tools::raxml_out& object = *it;
|
||||
if ( (object.cls().compare(HT::s_class()) == 0) &&
|
||||
(object.name().compare(objectName) == 0) ) {
|
||||
handler = &object;
|
||||
handler->disown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! handler ) {
|
||||
G4Analysis::Warn(
|
||||
"Cannot get " + objectName + " in file " + fileName,
|
||||
fkClass, inFunction);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return handler;
|
||||
}
|
||||
@@ -38,40 +38,60 @@
|
||||
#include "tools/raxml"
|
||||
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
class G4XmlRFileManager;
|
||||
struct G4XmlRNtupleDescription;
|
||||
|
||||
class G4XmlRNtupleManager : public G4TRNtupleManager<tools::aida::ntuple>
|
||||
{
|
||||
friend class G4XmlAnalysisReader;
|
||||
|
||||
protected:
|
||||
G4XmlRNtupleManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4XmlRNtupleManager();
|
||||
public:
|
||||
explicit G4XmlRNtupleManager(const G4AnalysisManagerState& state);
|
||||
G4XmlRNtupleManager() = delete;
|
||||
virtual ~G4XmlRNtupleManager() = default;
|
||||
|
||||
// Methods from base classes
|
||||
using G4BaseRNtupleManager::SetNtupleIColumn;
|
||||
using G4BaseRNtupleManager::SetNtupleFColumn;
|
||||
using G4BaseRNtupleManager::SetNtupleDColumn;
|
||||
using G4TRNtupleManager<tools::aida::ntuple>::SetNtupleIColumn;
|
||||
using G4TRNtupleManager<tools::aida::ntuple>::SetNtupleFColumn;
|
||||
using G4TRNtupleManager<tools::aida::ntuple>::SetNtupleDColumn;
|
||||
protected:
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4XmlRFileManager> fileManager);
|
||||
|
||||
// Methods from base classes
|
||||
using G4BaseRNtupleManager::SetNtupleIColumn;
|
||||
using G4BaseRNtupleManager::SetNtupleFColumn;
|
||||
using G4BaseRNtupleManager::SetNtupleDColumn;
|
||||
using G4TRNtupleManager<tools::aida::ntuple>::SetNtupleIColumn;
|
||||
using G4TRNtupleManager<tools::aida::ntuple>::SetNtupleFColumn;
|
||||
using G4TRNtupleManager<tools::aida::ntuple>::SetNtupleDColumn;
|
||||
using G4TRNtupleManager<tools::aida::ntuple>::SetNtupleSColumn;
|
||||
|
||||
// Override base class functions for vector columns
|
||||
// in order to fill the maps
|
||||
|
||||
virtual G4bool SetNtupleIColumn(G4int ntupleId, const G4String& columnName,
|
||||
|
||||
virtual G4bool SetNtupleIColumn(G4int ntupleId, const G4String& columnName,
|
||||
std::vector<G4int>& vector) final;
|
||||
virtual G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName,
|
||||
virtual G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName,
|
||||
std::vector<G4float>& vector) final;
|
||||
virtual G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
|
||||
virtual G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
|
||||
std::vector<G4double>& vector) final;
|
||||
virtual G4bool SetNtupleSColumn(G4int ntupleId, const G4String& columnName,
|
||||
std::vector<std::string>& vector) final;
|
||||
|
||||
private:
|
||||
// Methods from the templated base class
|
||||
//
|
||||
// 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::aida::ntuple>* ntupleDescription) final;
|
||||
};
|
||||
|
||||
// Static data members
|
||||
static constexpr std::string_view fkClass { "G4XmlRNtupleManager" };
|
||||
|
||||
// Data members
|
||||
std::shared_ptr<G4XmlRFileManager> fFileManager { nullptr };
|
||||
};
|
||||
|
||||
inline void
|
||||
G4XmlRNtupleManager::SetFileManager(std::shared_ptr<G4XmlRFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,25 +30,12 @@
|
||||
#define g4xml_defs_h
|
||||
|
||||
#include "tools/waxml/ntuple"
|
||||
#include "G4XmlAnalysisManager.hh"
|
||||
#include "G4XmlAnalysisReader.hh"
|
||||
#include "g4hntools_defs.hh"
|
||||
|
||||
namespace G4Xml
|
||||
{
|
||||
// Ntuple types
|
||||
using G4Ntuple = tools::waxml::ntuple;
|
||||
using G4NtupleIterator = std::vector<tools::waxml::ntuple*>::iterator;
|
||||
using G4NtupleConstIterator = std::vector<tools::waxml::ntuple*>::const_iterator;
|
||||
|
||||
// RNtuple types
|
||||
using G4RNtuple = tools::aida::ntuple;
|
||||
|
||||
// Managers
|
||||
using G4AnalysisManager = G4XmlAnalysisManager;
|
||||
using G4AnalysisReader = G4XmlAnalysisReader;
|
||||
}
|
||||
// Xml output specific types
|
||||
using G4XmlNtuple = tools::waxml::ntuple;
|
||||
using G4XmlRNtuple = tools::aida::ntuple;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user