The Gaudi Framework  v33r0 (d5ea422b)
MetaDataSvc.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 /*
12  * MetaDataSvc.cpp
13  *
14  * Created on: Mar 24, 2015
15  * Author: Ana Trisovic
16  */
17 
18 // Framework include files
20 #include "GaudiKernel/IAlgorithm.h"
22 #include "GaudiKernel/IProperty.h"
23 #include "GaudiKernel/IService.h"
25 #include "GaudiKernel/IToolSvc.h"
26 
27 #include "MetaDataSvc.h"
28 
29 using Gaudi::MetaDataSvc;
30 
31 namespace {
32  const auto get_name = []( const auto* i ) { return i->name(); };
33 
34  struct Identity {
35  template <typename T>
36  auto operator()( T&& t ) const -> decltype( auto ) {
37  return std::forward<T>( t );
38  }
39  };
40 
41  template <typename Iterator, typename Sep, typename Projection = Identity>
42  std::string join( Iterator first, Iterator last, Sep sep, Projection proj = {} ) {
43  std::string s;
44  if ( first != last ) s += proj( *first++ );
45  for ( ; first != last; ++first ) {
46  s += sep;
47  s += proj( *first );
48  }
49  return s;
50  }
51  template <typename Container, typename Sep, typename Projection = Identity>
52  std::string join( const Container& c, Sep sep, Projection proj = {} ) {
53  return join( begin( c ), end( c ), std::move( sep ), std::move( proj ) );
54  }
55 } // namespace
56 
58 
60  if ( msgLevel( MSG::DEBUG ) ) debug() << "started" << endmsg;
61  return collectData();
62 }
63 
64 std::map<std::string, std::string> MetaDataSvc::getMetaDataMap() const { return m_metadata; }
65 
67 
68  // save options for all clients
69  {
70  auto joSvc = service<IJobOptionsSvc>( "JobOptionsSvc" );
71  if ( !joSvc.isValid() ) return StatusCode::FAILURE;
72  for ( const auto c : joSvc->getClients() ) {
73  // get options for this client
74  const auto props = joSvc->getProperties( c );
75  if ( props ) {
76  for ( const auto prop : *props ) { m_metadata[c + "." + prop->name()] = prop->toString(); }
77  }
78  }
79  }
80 
81  for ( const auto* name : {"ApplicationMgr", "MessageSvc", "NTupleSvc"} ) {
82  auto svc = service<IProperty>( name );
83  if ( !svc.isValid() ) continue;
84  const auto prefix = name + std::string{"."};
85  for ( const auto* prop : svc->getProperties() ) { m_metadata[prefix + prop->name()] = prop->toString(); }
86  }
87 
88  /*
89  * TOOLS
90  * */
91  SmartIF<IToolSvc> tSvc( serviceLocator()->service( "ToolSvc" ) );
92  if ( tSvc.isValid() ) { m_metadata["ToolSvc"] = join( tSvc->getInstances( "" ), ", " ); }
93 
94  /*
95  * SERVICES
96  * */
97  m_metadata["ISvcLocator.Services"] = join( serviceLocator()->getServices(), ", ", get_name );
98 
99  /*
100  * ALGORITHMS
101  * */
103  m_metadata["IAlgManager.Algorithms"] = join( algMan->getAlgorithms(), ", ", get_name );
104 
105  /*
106  * JOB OPTIONS SERVICE
107  * */
108  {
109  auto joSvc = service<IProperty>( "JobOptionsSvc" );
110  if ( !joSvc.isValid() ) return StatusCode::FAILURE;
111  for ( const auto* prop : joSvc->getProperties() ) {
112  m_metadata["JobOptionsSvc." + prop->name()] = prop->toString();
113  }
114  }
115 
116  if ( msgLevel( MSG::DEBUG ) ) {
117  debug() << "Metadata collected:\n";
118  for ( const auto& item : m_metadata ) { debug() << item.first << ':' << item.second << '\n'; }
119  debug() << endmsg;
120  }
121 
122  return StatusCode::SUCCESS;
123 }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:287
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:72
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
def start
Definition: IOTest.py:108
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
#define DECLARE_COMPONENT(type)
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
string prefix
Definition: gaudirun.py:343
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
def end
Definition: IOTest.py:123
T move(T... args)
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:28
string s
Definition: gaudirun.py:328
constexpr static const auto FAILURE
Definition: StatusCode.h:97
virtual std::vector< std::string > getInstances(const std::string &toolType)=0
Get the names of all instances of tools of a given type.
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:93
AttribStringParser::Iterator begin(const AttribStringParser &parser)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
StatusCode collectData()
Definition: MetaDataSvc.cpp:66
std::map< std::string, std::string > m_metadata
Definition: MetaDataSvc.h:40