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 
15 #include "GaudiKernel/Property.h"
16 #include "GaudiKernel/Selector.h"
17 #include "GaudiKernel/MsgStream.h"
18 #include "GaudiKernel/MetaData.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 
32 #include "GaudiKernel/DataSvc.h"
34 #include "GaudiKernel/IAlgTool.h"
35 #include "GaudiKernel/IAlgorithm.h"
38 #include "GaudiKernel/IConverter.h"
42 #include "GaudiKernel/IProperty.h"
45 #include "GaudiKernel/IToolSvc.h"
47 
48 #include "MetaDataSvc.h"
49 
50 using Gaudi::MetaDataSvc;
51 
53 
54 // Standard Constructor.
55 // Input: name String with service name
56 // Input: svc Pointer to service locator interface
57 
58 MetaDataSvc::MetaDataSvc( const std::string& name, ISvcLocator* svc )
59 : base_class(name, svc) {
60  declareProperty("Enable", m_isEnabled = true);
61 }
62 // Initialize the service.
65  if ( sc.isFailure() ) return sc;
66  return sc;
67 }
68 bool MetaDataSvc::isEnabled( ) const {
69  return m_isEnabled;
70 }
72  if (msgLevel(MSG::DEBUG)) debug() << "started" << endmsg;
73  return collectData();
74 }
76 }
78  return new MetaData(m_metadata);
79 }
81  return m_metadata;
82 }
84 {
85  std::string temp;
86  bool first{false};
87 
88  auto appMgr = service<IProperty>("ApplicationMgr");
89  if( appMgr.isValid() ) {
90  const std::vector<Property*> properties = appMgr->getProperties();
91  for( int i= 0; i< (signed)properties.size(); i++ ){
92  temp="ApplicationMgr." + properties[i]->name();
93  m_metadata[temp]=properties[i]->toString();
94  }
95  }
96  auto mSvc = service<IProperty>("MessageSvc");
97  if( mSvc.isValid() ) {
98  const std::vector<Property*> properties2 = mSvc->getProperties();
99  for( int i= 0; i< (signed)properties2.size(); i++ ){
100  temp="MessageSvc." + properties2[i]->name();
101  m_metadata[temp]=properties2[i]->toString();
102  }
103  }
104 
105  auto nSvc = service<IProperty>("NTupleSvc");
106  if( nSvc.isValid() ) {
107  const std::vector<Property*> properties5 = nSvc->getProperties();
108  for( int i= 0; i< (signed)properties5.size(); i++ ){
109  temp="NTupleSvc." + properties5[i]->name();
110  m_metadata[temp]=properties5[i]->toString();
111  }
112  }
113 
114  /*
115  * TOOLS
116  * */
117  SmartIF<IToolSvc> tSvc(serviceLocator()->service("ToolSvc"));
118  if(tSvc.isValid() ) {
119  std::vector<std::string> TSvcs = tSvc->getInstances("");
120  temp="";
121  for( int i= 0; i< (signed)TSvcs.size(); i++ ){
122  temp += TSvcs[i];
123  if (i!=(signed)TSvcs.size()-1)temp+=", ";
124  }
125  m_metadata["ToolSvc"]=temp;
126  }
127 
128  /*
129  * SERVICES
130  * */
131  auto Svcs = serviceLocator()->getServices();
132  temp = "";
133  first = true;
134  for (auto svc: Svcs) {
135  if (!first)
136  temp += ", ";
137  else
138  first = false;
139  temp += svc->name();
140  }
141  m_metadata["ISvcLocator.Services"]=temp;
142 
143  /*
144  * ALGORITHMS
145  * */
147  auto allAlgs = algMan->getAlgorithms();
148  temp = "";
149  first = true;
150  for(auto alg: allAlgs) {
151  if (!first)
152  temp += ", ";
153  else
154  first = false;
155  temp += alg->name();
156  }
157  m_metadata["IAlgManager.Algorithms"] = temp;
158 
159  /*
160  * JOB OPTIONS SERVICE
161  * */
162  auto joSvc = service<IProperty>("JobOptionsSvc");
163  if( !joSvc.isValid() ) { return StatusCode::FAILURE ;}
164  const std::vector<Property*> properties7 = joSvc->getProperties();
165  for( int i= 0; i< (signed)properties7.size(); i++ ){
166  temp="JobOptionsSvc." + properties7[i]->name();
167  m_metadata[temp]=properties7[i]->toString();
168  }
169 
170  if (msgLevel(MSG::DEBUG)) {
171  std::stringstream ss_metadata;
172  for(auto item: m_metadata) {
173  ss_metadata << item.first
174  << ':'
175  << item.second
176  << '\n';
177  }
178  debug() << "Metadata collected:\n" << ss_metadata.str() << endmsg;
179  }
180 
181  return StatusCode::SUCCESS;
182 }
StatusCode initialize() override
Definition: Service.cpp:68
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
bool isEnabled() const
Definition: MetaDataSvc.cpp:68
def initialize()
Definition: AnalysisTest.py:12
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
STL namespace.
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
std::map< std::string, std::string > getMetaDataMap()
Definition: MetaDataSvc.cpp:80
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
#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
T str(T...args)
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
MetaData * getMetaData()
Definition: MetaDataSvc.cpp:77
tuple item
print s1,s2
Definition: ana.py:146
tuple appMgr
Definition: IOTest.py:83
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:144
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
StatusCode start()
Definition: MetaDataSvc.cpp:71
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode collectData()
Definition: MetaDataSvc.cpp:83
std::map< std::string, std::string > m_metadata
Definition: MetaDataSvc.h:35