JobOptionsSvc Class Reference

#include <src/JobOptionsSvc/JobOptionsSvc.h>

Inheritance diagram for JobOptionsSvc:
Collaboration diagram for JobOptionsSvc:

Public Types

typedef std::vector< const Property * > PropertiesT
 
- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

 JobOptionsSvc (const std::string &name, ISvcLocator *svc)
 
 ~JobOptionsSvc () override=default
 destructor More...
 
StatusCode initialize () override
 
StatusCode setMyProperties (const std::string &client, IProperty *me) override
 Override default properties of the calling client. More...
 
StatusCode addPropertyToCatalogue (const std::string &client, const Property &property) override
 Add a property into the JobOptions catalog. More...
 
StatusCode removePropertyFromCatalogue (const std::string &client, const std::string &name) override
 Remove a property from the JobOptions catalog. More...
 
const std::vector< const Property * > * getProperties (const std::string &client) const override
 Get the properties associated to a given client. More...
 
std::vector< std::string > getClients () const override
 Get the list of clients. More...
 
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 More...
 
StatusCode setProperty (const Property &p) override
 IProperty implementation (needed for initialisation) More...
 
StatusCode getProperty (Property *p) const override
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Member Functions

void fillServiceCatalog (const Gaudi::Parsers::Catalog &catalog)
 
void dump (const std::string &file, const Gaudi::Parsers::Catalog &catalog) const
 

Private Attributes

PropertyMgr m_pmgr
 dump the content of Properties catalog to the predefined file More...
 
std::string m_source_path
 
std::string m_source_type
 
std::string m_dir_search_path
 
std::string m_dump
 
std::string m_pythonAction
 
std::string m_pythonParams
 
SvcCatalog m_svc_catalog
 

Detailed Description

Definition at line 20 of file JobOptionsSvc.h.

Member Typedef Documentation

typedef std::vector<const Property*> JobOptionsSvc::PropertiesT

Definition at line 22 of file JobOptionsSvc.h.

Constructor & Destructor Documentation

JobOptionsSvc::JobOptionsSvc ( const std::string &  name,
ISvcLocator svc 
)

Definition at line 27 of file JobOptionsSvc.cpp.

27  :
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 
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 }
std::string m_source_type
Definition: JobOptionsSvc.h:75
std::string m_pythonAction
Definition: JobOptionsSvc.h:78
extends base_class
Typedef to this class.
Definition: extends.h:14
std::string m_dir_search_path
Definition: JobOptionsSvc.h:76
Property * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
Definition: PropertyMgr.h:188
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:44
std::string m_dump
Definition: JobOptionsSvc.h:77
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:617
std::string m_pythonParams
Definition: JobOptionsSvc.h:79
PropertyMgr m_pmgr
dump the content of Properties catalog to the predefined file
Definition: JobOptionsSvc.h:73
std::string m_source_path
Definition: JobOptionsSvc.h:74
JobOptionsSvc::~JobOptionsSvc ( )
overridedefault

destructor

Member Function Documentation

StatusCode JobOptionsSvc::addPropertyToCatalogue ( const std::string &  client,
const Property property 
)
override

Add a property into the JobOptions catalog.

Definition at line 75 of file JobOptionsSvc.cpp.

77 {
78  std::unique_ptr<Property> p { new StringProperty ( property.name(), "" ) } ;
79  return property.load( *p ) ? m_svc_catalog.addProperty( client , p.release() )
81 }
const std::string & name() const
property name
Definition: Property.h:45
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:80
StatusCode addProperty(const std::string &client, const Property *property)
Definition: SvcCatalog.cpp:35
SimpleProperty< std::string > StringProperty
Definition: Property.h:718
bool load(Property &dest) const override
set value for another property
Definition: Property.h:283
void JobOptionsSvc::dump ( const std::string &  file,
const Gaudi::Parsers::Catalog catalog 
) const
private

Definition at line 128 of file JobOptionsSvc.cpp.

129  {
130  MsgStream log ( msgSvc() , name() ) ;
131  std::ofstream out( file , std::ios_base::out | std::ios_base::trunc );
132  if ( !out ) {
133  log << MSG::ERROR << "Unable to open dump-file \""+file+"\"" << endmsg ;
134  return ; // RETURN
135  }
136  log << MSG::INFO << "Properties are dumped into \""+file+"\"" << endmsg ;
137  // perform the actual dump:
138  out << catalog;
139 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
list file
Definition: ana.py:160
void JobOptionsSvc::fillServiceCatalog ( const Gaudi::Parsers::Catalog catalog)
private

Definition at line 141 of file JobOptionsSvc.cpp.

141  {
142  for (const auto& client : catalog) {
143  for (const auto& current : client.second ) {
144  addPropertyToCatalogue ( client.first ,
145  StringProperty{ current.NameInClient(),
146  current.ValueAsString() } );
147  }
148  }
149 }
StatusCode addPropertyToCatalogue(const std::string &client, const Property &property) override
Add a property into the JobOptions catalog.
std::vector< std::string > JobOptionsSvc::getClients ( ) const
override

Get the list of clients.

Definition at line 123 of file JobOptionsSvc.cpp.

123  {
124  return m_svc_catalog.getClients();
125 }
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:80
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:67
const JobOptionsSvc::PropertiesT * JobOptionsSvc::getProperties ( const std::string &  client) const
override

Get the properties associated to a given client.

Definition at line 92 of file JobOptionsSvc.cpp.

93 {
94  return m_svc_catalog.getProperties(client);
95 }
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:80
StatusCode JobOptionsSvc::getProperty ( Property p) const
override

Definition at line 50 of file JobOptionsSvc.cpp.

51 {
52  return m_pmgr.getProperty( p );
53 }
StatusCode getProperty(Property *p) const override
get the property
PropertyMgr m_pmgr
dump the content of Properties catalog to the predefined file
Definition: JobOptionsSvc.h:73
StatusCode JobOptionsSvc::initialize ( )
override

Definition at line 55 of file JobOptionsSvc.cpp.

56 {
57  // Call base class initializer
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 {
68  }
69  }
70  return sc;
71 }
StatusCode initialize() override
Definition: Service.cpp:63
std::string m_source_type
Definition: JobOptionsSvc.h:75
std::string m_pythonAction
Definition: JobOptionsSvc.h:78
std::string m_dir_search_path
Definition: JobOptionsSvc.h:76
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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 ...
std::string m_pythonParams
Definition: JobOptionsSvc.h:79
std::string m_source_path
Definition: JobOptionsSvc.h:74
StatusCode JobOptionsSvc::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

Parameters
filefile name
pathsearch path
Returns
status code

Definition at line 151 of file JobOptionsSvc.cpp.

152  {
153  std::string search_path = path;
154  if ( search_path.empty() && !m_dir_search_path.empty() )
155  { search_path = m_dir_search_path ; }
156  //
157  MsgStream my_log( msgSvc(), name() );
158  if (UNLIKELY(outputLevel() <= MSG::DEBUG))
159  my_log << MSG::DEBUG // debug
160  << "Reading options from the file "
161  << "'" << file << "'" << endmsg;
162  gp::Messages messages(my_log);
163  gp::Catalog catalog;
164  gp::Units units;
165  gp::PragmaOptions pragma;
166  gp::Node ast;
167  StatusCode sc = gp::ReadOptions(file, path, &messages, &catalog, &units,
168  &pragma, &ast);
169 
170  // --------------------------------------------------------------------------
171  if ( sc.isSuccess() )
172  {
173  if (pragma.IsPrintOptions()) {
174  my_log << MSG::INFO << "Print options" << std::endl << catalog
175  << endmsg;
176  }
177  if (pragma.IsPrintTree()) {
178  my_log << MSG::INFO << "Print tree:" << std::endl << ast.ToString()
179  << endmsg;
180  }
181  if (pragma.HasDumpFile()) dump(pragma.dumpFile(), catalog);
182  my_log << MSG::INFO
183  << "Job options successfully read in from " << file << endmsg;
184  fillServiceCatalog(catalog);
185  } else {
186  my_log << MSG::FATAL << "Job options errors."<< endmsg;
187  }
188  // ----------------------------------------------------------------------------
189  return sc;
190 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
void fillServiceCatalog(const Gaudi::Parsers::Catalog &catalog)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
list path
Definition: __init__.py:15
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
std::string m_dir_search_path
Definition: JobOptionsSvc.h:76
void dump(const std::string &file, const Gaudi::Parsers::Catalog &catalog) const
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
list file
Definition: ana.py:160
#define UNLIKELY(x)
Definition: Kernel.h:126
StatusCode JobOptionsSvc::removePropertyFromCatalogue ( const std::string &  client,
const std::string &  name 
)
override

Remove a property from the JobOptions catalog.

Definition at line 85 of file JobOptionsSvc.cpp.

87 {
88  return m_svc_catalog.removeProperty(client,name);
89 }
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:80
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:49
StatusCode JobOptionsSvc::setMyProperties ( const std::string &  client,
IProperty me 
)
override

Override default properties of the calling client.

Parameters
clientName of the client algorithm or service
meAddress of the interface IProperty of the client

Definition at line 97 of file JobOptionsSvc.cpp.

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  MsgStream my_log( msgSvc(), name() );
110  my_log
111  << MSG::ERROR
112  << "Unable to set the property '" << cur->name() << "'"
113  << " of '" << client << "'. "
114  << "Check option and algorithm names, type and bounds."
115  << endmsg;
116  fail = true;
117  }
118  }
119  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS ;
120 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:80
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode JobOptionsSvc::setProperty ( const Property p)
override

IProperty implementation (needed for initialisation)

Definition at line 45 of file JobOptionsSvc.cpp.

46 {
47  return m_pmgr.setProperty( p );
48 }
StatusCode setProperty(const Property &p) override
set the property form another property
PropertyMgr m_pmgr
dump the content of Properties catalog to the predefined file
Definition: JobOptionsSvc.h:73

Member Data Documentation

std::string JobOptionsSvc::m_dir_search_path
private

Definition at line 76 of file JobOptionsSvc.h.

std::string JobOptionsSvc::m_dump
private

Definition at line 77 of file JobOptionsSvc.h.

PropertyMgr JobOptionsSvc::m_pmgr
private

dump the content of Properties catalog to the predefined file

Definition at line 73 of file JobOptionsSvc.h.

std::string JobOptionsSvc::m_pythonAction
private

Definition at line 78 of file JobOptionsSvc.h.

std::string JobOptionsSvc::m_pythonParams
private

Definition at line 79 of file JobOptionsSvc.h.

std::string JobOptionsSvc::m_source_path
private

Definition at line 74 of file JobOptionsSvc.h.

std::string JobOptionsSvc::m_source_type
private

Definition at line 75 of file JobOptionsSvc.h.

SvcCatalog JobOptionsSvc::m_svc_catalog
private

Definition at line 80 of file JobOptionsSvc.h.


The documentation for this class was generated from the following files: