Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MapAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ============================================================================
12 // Include files
13 // ============================================================================
14 // from GaudiKernel
15 // ============================================================================
16 #include "GaudiKernel/HashMap.h"
18 #include "GaudiKernel/Map.h"
20 #include "GaudiKernel/System.h"
21 #include "GaudiKernel/ToStream.h"
22 #include "GaudiKernel/VectorMap.h"
23 // ============================================================================
24 // GaudiAlg
25 // ============================================================================
26 #include "GaudiKernel/Algorithm.h"
27 // ============================================================================
39 // ============================================================================
51 class MapAlg : public Algorithm {
52 public:
53  typedef int Key;
54  typedef double Value;
55 
56 public:
58  StatusCode finalize() override {
59  always() << endmsg << " FINALIZE " << endmsg << " \tTested maps : " << endmsg << " \t1) "
60  << System::typeinfoName( typeid( m_map1 ) ) << endmsg << " \t2) "
61  << System::typeinfoName( typeid( m_map2 ) ) << endmsg << " \t3) "
62  << System::typeinfoName( typeid( m_map3 ) ) << endmsg << " \t4) "
63  << System::typeinfoName( typeid( m_map4 ) ) << endmsg;
64  // finalize the base class
65  return Algorithm::finalize();
66  };
68  StatusCode execute() override;
69 
70 public:
76 
78  MapAlg( const MapAlg& ) = delete;
80  MapAlg& operator=( const MapAlg& ) = delete;
81 
82 private:
84  void print1( Key key ) const;
86  void print2( Key key );
87 
88 private:
93 
98 };
99 // ==========================================================================
101 // ==========================================================================
103 
104 // ==========================================================================
106 // ==========================================================================
108  using namespace Gaudi::Utils;
109 
110  Rndm::Numbers gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
111  Rndm::Numbers gauss2( randSvc(), Rndm::Gauss( 0.0, 10.0 ) );
112 
113  const Key key = Key( gauss2() );
114  const Value value1 = Value( int( 100 * gauss() ) ) / 100.0;
115 
116  always() << " Inserting key " << toString( key ) << " 1st: "
117  << " " << toString( m_map1.insert( std::make_pair( key, value1 ) ).second ) << " "
118  << toString( m_map2.insert( std::make_pair( key, value1 ) ).second ) << " "
119  << toString( m_map3.insert( std::make_pair( key, value1 ) ).second ) << " "
120  << toString( m_map4.insert( std::make_pair( key, value1 ) ).second ) << endmsg;
121 
122  always() << "1 Map1: " << toString( m_map1 ) << endmsg;
123  always() << "1 Map2: " << toString( m_map2 ) << endmsg;
124  always() << "1 Map3: " << toString( m_map3 ) << endmsg;
125  always() << "1 Map4: " << toString( m_map4 ) << endmsg;
126 
127  print1( (Key)1 );
128 
129  always() << "2 Map1: " << toString( m_map1 ) << endmsg;
130  always() << "2 Map2: " << toString( m_map2 ) << endmsg;
131  always() << "2 Map3: " << toString( m_map3 ) << endmsg;
132  always() << "2 Map4: " << toString( m_map4 ) << endmsg;
133 
134  print2( (Key)7 );
135 
136  always() << "3 Map1: " << toString( m_map1 ) << endmsg;
137  always() << "3 Map2: " << toString( m_map2 ) << endmsg;
138  always() << "3 Map3: " << toString( m_map3 ) << endmsg;
139  always() << "3 Map4: " << toString( m_map4 ) << endmsg;
140 
141  const Value value2 = gauss();
142 
143  always() << " Inserting key " << toString( key ) << " 2nd: "
144  << " " << toString( m_map1.insert( std::make_pair( key, value2 ) ).second ) << " "
145  << toString( m_map2.insert( std::make_pair( key, value2 ) ).second ) << " "
146  << toString( m_map3.insert( std::make_pair( key, value2 ) ).second ) << " "
147  << toString( m_map4.insert( std::make_pair( key, value2 ) ).second ) << endmsg;
148 
149  always() << "4 Map1: " << toString( m_map1 ) << endmsg;
150  always() << "4 Map2: " << toString( m_map2 ) << endmsg;
151  always() << "4 Map3: " << toString( m_map3 ) << endmsg;
152  always() << "4 Map4: " << toString( m_map4 ) << endmsg;
153 
154  if ( 0 == ::labs( key ) % 2 ) {
155  always() << " Erased : "
156  << " " << toString( 0 != m_map1.erase( key ) ) << " " << toString( 0 != m_map2.erase( key ) ) << " "
157  << toString( 0 != m_map3.erase( key ) ) << " " << toString( 0 != m_map4.erase( key ) ) << endmsg;
158  }
159 
160  always() << "5 Map1: " << toString( m_map1 ) << endmsg;
161  always() << "5 Map2: " << toString( m_map2 ) << endmsg;
162  always() << "5 Map3: " << toString( m_map3 ) << endmsg;
163  always() << "5 Map4: " << toString( m_map4 ) << endmsg;
164 
165  always() << " Count key 0 : "
166  << " " << m_map1.count( 0 ) << " " << m_map2.count( 0 ) << " " << m_map3.count( 0 ) << " "
167  << m_map4.count( 0 ) << endmsg;
168  always() << " Count key 1 : "
169  << " " << m_map1.count( 1 ) << " " << m_map2.count( 1 ) << " " << m_map3.count( 1 ) << " "
170  << m_map4.count( 1 ) << endmsg;
171  always() << " Count key 7 : "
172  << " " << m_map1.count( 7 ) << " " << m_map2.count( 7 ) << " " << m_map3.count( 7 ) << " "
173  << m_map4.count( 7 ) << endmsg;
174  always() << " Count key -100 : "
175  << " " << m_map1.count( -100 ) << " " << m_map2.count( -100 ) << " " << m_map3.count( -100 ) << " "
176  << m_map4.count( -100 ) << endmsg;
177 
178  return StatusCode::SUCCESS;
179 }
180 // ============================================================================
182  always() << " CONST: "
183  << " map2['" << key << "']: " << m_map2[key] << ", map3['" << key << "']: " << m_map3[key] << ", map4['"
184  << key << "']: " << m_map4[key] << endmsg;
185 }
186 // ============================================================================
188  always() << " NON-CONST: "
189  << " map1['" << key << "']: " << m_map1[key] << ", map2['" << key << "']: " << m_map2[key] << ", map3['"
190  << key << "']: " << m_map3[key] << ", map4['" << key << "']: " << m_map4[key] << endmsg;
191 }
192 // ============================================================================
193 
194 // ==========================================================================
195 // The END
196 // ==========================================================================
MapAlg::Value
double Value
Definition: MapAlg.cpp:54
MapAlg::m_map4
Map4 m_map4
Definition: MapAlg.cpp:97
MapAlg::print2
void print2(Key key)
non-const printout
Definition: MapAlg.cpp:187
MapAlg
Definition: MapAlg.cpp:51
MapAlg::m_map2
Map2 m_map2
Definition: MapAlg.cpp:95
RndmGenerators.h
System.h
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
GaudiUtils::VectorMap< Key, Value >
IRndmGenSvc.h
Algorithm.h
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:313
Gaudi::Utils
Definition: Fill.h:34
MapAlg::Key
int Key
Definition: MapAlg.cpp:53
MultiMergers.Value
Value
Definition: MultiMergers.py:15
MapAlg::m_map1
Map1 m_map1
Definition: MapAlg.cpp:94
ToStream.h
HashMap.h
MapAlg::Map1
std::map< Key, Value > Map1
Definition: MapAlg.cpp:89
StringKeyEx.Key
Key
Definition: StringKeyEx.py:32
VectorMap.h
StatusCode
Definition: StatusCode.h:65
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
GaudiPython.Pythonizations.execute
execute
Definition: Pythonizations.py:578
MapAlg::Map2
GaudiUtils::VectorMap< Key, Value > Map2
Definition: MapAlg.cpp:90
MapAlg::Map3
GaudiUtils::Map< Key, Value > Map3
Definition: MapAlg.cpp:91
GaudiUtils::Map< Key, Value >
MapAlg::execute
StatusCode execute() override
the main execution method
Definition: MapAlg.cpp:107
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
std::map< Key, Value >
MapAlg::Map4
GaudiUtils::HashMap< Key, Value > Map4
Definition: MapAlg.cpp:92
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:354
MapAlg::MapAlg
MapAlg(const MapAlg &)=delete
The copy constructor is disabled.
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:184
Gaudi::Units::gauss
constexpr double gauss
Definition: SystemOfUnits.h:252
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
MapAlg::operator=
MapAlg & operator=(const MapAlg &)=delete
The assignement is disabled.
std::make_pair
T make_pair(T... args)
Map.h
GaudiUtils::HashMap< Key, Value >
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.h:101
ProduceConsume.key
key
Definition: ProduceConsume.py:81
MapAlg::print1
void print1(Key key) const
const-printout
Definition: MapAlg.cpp:181
MapAlg::m_map3
Map3 m_map3
Definition: MapAlg.cpp:96
MapAlg::finalize
StatusCode finalize() override
finalization
Definition: MapAlg.cpp:58