The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
CustomPropertiesAlg.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
#include "
CustomPropertiesAlg.h
"
12
13
// ----------------------------------------------------------------------------
14
// Allow to use std::unordered_map as a property
15
// ----------------------------------------------------------------------------
16
// Includes needed for the custom type
17
#include <string>
18
#include <unordered_map>
19
// A typedef may save a lot of mistakes
20
typedef
std::unordered_map<std::string, std::string>
MyCustomType
;
21
22
// Define the parser
23
#include <
Gaudi/Parsers/Factory.h
>
24
25
namespace
Gaudi
{
26
namespace
Parsers {
27
28
// Parser grammar
29
template
<
typename
Iterator,
typename
Skipper>
30
struct
Grammar_
<
Iterator
,
MyCustomType
,
Skipper
> {
31
// In this case, the type is a mapping type, so it requires the MapGrammar.
32
// For other grammars see Gaudi/Parsers/Grammars.h
33
typedef
MapGrammar<Iterator, MyCustomType, Skipper>
Grammar
;
34
};
35
36
// Parse function... nothing special, but it must be done explicitely.
37
StatusCode
parse
(
MyCustomType
& result, std::string_view input ) {
return
parse_
( result, input ); }
38
}
// namespace Parsers
39
}
// namespace Gaudi
40
41
// We also need to be able to print an object of our type as a string that both
42
// Python and our parser can understand,
43
#include <
GaudiKernel/ToStream.h
>
44
#include <map>
45
namespace
std
{
46
// This is an example valid for any mapping type.
47
ostream&
operator<<
( ostream& s,
const
MyCustomType
& m ) {
48
bool
first =
true
;
49
s <<
'{'
;
50
// this is not strictly needed, but it makes the output sorted, which is
51
// always nice (in particular for tests)
52
const
map<string, string> m1( m.begin(), m.end() );
53
for
(
const
auto
& i : m1 ) {
54
if
( first )
55
first =
false
;
56
else
57
s <<
", "
;
58
Gaudi::Utils::toStream
( i.first, s ) <<
": "
;
59
Gaudi::Utils::toStream
( i.second, s );
60
}
61
s <<
'}'
;
62
return
s;
63
}
64
}
// namespace std
65
66
// ----------------------------------------------------------------------------
67
// Implementation file for class: CustomPropertiesAlg
68
//
69
// 14/11/2014: Marco Clemencic
70
// ----------------------------------------------------------------------------
71
namespace
Gaudi
{
72
namespace
TestSuite
{
73
DECLARE_COMPONENT
(
CustomPropertiesAlg
)
74
75
// ============================================================================
76
// Initialization
77
// ============================================================================
78
StatusCode
CustomPropertiesAlg
::
initialize
() {
79
StatusCode
sc =
TestAlg::initialize
();
// must be executed first
80
if
( sc.
isFailure
() )
return
sc;
// error printed already by TestAlg
81
82
if
(
msgLevel
(
MSG::DEBUG
) )
debug
() <<
"==> Initialize"
<<
endmsg
;
83
84
// TODO initialization procedure
85
86
return
StatusCode::SUCCESS
;
87
}
88
89
// ============================================================================
90
// Main execution
91
// ============================================================================
92
StatusCode
CustomPropertiesAlg::execute
() {
93
if
(
msgLevel
(
MSG::DEBUG
) )
debug
() <<
"==> Execute"
<<
endmsg
;
94
95
// TODO execution logic
96
97
return
StatusCode::SUCCESS
;
98
}
99
100
// ============================================================================
101
// Finalize
102
// ============================================================================
103
StatusCode
CustomPropertiesAlg::finalize
() {
104
if
(
msgLevel
(
MSG::DEBUG
) )
debug
() <<
"==> Finalize"
<<
endmsg
;
105
106
// TODO Implement finalize
107
108
return
TestAlg::finalize
();
// must be called after all other actions
109
}
110
}
// namespace TestSuite
111
}
// namespace Gaudi
112
// ============================================================================
MyCustomType
std::unordered_map< std::string, std::string > MyCustomType
Definition
CustomPropertiesAlg.cpp:20
CustomPropertiesAlg.h
Factory.h
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition
Iterator.h:18
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
ToStream.h
implementation of various functions for streaming.
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition
CommonMessaging.h:118
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition
CommonMessaging.h:127
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition
Algorithm.h:181
Gaudi::TestSuite::CustomPropertiesAlg
Example on how to use custom property types.
Definition
CustomPropertiesAlg.h:27
Gaudi::TestSuite::CustomPropertiesAlg::execute
StatusCode execute() override
Algorithm execution.
Definition
CustomPropertiesAlg.cpp:92
Gaudi::TestSuite::CustomPropertiesAlg::finalize
StatusCode finalize() override
Algorithm finalization.
Definition
CustomPropertiesAlg.cpp:103
Gaudi::TestSuite::CustomPropertiesAlg::initialize
StatusCode initialize() override
Algorithm initialization.
Definition
CustomPropertiesAlg.cpp:78
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
Gaudi::Parsers::Skipper
SkipperGrammar< IteratorT > Skipper
Definition
Factory.h:20
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition
DODBasicMapper.cpp:21
Gaudi::Parsers::parse_
StatusCode parse_(ResultT &result, std::string_view input)
Definition
Factory.h:22
Gaudi::TestSuite
Definition
ConditionAccessorHolder.h:21
Gaudi::Utils::toStream
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition
ToStream.h:307
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
MSG::DEBUG
@ DEBUG
Definition
IMessageSvc.h:22
std
STL namespace.
std::operator<<
ostream & operator<<(ostream &s, const MyCustomType &m)
Definition
CustomPropertiesAlg.cpp:47
Gaudi::Parsers::Grammar_< Iterator, MyCustomType, Skipper >::Grammar
MapGrammar< Iterator, MyCustomType, Skipper > Grammar
Definition
CustomPropertiesAlg.cpp:33
Gaudi::Parsers::Grammar_
Definition
Grammars.h:55
Gaudi::Parsers::MapGrammar
Definition
Grammars.h:236
Gaudi::TestSuite::TestAlg::initialize
StatusCode initialize() override
Definition
TestAlg.h:21
GaudiTestSuite
src
Properties
CustomPropertiesAlg.cpp
Generated on
for The Gaudi Framework by
1.17.0