| The Gaudi Framework v27r1

- 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 "Messages.h"
7 #include "Catalog.h"
8 #include "Units.h"
9 #include "PragmaOptions.h"
10 #include "Node.h"
11 #include "PythonConfig.h"
12 // ============================================================================
13 // Gaudi:
14 // ============================================================================
15 #include "GaudiKernel/IProperty.h"
16 #include "GaudiKernel/Property.h"
17
18 #include "GaudiKernel/MsgStream.h"
19 #include "GaudiKernel/System.h"
20 // ============================================================================
21 DECLARE_COMPONENT(JobOptionsSvc)
22 // ============================================================================
23 // Namespace aliases:
24 // ============================================================================
25 namespace gp = Gaudi::Parsers;
26 // ============================================================================
27 JobOptionsSvc::JobOptionsSvc(const std::string& name,ISvcLocator* svc):
28 base_class(name,svc)
29 {
30 m_pmgr.addRef(); // make sure the refCount doesn't go to zero too soon...
31 std::string tmp ;
32 tmp = System::getEnv ( "JOBOPTSEARCHPATH" ) ;
33 if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dir_search_path = tmp ; }
34 tmp = System::getEnv ( "JOBOPTSDUMPFILE" ) ;
35 if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dump = tmp ; }
36
37 m_pmgr.declareProperty( "TYPE" , m_source_type ) ;
38 m_pmgr.declareProperty( "PATH" , m_source_path ) ;
39 m_pmgr.declareProperty( "SEARCHPATH" , m_dir_search_path ) ;
40 m_pmgr.declareProperty( "DUMPFILE" , m_dump ) ;
41 m_pmgr.declareProperty( "PYTHONACTION" , m_pythonAction ) ;
42 m_pmgr.declareProperty( "PYTHONPARAMS" , m_pythonParams ) ;
43 }
44 // ============================================================================
45 StatusCode JobOptionsSvc::setProperty( const Property &p )
46 {
47 return m_pmgr.setProperty( p );
48 }
49 // ============================================================================
50 StatusCode JobOptionsSvc::getProperty( Property *p ) const
51 {
52 return m_pmgr.getProperty( p );
53 }
54 // ============================================================================
55 StatusCode JobOptionsSvc::initialize()
56 {
57 // Call base class initializer
58 StatusCode sc = Service::initialize();
59 // Read the job options if needed
60 if (sc) {
61 if (m_source_type == "NONE") {
62 return sc;
63 } else if (m_source_type == "PYTHON") {
64 PythonConfig conf(this);
65 return conf.evaluateConfig(m_source_path, m_pythonParams, m_pythonAction);
66 } else {
67 return readOptions( m_source_path , m_dir_search_path);
68 }
69 }
70 return sc;
71 }
72
73 // ============================================================================
74 StatusCode JobOptionsSvc::addPropertyToCatalogue
75 ( const std::string& client,
76 const Property& property )
77 {
78 std::unique_ptr<Property> p { new StringProperty ( property.name(), "" ) } ;
79 return property.load( *p ) ? m_svc_catalog.addProperty( client , p.release() )
80 : StatusCode::FAILURE ;
81 }
82 // ============================================================================
83 StatusCode
84 JobOptionsSvc::removePropertyFromCatalogue
85 ( const std::string& client,
86 const std::string& name )
87 {
88 return m_svc_catalog.removeProperty(client,name);
89 }
90 // ============================================================================
91 const JobOptionsSvc::PropertiesT*
92 JobOptionsSvc::getProperties( const std::string& client) const
93 {
94 return m_svc_catalog.getProperties(client);
95 }
96 // ============================================================================
97 StatusCode JobOptionsSvc::setMyProperties( const std::string& client,
98 IProperty* myInt )
99 {
100 const auto* props = m_svc_catalog.getProperties(client);
101 if ( !props ){ return StatusCode::SUCCESS; }
102
103 bool fail = false;
104 for ( const auto& cur : *props )
105 {
106 StatusCode sc = myInt->setProperty ( *cur ) ;
107 if ( sc.isFailure() )
108 {
109 error()
110 << "Unable to set the property '" << cur->name() << "'"
111 << " of '" << client << "'. "
112 << "Check option and algorithm names, type and bounds."
113 << endmsg;
114 fail = true;
115 }
116 }
117 return fail ? StatusCode::FAILURE : StatusCode::SUCCESS ;
118 }
119
121 std::vector<std::string> JobOptionsSvc::getClients() const {
122 return m_svc_catalog.getClients();
123 }
124
125
126 void JobOptionsSvc::dump (const std::string& file,
127 const gp::Catalog& catalog) const {
128 std::ofstream out( file , std::ios_base::out | std::ios_base::trunc );
129 if ( !out ) {
130 error() << "Unable to open dump-file \""+file+"\"" << endmsg ;
131 return ; // RETURN
132 }
133 info() << "Properties are dumped into \""+file+"\"" << endmsg ;
134 // perform the actual dump:
135 out << catalog;
136 }
137
138 void JobOptionsSvc::fillServiceCatalog(const gp::Catalog& catalog) {
139 for (const auto& client : catalog) {
140 for (const auto& current : client.second ) {
141 addPropertyToCatalogue ( client.first ,
142 StringProperty{ current.NameInClient(),
143 current.ValueAsString() } );
144 }
145 }
146 }
147
148 StatusCode JobOptionsSvc::readOptions ( const std::string& file,
149 const std::string& path) {
150 std::string search_path = path;
151 if ( search_path.empty() && !m_dir_search_path.empty() )
152 { search_path = m_dir_search_path ; }
153 //
154 if (msgLevel(MSG::DEBUG))
155 debug() << "Reading options from the file "
156 << "'" << file << "'" << endmsg;
157 gp::Messages messages(msgStream());
158 gp::Catalog catalog;
159 gp::Units units;
160 gp::PragmaOptions pragma;
161 gp::Node ast;
162 StatusCode sc = gp::ReadOptions(file, path, &messages, &catalog, &units,
163 &pragma, &ast);
164
165 // --------------------------------------------------------------------------
166 if ( sc.isSuccess() )
167 {
168 if (pragma.IsPrintOptions()) {
169 info() << "Print options" << std::endl << catalog
170 << endmsg;
171 }
172 if (pragma.IsPrintTree()) {
173 info() << "Print tree:" << std::endl << ast.ToString()
174 << endmsg;
175 }
176 if (pragma.HasDumpFile()) dump(pragma.dumpFile(), catalog);
177 info() << "Job options successfully read in from " << file << endmsg;
178 fillServiceCatalog(catalog);
179 } else {
180 fatal() << "Job options errors."<< endmsg;
181 }
182 // ----------------------------------------------------------------------------
183 return sc;
184 }
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:617
Analyzer.h
PragmaOptions.h
System.h
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
std::string::empty
T empty(T...args)
JobOptionsSvc::fillServiceCatalog
void fillServiceCatalog(const Gaudi::Parsers::Catalog &catalog)
Definition: JobOptionsSvc.cpp:138
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
JobOptionsSvc::getClients
std::vector< std::string > getClients() const override
Get the list of clients.
Definition: JobOptionsSvc.cpp:121
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
JobOptionsSvc::m_source_type
std::string m_source_type
Definition: JobOptionsSvc.h:77
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
SvcCatalog::getProperties
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
Property::name
const std::string & name() const
property name
Definition: Property.h:45
PropertyMgr::setProperty
StatusCode setProperty(const Property &p) override
set the property form another property
Definition: PropertyMgr.cpp:105
Messages.h
JobOptionsSvc::m_pythonAction
std::string m_pythonAction
Definition: JobOptionsSvc.h:80
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
JobOptionsSvc::m_svc_catalog
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:82
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
std
STL namespace.
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
merge_files.sc
int sc
Definition: merge_files.py:167
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
JobOptionsSvc::getProperty
StatusCode getProperty(Property *p) const override
Definition: JobOptionsSvc.cpp:50
StringProperty
SimpleProperty< std::string > StringProperty
Definition: Property.h:718
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
SvcCatalog::getClients
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:67
JobOptionsSvc::m_dir_search_path
std::string m_dir_search_path
Definition: JobOptionsSvc.h:78
Catalog.h
std::string
STL class.
SimpleProperty< std::string >
PropertyMgr::getProperty
StatusCode getProperty(Property *p) const override
get the property
Definition: PropertyMgr.cpp:144
PythonConfig
Definition: PythonConfig.h:23
Service::getProperties
const std::vector< Property * > & getProperties() const override
Definition: Service.cpp:354
JobOptionsSvc::dump
void dump(const std::string &file, const Gaudi::Parsers::Catalog &catalog) const
Definition: JobOptionsSvc.cpp:126
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
std::ofstream
STL class.
JobOptionsSvc::setMyProperties
StatusCode setMyProperties(const std::string &client, IProperty *me) override
Override default properties of the calling client.
Definition: JobOptionsSvc.cpp:97
JobOptionsSvc::setProperty
StatusCode setProperty(const Property &p) override
IProperty implementation (needed for initialisation)
Definition: JobOptionsSvc.cpp:45
JobOptionsSvc
Definition: JobOptionsSvc.h:20
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
IProperty::setProperty
virtual StatusCode setProperty(const Property &p)=0
Set the property by property.
Node.h
ana.file
list file
Definition: ana.py:160
Gaudi::Utils::Histos::path
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
Definition: HistoTableFormat.cpp:191
IProperty.h
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector
STL class.
std::unique_ptr< Property >
Units.h
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
Property.h
JobOptionsSvc::readOptions
StatusCode readOptions(const std::string &file, const std::string &path="") override
look for file 'file' into search path 'path' and read it to update existing JobOptionsCatalogue ...
Definition: JobOptionsSvc.cpp:148
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:85
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition: CommonMessaging.h:89
JobOptionsSvc::addPropertyToCatalogue
StatusCode addPropertyToCatalogue(const std::string &client, const Property &property) override
Add a property into the JobOptions catalog.
Definition: JobOptionsSvc.cpp:75
JobOptionsSvc::initialize
StatusCode initialize() override
Definition: JobOptionsSvc.cpp:55
CommonMessaging
Definition: CommonMessaging.h:58
JobOptionsSvc::m_pythonParams
std::string m_pythonParams
Definition: JobOptionsSvc.h:81
PropertyWithValue::load
bool load(Property &dest) const override
set value for another property
Definition: Property.h:283
JobOptionsSvc::m_pmgr
PropertyMgr m_pmgr
dump the content of Properties catalog to the predefined file
Definition: JobOptionsSvc.h:75
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:112
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
JobOptionsSvc::m_source_path
std::string m_source_path
Definition: JobOptionsSvc.h:76
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244