The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
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>
24// ===========================================================================
26// ===========================================================================
27namespace 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 // ======================================================================
51 typedef std::vector<Key> Keys;
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;
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// ========-===================================================================
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
unsigned int index() const override
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
Helper class for efficient "key" access for strings.
Definition StringKey.h:66
Simple example which illustrate the usage of class StringKey.
Gaudi::Property< Keys > m_keys
Gaudi::Property< Key > m_key
StatusCode execute() override
execution of the Testalg
Common class providing an architecture-independent hash map.
Definition HashMap.h:80
Extension of the STL map.
Definition Map.h:83
A bit modified version of 'Loki::AssocVector' associative vector from Loki library by Andrei Alexandr...
Definition VectorMap.h:100
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition ToStream.h:326
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
Simple algorithm useful as base class for tests.
Definition TestAlg.h:19