| The Gaudi Framework v28r2-patches (bc4ad17a)

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

- File List
- File Members

JobOptionsSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Local:
3 // ============================================================================
4 #include "JobOptionsSvc.h"
5 #include "Analyzer.h"
6 #include "Catalog.h"
7 #include "Messages.h"
8 #include "Node.h"
9 #include "PragmaOptions.h"
10 #include "PythonConfig.h"
11 #include "Units.h"
12 // ============================================================================
13 // Gaudi:
14 // ============================================================================
15 #include "GaudiKernel/MsgStream.h"
16 #include "GaudiKernel/System.h"
17 // ============================================================================
18 DECLARE_COMPONENT( JobOptionsSvc )
19 // ============================================================================
20 // Namespace aliases:
21 // ============================================================================
22 namespace gp = Gaudi::Parsers;
23 // ============================================================================
24 JobOptionsSvc::JobOptionsSvc( const std::string& name, ISvcLocator* svc ) : base_class( name, svc )
25 {
26 if ( System::isEnvSet( "JOBOPTSEARCHPATH" ) ) m_dir_search_path = System::getEnv( "JOBOPTSEARCHPATH" );
27 if ( System::isEnvSet( "JOBOPTSDUMPFILE" ) ) m_dump = System::getEnv( "JOBOPTSDUMPFILE" );
28 }
29 // ============================================================================
30 StatusCode JobOptionsSvc::initialize()
31 {
32 // Call base class initializer
33 StatusCode sc = Service::initialize();
34 // Read the job options if needed
35 if ( sc ) {
36 if ( m_source_type == "NONE" ) {
37 return sc;
38 } else if ( m_source_type == "PYTHON" ) {
39 PythonConfig conf( this );
40 return conf.evaluateConfig( m_source_path, m_pythonParams, m_pythonAction );
41 } else {
42 return readOptions( m_source_path, m_dir_search_path );
43 }
44 }
45 return sc;
46 }
47
48 // ============================================================================
49 StatusCode JobOptionsSvc::addPropertyToCatalogue( const std::string& client,
50 const Gaudi::Details::PropertyBase& property )
51 {
52 std::unique_ptr<Gaudi::Details::PropertyBase> p{new Gaudi::Property<std::string>( property.name(), "" )};
53 return property.load( *p ) ? m_svc_catalog.addProperty( client, p.release() ) : StatusCode::FAILURE;
54 }
55 // ============================================================================
56 StatusCode JobOptionsSvc::removePropertyFromCatalogue( const std::string& client, const std::string& name )
57 {
58 return m_svc_catalog.removeProperty( client, name );
59 }
60 // ============================================================================
61 const JobOptionsSvc::PropertiesT* JobOptionsSvc::getProperties( const std::string& client ) const
62 {
63 return m_svc_catalog.getProperties( client );
64 }
65 // ============================================================================
66 StatusCode JobOptionsSvc::setMyProperties( const std::string& client, IProperty* myInt )
67 {
68 const auto* props = m_svc_catalog.getProperties( client );
69 if ( !props ) {
70 return StatusCode::SUCCESS;
71 }
72
73 bool fail = false;
74 for ( const auto& cur : *props ) {
75 StatusCode sc = myInt->setProperty( *cur );
76 if ( sc.isFailure() ) {
77 error() << "Unable to set the property '" << cur->name() << "'"
78 << " of '" << client << "'. "
79 << "Check option and algorithm names, type and bounds." << endmsg;
80 fail = true;
81 }
82 }
83 return fail ? StatusCode::FAILURE : StatusCode::SUCCESS;
84 }
85
87 std::vector<std::string> JobOptionsSvc::getClients() const { return m_svc_catalog.getClients(); }
88
89 void JobOptionsSvc::dump( const std::string& file, const gp::Catalog& catalog ) const
90 {
91 std::ofstream out( file, std::ios_base::out | std::ios_base::trunc );
92 if ( !out ) {
93 error() << "Unable to open dump-file \"" + file + "\"" << endmsg;
94 return; // RETURN
95 }
96 info() << "Properties are dumped into \"" + file + "\"" << endmsg;
97 // perform the actual dump:
98 out << catalog;
99 }
100
101 void JobOptionsSvc::fillServiceCatalog( const gp::Catalog& catalog )
102 {
103 for ( const auto& client : catalog ) {
104 for ( const auto& current : client.second ) {
105 addPropertyToCatalogue( client.first,
106 Gaudi::Property<std::string>{current.NameInClient(), current.ValueAsString()} );
107 }
108 }
109 }
110
111 StatusCode JobOptionsSvc::readOptions( const std::string& file, const std::string& path )
112 {
113 std::string search_path = path;
114 if ( search_path.empty() && !m_dir_search_path.empty() ) {
115 search_path = m_dir_search_path;
116 }
117 //
118 if ( msgLevel( MSG::DEBUG ) )
119 debug() << "Reading options from the file "
120 << "'" << file << "'" << endmsg;
121 gp::Messages messages( msgStream() );
122 gp::Catalog catalog;
123 gp::Units units;
124 gp::PragmaOptions pragma;
125 gp::Node ast;
126 StatusCode sc = gp::ReadOptions( file, path, &messages, &catalog, &units, &pragma, &ast );
127
128 // --------------------------------------------------------------------------
129 if ( sc.isSuccess() ) {
130 if ( pragma.IsPrintOptions() ) {
131 info() << "Print options" << std::endl << catalog << endmsg;
132 }
133 if ( pragma.IsPrintTree() ) {
134 info() << "Print tree:" << std::endl << ast.ToString() << endmsg;
135 }
136 if ( pragma.HasDumpFile() ) dump( pragma.dumpFile(), catalog );
137 info() << "Job options successfully read in from " << file << endmsg;
138 fillServiceCatalog( catalog );
139 } else {
140 fatal() << "Job options errors." << endmsg;
141 }
142 // ----------------------------------------------------------------------------
143 return sc;
144 }
PythonConfig.h
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:550
Analyzer.h
PragmaOptions.h
System.h
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
StatusCode::SUCCESS
Definition: StatusCode.h:30
JobOptionsSvc::m_source_path
Gaudi::Property< std::string > m_source_path
Definition: JobOptionsSvc.h:74
std::string::empty
T empty(T...args)
JobOptionsSvc::fillServiceCatalog
void fillServiceCatalog(const Gaudi::Parsers::Catalog &catalog)
Definition: JobOptionsSvc.cpp:101
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:772
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::FAILURE
Definition: StatusCode.h:29
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::property
Gaudi::Details::PropertyBase * property(const std::string &name) const
Definition: PropertyHolder.h:345
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:314
MsgStream.h
JobOptionsSvc::m_pythonAction
Gaudi::Property< std::string > m_pythonAction
Definition: JobOptionsSvc.h:77
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:123
SvcCatalog::getProperties
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::getProperties
const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const override
get all properties
Definition: PropertyHolder.h:331
Messages.h
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
JobOptionsSvc::m_svc_catalog
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:80
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
std
STL namespace.
SvcCatalog::addProperty
StatusCode addProperty(const std::string &client, const Gaudi::Details::PropertyBase *property)
Definition: SvcCatalog.cpp:40
JobOptionsSvc.h
Gaudi::Parsers::ReadOptions
bool ReadOptions(const std::string &filename, const std::string &search_path, Messages *messages, Catalog *catalog, Units *units, PragmaOptions *pragma, Node *root)
Parse and analyze filename, save all messages and properties.
Definition: Analyzer.cpp:416
PythonConfig::evaluateConfig
StatusCode evaluateConfig(const std::string &filename, const std::string &preAction, const std::string &postAction)
Definition: PythonConfig.cpp:8
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
SvcCatalog::removeProperty
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:52
SvcCatalog::getClients
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:70
Catalog.h
std::string
STL class.
PythonConfig
Definition: PythonConfig.h:25
JobOptionsSvc::dump
void dump(const std::string &file, const Gaudi::Parsers::Catalog &catalog) const
Definition: JobOptionsSvc.cpp:89
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
std::ofstream
STL class.
IProperty::setProperty
virtual StatusCode setProperty(const Gaudi::Details::PropertyBase &p)=0
Set the property by property.
JobOptionsSvc::setMyProperties
StatusCode setMyProperties(const std::string &client, IProperty *me) override
Override default properties of the calling client.
Definition: JobOptionsSvc.cpp:66
JobOptionsSvc
Definition: JobOptionsSvc.h:23
JobOptionsSvc::m_pythonParams
Gaudi::Property< std::string > m_pythonParams
Definition: JobOptionsSvc.h:78
JobOptionsSvc::m_dir_search_path
Gaudi::Property< std::string > m_dir_search_path
Definition: JobOptionsSvc.h:75
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Node.h
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
System::isEnvSet
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:570
Gaudi::Property::load
bool load(Details::PropertyBase &dest) const override
set value to another property
Definition: Property.h:609
std::vector
STL class.
std::unique_ptr< Gaudi::Details::PropertyBase >
Units.h
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:126
JobOptionsSvc::readOptions
StatusCode readOptions(const std::string &file, const std::string &path="") override
look for file &#39;file&#39; into search path &#39;path&#39; and read it to update existing JobOptionsCatalogue ...
Definition: JobOptionsSvc.cpp:111
Gaudi::Parsers
Definition: DODBasicMapper.cpp:7
JobOptionsSvc::removePropertyFromCatalogue
StatusCode removePropertyFromCatalogue(const std::string &client, const std::string &name) override
Remove a property from the JobOptions catalog.
Definition: JobOptionsSvc.cpp:56
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition: CommonMessaging.h:88
JobOptionsSvc::initialize
StatusCode initialize() override
Definition: JobOptionsSvc.cpp:30
CommonMessaging
Definition: CommonMessaging.h:55
JobOptionsSvc::m_source_type
Gaudi::Property< std::string > m_source_type
dump the content of Properties catalog to the predefined file
Definition: JobOptionsSvc.h:73
JobOptionsSvc::addPropertyToCatalogue
StatusCode addPropertyToCatalogue(const std::string &client, const Gaudi::Details::PropertyBase &property) override
Add a property into the JobOptions catalog.
Definition: JobOptionsSvc.cpp:49
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:111
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:135
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
JobOptionsSvc::getClients
std::vector< std::string > getClients() const override
Get the list of clients.
Definition: JobOptionsSvc.cpp:87
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244