42using std::make_shared;
58 auto mergeNtuples =
false;
59 SetNtupleMergingMode(mergeNtuples, fNofNtupleFiles);
73void G4RootNtupleFileManager::SetNtupleMergingMode(
G4bool mergeNtuples,
83 Warn(
"Merging ntuples is not applicable in sequential application.\n"
84 "Setting was ignored.",
85 fkClass,
"SetNtupleMergingMode");
91 Warn(
"Merging ntuples requires G4AnalysisManager instance on master.\n"
92 "Setting was ignored.",
93 fkClass,
"SetNtupleMergingMode");
98 if ( ( ! mergeNtuples ) || ( ! canMerge ) ) {
100 mergingMode =
"G4NtupleMergeMode::kNone";
104 fNofNtupleFiles = nofNtupleFiles;
107 if ( fNofNtupleFiles < 0 ) {
108 Warn(
"Number of reduced files must be [0, nofThreads].\n"
109 "Cannot set " + to_string(nofNtupleFiles) +
" files.\n" +
110 "Setting was ignored.",
111 fkClass,
"SetNtupleMergingMode");
120 mergingMode =
"G4NtupleMergeMode::kMain";
123 mergingMode =
"G4NtupleMergeMode::kSlave";
127 Message(
kVL2,
"set",
"ntuple merging mode", mergingMode);
131G4int G4RootNtupleFileManager::GetNtupleFileNumber()
133 if (fNofNtupleFiles == 0)
return 0;
135 G4int nofMainManagers = fNofNtupleFiles;
136 if (nofMainManagers == 0) nofMainManagers = 1;
143G4bool G4RootNtupleFileManager::CloseNtupleFiles()
146 auto mainNumber = ( fNofNtupleFiles > 0 ) ? 0 : -1;
149 auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
150 for (
auto ntupleDescription : ntupleVector) {
151 for (
G4int i = mainNumber; i < fNofNtupleFiles; ++i ) {
152 result &= fFileManager->CloseNtupleFile(ntupleDescription, i);
164 G4int nofNtupleFiles)
167 if ( fIsInitialized ) {
168 Warn(
"Cannot change merging mode.\n"
169 "The function must be called before OpenFile().",
170 fkClass,
"SetNtupleMerging");
175 SetNtupleMergingMode(mergeNtuples, nofNtupleFiles);
186 rowWiseMode =
"row-wise with extra branch";
188 else if ( rowMode ) {
189 rowWiseMode =
"row-wise";
192 rowWiseMode =
"column-wise";
195 Message(
kVL1,
"set",
"ntuple merging row mode", rowWiseMode);
198 if ( fNtupleRowWise == rowWise && fNtupleRowMode == rowMode )
return;
200 fNtupleRowWise = rowWise;
201 fNtupleRowMode = rowMode;
203 if ( fNtupleManager ) {
204 fNtupleManager->SetNtupleRowWise(rowWise, rowMode);
207 if ( fSlaveNtupleManager ) {
208 fSlaveNtupleManager->SetNtupleRowWise(rowWise, rowMode);
215 fFileManager->SetBasketSize(basketSize);
221 fFileManager->SetBasketEntries(basketEntries);
235 std::shared_ptr<G4VNtupleManager> activeNtupleManager =
nullptr;
236 switch ( fNtupleMergeMode )
240 = make_shared<G4RootNtupleManager>(
242 fNtupleManager->SetFileManager(fFileManager);
243 activeNtupleManager = fNtupleManager;
247 G4int nofMainManagers = fNofNtupleFiles;
248 if (nofMainManagers == 0) {
253 = make_shared<G4RootNtupleManager>(
255 fNtupleManager->SetFileManager(fFileManager);
256 activeNtupleManager = fNtupleManager;
261 fNtupleManager = fgMasterInstance->fNtupleManager;
263 auto mainNtupleManager
264 = fNtupleManager->GetMainNtupleManager(GetNtupleFileNumber());
266 = make_shared<G4RootPNtupleManager>(
268 activeNtupleManager = fSlaveNtupleManager;
273 switch ( fNtupleMergeMode ) {
281 mergeMode =
"slave ";
284 Message(
kVL3,
"create", mergeMode +
"ntuple manager");
286 fIsInitialized =
true;
288 return activeNtupleManager;
299 G4String objectType =
"analysis file";
301 objectType =
"main analysis file";
306 fNtupleManager->CreateNtuplesFromBooking(
337 result &= fNtupleManager->Merge();
341 result &= fSlaveNtupleManager->Merge();
353 fSlaveNtupleManager->SetNewCycle(
false);
357 return CloseNtupleFiles();
369 result &= fNtupleManager->Reset();
373 fSlaveNtupleManager->Reset();
G4bool GetIsMaster() const
void SetNtupleMerging(G4bool mergeNtuples, G4int nofReducedNtupleFiles=0) override
void SetNtupleRowWise(G4bool rowWise, G4bool rowMode=true) override
void SetBasketSize(unsigned int basketSize) override
G4bool ActionAtCloseFile() override
std::shared_ptr< G4VNtupleManager > CreateNtupleManager() override
~G4RootNtupleFileManager() override
G4bool ActionAtWrite() override
void SetBasketEntries(unsigned int basketEntries) override
G4bool ActionAtOpenFile(const G4String &fileName) override
G4RootNtupleFileManager()=delete
std::shared_ptr< G4NtupleBookingManager > fBookingManager
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
const G4AnalysisManagerState & fState
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
G4bool IsMultithreadedApplication()