Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (01b473db)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PythonConfig Class Reference

#include </builds/gaudi/Gaudi/GaudiCoreSvc/src/JobOptionsSvc/PythonConfig.h>

Collaboration diagram for PythonConfig:

Public Member Functions

 PythonConfig (Gaudi::Interfaces::IOptionsSvc *optsSvc)
 
StatusCode evaluateConfig (const std::string &filename, const std::string &preAction, const std::string &postAction)
 

Private Attributes

Gaudi::Interfaces::IOptionsSvcm_optsSvc
 

Detailed Description

Definition at line 30 of file PythonConfig.h.

Constructor & Destructor Documentation

◆ PythonConfig()

PythonConfig::PythonConfig ( Gaudi::Interfaces::IOptionsSvc optsSvc)
inline

Definition at line 32 of file PythonConfig.h.

32 : m_optsSvc( optsSvc ) {}

Member Function Documentation

◆ evaluateConfig()

StatusCode PythonConfig::evaluateConfig ( const std::string &  filename,
const std::string &  preAction,
const std::string &  postAction 
)

Definition at line 17 of file PythonConfig.cpp.

18  {
19  try {
20  // Prepare a Python environment
21  Py_Initialize();
22  object main_module( ( handle<>( borrowed( PyImport_AddModule( "__main__" ) ) ) ) );
23  object main_namespace = main_module.attr( "__dict__" );
24 
25  // make the translator class known to Python
26  main_namespace["PythonAdaptor"] =
27  class_<PythonAdaptor>( "PythonAdaptor", boost::python::init<Gaudi::Interfaces::IOptionsSvc*>() )
28  .def( "addPropertyToJobOptions", &PythonAdaptor::addPropertyToJobOptions );
29 
30  // create an instance of it and pass it to Python
31  PythonAdaptor adaptor( m_optsSvc );
32  main_namespace["adaptor"] = ptr( &adaptor );
33 
34  // some python helper
35  std::string command( preAction );
36  command += "\nfor name in '";
37  command += filename + "'.split(','):\n";
38  command += " with open(name) as f:\n";
39  command += " code = compile(f.read(), name, 'exec')\n";
40  command += " exec(code)\n";
41  command += "from GaudiKernel.Configurable import expandvars\nfrom GaudiKernel.Proxy.Configurable import "
42  "applyConfigurableUsers\napplyConfigurableUsers()\n";
43  command += postAction;
44  command += "\nfor n, c in Configurable.allConfigurables.items():\n for p, v in c.getValuedProperties().items() "
45  ":\n v = expandvars(v)\n if type(v) == str : v = repr(v) # need double quotes\n elif "
46  "type(v) == long: v = '%d' % v # prevent pending 'L'\n adaptor.addPropertyToJobOptions(n,p,str(v))";
47 
48  // Now fire off the translation
49  handle<> ignored( ( PyRun_String( command.c_str(), Py_file_input, main_namespace.ptr(), main_namespace.ptr() ) ) );
50  } catch ( const error_already_set& ) {
51  std::cout << "Error in python script:" << std::endl;
52  PyErr_Print();
53  return StatusCode::FAILURE;
54  }
55 
56  return StatusCode::SUCCESS;
57 }

Member Data Documentation

◆ m_optsSvc

Gaudi::Interfaces::IOptionsSvc* PythonConfig::m_optsSvc
private

Definition at line 36 of file PythonConfig.h.


The documentation for this class was generated from the following files:
PythonAdaptor::addPropertyToJobOptions
void addPropertyToJobOptions(const std::string &client, const std::string &name, const std::string &value)
Definition: PythonConfig.h:21
brunelWrapper.command
command
Definition: brunelWrapper.py:135
PythonConfig::m_optsSvc
Gaudi::Interfaces::IOptionsSvc * m_optsSvc
Definition: PythonConfig.h:36
PythonAdaptor
Definition: PythonConfig.h:18
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:100
graphanalysis.filename
filename
Definition: graphanalysis.py:130