4 // Author: I. Hrivnacova
6 // Class TG4ProcessControlMap
7 // --------------------------
8 // See the class description in the header file.
10 #include "TG4ProcessControlMap.h"
11 #include "TG4G3ControlVector.h"
12 #include "TG4Globals.h"
14 #include <G4VProcess.hh>
15 #include "g4std/iomanip"
18 TG4ProcessControlMap* TG4ProcessControlMap::fgInstance = 0;
20 //_____________________________________________________________________________
21 TG4ProcessControlMap::TG4ProcessControlMap() {
24 TG4Globals::Exception(
25 "TG4ProcessControlMap: attempt to create two instances of singleton.");
31 //_____________________________________________________________________________
32 TG4ProcessControlMap::TG4ProcessControlMap(const TG4ProcessControlMap& right) {
34 TG4Globals::Exception(
35 "Attempt to copy TG4ProcessControlMap singleton.");
38 //_____________________________________________________________________________
39 TG4ProcessControlMap::~TG4ProcessControlMap() {
45 //_____________________________________________________________________________
46 TG4ProcessControlMap& TG4ProcessControlMap::operator=(const TG4ProcessControlMap& right)
48 // check assignement to self
49 if (this == &right) return *this;
51 TG4Globals::Exception(
52 "Attempt to assign TG4ProcessControlMap singleton.");
59 //_____________________________________________________________________________
60 G4bool TG4ProcessControlMap::IsDefined(const G4String& processName)
62 // Returns true if the first is already in the map.
65 if (fMap.find(processName) == fMap.end())
73 //_____________________________________________________________________________
74 G4bool TG4ProcessControlMap::Add(G4VProcess* process, TG4G3Control control)
76 // Adds the pair to the map.
79 if (!process) return false;
81 return Add(process->GetProcessName(), control);
84 //_____________________________________________________________________________
85 G4bool TG4ProcessControlMap::Add(G4String processName, TG4G3Control control)
87 // Adds the pair to the map.
90 if (!IsDefined(processName)) {
92 // only in case it is not yet here
93 fMap[processName] = control;
99 //_____________________________________________________________________________
100 void TG4ProcessControlMap::PrintAll() const
106 G4cout << "Dump of TG4ProcessControlMap - " << fMap.size() << " entries:" << G4endl;
108 for (MapConstIterator i=fMap.begin(); i != fMap.end(); i++) {
109 G4String processName = (*i).first;
110 TG4G3Control control = (*i).second;
111 G4cout << "Map element " << G4std::setw(3) << counter++ << " "
112 << processName << " "
113 << TG4G3ControlVector::GetControlName(control)
119 //_____________________________________________________________________________
120 void TG4ProcessControlMap::Clear()
128 //_____________________________________________________________________________
130 TG4ProcessControlMap::GetControl(const G4VProcess* process)
132 // Returns the G3 process control for the process with a given name.
135 if (!process) return kNoG3Controls;
137 return GetControl(process->GetProcessName());
140 //_____________________________________________________________________________
142 TG4ProcessControlMap::GetControl(const G4String& processName)
144 // Returns the G3 process control for the process with a given name.
147 MapIterator i = fMap.find(processName);
149 return kNoG3Controls;
154 //_____________________________________________________________________________
156 TG4ProcessControlMap::GetControlName(const G4VProcess* process)
158 // Returns the G3 process control name for the process with a given name.
162 return TG4G3ControlVector::GetControlName(kNoG3Controls);
164 return GetControlName(process->GetProcessName());
167 //_____________________________________________________________________________
169 TG4ProcessControlMap::GetControlName(const G4String& processName)
171 // Returns the G3 process control name for the process with a given name.
174 return TG4G3ControlVector::GetControlName(GetControl(processName));