Import Geant4 10.4.0 source tree
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4RootAnalysisManager.cc 103532 2017-04-13 14:00:35Z gcosmo $
|
||||
// $Id: G4RootAnalysisManager.cc 106985 2017-10-31 10:07:18Z gcosmo $
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
|
||||
@@ -80,6 +80,7 @@ G4bool G4RootAnalysisManager::IsInstance()
|
||||
G4RootAnalysisManager::G4RootAnalysisManager(G4bool isMaster)
|
||||
: G4ToolsAnalysisManager("Root", isMaster),
|
||||
fNofNtupleFiles(0),
|
||||
fNtupleRowWise(true),
|
||||
fNtupleMergeMode(G4NtupleMergeMode::kNone),
|
||||
fNtupleManager(nullptr),
|
||||
fSlaveNtupleManager(nullptr),
|
||||
@@ -268,7 +269,7 @@ void G4RootAnalysisManager::CreateNtupleManagers()
|
||||
G4int nofMainManagers = fNofNtupleFiles;
|
||||
if ( ! nofMainManagers ) nofMainManagers = 1;
|
||||
// create one manager if merging required into the histos & profiles files
|
||||
fNtupleManager = new G4RootNtupleManager(fState, nofMainManagers);
|
||||
fNtupleManager = new G4RootNtupleManager(fState, nofMainManagers, fNtupleRowWise);
|
||||
fNtupleManager->SetFileManager(fFileManager);
|
||||
SetNtupleManager(fNtupleManager);
|
||||
break;
|
||||
@@ -539,6 +540,7 @@ G4bool G4RootAnalysisManager::OpenFileImpl(const G4String& fileName)
|
||||
}
|
||||
|
||||
if ( fNtupleMergeMode == G4NtupleMergeMode::kSlave ) {
|
||||
G4cout << "Going to create slave ntuples from main" << G4endl;
|
||||
// No file is open by Slave manager
|
||||
fSlaveNtupleManager->CreateNtuplesFromMain();
|
||||
}
|
||||
@@ -663,12 +665,14 @@ G4bool G4RootAnalysisManager::CloseFileImpl()
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootAnalysisManager::SetNtupleMerging(G4bool mergeNtuples,
|
||||
G4int nofNtupleFiles,
|
||||
G4int nofNtupleFiles,
|
||||
G4bool rowWise,
|
||||
unsigned int basketSize)
|
||||
|
||||
{
|
||||
// Keep basketSize in file manager
|
||||
fFileManager->SetBasketSize(basketSize);
|
||||
fNtupleRowWise = rowWise;
|
||||
|
||||
// Set ntuple merging mode
|
||||
SetNtupleMergingMode(mergeNtuples, nofNtupleFiles);
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "G4RootAnalysisReader.hh"
|
||||
#include "G4RootRFileManager.hh"
|
||||
#include "G4RootRNtupleManager.hh"
|
||||
#include "G4RootRNtupleDescription.hh"
|
||||
#include "G4AnalysisVerbose.hh"
|
||||
#include "G4AnalysisUtilities.hh"
|
||||
#include "G4Threading.hh"
|
||||
@@ -165,6 +164,7 @@ G4bool G4RootAnalysisReader::Reset()
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootAnalysisReader::ReadH1Impl(const G4String& h1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
@@ -201,6 +201,7 @@ G4int G4RootAnalysisReader::ReadH1Impl(const G4String& h1Name,
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootAnalysisReader::ReadH2Impl(const G4String& h2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
@@ -242,6 +243,7 @@ G4int G4RootAnalysisReader::ReadH2Impl(const G4String& h2Name,
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootAnalysisReader::ReadH3Impl(const G4String& h3Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
|
||||
@@ -283,6 +285,7 @@ G4int G4RootAnalysisReader::ReadH3Impl(const G4String& h3Name,
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootAnalysisReader::ReadP1Impl(const G4String& p1Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
@@ -319,6 +322,7 @@ G4int G4RootAnalysisReader::ReadP1Impl(const G4String& p1Name,
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootAnalysisReader::ReadP2Impl(const G4String& p2Name,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool /*isUserFileName*/)
|
||||
{
|
||||
|
||||
@@ -356,6 +360,7 @@ G4int G4RootAnalysisReader::ReadP2Impl(const G4String& p2Name,
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootAnalysisReader::ReadNtupleImpl(const G4String& ntupleName,
|
||||
const G4String& fileName,
|
||||
const G4String& /*dirName*/,
|
||||
G4bool isUserFileName)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
@@ -402,6 +407,8 @@ G4int G4RootAnalysisReader::ReadNtupleImpl(const G4String& ntupleName,
|
||||
auto buffer
|
||||
= new tools::rroot::buffer(G4cout, rfile->byte_swap(), size, charBuffer,
|
||||
key->key_length(), verbose);
|
||||
buffer->set_map_objs(true);
|
||||
|
||||
auto fac = new tools::rroot::fac(G4cout);
|
||||
|
||||
auto tree = new tools::rroot::tree(*rfile, *fac);
|
||||
@@ -418,10 +425,8 @@ G4int G4RootAnalysisReader::ReadNtupleImpl(const G4String& ntupleName,
|
||||
return kInvalidId;
|
||||
}
|
||||
|
||||
auto rntuple
|
||||
= new tools::rroot::ntuple(*tree); //use the flat ntuple API.
|
||||
auto rntupleDescription
|
||||
= new G4RootRNtupleDescription(rntuple, buffer, fac, tree);
|
||||
auto rntuple = new tools::rroot::ntuple(*tree); //use the flat ntuple API.
|
||||
auto rntupleDescription = new G4TRNtupleDescription<tools::rroot::ntuple>(rntuple);
|
||||
|
||||
auto id = fNtupleManager->SetNtuple(rntupleDescription);
|
||||
|
||||
|
||||
@@ -36,9 +36,11 @@
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootMainNtupleManager::G4RootMainNtupleManager(G4RootNtupleManager* ntupleBuilder,
|
||||
G4bool rowWise,
|
||||
const G4AnalysisManagerState& state)
|
||||
: G4BaseAnalysisManager(state),
|
||||
fNtupleBuilder(ntupleBuilder),
|
||||
fRowWise(rowWise),
|
||||
fNtupleDirectory(nullptr),
|
||||
fNtupleVector()
|
||||
{}
|
||||
@@ -49,10 +51,6 @@ G4RootMainNtupleManager::~G4RootMainNtupleManager()
|
||||
// ntuple objects are deleted automatically when closing a file
|
||||
}
|
||||
|
||||
//
|
||||
// private functions
|
||||
//
|
||||
|
||||
//
|
||||
// protected functions
|
||||
//
|
||||
@@ -84,7 +82,7 @@ void G4RootMainNtupleManager::CreateNtuple(const tools::ntuple_booking& ntupleBo
|
||||
#endif
|
||||
|
||||
// Create ntuple
|
||||
auto ntuple = new tools::wroot::ntuple(*fNtupleDirectory, ntupleBooking);
|
||||
auto ntuple = new tools::wroot::ntuple(*fNtupleDirectory, ntupleBooking, fRowWise);
|
||||
// ntuple object is deleted automatically when closing a file
|
||||
auto basketSize = fNtupleBuilder->GetBasketSize();
|
||||
ntuple->set_basket_size(basketSize);
|
||||
|
||||
@@ -39,7 +39,8 @@ using namespace G4Analysis;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootNtupleManager::G4RootNtupleManager(const G4AnalysisManagerState& state,
|
||||
G4int nofMainManagers)
|
||||
G4int nofMainManagers,
|
||||
G4bool rowWise)
|
||||
: G4TNtupleManager<tools::wroot::ntuple>(state),
|
||||
fCreateMode(G4NtupleCreateMode::kUndefined),
|
||||
fFileManager(nullptr),
|
||||
@@ -48,7 +49,7 @@ G4RootNtupleManager::G4RootNtupleManager(const G4AnalysisManagerState& state,
|
||||
{
|
||||
for ( G4int i=0; i<nofMainManagers; ++i) {
|
||||
fMainNtupleManagers.push_back(
|
||||
new G4RootMainNtupleManager(this, fState));
|
||||
new G4RootMainNtupleManager(this, rowWise, fState));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,29 +102,28 @@ void G4RootNtupleManager::SetCreateMode()
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootNtupleManager::CreateTNtuple(
|
||||
G4TNtupleDescription<tools::wroot::ntuple>* ntupleDescription,
|
||||
const G4String& name, const G4String& title)
|
||||
void G4RootNtupleManager::CreateTNtuple(
|
||||
G4TNtupleDescription<tools::wroot::ntuple>* ntupleDescription)
|
||||
{
|
||||
// Set create mode if not yet defined
|
||||
SetCreateMode();
|
||||
|
||||
if ( fCreateMode == G4NtupleCreateMode::kNoMergeAfterOpen ) {
|
||||
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, name, title);
|
||||
ntupleDescription->fIsNtupleOwner = false;
|
||||
// ntuple object is deleted automatically when closing a file
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -131,28 +131,10 @@ void G4RootNtupleManager::CreateTNtupleFromBooking(
|
||||
G4TNtupleDescription<tools::wroot::ntuple>* ntupleDescription)
|
||||
{
|
||||
if ( fCreateMode == G4NtupleCreateMode::kNoMergeBeforeOpen ) {
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
CreateTNtuple(ntupleDescription);
|
||||
}
|
||||
|
||||
|
||||
if ( fCreateMode == G4NtupleCreateMode::kMainBeforeOpen ) {
|
||||
auto counter = 0;
|
||||
for ( auto manager : fMainNtupleManagers ) {
|
||||
@@ -172,6 +154,15 @@ void G4RootNtupleManager::FinishTNtuple(
|
||||
{
|
||||
// Create main ntuples
|
||||
|
||||
// Set create mode if not yet defined
|
||||
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 ) {
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace {
|
||||
//_____________________________________________________________________________
|
||||
G4RootPNtupleManager::G4RootPNtupleManager(G4RootMainNtupleManager* main,
|
||||
const G4AnalysisManagerState& state)
|
||||
: G4VNtupleManager(state),
|
||||
: G4BaseNtupleManager(state),
|
||||
fCreateMode(G4PNtupleCreateMode::kUndefined),
|
||||
fMainNtupleManager(main),
|
||||
fNtupleVector()
|
||||
@@ -83,13 +83,14 @@ G4RootPNtupleManager::GetNtupleDescriptionInFunction(
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::wroot::pntuple* G4RootPNtupleManager::GetNtupleInFunction(
|
||||
tools::wroot::base_pntuple*
|
||||
G4RootPNtupleManager::GetNtupleInFunction(
|
||||
G4int id, G4String functionName, G4bool warn) const
|
||||
{
|
||||
auto ntupleDescription = GetNtupleDescriptionInFunction(id, functionName);
|
||||
if ( ! ntupleDescription ) return nullptr;
|
||||
|
||||
if ( ! ntupleDescription->fNtuple ) {
|
||||
if ( ! ntupleDescription->fBasePNtuple ) {
|
||||
if ( warn ) {
|
||||
G4String inFunction = "G4RootPNtupleManager::";
|
||||
inFunction += functionName;
|
||||
@@ -99,7 +100,7 @@ tools::wroot::pntuple* G4RootPNtupleManager::GetNtupleInFunction(
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return ntupleDescription->fNtuple;
|
||||
return ntupleDescription->fBasePNtuple;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -141,29 +142,53 @@ void G4RootPNtupleManager::CreateNtuple(G4RootPNtupleDescription* ntupleDescript
|
||||
#endif
|
||||
|
||||
auto rfile = fMainNtupleManager->GetNtupleFile();
|
||||
auto directory = fMainNtupleManager->GetNtupleDirectory();
|
||||
// auto directory = fMainNtupleManager->GetNtupleDirectory();
|
||||
|
||||
// Get parameters from main ntuple
|
||||
auto mainBranch = mainNtuple->get_row_wise_branch();
|
||||
auto rowWise = mainBranch ? true : false;
|
||||
|
||||
ntupleDescription->fFile = rfile.get();
|
||||
mainNtuple->get_branches(ntupleDescription->fMainBranches);
|
||||
|
||||
std::vector<tools::uint32> basketSizes;
|
||||
tools_vforcit(tools::wroot::branch*, ntupleDescription->fMainBranches, it) {
|
||||
basketSizes.push_back((*it)->basket_size());
|
||||
G4bool verbose = true;
|
||||
if ( rowWise ) {
|
||||
tools::wroot::mt_ntuple_row_wise* mtNtuple
|
||||
= new tools::wroot::mt_ntuple_row_wise(
|
||||
G4cout, rfile->byte_swap(), rfile->compression(),
|
||||
mainNtuple->dir().seek_directory(),
|
||||
*mainBranch, mainBranch->basket_size(),
|
||||
ntupleDescription->fNtupleBooking, verbose);
|
||||
|
||||
ntupleDescription->fNtuple
|
||||
= static_cast<tools::wroot::imt_ntuple*>(mtNtuple);
|
||||
ntupleDescription->fBasePNtuple
|
||||
= static_cast<tools::wroot::base_pntuple*>(mtNtuple);
|
||||
}
|
||||
else {
|
||||
std::vector<tools::uint32> basketSizes;
|
||||
tools_vforcit(tools::wroot::branch*, ntupleDescription->fMainBranches, it) {
|
||||
basketSizes.push_back((*it)->basket_size());
|
||||
}
|
||||
|
||||
tools::wroot::mt_ntuple_column_wise* mtNtuple =
|
||||
new tools::wroot::mt_ntuple_column_wise(
|
||||
G4cout, rfile->byte_swap(), rfile->compression(),
|
||||
mainNtuple->dir().seek_directory(),
|
||||
ntupleDescription->fMainBranches, basketSizes,
|
||||
ntupleDescription->fNtupleBooking, verbose);
|
||||
|
||||
ntupleDescription->fNtuple
|
||||
= static_cast<tools::wroot::imt_ntuple*>(mtNtuple);
|
||||
ntupleDescription->fBasePNtuple
|
||||
= static_cast<tools::wroot::base_pntuple*>(mtNtuple);
|
||||
}
|
||||
|
||||
// Create pntuple
|
||||
G4bool verbose = true;
|
||||
ntupleDescription->fNtuple
|
||||
= new tools::wroot::pntuple(
|
||||
G4cout, rfile->byte_swap(), rfile->compression(),
|
||||
directory->seek_directory(), basketSizes,
|
||||
ntupleDescription->fNtupleBooking, verbose);
|
||||
|
||||
ntupleDescription->fIsNtupleOwner = true;
|
||||
// pntuple object is not deleted automatically
|
||||
// // pntuple object is not deleted automatically
|
||||
fNtupleVector.push_back(ntupleDescription->fNtuple);
|
||||
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL3() )
|
||||
fState.GetVerboseL3()
|
||||
@@ -180,13 +205,16 @@ void G4RootPNtupleManager::CreateNtuplesFromMain()
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kUndefined ) {
|
||||
if ( fNtupleDescriptionVector.size() ) {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveBeforeOpen;
|
||||
// G4cout << "Create mode: kSlaveBeforeOpen" << G4endl;
|
||||
} else {
|
||||
fCreateMode = G4PNtupleCreateMode::kSlaveAfterOpen;
|
||||
// G4cout << "Create mode: kSlaveAfterOpen" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
if ( fCreateMode == G4PNtupleCreateMode::kSlaveAfterOpen ) {
|
||||
// ntuples are not yet booked
|
||||
// G4cout << "Ntuples are not yet booked ?" << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -244,41 +272,6 @@ G4int G4RootPNtupleManager::CreateNtuple(
|
||||
return index + fFirstId;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleIColumn(
|
||||
const G4String& name, std::vector<int>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<int>(name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleFColumn(
|
||||
const G4String& name, std::vector<float>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<float>(name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleDColumn(
|
||||
const G4String& name, std::vector<double>* vector)
|
||||
{
|
||||
return CreateNtupleTColumn<double>(name, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleSColumn(
|
||||
const G4String& name)
|
||||
{
|
||||
return CreateNtupleTColumn<std::string>(name, nullptr);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4RootPNtupleManager::FinishNtuple()
|
||||
{
|
||||
auto ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
|
||||
FinishNtuple(ntupleId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::CreateNtupleIColumn(
|
||||
G4int ntupleId, const G4String& name, std::vector<int>* vector)
|
||||
@@ -326,40 +319,6 @@ void G4RootPNtupleManager::FinishNtuple(G4int ntupleId)
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::FillNtupleIColumn(
|
||||
G4int columnId, G4int value)
|
||||
{
|
||||
return FillNtupleTColumn<int>(columnId, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::FillNtupleFColumn(
|
||||
G4int columnId, G4float value)
|
||||
{
|
||||
return FillNtupleTColumn<float>(columnId, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::FillNtupleDColumn(
|
||||
G4int columnId, G4double value)
|
||||
{
|
||||
return FillNtupleTColumn<double>(columnId, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::FillNtupleSColumn(
|
||||
G4int columnId, const G4String& value)
|
||||
{
|
||||
return FillNtupleTColumn<std::string>(columnId, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::AddNtupleRow()
|
||||
{
|
||||
return AddNtupleRow(fFirstId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::FillNtupleIColumn(
|
||||
G4int ntupleId, G4int columnId, G4int value)
|
||||
@@ -411,7 +370,7 @@ G4bool G4RootPNtupleManager::AddNtupleRow(G4int ntupleId)
|
||||
mutex toolsLock(lock);
|
||||
auto result
|
||||
= ntupleDescription->fNtuple
|
||||
->add_row(toolsLock, *ntupleDescription->fFile, ntupleDescription->fMainBranches);
|
||||
->add_row(toolsLock, *ntupleDescription->fFile);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
@@ -451,7 +410,7 @@ G4bool G4RootPNtupleManager::Merge()
|
||||
mutex toolsLock(lock);
|
||||
auto result
|
||||
= ntupleDescription->fNtuple
|
||||
->end_fill(toolsLock, *ntupleDescription->fFile, ntupleDescription->fMainBranches);
|
||||
->end_fill(toolsLock, *ntupleDescription->fFile);
|
||||
|
||||
if ( ! result ) {
|
||||
G4ExceptionDescription description;
|
||||
@@ -527,6 +486,12 @@ G4int G4RootPNtupleManager::GetNofNtuples() const
|
||||
return fNtupleVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootPNtupleManager::GetNofNtupleBookings() const
|
||||
{
|
||||
return fNtupleDescriptionVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootPNtupleManager::IsEmpty() const
|
||||
{
|
||||
|
||||
@@ -28,406 +28,37 @@
|
||||
// Author: Ivana Hrivnacova, 09/04/2014 (ivana@ipno.in2p3.fr)
|
||||
|
||||
#include "G4RootRNtupleManager.hh"
|
||||
#include "G4RootRNtupleDescription.hh"
|
||||
#include "G4AnalysisManagerState.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootRNtupleManager::G4RootRNtupleManager(const G4AnalysisManagerState& state)
|
||||
: G4VRNtupleManager(state),
|
||||
fNtupleVector()
|
||||
{
|
||||
}
|
||||
: G4TRNtupleManager<tools::rroot::ntuple>(state)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootRNtupleManager::~G4RootRNtupleManager()
|
||||
{
|
||||
std::vector<G4RootRNtupleDescription*>::iterator it;
|
||||
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
//
|
||||
// private methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4RootRNtupleDescription* G4RootRNtupleManager::GetNtupleInFunction(G4int id,
|
||||
G4String functionName, G4bool warn) const
|
||||
{
|
||||
G4int index = id - fFirstId;
|
||||
if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
|
||||
if ( warn) {
|
||||
G4String inFunction = "G4RootRNtupleManager::";
|
||||
inFunction += functionName;
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "ntuple " << id << " does not exist.";
|
||||
G4Exception(inFunction, "Analysis_WR011", JustWarning, description);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fNtupleVector[index];
|
||||
}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::IsEmpty() const
|
||||
G4bool G4RootRNtupleManager::GetTNtupleRow(
|
||||
G4TRNtupleDescription<tools::rroot::ntuple>* ntupleDescription)
|
||||
{
|
||||
return ! fNtupleVector.size();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::Reset()
|
||||
{
|
||||
// Reset ntuples
|
||||
|
||||
std::vector<G4RootRNtupleDescription*>::iterator it;
|
||||
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
|
||||
// ntuple is deleted automatically when file is closed
|
||||
// delete (*it)->fNtuple;
|
||||
(*it)->fNtuple=0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::rroot::ntuple* G4RootRNtupleManager::GetNtuple() const
|
||||
{
|
||||
return GetNtuple(fFirstId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
tools::rroot::ntuple* G4RootRNtupleManager::GetNtuple(G4int ntupleId) const
|
||||
{
|
||||
G4RootRNtupleDescription* rntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "GetRNtuple");
|
||||
|
||||
if ( ! rntupleDescription ) return nullptr;
|
||||
|
||||
return rntupleDescription->fNtuple;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4int G4RootRNtupleManager::SetNtuple(G4RootRNtupleDescription* rntupleDescription)
|
||||
{
|
||||
G4int id = fNtupleVector.size() + fFirstId;
|
||||
|
||||
fNtupleVector.push_back(rntupleDescription);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleIColumn(const G4String& columnName,
|
||||
G4int& value)
|
||||
{
|
||||
return SetNtupleIColumn(fFirstId, columnName, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleFColumn(const G4String& columnName,
|
||||
G4float& value)
|
||||
{
|
||||
return SetNtupleFColumn(fFirstId, columnName, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleDColumn(const G4String& columnName,
|
||||
G4double& value)
|
||||
{
|
||||
return SetNtupleDColumn(fFirstId, columnName, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleSColumn(const G4String& columnName,
|
||||
G4String& value)
|
||||
{
|
||||
return SetNtupleSColumn(fFirstId, columnName, value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleIColumn(const G4String& columnName,
|
||||
std::vector<G4int>& vector)
|
||||
{
|
||||
return SetNtupleIColumn(fFirstId, columnName, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleFColumn(const G4String& columnName,
|
||||
std::vector<G4float>& vector)
|
||||
{
|
||||
return SetNtupleFColumn(fFirstId, columnName, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleDColumn(const G4String& columnName,
|
||||
std::vector<G4double>& vector)
|
||||
{
|
||||
return SetNtupleDColumn(fFirstId, columnName, vector);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleIColumn(G4int ntupleId,
|
||||
const G4String& columnName,
|
||||
G4int& value)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL4()->Message("set", "ntuple I column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4RootRNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "SetNtupleIColumn");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
ntupleBinding->add_column(columnName, value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL2()->Message("set", "ntuple I colum", description, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleFColumn(G4int ntupleId,
|
||||
const G4String& columnName,
|
||||
G4float& value)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL4()->Message("set", "ntuple F column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4RootRNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "SetNtupleFColumn");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
ntupleBinding->add_column(columnName, value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL2()->Message("set", "ntuple F colum", description, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleDColumn(G4int ntupleId,
|
||||
const G4String& columnName,
|
||||
G4double& value)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL4()->Message("set", "ntuple D column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4RootRNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "SetNtupleDColumn");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
ntupleBinding->add_column(columnName, value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL2()->Message("set", "ntuple D colum", description, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleSColumn(G4int ntupleId,
|
||||
const G4String& columnName,
|
||||
G4String& value)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL4()->Message("set", "ntuple S column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4RootRNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "SetNtupleSColumn");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
ntupleBinding->add_column(columnName, value);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL2()->Message("set", "ntuple S colum", description, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleIColumn(G4int ntupleId,
|
||||
const G4String& columnName,
|
||||
std::vector<G4int>& vector)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL4()->Message("set", "ntuple I column", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4RootRNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "SetNtupleIColumn");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
ntupleBinding->add_column(columnName, vector);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL2()->Message("set", "ntuple I colum", description, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleFColumn(G4int ntupleId,
|
||||
const G4String& columnName,
|
||||
std::vector<G4float>& vector)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL4()->Message("set", "ntuple F column of vector", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4RootRNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "SetNtupleFColumn");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
ntupleBinding->add_column(columnName, vector);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL2()->Message("set", "ntuple F colum", description, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::SetNtupleDColumn(G4int ntupleId,
|
||||
const G4String& columnName,
|
||||
std::vector<G4double>& vector)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL4()->Message("set", "ntuple D column of vector", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4RootRNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "SetNtupleDColumn");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
ntupleBinding->add_column(columnName, vector);
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId << " " << columnName;
|
||||
fState.GetVerboseL2()->Message("set", "ntuple D colum", description, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::GetNtupleRow()
|
||||
{
|
||||
return GetNtupleRow(fFirstId);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4RootRNtupleManager::GetNtupleRow(G4int ntupleId)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("get", "ntuple row", description);
|
||||
}
|
||||
#endif
|
||||
|
||||
G4RootRNtupleDescription* ntupleDescription
|
||||
= GetNtupleInFunction(ntupleId, "GetNtupleRow");
|
||||
if ( ! ntupleDescription ) return false;
|
||||
|
||||
tools::rroot::ntuple* ntuple = ntupleDescription->fNtuple;
|
||||
tools::ntuple_binding* ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
auto ntuple = ntupleDescription->fNtuple;
|
||||
auto ntupleBinding = ntupleDescription->fNtupleBinding;
|
||||
|
||||
G4bool isInitialized = ntupleDescription->fIsInitialized;
|
||||
if ( ! isInitialized ) {
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL4() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL4()->Message("initialize", "ntuple", description);
|
||||
}
|
||||
#endif
|
||||
if ( ! ntuple->initialize(G4cout, *ntupleBinding) ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple initialization failed !!";
|
||||
G4Exception("G4RootRNtuple::GetNtupleRow()",
|
||||
G4Exception("G4RootRNtuple::GetTNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
@@ -435,26 +66,18 @@ G4bool G4RootRNtupleManager::GetNtupleRow(G4int ntupleId)
|
||||
ntuple->start();
|
||||
}
|
||||
|
||||
G4bool next = ntuple->next();
|
||||
auto next = ntuple->next();
|
||||
if ( next ) {
|
||||
if ( ! ntuple->get_row() ) {
|
||||
G4ExceptionDescription description;
|
||||
description
|
||||
<< " "
|
||||
<< "Ntuple get_row() failed !!";
|
||||
G4Exception("G4RootRNtuple::GetNtupleRow()",
|
||||
G4Exception("G4RootRNtuple::GetTNtupleRow()",
|
||||
"Analysis_WR021", JustWarning, description);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if ( fState.GetVerboseL2() ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " ntupleId " << ntupleId;
|
||||
fState.GetVerboseL2()->Message("get", "ntuple row", description, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user