]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4IntMap.cxx
added ClassImp macro
[u/mrichter/AliRoot.git] / TGeant4 / TG4IntMap.cxx
CommitLineData
2817d3e2 1// $Id$
2// Category: global
3//
79401af9 4// Author: I. Hrivnacova
5//
6// Class TG4IntMap
7// ---------------
2817d3e2 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
72095f7c 16//_____________________________________________________________________________
2817d3e2 17TG4IntMap::TG4IntMap(){
18//
19}
20
72095f7c 21//_____________________________________________________________________________
2817d3e2 22TG4IntMap::TG4IntMap(const TG4IntMap& right) {
23//
24 TG4Globals::Exception("TG4IntMap is protected from copying.");
25}
26
72095f7c 27//_____________________________________________________________________________
2817d3e2 28TG4IntMap::~TG4IntMap() {
29//
30}
31
32// operators
33
72095f7c 34//_____________________________________________________________________________
2817d3e2 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
72095f7c 47//_____________________________________________________________________________
2817d3e2 48G4bool TG4IntMap::IsDefined(const G4String& first)
49{
50// Returns true if the first is already in the map.
51// ---
52
79401af9 53 MapIterator i = fMap.find(first);
2817d3e2 54 if (i == fMap.end())
55 return false;
56 else
57 return true;
58}
59
60// public methods
61
72095f7c 62//_____________________________________________________________________________
2817d3e2 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
72095f7c 77//_____________________________________________________________________________
11755011 78G4int TG4IntMap::GetSecond(const G4String& name, G4bool warn)
2817d3e2 79{
80// Gets second name associated with given name.
81// ---
82
79401af9 83 MapIterator i = fMap.find(name);
2817d3e2 84 if (i == fMap.end()) {
11755011 85 if (warn) {
86 G4String text = " TG4IntMap::GetSecond: ";
87 text = text + name + " is not defined.";
88 TG4Globals::Warning(text);
89 }
2817d3e2 90 return 0;
91 }
92 else {
93 return (*i).second;
94 }
95}
96
72095f7c 97//_____________________________________________________________________________
79401af9 98void TG4IntMap::PrintAll() const
2817d3e2 99{
100// Dumps all map.
101// ---
102
103 if (fMap.size()) {
104 G4cout << "Dump of TG4IntMap - " << fMap.size() << " entries:" << G4endl;
105 G4int counter = 0;
79401af9 106 for (MapConstIterator i=fMap.begin(); i != fMap.end(); i++) {
2817d3e2 107 const G4String& first = (*i).first;
108 G4int second = (*i).second;
109 G4cout << "Map element " << G4std::setw(3) << counter++ << " "
110 << first << " " << second << G4endl;
111 }
112 }
113}
114
72095f7c 115//_____________________________________________________________________________
2817d3e2 116void TG4IntMap::Clear()
117{
118// Clears the map.
119// ---
120
121 if (fMap.size()>0) fMap.clear();
122}