Hello Pytablers,

In our readout software for a PET scanner, I write the data to an HDF5
array of compound datatypes (in C++).
When I want to read this table in ipython with pytables, I get the message:


In [11]:  import tables

In [11]: f=tables.openFile("Events_0012.h5")

In [12]: f.root.dset
/usr/local/lib/python2.6/dist-packages/tables/path.py:102:
NaturalNameWarning: object name is not a valid Python identifier: 'ToT
    '; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you
will not be able to use natural naming to access this object; using
``getattr()`` will still work, though
  NaturalNameWarning )
/usr/local/lib/python2.6/dist-packages/tables/group.py:1215:
UserWarning: problems loading leaf ``/dset``::

  table ``/dset``, column ``hits``: data type not understood

The leaf will become an ``UnImplemented`` node.
  % (self._g_join(childName), exc))
Out[12]:
/dset (UnImplemented(16384,)) ''
  NOTE: <The UnImplemented object represents a PyTables unimplemented
         dataset present in the 'Events_0012.h5' HDF5 file.  If you
want to see this
         kind of HDF5 dataset implemented in PyTables, please contact the
         developers.>


I also attached the C++ code which writes the table.
Should I write the HDF5 file in a different way in order to read the
data with pytables?

Thanks a lot for your help!



Best regards,
Michael Rissi





-- 

Dr. Michael Rissi
room ø385A
Sem Sælandsvei 24
N-0316 Oslo

Universitetet i Oslo
NORWAY
#include <iostream>
#include <sys/prctl.h>
#include <unistd.h>
#include "hdf5.h"
#include "CWriteHDF5.h"


 
  
void CWriteHDF5::start()
{
  m_Thread = boost::thread(&CWriteHDF5::WriteHDF5, this);
  
}
void  CWriteHDF5::join()
{
  m_Thread.join();
  
}
void CWriteHDF5::WriteHDF5()
{
  //thread name:
  char thr_name[] = "CREADOUT_WriteHDF5\0";
  prctl(PR_SET_NAME, thr_name);
  

  //set up the HDF5 stuff:
  
  hid_t       file_id, dataset_id,dataspace_id;  /* identifiers */
  herr_t      status;
  
  hsize_t     dims[] = {NUMBEROFEVENTSPERFILE};
   

  C5Event *c5event = new C5Event[NUMBEROFEVENTSPERFILE];

  hsize_t dim[] = {MAXNUMHITSINSLOT};
 hid_t hits_datatype = H5Tcreate (H5T_COMPOUND, sizeof (CHit));
 H5Tinsert(hits_datatype, "ev_nr"   , HOFFSET(C5Hit, ev_nr)   , H5T_NATIVE_USHORT);
 H5Tinsert(hits_datatype, "ch_nr"   , HOFFSET(C5Hit, ch_nr)   , H5T_NATIVE_USHORT);
 H5Tinsert(hits_datatype, "rel_time", HOFFSET(C5Hit, rel_time), H5T_NATIVE_USHORT);
 H5Tinsert(hits_datatype, "ToT     ", HOFFSET(C5Hit, ToT)     , H5T_NATIVE_USHORT);

 hid_t array_tid = H5Tarray_create(hits_datatype, 1, dim, NULL);

 //create the compound data type:
 hid_t events_datatype = H5Tcreate (H5T_COMPOUND, sizeof(C5Event));
 H5Tinsert(events_datatype, "numhits", HOFFSET(C5Event, numhits), H5T_NATIVE_INT);


  H5Tinsert(events_datatype, "hits", HOFFSET(C5Event, hits), array_tid);
  dataspace_id = H5Screate_simple(1, dims, NULL);

  
  int evt = 0;
  int filenumber = 0;
  while(!m_exitflag)
    {
      CEvent event_tmp;
      m_events->pop_back(&event_tmp);
      usleep(100);
      c5event[evt] = event_tmp.copy();
      evt++;
      if(evt == NUMBEROFEVENTSPERFILE)
	{
	  evt = 0;
	  filenumber++;
	  char filename[128];
	  sprintf(filename, "Events_%04u.h5",filenumber);
	   file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
	     
	      dataset_id = H5Dcreate(file_id, "/dset", events_datatype, dataspace_id, H5P_DEFAULT);
	      std::cout<<"writing file "<<filename<<std::endl;
	      status = H5Dwrite(dataset_id, events_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, 
				c5event);
		  
	      status = H5Dclose(dataset_id);

	     
	      status = H5Fclose(file_id);

	}

    

    }





}
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to