| The Gaudi Framework v32r1 (f65d50dc)

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
9 #include "GaudiKernel/IAlgManager.h"
10 #include "GaudiKernel/IAlgorithm.h"
11 #include "GaudiKernel/IJobOptionsSvc.h"
12 #include "GaudiKernel/IProperty.h"
13 #include "GaudiKernel/IService.h"
14 #include "GaudiKernel/ISvcLocator.h"
15 #include "GaudiKernel/IToolSvc.h"
16
17 #include "MetaDataSvc.h"
18
19 using Gaudi::MetaDataSvc;
20
21 namespace {
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 return std::forward<T>( t );
28 }
29 };
30
31 template <typename Iterator, typename Sep, typename Projection = Identity>
32 std::string join( Iterator first, Iterator last, Sep sep, Projection proj = {} ) {
33 std::string s;
34 if ( first != last ) s += proj( *first++ );
35 for ( ; first != last; ++first ) {
36 s += sep;
37 s += proj( *first );
38 }
39 return s;
40 }
41 template <typename Container, typename Sep, typename Projection = Identity>
42 std::string join( const Container& c, Sep sep, Projection proj = {} ) {
43 return join( begin( c ), end( c ), std::move( sep ), std::move( proj ) );
44 }
45 } // namespace
46
47 DECLARE_COMPONENT( MetaDataSvc )
48
49 StatusCode MetaDataSvc::start() {
50 if ( msgLevel( MSG::DEBUG ) ) debug() << "started" << endmsg;
51 return collectData();
52 }
53
54 std::map<std::string, std::string> MetaDataSvc::getMetaDataMap() const { return m_metadata; }
55
56 StatusCode MetaDataSvc::collectData() {
57
58 // save options for all clients
59 {
60 auto joSvc = service<IJobOptionsSvc>( "JobOptionsSvc" );
61 if ( !joSvc.isValid() ) return StatusCode::FAILURE;
62 for ( const auto c : joSvc->getClients() ) {
63 // get options for this client
64 const auto props = joSvc->getProperties( c );
65 if ( props ) {
66 for ( const auto prop : *props ) { m_metadata[c + "." + prop->name()] = prop->toString(); }
67 }
68 }
69 }
70
71 for ( const auto* name : {"ApplicationMgr", "MessageSvc", "NTupleSvc"} ) {
72 auto svc = service<IProperty>( name );
73 if ( !svc.isValid() ) continue;
74 const auto prefix = name + std::string{"."};
75 for ( const auto* prop : svc->getProperties() ) { m_metadata[prefix + prop->name()] = prop->toString(); }
76 }
77
78 /*
79 * TOOLS
80 * */
81 SmartIF<IToolSvc> tSvc( serviceLocator()->service( "ToolSvc" ) );
82 if ( tSvc.isValid() ) { m_metadata["ToolSvc"] = join( tSvc->getInstances( "" ), ", " ); }
83
84 /*
85 * SERVICES
86 * */
87 m_metadata["ISvcLocator.Services"] = join( serviceLocator()->getServices(), ", ", get_name );
88
89 /*
90 * ALGORITHMS
91 * */
92 SmartIF<IAlgManager> algMan( serviceLocator() );
93 m_metadata["IAlgManager.Algorithms"] = join( algMan->getAlgorithms(), ", ", get_name );
94
95 /*
96 * JOB OPTIONS SERVICE
97 * */
98 {
99 auto joSvc = service<IProperty>( "JobOptionsSvc" );
100 if ( !joSvc.isValid() ) return StatusCode::FAILURE;
101 for ( const auto* prop : joSvc->getProperties() ) {
102 m_metadata["JobOptionsSvc." + prop->name()] = prop->toString();
103 }
104 }
105
106 if ( msgLevel( MSG::DEBUG ) ) {
107 debug() << "Metadata collected:\n";
108 for ( const auto& item : m_metadata ) { debug() << item.first << ':' << item.second << '\n'; }
109 debug() << endmsg;
110 }
111
112 return StatusCode::SUCCESS;
113 }
SmartIF< IToolSvc >
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:277
gaudirun.c
c
Definition: gaudirun.py:487
IAlgorithm.h
MSG::DEBUG
Definition: IMessageSvc.h:15
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
IAlgManager::getAlgorithms
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
IToolSvc.h
IOTest.start
def start
Definition: IOTest.py:97
std::map< std::string, std::string >
CommonMessaging< implements< IService, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:138
std::string
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
gaudirun.prefix
string prefix
Definition: gaudirun.py:331
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:107
IOTest.end
def end
Definition: IOTest.py:112
std::move
T move(T... args)
IService.h
Gaudi::MetaDataSvc
Definition: MetaDataSvc.h:15
IProperty.h
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:18
gaudirun.s
string s
Definition: gaudirun.py:316
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
IAlgManager.h
IToolSvc::getInstances
virtual std::vector< std::string > getInstances(const std::string &toolType)=0
Get the names of all instances of tools of a given type.
Service::service
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:83
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:120
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi::MetaDataSvc::collectData
StatusCode collectData()
Definition: MetaDataSvc.cpp:56
MetaDataSvc.h
Gaudi::MetaDataSvc::m_metadata
std::map< std::string, std::string > m_metadata
Definition: MetaDataSvc.h:30
IJobOptionsSvc.h