36 #include "tools/wroot/file"
38 using namespace G4Analysis;
42 G4int nofMainManagers)
45 fFileManager(nullptr),
46 fNtupleDirectory(nullptr),
49 for (
G4int i=0; i<nofMainManagers; ++i) {
50 fMainNtupleManagers.push_back(
64 void G4RootNtupleManager::SetCreateMode()
71 ->
Message(
"set",
"ntuple create mode",
"");
76 if ( fMainNtupleManagers.size() ) {
77 if ( fFileManager->GetNtupleFile(0) ) {
79 createMode =
"G4NtupleCreateMode::kMainAfterOpen";
82 createMode =
"G4NtupleCreateMode::kMainBeforeOpen";
86 if ( fNtupleDirectory ) {
88 createMode =
"G4NtupleCreateMode::kNoMergeAfterOpen";
91 createMode =
"G4NtupleCreateMode::kNoMergeBeforeOpen";
99 ->
Message(
"set",
"ntuple create mode", createMode);
104 void G4RootNtupleManager::CreateTNtuple(
112 if ( ! fNtupleDirectory ) {
113 G4String inFunction =
"G4RootNtupleManager::::CreateTNtuple";
116 <<
"Cannot create ntuple. Ntuple directory does not exist." <<
G4endl;
122 =
new tools::wroot::ntuple(*fNtupleDirectory, name, title);
130 void G4RootNtupleManager::CreateTNtupleFromBooking(
135 if ( ! fNtupleDirectory ) {
136 G4String inFunction =
"G4RootNtupleManager::::CreateTNtuple";
139 <<
"Cannot create ntuple. Ntuple directory does not exist." <<
G4endl;
145 =
new tools::wroot::ntuple(
148 auto basketSize = fFileManager->GetBasketSize();
149 ntupleDescription->
fNtuple->set_basket_size(basketSize);
158 for (
auto manager : fMainNtupleManagers ) {
159 if ( ! manager->GetNtupleVector().size() ) {
161 manager->SetNtupleFile(fFileManager->GetNtupleFile(counter));
162 manager->SetNtupleDirectory(fFileManager->GetMainNtupleDirectory(counter++));
163 manager->CreateNtuplesFromBooking();
170 void G4RootNtupleManager::FinishTNtuple(
177 for (
auto manager : fMainNtupleManagers ) {
179 manager->SetNtupleFile(fFileManager->GetNtupleFile(counter));
180 manager->SetNtupleDirectory(fFileManager->GetMainNtupleDirectory(counter++));
197 auto finalResult =
true;
198 for (
auto manager : fMainNtupleManagers ) {
199 auto result = manager->Reset(
false);
200 finalResult =
result && finalResult;
207 G4bool G4RootNtupleManager::Merge()
209 auto finalResult =
true;
211 for (
auto manager : fMainNtupleManagers ) {
212 auto result = manager->Merge();
213 finalResult =
result && finalResult;
222 if ( index < 0 || index >=
G4int(fMainNtupleManagers.size()) ) {
223 G4String inFunction =
"G4RootNtupleManager::::GetMainNtupleManager";
225 description <<
" " <<
"main ntuple manager " << index <<
" does not exist.";
230 return fMainNtupleManagers[index];
234 unsigned int G4RootNtupleManager::GetBasketSize()
const
236 if ( ! fFileManager ) {
237 G4String inFunction =
"G4RootNtupleManager::::GetBasketSize";
239 description <<
" " <<
"File manager must be defined first.";
244 return fFileManager->GetBasketSize();
G4double G4ParticleHPJENDLHEData::G4double result
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
std::ostringstream G4ExceptionDescription
G4RootNtupleManager(const G4AnalysisManagerState &state, G4int nofMainManagers=0)
std::vector< G4TNtupleDescription< tools::wroot::ntuple > * > fNtupleDescriptionVector
const G4AnalysisVerbose * GetVerboseL2() const
G4bool Reset(G4bool deleteNtuple)
virtual ~G4RootNtupleManager()
const G4AnalysisVerbose * GetVerboseL4() const
friend class G4RootMainNtupleManager
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
std::vector< tools::wroot::ntuple * > fNtupleVector
tools::ntuple_booking fNtupleBooking
const G4AnalysisManagerState & fState