The Gaudi Framework  v30r3 (a5ef0a68)
MetaDataSvc.cpp
Go to the documentation of this file.
1 /*
2  * MetaDataSvc.cpp
3  *
4  * Created on: Mar 24, 2015
5  * Author: Ana Trisovic
6  */
7 
8 // Framework include files
10 #include "GaudiKernel/IAlgorithm.h"
11 #include "GaudiKernel/IProperty.h"
12 #include "GaudiKernel/IService.h"
14 #include "GaudiKernel/IToolSvc.h"
15 
16 #include "MetaDataSvc.h"
17 
18 using Gaudi::MetaDataSvc;
19 
20 namespace
21 {
22  const auto get_name = []( const auto* i ) { return i->name(); };
23 
24  struct Identity {
25  template <typename T>
26  auto operator()( T&& t ) const -> decltype( auto )
27  {
28  return std::forward<T>( t );
29  }
30  };
31 
32  template <typename Iterator, typename Sep, typename Projection = Identity>
33  std::string join( Iterator first, Iterator last, Sep sep, Projection proj = {} )
34  {
35  std::string s;
36  if ( first != last ) s += proj( *first++ );
37  for ( ; first != last; ++first ) {
38  s += sep;
39  s += proj( *first );
40  }
41  return s;
42  }
43  template <typename Container, typename Sep, typename Projection = Identity>
44  std::string join( const Container& c, Sep sep, Projection proj = {} )
45  {
46  return join( begin( c ), end( c ), std::move( sep ), std::move( proj ) );
47  }
48 }
49 
51 
53 {
54  if ( msgLevel( MSG::DEBUG ) ) debug() << "started" << endmsg;
55  return collectData();
56 }
57 
58 std::map<std::string, std::string> MetaDataSvc::getMetaDataMap() const { return m_metadata; }
59 
60 StatusCode MetaDataSvc::collectData()
61 {
62  for ( const auto* name : {"ApplicationMgr", "MessageSvc", "NTupleSvc"} ) {
63  auto svc = service<IProperty>( name );
64  if ( !svc.isValid() ) continue;
65  const auto prefix = name + std::string{"."};
66  for ( const auto* prop : svc->getProperties() ) {
67  m_metadata[prefix + prop->name()] = prop->toString();
68  }
69  }
70 
71  /*
72  * TOOLS
73  * */
74  SmartIF<IToolSvc> tSvc( serviceLocator()->service( "ToolSvc" ) );
75  if ( tSvc.isValid() ) {
76  m_metadata["ToolSvc"] = join( tSvc->getInstances( "" ), ", " );
77  }
78 
79  /*
80  * SERVICES
81  * */
82  m_metadata["ISvcLocator.Services"] = join( serviceLocator()->getServices(), ", ", get_name );
83 
84  /*
85  * ALGORITHMS
86  * */
87  SmartIF<IAlgManager> algMan( serviceLocator() );
88  m_metadata["IAlgManager.Algorithms"] = join( algMan->getAlgorithms(), ", ", get_name );
89 
90  /*
91  * JOB OPTIONS SERVICE
92  * */
93  auto joSvc = service<IProperty>( "JobOptionsSvc" );
94  if ( !joSvc.isValid() ) return StatusCode::FAILURE;
95  for ( const auto* prop : joSvc->getProperties() ) {
96  m_metadata["JobOptionsSvc." + prop->name()] = prop->toString();
97  }
98 
99  if ( msgLevel( MSG::DEBUG ) ) {
100  debug() << "Metadata collected:\n";
101  for ( const auto& item : m_metadata ) {
102  debug() << item.first << ':' << item.second << '\n';
103  }
104  debug() << endmsg;
105  }
106 
107  return StatusCode::SUCCESS;
108 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
STL class.
#define DECLARE_COMPONENT(type)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
start
Definition: IOTest.py:99
string prefix
Definition: gaudirun.py:268
T move(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:18
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
string s
Definition: gaudirun.py:253
virtual std::vector< std::string > getInstances(const std::string &toolType)=0
Get the names of all instances of tools of a given type.
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209