Import Geant4 10.7.0 source tree
This commit is contained in:
@@ -41,9 +41,7 @@
|
||||
#include <memory>
|
||||
|
||||
class G4RootFileManager;
|
||||
class G4RootNtupleManager;
|
||||
class G4RootMainNtupleManager;
|
||||
class G4RootPNtupleManager;
|
||||
class G4RootNtupleFileManager;
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
@@ -51,12 +49,6 @@ class directory;
|
||||
}
|
||||
}
|
||||
|
||||
enum class G4NtupleMergeMode {
|
||||
kNone,
|
||||
kMain,
|
||||
kSlave
|
||||
};
|
||||
|
||||
class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
{
|
||||
friend class G4RootMpiAnalysisManager;
|
||||
@@ -89,11 +81,11 @@ class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
protected:
|
||||
// virtual methods from base class
|
||||
virtual G4bool OpenFileImpl(const G4String& fileName) override;
|
||||
virtual G4bool WriteImpl() final;
|
||||
virtual G4bool WriteImpl() override;
|
||||
virtual G4bool CloseFileImpl(G4bool reset) override;
|
||||
virtual G4bool IsOpenFileImpl() const final;
|
||||
|
||||
// virtual functions (overriden in MPI implementation)
|
||||
virtual G4bool WriteNtuple();
|
||||
virtual G4bool Reset();
|
||||
|
||||
private:
|
||||
@@ -102,17 +94,9 @@ class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
static G4ThreadLocal G4RootAnalysisManager* fgInstance;
|
||||
|
||||
// methods
|
||||
void SetNtupleMergingMode(G4bool mergeNtuples,
|
||||
G4int nofNtupleFiles);
|
||||
void ClearNtupleManagers();
|
||||
void CreateNtupleManagers();
|
||||
G4int GetNtupleFileNumber();
|
||||
G4bool ResetNtuple();
|
||||
|
||||
template <typename T>
|
||||
G4bool WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
tools::wroot::directory* directory,
|
||||
const G4String& hnType);
|
||||
G4bool WriteH1();
|
||||
G4bool WriteH2();
|
||||
@@ -121,13 +105,8 @@ class G4RootAnalysisManager : public G4ToolsAnalysisManager
|
||||
G4bool WriteP2();
|
||||
|
||||
// data members
|
||||
G4int fNofNtupleFiles;
|
||||
G4bool fNtupleRowWise;
|
||||
G4bool fNtupleRowMode;
|
||||
G4NtupleMergeMode fNtupleMergeMode;
|
||||
G4RootNtupleManager* fNtupleManager;
|
||||
G4RootPNtupleManager* fSlaveNtupleManager;
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
std::shared_ptr<G4RootNtupleFileManager> fNtupleFileManager;
|
||||
};
|
||||
|
||||
#include "G4RootAnalysisManager.icc"
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
//
|
||||
|
||||
#include "G4RootNtupleManager.hh"
|
||||
#include "G4RootNtupleFileManager.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
|
||||
#include "tools/wroot/to"
|
||||
@@ -35,12 +36,13 @@ template <typename T>
|
||||
inline
|
||||
G4bool G4RootAnalysisManager::WriteT(const std::vector<T*>& htVector,
|
||||
const std::vector<G4HnInformation*>& hnVector,
|
||||
tools::wroot::directory* directory,
|
||||
const G4String& hnType)
|
||||
{
|
||||
// Do nothing if there is no file
|
||||
if ( ! directory ) return true;
|
||||
if ( ! fFileManager->GetFile() ) return true;
|
||||
|
||||
auto directory = std::get<1>(*fFileManager->GetFile());
|
||||
|
||||
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
|
||||
auto info = hnVector[i];
|
||||
auto activation = info->GetActivation();
|
||||
@@ -77,28 +79,28 @@ G4bool G4RootAnalysisManager::IsOpenFileImpl() const
|
||||
inline
|
||||
tools::wroot::ntuple* G4RootAnalysisManager::GetNtuple() const
|
||||
{
|
||||
return fNtupleManager->GetNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
tools::wroot::ntuple* G4RootAnalysisManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
return fNtupleManager->GetNtuple(ntupleId);
|
||||
return fNtupleFileManager->GetNtupleManager()->GetNtuple(ntupleId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wroot::ntuple*>::iterator G4RootAnalysisManager::BeginNtuple()
|
||||
{
|
||||
return fNtupleManager->BeginNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline
|
||||
std::vector<tools::wroot::ntuple*>::iterator G4RootAnalysisManager::EndNtuple()
|
||||
{
|
||||
return fNtupleManager->EndNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->EndNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -106,7 +108,7 @@ inline
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator
|
||||
G4RootAnalysisManager::BeginConstNtuple() const
|
||||
{
|
||||
return fNtupleManager->BeginConstNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->BeginConstNtuple();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -114,5 +116,5 @@ inline
|
||||
std::vector<tools::wroot::ntuple*>::const_iterator
|
||||
G4RootAnalysisManager::EndConstNtuple() const
|
||||
{
|
||||
return fNtupleManager->EndConstNtuple();
|
||||
return fNtupleFileManager->GetNtupleManager()->EndConstNtuple();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Manager class for Root ntuples.
|
||||
// It implements functions specific to Root ntuples in sequential mode.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4RootFile_h
|
||||
#define G4RootFile_h 1
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class directory;
|
||||
class file;
|
||||
}
|
||||
}
|
||||
|
||||
using G4RootFile = std::tuple<std::shared_ptr<tools::wroot::file>,
|
||||
tools::wroot::directory*,
|
||||
tools::wroot::directory*>;
|
||||
|
||||
#endif
|
||||
@@ -31,85 +31,92 @@
|
||||
#ifndef G4RootFileManager_h
|
||||
#define G4RootFileManager_h 1
|
||||
|
||||
#include "G4VFileManager.hh"
|
||||
#include "G4VTFileManager.hh"
|
||||
#include "G4RootFileDef.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class file;
|
||||
class directory;
|
||||
}
|
||||
namespace wroot{
|
||||
class ntuple;
|
||||
}
|
||||
}
|
||||
|
||||
class G4RootFileManager : public G4VFileManager
|
||||
// Types alias
|
||||
using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>;
|
||||
|
||||
class G4RootFileManager : public G4VTFileManager<G4RootFile>
|
||||
{
|
||||
public:
|
||||
explicit G4RootFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4RootFileManager();
|
||||
|
||||
// Methods to manipulate file
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
virtual G4bool WriteFile() final;
|
||||
virtual G4bool CloseFile() final;
|
||||
using G4BaseFileManager::GetNtupleFileName;
|
||||
using G4VTFileManager<G4RootFile>::WriteFile;
|
||||
using G4VTFileManager<G4RootFile>::CloseFile;
|
||||
|
||||
// Methods to manipulate file from base classes
|
||||
virtual G4bool OpenFile(const G4String& fileName) final;
|
||||
|
||||
virtual G4String GetFileType() const final { return "root"; }
|
||||
|
||||
// Specific methods for files per objects
|
||||
std::shared_ptr<G4RootFile> CreateNtupleFile(RootNtupleDescription* ntupleDescription,
|
||||
G4int mainNumber = -1);
|
||||
std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription,
|
||||
G4bool perThread = true,
|
||||
G4int mainNumber = -1) const;
|
||||
G4bool WriteNtupleFile(RootNtupleDescription* ntupleDescription);
|
||||
G4bool CloseNtupleFile(RootNtupleDescription* ntupleDescription);
|
||||
|
||||
G4bool CreateHistoDirectory();
|
||||
G4bool CreateNtupleDirectory();
|
||||
|
||||
// Set methods
|
||||
void SetNofNtupleFiles(G4int nofFiles);
|
||||
void SetBasketSize(unsigned int basketSize);
|
||||
void SetBasketEntries(unsigned int basketEntries);
|
||||
|
||||
// Get methods
|
||||
tools::wroot::directory* GetHistoDirectory() const;
|
||||
tools::wroot::directory* GetNtupleDirectory() const;
|
||||
std::shared_ptr<tools::wroot::file> GetNtupleFile(G4int index) const;
|
||||
tools::wroot::directory* GetMainNtupleDirectory(G4int index) const;
|
||||
unsigned int GetBasketSize() const;
|
||||
unsigned int GetBasketEntries() const;
|
||||
|
||||
protected:
|
||||
// Methods derived from templated base class
|
||||
virtual std::shared_ptr<G4RootFile> CreateFileImpl(const G4String& fileName) final;
|
||||
virtual G4bool WriteFileImpl(std::shared_ptr<G4RootFile> file) final;
|
||||
virtual G4bool CloseFileImpl(std::shared_ptr<G4RootFile> file) final;
|
||||
|
||||
private:
|
||||
// methods
|
||||
G4bool OpenNtupleFiles();
|
||||
G4bool WriteFile(std::shared_ptr<tools::wroot::file> rfile,
|
||||
const G4String& fileName);
|
||||
G4bool CloseFile(std::shared_ptr<tools::wroot::file> rfile,
|
||||
const G4String& fileName);
|
||||
tools::wroot::directory* CreateDirectory(
|
||||
std::shared_ptr<tools::wroot::file> rfile,
|
||||
const G4String& directoryName,
|
||||
const G4String& objectType) const;
|
||||
G4String GetNtupleFileName(
|
||||
RootNtupleDescription* ntupleDescription,
|
||||
G4bool perThread = true,
|
||||
G4int mainNumber = -1) const;
|
||||
|
||||
// data members
|
||||
std::shared_ptr<tools::wroot::file> fFile;
|
||||
tools::wroot::directory* fHistoDirectory;
|
||||
tools::wroot::directory* fNtupleDirectory;
|
||||
G4int fNofNtupleFiles;
|
||||
std::vector<std::shared_ptr<tools::wroot::file> > fNtupleFiles;
|
||||
std::vector<tools::wroot::directory*> fMainNtupleDirectories;
|
||||
unsigned int fBasketSize;
|
||||
unsigned int fBasketEntries;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void G4RootFileManager::SetNofNtupleFiles(G4int nofFiles)
|
||||
{ fNofNtupleFiles = nofFiles; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4RootFileManager::SetBasketSize(unsigned int basketSize)
|
||||
{ fBasketSize = basketSize; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4RootFileManager::SetBasketEntries(unsigned int basketEntries)
|
||||
{ fBasketEntries = basketEntries; }
|
||||
|
||||
inline tools::wroot::directory* G4RootFileManager::GetHistoDirectory() const
|
||||
{ return fHistoDirectory; }
|
||||
|
||||
inline tools::wroot::directory* G4RootFileManager::GetNtupleDirectory() const
|
||||
{ return fNtupleDirectory; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline unsigned int G4RootFileManager::GetBasketSize() const
|
||||
{ return fBasketSize; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline unsigned int G4RootFileManager::GetBasketEntries() const
|
||||
{ return fBasketEntries; }
|
||||
|
||||
|
||||
@@ -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 for histogram/profile Root file output.
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4RootHnFileManager_h
|
||||
#define G4RootHnFileManager_h 1
|
||||
|
||||
#include "G4VTHnFileManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4RootFileManager;
|
||||
|
||||
template <typename HT>
|
||||
class G4RootHnFileManager : public G4VTHnFileManager<HT>
|
||||
{
|
||||
public:
|
||||
G4RootHnFileManager(G4RootFileManager* fileManger)
|
||||
: G4VTHnFileManager<HT>(), fFileManager(fileManger) {}
|
||||
virtual ~G4RootHnFileManager() {}
|
||||
|
||||
// Methods for writing objects
|
||||
// Write to a new file (the file is closed after write)
|
||||
virtual G4bool WriteExtra(HT* ht, const G4String& htName, const G4String& fileName) final;
|
||||
// Write to the default file (handled with OpenFile()/CloseFile methods)
|
||||
virtual G4bool Write(HT* ht, const G4String& htName, G4String& fileName) final;
|
||||
|
||||
private:
|
||||
// Methods
|
||||
G4bool Write(tools::wroot::directory* directory, HT* ht, const G4String& htName);
|
||||
|
||||
// Data members
|
||||
G4RootFileManager* fFileManager;
|
||||
};
|
||||
|
||||
#include "G4RootHnFileManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "tools/wroot/to"
|
||||
#include "tools/wroot/file"
|
||||
#include "tools/zlib"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
G4bool G4RootHnFileManager<HT>::Write(
|
||||
tools::wroot::directory* directory, HT* ht, const G4String& htName)
|
||||
{
|
||||
// write histpgram
|
||||
return to(*directory, *ht, htName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
G4bool G4RootHnFileManager<HT>::WriteExtra(
|
||||
HT* ht, const G4String& htName, const G4String& fileName)
|
||||
{
|
||||
auto finalResult = true;
|
||||
auto result = true;
|
||||
|
||||
// // create a new file
|
||||
tools::wroot::file* rfile = new tools::wroot::file(G4cout, fileName);
|
||||
// TO DO
|
||||
// rfile->add_ziper('Z', tools::compress_buffer);
|
||||
// rfile->set_compression(fState.GetCompressionLevel());
|
||||
if ( ! rfile ) return false;
|
||||
|
||||
// no directory supported in this mode
|
||||
auto hdirectory = &(rfile->dir());
|
||||
if ( ! hdirectory ) return false;
|
||||
|
||||
// write histo
|
||||
result = Write(hdirectory, ht, htName);
|
||||
finalResult = result && finalResult;
|
||||
|
||||
// write file
|
||||
unsigned int n;
|
||||
result = rfile->write(n);
|
||||
finalResult = result && finalResult;
|
||||
|
||||
// close file
|
||||
rfile->close();
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename HT>
|
||||
G4bool G4RootHnFileManager<HT>::Write(
|
||||
HT* ht, const G4String& htName, G4String& fileName)
|
||||
{
|
||||
if ( fileName.empty()) {
|
||||
// should not happen
|
||||
G4cerr << "!!! Root file name not defined." << G4endl;
|
||||
G4cerr << "!!! Write " << htName << " failed." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto hdirectory = std::get<1>(*fFileManager->GetTFile(fileName));
|
||||
if ( hdirectory == nullptr ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Failed to get Root file " << fileName << " histo directory.";
|
||||
G4Exception("G4RootHnFileManager<HT>::Write()",
|
||||
"Analysis_W022", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto result = Write(hdirectory, ht, htName);
|
||||
fFileManager->LockDirectoryNames();
|
||||
return result;
|
||||
}
|
||||
@@ -32,81 +32,74 @@
|
||||
#define G4RootMainNtupleManager_h 1
|
||||
|
||||
#include "G4BaseAnalysisManager.hh"
|
||||
#include "G4NtupleBookingManager.hh"
|
||||
#include "G4TNtupleDescription.hh"
|
||||
#include "G4RootNtupleManager.hh"
|
||||
#include "G4RootFileDef.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class G4RootFileManager;
|
||||
class G4RootNtupleManager;
|
||||
class G4NtupleBookingManager;
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class file;
|
||||
class ntuple;
|
||||
}
|
||||
}
|
||||
|
||||
// Types alias
|
||||
using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>;
|
||||
|
||||
class G4RootMainNtupleManager : public G4BaseAnalysisManager
|
||||
{
|
||||
friend class G4RootPNtupleManager;
|
||||
friend class G4RootNtupleManager;
|
||||
|
||||
public:
|
||||
explicit G4RootMainNtupleManager(G4RootNtupleManager* ntupleBuilder,
|
||||
G4bool rowWise,
|
||||
const G4AnalysisManagerState& state);
|
||||
explicit G4RootMainNtupleManager(
|
||||
G4RootNtupleManager* ntupleBuilder,
|
||||
G4NtupleBookingManager* bookingManager,
|
||||
G4bool rowWise, G4int fileNumber,
|
||||
const G4AnalysisManagerState& state);
|
||||
~G4RootMainNtupleManager();
|
||||
|
||||
protected:
|
||||
// Types alias
|
||||
using NtupleType = tools::wroot::ntuple;
|
||||
using NtupleDescriptionType = G4TNtupleDescription<NtupleType>;
|
||||
|
||||
// Methods to manipulate ntuples
|
||||
void CreateNtuple(const tools::ntuple_booking& ntupleBooking, G4bool warn = true);
|
||||
void CreateNtuplesFromBooking();
|
||||
void CreateNtuple(RootNtupleDescription* ntupleDescription, G4bool warn = true);
|
||||
G4bool Merge();
|
||||
G4bool Reset(G4bool deleteNtuple);
|
||||
|
||||
// Set/get methods
|
||||
void SetNtupleFile(std::shared_ptr<tools::wroot::file> rfile);
|
||||
void SetNtupleDirectory(tools::wroot::directory* directory);
|
||||
void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
|
||||
void SetRowWise(G4bool rowWise);
|
||||
std::shared_ptr<tools::wroot::file> GetNtupleFile() const;
|
||||
tools::wroot::directory* GetNtupleDirectory() const;
|
||||
std::shared_ptr<G4RootFile> GetNtupleFile(RootNtupleDescription* ntupleDescription) const;
|
||||
|
||||
// Access functions
|
||||
const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector()
|
||||
{ return fNtupleBuilder->GetNtupleDescriptionVector(); }
|
||||
const std::vector<tools::wroot::ntuple*>& GetNtupleVector()
|
||||
{ return fNtupleVector; }
|
||||
unsigned int GetBasketEntries() const;
|
||||
|
||||
private:
|
||||
// Data members
|
||||
G4RootNtupleManager* fNtupleBuilder;
|
||||
G4RootNtupleManager* fNtupleBuilder;
|
||||
G4NtupleBookingManager* fBookingManager;
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
G4bool fRowWise;
|
||||
std::shared_ptr<tools::wroot::file> fNtupleFile;
|
||||
tools::wroot::directory* fNtupleDirectory;
|
||||
std::vector<tools::wroot::ntuple*> fNtupleVector;
|
||||
G4int fFileNumber;
|
||||
std::vector<tools::wroot::ntuple*> fNtupleVector;
|
||||
std::vector<RootNtupleDescription*> fNtupleDescriptionVector;
|
||||
};
|
||||
|
||||
inline void G4RootMainNtupleManager::SetNtupleFile(std::shared_ptr<tools::wroot::file> rfile)
|
||||
{ fNtupleFile = rfile; }
|
||||
|
||||
inline void G4RootMainNtupleManager::SetNtupleDirectory(tools::wroot::directory* directory)
|
||||
{ fNtupleDirectory = directory; }
|
||||
inline void G4RootMainNtupleManager::SetFileManager(
|
||||
std::shared_ptr<G4RootFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline void G4RootMainNtupleManager::SetRowWise(G4bool rowWise)
|
||||
{ fRowWise = rowWise; }
|
||||
|
||||
inline std::shared_ptr<tools::wroot::file> G4RootMainNtupleManager::GetNtupleFile() const
|
||||
{ return fNtupleFile; }
|
||||
|
||||
inline tools::wroot::directory* G4RootMainNtupleManager::GetNtupleDirectory() const
|
||||
{ return fNtupleDirectory; }
|
||||
|
||||
inline unsigned int G4RootMainNtupleManager::GetBasketEntries() const
|
||||
{ return fNtupleBuilder->GetBasketEntries(); }
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Manager class for ntuple Root file output,
|
||||
// provides handling Root ntuple managers in parallel processing.
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#ifndef G4RootNtupleFileManager_h
|
||||
#define G4RootNtupleFileManager_h 1
|
||||
|
||||
#include "G4VNtupleFileManager.hh"
|
||||
|
||||
class G4RootFileManager;
|
||||
class G4RootNtupleManager;
|
||||
class G4RootPNtupleManager;
|
||||
class G4VNtupleManager;
|
||||
class G4NtupleBookingManager;
|
||||
|
||||
enum class G4NtupleMergeMode {
|
||||
kNone,
|
||||
kMain,
|
||||
kSlave
|
||||
};
|
||||
|
||||
class G4RootNtupleFileManager : public G4VNtupleFileManager
|
||||
{
|
||||
friend class G4RootMpiNtupleFileManager;
|
||||
|
||||
public:
|
||||
explicit G4RootNtupleFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4RootNtupleFileManager();
|
||||
|
||||
// MT/MPI
|
||||
virtual void SetNtupleMerging(G4bool mergeNtuples,
|
||||
G4int nofReducedNtupleFiles = 0) override;
|
||||
virtual void SetNtupleRowWise(G4bool rowWise, G4bool rowMode = true) override;
|
||||
virtual void SetBasketSize(unsigned int basketSize) override;
|
||||
virtual void SetBasketEntries(unsigned int basketEntries) override;
|
||||
|
||||
// virtual methods from base class
|
||||
virtual G4bool ActionAtOpenFile(const G4String& fileName) override;
|
||||
virtual G4bool ActionAtWrite() override;
|
||||
virtual G4bool ActionAtCloseFile(G4bool reset) override;
|
||||
virtual G4bool Reset() override;
|
||||
virtual G4bool IsNtupleMergingSupported() const override;
|
||||
|
||||
virtual std::shared_ptr<G4VNtupleManager> CreateNtupleManager() override;
|
||||
|
||||
void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
|
||||
|
||||
G4NtupleMergeMode GetMergeMode() const;
|
||||
std::shared_ptr<G4RootNtupleManager> GetNtupleManager() const;
|
||||
|
||||
private:
|
||||
// static data members
|
||||
static G4RootNtupleFileManager* fgMasterInstance;
|
||||
|
||||
void SetNtupleMergingMode(G4bool mergeNtuples, G4int nofNtupleFiles);
|
||||
G4int GetNtupleFileNumber();
|
||||
G4bool CloseNtupleFiles();
|
||||
|
||||
// data members
|
||||
G4bool fIsInitialized;
|
||||
G4int fNofNtupleFiles;
|
||||
G4bool fNtupleRowWise;
|
||||
G4bool fNtupleRowMode;
|
||||
G4NtupleMergeMode fNtupleMergeMode;
|
||||
std::shared_ptr<G4RootNtupleManager> fNtupleManager;
|
||||
std::shared_ptr<G4RootPNtupleManager> fSlaveNtupleManager;
|
||||
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
};
|
||||
|
||||
inline void G4RootNtupleFileManager::SetFileManager(
|
||||
std::shared_ptr<G4RootFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline G4NtupleMergeMode G4RootNtupleFileManager::GetMergeMode() const
|
||||
{ return fNtupleMergeMode; }
|
||||
|
||||
inline G4bool G4RootNtupleFileManager::IsNtupleMergingSupported() const
|
||||
{ return true; }
|
||||
|
||||
inline std::shared_ptr<G4RootNtupleManager> G4RootNtupleFileManager::GetNtupleManager() const
|
||||
{ return fNtupleManager; }
|
||||
|
||||
#endif
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
|
||||
// Manager class for Root ntuples.
|
||||
// It implements functions specific to Root ntuples.
|
||||
// It implements functions specific to Root ntuples in sequential mode.
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -33,160 +33,73 @@
|
||||
#define G4RootNtupleManager_h 1
|
||||
|
||||
#include "G4TNtupleManager.hh"
|
||||
#include "G4RootFileDef.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/wroot/ntuple"
|
||||
|
||||
class G4RootMainNtupleManager;
|
||||
class G4NtupleBookingManager;
|
||||
class G4RootFileManager;
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class directory;
|
||||
}
|
||||
}
|
||||
|
||||
enum class G4NtupleCreateMode {
|
||||
kNoMergeBeforeOpen,
|
||||
kNoMergeAfterOpen,
|
||||
kMainBeforeOpen,
|
||||
kMainAfterOpen,
|
||||
kUndefined
|
||||
};
|
||||
// Types alias
|
||||
using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>;
|
||||
|
||||
// template specializations used by this class defined below
|
||||
|
||||
template <>
|
||||
template <>
|
||||
G4bool G4TNtupleManager<tools::wroot::ntuple>::FillNtupleTColumn(
|
||||
G4bool G4TNtupleManager<tools::wroot::ntuple, G4RootFile>::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const std::string& value);
|
||||
|
||||
|
||||
class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple>
|
||||
class G4RootNtupleManager : public G4TNtupleManager<tools::wroot::ntuple,
|
||||
G4RootFile>
|
||||
{
|
||||
friend class G4RootAnalysisManager;
|
||||
friend class G4RootMainNtupleManager;
|
||||
friend class G4RootMpiAnalysisManager;
|
||||
friend class G4RootNtupleFileManager;
|
||||
friend class G4RootMpiNtupleFileManager;
|
||||
friend class G4RootMpiNtupleManager;
|
||||
|
||||
public:
|
||||
explicit G4RootNtupleManager(const G4AnalysisManagerState& state,
|
||||
G4int nofMainManagers,
|
||||
G4bool rowWise, G4bool rowMode);
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManger,
|
||||
G4int nofMainManagers, G4int nofReducedFiles,
|
||||
G4bool rowWise, G4bool rowMode);
|
||||
virtual ~G4RootNtupleManager();
|
||||
|
||||
private:
|
||||
// Types alias
|
||||
using NtupleType = tools::wroot::ntuple;
|
||||
using NtupleDescriptionType = G4TNtupleDescription<NtupleType>;
|
||||
|
||||
// Functions specific to the output type
|
||||
|
||||
void SetNtupleDirectory(tools::wroot::directory* directory);
|
||||
void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
|
||||
|
||||
// Utility function
|
||||
void CreateTNtuple(NtupleDescriptionType* ntupleDescription);
|
||||
|
||||
// Methods from the templated base class
|
||||
|
||||
virtual void CreateTNtupleFromBooking(
|
||||
NtupleDescriptionType* ntupleDescription) final;
|
||||
|
||||
RootNtupleDescription* ntupleDescription) final;
|
||||
virtual void FinishTNtuple(
|
||||
NtupleDescriptionType* ntupleDescription,
|
||||
RootNtupleDescription* ntupleDescription,
|
||||
G4bool fromBooking) final;
|
||||
|
||||
virtual G4bool Reset(G4bool deleteNtuple);
|
||||
|
||||
// Method for merging
|
||||
//
|
||||
virtual G4bool Reset(G4bool deleteNtuple) final;
|
||||
virtual G4bool Merge();
|
||||
|
||||
// Set functions
|
||||
void SetFileManager(std::shared_ptr<G4RootFileManager> fileManager);
|
||||
void SetNtupleFile(std::shared_ptr<G4RootFile> file);
|
||||
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
|
||||
|
||||
// Access functions
|
||||
//
|
||||
const std::vector<NtupleDescriptionType*>& GetNtupleDescriptionVector() const;
|
||||
G4RootMainNtupleManager* GetMainNtupleManager(G4int index) const;
|
||||
const std::vector<RootNtupleDescription*>& GetNtupleDescriptionVector() const;
|
||||
std::shared_ptr<G4RootMainNtupleManager> GetMainNtupleManager(G4int index) const;
|
||||
unsigned int GetBasketSize() const;
|
||||
unsigned int GetBasketEntries() const;
|
||||
|
||||
// Utility functions
|
||||
//
|
||||
void SetCreateMode();
|
||||
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
|
||||
|
||||
// data members
|
||||
//
|
||||
G4NtupleCreateMode fCreateMode;
|
||||
std::shared_ptr<G4RootFileManager> fFileManager;
|
||||
tools::wroot::directory* fNtupleDirectory;
|
||||
std::vector<G4RootMainNtupleManager*> fMainNtupleManagers;
|
||||
std::vector<std::shared_ptr<G4RootMainNtupleManager>> fMainNtupleManagers;
|
||||
std::shared_ptr<G4RootFile> fNtupleFile;
|
||||
G4bool fRowWise;
|
||||
G4bool fRowMode;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline void
|
||||
G4RootNtupleManager::SetNtupleDirectory(tools::wroot::directory* directory)
|
||||
{ fNtupleDirectory = directory; }
|
||||
|
||||
inline void
|
||||
G4RootNtupleManager::SetFileManager(std::shared_ptr<G4RootFileManager> fileManager)
|
||||
{ fFileManager = fileManager; }
|
||||
|
||||
inline const std::vector<G4TNtupleDescription<tools::wroot::ntuple>* >&
|
||||
G4RootNtupleManager::GetNtupleDescriptionVector() const
|
||||
{ return fNtupleDescriptionVector; }
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
template <>
|
||||
inline G4bool G4TNtupleManager<tools::wroot::ntuple>::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const std::string& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
//G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4RootNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
auto column = dynamic_cast<tools::wroot::ntuple::column_string* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4RootNtupleManager:FillNtupleColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
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;
|
||||
}
|
||||
#include "G4RootNtupleManager.icc"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4RootNtupleManager::SetNtupleFile(std::shared_ptr<G4RootFile> file)
|
||||
{
|
||||
fNtupleFile = file;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline const
|
||||
std::vector<G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>* >&
|
||||
G4RootNtupleManager::GetNtupleDescriptionVector() const
|
||||
{
|
||||
return fNtupleDescriptionVector;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
template <>
|
||||
inline G4bool G4TNtupleManager<tools::wroot::ntuple, G4RootFile>::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const std::string& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
//G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4RootNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
auto column = dynamic_cast<tools::wroot::ntuple::column_string* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4RootNtupleManager:FillNtupleColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
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;
|
||||
}
|
||||
@@ -31,6 +31,8 @@
|
||||
#ifndef G4RootPNtupleDescription_h
|
||||
#define G4RootPNtupleDescription_h 1
|
||||
|
||||
#include "G4TNtupleDescription.hh"
|
||||
#include "G4RootFileDef.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include "tools/ntuple_booking"
|
||||
@@ -41,34 +43,30 @@
|
||||
|
||||
namespace tools {
|
||||
namespace wroot {
|
||||
class file;
|
||||
class branch;
|
||||
class ntuple;
|
||||
}
|
||||
}
|
||||
|
||||
using RootNtupleDescription = G4TNtupleDescription<tools::wroot::ntuple, G4RootFile>;
|
||||
|
||||
struct G4RootPNtupleDescription
|
||||
{
|
||||
G4RootPNtupleDescription()
|
||||
: fFile(nullptr),
|
||||
G4RootPNtupleDescription(G4NtupleBooking* g4NtupleBooking)
|
||||
: fDescription(g4NtupleBooking),
|
||||
fNtuple(nullptr),
|
||||
fBasePNtuple(nullptr),
|
||||
fMainBranches(),
|
||||
fNtupleBooking(),
|
||||
fActivation(true),
|
||||
fIsNtupleOwner(true) {}
|
||||
fMainBranches() {}
|
||||
|
||||
~G4RootPNtupleDescription()
|
||||
{
|
||||
if ( fIsNtupleOwner ) delete fNtuple;
|
||||
if ( fDescription.fIsNtupleOwner ) delete fNtuple;
|
||||
}
|
||||
|
||||
tools::wroot::file* fFile;
|
||||
RootNtupleDescription fDescription;
|
||||
tools::wroot::imt_ntuple* fNtuple;
|
||||
tools::wroot::base_pntuple* fBasePNtuple;
|
||||
std::vector<tools::wroot::branch*> fMainBranches;
|
||||
tools::ntuple_booking fNtupleBooking;
|
||||
G4bool fActivation;
|
||||
G4bool fIsNtupleOwner;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -75,48 +75,29 @@ protected:
|
||||
G4AutoLock& m_mutex;
|
||||
};
|
||||
|
||||
class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
{
|
||||
friend class G4RootAnalysisManager;
|
||||
friend class G4RootNtupleFileManager;
|
||||
|
||||
public:
|
||||
explicit G4RootPNtupleManager(G4RootMainNtupleManager* main,
|
||||
const G4AnalysisManagerState& state,
|
||||
explicit G4RootPNtupleManager(const G4AnalysisManagerState& state,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManger,
|
||||
std::shared_ptr<G4RootMainNtupleManager> main,
|
||||
G4bool rowWise, G4bool rowMode);
|
||||
~G4RootPNtupleManager();
|
||||
|
||||
private:
|
||||
enum class G4PNtupleCreateMode {
|
||||
kSlaveBeforeOpen,
|
||||
kSlaveAfterOpen,
|
||||
kUndefined
|
||||
};
|
||||
|
||||
// Methods to manipulate ntuples
|
||||
void CreateNtuple(G4RootPNtupleDescription* ntupleDescription,
|
||||
tools::wroot::ntuple* mainNtuple);
|
||||
void CreateNtupleFromMain(G4RootPNtupleDescription* ntupleDescription,
|
||||
tools::wroot::ntuple* mainNtuple);
|
||||
// void CreateNtupleFromMain(G4NtupleBooking* g4NtupleBooking,
|
||||
// tools::wroot::ntuple* mainNtuple);
|
||||
void CreateNtuplesFromMain();
|
||||
|
||||
// Methods to create ntuples
|
||||
//
|
||||
virtual G4int CreateNtuple(const G4String& name, const G4String& title) final;
|
||||
|
||||
// Create columns in the last created ntuple (from base class)
|
||||
using G4BaseNtupleManager::CreateNtupleIColumn;
|
||||
using G4BaseNtupleManager::CreateNtupleFColumn;
|
||||
using G4BaseNtupleManager::CreateNtupleDColumn;
|
||||
using G4BaseNtupleManager::CreateNtupleSColumn;
|
||||
using G4BaseNtupleManager::FinishNtuple;
|
||||
|
||||
// Create columns in the ntuple with given id
|
||||
virtual G4int CreateNtupleIColumn(G4int ntupleId,
|
||||
const G4String& name, std::vector<int>* vector) override;
|
||||
virtual G4int CreateNtupleFColumn(G4int ntupleId,
|
||||
const G4String& name, std::vector<float>* vector) override;
|
||||
virtual G4int CreateNtupleDColumn(G4int ntupleId,
|
||||
const G4String& name, std::vector<double>* vector) override;
|
||||
virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String& name) override;
|
||||
virtual void FinishNtuple(G4int ntupleId) override;
|
||||
virtual G4int CreateNtuple(G4NtupleBooking* booking) final;
|
||||
|
||||
// Methods to fill ntuples
|
||||
// Methods for ntuple with id = FirstNtupleId (from base class)
|
||||
@@ -142,11 +123,9 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
virtual void SetActivation(G4bool activation) final;
|
||||
virtual void SetActivation(G4int ntupleId, G4bool activation) final;
|
||||
virtual G4bool GetActivation(G4int ntupleId) const final;
|
||||
virtual G4bool IsEmpty() const final;
|
||||
|
||||
// Access methods
|
||||
virtual G4int GetNofNtuples() const final;
|
||||
virtual G4int GetNofNtupleBookings() const final;
|
||||
|
||||
// Set methods
|
||||
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode);
|
||||
@@ -159,14 +138,6 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
tools::wroot::ntuple*
|
||||
GetMainNtupleInFunction(G4int id, G4String function, G4bool warn = true) const;
|
||||
|
||||
template <typename T>
|
||||
G4int CreateNtupleTColumn(G4int ntupleId,
|
||||
const G4String& name, std::vector<T>* vector);
|
||||
|
||||
template <typename T>
|
||||
G4int CreateNtupleTColumn(
|
||||
const G4String& name, std::vector<T>* vector);
|
||||
|
||||
template <typename T>
|
||||
G4bool FillNtupleTColumn(G4int ntupleId, G4int columnId, const T& value);
|
||||
|
||||
@@ -174,184 +145,14 @@ class G4RootPNtupleManager : public G4BaseNtupleManager
|
||||
G4bool FillNtupleTColumn(G4int columnId, const T& value);
|
||||
|
||||
// Data members
|
||||
G4PNtupleCreateMode fCreateMode;
|
||||
G4RootMainNtupleManager* fMainNtupleManager;
|
||||
std::shared_ptr<G4NtupleBookingManager> fBookingManager;
|
||||
std::shared_ptr<G4RootMainNtupleManager> fMainNtupleManager;
|
||||
std::vector<G4RootPNtupleDescription*> fNtupleDescriptionVector;
|
||||
std::vector<tools::wroot::imt_ntuple*> fNtupleVector;
|
||||
G4bool fRowWise;
|
||||
G4bool fRowMode;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4int G4RootPNtupleManager::CreateNtupleTColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<T>* vector)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("create", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "CreateNtupleTColumn");
|
||||
if ( ! ntupleDescription ) return G4Analysis::kInvalidId;
|
||||
|
||||
// Save column info in booking
|
||||
auto& ntupleBooking = ntupleDescription->fNtupleBooking;
|
||||
auto index = ntupleBooking.columns().size();
|
||||
if ( ! vector )
|
||||
ntupleBooking.template add_column<T>(name);
|
||||
else
|
||||
ntupleBooking.template add_column<T>(name, *vector);
|
||||
|
||||
fLockFirstNtupleColumnId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL2()->Message("create", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return index + fFirstNtupleColumnId;
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4int G4RootPNtupleManager::CreateNtupleTColumn(
|
||||
const G4String& name, std::vector<T>* vector)
|
||||
{
|
||||
auto ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
|
||||
return CreateNtupleTColumn<T>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const std::string& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4RootNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
auto column = dynamic_cast<tools::wroot::base_pntuple::column_string* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4RootNtupleManager:FillNtupleColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("done fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const T& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
// 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::wroot::base_pntuple::column<T>* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4TNtupleManager:FillNtupleTColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("done fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4RootPNtupleManager::FillNtupleTColumn(G4int columnId, const T& value) {
|
||||
return FillNtupleTColumn(0, columnId, value);
|
||||
}
|
||||
#include "G4RootPNtupleManager.icc"
|
||||
|
||||
#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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <>
|
||||
inline G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const std::string& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto ntuple = GetNtupleInFunction(ntupleId, "FillNtupleTColumn");
|
||||
if ( ! ntuple ) return false;
|
||||
|
||||
auto index = columnId - fFirstNtupleColumnId;
|
||||
if ( index < 0 || index >= G4int(ntuple->columns().size()) ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " does not exist.";
|
||||
G4Exception("G4RootNtupleManager::FillNtupleTColumn()",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto icolumn = ntuple->columns()[index];
|
||||
auto column = dynamic_cast<tools::wroot::base_pntuple::column_string* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4RootNtupleManager:FillNtupleColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("done fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4RootPNtupleManager::FillNtupleTColumn(
|
||||
G4int ntupleId, G4int columnId, const T& value)
|
||||
{
|
||||
if ( fState.GetIsActivation() && ( ! GetActivation(ntupleId) ) ) {
|
||||
G4cout << "Skipping FillNtupleIColumn for " << ntupleId << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
// 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::wroot::base_pntuple::column<T>* >(icolumn);
|
||||
if ( ! column ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " Column type does not match: "
|
||||
<< " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
G4Exception("G4TNtupleManager:FillNtupleTColumn",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
column->fill(value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId
|
||||
<< " columnId " << columnId << " value " << value;
|
||||
fState.GetVerboseL4()->Message("done fill", "pntuple T column", description);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4RootPNtupleManager::FillNtupleTColumn(G4int columnId, const T& value) {
|
||||
return FillNtupleTColumn(0, columnId, value);
|
||||
}
|
||||
@@ -49,6 +49,8 @@ class G4RootRFileManager : public G4BaseFileManager
|
||||
explicit G4RootRFileManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4RootRFileManager();
|
||||
|
||||
virtual G4String GetFileType() const final { return "Root"; }
|
||||
|
||||
// Methods to manipulate input files
|
||||
virtual G4bool OpenRFile(const G4String& fileName,
|
||||
G4bool isPerThread);
|
||||
|
||||
@@ -12,11 +12,17 @@ geant4_define_module(NAME G4root
|
||||
G4RootAnalysisManager.icc
|
||||
G4RootAnalysisReader.hh
|
||||
G4RootAnalysisReader.icc
|
||||
G4RootFileDef.hh
|
||||
G4RootFileManager.hh
|
||||
G4RootHnFileManager.hh
|
||||
G4RootHnFileManager.icc
|
||||
G4RootMainNtupleManager.hh
|
||||
G4RootNtupleFileManager.hh
|
||||
G4RootNtupleManager.hh
|
||||
G4RootNtupleManager.icc
|
||||
G4RootPNtupleDescription.hh
|
||||
G4RootPNtupleManager.hh
|
||||
G4RootPNtupleManager.icc
|
||||
G4RootRFileManager.hh
|
||||
G4RootRNtupleManager.hh
|
||||
g4root_defs.hh
|
||||
@@ -26,6 +32,7 @@ geant4_define_module(NAME G4root
|
||||
G4RootAnalysisReader.cc
|
||||
G4RootFileManager.cc
|
||||
G4RootMainNtupleManager.cc
|
||||
G4RootNtupleFileManager.cc
|
||||
G4RootNtupleManager.cc
|
||||
G4RootPNtupleManager.cc
|
||||
G4RootRFileManager.cc
|
||||
|
||||
@@ -28,11 +28,10 @@
|
||||
|
||||
#include "G4RootAnalysisManager.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4RootNtupleManager.hh"
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
#include "G4RootPNtupleManager.hh"
|
||||
#include "G4RootNtupleFileManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
@@ -40,6 +39,8 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace G4Analysis;
|
||||
|
||||
// mutex in a file scope
|
||||
|
||||
namespace {
|
||||
@@ -78,13 +79,8 @@ G4bool G4RootAnalysisManager::IsInstance()
|
||||
//_____________________________________________________________________________
|
||||
G4RootAnalysisManager::G4RootAnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("Root", isMaster),
|
||||
fNofNtupleFiles(0),
|
||||
fNtupleRowWise(false),
|
||||
fNtupleRowMode(true),
|
||||
fNtupleMergeMode(G4NtupleMergeMode::kNone),
|
||||
fNtupleManager(nullptr),
|
||||
fSlaveNtupleManager(nullptr),
|
||||
fFileManager(nullptr)
|
||||
fFileManager(nullptr),
|
||||
fNtupleFileManager(nullptr)
|
||||
{
|
||||
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
@@ -104,14 +100,10 @@ G4RootAnalysisManager::G4RootAnalysisManager(G4bool isMaster)
|
||||
fFileManager->SetBasketSize(fgkDefaultBasketSize);
|
||||
fFileManager->SetBasketEntries(fgkDefaultBasketEntries);
|
||||
|
||||
// Do not merge ntuples by default
|
||||
// Merging may require user code migration as analysis manager
|
||||
// must be created both on master and workers.
|
||||
auto mergeNtuples = false;
|
||||
SetNtupleMergingMode(mergeNtuples, fNofNtupleFiles);
|
||||
|
||||
// Create ntuple managers
|
||||
CreateNtupleManagers();
|
||||
// Ntuple file manager
|
||||
fNtupleFileManager = std::make_shared<G4RootNtupleFileManager>(fState);
|
||||
fNtupleFileManager->SetFileManager(fFileManager);
|
||||
fNtupleFileManager->SetBookingManager(fNtupleBookingManager);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -125,190 +117,6 @@ G4RootAnalysisManager::~G4RootAnalysisManager()
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootAnalysisManager::SetNtupleMergingMode(G4bool mergeNtuples,
|
||||
G4int nofNtupleFiles)
|
||||
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("set", "ntuple merging mode", "");
|
||||
#endif
|
||||
|
||||
auto canMerge = true;
|
||||
|
||||
// Illegal situations
|
||||
if ( mergeNtuples && ( ! G4Threading::IsMultithreadedApplication() ) ) {
|
||||
if ( nofNtupleFiles > 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "Merging ntuples is not applicable in sequential application."
|
||||
<< G4endl
|
||||
<< " " << "Setting was ignored.";
|
||||
G4Exception("G4RootAnalysisManager::SetNtupleMergingMode()",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
}
|
||||
canMerge = false;
|
||||
}
|
||||
|
||||
// Illegal situations
|
||||
if ( mergeNtuples && G4Threading::IsMultithreadedApplication() &&
|
||||
( ! fgMasterInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "Merging ntuples requires G4AnalysisManager instance on master."
|
||||
<< G4endl
|
||||
<< " " << "Setting was ignored.";
|
||||
G4Exception("G4RootAnalysisManager::SetNtupleMergingMode()",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
canMerge = false;
|
||||
}
|
||||
|
||||
G4String mergingMode;
|
||||
if ( ( ! mergeNtuples ) || ( ! canMerge ) ) {
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kNone;
|
||||
mergingMode = "G4NtupleMergeMode::kNone";
|
||||
}
|
||||
else {
|
||||
// Set the number of reduced ntuple files
|
||||
fNofNtupleFiles = nofNtupleFiles;
|
||||
|
||||
// Check the number of reduced ntuple files
|
||||
// if ( fNofNtupleFiles < 0 || fNofNtupleFiles > nofThreads ) {
|
||||
if ( fNofNtupleFiles < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "Number of reduced files must be [0, nofThreads]."
|
||||
<< G4endl
|
||||
<< " " << "Cannot set " << nofNtupleFiles
|
||||
// << " files when nofThreads is " << nofThreads << G4endl
|
||||
<< " files" << G4endl
|
||||
<< " " << "Ntuples will be merged in a single file.";
|
||||
G4Exception("G4RootAnalysisManager::SetNtupleMergingMode()",
|
||||
"Analysis_W013", JustWarning, description);
|
||||
fNofNtupleFiles = 0;
|
||||
}
|
||||
|
||||
// if ( fNofNtupleFiles == nofThreads ) {
|
||||
// // add warning that no merging will be applied
|
||||
// fNtupleMergeMode = G4NtupleMergeMode::kNone;
|
||||
// fNofNtupleFiles = 0;
|
||||
// mergingMode = "G4NtupleMergeMode::kNone";
|
||||
// }
|
||||
// else {
|
||||
// G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
// if ( isMaster ) {
|
||||
// fNtupleMergeMode = G4NtupleMergeMode::kMain;
|
||||
// mergingMode = "G4NtupleMergeMode::kMain";
|
||||
// } else {
|
||||
// fNtupleMergeMode = G4NtupleMergeMode::kSlave;
|
||||
// mergingMode = "G4NtupleMergeMode::kSlave";
|
||||
// }
|
||||
// }
|
||||
|
||||
// Forced merging mode
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
if ( isMaster ) {
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kMain;
|
||||
mergingMode = "G4NtupleMergeMode::kMain";
|
||||
} else {
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kSlave;
|
||||
mergingMode = "G4NtupleMergeMode::kSlave";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()
|
||||
->Message("set", "ntuple merging mode", mergingMode);
|
||||
#endif
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootAnalysisManager::ClearNtupleManagers()
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("clear", "ntuple managers", "");
|
||||
#endif
|
||||
|
||||
if ( fNtupleMergeMode != G4NtupleMergeMode::kSlave ) {
|
||||
// Do not reset master ntuple manager
|
||||
delete fNtupleManager;
|
||||
fNtupleManager = nullptr;
|
||||
// SetNtupleManager(fNtupleManager);
|
||||
}
|
||||
|
||||
delete fSlaveNtupleManager;
|
||||
fSlaveNtupleManager = nullptr;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()->Message("clear", "ntuple managers", "");
|
||||
#endif
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootAnalysisManager::CreateNtupleManagers()
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "ntuple managers", "");
|
||||
#endif
|
||||
|
||||
switch ( fNtupleMergeMode )
|
||||
{
|
||||
case G4NtupleMergeMode::kNone:
|
||||
fNtupleManager = new G4RootNtupleManager(fState, 0, fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
SetNtupleManager(fNtupleManager);
|
||||
break;
|
||||
|
||||
case G4NtupleMergeMode::kMain: {
|
||||
G4int nofMainManagers = fNofNtupleFiles;
|
||||
if ( ! nofMainManagers ) nofMainManagers = 1;
|
||||
// create one manager if merging required into the histos & profiles files
|
||||
fNtupleManager
|
||||
= new G4RootNtupleManager(fState, nofMainManagers, fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
SetNtupleManager(fNtupleManager);
|
||||
break;
|
||||
}
|
||||
|
||||
case G4NtupleMergeMode::kSlave:
|
||||
fNtupleManager = fgMasterInstance->fNtupleManager;
|
||||
// The master class is used only in Get* functions
|
||||
auto mainNtupleManager
|
||||
= fNtupleManager->GetMainNtupleManager(GetNtupleFileNumber());
|
||||
fSlaveNtupleManager
|
||||
= new G4RootPNtupleManager(mainNtupleManager, fState, fNtupleRowWise, fNtupleRowMode);
|
||||
SetNtupleManager(fSlaveNtupleManager);
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()->Message("create", "ntuple managers", "");
|
||||
#endif
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootAnalysisManager::GetNtupleFileNumber()
|
||||
{
|
||||
if ( ! fNofNtupleFiles ) return 0;
|
||||
|
||||
G4int nofMainManagers = fNofNtupleFiles;
|
||||
if ( ! nofMainManagers ) nofMainManagers = 1;
|
||||
|
||||
// Debug - check G4Threading::GetNumberOfRunningWorkerThreads()
|
||||
G4cout << "In GetNtupleFileNumber: "
|
||||
<< G4Threading::GetNumberOfRunningWorkerThreads() << G4endl;
|
||||
|
||||
auto fileNumber = G4Threading::G4GetThreadId() % nofMainManagers;
|
||||
return fileNumber;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootAnalysisManager::WriteH1()
|
||||
{
|
||||
@@ -320,8 +128,7 @@ G4bool G4RootAnalysisManager::WriteH1()
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
result = WriteT(h1Vector, hnVector, directory, "h1");
|
||||
result = WriteT(h1Vector, hnVector, "h1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
@@ -345,8 +152,7 @@ G4bool G4RootAnalysisManager::WriteH2()
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
result = WriteT(h2Vector, hnVector, directory, "h2");
|
||||
result = WriteT(h2Vector, hnVector, "h2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
@@ -370,8 +176,7 @@ G4bool G4RootAnalysisManager::WriteH3()
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
result = WriteT(h3Vector, hnVector, directory, "h3");
|
||||
result = WriteT(h3Vector, hnVector, "h3");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
@@ -395,8 +200,7 @@ G4bool G4RootAnalysisManager::WriteP1()
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
result = WriteT(p1Vector, hnVector, directory, "p1");
|
||||
result = WriteT(p1Vector, hnVector, "p1");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
@@ -420,8 +224,7 @@ G4bool G4RootAnalysisManager::WriteP2()
|
||||
auto result = true;
|
||||
|
||||
if ( ! G4Threading::IsWorkerThread() ) {
|
||||
auto directory = fFileManager->GetHistoDirectory();
|
||||
result = WriteT(p2Vector, hnVector, directory, "p2");
|
||||
result = WriteT(p2Vector, hnVector, "p2");
|
||||
}
|
||||
else {
|
||||
// The worker manager just adds its histograms to the master
|
||||
@@ -434,56 +237,6 @@ G4bool G4RootAnalysisManager::WriteP2()
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootAnalysisManager::WriteNtuple()
|
||||
{
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) return true;
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
G4String ntupleType;
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) ntupleType = "main ntuples";
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) ntupleType = "slave ntuples";
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("merge", ntupleType, "");
|
||||
#endif
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
auto result = fNtupleManager->Merge();
|
||||
finalResult = result && finalResult;
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
|
||||
auto result = fSlaveNtupleManager->Merge();
|
||||
finalResult = result && finalResult;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("merge", ntupleType, "");
|
||||
#endif
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootAnalysisManager::ResetNtuple()
|
||||
{
|
||||
// Reset histograms and ntuple
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ||
|
||||
fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
auto result = fNtupleManager->Reset(false);
|
||||
finalResult = result && finalResult;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootAnalysisManager::Reset()
|
||||
{
|
||||
@@ -494,7 +247,7 @@ G4bool G4RootAnalysisManager::Reset()
|
||||
auto result = G4ToolsAnalysisManager::Reset();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
result = ResetNtuple();
|
||||
result = fNtupleFileManager->Reset();
|
||||
finalResult = result && finalResult;
|
||||
|
||||
return finalResult;
|
||||
@@ -507,67 +260,36 @@ G4bool G4RootAnalysisManager::Reset()
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
{
|
||||
// Create ntuple manager(s)
|
||||
// and set it to base class which takes then their ownership
|
||||
SetNtupleManager(fNtupleFileManager->CreateNtupleManager());
|
||||
|
||||
auto finalResult = true;
|
||||
auto result = fFileManager->SetFileName(fileName);
|
||||
|
||||
// Open file
|
||||
if ( fNtupleFileManager->GetMergeMode() != G4NtupleMergeMode::kSlave ) {
|
||||
auto result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
// Open ntuple file(s) and create ntuples from bookings
|
||||
auto result = fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
G4String name = fFileManager->GetFullFileName();
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("open", "analysis file", name);
|
||||
#endif
|
||||
|
||||
result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
fNtupleManager->SetNtupleDirectory(fFileManager->GetNtupleDirectory());
|
||||
|
||||
fNtupleManager->CreateNtuplesFromBooking();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("open", "analysis file", name, finalResult);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
G4String name = fFileManager->GetFullFileName();
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("open", "main analysis file", name);
|
||||
#endif
|
||||
|
||||
fFileManager->SetNofNtupleFiles(fNofNtupleFiles);
|
||||
result = fFileManager->OpenFile(fileName);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
fNtupleManager->CreateNtuplesFromBooking();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("open", "main analysis file", name, finalResult);
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
|
||||
G4cout << "Going to create slave ntuples from main" << G4endl;
|
||||
// No file is open by Slave manager
|
||||
fSlaveNtupleManager->CreateNtuplesFromMain();
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootAnalysisManager::WriteImpl()
|
||||
{
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("write", "files", "");
|
||||
#endif
|
||||
|
||||
if ( ! fgMasterInstance &&
|
||||
( ( ! fH1Manager->IsEmpty() ) || ( ! fH2Manager->IsEmpty() ) ||
|
||||
( ! fH3Manager->IsEmpty() ) || ( ! fP1Manager->IsEmpty() ) ||
|
||||
@@ -602,12 +324,13 @@ G4bool G4RootAnalysisManager::WriteImpl()
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// Ntuples
|
||||
result = WriteNtuple();
|
||||
result = fNtupleFileManager->ActionAtWrite();
|
||||
finalResult = finalResult && result;
|
||||
|
||||
// File
|
||||
if ( fNtupleMergeMode != G4NtupleMergeMode::kSlave ) {
|
||||
result = fFileManager->WriteFile();
|
||||
if ( fNtupleFileManager->GetMergeMode() != G4NtupleMergeMode::kSlave ) {
|
||||
// write all open files
|
||||
result = fFileManager->WriteFiles();
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
@@ -617,6 +340,12 @@ G4bool G4RootAnalysisManager::WriteImpl()
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("write", "files", "", finalResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
@@ -625,46 +354,51 @@ G4bool G4RootAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
G4bool isNtupleManagerEmpty = fNtupleManager->IsEmpty();
|
||||
// the ntuple decription vector is cleared on Reset()
|
||||
// in kNoMergeAfterOpen ntuple manager mode
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("close", "files", "");
|
||||
#endif
|
||||
|
||||
auto result = true;
|
||||
if ( reset ) {
|
||||
result = Reset();
|
||||
} else {
|
||||
// ntuple must be reset
|
||||
result = ResetNtuple();
|
||||
}
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4RootAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4RootAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
}
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
|
||||
if ( fNtupleMergeMode != G4NtupleMergeMode::kSlave ) {
|
||||
// close file
|
||||
fFileManager->CloseFile();
|
||||
result = fNtupleFileManager->ActionAtCloseFile(reset);
|
||||
finalResult = finalResult && result;
|
||||
|
||||
if ( fNtupleFileManager->GetMergeMode() != G4NtupleMergeMode::kSlave ) {
|
||||
// close all open files
|
||||
result = fFileManager->CloseFiles();
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
// No files clean-up in sequential mode
|
||||
if ( ! G4Threading::IsMultithreadedApplication() ) return finalResult;
|
||||
|
||||
G4bool isNtupleManagerEmpty = fNtupleBookingManager->IsEmpty();
|
||||
|
||||
// Delete files if empty in MT mode
|
||||
if ( ( fState.GetIsMaster() &&
|
||||
fH1Manager->IsEmpty() && fH2Manager->IsEmpty() && fH3Manager->IsEmpty() &&
|
||||
fP1Manager->IsEmpty() && fP2Manager->IsEmpty() && isNtupleManagerEmpty ) ||
|
||||
( ( ! fState.GetIsMaster() ) && isNtupleManagerEmpty &&
|
||||
fNtupleMergeMode == G4NtupleMergeMode::kNone ) ) {
|
||||
fNtupleFileManager->GetMergeMode() == G4NtupleMergeMode::kNone ) ) {
|
||||
|
||||
result = ! std::remove(fFileManager->GetFullFileName());
|
||||
// std::remove returns 0 when success
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Removing file "
|
||||
<< fFileManager->GetFullFileName() << " failed";
|
||||
G4Exception("G4XmlAnalysisManager::CloseFile()",
|
||||
G4Exception("G4RootAnalysisManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
@@ -674,6 +408,13 @@ G4bool G4RootAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
->Message("delete", "empty file", fFileManager->GetFullFileName());
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()
|
||||
->Message("close", "files", "");
|
||||
#endif
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
@@ -685,53 +426,14 @@ G4bool G4RootAnalysisManager::CloseFileImpl(G4bool reset)
|
||||
//_____________________________________________________________________________
|
||||
void G4RootAnalysisManager::SetNtupleMerging(G4bool mergeNtuples,
|
||||
G4int nofNtupleFiles)
|
||||
|
||||
{
|
||||
// Set ntuple merging mode
|
||||
SetNtupleMergingMode(mergeNtuples, nofNtupleFiles);
|
||||
|
||||
// Clear existing managers
|
||||
ClearNtupleManagers();
|
||||
|
||||
// Re-create managers
|
||||
CreateNtupleManagers();
|
||||
fNtupleFileManager->SetNtupleMerging(mergeNtuples, nofNtupleFiles);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootAnalysisManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
// Print info even when setting makes no effect
|
||||
// (as we do not get printed the default setting in the output)
|
||||
G4String rowWiseMode;
|
||||
if ( rowWise ) {
|
||||
rowWiseMode = "row-wise with extra branch";
|
||||
}
|
||||
else if ( rowMode ) {
|
||||
rowWiseMode = "row-wise";
|
||||
}
|
||||
else {
|
||||
rowWiseMode = "column-wise";
|
||||
}
|
||||
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("set", "ntuple merging row mode", rowWiseMode);
|
||||
#endif
|
||||
|
||||
// Do nothing if the mode is not changed
|
||||
if ( fNtupleRowWise == rowWise && fNtupleRowMode == rowMode ) return;
|
||||
|
||||
fNtupleRowWise = rowWise;
|
||||
fNtupleRowMode = rowMode;
|
||||
|
||||
if ( fNtupleManager ) {
|
||||
fNtupleManager->SetNtupleRowWise(rowWise, rowMode);
|
||||
}
|
||||
|
||||
if ( fSlaveNtupleManager ) {
|
||||
fSlaveNtupleManager->SetNtupleRowWise(rowWise, rowMode);
|
||||
}
|
||||
fNtupleFileManager->SetNtupleRowWise(rowWise, rowMode);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
|
||||
@@ -27,29 +27,33 @@
|
||||
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4RootHnFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/wroot/file"
|
||||
#include "tools/wroot/to"
|
||||
#include "tools/zlib"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace tools;
|
||||
using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootFileManager::G4RootFileManager(const G4AnalysisManagerState& state)
|
||||
: G4VFileManager(state),
|
||||
fFile(nullptr),
|
||||
fHistoDirectory(nullptr),
|
||||
fNtupleDirectory(nullptr),
|
||||
fNofNtupleFiles(0),
|
||||
fNtupleFiles(),
|
||||
fMainNtupleDirectories(),
|
||||
: G4VTFileManager<G4RootFile>(state),
|
||||
fBasketSize(0),
|
||||
fBasketEntries(0)
|
||||
{}
|
||||
{
|
||||
// Create helpers defined in the base class
|
||||
fH1FileManager = std::make_shared<G4RootHnFileManager<histo::h1d>>(this);
|
||||
fH2FileManager = std::make_shared<G4RootHnFileManager<histo::h2d>>(this);
|
||||
fH3FileManager = std::make_shared<G4RootHnFileManager<histo::h3d>>(this);
|
||||
fP1FileManager = std::make_shared<G4RootHnFileManager<histo::p1d>>(this);
|
||||
fP2FileManager = std::make_shared<G4RootHnFileManager<histo::p2d>>(this);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootFileManager::~G4RootFileManager()
|
||||
@@ -60,294 +64,222 @@ G4RootFileManager::~G4RootFileManager()
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::OpenNtupleFiles()
|
||||
tools::wroot::directory* G4RootFileManager::CreateDirectory(
|
||||
std::shared_ptr<tools::wroot::file> rfile,
|
||||
#ifdef G4VERBOSE
|
||||
const G4String& directoryName, const G4String& objectType) const
|
||||
#else
|
||||
const G4String& directoryName, const G4String& /*objectType*/) const
|
||||
#endif
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
for ( auto i = 0; i < fNofNtupleFiles; i++ ) {
|
||||
|
||||
auto name = GetNtupleFileName(i);
|
||||
if ( ! rfile ) return nullptr;
|
||||
|
||||
if ( directoryName == "" ) {
|
||||
// Do not create a new directory if its name is not set
|
||||
return &(rfile->dir());
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("create", "main ntuple file", name);
|
||||
->Message("create", "directory for " + objectType, directoryName);
|
||||
#endif
|
||||
|
||||
// create new file
|
||||
auto rfile = std::make_shared<tools::wroot::file>(G4cout, name);
|
||||
rfile->add_ziper('Z', tools::compress_buffer);
|
||||
rfile->set_compression(fState.GetCompressionLevel());
|
||||
|
||||
if ( ! rfile->is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << name;
|
||||
G4Exception("G4RootAnalysisManager::OpenFile()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
finalResult = false;
|
||||
}
|
||||
|
||||
// Do not create directory if extra ntuple files
|
||||
// auto result = CreateNtupleDirectory(rfile);
|
||||
// finalResult = finalResult && result;
|
||||
tools::wroot::directory* directory = &rfile->dir();
|
||||
if ( fNtupleDirectoryName != "" ) {
|
||||
directory = rfile->dir().mkdir(fNtupleDirectoryName);
|
||||
if ( ! directory ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot create directory " << fNtupleDirectoryName;
|
||||
G4Exception("G4RootFileManager::OpenNtupleFiles()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
directory = &fFile->dir();
|
||||
}
|
||||
}
|
||||
|
||||
fNtupleFiles.push_back(rfile);
|
||||
fMainNtupleDirectories.push_back(directory);
|
||||
|
||||
|
||||
auto directory = rfile->dir().mkdir(directoryName);
|
||||
if ( ! directory ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot create directory " << directoryName;
|
||||
G4Exception("G4RootFileManager::CreateDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("create", "main ntuple file", name);
|
||||
else {
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()
|
||||
->Message("create", "directory for " + objectType, directoryName);
|
||||
}
|
||||
#endif
|
||||
return directory;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4String G4RootFileManager::GetNtupleFileName(
|
||||
RootNtupleDescription* ntupleDescription,
|
||||
G4bool perThread,
|
||||
G4int mainNumber) const
|
||||
{
|
||||
// get ntuple file name
|
||||
|
||||
auto ntupleFileName = ntupleDescription->fFileName;
|
||||
if ( ntupleFileName.size() ) {
|
||||
if ( perThread ) {
|
||||
ntupleFileName = GetTnFileName(ntupleFileName, GetFileType());
|
||||
}
|
||||
} else {
|
||||
// get default file name
|
||||
ntupleFileName = GetFullFileName(fFileName, perThread);
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
// update filename per mainNumber
|
||||
if ( mainNumber > -1 ) {
|
||||
// update filename per mainNumber
|
||||
ntupleFileName
|
||||
= G4Analysis::GetNtupleFileName(ntupleFileName, GetFileType(), mainNumber);
|
||||
}
|
||||
|
||||
return ntupleFileName;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::WriteFile(std::shared_ptr<tools::wroot::file> rfile,
|
||||
#ifdef G4VERBOSE
|
||||
const G4String& fileName)
|
||||
#else
|
||||
const G4String& /*fileName*/)
|
||||
#endif
|
||||
{
|
||||
// Do nothing if there is no file
|
||||
if ( ! fIsOpenFile ) return true;
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("write", "file", fileName);
|
||||
#endif
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4RootFile>
|
||||
G4RootFileManager::CreateFileImpl(const G4String& fileName)
|
||||
{
|
||||
// create file
|
||||
std::shared_ptr<wroot::file> file = std::make_shared<wroot::file>(G4cout, fileName);
|
||||
file->add_ziper('Z',compress_buffer);
|
||||
file->set_compression(fState.GetCompressionLevel());
|
||||
|
||||
if ( ! file->is_open() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot create file " << fileName;
|
||||
G4Exception("G4RootFileManager::CreateFileImpl()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// create histo directory
|
||||
tools::wroot::directory* hdirectory
|
||||
= CreateDirectory(file, fHistoDirectoryName, "histograms");
|
||||
if ( ! hdirectory ) {
|
||||
// Warning is issued in CreateDirectory
|
||||
return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// create ntuple directory
|
||||
tools::wroot::directory* ndirectory
|
||||
= CreateDirectory(file, fNtupleDirectoryName, "ntuples");
|
||||
if ( ! ndirectory ) {
|
||||
// Warning is issued in CreateDirectory
|
||||
return std::make_shared<G4RootFile>(nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
return std::make_shared<G4RootFile>(file, hdirectory, ndirectory);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::WriteFileImpl(std::shared_ptr<G4RootFile> file)
|
||||
{
|
||||
// New prototype: called by G4TFileManager base classe
|
||||
|
||||
if ( ! file ) return false;
|
||||
|
||||
unsigned int n;
|
||||
auto result = rfile->write(n);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("write", "file", fileName, result);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
return std::get<0>(*file)->write(n);
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::CloseFile(std::shared_ptr<tools::wroot::file> rfile,
|
||||
#ifdef G4VERBOSE
|
||||
const G4String& fileName)
|
||||
#else
|
||||
const G4String& /*fileName*/)
|
||||
#endif
|
||||
G4bool G4RootFileManager::CloseFileImpl(std::shared_ptr<G4RootFile> file)
|
||||
{
|
||||
// Do nothing if there is no file
|
||||
if ( ! fIsOpenFile ) return true;
|
||||
// New prototype: called by G4TFileManager base classe
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("close", "file", fileName);
|
||||
#endif
|
||||
if ( ! file ) return false;
|
||||
|
||||
rfile->close();
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("close", "file", fileName, true);
|
||||
#endif
|
||||
// close file
|
||||
std::get<0>(*file)->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::OpenFile(const G4String& fileName)
|
||||
{
|
||||
// Open default file
|
||||
|
||||
// Keep file name
|
||||
fFileName = fileName;
|
||||
auto name = GetFullFileName();
|
||||
|
||||
// delete previous file if exists
|
||||
//if ( fFile ) delete fFile;
|
||||
|
||||
// create new file
|
||||
fFile = std::make_shared<tools::wroot::file>(G4cout, name);
|
||||
fFile->add_ziper('Z',tools::compress_buffer);
|
||||
fFile->set_compression(fState.GetCompressionLevel());
|
||||
|
||||
if ( ! fFile->is_open() ) {
|
||||
fFile = nullptr;
|
||||
if ( fFile ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Cannot open file " << fileName;
|
||||
G4Exception("G4RootAnalysisManager::OpenFile()",
|
||||
description << "File " << fileName << " already exists.";
|
||||
G4Exception("G4RootFileManager::OpenFile()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
fFile.reset();
|
||||
}
|
||||
|
||||
// Create file (and save in in the file map)
|
||||
fFile = CreateTFile(name);
|
||||
if ( ! fFile ) {
|
||||
G4ExceptionDescription description;
|
||||
description << "Failed to create file " << fileName;
|
||||
G4Exception("G4RootFileManager::OpenFile()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create directories
|
||||
if ( ! CreateHistoDirectory() ) return false;
|
||||
if ( ! CreateNtupleDirectory() ) return false;
|
||||
|
||||
// Open ntuple files
|
||||
OpenNtupleFiles();
|
||||
|
||||
fLockFileName = true;
|
||||
fLockHistoDirectoryName = true;
|
||||
fLockNtupleDirectoryName = true;
|
||||
|
||||
fIsOpenFile = true;
|
||||
fLockDirectoryNames = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager:: WriteFile()
|
||||
std::shared_ptr<G4RootFile> G4RootFileManager::CreateNtupleFile(
|
||||
RootNtupleDescription* ntupleDescription, G4int mainNumber)
|
||||
{
|
||||
// get ntuple file name per object
|
||||
auto perThread = true;
|
||||
auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
|
||||
|
||||
auto file = GetTFile(ntupleFileName, false);
|
||||
if (! file) {
|
||||
file = CreateTFile(ntupleFileName);
|
||||
}
|
||||
|
||||
// register file in ntuple description only if it is not main ntuple file
|
||||
// (main ntuple files are managed in main ntuple manager)
|
||||
if ( mainNumber == -1 ) {
|
||||
ntupleDescription->fFile = file;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4RootFile> G4RootFileManager::GetNtupleFile(
|
||||
RootNtupleDescription* ntupleDescription, G4bool perThread, G4int mainNumber) const
|
||||
{
|
||||
// get ntuple file name per object
|
||||
auto ntupleFileName = GetNtupleFileName(ntupleDescription, perThread, mainNumber);
|
||||
|
||||
return GetTFile(ntupleFileName, false);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::CloseNtupleFile(
|
||||
RootNtupleDescription* ntupleDescription)
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = WriteFile(fFile, GetFullFileName());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
auto counter = 0;
|
||||
for ( auto ntupleFile : fNtupleFiles ) {
|
||||
result = WriteFile(ntupleFile, GetNtupleFileName(counter++));
|
||||
finalResult = finalResult && result;
|
||||
if ( ntupleDescription->fFile ) {
|
||||
// Ntuple files are registered in file manager map.
|
||||
// they will be closed with CloseFiles() calls
|
||||
ntupleDescription->fFile.reset();
|
||||
// Notify not empty file
|
||||
auto ntupleFileName = GetNtupleFileName(ntupleDescription);
|
||||
auto result = SetIsEmpty(ntupleFileName, ! ntupleDescription->fHasFill);
|
||||
finalResult = result && finalResult;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::CloseFile()
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
auto result = CloseFile(fFile, GetFullFileName());
|
||||
finalResult = finalResult && result;
|
||||
|
||||
auto counter = 0;
|
||||
for ( auto ntupleFile : fNtupleFiles ) {
|
||||
result = CloseFile(ntupleFile, GetNtupleFileName(counter++));
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
fLockFileName = false;
|
||||
fIsOpenFile = false;
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::CreateHistoDirectory()
|
||||
{
|
||||
if ( fHistoDirectoryName == "" ) {
|
||||
// Do not create a new directory if its name is not set
|
||||
fHistoDirectory = &(fFile->dir());
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("create", "directory for histograms", fHistoDirectoryName);
|
||||
#endif
|
||||
|
||||
fHistoDirectory = fFile->dir().mkdir(fHistoDirectoryName);
|
||||
if ( ! fHistoDirectory ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot create directory " << fHistoDirectoryName;
|
||||
G4Exception("G4RootFileManager::CreateHistoDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
else {
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()
|
||||
->Message("create", "directory for histograms", fHistoDirectoryName);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootFileManager::CreateNtupleDirectory()
|
||||
{
|
||||
if ( fNtupleDirectoryName == "" ) {
|
||||
// Do not create a new directory if its name is not set
|
||||
fNtupleDirectory = &(fFile->dir());
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("create", "directory for ntuples", fNtupleDirectoryName);
|
||||
#endif
|
||||
|
||||
fNtupleDirectory = fFile->dir().mkdir(fNtupleDirectoryName);
|
||||
if ( ! fNtupleDirectory ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "cannot create directory " << fNtupleDirectoryName;
|
||||
G4Exception("G4RootFileManager::CreateNtupleDirectory()",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
else {
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()
|
||||
->Message("create", "directory for ntuples", fNtupleDirectoryName);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<tools::wroot::file>
|
||||
G4RootFileManager::GetNtupleFile(G4int index) const
|
||||
{
|
||||
if ( index==0 && ( ! fNtupleFiles.size() ) ) return fFile;
|
||||
|
||||
if ( index < 0 || index >= G4int(fNtupleFiles.size()) ) {
|
||||
G4String inFunction = "G4RootFileManager::GetNtupleFile()";
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntuple file " << index << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fNtupleFiles[index];
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::wroot::directory*
|
||||
G4RootFileManager::GetMainNtupleDirectory(G4int index) const
|
||||
{
|
||||
if ( index==0 && ( ! fMainNtupleDirectories.size() ) ) return fNtupleDirectory;
|
||||
|
||||
if ( index < 0 || index >= G4int(fMainNtupleDirectories.size()) ) {
|
||||
G4String inFunction = "G4RootFileManager::GetMainNtupleDirectory()";
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "main ntuple directory " << index << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fMainNtupleDirectories[index];
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4RootNtupleManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
@@ -34,14 +35,20 @@
|
||||
#include "tools/wroot/ntuple"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMainNtupleManager::G4RootMainNtupleManager(G4RootNtupleManager* ntupleBuilder,
|
||||
G4bool rowWise,
|
||||
const G4AnalysisManagerState& state)
|
||||
G4RootMainNtupleManager::G4RootMainNtupleManager(
|
||||
G4RootNtupleManager* ntupleBuilder,
|
||||
G4NtupleBookingManager* bookingManager,
|
||||
G4bool rowWise,
|
||||
G4int fileNumber,
|
||||
const G4AnalysisManagerState& state)
|
||||
: G4BaseAnalysisManager(state),
|
||||
fNtupleBuilder(ntupleBuilder),
|
||||
fBookingManager(bookingManager),
|
||||
fFileManager(nullptr),
|
||||
fRowWise(rowWise),
|
||||
fNtupleDirectory(nullptr),
|
||||
fNtupleVector()
|
||||
fFileNumber(fileNumber),
|
||||
fNtupleVector(),
|
||||
fNtupleDescriptionVector()
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -55,25 +62,28 @@ G4RootMainNtupleManager::~G4RootMainNtupleManager()
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMainNtupleManager::CreateNtuple(const tools::ntuple_booking& ntupleBooking,
|
||||
void G4RootMainNtupleManager::CreateNtuple(RootNtupleDescription* ntupleDescription,
|
||||
G4bool warn)
|
||||
{
|
||||
// Create ntuple from booking if file was open
|
||||
|
||||
// Check that file is set
|
||||
if ( ! fNtupleDirectory ) {
|
||||
// Get/Create main ntuple file
|
||||
auto ntupleFile = fFileManager->CreateNtupleFile(ntupleDescription, fFileNumber);
|
||||
if ( ! ntupleFile ) {
|
||||
if ( warn ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "Ntuple file must be defined first."
|
||||
<< G4endl
|
||||
<< " " << "Cannot create main ntuples from builder.";
|
||||
G4Exception("G4RootAnalysisManager::CreateNtuplesFromBooking",
|
||||
<< "Ntuple file must be defined first." << G4endl
|
||||
<< "Cannot create main ntuple.";
|
||||
G4Exception("G4RootMainAnalysisManager::CreateNtuple",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Get ntuple booking
|
||||
auto ntupleBooking = ntupleDescription->fNtupleBooking;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
@@ -81,12 +91,13 @@ void G4RootMainNtupleManager::CreateNtuple(const tools::ntuple_booking& ntupleBo
|
||||
#endif
|
||||
|
||||
// Create ntuple
|
||||
auto ntuple = new tools::wroot::ntuple(*fNtupleDirectory, ntupleBooking, fRowWise);
|
||||
auto ntuple = new tools::wroot::ntuple(*std::get<2>(*ntupleFile), ntupleBooking, fRowWise);
|
||||
// ntuple object is deleted automatically when closing a file
|
||||
auto basketSize = fNtupleBuilder->GetBasketSize();
|
||||
ntuple->set_basket_size(basketSize);
|
||||
|
||||
fNtupleVector.push_back(ntuple);
|
||||
fNtupleDescriptionVector.push_back(ntupleDescription);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
@@ -95,36 +106,20 @@ void G4RootMainNtupleManager::CreateNtuple(const tools::ntuple_booking& ntupleBo
|
||||
#endif
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootMainNtupleManager::CreateNtuplesFromBooking()
|
||||
{
|
||||
// Create ntuple from booking in master
|
||||
|
||||
// Check that file is set
|
||||
if ( ! fNtupleDirectory ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " " << "Ntuple file must be defined first."
|
||||
<< G4endl
|
||||
<< " " << "Cannot create main ntuples from builder.";
|
||||
G4Exception("G4RootAnalysisManager::CreateNtuplesFromBooking",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
auto& ntupleDescriptionVector
|
||||
= fNtupleBuilder->GetNtupleDescriptionVector();
|
||||
|
||||
for ( auto ntupleDescription : ntupleDescriptionVector ) {
|
||||
CreateNtuple(ntupleDescription->fNtupleBooking);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootMainNtupleManager::Merge()
|
||||
{
|
||||
std::size_t counter = 0;
|
||||
|
||||
for ( auto ntuple : fNtupleVector ) {
|
||||
ntuple->merge_number_of_entries();
|
||||
|
||||
// Notify ntuple description that file is not empty
|
||||
if ( ntuple->entries() ) {
|
||||
auto ntupleDescription = fNtupleDescriptionVector.at(counter);
|
||||
ntupleDescription->fHasFill = true;
|
||||
}
|
||||
++counter;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -140,6 +135,15 @@ G4bool G4RootMainNtupleManager::Reset(G4bool deleteNtuple)
|
||||
}
|
||||
|
||||
fNtupleVector.clear();
|
||||
fNtupleDescriptionVector.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4RootFile>
|
||||
G4RootMainNtupleManager::GetNtupleFile(RootNtupleDescription* ntupleDescription) const
|
||||
{
|
||||
auto perThread = false;
|
||||
return fFileManager->GetNtupleFile(ntupleDescription, perThread, fFileNumber);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,460 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 15/09/2020 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootNtupleFileManager.hh"
|
||||
#include "G4RootFileManager.hh"
|
||||
#include "G4RootNtupleManager.hh"
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
#include "G4RootPNtupleManager.hh"
|
||||
#include "G4VAnalysisManager.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
namespace {
|
||||
|
||||
void MergingException(const G4String& functionName,
|
||||
G4ExceptionDescription& description)
|
||||
{
|
||||
G4String inFunction = "G4RootNtupleFileManager::" + functionName;
|
||||
G4Exception(inFunction, "Analysis_W013", JustWarning, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using namespace G4Analysis;
|
||||
using std::make_shared;
|
||||
|
||||
G4RootNtupleFileManager* G4RootNtupleFileManager::fgMasterInstance = nullptr;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootNtupleFileManager::G4RootNtupleFileManager(const G4AnalysisManagerState& state)
|
||||
: G4VNtupleFileManager(state, "root"),
|
||||
fIsInitialized(false),
|
||||
fNofNtupleFiles(0),
|
||||
fNtupleRowWise(false),
|
||||
fNtupleRowMode(true),
|
||||
fNtupleMergeMode(G4NtupleMergeMode::kNone),
|
||||
fNtupleManager(nullptr),
|
||||
fSlaveNtupleManager(nullptr),
|
||||
fFileManager(nullptr)
|
||||
{
|
||||
if ( G4Threading::IsMasterThread() && fgMasterInstance ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "G4RootNtupleFileManager already exists."
|
||||
<< "Cannot create another instance.";
|
||||
G4Exception("G4RootNtupleFileManager::G4RootNtupleFileManager()",
|
||||
"Analysis_F001", FatalException, description);
|
||||
}
|
||||
if ( G4Threading::IsMasterThread() ) fgMasterInstance = this;
|
||||
|
||||
// Do not merge ntuples by default
|
||||
// Merging may require user code migration as analysis manager
|
||||
// must be created both on master and workers.
|
||||
auto mergeNtuples = false;
|
||||
SetNtupleMergingMode(mergeNtuples, fNofNtupleFiles);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootNtupleFileManager::~G4RootNtupleFileManager()
|
||||
{
|
||||
if ( fState.GetIsMaster() ) fgMasterInstance = nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleFileManager::SetNtupleMergingMode(G4bool mergeNtuples,
|
||||
G4int nofNtupleFiles)
|
||||
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()->Message("set", "ntuple merging mode", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
auto canMerge = true;
|
||||
|
||||
// Illegal situations
|
||||
if ( mergeNtuples && ( ! G4Threading::IsMultithreadedApplication() ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Merging ntuples is not applicable in sequential application." << G4endl
|
||||
<< "Setting was ignored.";
|
||||
MergingException("SetNtupleMergingMode", description);
|
||||
canMerge = false;
|
||||
}
|
||||
|
||||
// Illegal situations
|
||||
if ( mergeNtuples && G4Threading::IsMultithreadedApplication() &&
|
||||
( ! fgMasterInstance ) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Merging ntuples requires G4AnalysisManager instance on master." << G4endl
|
||||
<< "Setting was ignored.";
|
||||
MergingException("SetNtupleMergingMode", description);
|
||||
canMerge = false;
|
||||
}
|
||||
|
||||
G4String mergingMode;
|
||||
if ( ( ! mergeNtuples ) || ( ! canMerge ) ) {
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kNone;
|
||||
mergingMode = "G4NtupleMergeMode::kNone";
|
||||
}
|
||||
else {
|
||||
// Set the number of reduced ntuple files
|
||||
fNofNtupleFiles = nofNtupleFiles;
|
||||
|
||||
// Check the number of reduced ntuple files
|
||||
if ( fNofNtupleFiles < 0 ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Number of reduced files must be [0, nofThreads]." << G4endl
|
||||
<< "Cannot set " << nofNtupleFiles << " files" << G4endl
|
||||
<< "Ntuples will be merged in a single file.";
|
||||
MergingException("SetNtupleMergingMode", description);
|
||||
fNofNtupleFiles = 0;
|
||||
}
|
||||
|
||||
// Forced merging mode
|
||||
G4bool isMaster = ! G4Threading::IsWorkerThread();
|
||||
if ( isMaster ) {
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kMain;
|
||||
mergingMode = "G4NtupleMergeMode::kMain";
|
||||
} else {
|
||||
fNtupleMergeMode = G4NtupleMergeMode::kSlave;
|
||||
mergingMode = "G4NtupleMergeMode::kSlave";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
fState.GetVerboseL2()->Message("set", "ntuple merging mode", mergingMode);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootNtupleFileManager::GetNtupleFileNumber()
|
||||
{
|
||||
if ( ! fNofNtupleFiles ) return 0;
|
||||
|
||||
G4int nofMainManagers = fNofNtupleFiles;
|
||||
if ( ! nofMainManagers ) nofMainManagers = 1;
|
||||
|
||||
auto fileNumber = G4Threading::G4GetThreadId() % nofMainManagers;
|
||||
return fileNumber;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootNtupleFileManager::CloseNtupleFiles()
|
||||
{
|
||||
// Close ntuple files
|
||||
|
||||
auto finalResult = true;
|
||||
auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
|
||||
for ( auto ntupleDescription : ntupleVector) {
|
||||
auto result = fFileManager->CloseNtupleFile(ntupleDescription);
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleFileManager::SetNtupleMerging(G4bool mergeNtuples,
|
||||
G4int nofNtupleFiles)
|
||||
|
||||
{
|
||||
if ( fIsInitialized ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot change merging mode." << G4endl
|
||||
<< "The function must be called before OpenFile().";
|
||||
MergingException("SetNtupleMerging", description);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set ntuple merging mode
|
||||
SetNtupleMergingMode(mergeNtuples, nofNtupleFiles);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleFileManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
// Print info even when setting makes no effect
|
||||
// (as we do not get printed the default setting in the output)
|
||||
G4String rowWiseMode;
|
||||
if ( rowWise ) {
|
||||
rowWiseMode = "row-wise with extra branch";
|
||||
}
|
||||
else if ( rowMode ) {
|
||||
rowWiseMode = "row-wise";
|
||||
}
|
||||
else {
|
||||
rowWiseMode = "column-wise";
|
||||
}
|
||||
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()
|
||||
->Message("set", "ntuple merging row mode", rowWiseMode);
|
||||
#endif
|
||||
|
||||
// Do nothing if the mode is not changed
|
||||
if ( fNtupleRowWise == rowWise && fNtupleRowMode == rowMode ) return;
|
||||
|
||||
fNtupleRowWise = rowWise;
|
||||
fNtupleRowMode = rowMode;
|
||||
|
||||
if ( fNtupleManager ) {
|
||||
fNtupleManager->SetNtupleRowWise(rowWise, rowMode);
|
||||
}
|
||||
|
||||
if ( fSlaveNtupleManager ) {
|
||||
fSlaveNtupleManager->SetNtupleRowWise(rowWise, rowMode);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleFileManager::SetBasketSize(unsigned int basketSize)
|
||||
{
|
||||
fFileManager->SetBasketSize(basketSize);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleFileManager::SetBasketEntries(unsigned int basketEntries)
|
||||
{
|
||||
fFileManager->SetBasketEntries(basketEntries);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4VNtupleManager> G4RootNtupleFileManager::CreateNtupleManager()
|
||||
{
|
||||
// Create and return ntuple manager.
|
||||
// If ntuple merging is activated, managers of different types are created
|
||||
// on master/worker.
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "ntuple manager", "");
|
||||
#endif
|
||||
|
||||
// Check that file manager and anaysis manager are set !
|
||||
|
||||
std::shared_ptr<G4VNtupleManager> activeNtupleManager = nullptr;
|
||||
switch ( fNtupleMergeMode )
|
||||
{
|
||||
case G4NtupleMergeMode::kNone:
|
||||
fNtupleManager
|
||||
= make_shared<G4RootNtupleManager>(
|
||||
fState, fBookingManager, 0, 0, fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
activeNtupleManager = fNtupleManager;
|
||||
break;
|
||||
|
||||
case G4NtupleMergeMode::kMain: {
|
||||
G4int nofMainManagers = fNofNtupleFiles;
|
||||
if ( ! nofMainManagers ) nofMainManagers = 1;
|
||||
// create one manager if merging required into the histos & profiles files
|
||||
fNtupleManager
|
||||
= make_shared<G4RootNtupleManager>(
|
||||
fState, fBookingManager, nofMainManagers, fNofNtupleFiles, fNtupleRowWise, fNtupleRowMode);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
activeNtupleManager = fNtupleManager;
|
||||
break;
|
||||
}
|
||||
|
||||
case G4NtupleMergeMode::kSlave:
|
||||
fNtupleManager = fgMasterInstance->fNtupleManager;
|
||||
// The master class is used only in Get* functions
|
||||
auto mainNtupleManager
|
||||
= fNtupleManager->GetMainNtupleManager(GetNtupleFileNumber());
|
||||
fSlaveNtupleManager
|
||||
= make_shared<G4RootPNtupleManager>(
|
||||
fState, fgMasterInstance->fBookingManager, mainNtupleManager, fNtupleRowWise, fNtupleRowMode);
|
||||
activeNtupleManager = fSlaveNtupleManager;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
G4String mergeMode;
|
||||
switch ( fNtupleMergeMode ) {
|
||||
case G4NtupleMergeMode::kNone:
|
||||
mergeMode = "";
|
||||
break;
|
||||
case G4NtupleMergeMode::kMain:
|
||||
mergeMode = "main ";
|
||||
break;
|
||||
case G4NtupleMergeMode::kSlave:
|
||||
mergeMode = "slave ";
|
||||
break;
|
||||
}
|
||||
fState.GetVerboseL3()->Message("create", mergeMode + "ntuple manager", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
fIsInitialized = true;
|
||||
|
||||
return activeNtupleManager;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
#ifdef G4VERBOSE
|
||||
G4bool G4RootNtupleFileManager::ActionAtOpenFile(const G4String& fileName)
|
||||
#else
|
||||
G4bool G4RootNtupleFileManager::ActionAtOpenFile(const G4String& /*fileName*/)
|
||||
#endif
|
||||
{
|
||||
// Check if fNtupleBookingManager is set
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ||
|
||||
fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
G4String objectType = "analysis file";
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
objectType = "main analysis file";
|
||||
}
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("open", objectType, fileName);
|
||||
#endif
|
||||
|
||||
// Creating files is triggered from CreateNtuple
|
||||
fNtupleManager->CreateNtuplesFromBooking(
|
||||
fBookingManager->GetNtupleBookingVector());
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() ) {
|
||||
fState.GetVerboseL1()->Message("open", objectType, fileName, finalResult);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
|
||||
// G4cout << "Going to create slave ntuples from main" << G4endl;
|
||||
fSlaveNtupleManager->CreateNtuplesFromMain();
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootNtupleFileManager::ActionAtWrite()
|
||||
{
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
G4String ntupleType;
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) ntupleType = "main ntuples";
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) ntupleType = "slave ntuples";
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("merge", ntupleType, "");
|
||||
#endif
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
auto result = fNtupleManager->Merge();
|
||||
finalResult = result && finalResult;
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
|
||||
auto result = fSlaveNtupleManager->Merge();
|
||||
finalResult = result && finalResult;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL1() )
|
||||
fState.GetVerboseL1()->Message("merge", ntupleType, "");
|
||||
#endif
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootNtupleFileManager::ActionAtCloseFile(G4bool reset)
|
||||
{
|
||||
auto finalResult = true;
|
||||
|
||||
// close files
|
||||
if ( fNtupleMergeMode != G4NtupleMergeMode::kSlave ) {
|
||||
auto result = CloseNtupleFiles();
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
if ( ! reset ) {
|
||||
// The ntuples must be always reset when closing file)
|
||||
auto result = Reset();
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Resetting data failed";
|
||||
G4Exception("G4RootNtupleFileManager::CloseFile()",
|
||||
"Analysis_W021", JustWarning, description);
|
||||
}
|
||||
finalResult = finalResult && result;
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootNtupleFileManager::Reset()
|
||||
{
|
||||
// Reset ntuples
|
||||
|
||||
auto result = true;
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kNone ||
|
||||
fNtupleMergeMode == G4NtupleMergeMode::kMain ) {
|
||||
result = fNtupleManager->Reset(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -38,19 +38,25 @@ using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootNtupleManager::G4RootNtupleManager(const G4AnalysisManagerState& state,
|
||||
G4int nofMainManagers,
|
||||
G4bool rowWise, G4bool rowMode)
|
||||
: G4TNtupleManager<tools::wroot::ntuple>(state),
|
||||
fCreateMode(G4NtupleCreateMode::kUndefined),
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManger,
|
||||
G4int nofMainManagers, G4int nofFiles,
|
||||
G4bool rowWise, G4bool rowMode)
|
||||
: G4TNtupleManager<tools::wroot::ntuple, G4RootFile>(state),
|
||||
fFileManager(nullptr),
|
||||
fNtupleDirectory(nullptr),
|
||||
fMainNtupleManagers(),
|
||||
fNtupleFile(nullptr),
|
||||
fRowWise(rowWise),
|
||||
fRowMode(rowMode)
|
||||
{
|
||||
for ( G4int i=0; i<nofMainManagers; ++i) {
|
||||
auto fileNumber = i;
|
||||
if ( (i == 0) && (nofFiles == 0) ) {
|
||||
// the main ntuple file will be merged in the default file
|
||||
fileNumber = -1;
|
||||
}
|
||||
fMainNtupleManagers.push_back(
|
||||
new G4RootMainNtupleManager(this, rowWise, fState));
|
||||
std::make_shared<G4RootMainNtupleManager>(
|
||||
this, bookingManger.get(), rowWise, fileNumber, fState));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,161 +68,65 @@ G4RootNtupleManager::~G4RootNtupleManager()
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleManager::SetCreateMode()
|
||||
{
|
||||
// Set create mode if not yet defined, or reset it if ntuples are defined both
|
||||
// before and after open file
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("set", "ntuple create mode", "");
|
||||
#endif
|
||||
|
||||
G4String createMode;
|
||||
if ( fCreateMode == G4NtupleCreateMode::kUndefined ) {
|
||||
if ( fMainNtupleManagers.size() ) {
|
||||
if ( fFileManager->GetNtupleFile(0) ) {
|
||||
fCreateMode = G4NtupleCreateMode::kMainAfterOpen;
|
||||
createMode = "G4NtupleCreateMode::kMainAfterOpen";
|
||||
} else {
|
||||
fCreateMode = G4NtupleCreateMode::kMainBeforeOpen;
|
||||
createMode = "G4NtupleCreateMode::kMainBeforeOpen";
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( fNtupleDirectory ) {
|
||||
fCreateMode = G4NtupleCreateMode::kNoMergeAfterOpen;
|
||||
createMode = "G4NtupleCreateMode::kNoMergeAfterOpen";
|
||||
} else {
|
||||
fCreateMode = G4NtupleCreateMode::kNoMergeBeforeOpen;
|
||||
createMode = "G4NtupleCreateMode::kNoMergeBeforeOpen";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( fCreateMode == G4NtupleCreateMode::kNoMergeBeforeOpen &&
|
||||
fFileManager->GetNtupleFile(0) ) {
|
||||
fCreateMode = G4NtupleCreateMode::kNoMergeAfterOpen;
|
||||
createMode = "G4NtupleCreateMode::kNoMergeAfterOpen";
|
||||
}
|
||||
|
||||
if ( fCreateMode == G4NtupleCreateMode::kMainBeforeOpen &&
|
||||
fFileManager->GetNtupleFile(0) ) {
|
||||
fCreateMode = G4NtupleCreateMode::kMainAfterOpen;
|
||||
createMode = "G4NtupleCreateMode::kMainAfterOpen";
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() )
|
||||
fState.GetVerboseL2()
|
||||
->Message("set", "ntuple create mode", createMode);
|
||||
#endif
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
|
||||
{
|
||||
// Set rowWise mode and propagate it to main ntuple managers
|
||||
|
||||
fRowWise = rowWise;
|
||||
fRowMode = rowMode;
|
||||
|
||||
for (auto& mainNtupleManager : fMainNtupleManagers ) {
|
||||
mainNtupleManager->SetRowWise(rowWise);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleManager::CreateTNtuple(
|
||||
G4TNtupleDescription<tools::wroot::ntuple>* ntupleDescription)
|
||||
{
|
||||
if ( ! fNtupleDirectory ) {
|
||||
G4String inFunction = "G4RootNtupleManager::::CreateTNtuple";
|
||||
G4ExceptionDescription description;
|
||||
description << " "
|
||||
<< "Cannot create ntuple. Ntuple directory does not exist." << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W002", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
ntupleDescription->fNtuple
|
||||
= new tools::wroot::ntuple(
|
||||
*fNtupleDirectory, ntupleDescription->fNtupleBooking, fRowWise);
|
||||
|
||||
auto basketSize = fFileManager->GetBasketSize();
|
||||
ntupleDescription->fNtuple->set_basket_size(basketSize);
|
||||
|
||||
ntupleDescription->fIsNtupleOwner = false;
|
||||
// ntuple object is deleted automatically when closing a file
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleManager::CreateTNtupleFromBooking(
|
||||
G4TNtupleDescription<tools::wroot::ntuple>* ntupleDescription)
|
||||
RootNtupleDescription* ntupleDescription)
|
||||
{
|
||||
if ( fCreateMode == G4NtupleCreateMode::kNoMergeBeforeOpen ) {
|
||||
if ( ! fMainNtupleManagers.size() ) {
|
||||
// No merging
|
||||
if ( ntupleDescription->fNtuple ) {
|
||||
G4String inFunction = "G4RootNtupleManager::::CreateTNtupleFromBooking";
|
||||
G4ExceptionDescription description;
|
||||
description << "Cannot create ntuple. Ntuple already exists." << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W002", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
CreateTNtuple(ntupleDescription);
|
||||
}
|
||||
|
||||
if ( fCreateMode == G4NtupleCreateMode::kMainBeforeOpen ) {
|
||||
auto counter = 0;
|
||||
// Create ntuple file from ntuple description
|
||||
auto ntupleFile = fFileManager->CreateNtupleFile(ntupleDescription);
|
||||
if ( ! ntupleFile ) {
|
||||
G4String inFunction = "G4RootNtupleManager::::CreateTNtupleFromBooking";
|
||||
G4ExceptionDescription description;
|
||||
description << "Cannot create ntuple. Ntuple file does not exist." << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W002", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
auto directory = std::get<2>(*ntupleFile);
|
||||
ntupleDescription->fNtuple
|
||||
= new tools::wroot::ntuple(
|
||||
*directory, ntupleDescription->fNtupleBooking, fRowWise);
|
||||
|
||||
auto basketSize = fFileManager->GetBasketSize();
|
||||
ntupleDescription->fNtuple->set_basket_size(basketSize);
|
||||
|
||||
ntupleDescription->fIsNtupleOwner = false;
|
||||
// ntuple object is deleted automatically when closing a file
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
}
|
||||
else {
|
||||
// Merging activated
|
||||
for ( auto manager : fMainNtupleManagers ) {
|
||||
if ( ! manager->GetNtupleVector().size() ) {
|
||||
// Create only once !!
|
||||
manager->SetNtupleFile(fFileManager->GetNtupleFile(counter));
|
||||
manager->SetNtupleDirectory(fFileManager->GetMainNtupleDirectory(counter++));
|
||||
manager->CreateNtuplesFromBooking();
|
||||
}
|
||||
manager->CreateNtuple(ntupleDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleManager::FinishTNtuple(
|
||||
G4TNtupleDescription<tools::wroot::ntuple>* ntupleDescription,
|
||||
G4bool fromBooking)
|
||||
RootNtupleDescription* /*ntupleDescription*/, G4bool /*fromBooking*/)
|
||||
{
|
||||
// Create main ntuples
|
||||
|
||||
// Set create mode if not yet defined
|
||||
if ( ! fromBooking ) {
|
||||
SetCreateMode();
|
||||
}
|
||||
|
||||
// Create ntuple if file is open
|
||||
if ( fCreateMode == G4NtupleCreateMode::kNoMergeAfterOpen ) {
|
||||
CreateTNtuple(ntupleDescription);
|
||||
}
|
||||
|
||||
// Create main ntuples if file is open
|
||||
if ( fCreateMode == G4NtupleCreateMode::kMainAfterOpen ) {
|
||||
auto counter = 0;
|
||||
for ( auto manager : fMainNtupleManagers ) {
|
||||
auto warn = true;
|
||||
manager->SetNtupleFile(fFileManager->GetNtupleFile(counter));
|
||||
manager->SetNtupleDirectory(fFileManager->GetMainNtupleDirectory(counter++));
|
||||
manager->CreateNtuple(ntupleDescription->fNtupleBooking, warn);
|
||||
}
|
||||
}
|
||||
// nothing to be done
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootNtupleManager::Reset(G4bool deleteNtuple)
|
||||
{
|
||||
G4TNtupleManager<tools::wroot::ntuple> ::Reset(deleteNtuple);
|
||||
G4TNtupleManager<tools::wroot::ntuple, G4RootFile> ::Reset(deleteNtuple);
|
||||
// this will clear ntuple vector
|
||||
|
||||
if ( fCreateMode == G4NtupleCreateMode::kNoMergeAfterOpen ) {
|
||||
// clear also ntuple description vector
|
||||
fNtupleDescriptionVector.clear();
|
||||
}
|
||||
|
||||
auto finalResult = true;
|
||||
|
||||
for ( auto manager : fMainNtupleManagers ) {
|
||||
auto result = manager->Reset(false);
|
||||
finalResult = result && finalResult;
|
||||
@@ -239,7 +149,31 @@ G4bool G4RootNtupleManager::Merge()
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMainNtupleManager* G4RootNtupleManager::GetMainNtupleManager(G4int index) const
|
||||
void G4RootNtupleManager::SetFileManager(std::shared_ptr<G4RootFileManager> fileManager)
|
||||
{
|
||||
fFileManager = fileManager;
|
||||
|
||||
for ( auto mainNtupleManager : fMainNtupleManagers) {
|
||||
mainNtupleManager->SetFileManager(fileManager);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
|
||||
{
|
||||
// Set rowWise mode and propagate it to main ntuple managers
|
||||
|
||||
fRowWise = rowWise;
|
||||
fRowMode = rowMode;
|
||||
|
||||
for (auto& mainNtupleManager : fMainNtupleManagers ) {
|
||||
mainNtupleManager->SetRowWise(rowWise);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
std::shared_ptr<G4RootMainNtupleManager>
|
||||
G4RootNtupleManager::GetMainNtupleManager(G4int index) const
|
||||
{
|
||||
if ( index < 0 || index >= G4int(fMainNtupleManagers.size()) ) {
|
||||
G4String inFunction = "G4RootNtupleManager::::GetMainNtupleManager";
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 04/10/2016 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4NtupleBookingManager.hh"
|
||||
#include "G4RootPNtupleManager.hh"
|
||||
#include "G4RootMainNtupleManager.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
@@ -35,17 +36,31 @@
|
||||
|
||||
// mutex in a file scope
|
||||
namespace {
|
||||
//Mutex to lock master manager when adding ntuple row and ending fill
|
||||
G4Mutex pntupleMutex = G4MUTEX_INITIALIZER;
|
||||
|
||||
//Mutex to lock master manager when adding ntuple row and ending fill
|
||||
G4Mutex pntupleMutex = G4MUTEX_INITIALIZER;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void NotExistException(const G4String& what, G4int id, const G4String& functionName)
|
||||
{
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << what << " id= " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootPNtupleManager::G4RootPNtupleManager(G4RootMainNtupleManager* main,
|
||||
const G4AnalysisManagerState& state,
|
||||
G4bool rowWise, G4bool rowMode)
|
||||
G4RootPNtupleManager::G4RootPNtupleManager(const G4AnalysisManagerState& state,
|
||||
std::shared_ptr<G4NtupleBookingManager> bookingManger,
|
||||
std::shared_ptr<G4RootMainNtupleManager> main,
|
||||
G4bool rowWise, G4bool rowMode)
|
||||
: G4BaseNtupleManager(state),
|
||||
fCreateMode(G4PNtupleCreateMode::kUndefined),
|
||||
fBookingManager(bookingManger),
|
||||
fMainNtupleManager(main),
|
||||
fNtupleDescriptionVector(),
|
||||
fNtupleVector(),
|
||||
fRowWise(rowWise),
|
||||
fRowMode(rowMode)
|
||||
@@ -71,11 +86,7 @@ G4RootPNtupleManager::GetNtupleDescriptionInFunction(
|
||||
auto index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(fNtupleDescriptionVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntuple " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
NotExistException("ntuple description", id, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -93,11 +104,7 @@ tools::wroot::base_pntuple*
|
||||
|
||||
if ( ! ntupleDescription->fBasePNtuple ) {
|
||||
if ( warn ) {
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntupleId " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
NotExistException("ntuple", id, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -109,17 +116,12 @@ tools::wroot::ntuple*
|
||||
G4RootPNtupleManager::GetMainNtupleInFunction(
|
||||
G4int id, G4String functionName, G4bool warn) const
|
||||
{
|
||||
auto& mainNtupleVector
|
||||
= fMainNtupleManager->GetNtupleVector();
|
||||
|
||||
auto& mainNtupleVector = fMainNtupleManager->GetNtupleVector();
|
||||
|
||||
auto index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(mainNtupleVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "main ntuple " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_W011", JustWarning, description);
|
||||
NotExistException("main ntuple", id, functionName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -127,28 +129,38 @@ G4RootPNtupleManager::GetMainNtupleInFunction(
|
||||
return mainNtupleVector[index];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// protected functions
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescription,
|
||||
tools::wroot::ntuple* mainNtuple)
|
||||
void G4RootPNtupleManager::CreateNtupleFromMain(
|
||||
G4RootPNtupleDescription* ntupleDescription,
|
||||
tools::wroot::ntuple* mainNtuple)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()
|
||||
->Message("create from main", "pntuple", mainNtuple->name());
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()
|
||||
->Message("create from main", "pntuple", mainNtuple->name());
|
||||
}
|
||||
#endif
|
||||
|
||||
auto rfile = fMainNtupleManager->GetNtupleFile();
|
||||
// auto directory = fMainNtupleManager->GetNtupleDirectory();
|
||||
auto file = fMainNtupleManager->GetNtupleFile(&ntupleDescription->fDescription);
|
||||
if ( ! file ) {
|
||||
G4String inFunction = "G4RootPNtupleManager::::CreateNtupleFromMain";
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< "Cannot create pntuple. Main ntuple file does not exist." << G4endl;
|
||||
G4Exception(inFunction, "Analysis_W002", JustWarning, description);
|
||||
return;
|
||||
}
|
||||
|
||||
ntupleDescription->fDescription.fFile = file;
|
||||
|
||||
// Get parameters from ntupleDescription
|
||||
ntupleDescription->fFile = rfile.get();
|
||||
mainNtuple->get_branches(ntupleDescription->fMainBranches);
|
||||
|
||||
auto rfile = std::get<0>(*file);
|
||||
G4bool verbose = true;
|
||||
if ( fRowWise ) {
|
||||
auto mainBranch = mainNtuple->get_row_wise_branch();
|
||||
@@ -157,7 +169,7 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
G4cout, rfile->byte_swap(), rfile->compression(),
|
||||
mainNtuple->dir().seek_directory(),
|
||||
*mainBranch, mainBranch->basket_size(),
|
||||
ntupleDescription->fNtupleBooking, verbose);
|
||||
ntupleDescription->fDescription.fNtupleBooking, verbose);
|
||||
|
||||
ntupleDescription->fNtuple
|
||||
= static_cast<tools::wroot::imt_ntuple*>(mtNtuple);
|
||||
@@ -176,7 +188,7 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
G4cout, rfile->byte_swap(), rfile->compression(),
|
||||
mainNtuple->dir().seek_directory(),
|
||||
ntupleDescription->fMainBranches, basketSizes,
|
||||
ntupleDescription->fNtupleBooking,
|
||||
ntupleDescription->fDescription.fNtupleBooking,
|
||||
fRowMode, basketEntries, verbose);
|
||||
|
||||
ntupleDescription->fNtuple
|
||||
@@ -185,15 +197,15 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
= static_cast<tools::wroot::base_pntuple*>(mtNtuple);
|
||||
}
|
||||
|
||||
ntupleDescription->fIsNtupleOwner = true;
|
||||
ntupleDescription->fDescription.fIsNtupleOwner = true;
|
||||
// // pntuple object is not deleted automatically
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()
|
||||
->Message("create from main", "pntuple", mainNtuple->name());
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()
|
||||
->Message("create from main", "pntuple", mainNtuple->name());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -201,125 +213,34 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
void G4RootPNtupleManager::CreateNtuplesFromMain()
|
||||
{
|
||||
// Create ntuple from booking (if not yet done) and main ntuple
|
||||
// This function is called from G4AnalysisManager::OpenFile.
|
||||
// This function is called from G4RootNtupleFileManager::ActionAtOpenFile.
|
||||
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kUndefined ) {
|
||||
if ( fNtupleDescriptionVector.size() ) {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveBeforeOpen;
|
||||
// G4cout << "Create mode: kSlaveBeforeOpen" << G4endl;
|
||||
} else {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveAfterOpen;
|
||||
// G4cout << "Create mode: kSlaveAfterOpen" << G4endl;
|
||||
}
|
||||
// Create pntuple descriptions from ntuple booking.
|
||||
auto g4NtupleBookings = fBookingManager->GetNtupleBookingVector();
|
||||
for ( auto g4NtupleBooking : g4NtupleBookings ) {
|
||||
auto ntupleDescription = new G4RootPNtupleDescription(g4NtupleBooking);
|
||||
// Save g4booking, activation in pntuple booking
|
||||
fNtupleDescriptionVector.push_back(ntupleDescription);
|
||||
}
|
||||
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kSlaveAfterOpen ) {
|
||||
// ntuples are not yet booked
|
||||
// G4cout << "Ntuples are not yet booked ?" << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto& mainNtupleVector
|
||||
= fMainNtupleManager->GetNtupleVector();
|
||||
auto& mainNtupleVector = fMainNtupleManager->GetNtupleVector();
|
||||
|
||||
G4int lcounter = 0;
|
||||
for ( auto mainNtuple : mainNtupleVector ) {
|
||||
|
||||
auto& ntupleDescription
|
||||
= fNtupleDescriptionVector[lcounter++];
|
||||
CreateNtuple(ntupleDescription, mainNtuple);
|
||||
for ( auto mainNtuple : mainNtupleVector ) {
|
||||
auto& ntupleDescription = fNtupleDescriptionVector[lcounter++];
|
||||
CreateNtupleFromMain(ntupleDescription, mainNtuple);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtuple(
|
||||
const G4String& name, const G4String& title)
|
||||
G4int G4RootPNtupleManager::CreateNtuple(G4NtupleBooking* /*booking*/)
|
||||
{
|
||||
// Create pntuple description with ntuple_booking
|
||||
// Create pntuple from g4 ntuple booking.
|
||||
// Nothing to be done here.
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() )
|
||||
fState.GetVerboseL4()->Message("create", "pntuple booking", name);
|
||||
#endif
|
||||
|
||||
// Set create mode if not yet defined
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kUndefined ) {
|
||||
if ( fMainNtupleManager->GetNtupleFile() ) {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveAfterOpen;
|
||||
} else {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveBeforeOpen;
|
||||
}
|
||||
}
|
||||
|
||||
// Create ntuple description
|
||||
auto index = fNtupleDescriptionVector.size();
|
||||
auto ntupleDescription = new G4RootPNtupleDescription();
|
||||
fNtupleDescriptionVector.push_back(ntupleDescription);
|
||||
|
||||
// Save name & title in ntuple booking
|
||||
ntupleDescription->fNtupleBooking.set_name(name);
|
||||
ntupleDescription->fNtupleBooking.set_title(title);
|
||||
|
||||
fLockFirstId = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << name << " ntupleId " << index + fFirstId;
|
||||
fState.GetVerboseL2()->Message("create", "pntuple booking", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
return index + fFirstId;
|
||||
return G4Analysis::kInvalidId;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleIColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<int>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<int>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleFColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<float>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<float>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleDColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<double>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<double>(ntupleId, name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleSColumn(
|
||||
G4int ntupleId, const G4String& name)
|
||||
{
|
||||
return CreateNtupleTColumn<std::string>(ntupleId, name, nullptr);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootPNtupleManager::FinishNtuple(G4int ntupleId)
|
||||
{
|
||||
// create ntuple if file was open
|
||||
|
||||
// if ( fMainNtupleManager->GetNtupleFile() ) {
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kSlaveAfterOpen ) {
|
||||
auto ntupleDescription
|
||||
= GetNtupleDescriptionInFunction(ntupleId, "FinishNtuple");
|
||||
if ( ! ntupleDescription ) return;
|
||||
|
||||
auto mainNtuple = GetMainNtupleInFunction(ntupleId, "FinishNtuple");
|
||||
if ( ! mainNtuple ) return;
|
||||
|
||||
CreateNtuple(ntupleDescription, mainNtuple);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::FillNtupleIColumn(
|
||||
G4int ntupleId, G4int columnId, G4int value)
|
||||
@@ -367,20 +288,23 @@ G4bool G4RootPNtupleManager::AddNtupleRow(G4int ntupleId)
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "AddNtupleRow");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
|
||||
|
||||
G4AutoLock lock(&pntupleMutex);
|
||||
lock.unlock();
|
||||
mutex toolsLock(lock);
|
||||
auto result
|
||||
= ntupleDescription->fNtuple
|
||||
->add_row(toolsLock, *ntupleDescription->fFile);
|
||||
= ntupleDescription->fNtuple->add_row(toolsLock, *rfile);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << " ntupleId " << ntupleId
|
||||
<< "adding row has failed.";
|
||||
G4Exception("G4RootPNtupleManager::AddNtupleRow()",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
}
|
||||
"Analysis_W022", JustWarning, description);
|
||||
}
|
||||
|
||||
ntupleDescription->fDescription.fHasFill = true;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
@@ -399,29 +323,32 @@ G4bool G4RootPNtupleManager::Merge()
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector) {
|
||||
|
||||
// skip inactivated ntuples
|
||||
if(!ntupleDescription->fActivation || !ntupleDescription->fNtuple)
|
||||
if(!ntupleDescription->fDescription.fActivation || !ntupleDescription->fNtuple) {
|
||||
// G4cout << "skipping inactive ntuple " << G4endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
fState.GetVerboseL4()
|
||||
->Message("merge", "pntuple", ntupleDescription->fNtupleBooking.name());
|
||||
->Message("merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
|
||||
}
|
||||
#endif
|
||||
|
||||
auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
|
||||
|
||||
G4AutoLock lock(&pntupleMutex);
|
||||
lock.unlock();
|
||||
mutex toolsLock(lock);
|
||||
auto result
|
||||
= ntupleDescription->fNtuple
|
||||
->end_fill(toolsLock, *ntupleDescription->fFile);
|
||||
= ntupleDescription->fNtuple->end_fill(toolsLock, *rfile);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << " ntuple " << ntupleDescription->fNtupleBooking.name()
|
||||
description << " " << " ntuple " << ntupleDescription->fDescription.fNtupleBooking.name()
|
||||
<< "end fill has failed.";
|
||||
G4Exception("G4RootPNtupleManager::Merge()",
|
||||
"Analysis_W002", JustWarning, description);
|
||||
"Analysis_W031", JustWarning, description);
|
||||
}
|
||||
|
||||
delete ntupleDescription->fNtuple;
|
||||
@@ -430,7 +357,7 @@ G4bool G4RootPNtupleManager::Merge()
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() ) {
|
||||
fState.GetVerboseL3()
|
||||
->Message("merge", "pntuple", ntupleDescription->fNtupleBooking.name());
|
||||
->Message("merge", "pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -459,7 +386,7 @@ void G4RootPNtupleManager::SetActivation(
|
||||
G4bool activation)
|
||||
{
|
||||
for ( auto ntupleDescription : fNtupleDescriptionVector ) {
|
||||
ntupleDescription->fActivation = activation;
|
||||
ntupleDescription->fDescription.fActivation = activation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,7 +398,7 @@ void G4RootPNtupleManager::SetActivation(
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "SetActivation");
|
||||
if ( ! ntupleDescription ) return;
|
||||
|
||||
ntupleDescription->fActivation = activation;
|
||||
ntupleDescription->fDescription.fActivation = activation;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -481,7 +408,7 @@ G4bool G4RootPNtupleManager::GetActivation(
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId, "GetActivation");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
return ntupleDescription->fActivation;
|
||||
return ntupleDescription->fDescription.fActivation;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -490,18 +417,6 @@ G4int G4RootPNtupleManager::GetNofNtuples() const
|
||||
return fNtupleVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::GetNofNtupleBookings() const
|
||||
{
|
||||
return fNtupleDescriptionVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::IsEmpty() const
|
||||
{
|
||||
return ! fNtupleDescriptionVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootPNtupleManager::SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "G4RootRFileManager.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
|
||||
#include "tools/rroot/file"
|
||||
#include <tools/zlib>
|
||||
|
||||
Reference in New Issue
Block a user