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;
114 ntupleBooking->
Reset();
126 fCurrentNtupleId = ntupleBooking->
fNtupleId;
129 name +
" ntupleId " + to_string(ntupleBooking->
fNtupleId));
131 return fCurrentNtupleId;
136 std::vector<int>* vector)
143 std::vector<float>* vector)
150 std::vector<double>* vector)
157 std::vector<std::string>* vector)
170 G4int ntupleId,
const G4String& name, std::vector<int>* vector)
172 return CreateNtupleTColumn<int>(ntupleId, name, vector);
177 G4int ntupleId,
const G4String& name, std::vector<float>* vector)
179 return CreateNtupleTColumn<float>(ntupleId, name, vector);
184 G4int ntupleId,
const G4String& name, std::vector<double>* vector)
186 return CreateNtupleTColumn<double>(ntupleId, name, vector);
191 G4int ntupleId,
const G4String& name, std::vector<std::string>* vector)
193 return CreateNtupleTColumn<std::string>(ntupleId, name, vector);
201 return GetNtupleBookingInFunction(ntupleId,
"FinishNtuple");
207 if ( fLockFirstNtupleColumnId ) {
208 Warn(
"Cannot set FirstNtupleColumnId as its value was already used.",
209 fkClass,
"SetFirstNtupleColumnId");
213 fFirstNtupleColumnId = firstId;
222 ntupleBooking->fActivation = activation;
231 = GetNtupleBookingInFunction(ntupleId,
"SetActivation");
232 if (ntupleBooking ==
nullptr)
return;
234 ntupleBooking->fActivation = activation;
239 G4int ntupleId)
const
242 = GetNtupleBookingInFunction(ntupleId,
"GetActivation");
243 if (ntupleBooking ==
nullptr)
return false;
245 return ntupleBooking->fActivation;
253 ntupleBooking->fFileName = fileName;
262 = GetNtupleBookingInFunction(ntupleId,
"SetFileName");
263 if (ntupleBooking ==
nullptr)
return;
266 if ( ntupleBooking->fFileName == fileName )
return;
268 auto ntupleFileName = fileName;
270 if (extension.size() != 0u) {
274 Warn(
"The file extension " + extension +
" is not supported.",
275 fkClass,
"SetFileName");
280 if (fFileType.size() != 0u) {
282 ntupleFileName = fileName +
"." + fFileType;
289 ntupleBooking->fFileName = ntupleFileName;
294 G4int ntupleId)
const
297 = GetNtupleBookingInFunction(ntupleId,
"GetFileName");
298 if (ntupleBooking ==
nullptr)
return "";
300 return ntupleBooking->fFileName;
307 delete ntupleBooking;
310 fLockFirstNtupleColumnId =
false;
318 Message(
kVL4,
"delete",
"ntuple booking ntupleId " + to_string(
id));
320 auto ntupleBooking = GetNtupleBookingInFunction(
id,
"Delete",
true);
322 if (ntupleBooking ==
nullptr)
return false;
325 ntupleBooking->SetDeleted(
true, keepSetting);
339 std::ios_base::fmtflags outputFlags(output.flags() );
342 size_t maxNameLength = 0;
343 size_t maxTitleLength = 0;
345 size_t nofActive = 0;
347 const auto& ntupleBooking = g4NtupleBooking->fNtupleBooking;
348 if (ntupleBooking.name().length() > maxNameLength) {
349 maxNameLength = ntupleBooking.name().length();
351 if (ntupleBooking.title().length() > maxTitleLength) {
352 maxTitleLength = ntupleBooking.title().length();
357 if (g4NtupleBooking->fActivation) {
367 output <<
"Ntuple: " << nofActive <<
" active ";
368 if (! onlyIfActive) {
376 const auto& ntupleBooking = g4NtupleBooking->fNtupleBooking;
382 output <<
" id: " << std::setw((
G4int)maxIdWidth) <<
GetFirstId() + counter++
383 <<
" name: \"" << std::setw((
G4int)maxNameLength) << std::left << ntupleBooking.name() +
"\""
384 <<
" title: \"" << std::setw((
G4int)maxTitleLength) << std::left << ntupleBooking.title() +
"\"";
386 if (! onlyIfActive) {
387 output <<
" active: " << std::boolalpha << g4NtupleBooking->fActivation;
393 output.flags(outputFlags);
395 return output.good();
406 if ( fFileType == fileType )
return;
409 fFileType = fileType;
414 if ((ntupleBooking->fFileName).size() == 0u)
continue;
416 auto extension =
GetExtension(ntupleBooking->fFileName);
417 if ( fFileType == extension )
continue;
420 auto baseFileName =
GetBaseName(ntupleBooking->fFileName);
421 auto ntupleFileName = baseFileName +
"." + fFileType;
422 if (extension.size() != 0u) {
423 Warn(
"Writing ntuples in files of different output types " +
424 fFileType +
", " + extension +
" is not supported.",
425 fkClass,
"SetFileType");
429 ntupleBooking->fFileName = ntupleFileName;
444 auto g4Booking = GetNtupleBookingInFunction(ntupleId,
"GetNtuple", warn);
446 if (g4Booking ==
nullptr)
return nullptr;
448 if ( ( g4Booking->GetDeleted() ) ||
449 ( onlyIfActive && (! g4Booking->fActivation) ) )
return nullptr;
451 return &(g4Booking->fNtupleBooking);
G4bool GetIsActivation() const
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
const G4AnalysisManagerState & fState
G4bool GetActivation(G4int ntupleId) const
G4bool SetFirstNtupleColumnId(G4int firstId)
std::vector< G4NtupleBooking * > fNtupleBookingVector
G4int GetNofNtuples(G4bool onlyIfExist=false) const
G4String GetFileName(G4int id) const
G4int CreateNtupleSColumn(const G4String &name, std::vector< std::string > *vector)
G4NtupleBooking * FinishNtuple()
G4bool Delete(G4int id, G4bool keepSetting)
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
std::set< G4int > fFreeIds
G4NtupleBookingManager()=delete
void SetFileName(const G4String &fileName)
G4bool List(std::ostream &output, G4bool onlyIfActive=true)
tools::ntuple_booking * GetNtuple(G4bool warn, G4bool onlyIfActive) const
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)
tools::ntuple_booking fNtupleBooking