]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4VerboseMessenger.cxx
Class for fixed point operations.
[u/mrichter/AliRoot.git] / TGeant4 / TG4VerboseMessenger.cxx
1 // $Id$
2 // Category: global
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class TG4VerboseMessenger
7 // ------------------
8 // See the class description in the header file.
9
10 #include "TG4VerboseMessenger.h"
11 #include "TG4VVerbose.h"
12 #include "TG4Globals.h"
13
14 #include <G4UIcmdWithAnInteger.hh>
15 #include <G4UIdirectory.hh>
16 #include <G4UImanager.hh>
17 #include <G4UIcommandTree.hh>
18
19 //_____________________________________________________________________________
20 TG4VerboseMessenger::TG4VerboseMessenger(const G4String& directoryName)
21   : fkDirectoryName(directoryName)
22
23 //
24
25   fDirectory = new G4UIdirectory(directoryName);
26   fDirectory->SetGuidance("TGeant4 verbose control commands.");
27
28   // sets the given level to all verbose instances
29   fGlobalVerboseCmd 
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);
35 }
36
37
38 //_____________________________________________________________________________
39 void TG4VerboseMessenger::AddCommand(TG4VVerbose* verbose, 
40                                      const G4String& cmdName)
41 {
42 //
43 //--
44
45   G4UIcmdWithAnInteger* cmd 
46     = new G4UIcmdWithAnInteger(G4String(fkDirectoryName + cmdName), this);
47
48   fVerboseVector.push_back(verbose);
49   fCommandVector.push_back(cmd);
50
51   G4String guidance("Set  verbose level.");
52   guidance.insert(4,cmdName);
53   cmd->SetGuidance(guidance);
54
55   G4String parameterName("Verbose");
56   parameterName.insert(0,cmdName);
57   cmd->SetParameterName(parameterName, false);
58   
59   cmd->AvailableForStates(PreInit, Init, Idle);
60 }
61
62 //_____________________________________________________________________________
63 TG4VerboseMessenger::TG4VerboseMessenger(){
64 //
65
66
67 //_____________________________________________________________________________
68 TG4VerboseMessenger::TG4VerboseMessenger(const TG4VerboseMessenger& right) {
69 // 
70   TG4Globals::Exception("TG4VerboseMessenger is protected from copying.");
71 }
72
73 //_____________________________________________________________________________
74 TG4VerboseMessenger::~TG4VerboseMessenger() {
75 //
76
77   delete fDirectory;
78   delete fGlobalVerboseCmd;
79
80   for (G4int i=0; i<fCommandVector.size(); i++)
81     delete fCommandVector[i];
82 }
83
84 // operators
85
86 //_____________________________________________________________________________
87 TG4VerboseMessenger& TG4VerboseMessenger::operator=(const TG4VerboseMessenger& right)
88 {
89   // check assignement to self
90   if (this == &right) return *this;
91
92   TG4Globals::Exception("TG4VerboseMessenger is protected from assigning.");
93     
94   return *this;  
95 }    
96           
97 // private methods
98
99 //_____________________________________________________________________________
100 void TG4VerboseMessenger::SetNewValueToAll(const G4String value) const
101 {
102 // Sets the value to all registered verbose instances.
103 // ---
104    
105    G4UIcommandTree* cmdTree
106      = G4UImanager::GetUIpointer()->GetTree()->GetTree(fkDirectoryName);
107
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);     
112      }  
113    }  
114 }
115
116 // public methods
117
118 //_____________________________________________________________________________
119 void TG4VerboseMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
120
121 // Applies command to the associated object.
122 // ---
123
124   if (command == fGlobalVerboseCmd) {
125     G4cout << "SetNewValueToAll  " << G4endl;
126     SetNewValueToAll(newValue); 
127   }    
128   for (G4int i=0; i<fCommandVector.size(); i++)  
129     if (command == fCommandVector[i]) {
130       fVerboseVector[i]
131         ->VerboseLevel(fCommandVector[i]->GetNewIntValue(newValue)); 
132     }    
133 }