The Gaudi Framework  v29r0 (ff2e7097)
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/xtoa.h"
10 
11 #include "GaudiKernel/DataObject.h"
14 
17 #include "GaudiKernel/MetaData.h"
18 #include "GaudiKernel/MsgStream.h"
20 #include "GaudiKernel/Property.h"
21 #include "GaudiKernel/Selector.h"
22 
23 #include "GaudiKernel/Bootstrap.h"
24 
26 #include "GaudiKernel/Service.h"
27 #include "GaudiKernel/SmartIF.h"
28 
29 #include "GaudiKernel/DataObject.h"
31 
33 #include "GaudiKernel/DataSvc.h"
35 #include "GaudiKernel/IAlgTool.h"
36 #include "GaudiKernel/IAlgorithm.h"
38 #include "GaudiKernel/IConverter.h"
43 #include "GaudiKernel/IProperty.h"
45 #include "GaudiKernel/IToolSvc.h"
46 
47 #include "MetaDataSvc.h"
48 
49 using Gaudi::MetaDataSvc;
50 
52 
54 {
55  if ( msgLevel( MSG::DEBUG ) ) debug() << "started" << endmsg;
56  return collectData();
57 }
61 {
62  std::string temp;
63  bool first{false};
64 
65  auto appMgr = service<IProperty>( "ApplicationMgr" );
66  if ( appMgr.isValid() ) {
68  for ( int i = 0; i < (signed)properties.size(); i++ ) {
69  temp = "ApplicationMgr." + properties[i]->name();
70  m_metadata[temp] = properties[i]->toString();
71  }
72  }
73  auto mSvc = service<IProperty>( "MessageSvc" );
74  if ( mSvc.isValid() ) {
75  const std::vector<Gaudi::Details::PropertyBase*> properties2 = mSvc->getProperties();
76  for ( int i = 0; i < (signed)properties2.size(); i++ ) {
77  temp = "MessageSvc." + properties2[i]->name();
78  m_metadata[temp] = properties2[i]->toString();
79  }
80  }
81 
82  auto nSvc = service<IProperty>( "NTupleSvc" );
83  if ( nSvc.isValid() ) {
84  const std::vector<Gaudi::Details::PropertyBase*> properties5 = nSvc->getProperties();
85  for ( int i = 0; i < (signed)properties5.size(); i++ ) {
86  temp = "NTupleSvc." + properties5[i]->name();
87  m_metadata[temp] = properties5[i]->toString();
88  }
89  }
90 
91  /*
92  * TOOLS
93  * */
94  SmartIF<IToolSvc> tSvc( serviceLocator()->service( "ToolSvc" ) );
95  if ( tSvc.isValid() ) {
96  std::vector<std::string> TSvcs = tSvc->getInstances( "" );
97  temp = "";
98  for ( int i = 0; i < (signed)TSvcs.size(); i++ ) {
99  temp += TSvcs[i];
100  if ( i != (signed)TSvcs.size() - 1 ) temp += ", ";
101  }
102  m_metadata["ToolSvc"] = temp;
103  }
104 
105  /*
106  * SERVICES
107  * */
108  auto Svcs = serviceLocator()->getServices();
109  temp = "";
110  first = true;
111  for ( auto svc : Svcs ) {
112  if ( !first )
113  temp += ", ";
114  else
115  first = false;
116  temp += svc->name();
117  }
118  m_metadata["ISvcLocator.Services"] = temp;
119 
120  /*
121  * ALGORITHMS
122  * */
124  auto allAlgs = algMan->getAlgorithms();
125  temp = "";
126  first = true;
127  for ( auto alg : allAlgs ) {
128  if ( !first )
129  temp += ", ";
130  else
131  first = false;
132  temp += alg->name();
133  }
134  m_metadata["IAlgManager.Algorithms"] = temp;
135 
136  /*
137  * JOB OPTIONS SERVICE
138  * */
139  auto joSvc = service<IProperty>( "JobOptionsSvc" );
140  if ( !joSvc.isValid() ) {
141  return StatusCode::FAILURE;
142  }
143  const std::vector<Gaudi::Details::PropertyBase*> properties7 = joSvc->getProperties();
144  for ( int i = 0; i < (signed)properties7.size(); i++ ) {
145  temp = "JobOptionsSvc." + properties7[i]->name();
146  m_metadata[temp] = properties7[i]->toString();
147  }
148 
149  if ( msgLevel( MSG::DEBUG ) ) {
150  std::stringstream ss_metadata;
151  for ( auto item : m_metadata ) {
152  ss_metadata << item.first << ':' << item.second << '\n';
153  }
154  debug() << "Metadata collected:\n" << ss_metadata.str() << endmsg;
155  }
156 
157  return StatusCode::SUCCESS;
158 }
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
start
Definition: IOTest.py:99
T str(T...args)
def getMetaData(path)
Definition: __init__.py:1
T size(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
std::map< std::string, std::string > getMetaDataMap() override
Definition: MetaDataSvc.cpp:59
appMgr
Definition: IOTest.py:94
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
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&#39;t already exist.
Definition: Service.h:85
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:292
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode collectData()
Definition: MetaDataSvc.cpp:60
std::map< std::string, std::string > m_metadata
Definition: MetaDataSvc.h:33