| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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"
12 #include "GaudiKernel/ObjectFactory.h"
13 #include "GaudiKernel/GenericAddress.h"
14
15 #include "GaudiKernel/Property.h"
16 #include "GaudiKernel/Selector.h"
17 #include "GaudiKernel/MsgStream.h"
18 #include "GaudiKernel/MetaData.h"
19 #include "GaudiKernel/ConversionSvc.h"
20 #include "GaudiKernel/DataSelectionAgent.h"
21 #include "GaudiKernel/NTupleImplementation.h"
22
23 #include "GaudiKernel/Bootstrap.h"
24
25 #include "GaudiKernel/PropertyMgr.h"
26 #include "GaudiKernel/Service.h"
27 #include "GaudiKernel/SmartIF.h"
28
29 #include "GaudiKernel/DataObject.h"
30 #include "GaudiKernel/GaudiException.h"
31
32 #include "GaudiKernel/DataSvc.h"
33 #include "GaudiKernel/DataIncident.h"
34 #include "GaudiKernel/IAlgTool.h"
35 #include "GaudiKernel/IAlgorithm.h"
36 #include "GaudiKernel/IAlgManager.h"
37 #include "GaudiKernel/IMessageSvc.h"
38 #include "GaudiKernel/IConverter.h"
39 #include "GaudiKernel/IOpaqueAddress.h"
40 #include "GaudiKernel/IConversionSvc.h"
41 #include "GaudiKernel/ISvcLocator.h"
42 #include "GaudiKernel/IProperty.h"
43 #include "GaudiKernel/ISvcLocator.h"
44 #include "GaudiKernel/IDataSelector.h"
45 #include "GaudiKernel/IToolSvc.h"
46 #include "GaudiKernel/IJobOptionsSvc.h"
47
48 #include "MetaDataSvc.h"
49
50 using Gaudi::MetaDataSvc;
51
52 DECLARE_COMPONENT(MetaDataSvc)
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.
63 StatusCode MetaDataSvc::initialize() {
64 StatusCode sc = Service::initialize();
65 if ( sc.isFailure() ) return sc;
66 return sc;
67 }
68 bool MetaDataSvc::isEnabled( ) const {
69 return m_isEnabled;
70 }
71 StatusCode MetaDataSvc::start(){
72 if (msgLevel(MSG::DEBUG)) debug() << "started" << endmsg;
73 return collectData();
74 }
75 MetaDataSvc::~MetaDataSvc() {
76 }
77 MetaData* MetaDataSvc::getMetaData() {
78 return new MetaData(m_metadata);
79 }
80 std::map <std::string, std::string> MetaDataSvc::getMetaDataMap() {
81 return m_metadata;
82 }
83 StatusCode MetaDataSvc::collectData ()
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 * */
146 SmartIF<IAlgManager> algMan(serviceLocator());
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 }
IDataSelector.h
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
SmartIF< IToolSvc >
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
NTupleImplementation.h
Gaudi::MetaDataSvc::isEnabled
bool isEnabled() const
Definition: MetaDataSvc.cpp:68
AnalysisTest.initialize
def initialize()
Definition: AnalysisTest.py:12
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
MsgStream.h
ConversionSvc.h
IAlgorithm.h
MSG::DEBUG
Definition: IMessageSvc.h:18
ObjectFactory.h
Bootstrap.h
std
STL namespace.
MetaData.h
IAlgManager::getAlgorithms
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
merge_files.sc
int sc
Definition: merge_files.py:167
IToolSvc.h
std::map< std::string, std::string >
Gaudi::MetaDataSvc::getMetaDataMap
std::map< std::string, std::string > getMetaDataMap()
Definition: MetaDataSvc.cpp:80
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
std::stringstream
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string
STL class.
Service.h
DataSvc.h
xtoa.h
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiException.h
SmartIF.h
IAlgTool.h
std::stringstream::str
T str(T...args)
IMessageSvc.h
Gaudi::MetaDataSvc
Definition: MetaDataSvc.h:14
IOpaqueAddress.h
std::vector::size
T size(T...args)
IProperty.h
std::vector< Property * >
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
IConversionSvc.h
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
Gaudi::MetaDataSvc::~MetaDataSvc
~MetaDataSvc()
Definition: MetaDataSvc.cpp:75
Property.h
Gaudi::MetaDataSvc::getMetaData
MetaData * getMetaData()
Definition: MetaDataSvc.cpp:77
PropertyMgr.h
ana.item
tuple item
print s1,s2
Definition: ana.py:146
CommonMessaging
Definition: CommonMessaging.h:58
IOTest.appMgr
tuple appMgr
Definition: IOTest.py:83
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:144
gaudiComponentHelp.properties
tuple properties
Definition: gaudiComponentHelp.py:37
ISvcLocator::getServices
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
Gaudi::MetaDataSvc::start
StatusCode start()
Definition: MetaDataSvc.cpp:71
DataSelectionAgent.h
MetaData
Definition: MetaData.h:21
Selector.h
DataIncident.h
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
ana.i
list i
Definition: ana.py:128
IConverter.h
GenericAddress.h
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Gaudi::MetaDataSvc::collectData
StatusCode collectData()
Definition: MetaDataSvc.cpp:83
MetaDataSvc.h
DataObject.h
Gaudi::MetaDataSvc::m_isEnabled
bool m_isEnabled
Definition: MetaDataSvc.h:34
Gaudi::MetaDataSvc::m_metadata
std::map< std::string, std::string > m_metadata
Definition: MetaDataSvc.h:35
IJobOptionsSvc.h