37using std::make_shared;
60 if ( fgInstance ==
nullptr ) {
71 return ( fgInstance != 0 );
77 fFileManager(nullptr),
78 fNtupleFileManager(nullptr)
80 if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
84 <<
"G4XmlAnalysisManager already exists."
85 <<
"Cannot create another instance.";
86 G4Exception(
"G4XmlAnalysisManager::G4XmlAnalysisManager",
89 if ( isMaster ) fgMasterInstance =
this;
93 fFileManager = std::make_shared<G4XmlFileManager>(
fState);
97 fNtupleFileManager = std::make_shared<G4XmlNtupleFileManager>(
fState);
98 fNtupleFileManager->SetFileManager(fFileManager);
106 fgInstance =
nullptr;
114G4bool G4XmlAnalysisManager::WriteH1()
119 if ( ! h1Vector.size() )
return true;
124 auto directoryName = fFileManager->GetHistoDirectoryName();
125 result = WriteT(h1Vector, hnVector, directoryName,
"h1");
139G4bool G4XmlAnalysisManager::WriteH2()
144 if ( ! h2Vector.size() )
return true;
149 auto directoryName = fFileManager->GetHistoDirectoryName();
150 result = WriteT(h2Vector, hnVector, directoryName,
"h2");
164G4bool G4XmlAnalysisManager::WriteH3()
169 if ( ! h3Vector.size() )
return true;
174 auto directoryName = fFileManager->GetHistoDirectoryName();
175 result = WriteT(h3Vector, hnVector, directoryName,
"h3");
189G4bool G4XmlAnalysisManager::WriteP1()
194 if ( ! p1Vector.size() )
return true;
199 auto directoryName = fFileManager->GetHistoDirectoryName();
200 result = WriteT(p1Vector, hnVector, directoryName,
"p1");
214G4bool G4XmlAnalysisManager::WriteP2()
219 if ( ! p2Vector.size() )
return true;
224 auto directoryName = fFileManager->GetHistoDirectoryName();
225 result = WriteT(p2Vector, hnVector, directoryName,
"p2");
239G4bool G4XmlAnalysisManager::Reset()
243 auto finalResult =
true;
246 finalResult = finalResult && result;
248 result = fNtupleFileManager->Reset();
249 finalResult = finalResult && result;
265 auto finalResult =
true;
268 auto result = fFileManager->OpenFile(fileName);
269 finalResult = finalResult && result;
272 result = fNtupleFileManager->ActionAtOpenFile(fFileManager->GetFullFileName());
273 finalResult = finalResult && result;
281 auto finalResult =
true;
290 fNtupleFileManager->ActionAtWrite();
292 if ( ! fgMasterInstance &&
299 <<
" " <<
"No master G4XmlAnalysisManager instance exists."
301 <<
" " <<
"Histogram 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;
328 result =
WriteAscii(fFileManager->GetFileName());
329 finalResult = finalResult && result;
344 auto finalResult =
true;
352 auto result = fFileManager->CloseFiles();
353 finalResult = finalResult && result;
360 result = fNtupleFileManager->ActionAtCloseFile(reset);
361 finalResult = finalResult && result;
368 description <<
" " <<
"Resetting data failed";
372 finalResult = finalResult && result;
377 if ( fFileManager->GetFile() &&
380 result = ! std::remove(fFileManager->GetFullFileName());
384 description <<
" " <<
"Removing file "
385 << fFileManager->GetFullFileName() <<
" failed";
389 finalResult = finalResult && result;
393 ->
Message(
"delete",
"empty file", fFileManager->GetFullFileName());
400 ->
Message(
"close",
"files",
"");
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
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 G4bool IsInstance()
static G4XmlAnalysisManager * Instance()
virtual G4bool CloseFileImpl(G4bool reset) final
virtual G4bool WriteImpl() final
virtual G4bool OpenFileImpl(const G4String &fileName) final
G4XmlAnalysisManager(G4bool isMaster=true)