Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4NtupleMessenger Class Reference

#include <G4NtupleMessenger.hh>

+ Inheritance diagram for G4NtupleMessenger:

Public Member Functions

 G4NtupleMessenger (G4VAnalysisManager *manager)
 
 G4NtupleMessenger ()=delete
 
 ~G4NtupleMessenger () override
 
void SetNewValue (G4UIcommand *command, G4String value) final
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()=default
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String LtoS (G4long l)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (const G4String &s)
 
G4long StoL (const G4String &s)
 
G4double StoD (const G4String &s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 

Detailed Description

Definition at line 50 of file G4NtupleMessenger.hh.

Constructor & Destructor Documentation

◆ G4NtupleMessenger() [1/2]

G4NtupleMessenger::G4NtupleMessenger ( G4VAnalysisManager * manager)
explicit

Definition at line 43 of file G4NtupleMessenger.cc.

44 : fManager(manager)
45{
46 fNtupleDir = std::make_unique<G4UIdirectory>("/analysis/ntuple/");
47 fNtupleDir->SetGuidance("ntuple control");
48
49 CreateCmd();
50 CreateColumnCmds();
51 FinishCmd();
52 DeleteCmd();
53 SetActivationCmd();
54 SetActivationToAllCmd();
55 SetFileNameCmd();
56 SetFileNameToAllCmd();
57 ListCmd();
58}

◆ G4NtupleMessenger() [2/2]

G4NtupleMessenger::G4NtupleMessenger ( )
delete

◆ ~G4NtupleMessenger()

G4NtupleMessenger::~G4NtupleMessenger ( )
overridedefault

Member Function Documentation

◆ SetNewValue()

void G4NtupleMessenger::SetNewValue ( G4UIcommand * command,
G4String value )
finalvirtual

Reimplemented from G4UImessenger.

Definition at line 191 of file G4NtupleMessenger.cc.

192{
193 // process "All" commands first
194
195 if ( command == fSetActivationAllCmd.get() ) {
196 fManager->SetActivation(fSetActivationAllCmd->GetNewBoolValue(newValues));
197 return;
198 }
199
200 if ( command == fSetFileNameAllCmd.get() ) {
201 fManager->SetFileName(newValues);
202 return;
203 }
204
205 // Tokenize parameters in a vector
206 std::vector<G4String> parameters;
207 G4Analysis::Tokenize(newValues, parameters);
208 // check consistency
209 if ( parameters.size() != command->GetParameterEntries() ) {
210 // Should never happen but let's check anyway for consistency
212 "Got wrong number of \"" + command->GetCommandName() +
213 "\" parameters: " + std::to_string(parameters.size()) +
214 " instead of " + std::to_string(command->GetParameterEntries()) + " expected",
215 fkClass, "WarnAboutParameters");
216 return;
217 }
218
219 auto counter = 0;
220
221 // commands without Id parameter
222
223 if ( command == fCreateCmd.get() ) {
224 auto name = parameters[counter++];
225 auto title = parameters[counter++];
226 fTmpNtupleId = fManager->CreateNtuple(name, title);
227 return;
228 }
229
230 for (const auto& [colType, checkCommand] : fCreateColumnCmds) {
231 if ( command == checkCommand.get() ) {
232 auto name = parameters[counter++];
233 switch (colType) {
234 case 'I':
235 fManager->CreateNtupleIColumn(fTmpNtupleId, name);
236 return;
237 case 'F':
238 fManager->CreateNtupleFColumn(fTmpNtupleId, name);
239 return;
240 case 'D':
241 fManager->CreateNtupleDColumn(fTmpNtupleId, name);
242 return;
243 case 'S':
244 fManager->CreateNtupleSColumn(fTmpNtupleId, name);
245 return;
246 default:
247 return;
248 }
249 }
250 }
251
252 if ( command == fFinishCmd.get() ) {
253 fManager->FinishNtuple(fTmpNtupleId);
254 fTmpNtupleId = G4Analysis::kInvalidId;
255 return;
256 }
257
258 // commands with Id parameter
259
260 auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
261
262 if ( command == fDeleteCmd.get() ) {
263 auto keepSetting = G4UIcommand::ConvertToBool(parameters[counter++]);
264 fManager->DeleteNtuple(id, keepSetting);
265 return;
266 }
267
268 if ( command == fSetActivationCmd.get() ) {
269 fManager->SetNtupleActivation(id, G4UIcommand::ConvertToBool(parameters[counter++]));
270 return;
271 }
272
273 if ( command == fSetFileNameCmd.get() ) {
274 fManager->SetNtupleFileName(id, parameters[counter++]);
275 return;
276 }
277
278 if ( command == fListCmd.get() ) {
279 auto onlyIfActive = G4UIcommand::ConvertToBool(parameters[0]);
280 fManager->ListNtuple(onlyIfActive);
281 return;
282 }
283}
std::size_t GetParameterEntries() const
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)

The documentation for this class was generated from the following files: