Salut Rémi,

El dl 23 de 01 del 2006 a les 17:28 +0100, en/na [EMAIL PROTECTED]
va escriure:

> I've started modifying my work to allow PyTables objects to be created
> from references.
> But now I'm stuck, because of the attributes.
> The problem is that an instance of AttributeSet needs to know the path
> of the Node it is attached to (so that it can be retrieved if needed).
> This need is met by the property '_v_node'.

Well, you can forge one ;-) I've been looking at the AttributeSet code,
and I think you just need to assign a few attributes to "simulate" that
the node passed to AttributeSet is like a regular Node in the object
tree. My guess if that providing a node with the next attributes would
be enough:

- _v_objectID --> The dataset ID of the owner node (you already know it)
- _v_file     --> A pointer with the file (that's easy to get)
- _v_hdf5name --> The 'forged' name of the reference node
- _v_pathname --> The complete pathname of the reference container + the
'forged' name.

For example, if, say, /table has a list of references called
DIMENSION_LIST, you can forge the name and pathname for the first
reference by following the next algorithm:

1.- Try to see if the referenced object has a 'NAME' HDF5 attribute (you
can do this in the same way as reading the 'CLASS' attribute). If so,
this will become the 'forged' name.

2.- If the referenced node doesn't have a 'NAME' attribute, then forge
one, like, for example: 'REF_0', 'REF_1' and so on for each reference of
the list (we should think about other schemas for references that are
not on lists, but this is not our business right now).

3.- The _v_pathname can be assigned to
'/table'+'/ATTRS'+'/DIMENSION_LIST/'+forged_name

Assigning these four attributes to your node, and applying the attached
patch (it gets rid of _v_parentID that was not useful at all), you can
succeed making AttributeSet to think that it belongs to a Node in the
object tree.

Good luck!

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"

Index: src/hdf5Extension.pyx
===================================================================
--- src/hdf5Extension.pyx	(revision 1405)
+++ src/hdf5Extension.pyx	(working copy)
@@ -637,14 +637,13 @@
 
 
 cdef class AttributeSet:
-  cdef hid_t   parent_id, dataset_id
+  cdef hid_t   dataset_id
   cdef char    *name
 
   def _g_new(self, node):
     # Initialize the C attributes of Node object
     self.name =  PyString_AsString(node._v_hdf5name)
-    # The parent group id of the node
-    self.parent_id = node._v_parent._v_objectID
+    # The dataset id of the node
     self.dataset_id = node._v_objectID
 
   def __g_listAttr(self):
@@ -706,9 +705,7 @@
     cdef hid_t type_id
     cdef H5T_sign_t sign #H5T_SGN_ERROR (-1), H5T_SGN_NONE (0), H5T_SGN_2 (1)
     cdef char *dsetname
-    cdef hid_t parent_id
 
-    parent_id = self.parent_id
     dsetname = self.name
 
     # Check if attribute exists
@@ -936,8 +933,6 @@
                          % (attrname, self.name))
 
   def __dealloc__(self):
-    #print "Destroying object AttributeSet in Extension"
-    self.parent_id = 0
     self.dataset_id = 0
 
 

Reply via email to