Commits

bi...@4525493e-7705-40b1-a816-d608a930855b  committed 47a8273

addressing the CLID/typename/typedef problem

  • Participants
  • Parent commits bb71322

Comments (0)

Files changed (2)

+2008-04-03  Sebastien Binet  <binet@lblbox>
+
+	* tagging StoreGateBindings-00-01-02
+	* addressing the CLID/typename/typedef problem: when the CLID of a type
+	  is looked for by the SG::PyProxyDict class, an additional look-up
+	  into a dictionary of "typedef'ed type"->"typename" is performed to
+	  handle cases such as the INavigable4MomentumCollection which has
+	  been registered with the CLIDSvc with this typedef string rather than
+	  the real C++ name. This confuses the (Py)CLIDSvc...
+	  This dictionary of aliases is installed on the python side, in the 
+	  AthenaPython.Bindings module, '_clid_typename_aliases'.
+	* M src/StoreGatePyExt.cxx
+
 2008-03-21  Sebastien Binet  <binet@lblbox>
 
 	* tagging StoreGateBindings-00-01-01

File src/StoreGatePyExt.cxx

   struct PyProxyMgr
   {
     IClassIDSvc* m_clidSvc;
+    /// a dictionary of "typedef'ed typename" -> "typename"
+    PyObject* m_aliases;
+
     /// a dictionary of 'typename' -> CLID
     PyObject* m_clids;
 
 
     PyProxyMgr()
     {
+      m_aliases = importDictAliases();
       m_clids   = PyDict_New();
       m_clidSvc = 0;
       if ( !Gaudi::svcLocator()->getService("ClassIDSvc", 
 
     ~PyProxyMgr() 
     {
+      Py_DECREF(m_aliases);
       Py_DECREF(m_clids);
       // delete the proxy dicts...
       for ( PyProxyMap_t::iterator 
     {
       CLID id = CLID_NULL;
       m_clidSvc->getIDOfTypeName(PyString_AS_STRING(tp), id).ignore();
+      if ( id == CLID_NULL ) {
+	// try an alias...
+	PyObject* alias = PyDict_GetItem(m_aliases, tp);
+	if ( alias ){
+	  m_clidSvc->getIDOfTypeName(PyString_AS_STRING(alias), id).ignore();
+	}
+      }
       return id;
     }
 
-  };
+   private:
+    /// import the dictionary of aliases from a well known location
+    PyObject* importDictAliases()
+    {
+      const std::string moduleName = "AthenaPython.Bindings";
+      PyObject* module = PyImport_ImportModule
+	( const_cast<char*>(moduleName.c_str()) );
+      if ( !module || !PyModule_Check(module) ) {
+	std::cerr << "SG::PyProxyDict WARNING: could not import module '"
+		  << moduleName << "' !\n";
+	Py_XDECREF(module);
+	return PyDict_New();
+      }
+
+      m_aliases = PyDict_GetItemString(PyModule_GetDict(module),
+				       (char*)"_clid_typename_aliases");
+      // borrowed ref. so we increment it
+      Py_XINCREF(m_aliases);
+      // don't need this one anymore
+      Py_DECREF(module);
+
+      if ( !m_aliases ) {
+	std::cerr << "SG::PyProxyDict WARNING: could not retrieve the "
+		  << "dictionary of aliases from '"
+		  << moduleName << "' !\n";
+	Py_XDECREF(m_aliases);
+	m_aliases = PyDict_New();
+      }
+
+      return m_aliases;
+    }
+    
+  }; //> class PyProxyDict
 
 } //> end namespace SG