35#include "tools/wroot/file"
41 std::shared_ptr<G4NtupleBookingManager> bookingManger,
45 fFileManager(nullptr),
46 fMainNtupleManagers(),
51 for (
G4int i=0; i<nofMainManagers; ++i) {
53 if ( (i == 0) && (nofFiles == 0) ) {
57 fMainNtupleManagers.push_back(
58 std::make_shared<G4RootMainNtupleManager>(
59 this, bookingManger.get(), rowWise, fileNumber,
fState));
72void G4RootNtupleManager::CreateTNtupleFromBooking(
75 if ( ! fMainNtupleManagers.size() ) {
77 if ( ntupleDescription->
fNtuple ) {
78 G4String inFunction =
"G4RootNtupleManager::::CreateTNtupleFromBooking";
80 description <<
"Cannot create ntuple. Ntuple already exists." <<
G4endl;
86 auto ntupleFile = fFileManager->CreateNtupleFile(ntupleDescription);
88 G4String inFunction =
"G4RootNtupleManager::::CreateTNtupleFromBooking";
90 description <<
"Cannot create ntuple. Ntuple file does not exist." <<
G4endl;
95 auto directory = std::get<2>(*ntupleFile);
97 =
new tools::wroot::ntuple(
100 auto basketSize = fFileManager->GetBasketSize();
101 ntupleDescription->
fNtuple->set_basket_size(basketSize);
109 for (
auto manager : fMainNtupleManagers ) {
110 manager->CreateNtuple(ntupleDescription);
116void G4RootNtupleManager::FinishTNtuple(
128 auto finalResult =
true;
130 for (
auto manager : fMainNtupleManagers ) {
131 auto result = manager->Reset(
false);
132 finalResult = result && finalResult;
139G4bool G4RootNtupleManager::Merge()
141 auto finalResult =
true;
143 for (
auto manager : fMainNtupleManagers ) {
144 auto result = manager->Merge();
145 finalResult = result && finalResult;
152void G4RootNtupleManager::SetFileManager(std::shared_ptr<G4RootFileManager> fileManager)
154 fFileManager = fileManager;
156 for (
auto mainNtupleManager : fMainNtupleManagers) {
157 mainNtupleManager->SetFileManager(fileManager);
162void G4RootNtupleManager::SetNtupleRowWise(
G4bool rowWise,
G4bool rowMode)
169 for (
auto& mainNtupleManager : fMainNtupleManagers ) {
170 mainNtupleManager->SetRowWise(rowWise);
175std::shared_ptr<G4RootMainNtupleManager>
176G4RootNtupleManager::GetMainNtupleManager(
G4int index)
const
178 if ( index < 0 || index >=
G4int(fMainNtupleManagers.size()) ) {
179 G4String inFunction =
"G4RootNtupleManager::::GetMainNtupleManager";
181 description <<
" " <<
"main ntuple manager " << index <<
" does not exist.";
186 return fMainNtupleManagers[index];
190unsigned int G4RootNtupleManager::GetBasketSize()
const
192 if ( ! fFileManager ) {
193 G4String inFunction =
"G4RootNtupleManager::::GetBasketSize";
195 description <<
" " <<
"File manager must be defined first.";
200 return fFileManager->GetBasketSize();
204unsigned int G4RootNtupleManager::GetBasketEntries()
const
206 if ( ! fFileManager ) {
207 G4String inFunction =
"G4RootNtupleManager::::GetBasketEntries";
209 description <<
" " <<
"File manager must be defined first.";
214 return fFileManager->GetBasketEntries();
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::tuple< std::shared_ptr< tools::wroot::file >, tools::wroot::directory *, tools::wroot::directory * > G4RootFile
const G4AnalysisManagerState & fState
G4RootNtupleManager(const G4AnalysisManagerState &state, std::shared_ptr< G4NtupleBookingManager > bookingManger, G4int nofMainManagers, G4int nofReducedFiles, G4bool rowWise, G4bool rowMode)
virtual ~G4RootNtupleManager()
std::vector< tools::wroot::ntuple * > fNtupleVector
tools::ntuple_booking fNtupleBooking