The Gaudi Framework  master (37c0b60a)
MapAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 #include <GaudiKernel/Algorithm.h>
25 // ============================================================================
37 // ============================================================================
49 class MapAlg : public Algorithm {
50 public:
51  typedef int Key;
52  typedef double Value;
53 
54 public:
56  StatusCode finalize() override {
57  always() << endmsg << " FINALIZE " << endmsg << " \tTested maps : " << endmsg << " \t1) "
58  << System::typeinfoName( typeid( m_map1 ) ) << endmsg << " \t2) "
59  << System::typeinfoName( typeid( m_map2 ) ) << endmsg << " \t3) "
60  << System::typeinfoName( typeid( m_map3 ) ) << endmsg << " \t4) "
61  << System::typeinfoName( typeid( m_map4 ) ) << endmsg;
62  // finalize the base class
63  return Algorithm::finalize();
64  };
66  StatusCode execute() override;
67 
68 public:
74 
76  MapAlg( const MapAlg& ) = delete;
78  MapAlg& operator=( const MapAlg& ) = delete;
79 
80 private:
82  void print1( Key key ) const;
84  void print2( Key key );
85 
86 private:
91 
96 };
97 // ==========================================================================
99 // ==========================================================================
101 
102 // ==========================================================================
104 // ==========================================================================
106  using namespace Gaudi::Utils;
107 
108  Rndm::Numbers gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
109  Rndm::Numbers gauss2( randSvc(), Rndm::Gauss( 0.0, 10.0 ) );
110 
111  const Key key = Key( gauss2() );
112  const Value value1 = Value( int( 100 * gauss() ) ) / 100.0;
113 
114  always() << " Inserting key " << toString( key ) << " 1st: "
115  << " " << toString( m_map1.insert( std::make_pair( key, value1 ) ).second ) << " "
116  << toString( m_map2.insert( std::make_pair( key, value1 ) ).second ) << " "
117  << toString( m_map3.insert( std::make_pair( key, value1 ) ).second ) << " "
118  << toString( m_map4.insert( std::make_pair( key, value1 ) ).second ) << endmsg;
119 
120  always() << "1 Map1: " << toString( m_map1 ) << endmsg;
121  always() << "1 Map2: " << toString( m_map2 ) << endmsg;
122  always() << "1 Map3: " << toString( m_map3 ) << endmsg;
123  always() << "1 Map4: " << toString( m_map4 ) << endmsg;
124 
125  print1( (Key)1 );
126 
127  always() << "2 Map1: " << toString( m_map1 ) << endmsg;
128  always() << "2 Map2: " << toString( m_map2 ) << endmsg;
129  always() << "2 Map3: " << toString( m_map3 ) << endmsg;
130  always() << "2 Map4: " << toString( m_map4 ) << endmsg;
131 
132  print2( (Key)7 );
133 
134  always() << "3 Map1: " << toString( m_map1 ) << endmsg;
135  always() << "3 Map2: " << toString( m_map2 ) << endmsg;
136  always() << "3 Map3: " << toString( m_map3 ) << endmsg;
137  always() << "3 Map4: " << toString( m_map4 ) << endmsg;
138 
139  const Value value2 = gauss();
140 
141  always() << " Inserting key " << toString( key ) << " 2nd: "
142  << " " << toString( m_map1.insert( std::make_pair( key, value2 ) ).second ) << " "
143  << toString( m_map2.insert( std::make_pair( key, value2 ) ).second ) << " "
144  << toString( m_map3.insert( std::make_pair( key, value2 ) ).second ) << " "
145  << toString( m_map4.insert( std::make_pair( key, value2 ) ).second ) << endmsg;
146 
147  always() << "4 Map1: " << toString( m_map1 ) << endmsg;
148  always() << "4 Map2: " << toString( m_map2 ) << endmsg;
149  always() << "4 Map3: " << toString( m_map3 ) << endmsg;
150  always() << "4 Map4: " << toString( m_map4 ) << endmsg;
151 
152  if ( 0 == ::labs( key ) % 2 ) {
153  always() << " Erased : "
154  << " " << toString( 0 != m_map1.erase( key ) ) << " " << toString( 0 != m_map2.erase( key ) ) << " "
155  << toString( 0 != m_map3.erase( key ) ) << " " << toString( 0 != m_map4.erase( key ) ) << endmsg;
156  }
157 
158  always() << "5 Map1: " << toString( m_map1 ) << endmsg;
159  always() << "5 Map2: " << toString( m_map2 ) << endmsg;
160  always() << "5 Map3: " << toString( m_map3 ) << endmsg;
161  always() << "5 Map4: " << toString( m_map4 ) << endmsg;
162 
163  always() << " Count key 0 : "
164  << " " << m_map1.count( 0 ) << " " << m_map2.count( 0 ) << " " << m_map3.count( 0 ) << " "
165  << m_map4.count( 0 ) << endmsg;
166  always() << " Count key 1 : "
167  << " " << m_map1.count( 1 ) << " " << m_map2.count( 1 ) << " " << m_map3.count( 1 ) << " "
168  << m_map4.count( 1 ) << endmsg;
169  always() << " Count key 7 : "
170  << " " << m_map1.count( 7 ) << " " << m_map2.count( 7 ) << " " << m_map3.count( 7 ) << " "
171  << m_map4.count( 7 ) << endmsg;
172  always() << " Count key -100 : "
173  << " " << m_map1.count( -100 ) << " " << m_map2.count( -100 ) << " " << m_map3.count( -100 ) << " "
174  << m_map4.count( -100 ) << endmsg;
175 
176  return StatusCode::SUCCESS;
177 }
178 // ============================================================================
180  always() << " CONST: "
181  << " map2['" << key << "']: " << m_map2[key] << ", map3['" << key << "']: " << m_map3[key] << ", map4['"
182  << key << "']: " << m_map4[key] << endmsg;
183 }
184 // ============================================================================
186  always() << " NON-CONST: "
187  << " map1['" << key << "']: " << m_map1[key] << ", map2['" << key << "']: " << m_map2[key] << ", map3['"
188  << key << "']: " << m_map3[key] << ", map4['" << key << "']: " << m_map4[key] << endmsg;
189 }
190 // ============================================================================
191 
192 // ==========================================================================
193 // The END
194 // ==========================================================================
MapAlg::Value
double Value
Definition: MapAlg.cpp:52
MapAlg::m_map4
Map4 m_map4
Definition: MapAlg.cpp:95
MapAlg::print2
void print2(Key key)
non-const printout
Definition: MapAlg.cpp:185
MapAlg
Definition: MapAlg.cpp:49
MapAlg::m_map2
Map2 m_map2
Definition: MapAlg.cpp:93
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:315
Gaudi::Utils
Definition: Property.h:650
MapAlg::Key
int Key
Definition: MapAlg.cpp:51
MultiMergers.Value
Value
Definition: MultiMergers.py:15
MapAlg::m_map1
Map1 m_map1
Definition: MapAlg.cpp:92
ToStream.h
HashMap.h
MapAlg::Map1
std::map< Key, Value > Map1
Definition: MapAlg.cpp:87
StringKeyEx.Key
Key
Definition: StringKeyEx.py:33
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:88
MapAlg::Map3
GaudiUtils::Map< Key, Value > Map3
Definition: MapAlg.cpp:89
GaudiUtils::Map< Key, Value >
MapAlg::execute
StatusCode execute() override
the main execution method
Definition: MapAlg.cpp:105
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
std::map< Key, Value >
MapAlg::Map4
GaudiUtils::HashMap< Key, Value > Map4
Definition: MapAlg.cpp:90
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
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:84
MapAlg::print1
void print1(Key key) const
const-printout
Definition: MapAlg.cpp:179
MapAlg::m_map3
Map3 m_map3
Definition: MapAlg.cpp:94
MapAlg::finalize
StatusCode finalize() override
finalization
Definition: MapAlg.cpp:56