The Gaudi Framework  master (37c0b60a)
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
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>
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,
43 #include <GaudiKernel/ToStream.h>
44 #include <map>
45 namespace std {
46  // This is an example valid for any mapping type.
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  // ============================================================================
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  // ============================================================================
93  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
94 
95  // TODO execution logic
96 
97  return StatusCode::SUCCESS;
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 // ============================================================================
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
Gaudi::Parsers::Grammar_< Iterator, MyCustomType, Skipper >::Grammar
MapGrammar< Iterator, MyCustomType, Skipper > Grammar
Definition: CustomPropertiesAlg.cpp:33
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
gaudirun.s
string s
Definition: gaudirun.py:346
TestSuite
#define TestSuite
Definition: MakeAndConsume.cpp:658
Gaudi::Parsers::parse_
StatusCode parse_(ResultT &result, std::string_view input)
Definition: Factory.h:39
MyCustomType
std::unordered_map< std::string, std::string > MyCustomType
Definition: CustomPropertiesAlg.cpp:20
Gaudi::TestSuite::TestAlg::initialize
StatusCode initialize() override
Definition: TestAlg.h:21
std::operator<<
ostream & operator<<(ostream &s, const MyCustomType &m)
Definition: CustomPropertiesAlg.cpp:47
ToStream.h
CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:148
StatusCode
Definition: StatusCode.h:65
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
std::ostream
STL class.
Gaudi::Parsers::SkipperGrammar
Definition: Grammar.h:51
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
std::map
STL class.
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::TestSuite::CustomPropertiesAlg::execute
StatusCode execute() override
Algorithm execution.
Definition: CustomPropertiesAlg.cpp:92
Factory.h
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:184
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
CustomPropertiesAlg.h
Gaudi::Parsers::Grammar_
Definition: Grammars.h:68
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
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:299
Gaudi::TestSuite::CustomPropertiesAlg::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: CustomPropertiesAlg.cpp:103
std::unordered_map< std::string, std::string >
Gaudi::Parsers::MapGrammar
Definition: Grammars.h:362
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28
Gaudi::TestSuite::CustomPropertiesAlg
Definition: CustomPropertiesAlg.h:28