The Gaudi Framework  master (da3d77e1)
StringKeyEx.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 // STD & STL
15 // ===========================================================================
16 #include <map>
17 // ===========================================================================
18 // GaudiKernel
19 // ===========================================================================
20 #include <GaudiKernel/HashMap.h>
21 #include <GaudiKernel/Map.h>
22 #include <GaudiKernel/StatusCode.h>
23 #include <GaudiKernel/StringKey.h>
24 // ===========================================================================
26 // ===========================================================================
27 namespace Gaudi {
28  // =========================================================================
29  namespace TestSuite {
30  // =======================================================================
37  class StringKeyEx : public TestAlg {
38  public:
39  // ======================================================================
41  StatusCode execute() override;
42  // ======================================================================
43  public:
44  // ======================================================================
46  using TestAlg::TestAlg;
47  // ======================================================================
48  private:
49  // ======================================================================
52  // ======================================================================
53  Gaudi::Property<Key> m_key{ this, "Key", {}, "The string key" };
54  Gaudi::Property<Keys> m_keys{ this, "Keys", {}, "The vector of keys" };
55  // ======================================================================
56  };
57  // ========================================================================
58  } // namespace TestSuite
59  // ==========================================================================
60 } // end of namespace Gaudi
61 // ============================================================================
62 // Execution method
63 // ============================================================================
65  // 1. check the settings of key from the properties
66  always() << "The Key : " << Gaudi::Utils::toString( m_key.value() ) << endmsg;
67  always() << "The Keys : " << Gaudi::Utils::toString( m_keys.value() ) << endmsg;
68  //
69 
70  // prepare some maps
71  typedef std::map<std::string, int> MAP1;
75 
76  typedef std::map<Key, int> MAP01;
77  typedef GaudiUtils::Map<Key, int> MAP02;
78  typedef GaudiUtils::HashMap<Key, int> MAP03;
79  typedef GaudiUtils::VectorMap<Key, int> MAP04;
80 
81  MAP1 map1;
82  MAP2 map2;
83  MAP3 map3;
84  MAP4 map4;
85 
86  MAP01 map01;
87  MAP02 map02;
88  MAP03 map03;
89  MAP04 map04;
90 
91  for ( Keys::const_iterator it = m_keys.begin(); m_keys.end() != it; ++it ) {
92  int index = it - m_keys.begin();
93 
94  map1.insert( std::make_pair( *it, index ) );
95  map2.insert( std::make_pair( *it, index ) );
96  map3.insert( std::make_pair( *it, index ) );
97  map4.insert( std::make_pair( *it, index ) );
98 
99  map01.insert( std::make_pair( *it, index ) );
100  map02.insert( std::make_pair( *it, index ) );
101  map03.insert( std::make_pair( *it, index ) );
102  map04.insert( std::make_pair( *it, index ) );
103  }
104 
105  always() << "Map 1:" << Gaudi::Utils::toString( map1 ) << endmsg;
106  always() << "Map 2:" << Gaudi::Utils::toString( map2 ) << endmsg;
107  always() << "Map 3:" << Gaudi::Utils::toString( map3 ) << endmsg;
108  always() << "Map 4:" << Gaudi::Utils::toString( map4 ) << endmsg;
109 
110  always() << "Map01:" << Gaudi::Utils::toString( map01 ) << endmsg;
111  always() << "Map02:" << Gaudi::Utils::toString( map02 ) << endmsg;
112  always() << "Map03:" << Gaudi::Utils::toString( map03 ) << endmsg;
113  always() << "Map04:" << Gaudi::Utils::toString( map04 ) << endmsg;
114 
115  always() << "check for StringKey " << Gaudi::Utils::toString( m_key.value() ) << endmsg;
116 
117  always() << " In Map 1: " << Gaudi::Utils::toString( map1.end() != map1.find( m_key.value() ) ) << endmsg;
118  always() << " In Map 2: " << Gaudi::Utils::toString( map2.end() != map2.find( m_key.value() ) ) << endmsg;
119  always() << " In Map 3: " << Gaudi::Utils::toString( map3.end() != map3.find( m_key.value() ) ) << endmsg;
120  always() << " In Map 4: " << Gaudi::Utils::toString( map4.end() != map4.find( m_key.value() ) ) << endmsg;
121 
122  always() << " In Map01: " << Gaudi::Utils::toString( map01.end() != map01.find( m_key ) ) << endmsg;
123  always() << " In Map02: " << Gaudi::Utils::toString( map02.end() != map02.find( m_key ) ) << endmsg;
124  always() << " In Map03: " << Gaudi::Utils::toString( map03.end() != map03.find( m_key ) ) << endmsg;
125  always() << " In Map04: " << Gaudi::Utils::toString( map04.end() != map04.find( m_key ) ) << endmsg;
126 
127  std::string akey = "rrr";
128 
129  always() << "check for std::string key " << Gaudi::Utils::toString( akey ) << endmsg;
130 
131  always() << " In Map 1: " << Gaudi::Utils::toString( map1.end() != map1.find( akey ) ) << endmsg;
132  always() << " In Map 2: " << Gaudi::Utils::toString( map2.end() != map2.find( akey ) ) << endmsg;
133  always() << " In Map 3: " << Gaudi::Utils::toString( map3.end() != map3.find( akey ) ) << endmsg;
134  always() << " In Map 4: " << Gaudi::Utils::toString( map4.end() != map4.find( akey ) ) << endmsg;
135 
136  always() << " In Map01: " << Gaudi::Utils::toString( map01.end() != map01.find( akey ) ) << endmsg;
137  always() << " In Map02: " << Gaudi::Utils::toString( map02.end() != map02.find( akey ) ) << endmsg;
138  always() << " In Map03: " << Gaudi::Utils::toString( map03.end() != map03.find( akey ) ) << endmsg;
139  always() << " In Map04: " << Gaudi::Utils::toString( map04.end() != map04.find( akey ) ) << endmsg;
140 
141  return StatusCode::SUCCESS;
142 }
143 // ============================================================================
147 // ============================================================================
148 // The END
149 // ========-===================================================================
std::string
STL class.
Gaudi::Algorithm::index
unsigned int index() const override
Definition: Algorithm.cpp:532
Gaudi::TestSuite::StringKeyEx::Key
Gaudi::StringKey Key
Definition: StringKeyEx.cpp:50
Gaudi::TestSuite::StringKeyEx::m_keys
Gaudi::Property< Keys > m_keys
Definition: StringKeyEx.cpp:54
TestSuite
#define TestSuite
Definition: MakeAndConsume.cpp:658
Gaudi::TestSuite::StringKeyEx::execute
StatusCode execute() override
execution of the Testalg
Definition: StringKeyEx.cpp:64
std::vector
STL class.
GaudiUtils::VectorMap
Definition: VectorMap.h:112
Gaudi::TestSuite::TestAlg
Simple algorithm useful as base class for tests.
Definition: TestAlg.h:19
StringKey.h
TestAlg.h
StatusCode.h
HashMap.h
Gaudi::StringKey
Definition: StringKey.h:44
StatusCode
Definition: StatusCode.h:65
GaudiUtils::Map
Definition: Map.h:91
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
std::map< std::string, int >
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:357
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
std::make_pair
T make_pair(T... args)
Map.h
GaudiUtils::HashMap
Definition: HashMap.h:83
Gaudi::TestSuite::StringKeyEx
Definition: StringKeyEx.cpp:37
Gaudi::TestSuite::StringKeyEx::m_key
Gaudi::Property< Key > m_key
Definition: StringKeyEx.cpp:53
StringKeyEx
Definition: StringKeyEx.py:1
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:37
Gaudi::TestSuite::StringKeyEx::Keys
std::vector< Key > Keys
Definition: StringKeyEx.cpp:51