47 std::string_view inClass,
48 std::string_view inFunction)
50 Warn(
"Failed to get " + hnType +
" id " + to_string(
id), inClass, inFunction);
70G4GenericAnalysisManager::G4GenericAnalysisManager()
76 fFileManager = std::make_shared<G4GenericFileManager>(
fState);
92void G4GenericAnalysisManager::CreateNtupleFileManager(
const G4String& fileName)
94 if ( fNtupleFileManager ) {
95 Warn(
"The ntuple file manager already exists.",
96 fkClass,
"CreateNtupleFileManager");
103 Warn(
"The file type " + fileType +
"is not supported.",
104 fkClass,
"CreateNtupleFileManager");
111 Message(
kVL4,
"create",
"ntuple file manager", fileType);
113 fNtupleFileManager = fFileManager->CreateNtupleFileManager(output);
114 if (fNtupleFileManager) {
118 if ( fNtupleFileManager->IsNtupleMergingSupported() ) {
120 fNtupleFileManager->SetNtupleMerging(fMergeNtuples, fNofNtupleFiles);
121 fNtupleFileManager->SetNtupleRowWise(fNtupleRowWise, fNtupleRowMode);
122 fNtupleFileManager->SetBasketSize(fBasketSize);
123 fNtupleFileManager->SetBasketEntries(fBasketEntries);
125 else if ( fIsNtupleMergingSet && fMergeNtuples ) {
126 Warn(
"Ntuple merging is not available with " + fileType +
" output.\n" +
127 "Setting is ignored.",
128 fkClass,
"CreateNtupleFileManager");
132 Message(
kVL3,
"create",
"ntuple file manager", fileType);
145 auto fullFileName = fileName;
147 auto defaultFileType = fFileManager->GetDefaultFileType();
149 if (defaultFileType.size() == 0u) {
150 G4Exception(
"G4GenericAnalysisManager::OpenFileImpl",
"Analysis_F001",
152 G4String(
"Cannot open file \"" + fileName +
"\".\n"
153 "Please, use a file name with an extension or define the default file type\n"
154 "via G4AnalysisManager::SetDefaultFileType()"));
157 fullFileName = fileName +
"." + fFileManager->GetDefaultFileType();
161 if (! fNtupleFileManager) {
162 CreateNtupleFileManager(fullFileName);
166 if (fNtupleFileManager) {
171 result &= fFileManager->OpenFile(fullFileName);
184 fFileManager->SetDefaultFileType(value);
196 auto h1d =
GetH1(
id,
false);
197 if (h1d ==
nullptr) {
198 WriteHnWarning(
"H1",
id, fkClass,
"WriteH1");
203 return fFileManager->WriteTExtra<tools::histo::h1d>(fileName, h1d, h1Name);
215 auto h2d =
GetH2(
id,
false);
216 if (h2d ==
nullptr) {
217 WriteHnWarning(
"H2",
id, fkClass,
"WriteH2");
222 return fFileManager->WriteTExtra<tools::histo::h2d>(fileName, h2d, h2Name);
233 auto h3d =
GetH3(
id,
false);
234 if (h3d ==
nullptr) {
235 WriteHnWarning(
"H3",
id, fkClass,
"WriteH3");
240 return fFileManager->WriteTExtra<tools::histo::h3d>(fileName, h3d, h3Name);
252 auto p1d =
GetP1(
id,
false);
253 if (p1d ==
nullptr) {
254 WriteHnWarning(
"P1",
id, fkClass,
"WriteP1");
259 return fFileManager->WriteTExtra<tools::histo::p1d>(fileName, p1d, p1Name);
271 auto p2d =
GetP2(
id,
false);
272 if (p2d ==
nullptr) {
273 WriteHnWarning(
"P2",
id, fkClass,
"WriteP2");
278 return fFileManager->WriteTExtra<tools::histo::p2d>(fileName, p2d, p2Name);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4bool GetIsMaster() const
G4bool WriteP2(G4int id, const G4String &fileName)
G4bool WriteH2(G4int id, const G4String &fileName)
tools::ntuple_booking * GetNtuple(G4bool warn=true, G4bool onlyIfActive=true) const
~G4GenericAnalysisManager() override
G4bool WriteH3(G4int id, const G4String &fileName)
G4bool WriteH1(G4int id, const G4String &fileName)
static G4bool IsInstance()
G4bool WriteP1(G4int id, const G4String &fileName)
static G4GenericAnalysisManager * Instance()
G4bool OpenFileImpl(const G4String &fileName) override
void SetDefaultFileTypeImpl(const G4String &value) override
virtual void SetDefaultFileTypeImpl(const G4String &value)
G4String GetH1Name(G4int id) const
G4String GetH2Name(G4int id) const
G4String GetP2Name(G4int id) const
std::shared_ptr< G4NtupleBookingManager > fNtupleBookingManager
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
G4AnalysisManagerState fState
G4String GetP1Name(G4int id) const
G4String GetH3Name(G4int id) const
void SetFileManager(std::shared_ptr< G4VFileManager > fileManager)
void SetNtupleFileManager(std::shared_ptr< G4VNtupleFileManager > ntupleFileManager)
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)