CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
PythonManager Class Reference

#include <PythonManager.h>

Static Public Member Functions

static PythonManagerHandle handle ()
 

Private Member Functions

void decrement ()
 
void increment ()
 
 PythonManager ()
 
 ~PythonManager ()
 

Private Attributes

std::string initCommand_
 
unsigned long refCount_
 

Friends

class PythonManagerHandle
 

Detailed Description

Definition at line 24 of file PythonManager.h.

Constructor & Destructor Documentation

PythonManager::PythonManager ( )
private

Definition at line 37 of file PythonManager.cc.

References edm::hlt::Exception, initCommand_, initlibFWCorePython(), and query::result.

37  :
38  refCount_(0),
40  "import sys\n"
41  "sys.path.append('./')\n"
42  "import ROOT\n"
43  "ROOT.gSystem.Load(\"libFWCoreFWLite\")\n"
44  "ROOT.AutoLibraryLoader.enable()\n"
45  "import libFWCorePython as edm\n")
46  {
47  Py_InitializeEx(0);
48  using namespace boost::python;
49 
50  if(PyImport_AppendInittab(const_cast<char *>("libFWCorePython"),initlibFWCorePython)==-1) {
51  throw cms::Exception("InitializationFailure" )
52  <<"failed to add libFWCorePython python module to python interpreter";
53  }
54  object main_module((
55  boost::python::handle<PyObject>(borrowed(PyImport_AddModule(const_cast<char *>("__main__"))))));
56  object main_namespace = main_module.attr("__dict__");
57  try {
58  object result((boost::python::handle<>(PyRun_String(initCommand_.c_str(),
59  Py_file_input,
60  main_namespace.ptr(),
61  main_namespace.ptr()))));
62 
63  } catch(... ) {
64  throw cms::Exception("Configuration") << "test";
65  }
66 
67  }
std::string initCommand_
Definition: PythonManager.h:35
tuple result
Definition: query.py:137
unsigned long refCount_
Definition: PythonManager.h:34
void initlibFWCorePython()
PythonManager::~PythonManager ( )
inlineprivate

Definition at line 31 of file PythonManager.h.

31 { Py_Finalize(); }

Member Function Documentation

void PythonManager::decrement ( )
inlineprivate

Definition at line 33 of file PythonManager.h.

References refCount_.

Referenced by PythonManagerHandle::~PythonManagerHandle().

33 { --refCount_; if(0==refCount_) delete this; }
unsigned long refCount_
Definition: PythonManager.h:34
PythonManagerHandle PythonManager::handle ( )
static

Definition at line 32 of file PythonManager.cc.

References PythonManagerHandle.

32  {
33  static PythonManager s_manager;
34  return PythonManagerHandle( s_manager);
35  }
friend class PythonManagerHandle
Definition: PythonManager.h:26
void PythonManager::increment ( )
inlineprivate

Definition at line 32 of file PythonManager.h.

References refCount_.

Referenced by PythonManagerHandle::PythonManagerHandle().

32 { ++refCount_; }
unsigned long refCount_
Definition: PythonManager.h:34

Friends And Related Function Documentation

friend class PythonManagerHandle
friend

Definition at line 26 of file PythonManager.h.

Referenced by handle().

Member Data Documentation

std::string PythonManager::initCommand_
private

Definition at line 35 of file PythonManager.h.

Referenced by PythonManager().

unsigned long PythonManager::refCount_
private

Definition at line 34 of file PythonManager.h.

Referenced by decrement(), and increment().