34 #include "tools/wroot/file"
35 #include "tools/wroot/ntuple"
49 fMainNtupleManager(main),
57 delete ntupleDescription;
73 G4String inFunction =
"G4RootPNtupleManager::";
74 inFunction += functionName;
76 description <<
" " <<
"ntuple " <<
id <<
" does not exist.";
86 tools::wroot::base_pntuple*
91 if ( ! ntupleDescription )
return nullptr;
93 if ( ! ntupleDescription->fBasePNtuple ) {
95 G4String inFunction =
"G4RootPNtupleManager::";
96 inFunction += functionName;
98 description <<
" " <<
"ntupleId " <<
id <<
" does not exist.";
103 return ntupleDescription->fBasePNtuple;
111 auto& mainNtupleVector
115 if ( index < 0 || index >=
G4int(mainNtupleVector.size()) ) {
117 G4String inFunction =
"G4RootPNtupleManager::";
118 inFunction += functionName;
120 description <<
" " <<
"main ntuple " <<
id <<
" does not exist.";
126 return mainNtupleVector[index];
141 ->
Message(
"create from main",
"pntuple", mainNtuple->name());
148 auto mainBranch = mainNtuple->get_row_wise_branch();
149 auto rowWise = mainBranch ?
true :
false;
151 ntupleDescription->
fFile = rfile.get();
156 tools::wroot::mt_ntuple_row_wise* mtNtuple
157 =
new tools::wroot::mt_ntuple_row_wise(
158 G4cout, rfile->byte_swap(), rfile->compression(),
159 mainNtuple->dir().seek_directory(),
160 *mainBranch, mainBranch->basket_size(),
164 =
static_cast<tools::wroot::imt_ntuple*
>(mtNtuple);
166 =
static_cast<tools::wroot::base_pntuple*
>(mtNtuple);
169 std::vector<tools::uint32> basketSizes;
170 tools_vforcit(tools::wroot::branch*, ntupleDescription->
fMainBranches, it) {
171 basketSizes.push_back((*it)->basket_size());
174 tools::wroot::mt_ntuple_column_wise* mtNtuple =
175 new tools::wroot::mt_ntuple_column_wise(
176 G4cout, rfile->byte_swap(), rfile->compression(),
177 mainNtuple->dir().seek_directory(),
182 =
static_cast<tools::wroot::imt_ntuple*
>(mtNtuple);
184 =
static_cast<tools::wroot::base_pntuple*
>(mtNtuple);
195 ->
Message(
"create from main",
"pntuple", mainNtuple->name());
221 auto& mainNtupleVector
225 for (
auto mainNtuple : mainNtupleVector ) {
227 auto& ntupleDescription
259 ntupleDescription->fNtupleBooking.set_name(name);
260 ntupleDescription->fNtupleBooking.set_title(title);
267 description << name <<
" ntupleId " << index +
fFirstId;
279 return CreateNtupleTColumn<int>(ntupleId,
name, vector);
286 return CreateNtupleTColumn<float>(ntupleId,
name, vector);
294 return CreateNtupleTColumn<double>(ntupleId,
name, vector);
301 return CreateNtupleTColumn<std::string>(ntupleId,
name,
nullptr);
311 auto ntupleDescription
313 if ( ! ntupleDescription )
return;
316 if ( ! mainNtuple )
return;
326 return FillNtupleTColumn<int>(ntupleId, columnId,
value);
333 return FillNtupleTColumn<float>(ntupleId, columnId,
value);
340 return FillNtupleTColumn<double>(ntupleId, columnId,
value);
347 return FillNtupleTColumn<std::string>(ntupleId, columnId,
value);
361 description <<
" ntupleId " << ntupleId;
367 if ( ! ntupleDescription )
return false;
371 mutex toolsLock(lock);
373 = ntupleDescription->fNtuple
374 ->add_row(toolsLock, *ntupleDescription->fFile);
378 description <<
" " <<
" ntupleId " << ntupleId
379 <<
"adding row has failed.";
380 G4Exception(
"G4RootPNtupleManager::AddNtupleRow()",
387 description <<
" ntupleId " << ntupleId;
401 if ( ! ntupleDescription->fActivation )
continue;
406 ->
Message(
"merge",
"pntuple", ntupleDescription->fNtupleBooking.name());
412 mutex toolsLock(lock);
414 = ntupleDescription->fNtuple
415 ->end_fill(toolsLock, *ntupleDescription->fFile);
419 description <<
" " <<
" ntuple " << ntupleDescription->fNtupleBooking.name()
420 <<
"end fill has failed.";
425 delete ntupleDescription->fNtuple;
426 ntupleDescription->fNtuple =
nullptr;
431 ->
Message(
"merge",
"pntuple", ntupleDescription->fNtupleBooking.name());
443 if ( deleteNtuple ) {
444 delete ntupleDescription->fNtuple;
446 ntupleDescription->fNtuple =
nullptr;
460 ntupleDescription->fActivation = activation;
470 if ( ! ntupleDescription )
return;
472 ntupleDescription->fActivation = activation;
477 G4int ntupleId)
const
480 if ( ! ntupleDescription )
return false;
482 return ntupleDescription->fActivation;
tools::wroot::ntuple * GetMainNtupleInFunction(G4int id, G4String function, G4bool warn=true) const
const G4AnalysisVerbose * GetVerboseL2() const
tools::ntuple_booking fNtupleBooking
tools::wroot::base_pntuple * GetNtupleInFunction(G4int id, G4String function, G4bool warn=true) const
std::ostringstream G4ExceptionDescription
virtual G4bool Merge() final
virtual G4bool Reset(G4bool deleteNtuple) final
virtual G4int CreateNtupleFColumn(G4int ntupleId, const G4String &name, std::vector< float > *vector) override
G4RootPNtupleManager(G4RootMainNtupleManager *main, const G4AnalysisManagerState &state)
G4bool GetIsActivation() const
G4RootMainNtupleManager * fMainNtupleManager
std::shared_ptr< tools::wroot::file > GetNtupleFile() const
tools::wroot::base_pntuple * fBasePNtuple
virtual G4int GetNofNtupleBookings() const final
virtual G4int CreateNtupleDColumn(G4int ntupleId, const G4String &name, std::vector< double > *vector) override
G4PNtupleCreateMode fCreateMode
virtual G4bool FillNtupleFColumn(G4int ntupleId, G4int columnId, G4float value) final
#define G4MUTEX_INITIALIZER
virtual G4bool FillNtupleSColumn(G4int ntupleId, G4int columnId, const G4String &value) final
const XML_Char int const XML_Char * value
std::vector< tools::wroot::branch * > fMainBranches
const G4AnalysisVerbose * GetVerboseL4() const
virtual void SetActivation(G4bool activation) final
std::vector< tools::wroot::imt_ntuple * > fNtupleVector
virtual G4bool GetActivation(G4int ntupleId) const final
virtual G4int CreateNtupleIColumn(G4int ntupleId, const G4String &name, std::vector< int > *vector) override
const G4AnalysisVerbose * GetVerboseL3() const
virtual G4bool IsEmpty() const final
int main(int argc, char **argv)
const std::vector< tools::wroot::ntuple * > & GetNtupleVector()
G4double G4ParticleHPJENDLHEData::G4double result
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
tools::wroot::imt_ntuple * fNtuple
virtual G4bool AddNtupleRow() final
virtual G4int CreateNtupleSColumn(G4int ntupleId, const G4String &name) override
virtual void FinishNtuple() final
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4GLOB_DLL std::ostream G4cout
tools::wroot::file * fFile
virtual G4bool FillNtupleDColumn(G4int ntupleId, G4int columnId, G4double value) final
void CreateNtuple(G4RootPNtupleDescription *ntupleDescription, tools::wroot::ntuple *mainNtuple)
G4RootPNtupleDescription * GetNtupleDescriptionInFunction(G4int id, G4String function, G4bool warn=true) const
std::vector< G4RootPNtupleDescription * > fNtupleDescriptionVector
virtual G4int GetNofNtuples() const final
const G4AnalysisManagerState & fState
virtual G4bool FillNtupleIColumn(G4int ntupleId, G4int columnId, G4int value) final
void CreateNtuplesFromMain()