4 // Author: I. Hrivnacova
6 // Class TG4VerboseMessenger
8 // See the class description in the header file.
10 #include "TG4VerboseMessenger.h"
11 #include "TG4VVerbose.h"
12 #include "TG4Globals.h"
14 #include <G4UIcmdWithAnInteger.hh>
15 #include <G4UIdirectory.hh>
16 #include <G4UImanager.hh>
17 #include <G4UIcommandTree.hh>
19 //_____________________________________________________________________________
20 TG4VerboseMessenger::TG4VerboseMessenger(const G4String& directoryName)
21 : fkDirectoryName(directoryName)
25 fDirectory = new G4UIdirectory(directoryName);
26 fDirectory->SetGuidance("TGeant4 verbose control commands.");
28 // sets the given level to all verbose instances
30 = new G4UIcmdWithAnInteger(G4String(directoryName + "all"), this);
31 G4String guidance("Set a given verbose level to all verbose instances.");
32 fGlobalVerboseCmd->SetGuidance(guidance);
33 fGlobalVerboseCmd->SetParameterName("GlobalVerbose", false);
34 fGlobalVerboseCmd->AvailableForStates(PreInit, Init, Idle);
38 //_____________________________________________________________________________
39 void TG4VerboseMessenger::AddCommand(TG4VVerbose* verbose,
40 const G4String& cmdName)
45 G4UIcmdWithAnInteger* cmd
46 = new G4UIcmdWithAnInteger(G4String(fkDirectoryName + cmdName), this);
48 fVerboseVector.push_back(verbose);
49 fCommandVector.push_back(cmd);
51 G4String guidance("Set verbose level.");
52 guidance.insert(4,cmdName);
53 cmd->SetGuidance(guidance);
55 G4String parameterName("Verbose");
56 parameterName.insert(0,cmdName);
57 cmd->SetParameterName(parameterName, false);
59 cmd->AvailableForStates(PreInit, Init, Idle);
62 //_____________________________________________________________________________
63 TG4VerboseMessenger::TG4VerboseMessenger(){
67 //_____________________________________________________________________________
68 TG4VerboseMessenger::TG4VerboseMessenger(const TG4VerboseMessenger& right) {
70 TG4Globals::Exception("TG4VerboseMessenger is protected from copying.");
73 //_____________________________________________________________________________
74 TG4VerboseMessenger::~TG4VerboseMessenger() {
78 delete fGlobalVerboseCmd;
80 for (G4int i=0; i<fCommandVector.size(); i++)
81 delete fCommandVector[i];
86 //_____________________________________________________________________________
87 TG4VerboseMessenger& TG4VerboseMessenger::operator=(const TG4VerboseMessenger& right)
89 // check assignement to self
90 if (this == &right) return *this;
92 TG4Globals::Exception("TG4VerboseMessenger is protected from assigning.");
99 //_____________________________________________________________________________
100 void TG4VerboseMessenger::SetNewValueToAll(const G4String value) const
102 // Sets the value to all registered verbose instances.
105 G4UIcommandTree* cmdTree
106 = G4UImanager::GetUIpointer()->GetTree()->GetTree(fkDirectoryName);
108 for (G4int i=0; i<cmdTree->GetCommandEntry(); i++) {
109 if (cmdTree->GetCommand(i+1)->GetCommandName() != "all") {
110 // skip the first command in the tree ("all")
111 cmdTree->GetCommand(i+1)->DoIt(value);
118 //_____________________________________________________________________________
119 void TG4VerboseMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
121 // Applies command to the associated object.
124 if (command == fGlobalVerboseCmd) {
125 G4cout << "SetNewValueToAll " << G4endl;
126 SetNewValueToAll(newValue);
128 for (G4int i=0; i<fCommandVector.size(); i++)
129 if (command == fCommandVector[i]) {
131 ->VerboseLevel(fCommandVector[i]->GetNewIntValue(newValue));