Import Geant4 10.4.0 source tree
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# CMakeLists.txt
|
||||
# Module : G4analysis
|
||||
# Package: Geant4.src.G4analysis.G4xml
|
||||
#
|
||||
# CMakeLists.txt for building a single granular library.
|
||||
#
|
||||
# Created on : 27/07/2017
|
||||
#
|
||||
# $Id: CMakeLists.txt 105747 2017-08-16 13:16:13Z gcosmo $
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
if(GEANT4_BUILD_GRANULAR_LIBS)
|
||||
include(Geant4MacroLibraryTargets)
|
||||
GEANT4_GRANULAR_LIBRARY_TARGET(COMPONENT sources.cmake)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# $Id$
|
||||
# --------------------------------------------------------------------
|
||||
# GNUmakefile for analysis/hdf5 library.
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
name := G4hdf5
|
||||
|
||||
ifndef G4INSTALL
|
||||
G4INSTALL = ../../..
|
||||
endif
|
||||
|
||||
include $(G4INSTALL)/config/architecture.gmk
|
||||
|
||||
ifeq ($(G4SYSTEM), WIN32-VC)
|
||||
CPPFLAGS += -I$(G4BASE)/externals/expat/include
|
||||
endif
|
||||
ifdef G4LIB_BUILD_EXPAT
|
||||
CPPFLAGS += -I$(G4BASE)/externals/expat/include
|
||||
endif
|
||||
|
||||
CPPFLAGS += -I$(G4BASE)/global/management/include \
|
||||
-I$(G4BASE)/intercoms/include \
|
||||
-I$(G4BASE)/analysis/g4tools/include \
|
||||
-I$(G4BASE)/analysis/management/include \
|
||||
-I$(G4BASE)/analysis/hntools/include
|
||||
|
||||
include $(G4INSTALL)/config/common.gmk
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// The main manager for Hdf5 analysis.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4Hdf5AnalysisManager_h
|
||||
#define G4Hdf5AnalysisManager_h 1
|
||||
|
||||
#include "G4ToolsAnalysisManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class G4Hdf5FileManager;
|
||||
class G4Hdf5NtupleManager;
|
||||
|
||||
class G4Hdf5AnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
public:
|
||||
explicit G4Hdf5AnalysisManager(G4bool isMaster = true);
|
||||
~G4Hdf5AnalysisManager();
|
||||
|
||||
// static methods
|
||||
static G4Hdf5AnalysisManager* Instance();
|
||||
static G4bool IsInstance();
|
||||
|
||||
// Access methods
|
||||
tools::hdf5::ntuple* GetNtuple() const;
|
||||
tools::hdf5::ntuple* GetNtuple(G4int ntupleId) const;
|
||||
|
||||
// Iterators
|
||||
std::vector<tools::hdf5::ntuple*>::iterator BeginNtuple();
|
||||
std::vector<tools::hdf5::ntuple*>::iterator EndNtuple();
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator BeginConstNtuple() const;
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator EndConstNtuple() const;
|
||||
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool CloseFileImpl() final;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
|
||||
private:
|
||||
// constants
|
||||
static constexpr unsigned int fgkDefaultBasketSize = 32000;
|
||||
|
||||
// static data members
|
||||
static G4Hdf5AnalysisManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4Hdf5AnalysisManager* fgInstance;
|
||||
|
||||
// methods
|
||||
template <typename T>
|
||||
G4bool WriteHn(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& directoryName,
|
||||
const G4String& hnType);
|
||||
template <typename T>
|
||||
G4bool WritePn(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
const G4String& directoryName,
|
||||
const G4String& hnType);
|
||||
G4bool WriteDirectory();
|
||||
G4bool WriteH1();
|
||||
G4bool WriteH2();
|
||||
G4bool WriteH3();
|
||||
G4bool WriteP1();
|
||||
G4bool WriteP2();
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4Hdf5NtupleManager* fNtupleManager;
|
||||
std::shared_ptr<G4Hdf5FileManager> fFileManager;
|
||||
};
|
||||
|
||||
#include "G4Hdf5AnalysisManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5NtupleManager.hh"
|
||||
#include "G4Hdf5FileManager.hh"
|
||||
|
||||
#include "tools/hdf5/h2file"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4Hdf5AnalysisManager::WriteHn(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
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
// Do nothing if there is no directory
|
||||
if ( directory < 0 ) return false;
|
||||
|
||||
G4bool result
|
||||
= tools::hdf5::write_histo(G4cout, directory, name, *ht);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4Hdf5AnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
fFileManager->LockHistoDirectoryName();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
inline
|
||||
G4bool G4Hdf5AnalysisManager::WritePn(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
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
// Do nothing if there is no directory
|
||||
if ( directory < 0 ) return false;
|
||||
|
||||
G4bool result
|
||||
= tools::hdf5::write_profile(G4cout, directory, name, *ht);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "saving " << hnType << " " << name << " failed";
|
||||
G4Exception("G4Hdf5AnalysisManager::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
fFileManager->LockHistoDirectoryName();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
G4bool G4Hdf5AnalysisManager::IsOpenFileImpl() const
|
||||
{
|
||||
return fFileManager->IsOpenFile();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::hdf5::ntuple* G4Hdf5AnalysisManager::GetNtuple() const
|
||||
{
|
||||
return fNtupleManager->GetNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::hdf5::ntuple* G4Hdf5AnalysisManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleManager->GetNtuple(ntupleId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::hdf5::ntuple*>::iterator G4Hdf5AnalysisManager::BeginNtuple()
|
||||
{
|
||||
return fNtupleManager->BeginNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::hdf5::ntuple*>::iterator G4Hdf5AnalysisManager::EndNtuple()
|
||||
{
|
||||
return fNtupleManager->EndNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator
|
||||
G4Hdf5AnalysisManager::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleManager->BeginConstNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::hdf5::ntuple*>::const_iterator
|
||||
G4Hdf5AnalysisManager::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleManager->EndConstNtuple();
|
||||
}
|
||||
@@ -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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// The main manager for Hdf5 analysis reader.
|
||||
// It delegates most of functions to the object specific managers.
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4Hdf5AnalysisReader_h
|
||||
#define G4Hdf5AnalysisReader_h 1
|
||||
|
||||
#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/hdf5/ntuple"
|
||||
|
||||
class G4Hdf5RFileManager;
|
||||
class G4H1ToolsManager;
|
||||
class G4H2ToolsManager;
|
||||
class G4H3ToolsManager;
|
||||
class G4P1ToolsManager;
|
||||
class G4P2ToolsManager;
|
||||
class G4Hdf5RNtupleManager;
|
||||
|
||||
class G4Hdf5AnalysisReader : public G4ToolsAnalysisReader
|
||||
{
|
||||
public:
|
||||
explicit G4Hdf5AnalysisReader(G4bool isMaster = true);
|
||||
virtual ~G4Hdf5AnalysisReader();
|
||||
|
||||
// static methods
|
||||
static G4Hdf5AnalysisReader* Instance();
|
||||
|
||||
// Access methods
|
||||
tools::hdf5::ntuple* GetNtuple() const;
|
||||
tools::hdf5::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 G4Hdf5AnalysisReader* fgMasterInstance;
|
||||
static G4ThreadLocal G4Hdf5AnalysisReader* fgInstance;
|
||||
|
||||
// methods
|
||||
//
|
||||
template <typename T>
|
||||
T* ReadHnImpl(const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName);
|
||||
template <typename T>
|
||||
T* ReadPnImpl(const G4String& ptName, const G4String& fileName,
|
||||
const G4String& dirName);
|
||||
G4bool Reset();
|
||||
|
||||
// data members
|
||||
G4Hdf5RNtupleManager* fNtupleManager;
|
||||
G4Hdf5RFileManager* fFileManager;
|
||||
};
|
||||
|
||||
#include "G4Hdf5AnalysisReader.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#include "G4Hdf5RFileManager.hh"
|
||||
|
||||
#include <tools/hdf5/h2file>
|
||||
|
||||
// //_____________________________________________________________________________
|
||||
// inline
|
||||
// tools::hdf5::ntuple* G4Hdf5AnalysisReader::GetNtuple() const
|
||||
// {
|
||||
// return fNtupleManager->GetNtuple();
|
||||
// }
|
||||
|
||||
// //_____________________________________________________________________________
|
||||
// inline
|
||||
// tools::hdf5::ntuple* G4Hdf5AnalysisReader::GetNtuple(G4int ntupleId) const
|
||||
// {
|
||||
// return fNtupleManager->GetNtuple(ntupleId);
|
||||
// }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
T* G4Hdf5AnalysisReader::ReadHnImpl(
|
||||
const G4String& htName, const G4String& fileName,
|
||||
const G4String& dirName)
|
||||
{
|
||||
// Get directory
|
||||
auto directory = fFileManager->GetHistoRDirectory(fileName, dirName, false);
|
||||
if ( directory < 0 ) return nullptr;
|
||||
|
||||
// Read hn
|
||||
T* ht;
|
||||
auto result = tools::hdf5::read_histo(G4cout, directory, htName, ht);
|
||||
if ( ! result ) return nullptr;
|
||||
|
||||
if ( ! ht ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Streaming " << htName << " from file " << fileName << " failed.";
|
||||
G4Exception("G4Hdf5AnalysisReader::ReadHnImpl",
|
||||
"Analysis_WR011", JustWarning, description);
|
||||
|
||||
// when failure, directory and file should be closed
|
||||
// ::H5Gclose(histos);
|
||||
// ::H5Fclose(file);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ht;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
T* G4Hdf5AnalysisReader::ReadPnImpl(
|
||||
const G4String& ptName, const G4String& fileName,
|
||||
const G4String& dirName)
|
||||
{
|
||||
// Get directory
|
||||
auto directory = fFileManager->GetHistoRDirectory(fileName, dirName, false);
|
||||
if ( directory < 0 ) return nullptr;
|
||||
|
||||
// Read hn
|
||||
T* pt;
|
||||
auto result = tools::hdf5::read_profile(G4cout, directory, ptName, pt);
|
||||
if ( ! result ) return nullptr;
|
||||
|
||||
if ( ! pt ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Streaming " << ptName << " from file " << fileName << " failed.";
|
||||
G4Exception("G4Hdf5AnalysisReader::ReadPnImpl",
|
||||
"Analysis_WR011", JustWarning, description);
|
||||
|
||||
// when failure, directory and file should be closed
|
||||
// ::H5Gclose(histos);
|
||||
// ::H5Fclose(file);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return pt;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// The manager for Hdf5 file output operations.
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4Hdf5FileManager_h
|
||||
#define G4Hdf5FileManager_h 1
|
||||
|
||||
#include "G4VFileManager.hh"
|
||||
#include "G4TNtupleDescription.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
class G4AnalysisManagerState;
|
||||
|
||||
class G4Hdf5FileManager : public G4VFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4Hdf5FileManager(const G4AnalysisManagerState& state);
|
||||
~G4Hdf5FileManager();
|
||||
|
||||
// Type aliases
|
||||
using NtupleType = tools::hdf5::ntuple;
|
||||
using NtupleDescriptionType = G4TNtupleDescription<NtupleType>;
|
||||
|
||||
// Methods to manipulate output files
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
virtual G4bool WriteFile() final;
|
||||
virtual G4bool CloseFile() final;
|
||||
|
||||
G4bool WriteHistoDirectory();
|
||||
G4bool WriteNtupleDirectory();
|
||||
void CloseAfterHnWrite();
|
||||
|
||||
// Set methods
|
||||
void SetBasketSize(unsigned int basketSize);
|
||||
|
||||
// Get methods
|
||||
hid_t GetFile() const;
|
||||
hid_t GetHistoDirectory() const;
|
||||
hid_t GetNtupleDirectory() const;
|
||||
unsigned int GetBasketSize() const;
|
||||
|
||||
private:
|
||||
G4bool CreateDirectory(const G4String& directoryType,
|
||||
const G4String& directoryName, hid_t& directory);
|
||||
G4bool WriteDirectory(const G4String& directoryType,
|
||||
const G4String& directoryName, hid_t& directory);
|
||||
|
||||
// constants
|
||||
static const G4String fgkDefaultDirectoryName;
|
||||
|
||||
// data members
|
||||
hid_t fFile;
|
||||
hid_t fHistoDirectory;
|
||||
hid_t fNtupleDirectory;
|
||||
unsigned int fBasketSize;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void G4Hdf5FileManager::SetBasketSize(unsigned int basketSize)
|
||||
{ fBasketSize = basketSize; }
|
||||
|
||||
inline hid_t G4Hdf5FileManager::GetFile() const
|
||||
{ return fFile; }
|
||||
|
||||
inline hid_t G4Hdf5FileManager::GetHistoDirectory() const
|
||||
{ return fHistoDirectory; }
|
||||
|
||||
inline hid_t G4Hdf5FileManager::GetNtupleDirectory() const
|
||||
{ return fNtupleDirectory; }
|
||||
|
||||
inline unsigned int G4Hdf5FileManager::GetBasketSize() const
|
||||
{ return fBasketSize; }
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Manager class for Hdf5 ntuples
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4Hdf5NtupleManager_h
|
||||
#define G4Hdf5NtupleManager_h 1
|
||||
|
||||
#include "G4TNtupleManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
class G4Hdf5FileManager;
|
||||
|
||||
// template specialization used by this class defined below
|
||||
|
||||
template <>
|
||||
template <>
|
||||
G4bool G4TNtupleManager<tools::hdf5::ntuple>::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const std::string& value);
|
||||
|
||||
|
||||
class G4Hdf5NtupleManager : public G4TNtupleManager<tools::hdf5::ntuple>
|
||||
{
|
||||
friend class G4Hdf5AnalysisManager;
|
||||
|
||||
public:
|
||||
explicit G4Hdf5NtupleManager(const G4AnalysisManagerState& state);
|
||||
~G4Hdf5NtupleManager();
|
||||
|
||||
private:
|
||||
// Types alias
|
||||
using NtupleType = tools::hdf5::ntuple;
|
||||
using NtupleDescriptionType = G4TNtupleDescription<NtupleType>;
|
||||
|
||||
// Set methods
|
||||
void SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager);
|
||||
|
||||
// Access to ntuple vector (needed for Write())
|
||||
const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector() const;
|
||||
|
||||
// Methods from the templated base class
|
||||
//
|
||||
virtual void CreateTNtuple(
|
||||
NtupleDescriptionType* ntupleDescription,
|
||||
const G4String& name, const G4String& title) final;
|
||||
virtual void CreateTNtupleFromBooking(
|
||||
NtupleDescriptionType* ntupleDescription) final;
|
||||
|
||||
virtual void FinishTNtuple(
|
||||
NtupleDescriptionType* ntupleDescription) final;
|
||||
|
||||
// data members
|
||||
//
|
||||
std::shared_ptr<G4Hdf5FileManager> fFileManager;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void
|
||||
G4Hdf5NtupleManager::SetFileManager(std::shared_ptr<G4Hdf5FileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline const std::vector<G4TNtupleDescription<tools::hdf5::ntuple>*>&
|
||||
G4Hdf5NtupleManager::GetNtupleDescriptionVector() const
|
||||
{ return fNtupleDescriptionVector; }
|
||||
|
||||
template <>
|
||||
template <>
|
||||
inline G4bool G4TNtupleManager<tools::hdf5::ntuple>::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const std::string& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
//G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// get ntuple
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
// 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);
|
||||
return false;
|
||||
}
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
|
||||
// get column and check its type
|
||||
auto column = dynamic_cast<tools::hdf5::ntuple::column_string* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4TNtupleManager:FillNtupleTColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
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;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// The manager for Hdf5 file input operations.
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4Hdf5RFileManager_h
|
||||
#define G4Hdf5RFileManager_h 1
|
||||
|
||||
#include "G4BaseFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
#include <map>
|
||||
|
||||
class G4Hdf5RFileManager : public G4BaseFileManager
|
||||
{
|
||||
public:
|
||||
explicit G4Hdf5RFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4Hdf5RFileManager();
|
||||
|
||||
// Get methods
|
||||
hid_t GetRFile(const G4String& fileName, G4bool isPerThread) const;
|
||||
hid_t GetHistoRDirectory(const G4String& fileName, const G4String& dirName,
|
||||
G4bool isPerThread);
|
||||
hid_t GetNtupleRDirectory(const G4String& fileName, const G4String& dirName,
|
||||
G4bool isPerThread);
|
||||
|
||||
private:
|
||||
// constants
|
||||
static const G4String fgkDefaultDirectoryName;
|
||||
|
||||
// methods
|
||||
hid_t OpenRFile(const G4String& fileName, G4bool isPerThread);
|
||||
hid_t OpenDirectory(hid_t file, const G4String& directoryName);
|
||||
hid_t GetRDirectory(const G4String& directoryType,
|
||||
const G4String& fileName, const G4String& dirName,
|
||||
G4bool isPerThread);
|
||||
|
||||
// data members
|
||||
std::map<G4String, hid_t> fRFiles;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Manager class for Hdf5 read ntuples.
|
||||
// It implements functions specific to Hdf5 read ntuples.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4Hdf5RNtupleManager_h
|
||||
#define G4Hdf5RNtupleManager_h 1
|
||||
|
||||
#include "G4TRNtupleManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/hdf5/ntuple"
|
||||
|
||||
class G4Hdf5RNtupleManager : public G4TRNtupleManager<tools::hdf5::ntuple>
|
||||
{
|
||||
friend class G4Hdf5AnalysisReader;
|
||||
|
||||
protected:
|
||||
explicit G4Hdf5RNtupleManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4Hdf5RNtupleManager();
|
||||
|
||||
private:
|
||||
// Methods from the templated base class
|
||||
//
|
||||
virtual G4bool GetTNtupleRow(G4TRNtupleDescription<tools::hdf5::ntuple>* ntupleDescription) final;
|
||||
};
|
||||
|
||||
// // inline functions
|
||||
|
||||
// inline G4int G4Hdf5RNtupleManager::GetNofNtuples() const
|
||||
// { return fNtupleVector.size(); }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef g4hdf5_h
|
||||
#define g4hdf5_h
|
||||
|
||||
#include "g4hdf5_defs.hh"
|
||||
|
||||
using namespace G4Hdf5;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef g4hdf5_defs_h
|
||||
#define g4hdf5_defs_h
|
||||
|
||||
#include "tools/histo/h1d"
|
||||
#include "tools/histo/h2d"
|
||||
#include "tools/histo/h3d"
|
||||
#include "tools/histo/p1d"
|
||||
#include "tools/histo/p2d"
|
||||
#include "tools/hdf5/ntuple"
|
||||
#include "G4Hdf5AnalysisManager.hh"
|
||||
#include "G4Hdf5AnalysisReader.hh"
|
||||
|
||||
namespace G4Hdf5 {
|
||||
|
||||
// H1 types
|
||||
using G4AnaH1 = tools::histo::h1d; // keep for backward compatibility
|
||||
using G4H1 = tools::histo::h1d;
|
||||
using G4H1Iterator = std::vector<tools::histo::h1d*>::iterator;
|
||||
using G4H1ConstIterator = std::vector<tools::histo::h1d*>::const_iterator;
|
||||
|
||||
// H2 types
|
||||
using G4AnaH2 = tools::histo::h2d; // keep for backward compatibility
|
||||
using G4H2 = tools::histo::h2d;
|
||||
using G4H2Iterator = std::vector<tools::histo::h2d*>::iterator;
|
||||
using G4H2ConstIterator = std::vector<tools::histo::h2d*>::const_iterator;
|
||||
|
||||
// H3 types
|
||||
using G4H3 = tools::histo::h3d;
|
||||
using G4H3Iterator = std::vector<tools::histo::h3d*>::iterator;
|
||||
using G4H3ConstIterator = std::vector<tools::histo::h3d*>::const_iterator;
|
||||
|
||||
// P1 types
|
||||
using G4P1 = tools::histo::p1d;
|
||||
using G4P1Iterator = std::vector<tools::histo::p1d*>::iterator;
|
||||
using G4P1ConstIterator = std::vector<tools::histo::p1d*>::const_iterator;
|
||||
|
||||
// P2 types
|
||||
using G4P2 = tools::histo::p2d;
|
||||
using G4P2Iterator = std::vector<tools::histo::p2d*>::iterator;
|
||||
using G4P2ConstIterator = std::vector<tools::histo::p2d*>::const_iterator;
|
||||
|
||||
// Ntuple types
|
||||
using G4Ntuple = tools::hdf5::ntuple;
|
||||
using G4NtupleIterator = std::vector<tools::hdf5::ntuple*>::iterator;
|
||||
using G4NtupleConstIterator = std::vector<tools::hdf5::ntuple*>::const_iterator;
|
||||
|
||||
// RNtuple types
|
||||
using G4RNtuple = tools::hdf5::ntuple;
|
||||
|
||||
// Managers
|
||||
using G4AnalysisManager = G4Hdf5AnalysisManager;
|
||||
using G4AnalysisReader = G4Hdf5AnalysisReader;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# sources.cmake
|
||||
# Module : G4hdf5
|
||||
# Package: Geant4.src.G4analysis.G4hdf5
|
||||
#
|
||||
# Sources description for a library.
|
||||
# Lists the sources and headers of the code explicitely.
|
||||
# Lists include paths needed.
|
||||
# Lists the internal granular and global dependencies of the library.
|
||||
# Source specific properties should be added at the end.
|
||||
#
|
||||
# Generated on : 27/07/2017
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# List external includes needed.
|
||||
include_directories(${CLHEP_INCLUDE_DIRS})
|
||||
include_directories(${EXPAT_INCLUDE_DIRS})
|
||||
include_directories(${HDF5_INCLUDE_DIRS})
|
||||
|
||||
# List internal includes needed.
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/global/management/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/intercoms/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/g4tools/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/management/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/hntools/include)
|
||||
|
||||
#
|
||||
# Define the Geant4 Module.
|
||||
#
|
||||
include(Geant4MacroDefineModule)
|
||||
GEANT4_DEFINE_MODULE(NAME G4xml
|
||||
HEADERS
|
||||
G4Hdf5AnalysisManager.hh
|
||||
G4Hdf5AnalysisManager.icc
|
||||
G4Hdf5AnalysisReader.hh
|
||||
G4Hdf5AnalysisReader.icc
|
||||
G4Hdf5FileManager.hh
|
||||
G4Hdf5NtupleManager.hh
|
||||
G4Hdf5RNtupleManager.hh
|
||||
G4Hdf5RFileManager.hh
|
||||
g4hdf5_defs.hh
|
||||
g4hdf5.hh
|
||||
SOURCES
|
||||
G4Hdf5AnalysisManager.cc
|
||||
G4Hdf5AnalysisReader.cc
|
||||
G4Hdf5FileManager.cc
|
||||
G4Hdf5NtupleManager.cc
|
||||
G4Hdf5RFileManager.cc
|
||||
G4Hdf5RNtupleManager.cc
|
||||
GRANULAR_DEPENDENCIES
|
||||
G4globman
|
||||
G4intercoms
|
||||
G4analysismng
|
||||
G4hntools
|
||||
GLOBAL_DEPENDENCIES
|
||||
G4global
|
||||
G4intercoms
|
||||
LINK_LIBRARIES
|
||||
${HDF5_LIBRARIES}
|
||||
)
|
||||
|
||||
# List any source specific properties here
|
||||
@@ -0,0 +1,377 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5AnalysisManager.hh"
|
||||
#include "G4Hdf5FileManager.hh"
|
||||
#include "G4Hdf5NtupleManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
// mutex in a file scope
|
||||
|
||||
namespace {
|
||||
//Mutex to lock master manager when opening a file
|
||||
G4Mutex openFileMutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH2Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging H1 histograms
|
||||
G4Mutex mergeH3Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P1 profiles
|
||||
G4Mutex mergeP1Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when merging P2 profiles
|
||||
G4Mutex mergeP2Mutex = G4MUTEX_INITIALIZER;
|
||||
//Mutex to lock master manager when closing a file
|
||||
G4Mutex closeFileMutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4Hdf5AnalysisManager* G4Hdf5AnalysisManager::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4Hdf5AnalysisManager* G4Hdf5AnalysisManager::fgInstance = nullptr;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisManager* G4Hdf5AnalysisManager::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4Hdf5AnalysisManager(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::IsInstance()
|
||||
{
|
||||
return ( fgInstance != 0 );
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisManager::G4Hdf5AnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("Hdf5", isMaster),
|
||||
fNtupleManager(nullptr),
|
||||
fFileManager(nullptr)
|
||||
{
|
||||
#ifdef G4MULTITHREADED
|
||||
#ifndef H5_HAVE_THREADSAFE
|
||||
G4ExceptionDescription message;
|
||||
message
|
||||
<< "Your HDF5 lib is not built with H5_HAVE_THREADSAFE.";
|
||||
G4Exception("G4Hdf5AnalysisManager::G4Hdf5AnalysisManager",
|
||||
"Analysis_F001", FatalException, message);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4Hdf5AnalysisManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4Hdf5AnalysisManager::G4Hdf5AnalysisManager",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
|
||||
// File manager
|
||||
fFileManager = std::make_shared<G4Hdf5FileManager>(fState);
|
||||
SetFileManager(fFileManager);
|
||||
fFileManager->SetBasketSize(fgkDefaultBasketSize);
|
||||
|
||||
// Ntuple manager
|
||||
fNtupleManager = new G4Hdf5NtupleManager(fState);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
SetNtupleManager(fNtupleManager);
|
||||
// The managers will be deleted by the base class
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisManager::~G4Hdf5AnalysisManager()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteH1()
|
||||
{
|
||||
auto h1Vector = fH1Manager->GetH1Vector();
|
||||
auto hnVector = fH1Manager->GetHnVector();
|
||||
|
||||
if ( ! h1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directoryName = fFileManager->GetHistoDirectoryName();
|
||||
result = WriteHn(h1Vector, hnVector, directoryName, "h1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH1(&mergeH1Mutex);
|
||||
fgMasterInstance->fH1Manager->AddH1Vector(h1Vector);
|
||||
lH1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteH2()
|
||||
{
|
||||
auto h2Vector = fH2Manager->GetH2Vector();
|
||||
auto hnVector = fH2Manager->GetHnVector();
|
||||
|
||||
if ( ! h2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directoryName = fFileManager->GetHistoDirectoryName();
|
||||
result = WriteHn(h2Vector, hnVector, directoryName, "h2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH2(&mergeH2Mutex);
|
||||
fgMasterInstance->fH2Manager->AddH2Vector(h2Vector);
|
||||
lH2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteH3()
|
||||
{
|
||||
auto h3Vector = fH3Manager->GetH3Vector();
|
||||
auto hnVector = fH3Manager->GetHnVector();
|
||||
|
||||
if ( ! h3Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directoryName = fFileManager->GetHistoDirectoryName();
|
||||
result = WriteHn(h3Vector, hnVector, directoryName, "h3");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lH3(&mergeH3Mutex);
|
||||
fgMasterInstance->fH3Manager->AddH3Vector(h3Vector);
|
||||
lH3.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteP1()
|
||||
{
|
||||
auto p1Vector = fP1Manager->GetP1Vector();
|
||||
auto hnVector = fP1Manager->GetHnVector();
|
||||
|
||||
if ( ! p1Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directoryName = fFileManager->GetHistoDirectoryName();
|
||||
result = WritePn(p1Vector, hnVector, directoryName, "p1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP1(&mergeP1Mutex);
|
||||
fgMasterInstance->fP1Manager->AddP1Vector(p1Vector);
|
||||
lP1.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteP2()
|
||||
{
|
||||
auto p2Vector = fP2Manager->GetP2Vector();
|
||||
auto hnVector = fP2Manager->GetHnVector();
|
||||
|
||||
if ( ! p2Vector.size() ) return true;
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directoryName = fFileManager->GetHistoDirectoryName();
|
||||
result = WritePn(p2Vector, hnVector, directoryName, "p2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its profiles to the master
|
||||
// This operation needs a lock
|
||||
G4AutoLock lP2(&mergeP2Mutex);
|
||||
fgMasterInstance->fP2Manager->AddP2Vector(p2Vector);
|
||||
lP2.unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisManager::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleManager->Reset(true);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = fFileManager->SetFileName(fileName);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
G4String name = fFileManager->GetFullFileName();
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("open", "analysis file", name);
|
||||
#endif
|
||||
|
||||
G4AutoLock lock(&openFileMutex);
|
||||
result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// fNtupleManager->SetNtupleDirectory(fFileManager->GetNtupleDirectory());
|
||||
fNtupleManager->CreateNtuplesFromBooking();
|
||||
lock.unlock();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("open", "analysis file", name, finalResult);
|
||||
#endif
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::WriteImpl()
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
auto name = fFileManager->GetFullFileName();
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("write", "files", name);
|
||||
#endif
|
||||
|
||||
// Histo directory
|
||||
// auto result = fFileManager->WriteHistoDirectory();
|
||||
// if ( ! result ) return false;
|
||||
|
||||
auto result = WriteH1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H2
|
||||
result = WriteH2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// H3
|
||||
result = WriteH3();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P1
|
||||
result = WriteP1();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// P2
|
||||
result = WriteP2();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// // Ntuple directory
|
||||
// result = fFileManager->WriteNtupleDirectory();
|
||||
// if ( ! result ) return false;
|
||||
|
||||
// Write ASCII if activated
|
||||
if ( IsAscii() ) {
|
||||
result = WriteAscii(fFileManager->GetFileName());
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("write", "file", fFileManager->GetFullFileName(), finalResult);
|
||||
#endif
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisManager::CloseFileImpl()
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
G4AutoLock lock(&closeFileMutex);
|
||||
auto result = fFileManager->CloseFile();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// reset data
|
||||
result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4Hdf5AnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
}
|
||||
lock.unlock();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// No files clean-up as ntuples are not supported in MT mode
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5AnalysisReader.hh"
|
||||
#include "G4Hdf5RNtupleManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::fgMasterInstance = nullptr;
|
||||
G4ThreadLocal G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::fgInstance = nullptr;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisReader* G4Hdf5AnalysisReader::Instance()
|
||||
{
|
||||
if ( fgInstance == nullptr ) {
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
fgInstance = new G4Hdf5AnalysisReader(isMaster);
|
||||
}
|
||||
|
||||
return fgInstance;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisReader::G4Hdf5AnalysisReader(G4bool isMaster)
|
||||
: G4ToolsAnalysisReader("Hdf5", isMaster),
|
||||
fNtupleManager(nullptr),
|
||||
fFileManager(nullptr)
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4Hdf5AnalysisReader already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4Hdf5AnalysisReader::G4Hdf5AnalysisReader()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( isMaster ) fgMasterInstance = this;
|
||||
fgInstance = this;
|
||||
|
||||
// Create managers
|
||||
fNtupleManager = new G4Hdf5RNtupleManager(fState);
|
||||
fFileManager = new G4Hdf5RFileManager(fState);
|
||||
|
||||
// Set managers to base class
|
||||
SetNtupleManager(fNtupleManager);
|
||||
SetFileManager(fFileManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5AnalysisReader::~G4Hdf5AnalysisReader()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
fgInstance = nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5AnalysisReader::Reset()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = G4ToolsAnalysisReader::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = fNtupleManager->Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadH1Impl(const G4String& h1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h1", h1Name);
|
||||
#endif
|
||||
|
||||
auto h1 = ReadHnImpl<tools::histo::h1d>(h1Name, fileName, dirName);
|
||||
|
||||
if ( ! h1 ) return kInvalidId;
|
||||
|
||||
auto id = fH1Manager->AddH1(h1Name, h1);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h1", h1Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadH2Impl(const G4String& h2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h2", h2Name);
|
||||
#endif
|
||||
|
||||
auto h2 = ReadHnImpl<tools::histo::h2d>(h2Name, fileName, dirName);
|
||||
|
||||
if ( ! h2 ) return kInvalidId;
|
||||
|
||||
auto id = fH2Manager->AddH2(h2Name, h2);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h2", h2Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadH3Impl(const G4String& h3Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "h3", h3Name);
|
||||
#endif
|
||||
|
||||
auto h3 = ReadHnImpl<tools::histo::h3d>(h3Name, fileName, dirName);
|
||||
|
||||
if ( ! h3 ) return kInvalidId;
|
||||
|
||||
auto id = fH3Manager->AddH3(h3Name, h3);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "h3", h3Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadP1Impl(const G4String& p1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "p1", p1Name);
|
||||
#endif
|
||||
|
||||
auto p1 = ReadPnImpl<tools::histo::p1d>(p1Name, fileName, dirName);
|
||||
|
||||
if ( ! p1 ) return kInvalidId;
|
||||
|
||||
auto id = fP1Manager->AddP1(p1Name, p1);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "p1", p1Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadP2Impl(const G4String& p2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "p2", p2Name);
|
||||
#endif
|
||||
|
||||
auto p2 = ReadPnImpl<tools::histo::p2d>(p2Name, fileName, dirName);
|
||||
|
||||
if ( ! p2 ) return kInvalidId;
|
||||
|
||||
auto id = fP2Manager->AddP2(p2Name, p2);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "p2", p2Name, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4Hdf5AnalysisReader::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("read", "ntuple", ntupleName);
|
||||
#endif
|
||||
|
||||
// Ntuples are saved in files per thread
|
||||
// but apply thethe thread suffix only if fileName is not provided explicitly
|
||||
G4String fullFileName = fileName;
|
||||
if ( ! isUserFileName ) {
|
||||
fullFileName = fFileManager->GetFullFileName();
|
||||
}
|
||||
|
||||
// Get directory
|
||||
auto directory = fFileManager->GetNtupleRDirectory(fullFileName, dirName, false);
|
||||
if ( directory < 0 ) return kInvalidId;
|
||||
|
||||
// Create ntuple
|
||||
auto rntuple = new tools::hdf5::ntuple(G4cout, directory, ntupleName);
|
||||
auto rntupleDescription = new G4TRNtupleDescription<tools::hdf5::ntuple>(rntuple);
|
||||
auto id = fNtupleManager->SetNtuple(rntupleDescription);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()->Message("read", "ntuple", ntupleName, id > kInvalidId);
|
||||
#endif
|
||||
|
||||
return id;
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5FileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/hdf5/h2file"
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
const G4String G4Hdf5FileManager::fgkDefaultDirectoryName = "default";
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5FileManager::G4Hdf5FileManager(const G4AnalysisManagerState& state)
|
||||
: G4VFileManager(state),
|
||||
fFile(kInvalidId),
|
||||
fHistoDirectory(kInvalidId),
|
||||
fNtupleDirectory(kInvalidId),
|
||||
fBasketSize(0) // TO DO: check default value !! (433 in test)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5FileManager::~G4Hdf5FileManager()
|
||||
{}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5FileManager::CreateDirectory(const G4String& directoryType,
|
||||
const G4String& directoryName, hid_t& directory)
|
||||
{
|
||||
// Method for both histograms and ntuples directories.
|
||||
// For histos: CreateDirectory("histograms", fHistoDirectoryName, fHistoDirectory)
|
||||
// For ntples: CreateDirectory("ntuples", fNtupleDirectoryName, fNtupleDirectory)
|
||||
|
||||
auto newDirectoryName = directoryName;
|
||||
|
||||
if ( newDirectoryName == "" ) {
|
||||
// if ( fDefaultDirectory > 0 ) {
|
||||
// // Return the default directory if the name is not set and the default directory
|
||||
// // already exists
|
||||
// directory = fDefaultDirectory;
|
||||
// return true;
|
||||
// } else {
|
||||
// Create the default directory if the name is not set and the default directory
|
||||
// does not yet exist
|
||||
newDirectoryName = fgkDefaultDirectoryName;
|
||||
newDirectoryName += "_";
|
||||
newDirectoryName += directoryType;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4String message = "directory for ";
|
||||
message += directoryType;
|
||||
fState.GetVerboseL4()->Message("create", message, newDirectoryName);
|
||||
}
|
||||
#endif
|
||||
|
||||
directory = tools_H5Gcreate(fFile, newDirectoryName, 0);
|
||||
// 0 seems to be an optional parameter. The web doc does not say what should
|
||||
// be the default value but 0 is what is found in examples, and in the code, if we pass 0, clearly some
|
||||
// default value is taken.
|
||||
|
||||
if ( directory < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot create directory " << directoryName;
|
||||
G4Exception("G4Hdf5FileManager::CreateDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
else {
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4String message = "directory for ";
|
||||
message += directoryType;
|
||||
fState.GetVerboseL2()->Message("create", message, newDirectoryName);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
#ifdef G4VERBOSE
|
||||
G4bool G4Hdf5FileManager::WriteDirectory(const G4String& directoryType,
|
||||
const G4String& directoryName, hid_t& directory)
|
||||
#else
|
||||
G4bool G4Hdf5FileManager::WriteDirectory(const G4String& /*directoryType*/,
|
||||
const G4String& directoryName, hid_t& directory)
|
||||
#endif
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4String message = "directory for ";
|
||||
message += directoryType;
|
||||
fState.GetVerboseL4()
|
||||
->Message("write", message, directoryName);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto result
|
||||
= tools::hdf5::write_atb(directory, "type", "directory");
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot write directory " << directoryName;
|
||||
G4Exception("G4Hdf5FileManager::WriteDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
// close
|
||||
// ::H5Gclose(histos);
|
||||
// ::H5Fclose(file);
|
||||
|
||||
return false;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
else {
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4String message = "directory for ";
|
||||
message += directoryType;
|
||||
fState.GetVerboseL2()->Message("write", message, fHistoDirectoryName);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5FileManager::OpenFile(const G4String& fileName)
|
||||
{
|
||||
// Keep file name
|
||||
fFileName = fileName;
|
||||
auto name = GetFullFileName();
|
||||
|
||||
// delete previous file if exists
|
||||
//if ( fFile ) delete fFile;
|
||||
|
||||
// create new file
|
||||
fFile = ::H5Fcreate(name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if ( fFile < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << fileName;
|
||||
G4Exception("G4Hdf5AnalysisManager::OpenFile()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create directories
|
||||
if ( ! CreateDirectory("histograms", fHistoDirectoryName, fHistoDirectory) ) return false;
|
||||
if ( ! CreateDirectory("ntuples", fNtupleDirectoryName, fNtupleDirectory) ) return false;
|
||||
|
||||
// // Open ntuple files
|
||||
// OpenNtupleFiles();
|
||||
|
||||
// Write directories
|
||||
if ( ! WriteHistoDirectory() ) return false;
|
||||
if ( ! WriteNtupleDirectory() ) return false;
|
||||
|
||||
fLockFileName = true;
|
||||
fLockHistoDirectoryName = true;
|
||||
fLockNtupleDirectoryName = true;
|
||||
|
||||
fIsOpenFile = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5FileManager::WriteFile()
|
||||
{
|
||||
// Nothing to be done here
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5FileManager::CloseFile()
|
||||
{
|
||||
// Do nothing if there is no file
|
||||
if ( fFile < 0 ) return true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("close", "file", GetFullFileName());
|
||||
#endif
|
||||
|
||||
if ( fHistoDirectory >= 0 ) {
|
||||
::H5Gclose(fHistoDirectory);
|
||||
}
|
||||
if ( fNtupleDirectory >= 0 ) {
|
||||
::H5Gclose(fNtupleDirectory);
|
||||
}
|
||||
::H5Fclose(fFile);
|
||||
|
||||
fLockFileName = false;
|
||||
fIsOpenFile = false;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("close", "file", GetFullFileName(), true);
|
||||
#endif
|
||||
|
||||
// CHECK
|
||||
// the result not returned from hdf5
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5FileManager::WriteHistoDirectory()
|
||||
{
|
||||
return WriteDirectory("histograms", fHistoDirectoryName, fHistoDirectory);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5FileManager::WriteNtupleDirectory()
|
||||
{
|
||||
return WriteDirectory("ntuples", fNtupleDirectoryName, fNtupleDirectory);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4Hdf5FileManager::CloseAfterHnWrite()
|
||||
{
|
||||
if ( fHistoDirectory >= 0 ) {
|
||||
::H5Gclose(fHistoDirectory);
|
||||
}
|
||||
::H5Fclose(fFile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5NtupleManager.hh"
|
||||
#include "G4Hdf5FileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
|
||||
#include "tools/ntuple_booking"
|
||||
|
||||
#include <iostream>
|
||||
//#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5NtupleManager::G4Hdf5NtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TNtupleManager<tools::hdf5::ntuple>(state),
|
||||
fFileManager(nullptr)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5NtupleManager::~G4Hdf5NtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
//_____________________________________________________________________________
|
||||
void G4Hdf5NtupleManager::CreateTNtuple(
|
||||
G4TNtupleDescription<tools::hdf5::ntuple>* /*ntupleDescription*/,
|
||||
const G4String& /*name*/, const G4String& /*title*/)
|
||||
{
|
||||
// Ntuple will be created at finish ntuple from ntuple_booking
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4Hdf5NtupleManager::CreateTNtupleFromBooking(
|
||||
G4TNtupleDescription<tools::hdf5::ntuple>* ntupleDescription)
|
||||
{
|
||||
// create a file for this ntuple
|
||||
// if ( ! fFileManager->CreateNtupleFile(ntupleDescription) ) return;
|
||||
|
||||
// Check ntuple directory
|
||||
if ( fFileManager->GetNtupleDirectory() < 0 ) {
|
||||
G4String inFunction = "G4Hdf5NtupleManager::::CreateTNtupleFromBooking";
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "Cannot create ntuple. Ntuple directory does not exist." << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W002", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
auto basketSize = fFileManager->GetBasketSize();
|
||||
// auto compressionLevel = fState.GetCompressionLevel();
|
||||
auto compressionLevel = 0;
|
||||
|
||||
// create ntuple
|
||||
ntupleDescription->fNtuple
|
||||
= new tools::hdf5::ntuple(
|
||||
G4cout, fFileManager->GetNtupleDirectory(), ntupleDescription->fNtupleBooking,
|
||||
compressionLevel, basketSize);
|
||||
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4Hdf5NtupleManager::FinishTNtuple(
|
||||
G4TNtupleDescription<tools::hdf5::ntuple>* /*ntupleDescription*/)
|
||||
{
|
||||
// if ( ! ntupleDescription->fNtuple ) return;
|
||||
|
||||
// Only ntuple description is created on CreateNtuple call
|
||||
// CreateTNtupleFromBooking(ntupleDescription);
|
||||
|
||||
fFileManager->LockNtupleDirectoryName();
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5RFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/hdf5/h2file"
|
||||
#include <tools/zlib>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
const G4String G4Hdf5RFileManager::fgkDefaultDirectoryName = "default";
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5RFileManager::G4Hdf5RFileManager(const G4AnalysisManagerState& state)
|
||||
: G4BaseFileManager(state),
|
||||
fRFiles()
|
||||
{
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5RFileManager::~G4Hdf5RFileManager()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::OpenRFile(const G4String& fileName,
|
||||
G4bool isPerThread)
|
||||
{
|
||||
// Get full file name
|
||||
G4String name = GetFullFileName(fileName, isPerThread);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("open", "read analysis file", name);
|
||||
#endif
|
||||
|
||||
// create new file
|
||||
hid_t newFile = H5Fopen(name, H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||
if ( newFile < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << name;
|
||||
G4Exception("G4Hdf5RFileManager::OpenFile()",
|
||||
"Analysis_WR001", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
// newFile->add_unziper('Z',tools::decompress_buffer);
|
||||
|
||||
// add file in a map
|
||||
std::map<G4String, hid_t>::iterator it
|
||||
= fRFiles.find(name);
|
||||
if ( it != fRFiles.end() ) {
|
||||
it->second = newFile;
|
||||
}
|
||||
else {
|
||||
fRFiles[name] = newFile;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("open", "read analysis file", name);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::OpenDirectory(hid_t file, const G4String& directoryName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("open", "read directory", directoryName);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto directory = tools_H5Gopen(file, directoryName);
|
||||
if ( directory < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot open directory " << directoryName;
|
||||
G4Exception("G4Hdf5RFileManager::OpenDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return kInvalidId;
|
||||
}
|
||||
else {
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("open", "read directory", directoryName);
|
||||
}
|
||||
#endif
|
||||
return directory;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::GetRDirectory(const G4String& directoryType,
|
||||
const G4String& fileName,
|
||||
const G4String& dirName,
|
||||
G4bool isPerThread)
|
||||
{
|
||||
// Get or open a file
|
||||
auto rfile = GetRFile(fileName, isPerThread);
|
||||
if ( rfile < 0 ) {
|
||||
// Try to open it if not found in the map
|
||||
if ( ! OpenRFile(fileName, isPerThread) ) return kInvalidId;
|
||||
rfile = GetRFile(fileName, isPerThread);
|
||||
}
|
||||
|
||||
// Use default directory name if not specified
|
||||
auto newDirName = dirName;
|
||||
if ( newDirName == "" ) {
|
||||
// if ( fDefaultDirectory > 0 ) {
|
||||
// // Return the default directory if the name is not set and the default directory
|
||||
// // already exists
|
||||
// directory = fDefaultDirectory;
|
||||
// return true;
|
||||
// } else {
|
||||
// Create the default directory if the name is not set and the default directory
|
||||
// does not yet exist
|
||||
newDirName = fgkDefaultDirectoryName;
|
||||
newDirName += "_";
|
||||
newDirName += directoryType;
|
||||
}
|
||||
|
||||
// Open directory
|
||||
return OpenDirectory(rfile, newDirName);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::GetRFile(const G4String& fileName,
|
||||
G4bool isPerThread) const
|
||||
{
|
||||
// Get full file name
|
||||
G4String name = GetFullFileName(fileName, isPerThread);
|
||||
|
||||
std::map<G4String, hid_t>::const_iterator it
|
||||
= fRFiles.find(name);
|
||||
if ( it != fRFiles.end() )
|
||||
return it->second;
|
||||
else {
|
||||
return kInvalidId;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::GetHistoRDirectory(const G4String& fileName, const G4String& dirName,
|
||||
G4bool isPerThread)
|
||||
{
|
||||
return GetRDirectory("histograms", fileName, dirName, isPerThread);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
hid_t G4Hdf5RFileManager::GetNtupleRDirectory(const G4String& fileName, const G4String& dirName,
|
||||
G4bool isPerThread)
|
||||
{
|
||||
return GetRDirectory("ntuples", fileName, dirName, isPerThread);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
|
||||
// Author: Ivana Hrivnacova, 20/07/2017 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4Hdf5RNtupleManager.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5RNtupleManager::G4Hdf5RNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4TRNtupleManager<tools::hdf5::ntuple>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4Hdf5RNtupleManager::~G4Hdf5RNtupleManager()
|
||||
{}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4Hdf5RNtupleManager::GetTNtupleRow(
|
||||
G4TRNtupleDescription<tools::hdf5::ntuple>* ntupleDescription)
|
||||
{
|
||||
auto ntuple = ntupleDescription->fNtuple;
|
||||
|
||||
auto isInitialized = ntupleDescription->fIsInitialized;
|
||||
if ( ! isInitialized ) {
|
||||
auto ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
if ( ! ntuple->initialize(G4cout, *ntupleBinding) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple initialization failed !!";
|
||||
G4Exception("G4Hdf5RNtuple::GetNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
ntupleDescription->fIsInitialized = true;
|
||||
}
|
||||
|
||||
if ( ! ntuple->get_row() ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple get_row() failed !!";
|
||||
G4Exception("G4Hdf5RNtuple::GetNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user