]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TGeant4/TG4IntMap.cxx
Made some, mostly cosmetic, changes to SDD simulation. Improved complience with
[u/mrichter/AliRoot.git] / TGeant4 / TG4IntMap.cxx
... / ...
CommitLineData
1// $Id$
2// Category: global
3//
4// Author: I. Hrivnacova
5//
6// Class TG4IntMap
7// ---------------
8// See the class description in the header file.
9
10#include "TG4IntMap.h"
11#include "TG4Globals.h"
12
13#include "g4std/iomanip"
14#include "globals.hh"
15
16//_____________________________________________________________________________
17TG4IntMap::TG4IntMap(){
18//
19}
20
21//_____________________________________________________________________________
22TG4IntMap::TG4IntMap(const TG4IntMap& right) {
23//
24 TG4Globals::Exception("TG4IntMap is protected from copying.");
25}
26
27//_____________________________________________________________________________
28TG4IntMap::~TG4IntMap() {
29//
30}
31
32// operators
33
34//_____________________________________________________________________________
35TG4IntMap& TG4IntMap::operator=(const TG4IntMap& right)
36{
37 // check assignement to self
38 if (this == &right) return *this;
39
40 TG4Globals::Exception("TG4IntMap is protected from assigning.");
41
42 return *this;
43}
44
45// private methods
46
47//_____________________________________________________________________________
48G4bool TG4IntMap::IsDefined(const G4String& first)
49{
50// Returns true if the first is already in the map.
51// ---
52
53 MapIterator i = fMap.find(first);
54 if (i == fMap.end())
55 return false;
56 else
57 return true;
58}
59
60// public methods
61
62//_____________________________________________________________________________
63G4bool TG4IntMap::Add(const G4String& first, G4int second)
64{
65// Adds pair (name, int number) to the map.
66// ---
67
68 if (!IsDefined(first)) {
69 // insert into map
70 // only in case it is not yet here
71 fMap[first] = second;
72 return true;
73 }
74 return false;
75}
76
77//_____________________________________________________________________________
78G4int TG4IntMap::GetSecond(const G4String& name)
79{
80// Gets second name associated with given name.
81// ---
82
83 MapIterator i = fMap.find(name);
84 if (i == fMap.end()) {
85 G4String text = " TG4IntMap::GetSecond: ";
86 text = text + name + " is not defined.";
87 TG4Globals::Warning(text);
88 return 0;
89 }
90 else {
91 return (*i).second;
92 }
93}
94
95//_____________________________________________________________________________
96void TG4IntMap::PrintAll() const
97{
98// Dumps all map.
99// ---
100
101 if (fMap.size()) {
102 G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
103 G4int counter = 0;
104 for (MapConstIterator i=fMap.begin(); i != fMap.end(); i++) {
105 const G4String& first = (*i).first;
106 G4int second = (*i).second;
107 G4cout << "Map element " << G4std::setw(3) << counter++ << " "
108 << first << " " << second << G4endl;
109 }
110 }
111}
112
113//_____________________________________________________________________________
114void TG4IntMap::Clear()
115{
116// Clears the map.
117// ---
118
119 if (fMap.size()>0) fMap.clear();
120}