48 std::string_view inClass,
49 std::string_view inFunction)
51 Warn(
"Failed to get " + hnType +
" id " + to_string(
id), inClass, inFunction);
71G4GenericAnalysisManager::G4GenericAnalysisManager()
74 fMessenger = std::make_unique<G4GenericAnalysisMessenger>(
this);
79 fFileManager = std::make_shared<G4GenericFileManager>(
fState);
95void G4GenericAnalysisManager::CreateNtupleFileManager(
const G4String& fileName)
97 if ( fNtupleFileManager ) {
98 Warn(
"The ntuple file manager already exists.",
99 fkClass,
"CreateNtupleFileManager");
105 if ( output == G4AnalysisOutput::kNone ) {
106 Warn(
"The file type " + fileType +
"is not supported.",
107 fkClass,
"CreateNtupleFileManager");
114 Message(
kVL4,
"create",
"ntuple file manager", fileType);
116 fNtupleFileManager = fFileManager->CreateNtupleFileManager(output);
117 if (fNtupleFileManager) {
121 if ( fNtupleFileManager->IsNtupleMergingSupported() ) {
123 fNtupleFileManager->SetNtupleMerging(fMergeNtuples, fNofNtupleFiles);
124 fNtupleFileManager->SetNtupleRowWise(fNtupleRowWise, fNtupleRowMode);
125 fNtupleFileManager->SetBasketSize(fBasketSize);
126 fNtupleFileManager->SetBasketEntries(fBasketEntries);
128 else if ( fIsNtupleMergingSet && fMergeNtuples ) {
129 Warn(
"Ntuple merging is not available with " + fileType +
" output.\n" +
130 "Setting is ignored.",
131 fkClass,
"CreateNtupleFileManager");
135 Message(
kVL3,
"create",
"ntuple file manager", fileType);
148 auto fullFileName = fileName;
150 auto defaultFileType = fFileManager->GetDefaultFileType();
152 if (defaultFileType.size() == 0u) {
153 G4Exception(
"G4GenericAnalysisManager::OpenFileImpl",
"Analysis_F001",
155 G4String(
"Cannot open file \"" + fileName +
"\".\n"
156 "Please, use a file name with an extension or define the default file type\n"
157 "via G4AnalysisManager::SetDefaultFileType()"));
160 fullFileName = fileName +
"." + fFileManager->GetDefaultFileType();
164 if (! fNtupleFileManager) {
165 CreateNtupleFileManager(fullFileName);
169 if (fNtupleFileManager) {
174 result &= fFileManager->OpenFile(fullFileName);
191 auto h1d =
GetH1(
id,
false);
192 if (h1d ==
nullptr) {
193 WriteHnWarning(
"H1",
id, fkClass,
"WriteH1");
198 return fFileManager->WriteTExtra<tools::histo::h1d>(fileName, h1d, h1Name);
210 auto h2d =
GetH2(
id,
false);
211 if (h2d ==
nullptr) {
212 WriteHnWarning(
"H2",
id, fkClass,
"WriteH2");
217 return fFileManager->WriteTExtra<tools::histo::h2d>(fileName, h2d, h2Name);
228 auto h3d =
GetH3(
id,
false);
229 if (h3d ==
nullptr) {
230 WriteHnWarning(
"H3",
id, fkClass,
"WriteH3");
235 return fFileManager->WriteTExtra<tools::histo::h3d>(fileName, h3d, h3Name);
247 auto p1d =
GetP1(
id,
false);
248 if (p1d ==
nullptr) {
249 WriteHnWarning(
"P1",
id, fkClass,
"WriteP1");
254 return fFileManager->WriteTExtra<tools::histo::p1d>(fileName, p1d, p1Name);
265 auto p2d =
GetP2(
id,
false);
266 if (p2d ==
nullptr) {
267 WriteHnWarning(
"P2",
id, fkClass,
"WriteP2");
272 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)
~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
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)