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 >
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 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)
 IProperty implementation (needed for initialisation) More...
 
StatusCode getProperty (Property *p) const
 
- 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
 
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 26 of file JobOptionsSvc.cpp.

26  :
27  base_class(name,svc)
28 {
29  m_pmgr.addRef(); // make sure the refCount doesn't go to zero too soon...
30  std::string tmp ;
31  tmp = System::getEnv ( "JOBOPTSEARCHPATH" ) ;
32  if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dir_search_path = tmp ; }
33  tmp = System::getEnv ( "JOBOPTSDUMPFILE" ) ;
34  if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dump = tmp ; }
35 
38  m_pmgr.declareProperty( "SEARCHPATH" , m_dir_search_path ) ;
39  m_pmgr.declareProperty( "DUMPFILE" , m_dump ) ;
40 }
std::string m_source_type
Definition: JobOptionsSvc.h:75
std::string m_dir_search_path
Definition: JobOptionsSvc.h:76
extends base_class
Typedef to this class.
Definition: extends.h:14
Property * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
Definition: PropertyMgr.h:177
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:43
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:619
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 68 of file JobOptionsSvc.cpp.

70 {
71  std::unique_ptr<Property> p { new StringProperty ( property.name(), "" ) } ;
72  if ( !property.load( *p ) ) { return StatusCode::FAILURE ; }
73  return m_svc_catalog.addProperty( client , p.release() );
74 }
const std::string & name() const
property name
Definition: Property.h:45
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:78
StatusCode addProperty(const std::string &client, const Property *property)
Definition: SvcCatalog.cpp:35
virtual bool load(Property &dest) const =0
export the property value to the destination
SimpleProperty< std::string > StringProperty
Definition: Property.h:718
void JobOptionsSvc::dump ( const std::string &  file,
const Gaudi::Parsers::Catalog catalog 
) const
private

Definition at line 123 of file JobOptionsSvc.cpp.

124  {
125  MsgStream log ( msgSvc() , name() ) ;
126  std::ofstream out
127  ( file.c_str() , std::ios_base::out | std::ios_base::trunc ) ;
128  // perform the actual dumping
129  if ( !out ) {
130  log << MSG::ERROR << "Unable to open dump-file \""+file+"\"" << endmsg ;
131  return ; // RETURN
132  }
133  else {
134  log << MSG::INFO << "Properties are dumped into \""+file+"\"" << endmsg ;
135  }
136  // perform the actual dump:
137  out << catalog;
138 }
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 140 of file JobOptionsSvc.cpp.

140  {
141  for (const auto& client : catalog) {
142  for (const auto& current : client.second ) {
143  addPropertyToCatalogue ( client.first ,
144  StringProperty{ current.NameInClient(),
145  current.ValueAsString() } );
146  }
147  }
148 }
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 118 of file JobOptionsSvc.cpp.

118  {
119  return m_svc_catalog.getClients();
120 }
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:78
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 85 of file JobOptionsSvc.cpp.

86 {
87  return m_svc_catalog.getProperties(client);
88 }
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:78
StatusCode JobOptionsSvc::getProperty ( Property p) const

Definition at line 47 of file JobOptionsSvc.cpp.

48 {
49  return m_pmgr.getProperty( p );
50 }
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 52 of file JobOptionsSvc.cpp.

53 {
54  // Call base class initializer
56  if( !sc.isSuccess() ) return sc;
57  // Read the job options if needed
58  if ( this->m_source_type == "NONE" ) {
60  } else {
62  }
63  return sc;
64 }
StatusCode initialize() override
Definition: Service.cpp:62
std::string m_source_type
Definition: JobOptionsSvc.h:75
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
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_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 150 of file JobOptionsSvc.cpp.

151  {
152  std::string search_path = path;
153  if ( search_path.empty() && !m_dir_search_path.empty() )
154  { search_path = m_dir_search_path ; }
155  //
156  MsgStream my_log( this->msgSvc(), this->name() );
157  if (UNLIKELY(outputLevel() <= MSG::DEBUG))
158  my_log << MSG::DEBUG // debug
159  << "Reading options from the file "
160  << "'" << file << "'" << endmsg;
161  gp::Messages messages(my_log);
162  gp::Catalog catalog;
163  gp::Units units;
164  gp::PragmaOptions pragma;
165  gp::Node ast;
166  StatusCode sc = gp::ReadOptions(file, path, &messages, &catalog, &units,
167  &pragma, &ast);
168 
169  // --------------------------------------------------------------------------
170  if ( sc.isSuccess() )
171  {
172  if (pragma.IsPrintOptions()) {
173  my_log << MSG::INFO << "Print options" << std::endl << catalog
174  << endmsg;
175  }
176  if (pragma.IsPrintTree()) {
177  my_log << MSG::INFO << "Print tree:" << std::endl << ast.ToString()
178  << endmsg;
179  }
180  if (pragma.HasDumpFile()) {
181  dump(pragma.dumpFile(), catalog);
182  }
183  my_log << MSG::INFO
184  << "Job options successfully read in from " << file << endmsg;
185  fillServiceCatalog(catalog);
186  }
187  else
188  {
189  my_log << MSG::FATAL << "Job options errors."<< endmsg;
190  }
191  // ----------------------------------------------------------------------------
192  return sc;
193 }
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 78 of file JobOptionsSvc.cpp.

80 {
81  return m_svc_catalog.removeProperty(client,name);
82 }
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:78
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 90 of file JobOptionsSvc.cpp.

92 {
93  const SvcCatalog::PropertiesT* props =
95 
96  if ( !props ){ return StatusCode::SUCCESS; }
97 
98  bool fail = false;
99  for ( const auto& cur : *props )
100  {
101  StatusCode sc = myInt->setProperty ( *cur ) ;
102  if ( sc.isFailure() )
103  {
104  MsgStream my_log( this->msgSvc(), this->name() );
105  my_log
106  << MSG::ERROR
107  << "Unable to set the property '" << cur->name() << "'"
108  << " of '" << client << "'. "
109  << "Check option and algorithm names, type and bounds."
110  << endmsg;
111  fail = true;
112  }
113  }
114  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS ;
115 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SvcCatalog m_svc_catalog
Definition: JobOptionsSvc.h:78
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
std::vector< const Property * > PropertiesT
Definition: SvcCatalog.h:28
StatusCode JobOptionsSvc::setProperty ( const Property p)

IProperty implementation (needed for initialisation)

Definition at line 42 of file JobOptionsSvc.cpp.

43 {
44  return m_pmgr.setProperty( p );
45 }
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_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 78 of file JobOptionsSvc.h.


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