58 if ( fgInstance ==
nullptr ) {
69 return ( fgInstance != 0 );
75 fNtupleManager(nullptr),
78 if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
82 <<
"G4XmlAnalysisManager already exists."
83 <<
"Cannot create another instance.";
84 G4Exception(
"G4XmlAnalysisManager::G4XmlAnalysisManager",
87 if ( isMaster ) fgMasterInstance =
this;
92 fFileManager = std::make_shared<G4XmlFileManager>(
fState);
93 fNtupleManager->SetFileManager(fFileManager);
105 fgInstance =
nullptr;
113 G4bool G4XmlAnalysisManager::WriteH1()
118 if ( ! h1Vector.size() )
return true;
123 auto directoryName = fFileManager->GetHistoDirectoryName();
124 result = WriteT(h1Vector, hnVector, directoryName,
"h1");
138 G4bool G4XmlAnalysisManager::WriteH2()
143 if ( ! h2Vector.size() )
return true;
148 auto directoryName = fFileManager->GetHistoDirectoryName();
149 result = WriteT(h2Vector, hnVector, directoryName,
"h2");
163 G4bool G4XmlAnalysisManager::WriteH3()
168 if ( ! h3Vector.size() )
return true;
173 auto directoryName = fFileManager->GetHistoDirectoryName();
174 result = WriteT(h3Vector, hnVector, directoryName,
"h3");
188 G4bool G4XmlAnalysisManager::WriteP1()
193 if ( ! p1Vector.size() )
return true;
198 auto directoryName = fFileManager->GetHistoDirectoryName();
199 result = WriteT(p1Vector, hnVector, directoryName,
"p1");
213 G4bool G4XmlAnalysisManager::WriteP2()
218 if ( ! p2Vector.size() )
return true;
223 auto directoryName = fFileManager->GetHistoDirectoryName();
224 result = WriteT(p2Vector, hnVector, directoryName,
"p2");
238 G4bool G4XmlAnalysisManager::WriteNtuple()
240 auto ntupleVector = fNtupleManager->GetNtupleDescriptionVector();
242 for (
auto ntuple : ntupleVector ) {
243 if ( ntuple->fNtuple ) ntuple->fNtuple->write_trailer();
250 G4bool G4XmlAnalysisManager::CloseNtupleFiles()
252 auto ntupleDescriptionVector = fNtupleManager->GetNtupleDescriptionVector();
255 for (
auto ntupleDescription : ntupleDescriptionVector) {
256 fFileManager->CloseNtupleFile((ntupleDescription));
264 G4bool G4XmlAnalysisManager::Reset()
268 auto finalResult =
true;
271 finalResult = finalResult &&
result;
273 result = fNtupleManager->
Reset(
true);
274 finalResult = finalResult &&
result;
286 auto finalResult =
true;
287 auto result = fFileManager->SetFileName(fileName);
288 finalResult = finalResult &&
result;
291 auto name = fFileManager->GetFullFileName();
298 result = fFileManager->OpenFile(fileName);
299 finalResult = finalResult &&
result;
303 result = fFileManager->CreateHnFile();
304 finalResult = finalResult &&
result;
322 auto finalResult =
true;
325 auto name = fFileManager->GetFullFileName();
333 if ( ! fgMasterInstance &&
340 <<
" " <<
"No master G4XmlAnalysisManager instance exists."
342 <<
" " <<
"Histogram data will not be merged.";
347 auto result = fFileManager->CreateHnFile();
348 if ( ! result )
return false;
352 auto result = WriteH1();
353 finalResult = finalResult &&
result;
357 finalResult = finalResult &&
result;
361 finalResult = finalResult &&
result;
365 finalResult = finalResult &&
result;
369 finalResult = finalResult &&
result;
373 result =
WriteAscii(fFileManager->GetFileName());
374 finalResult = finalResult &&
result;
380 ->
Message(
"write",
"file", fFileManager->GetFullFileName(), finalResult);
389 auto finalResult =
true;
397 auto result = fFileManager->CloseFile();
398 finalResult = finalResult &&
result;
401 result = fFileManager->CloseHnFile();
402 finalResult = finalResult &&
result;
405 result = CloseNtupleFiles();
406 finalResult = finalResult &&
result;
412 description <<
" " <<
"Resetting data failed";
416 finalResult = finalResult &&
result;
420 if ( fFileManager->GetHnFile().get() &&
423 result = ! std::remove(fFileManager->GetFullFileName());
427 description <<
" " <<
"Removing file "
428 << fFileManager->GetFullFileName() <<
" failed";
432 finalResult = finalResult &&
result;
436 ->
Message(
"delete",
"empty file", fFileManager->GetFullFileName());
443 ->
Message(
"close",
"files",
"");
G4double G4ParticleHPJENDLHEData::G4double result
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
std::ostringstream G4ExceptionDescription
virtual G4bool OpenFileImpl(const G4String &fileName) final
static G4XmlAnalysisManager * Instance()
G4XmlAnalysisManager(G4bool isMaster=true)
void CreateNtuplesFromBooking()
static G4bool IsInstance()
#define G4MUTEX_INITIALIZER
const G4AnalysisVerbose * GetVerboseL2() const
G4bool Reset(G4bool deleteNtuple)
const G4AnalysisVerbose * GetVerboseL4() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
void SetFileManager(std::shared_ptr< G4VFileManager > fileManager)
virtual G4bool WriteImpl() final
G4bool GetIsMaster() const
G4AnalysisManagerState fState
const G4AnalysisVerbose * GetVerboseL1() const
void SetNtupleManager(G4VNtupleManager *ntupleManager)
G4bool WriteAscii(const G4String &fileName)
virtual G4bool CloseFileImpl() final