CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/FWCore/Python/src/PythonManager.h

Go to the documentation of this file.
00001 //
00002 // Smart reference + singleton to handle Python interpreter
00003 //
00004 //
00005 // Original Author:  Chris D Jones & Benedikt Hegner
00006 //         Created:  Sun Jul 22 11:03:53 CEST 2006
00007 //
00008 
00009 #ifndef FWCore_Python_PythonManager_h
00010 #define FWCore_Python_PythonManager_h
00011 
00012 #include "FWCore/PythonParameterSet/interface/BoostPython.h"
00013 
00014 extern "C" {
00015    //this is the entry point into the libFWCorePython python module
00016    void initlibFWCorePython();
00017    //void initROOT();
00018 }
00019 
00020 void pythonToCppException(const std::string& iType);
00021 
00022     class PythonManagerHandle;
00023         
00024     class PythonManager {
00025       public:
00026             friend class PythonManagerHandle;
00027             static PythonManagerHandle handle();
00028 
00029       private:
00030              PythonManager();
00031              ~PythonManager() { Py_Finalize(); }
00032              void increment() { ++refCount_; }
00033          void decrement() { --refCount_; if(0==refCount_) delete this; }
00034              unsigned long refCount_;
00035              std::string initCommand_;
00036     };
00037 
00038     class PythonManagerHandle {
00039       public:
00040             ~PythonManagerHandle() { manager_.decrement(); }
00041 
00042             PythonManagerHandle(PythonManager& iM):
00043               manager_(iM) {
00044               manager_.increment();
00045             }
00046 
00047             PythonManagerHandle(const PythonManagerHandle& iRHS) :
00048               manager_(iRHS.manager_) {
00049               manager_.increment();
00050             }
00051                 
00052       private:
00053             const PythonManagerHandle& operator=(const PythonManagerHandle&);
00054             PythonManager& manager_;
00055     };
00056 #endif // FWCore_Python_PythonManager_h