34#include "tools/wroot/file"
35#include "tools/wroot/ntuple"
49 std::string_view functionName)
51 Warn(what +
" id= " + to_string(
id) +
" does not exist.",
60 std::shared_ptr<G4NtupleBookingManager> bookingManger,
61 std::shared_ptr<G4RootMainNtupleManager>
main,
64 fBookingManager(
std::move(bookingManger)),
65 fMainNtupleManager(
std::move(
main)),
74 delete ntupleDescription;
85 G4int id, std::string_view functionName,
G4bool warn)
const
99tools::wroot::base_pntuple*
101 G4int id, std::string_view functionName,
G4bool warn)
const
104 if ( ! ntupleDescription )
return nullptr;
106 if ( ! ntupleDescription->fBasePNtuple ) {
112 return ntupleDescription->fBasePNtuple;
118 G4int id, std::string_view functionName,
G4bool warn)
const
123 if ( index < 0 || index >=
G4int(mainNtupleVector.size()) ) {
130 return mainNtupleVector[index];
140 tools::wroot::ntuple* mainNtuple)
142 Message(
kVL4,
"create from main",
"pntuple", mainNtuple->name());
146 Warn(
"Cannot create pntuple. Main ntuple file does not exist.",
147 fkClass,
"CreateNtupleFromMain");
156 auto rfile = std::get<0>(*
file);
159 auto mainBranch = mainNtuple->get_row_wise_branch();
161 =
new tools::wroot::mt_ntuple_row_wise(
162 G4cout, rfile->byte_swap(), rfile->compression(),
163 mainNtuple->dir().seek_directory(),
164 *mainBranch, mainBranch->basket_size(),
168 =
static_cast<tools::wroot::imt_ntuple*
>(mtNtuple);
170 =
static_cast<tools::wroot::base_pntuple*
>(mtNtuple);
173 std::vector<tools::uint32> basketSizes;
174 tools_vforcit(tools::wroot::branch*, ntupleDescription->
fMainBranches, it) {
175 basketSizes.push_back((*it)->basket_size());
180 new tools::wroot::mt_ntuple_column_wise(
181 G4cout, rfile->byte_swap(), rfile->compression(),
182 mainNtuple->dir().seek_directory(),
188 =
static_cast<tools::wroot::imt_ntuple*
>(mtNtuple);
190 =
static_cast<tools::wroot::base_pntuple*
>(mtNtuple);
197 Message(
kVL3,
"create from main",
"pntuple", mainNtuple->name());
208 for (
auto g4NtupleBooking : g4NtupleBookings ) {
217 for (
auto mainNtuple : mainNtupleVector ) {
238 return FillNtupleTColumn<int>(ntupleId, columnId, value);
245 return FillNtupleTColumn<float>(ntupleId, columnId, value);
252 return FillNtupleTColumn<double>(ntupleId, columnId, value);
259 return FillNtupleTColumn<std::string>(ntupleId, columnId, value);
275 Message(
kVL4,
"add",
"pntuple row",
" ntupleId " + to_string(ntupleId));
279 if ( ! ntupleDescription )
return false;
281 auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
285 mutex toolsLock(lock);
287 = ntupleDescription->fNtuple->add_row(toolsLock, *rfile);
290 Warn(
"NtupleId " + to_string(ntupleId) +
"adding row failed.",
294 ntupleDescription->fDescription.fHasFill =
true;
297 Message(
kVL3,
"add",
"pntuple row",
" ntupleId " + to_string(ntupleId));
310 if(!ntupleDescription->fDescription.fActivation || !ntupleDescription->fNtuple) {
316 Message(
kVL4,
"merge",
"pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
319 auto rfile = std::get<0>(*ntupleDescription->fDescription.fFile);
323 mutex toolsLock(lock);
325 = ntupleDescription->fNtuple->end_fill(toolsLock, *rfile);
328 Warn(
"Ntuple " + ntupleDescription->fDescription.fNtupleBooking.name() +
329 "end fill has failed.",
fkClass,
"Merge");
332 delete ntupleDescription->fNtuple;
333 ntupleDescription->fNtuple =
nullptr;
336 Message(
kVL3,
"merge",
"pntuple", ntupleDescription->fDescription.fNtupleBooking.name());
348 delete ntupleDescription->fNtuple;
363 ntupleDescription->fDescription.fActivation = activation;
373 if ( ! ntupleDescription )
return;
375 ntupleDescription->fDescription.fActivation = activation;
380 G4int ntupleId)
const
383 if ( ! ntupleDescription )
return false;
385 return ntupleDescription->fDescription.fActivation;
#define G4MUTEX_INITIALIZER
G4GLOB_DLL std::ostream G4cout
int main(int argc, char *argv[])
G4bool GetIsActivation() const
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
const G4AnalysisManagerState & fState
G4bool IsVerbose(G4int verboseLevel) const
virtual void SetActivation(G4bool activation) final
G4RootPNtupleDescription * GetNtupleDescriptionInFunction(G4int id, std::string_view function, G4bool warn=true) const
virtual G4int CreateNtuple(G4NtupleBooking *booking) final
virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final
std::vector< G4RootPNtupleDescription * > fNtupleDescriptionVector
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId, const G4String &value) final
tools::wroot::base_pntuple * GetNtupleInFunction(G4int id, std::string_view function, G4bool warn=true) const
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode)
G4RootPNtupleManager()=delete
std::shared_ptr< G4NtupleBookingManager > fBookingManager
static constexpr std::string_view fkClass
virtual void Clear() final
virtual G4bool Merge() final
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final
std::shared_ptr< G4RootMainNtupleManager > fMainNtupleManager
virtual ~G4RootPNtupleManager()
virtual G4int GetNofNtuples() const final
tools::wroot::ntuple * GetMainNtupleInFunction(G4int id, std::string_view function, G4bool warn=true) const
virtual G4bool GetActivation(G4int ntupleId) const final
std::vector< tools::wroot::imt_ntuple * > fNtupleVector
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final
void CreateNtupleFromMain(G4RootPNtupleDescription *ntupleDescription, tools::wroot::ntuple *mainNtuple)
void CreateNtuplesFromMain()
virtual G4bool AddNtupleRow() final
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
void NotExistWarning(const G4String &what, G4int id, std::string_view className, std::string_view functionName)
tools::wroot::base_pntuple * fBasePNtuple
tools::wroot::imt_ntuple * fNtuple
std::vector< tools::wroot::branch * > fMainBranches
RootNtupleDescription fDescription
tools::ntuple_booking fNtupleBooking
std::shared_ptr< FT > fFile