34 #include "tools/wroot/file"
35 #include "tools/wroot/ntuple"
49 fMainNtupleManager(main),
56 for (
auto ntupleDescription : fNtupleDescriptionVector ) {
57 delete ntupleDescription;
67 G4RootPNtupleManager::GetNtupleDescriptionInFunction(
71 if ( index < 0 || index >=
G4int(fNtupleDescriptionVector.size()) ) {
73 G4String inFunction =
"G4RootPNtupleManager::";
74 inFunction += functionName;
76 description <<
" " <<
"ntuple " <<
id <<
" does not exist.";
82 return fNtupleDescriptionVector[index];
86 tools::wroot::pntuple* G4RootPNtupleManager::GetNtupleInFunction(
89 auto ntupleDescription = GetNtupleDescriptionInFunction(
id, functionName);
90 if ( ! ntupleDescription )
return nullptr;
92 if ( ! ntupleDescription->fNtuple ) {
94 G4String inFunction =
"G4RootPNtupleManager::";
95 inFunction += functionName;
97 description <<
" " <<
"ntupleId " <<
id <<
" does not exist.";
102 return ntupleDescription->fNtuple;
106 tools::wroot::ntuple*
107 G4RootPNtupleManager::GetMainNtupleInFunction(
110 auto& mainNtupleVector
114 if ( index < 0 || index >=
G4int(mainNtupleVector.size()) ) {
116 G4String inFunction =
"G4RootPNtupleManager::";
117 inFunction += functionName;
119 description <<
" " <<
"main ntuple " <<
id <<
" does not exist.";
125 return mainNtupleVector[index];
135 tools::wroot::ntuple* mainNtuple)
140 ->
Message(
"create from main",
"pntuple", mainNtuple->name());
147 ntupleDescription->
fFile = rfile.get();
150 std::vector<tools::uint32> basketSizes;
151 tools_vforcit(tools::wroot::branch*, ntupleDescription->
fMainBranches, it) {
152 basketSizes.push_back((*it)->basket_size());
158 =
new tools::wroot::pntuple(
159 G4cout, rfile->byte_swap(), rfile->compression(),
160 directory->seek_directory(), basketSizes,
165 fNtupleVector.push_back(ntupleDescription->
fNtuple);
170 ->
Message(
"create from main",
"pntuple", mainNtuple->name());
175 void G4RootPNtupleManager::CreateNtuplesFromMain()
181 if ( fNtupleDescriptionVector.size() ) {
193 auto& mainNtupleVector
197 for (
auto mainNtuple : mainNtupleVector ) {
199 auto& ntupleDescription
200 = fNtupleDescriptionVector[lcounter++];
201 CreateNtuple(ntupleDescription, mainNtuple);
206 G4int G4RootPNtupleManager::CreateNtuple(
226 auto index = fNtupleDescriptionVector.size();
228 fNtupleDescriptionVector.push_back(ntupleDescription);
239 description << name <<
" ntupleId " << index +
fFirstId;
248 G4int G4RootPNtupleManager::CreateNtupleIColumn(
249 const G4String& name, std::vector<int>* vector)
251 return CreateNtupleTColumn<int>(
name, vector);
255 G4int G4RootPNtupleManager::CreateNtupleFColumn(
256 const G4String& name, std::vector<float>* vector)
258 return CreateNtupleTColumn<float>(
name, vector);
262 G4int G4RootPNtupleManager::CreateNtupleDColumn(
263 const G4String& name, std::vector<double>* vector)
265 return CreateNtupleTColumn<double>(
name, vector);
269 G4int G4RootPNtupleManager::CreateNtupleSColumn(
272 return CreateNtupleTColumn<std::string>(
name,
nullptr);
276 void G4RootPNtupleManager::FinishNtuple()
278 auto ntupleId = fNtupleDescriptionVector.size() + fFirstId - 1;
279 FinishNtuple(ntupleId);
283 G4int G4RootPNtupleManager::CreateNtupleIColumn(
284 G4int ntupleId,
const G4String& name, std::vector<int>* vector)
286 return CreateNtupleTColumn<int>(ntupleId,
name, vector);
290 G4int G4RootPNtupleManager::CreateNtupleFColumn(
291 G4int ntupleId,
const G4String& name, std::vector<float>* vector)
293 return CreateNtupleTColumn<float>(ntupleId,
name, vector);
298 G4int G4RootPNtupleManager::CreateNtupleDColumn(
299 G4int ntupleId,
const G4String& name, std::vector<double>* vector)
301 return CreateNtupleTColumn<double>(ntupleId,
name, vector);
305 G4int G4RootPNtupleManager::CreateNtupleSColumn(
308 return CreateNtupleTColumn<std::string>(ntupleId,
name,
nullptr);
312 void G4RootPNtupleManager::FinishNtuple(
G4int ntupleId)
318 auto ntupleDescription
319 = GetNtupleDescriptionInFunction(ntupleId,
"FinishNtuple");
320 if ( ! ntupleDescription )
return;
322 auto mainNtuple = GetMainNtupleInFunction(ntupleId,
"FinishNtuple");
323 if ( ! mainNtuple )
return;
325 CreateNtuple(ntupleDescription, mainNtuple);
330 G4bool G4RootPNtupleManager::FillNtupleIColumn(
333 return FillNtupleTColumn<int>(columnId,
value);
337 G4bool G4RootPNtupleManager::FillNtupleFColumn(
340 return FillNtupleTColumn<float>(columnId,
value);
344 G4bool G4RootPNtupleManager::FillNtupleDColumn(
347 return FillNtupleTColumn<double>(columnId,
value);
351 G4bool G4RootPNtupleManager::FillNtupleSColumn(
354 return FillNtupleTColumn<std::string>(columnId,
value);
358 G4bool G4RootPNtupleManager::AddNtupleRow()
360 return AddNtupleRow(fFirstId);
364 G4bool G4RootPNtupleManager::FillNtupleIColumn(
367 return FillNtupleTColumn<int>(ntupleId, columnId,
value);
371 G4bool G4RootPNtupleManager::FillNtupleFColumn(
374 return FillNtupleTColumn<float>(ntupleId, columnId,
value);
378 G4bool G4RootPNtupleManager::FillNtupleDColumn(
381 return FillNtupleTColumn<double>(ntupleId, columnId,
value);
385 G4bool G4RootPNtupleManager::FillNtupleSColumn(
388 return FillNtupleTColumn<std::string>(ntupleId, columnId,
value);
392 G4bool G4RootPNtupleManager::AddNtupleRow(
G4int ntupleId)
402 description <<
" ntupleId " << ntupleId;
407 auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId,
"AddNtupleRow");
408 if ( ! ntupleDescription )
return false;
411 mutex toolsLock(lock);
418 description <<
" " <<
" ntupleId " << ntupleId
419 <<
"adding row has failed.";
420 G4Exception(
"G4RootPNtupleManager::AddNtupleRow()",
427 description <<
" ntupleId " << ntupleId;
436 G4bool G4RootPNtupleManager::Merge()
438 for (
auto ntupleDescription : fNtupleDescriptionVector) {
451 mutex toolsLock(lock);
458 description <<
" " <<
" ntuple " << ntupleDescription->
fNtupleBooking.name()
459 <<
"end fill has failed.";
464 delete ntupleDescription->
fNtuple;
465 ntupleDescription->
fNtuple =
nullptr;
481 for (
auto ntupleDescription : fNtupleDescriptionVector ) {
482 if ( deleteNtuple ) {
483 delete ntupleDescription->
fNtuple;
485 ntupleDescription->
fNtuple =
nullptr;
488 fNtupleVector.clear();
495 void G4RootPNtupleManager::SetActivation(
498 for (
auto ntupleDescription : fNtupleDescriptionVector ) {
505 void G4RootPNtupleManager::SetActivation(
508 auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId,
"SetActivation");
509 if ( ! ntupleDescription )
return;
515 G4bool G4RootPNtupleManager::GetActivation(
516 G4int ntupleId)
const
518 auto ntupleDescription = GetNtupleDescriptionInFunction(ntupleId,
"GetActivation");
519 if ( ! ntupleDescription )
return false;
525 G4int G4RootPNtupleManager::GetNofNtuples()
const
527 return fNtupleVector.size();
531 G4bool G4RootPNtupleManager::IsEmpty()
const
533 return ! fNtupleDescriptionVector.size();
G4double G4ParticleHPJENDLHEData::G4double result
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
std::ostringstream G4ExceptionDescription
std::shared_ptr< tools::wroot::file > GetNtupleFile() const
std::vector< tools::wroot::branch * > fMainBranches
int main(int argc, char **argv)
#define G4MUTEX_INITIALIZER
const G4AnalysisVerbose * GetVerboseL2() const
const std::vector< tools::wroot::ntuple * > & GetNtupleVector()
const G4AnalysisVerbose * GetVerboseL3() const
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
const G4AnalysisVerbose * GetVerboseL4() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
tools::wroot::file * fFile
tools::ntuple_booking fNtupleBooking
tools::wroot::directory * GetNtupleDirectory() const
G4RootPNtupleManager(G4RootMainNtupleManager *main, const G4AnalysisManagerState &state)
tools::wroot::pntuple * fNtuple
G4bool GetIsActivation() const
const G4AnalysisManagerState & fState