46 fNtupleDir = std::make_unique<G4UIdirectory>(
"/analysis/ntuple/");
47 fNtupleDir->SetGuidance(
"ntuple control");
54 SetActivationToAllCmd();
56 SetFileNameToAllCmd();
68void G4NtupleMessenger::AddIdParameter(
G4UIcommand& command)
71 ntupleId->SetGuidance(
"Ntuple id");
72 ntupleId->SetParameterRange(
"NtupleId>=0");
78void G4NtupleMessenger::CreateCmd()
80 fCreateCmd = CreateCommand<G4UIcommand>(
"create",
"Create ntuple");
83 ntName->SetGuidance(
"Ntuple name");
84 fCreateCmd->SetParameter(ntName);
87 ntTitle->SetGuidance(
"Ntuple title");
88 fCreateCmd->SetParameter(ntTitle);
92void G4NtupleMessenger::CreateColumnCmds()
94 std::vector<char> colTypes = {
'I',
'F',
'D',
'S'};
96 for (
auto colType : colTypes ) {
98 G4String guidance =
"Create ntuple column";
99 name.insert(6, 1, colType);
100 guidance.insert(7, 1, colType);
101 auto cmd = CreateCommand<G4UIcmdWithAString>(name, guidance);
102 fCreateColumnCmds[colType] = std::move(cmd);
107void G4NtupleMessenger::FinishCmd()
109 fFinishCmd = CreateCommand<G4UIcmdWithoutParameter>(
110 "finish",
"Finish creating ntuple");
114void G4NtupleMessenger::DeleteCmd()
116 fDeleteCmd = CreateCommand<G4UIcommand>(
117 "delete",
"Delete ntuple with given id");
120 AddIdParameter(*fDeleteCmd);
122 auto parKeepSetting =
new G4UIparameter(
"keepSetting",
'b',
true);
124 "If set true, activation, file name, etc. options will be kept\n"
125 "and applied when a new object with the same id is created.";
126 parKeepSetting->SetGuidance(guidance.c_str());
127 parKeepSetting->SetDefaultValue(
"false");
128 fDeleteCmd->SetParameter(parKeepSetting);
132void G4NtupleMessenger::SetActivationCmd()
134 fSetActivationCmd = CreateCommand<G4UIcommand>(
135 "setActivation",
"Set activation for the ntuple with given id");
137 AddIdParameter(*fSetActivationCmd);
139 auto ntupleActivation =
new G4UIparameter(
"NtupleActivation",
'b',
true);
140 ntupleActivation->SetGuidance(
"Ntuple activation");
141 ntupleActivation->SetDefaultValue(
true);
142 fSetActivationCmd->SetParameter(ntupleActivation);
146void G4NtupleMessenger::SetActivationToAllCmd()
148 fSetActivationAllCmd = CreateCommand<G4UIcmdWithABool>(
149 "setActivationToAll",
"Set activation to all ntuples");
150 fSetActivationAllCmd->SetParameterName(
"AllNtupleActivation",
false);
154void G4NtupleMessenger::SetFileNameCmd()
156 fSetFileNameCmd = CreateCommand<G4UIcommand>(
157 "setFileName",
"Set file name for the ntuple with given id");
159 AddIdParameter(*fSetFileNameCmd);
161 auto ntupleFileName =
new G4UIparameter(
"NtupleFileName",
's',
false);
162 ntupleFileName->SetGuidance(
"Ntuple file name");
163 fSetFileNameCmd->SetParameter(ntupleFileName);
167void G4NtupleMessenger::SetFileNameToAllCmd()
169 fSetFileNameAllCmd = CreateCommand<G4UIcmdWithAString>(
170 "setFileNameToAll",
"Set file name to all ntuples");
171 fSetFileNameAllCmd->SetParameterName(
"AllNtupleFileName",
false);
175void G4NtupleMessenger::ListCmd()
177 fListCmd = CreateCommand<G4UIcommand>(
"list",
"List all/active ntuples");
180 auto parOnlyIfActive =
new G4UIparameter(
"onlyIfActive",
'b',
true);
181 parOnlyIfActive->SetGuidance(
"Option whether to list only active objects");
182 parOnlyIfActive->SetDefaultValue(
"true");
183 fListCmd->SetParameter(parOnlyIfActive);
195 if ( command == fSetActivationAllCmd.get() ) {
196 fManager->
SetActivation(fSetActivationAllCmd->GetNewBoolValue(newValues));
200 if ( command == fSetFileNameAllCmd.get() ) {
206 std::vector<G4String> parameters;
213 "\" parameters: " + std::to_string(parameters.size()) +
215 fkClass,
"WarnAboutParameters");
223 if ( command == fCreateCmd.get() ) {
224 auto name = parameters[counter++];
225 auto title = parameters[counter++];
230 for (
const auto& [colType, checkCommand] : fCreateColumnCmds) {
231 if ( command == checkCommand.get() ) {
232 auto name = parameters[counter++];
252 if ( command == fFinishCmd.get() ) {
262 if ( command == fDeleteCmd.get() ) {
268 if ( command == fSetActivationCmd.get() ) {
273 if ( command == fSetFileNameCmd.get() ) {
278 if ( command == fListCmd.get() ) {
void SetNewValue(G4UIcommand *command, G4String value) final
~G4NtupleMessenger() override
G4NtupleMessenger()=delete
std::size_t GetParameterEntries() const
void SetParameter(G4UIparameter *const newParameter)
static G4int ConvertToInt(const char *st)
static G4bool ConvertToBool(const char *st)
const G4String & GetCommandName() const
G4bool ListNtuple(G4bool onlyIfActive=true) const
G4bool DeleteNtuple(G4int id, G4bool clear=false)
G4int CreateNtupleIColumn(const G4String &name)
G4int CreateNtupleDColumn(const G4String &name)
void SetNtupleFileName(const G4String &fileName)
G4int CreateNtupleFColumn(const G4String &name)
void SetActivation(G4bool activation)
G4int CreateNtupleSColumn(const G4String &name)
G4int CreateNtuple(const G4String &name, const G4String &title)
G4bool SetFileName(const G4String &fileName)
void SetNtupleActivation(G4bool activation)
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
constexpr G4int kInvalidId
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
const char * name(G4int ptype)