The Gaudi Framework  master (82fdf313)
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
20typedef std::unordered_map<std::string, std::string> MyCustomType;
21
22// Define the parser
24
25namespace Gaudi {
26 namespace Parsers {
27
28 // Parser grammar
29 template <typename Iterator, typename 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
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,
44#include <map>
45namespace 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// ----------------------------------------------------------------------------
71namespace Gaudi {
72 namespace TestSuite {
74
75 // ============================================================================
76 // Initialization
77 // ============================================================================
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
87 }
88
89 // ============================================================================
90 // Main execution
91 // ============================================================================
93 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
94
95 // TODO execution logic
96
98 }
99
100 // ============================================================================
101 // Finalize
102 // ============================================================================
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// ============================================================================
std::unordered_map< std::string, std::string > MyCustomType
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition Iterator.h:18
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
implementation of various functions for streaming.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition Algorithm.h:181
Example on how to use custom property types.
StatusCode execute() override
Algorithm execution.
StatusCode finalize() override
Algorithm finalization.
StatusCode initialize() override
Algorithm initialization.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
SkipperGrammar< IteratorT > Skipper
Definition Factory.h:24
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
StatusCode parse_(ResultT &result, std::string_view input)
Definition Factory.h:26
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:304
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
@ DEBUG
Definition IMessageSvc.h:22
STL namespace.
ostream & operator<<(ostream &s, const MyCustomType &m)
MapGrammar< Iterator, MyCustomType, Skipper > Grammar
StatusCode initialize() override
Definition TestAlg.h:21