34#include "tools/wroot/file"
35#include "tools/wroot/ntuple"
42 std::shared_ptr<G4NtupleBookingManager> bookingManager,
47 fNtupleBuilder(ntupleBuilder),
48 fBookingManager(
std::move(bookingManager)),
50 fFileNumber(fileNumber)
58G4int G4RootMainNtupleManager::CreateNtupleFromBooking(
59 G4NtupleBooking* g4NtupleBooking, std::shared_ptr<G4RootFile> ntupleFile)
71 if ( (index <
G4int(fNtupleVector.size())) && (fNtupleVector[index] !=
nullptr) ) {
79 Message(
kVL4,
"create",
"main ntuple", ntupleBooking.name());
82 while ( index >=
G4int(fNtupleVector.size()) ) {
83 fNtupleVector.push_back(
nullptr);
87 auto ntuple =
new tools::wroot::ntuple(*std::get<2>(*ntupleFile), ntupleBooking, fRowWise);
89 auto basketSize = fNtupleBuilder->GetBasketSize();
90 ntuple->set_basket_size(basketSize);
93 fNtupleVector[index] = ntuple;
95 Message(
kVL3,
"create",
"main ntuple", ntupleBooking.name());
111 auto ntupleFile = fFileManager->CreateNtupleFile(ntupleDescription, fFileNumber);
112 if ( ntupleFile ==
nullptr ) {
114 Warn(
"Ntuple file must be defined first.\n"
115 "Cannot create main ntuple.",
116 fkClass,
"CreateNtuple");
123 auto index = CreateNtupleFromBooking(g4NtupleBooking, ntupleFile);
129 while ( index >=
G4int(fNtupleDescriptionVector.size()) ) {
130 fNtupleDescriptionVector.push_back(std::make_pair(
nullptr,
nullptr));
134 fNtupleDescriptionVector[index] = std::make_pair(ntupleDescription, ntupleFile);
140 if (fNtupleVector.empty()) {
147 Message(
kVL4,
"delete",
"main ntuple ntupleId: " + to_string(
id));
151 if ( index < 0 || index >=
G4int(fNtupleVector.size()) ) {
158 delete fNtupleVector[index];
159 fNtupleVector[index] =
nullptr;
161 Message(
kVL3,
"delete",
"main ntuple ntupleId: " + to_string(
id));
169 std::size_t counter = 0;
171 for (
auto ntuple : fNtupleVector ) {
173 if (ntuple ==
nullptr)
continue;
175 ntuple->merge_number_of_entries();
178 if (ntuple->entries() != 0u) {
179 auto ntupleDescription = fNtupleDescriptionVector.at(counter).first;
180 ntupleDescription->SetHasFill(
true);
194 fNtupleVector.clear();
202 fNtupleDescriptionVector.clear();
203 fNtupleVector.clear();
209std::shared_ptr<G4RootFile>
212 auto perThread =
false;
213 return fFileManager->GetNtupleFile(ntupleDescription, perThread, fFileNumber);
226 for (
auto [ntupleDescription, ntupleFile] : fNtupleDescriptionVector) {
227 CreateNtupleFromBooking(ntupleDescription->GetG4NtupleBooking(), ntupleFile);
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
void CreateNtuplesFromBooking()
std::shared_ptr< G4RootFile > GetNtupleFile(RootNtupleDescription *ntupleDescription) const
G4RootMainNtupleManager()=delete
void SetNewCycle(G4bool value)
void CreateNtuple(RootNtupleDescription *ntupleDescription, G4bool warn=true)
G4NtupleBooking * GetG4NtupleBooking() const
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
tools::ntuple_booking fNtupleBooking
G4bool GetDeleted() const