All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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"
46 #include "GaudiKernel/IToolSvc.h"
47 
48 #include "MetaDataSvc.h"
49 
50 using Gaudi::MetaDataSvc;
51 
53 
55 {
56  if ( msgLevel( MSG::DEBUG ) ) debug() << "started" << endmsg;
57  return collectData();
58 }
62 {
63  std::string temp;
64  bool first{false};
65 
66  auto appMgr = service<IProperty>( "ApplicationMgr" );
67  if ( appMgr.isValid() ) {
69  for ( int i = 0; i < (signed)properties.size(); i++ ) {
70  temp = "ApplicationMgr." + properties[i]->name();
71  m_metadata[temp] = properties[i]->toString();
72  }
73  }
74  auto mSvc = service<IProperty>( "MessageSvc" );
75  if ( mSvc.isValid() ) {
76  const std::vector<Gaudi::Details::PropertyBase*> properties2 = mSvc->getProperties();
77  for ( int i = 0; i < (signed)properties2.size(); i++ ) {
78  temp = "MessageSvc." + properties2[i]->name();
79  m_metadata[temp] = properties2[i]->toString();
80  }
81  }
82 
83  auto nSvc = service<IProperty>( "NTupleSvc" );
84  if ( nSvc.isValid() ) {
85  const std::vector<Gaudi::Details::PropertyBase*> properties5 = nSvc->getProperties();
86  for ( int i = 0; i < (signed)properties5.size(); i++ ) {
87  temp = "NTupleSvc." + properties5[i]->name();
88  m_metadata[temp] = properties5[i]->toString();
89  }
90  }
91 
92  /*
93  * TOOLS
94  * */
95  SmartIF<IToolSvc> tSvc( serviceLocator()->service( "ToolSvc" ) );
96  if ( tSvc.isValid() ) {
97  std::vector<std::string> TSvcs = tSvc->getInstances( "" );
98  temp = "";
99  for ( int i = 0; i < (signed)TSvcs.size(); i++ ) {
100  temp += TSvcs[i];
101  if ( i != (signed)TSvcs.size() - 1 ) temp += ", ";
102  }
103  m_metadata["ToolSvc"] = temp;
104  }
105 
106  /*
107  * SERVICES
108  * */
109  auto Svcs = serviceLocator()->getServices();
110  temp = "";
111  first = true;
112  for ( auto svc : Svcs ) {
113  if ( !first )
114  temp += ", ";
115  else
116  first = false;
117  temp += svc->name();
118  }
119  m_metadata["ISvcLocator.Services"] = temp;
120 
121  /*
122  * ALGORITHMS
123  * */
125  auto allAlgs = algMan->getAlgorithms();
126  temp = "";
127  first = true;
128  for ( auto alg : allAlgs ) {
129  if ( !first )
130  temp += ", ";
131  else
132  first = false;
133  temp += alg->name();
134  }
135  m_metadata["IAlgManager.Algorithms"] = temp;
136 
137  /*
138  * JOB OPTIONS SERVICE
139  * */
140  auto joSvc = service<IProperty>( "JobOptionsSvc" );
141  if ( !joSvc.isValid() ) {
142  return StatusCode::FAILURE;
143  }
144  const std::vector<Gaudi::Details::PropertyBase*> properties7 = joSvc->getProperties();
145  for ( int i = 0; i < (signed)properties7.size(); i++ ) {
146  temp = "JobOptionsSvc." + properties7[i]->name();
147  m_metadata[temp] = properties7[i]->toString();
148  }
149 
150  if ( msgLevel( MSG::DEBUG ) ) {
151  std::stringstream ss_metadata;
152  for ( auto item : m_metadata ) {
153  ss_metadata << item.first << ':' << item.second << '\n';
154  }
155  debug() << "Metadata collected:\n" << ss_metadata.str() << endmsg;
156  }
157 
158  return StatusCode::SUCCESS;
159 }
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
start
Definition: IOTest.py:88
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:62
std::map< std::string, std::string > getMetaDataMap() override
Definition: MetaDataSvc.cpp:60
appMgr
Definition: IOTest.py:83
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:244
StatusCode collectData()
Definition: MetaDataSvc.cpp:61
std::map< std::string, std::string > m_metadata
Definition: MetaDataSvc.h:33