The Gaudi Framework  v30r4 (9b837755)
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"
12 #include "GaudiKernel/IProperty.h"
13 #include "GaudiKernel/IService.h"
15 #include "GaudiKernel/IToolSvc.h"
16 
17 #include "MetaDataSvc.h"
18 
19 using Gaudi::MetaDataSvc;
20 
21 namespace
22 {
23  const auto get_name = []( const auto* i ) { return i->name(); };
24 
25  struct Identity {
26  template <typename T>
27  auto operator()( T&& t ) const -> decltype( auto )
28  {
29  return std::forward<T>( t );
30  }
31  };
32 
33  template <typename Iterator, typename Sep, typename Projection = Identity>
34  std::string join( Iterator first, Iterator last, Sep sep, Projection proj = {} )
35  {
36  std::string s;
37  if ( first != last ) s += proj( *first++ );
38  for ( ; first != last; ++first ) {
39  s += sep;
40  s += proj( *first );
41  }
42  return s;
43  }
44  template <typename Container, typename Sep, typename Projection = Identity>
45  std::string join( const Container& c, Sep sep, Projection proj = {} )
46  {
47  return join( begin( c ), end( c ), std::move( sep ), std::move( proj ) );
48  }
49 }
50 
52 
54 {
55  if ( msgLevel( MSG::DEBUG ) ) debug() << "started" << endmsg;
56  return collectData();
57 }
58 
59 std::map<std::string, std::string> MetaDataSvc::getMetaDataMap() const { return m_metadata; }
60 
61 StatusCode MetaDataSvc::collectData()
62 {
63 
64  // save options for all clients
65  {
66  auto joSvc = service<IJobOptionsSvc>( "JobOptionsSvc" );
67  if ( !joSvc.isValid() ) return StatusCode::FAILURE;
68  for ( const auto c : joSvc->getClients() ) {
69  // get options for this client
70  const auto props = joSvc->getProperties( c );
71  if ( props ) {
72  for ( const auto prop : *props ) {
73  m_metadata[c + "." + prop->name()] = prop->toString();
74  }
75  }
76  }
77  }
78 
79  for ( const auto* name : {"ApplicationMgr", "MessageSvc", "NTupleSvc"} ) {
80  auto svc = service<IProperty>( name );
81  if ( !svc.isValid() ) continue;
82  const auto prefix = name + std::string{"."};
83  for ( const auto* prop : svc->getProperties() ) {
84  m_metadata[prefix + prop->name()] = prop->toString();
85  }
86  }
87 
88  /*
89  * TOOLS
90  * */
91  SmartIF<IToolSvc> tSvc( serviceLocator()->service( "ToolSvc" ) );
92  if ( tSvc.isValid() ) {
93  m_metadata["ToolSvc"] = join( tSvc->getInstances( "" ), ", " );
94  }
95 
96  /*
97  * SERVICES
98  * */
99  m_metadata["ISvcLocator.Services"] = join( serviceLocator()->getServices(), ", ", get_name );
100 
101  /*
102  * ALGORITHMS
103  * */
104  SmartIF<IAlgManager> algMan( serviceLocator() );
105  m_metadata["IAlgManager.Algorithms"] = join( algMan->getAlgorithms(), ", ", get_name );
106 
107  /*
108  * JOB OPTIONS SERVICE
109  * */
110  {
111  auto joSvc = service<IProperty>( "JobOptionsSvc" );
112  if ( !joSvc.isValid() ) return StatusCode::FAILURE;
113  for ( const auto* prop : joSvc->getProperties() ) {
114  m_metadata["JobOptionsSvc." + prop->name()] = prop->toString();
115  }
116  }
117 
118  if ( msgLevel( MSG::DEBUG ) ) {
119  debug() << "Metadata collected:\n";
120  for ( const auto& item : m_metadata ) {
121  debug() << item.first << ':' << item.second << '\n';
122  }
123  debug() << endmsg;
124  }
125 
126  return StatusCode::SUCCESS;
127 }
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