56G4NtupleBookingManager::GetNtupleBookingInFunction(
57 G4int id, std::string_view functionName,
G4bool warn)
const
62 Warn(
"Ntuple booking " + to_string(
id) +
" does not exist.",
63 fkClass, functionName);
72G4bool G4NtupleBookingManager::CheckName(
75 if (
name.size() == 0u) {
76 Warn(
"Empty " + objectType +
" name is not allowed.\n" +
77 objectType +
" was not created.", fkClass,
"CheckName");
97 if ( ! CheckName(name,
"Ntuple") )
return kInvalidId;
107 ntupleBooking->fNtupleBooking.set_name(name);
108 ntupleBooking->fNtupleBooking.set_title(title);
115 name +
" ntupleId " + to_string(ntupleBooking->fNtupleId));
117 return ntupleBooking->fNtupleId;
122 std::vector<int>* vector)
129 std::vector<float>* vector)
136 std::vector<double>* vector)
143 std::vector<std::string>* vector)
156 G4int ntupleId,
const G4String& name, std::vector<int>* vector)
158 return CreateNtupleTColumn<int>(ntupleId, name, vector);
163 G4int ntupleId,
const G4String& name, std::vector<float>* vector)
165 return CreateNtupleTColumn<float>(ntupleId, name, vector);
170 G4int ntupleId,
const G4String& name, std::vector<double>* vector)
172 return CreateNtupleTColumn<double>(ntupleId, name, vector);
177 G4int ntupleId,
const G4String& name, std::vector<std::string>* vector)
179 return CreateNtupleTColumn<std::string>(ntupleId, name, vector);
187 return GetNtupleBookingInFunction(ntupleId,
"FinishNtuple");
193 if ( fLockFirstNtupleColumnId ) {
194 Warn(
"Cannot set FirstNtupleColumnId as its value was already used.",
195 fkClass,
"SetFirstNtupleColumnId");
199 fFirstNtupleColumnId = firstId;
208 ntupleBooking->fActivation = activation;
217 = GetNtupleBookingInFunction(ntupleId,
"SetActivation");
218 if (ntupleBooking ==
nullptr)
return;
220 ntupleBooking->fActivation = activation;
225 G4int ntupleId)
const
228 = GetNtupleBookingInFunction(ntupleId,
"GetActivation");
229 if (ntupleBooking ==
nullptr)
return false;
231 return ntupleBooking->fActivation;
239 ntupleBooking->fFileName = fileName;
248 = GetNtupleBookingInFunction(ntupleId,
"SetFileName");
249 if (ntupleBooking ==
nullptr)
return;
252 if ( ntupleBooking->fFileName == fileName )
return;
254 auto ntupleFileName = fileName;
256 if (extension.size() != 0u) {
259 if ( output == G4AnalysisOutput::kNone ) {
260 Warn(
"The file extension " + extension +
" is not supported.",
261 fkClass,
"SetFileName");
266 if (fFileType.size() != 0u) {
268 ntupleFileName = fileName +
"." + fFileType;
275 ntupleBooking->fFileName = ntupleFileName;
280 G4int ntupleId)
const
283 = GetNtupleBookingInFunction(ntupleId,
"GetFileName");
284 if (ntupleBooking ==
nullptr)
return "";
286 return ntupleBooking->fFileName;
293 delete ntupleBooking;
296 fLockFirstNtupleColumnId =
false;
309 if ( fFileType == fileType )
return;
312 fFileType = fileType;
317 if ((ntupleBooking->fFileName).size() == 0u)
continue;
319 auto extension =
GetExtension(ntupleBooking->fFileName);
320 if ( fFileType == extension )
continue;
323 auto baseFileName =
GetBaseName(ntupleBooking->fFileName);
324 auto ntupleFileName = baseFileName +
"." + fFileType;
325 if (extension.size() != 0u) {
326 Warn(
"Writing ntuples in files of different output types " +
327 fFileType +
", " + extension +
" is not supported.",
328 fkClass,
"SetFileType");
332 ntupleBooking->fFileName = ntupleFileName;
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
G4bool GetActivation(G4int ntupleId) const
G4bool SetFirstNtupleColumnId(G4int firstId)
std::vector< G4NtupleBooking * > fNtupleBookingVector
G4String GetFileName(G4int id) const
G4int CreateNtupleSColumn(const G4String &name, std::vector< std::string > *vector)
G4NtupleBooking * FinishNtuple()
G4int CreateNtupleDColumn(const G4String &name, std::vector< double > *vector)
G4int CreateNtuple(const G4String &name, const G4String &title)
G4int CreateNtupleFColumn(const G4String &name, std::vector< float > *vector)
~G4NtupleBookingManager() override
G4NtupleBookingManager()=delete
void SetFileName(const G4String &fileName)
G4int CreateNtupleIColumn(const G4String &name, std::vector< int > *vector)
void SetFileType(const G4String &fileType)
void SetActivation(G4bool activation)
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)
constexpr G4int kInvalidId
G4String GetBaseName(const G4String &fileName)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
const char * name(G4int ptype)