65 if ( fgInstance ==
nullptr ) {
76 return ( fgInstance !=
nullptr );
82 fFileManager(nullptr),
83 fNtupleFileManager(nullptr)
85 if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
89 <<
"G4RootAnalysisManager already exists."
90 <<
"Cannot create another instance.";
91 G4Exception(
"G4RootAnalysisManager::G4RootAnalysisManager()",
94 if ( isMaster ) fgMasterInstance =
this;
98 fFileManager = std::make_shared<G4RootFileManager>(
fState);
104 fNtupleFileManager = std::make_shared<G4RootNtupleFileManager>(
fState);
105 fNtupleFileManager->SetFileManager(fFileManager);
113 fgInstance =
nullptr;
121G4bool G4RootAnalysisManager::WriteH1()
126 if ( ! h1Vector.size() )
return true;
131 result = WriteT(h1Vector, hnVector,
"h1");
145G4bool G4RootAnalysisManager::WriteH2()
150 if ( ! h2Vector.size() )
return true;
155 result = WriteT(h2Vector, hnVector,
"h2");
169G4bool G4RootAnalysisManager::WriteH3()
174 if ( ! h3Vector.size() )
return true;
179 result = WriteT(h3Vector, hnVector,
"h3");
193G4bool G4RootAnalysisManager::WriteP1()
198 if ( ! p1Vector.size() )
return true;
203 result = WriteT(p1Vector, hnVector,
"p1");
217G4bool G4RootAnalysisManager::WriteP2()
222 if ( ! p2Vector.size() )
return true;
227 result = WriteT(p2Vector, hnVector,
"p2");
245 auto finalResult =
true;
248 finalResult = finalResult && result;
250 result = fNtupleFileManager->Reset();
251 finalResult = result && finalResult;
267 auto finalResult =
true;
270 if ( fNtupleFileManager->GetMergeMode() != G4NtupleMergeMode::kSlave ) {
271 auto result = fFileManager->OpenFile(fileName);
272 finalResult = finalResult && result;
276 auto result = fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
277 finalResult = finalResult && result;
286 auto finalResult =
true;
293 if ( ! fgMasterInstance &&
299 <<
" " <<
"No master G4RootAnalysisManager instance exists."
301 <<
" " <<
"Histogram/profile data will not be merged.";
307 auto result = WriteH1();
308 finalResult = finalResult && result;
312 finalResult = finalResult && result;
316 finalResult = finalResult && result;
320 finalResult = finalResult && result;
324 finalResult = finalResult && result;
327 result = fNtupleFileManager->ActionAtWrite();
328 finalResult = finalResult && result;
331 if ( fNtupleFileManager->GetMergeMode() != G4NtupleMergeMode::kSlave ) {
333 result = fFileManager->WriteFiles();
334 finalResult = finalResult && result;
339 result =
WriteAscii(fFileManager->GetFileName());
340 finalResult = finalResult && result;
355 auto finalResult =
true;
367 description <<
" " <<
"Resetting data failed";
372 finalResult = finalResult && result;
374 result = fNtupleFileManager->ActionAtCloseFile(reset);
375 finalResult = finalResult && result;
377 if ( fNtupleFileManager->GetMergeMode() != G4NtupleMergeMode::kSlave ) {
379 result = fFileManager->CloseFiles();
380 finalResult = finalResult && result;
393 fNtupleFileManager->GetMergeMode() == G4NtupleMergeMode::kNone ) ) {
395 result = ! std::remove(fFileManager->GetFullFileName());
399 description <<
" " <<
"Removing file "
400 << fFileManager->GetFullFileName() <<
" failed";
404 finalResult = finalResult && result;
408 ->
Message(
"delete",
"empty file", fFileManager->GetFullFileName());
415 ->
Message(
"close",
"files",
"");
428 G4int nofNtupleFiles)
430 fNtupleFileManager->SetNtupleMerging(mergeNtuples, nofNtupleFiles);
436 fNtupleFileManager->SetNtupleRowWise(rowWise, rowMode);
442 fFileManager->SetBasketSize(basketSize);
448 fFileManager->SetBasketEntries(basketEntries);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4MUTEX_INITIALIZER
const G4AnalysisVerbose * GetVerboseL2() const
const G4AnalysisVerbose * GetVerboseL1() const
G4bool GetIsMaster() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
virtual void SetBasketSize(unsigned int basketSize) override
virtual void SetNtupleMerging(G4bool mergeNtuples, G4int nofReducedNtupleFiles=0) override
virtual G4bool CloseFileImpl(G4bool reset) override
static G4RootAnalysisManager * Instance()
virtual G4bool WriteImpl() override
G4RootAnalysisManager(G4bool isMaster=true)
virtual ~G4RootAnalysisManager()
virtual G4bool OpenFileImpl(const G4String &fileName) override
static G4bool IsInstance()
virtual void SetNtupleRowWise(G4bool rowWise, G4bool rowMode=true) override
virtual void SetBasketEntries(unsigned int basketEntries) override
static constexpr unsigned int fgkDefaultBasketSize
std::shared_ptr< G4NtupleBookingManager > fNtupleBookingManager
G4AnalysisManagerState fState
void SetFileManager(std::shared_ptr< G4VFileManager > fileManager)
G4bool WriteAscii(const G4String &fileName)
void SetNtupleManager(std::shared_ptr< G4VNtupleManager > ntupleManager)
static constexpr unsigned int fgkDefaultBasketEntries
G4bool IsMultithreadedApplication()