51 G4String inFunction =
"G4GenericAnalysisManager::Write" + hnType;
53 description <<
"Failed to get " << hnType <<
" id " <<
id <<
G4endl;
65 if ( fgInstance ==
nullptr ) {
76 return ( fgInstance !=
nullptr );
82 fFileManager(nullptr),
83 fNtupleFileManager(nullptr)
85 if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
89 <<
"G4GenericAnalysisManager already exists."
90 <<
"Cannot create another instance.";
91 G4Exception(
"G4GenericAnalysisManager::G4GenericAnalysisManager()",
94 if ( isMaster ) fgMasterInstance =
this;
98 fFileManager = std::make_shared<G4GenericFileManager>(
fState);
106 fgInstance =
nullptr;
114void G4GenericAnalysisManager::CreateNtupleFileManager(
const G4String& fileName)
116 if ( fNtupleFileManager ) {
120 <<
"The ntuple file manager already exists.";
121 G4Exception(
"G4GenericAnalysisManager::CreateNtupleFileManager",
128 if ( output == G4AnalysisOutput::kNone ) {
131 <<
"The file type " << fileType <<
"is not supported.";
132 G4Exception(
"G4GenericAnalysisManager::CreateNtupleFileManager",
146 fNtupleFileManager = fFileManager->CreateNtupleFileManager(output);
147 if (fNtupleFileManager) {
151 if ( fNtupleFileManager->IsNtupleMergingSupported() ) {
153 fNtupleFileManager->SetNtupleMerging(fMergeNtuples, fNofNtupleFiles);
154 fNtupleFileManager->SetNtupleRowWise(fNtupleRowWise, fNtupleRowMode);
155 fNtupleFileManager->SetBasketSize(fBasketSize);
156 fNtupleFileManager->SetBasketEntries(fBasketEntries);
158 else if ( fIsNtupleMergingSet && fMergeNtuples ) {
161 <<
" " <<
"Ntuple merging is not available with "
162 << fileType <<
" output." <<
G4endl
163 <<
" " <<
"Setting is ignored.";
164 G4Exception(
"G4GenericAnalysisManager::CreateNtupleFileManager",
183 auto fullFileName = fileName;
186 fullFileName = fileName +
"." + fFileManager->GetDefaultFileType();
196 if (! fNtupleFileManager) {
197 CreateNtupleFileManager(fullFileName);
202 if (fNtupleFileManager) {
206 auto finalResult =
true;
209 auto result = fFileManager->OpenFile(fullFileName);
210 finalResult = finalResult && result;
213 if (fNtupleFileManager) {
214 result = fNtupleFileManager->ActionAtOpenFile(fullFileName);
215 finalResult = finalResult && result;
235 auto finalResult =
true;
238 if ( ! fgMasterInstance &&
244 <<
" " <<
"No master G4GenericAnalysisManager instance exists."
246 <<
" " <<
"Histogram/profile data will not be merged.";
253 finalResult = finalResult && result;
259 fFileManager->OpenFiles();
264 finalResult = finalResult && result;
267 finalResult = finalResult && result;
270 finalResult = finalResult && result;
273 finalResult = finalResult && result;
276 finalResult = finalResult && result;
280 if (fNtupleFileManager) {
281 result = fNtupleFileManager->ActionAtWrite();
282 finalResult = finalResult && result;
286 result = fFileManager->WriteFiles();
287 finalResult = finalResult && result;
291 result =
WriteAscii(fFileManager->GetFileName());
292 finalResult = finalResult && result;
307 auto finalResult =
true;
315 if (fNtupleFileManager) {
316 auto result = fNtupleFileManager->ActionAtCloseFile(reset);
317 finalResult = finalResult && result;
321 auto result = fFileManager->CloseFiles();
324 description <<
" " <<
"Closing files failed";
325 G4Exception(
"G4GenericAnalysisManager::CloseFile()",
328 finalResult = finalResult && result;
331 result = fFileManager->DeleteEmptyFiles();
334 description <<
" " <<
"Deleting empty files failed";
335 G4Exception(
"G4GenericAnalysisManager::CloseFile()",
338 finalResult = finalResult && result;
344 description <<
" " <<
"Resetting data failed";
345 G4Exception(
"G4GenericAnalysisManager::CloseFile()",
349 finalResult = finalResult && result;
365 auto finalResult =
true;
368 finalResult = finalResult && result;
370 result = fNtupleFileManager->Reset();
371 finalResult = result && finalResult;
413 auto h1d =
GetH1(
id,
false);
415 WriteHnException(
"H1",
id);
420 return fFileManager->WriteTExtra<tools::histo::h1d>(fileName, h1d, h1Name);
432 auto h2d =
GetH2(
id,
false);
434 WriteHnException(
"H2",
id);
439 return fFileManager->WriteTExtra<tools::histo::h2d>(fileName, h2d, h2Name);
450 auto h3d =
GetH3(
id,
false);
452 WriteHnException(
"H3",
id);
457 return fFileManager->WriteTExtra<tools::histo::h3d>(fileName, h3d, h3Name);
469 auto p1d =
GetP1(
id,
false);
471 WriteHnException(
"P1",
id);
476 return fFileManager->WriteTExtra<tools::histo::p1d>(fileName, p1d, p1Name);
487 auto p2d =
GetP2(
id,
false);
489 WriteHnException(
"P2",
id);
494 return fFileManager->WriteTExtra<tools::histo::p2d>(fileName, p2d, p2Name);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4MUTEX_INITIALIZER
const G4AnalysisVerbose * GetVerboseL3() const
G4bool GetIsMaster() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const
G4bool WriteP2(G4int id, const G4String &fileName)
G4bool WriteH2(G4int id, const G4String &fileName)
virtual G4bool CloseFileImpl(G4bool reset=true) override
G4bool WriteH3(G4int id, const G4String &fileName)
G4bool WriteH1(G4int id, const G4String &fileName)
static G4bool IsInstance()
G4GenericAnalysisManager(G4bool isMaster=true)
virtual G4bool WriteImpl() final
virtual ~G4GenericAnalysisManager()
virtual G4bool Reset() final
G4bool WriteP1(G4int id, const G4String &fileName)
static G4GenericAnalysisManager * Instance()
virtual G4bool OpenFileImpl(const G4String &fileName) override
void Merge(G4Mutex &mergeMutex, G4THnManager< T > *masterInstance)
G4String GetH1Name(G4int id) const
G4String GetH2Name(G4int id) const
G4String GetP2Name(G4int id) const
std::shared_ptr< G4NtupleBookingManager > fNtupleBookingManager
G4AnalysisManagerState fState
G4String GetP1Name(G4int id) const
G4String GetH3Name(G4int id) const
void SetFileManager(std::shared_ptr< G4VFileManager > fileManager)
G4bool WriteAscii(const G4String &fileName)
void SetNtupleManager(std::shared_ptr< G4VNtupleManager > ntupleManager)
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)