The Gaudi Framework  v33r1 (b1225454)
JobOptionsSvc Class Reference

#include <src/JobOptionsSvc/JobOptionsSvc.h>

Inheritance diagram for JobOptionsSvc:
Collaboration diagram for JobOptionsSvc:

Public Types

typedef std::vector< const Gaudi::Details::PropertyBase * > PropertiesT
 
- Public Types inherited from extends< Service, IJobOptionsSvc >
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 Service
using Factory = Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- 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...
 

Public Member Functions

 JobOptionsSvc (const std::string &name, ISvcLocator *svc)
 
StatusCode initialize () override
 
StatusCode start () 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 Gaudi::Details::PropertyBase &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 Gaudi::Details::PropertyBase * > * getProperties (const std::string &client) const override
 Get the properties associated to a given client. More...
 
const Gaudi::Details::PropertyBasegetClientProperty (const std::string &client, const std::string &name) const override
 Get a property for a client. More...
 
std::vector< std::stringgetClients () 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...
 
- Public Member Functions inherited from extends< Service, IJobOptionsSvc >
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::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
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. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 

Private Member Functions

void fillServiceCatalog (const Gaudi::Parsers::Catalog &catalog)
 
template<typename C >
void dump (const std::string &file, const C &catalog) const
 dump properties catalog to file More...
 

Private Attributes

Gaudi::Property< std::stringm_source_type {this, "TYPE"}
 
Gaudi::Property< std::stringm_source_path {this, "PATH"}
 
Gaudi::Property< std::stringm_dir_search_path {this, "SEARCHPATH"}
 
Gaudi::Property< std::stringm_dump {this, "DUMPFILE"}
 
Gaudi::Property< std::stringm_pythonAction {this, "PYTHONACTION"}
 
Gaudi::Property< std::stringm_pythonParams {this, "PYTHONPARAMS"}
 
SvcCatalog m_svc_catalog
 

Additional Inherited Members

- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::Property< int > m_outputLevel {this, "OutputLevel", MSG::NIL, "output level"}
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, " unused"}
 
Gaudi::Property< bool > m_auditorInitialize {this, "AuditInitialize", false, "trigger auditor on initialize()"}
 
Gaudi::Property< bool > m_auditorStart {this, "AuditStart", false, "trigger auditor on start()"}
 
Gaudi::Property< bool > m_auditorStop {this, "AuditStop", false, "trigger auditor on stop()"}
 
Gaudi::Property< bool > m_auditorFinalize {this, "AuditFinalize", false, "trigger auditor on finalize()"}
 
Gaudi::Property< bool > m_auditorReinitialize {this, "AuditReinitialize", false, "trigger auditor on reinitialize()"}
 
Gaudi::Property< bool > m_auditorRestart {this, "AuditRestart", false, "trigger auditor on restart()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

Definition at line 31 of file JobOptionsSvc.h.

Member Typedef Documentation

◆ PropertiesT

Constructor & Destructor Documentation

◆ JobOptionsSvc()

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

Definition at line 34 of file JobOptionsSvc.cpp.

34  : base_class( name, svc ) {
35  if ( System::isEnvSet( "JOBOPTSEARCHPATH" ) ) m_dir_search_path = System::getEnv( "JOBOPTSEARCHPATH" );
36  if ( System::isEnvSet( "JOBOPTSDUMPFILE" ) ) m_dump = System::getEnv( "JOBOPTSDUMPFILE" );
37 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:379
extends base_class
Typedef to this class.
Definition: extends.h:24
Gaudi::Property< std::string > m_dump
Definition: JobOptionsSvc.h:84
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
Gaudi::Property< std::string > m_dir_search_path
Definition: JobOptionsSvc.h:83
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:399

Member Function Documentation

◆ addPropertyToCatalogue()

StatusCode JobOptionsSvc::addPropertyToCatalogue ( const std::string client,
const Gaudi::Details::PropertyBase property 
)
override

Add a property into the JobOptions catalog.

Definition at line 63 of file JobOptionsSvc.cpp.

64  {
65  auto p = std::make_unique<Gaudi::Property<std::string>>( property.name(), "" );
66  return property.load( *p ) ? m_svc_catalog.addProperty( client, p.release() ) : StatusCode::FAILURE;
67 }
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:88
StatusCode addProperty(const std::string &client, const Gaudi::Details::PropertyBase *property)
Definition: SvcCatalog.cpp:46
constexpr static const auto FAILURE
Definition: StatusCode.h:101

◆ dump()

template<typename C >
void JobOptionsSvc::dump ( const std::string file,
const C &  catalog 
) const
private

dump properties catalog to file

Definition at line 98 of file JobOptionsSvc.cpp.

98  {
99  std::ofstream out( file, std::ios_base::out | std::ios_base::trunc );
100  if ( !out ) {
101  error() << "Unable to open dump-file \"" + file + "\"" << endmsg;
102  return; // RETURN
103  }
104  info() << "Properties are dumped into \"" + file + "\"" << endmsg;
105  // perform the actual dump:
106  out << catalog;
107 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ fillServiceCatalog()

void JobOptionsSvc::fillServiceCatalog ( const Gaudi::Parsers::Catalog catalog)
private

Definition at line 109 of file JobOptionsSvc.cpp.

109  {
110  for ( const auto& client : catalog ) {
111  for ( const auto& current : client.second ) {
112  if ( auto sc = addPropertyToCatalogue(
113  client.first, Gaudi::Property<std::string>{current.NameInClient(), current.ValueAsString()} );
114  !sc )
115  throw GaudiException( "Failed to fill the catalog", name(), sc );
116  }
117  }
118 }
Define general base for Gaudi exception.
Implementation of property with value of concrete type.
Definition: Property.h:370
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
StatusCode addPropertyToCatalogue(const std::string &client, const Gaudi::Details::PropertyBase &property) override
Add a property into the JobOptions catalog.

◆ getClientProperty()

const Gaudi::Details::PropertyBase* JobOptionsSvc::getClientProperty ( const std::string client,
const std::string name 
) const
inlineoverride

Get a property for a client.

Definition at line 58 of file JobOptionsSvc.h.

59  {
60  return m_svc_catalog.getProperty( client, name );
61  }
const Gaudi::Details::PropertyBase * getProperty(const std::string &client, const std::string &name) const
Definition: SvcCatalog.cpp:117
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:88
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284

◆ getClients()

std::vector< std::string > JobOptionsSvc::getClients ( ) const
override

Get the list of clients.

Definition at line 95 of file JobOptionsSvc.cpp.

95 { return m_svc_catalog.getClients(); }
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:88
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:73

◆ getProperties()

const JobOptionsSvc::PropertiesT * JobOptionsSvc::getProperties ( const std::string client) const
override

Get the properties associated to a given client.

Definition at line 73 of file JobOptionsSvc.cpp.

73  {
74  return m_svc_catalog.getProperties( client );
75 }
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:69
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:88

◆ initialize()

StatusCode JobOptionsSvc::initialize ( )
override

Definition at line 39 of file JobOptionsSvc.cpp.

39  {
40  // Call base class initializer
42  // Read the job options if needed
43  if ( sc ) {
44  if ( m_source_type == "NONE" ) {
45  return sc;
46  } else if ( m_source_type == "PYTHON" ) {
47  PythonConfig conf( this );
48  return conf.evaluateConfig( m_source_path, m_pythonParams, m_pythonAction );
49  } else {
51  }
52  }
53  return sc;
54 }
StatusCode initialize() override
Definition: Service.cpp:70
Gaudi::Property< std::string > m_source_path
Definition: JobOptionsSvc.h:82
Gaudi::Property< std::string > m_pythonAction
Definition: JobOptionsSvc.h:85
Gaudi::Property< std::string > m_pythonParams
Definition: JobOptionsSvc.h:86
Gaudi::Property< std::string > m_dir_search_path
Definition: JobOptionsSvc.h:83
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
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
Gaudi::Property< std::string > m_source_type
Definition: JobOptionsSvc.h:81

◆ readOptions()

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 120 of file JobOptionsSvc.cpp.

120  {
121  std::string search_path = path;
122  if ( search_path.empty() && !m_dir_search_path.empty() ) { search_path = m_dir_search_path; }
123  //
124  if ( msgLevel( MSG::DEBUG ) )
125  debug() << "Reading options from the file "
126  << "'" << file << "'" << endmsg;
127  gp::Messages messages( msgStream() );
128  gp::Catalog catalog;
129  gp::Units units;
130  gp::PragmaOptions pragma;
131  gp::Node ast;
132  StatusCode sc = gp::ReadOptions( file, path, &messages, &catalog, &units, &pragma, &ast ) ? StatusCode::SUCCESS
134 
135  // --------------------------------------------------------------------------
136  if ( sc.isSuccess() ) {
137  if ( pragma.IsPrintOptions() ) { info() << "Print options" << std::endl << catalog << endmsg; }
138  if ( pragma.IsPrintTree() ) { info() << "Print tree:" << std::endl << ast.ToString() << endmsg; }
139  if ( pragma.HasDumpFile() ) dump( pragma.dumpFile(), catalog );
140  info() << "Job options successfully read in from " << file << endmsg;
141  fillServiceCatalog( catalog );
142  } else {
143  fatal() << "Job options errors." << endmsg;
144  }
145  // ----------------------------------------------------------------------------
146  return sc;
147 }
T empty(T... args)
void fillServiceCatalog(const Gaudi::Parsers::Catalog &catalog)
T endl(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
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:387
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
void dump(const std::string &file, const C &catalog) const
dump properties catalog to file
STL class.
Gaudi::Property< std::string > m_dir_search_path
Definition: JobOptionsSvc.h:83
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & msgStream() const
Return an uninitialized MsgStream.
bool isSuccess() const
Definition: StatusCode.h:365
constexpr static const auto FAILURE
Definition: StatusCode.h:101
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ removePropertyFromCatalogue()

StatusCode JobOptionsSvc::removePropertyFromCatalogue ( const std::string client,
const std::string name 
)
override

Remove a property from the JobOptions catalog.

Definition at line 69 of file JobOptionsSvc.cpp.

69  {
70  return m_svc_catalog.removeProperty( client, name );
71 }
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:88
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:57
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284

◆ setMyProperties()

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 77 of file JobOptionsSvc.cpp.

77  {
78  const auto* props = m_svc_catalog.getProperties( client );
79  if ( !props ) { return StatusCode::SUCCESS; }
80 
81  bool fail = false;
82  for ( const auto& cur : *props ) {
83  StatusCode sc = myInt->setProperty( *cur );
84  if ( sc.isFailure() ) {
85  error() << "Unable to set the property '" << cur->name() << "'"
86  << " of '" << client << "'. "
87  << "Check option and algorithm names, type and bounds." << endmsg;
88  fail = true;
89  }
90  }
92 }
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:69
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:88
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
constexpr static const auto FAILURE
Definition: StatusCode.h:101
bool isFailure() const
Definition: StatusCode.h:145
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ start()

StatusCode JobOptionsSvc::start ( )
override

Definition at line 57 of file JobOptionsSvc.cpp.

57  {
58  if ( !m_dump.empty() ) { dump( m_dump, m_svc_catalog ); }
59  return StatusCode::SUCCESS;
60 }
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:88
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Gaudi::Property< std::string > m_dump
Definition: JobOptionsSvc.h:84
void dump(const std::string &file, const C &catalog) const
dump properties catalog to file

Member Data Documentation

◆ m_dir_search_path

Gaudi::Property<std::string> JobOptionsSvc::m_dir_search_path {this, "SEARCHPATH"}
private

Definition at line 83 of file JobOptionsSvc.h.

◆ m_dump

Gaudi::Property<std::string> JobOptionsSvc::m_dump {this, "DUMPFILE"}
private

Definition at line 84 of file JobOptionsSvc.h.

◆ m_pythonAction

Gaudi::Property<std::string> JobOptionsSvc::m_pythonAction {this, "PYTHONACTION"}
private

Definition at line 85 of file JobOptionsSvc.h.

◆ m_pythonParams

Gaudi::Property<std::string> JobOptionsSvc::m_pythonParams {this, "PYTHONPARAMS"}
private

Definition at line 86 of file JobOptionsSvc.h.

◆ m_source_path

Gaudi::Property<std::string> JobOptionsSvc::m_source_path {this, "PATH"}
private

Definition at line 82 of file JobOptionsSvc.h.

◆ m_source_type

Gaudi::Property<std::string> JobOptionsSvc::m_source_type {this, "TYPE"}
private

Definition at line 81 of file JobOptionsSvc.h.

◆ m_svc_catalog

SvcCatalog JobOptionsSvc::m_svc_catalog
private

Definition at line 88 of file JobOptionsSvc.h.


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