Commit 34a3717f authored by Celine Mercier's avatar Celine Mercier

The cython function to open a column is now a method of the OBIDMS class

parent 2698022a
......@@ -4,6 +4,12 @@ from pathlib import Path
from .capidms cimport *
from obitools3.obidms.obidmscolumn.obidmscolumn_int.capidmscolumn_int import *
from obitools3.obidms.obidmscolumn.obidmscolumn_float.capidmscolumn_float import *
from obitools3.obidms.obidmscolumn.obidmscolumn_bool.capidmscolumn_bool import *
from obitools3.obidms.obidmscolumn.obidmscolumn_char.capidmscolumn_char import *
from obitools3.obidms.obidmscolumn.obidmscolumn_idx.capidmscolumn_idx import *
cdef class OBIDMS :
......@@ -31,4 +37,83 @@ cdef class OBIDMS :
#dms[column_name]['latest_version'] = latest_version
#dms[column_name]['line_count'] = line_count
print("{:<25} {:<25} {:<25} {:<25}".format(column_name, data_type, latest_version, line_count))
\ No newline at end of file
def open_column(self,
column_name,
bint create=False,
bint clone=False, bint clone_data=True,
obiversion_t version_number=-1,
type=0,
size_t nb_lines=0,
size_t nb_elements_per_line=1,
str elements_names=None):
column_name_b = column_name.encode(encoding='UTF-8')
if not type :
if create :
print("A data type must be specified")
else :
type = obi_column_get_data_type_from_name(self.pointer, column_name_b)
if type == 1 :
if (create or clone) :
column = OBIDMS_column_int_writable(self, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_int_read(self, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
elif type == 2 :
if (create or clone) :
column = OBIDMS_column_float_writable(self, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_float_read(self, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
elif type == 3 :
if (create or clone) :
column = OBIDMS_column_bool_writable(self, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_bool_read(self, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
elif type == 4 :
if (create or clone) :
column = OBIDMS_column_char_writable(self, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_char_read(self, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
raise Exception("Problem with the data type")
return column
......@@ -12,7 +12,7 @@ cdef extern from "obitypes.h" nogil:
ctypedef OBIBool obibool_t
ctypedef int32_t obiint_t
ctypedef double obifloat_t
ctypedef char obichar_t
ctypedef bytes obichar_t
ctypedef size_t obiidx_t
char* name_data_type(int data_type)
......@@ -42,7 +42,7 @@ cdef extern from "obidmscolumn.h" nogil:
cdef class OBIDMS_column:
cdef OBIDMS_column_p pointer
cdef OBIDMS_p dms
cdef OBIDMS dms
cdef str data_type # keep as OBIType_t? both?
cdef str dms_name
cdef str column_name
#cython: language_level=3
from .capidmscolumn cimport *
from obitools3.obidms.obidmscolumn.obidmscolumn_int.capidmscolumn_int import *
from obitools3.obidms.obidmscolumn.obidmscolumn_float.capidmscolumn_float import *
from obitools3.obidms.obidmscolumn.obidmscolumn_bool.capidmscolumn_bool import *
from obitools3.obidms.obidmscolumn.obidmscolumn_char.capidmscolumn_char import *
from obitools3.obidms.obidmscolumn.obidmscolumn_idx.capidmscolumn_idx import *
cdef class OBIDMS_column:
#Should only be initialized through a subclass (or open())
def __init__(self, dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names):
column_name_b = column_name.encode(encoding='UTF-8')
dms_name_b = dms_name.encode(encoding='UTF-8')
self.dms_name = dms_name
self.column_name = column_name
#Should only be initialized through a subclass
def __init__(self,
OBIDMS dms,
column_name,
bint create,
bint clone, bint clone_data,
obiversion_t version_number,
OBIType_t type,
size_t nb_lines,
size_t nb_elements_per_line,
str elements_names):
self.dms = dms
self.data_type = (name_data_type(type)).decode('UTF-8')
self.column_name = column_name
column_name_b = column_name.encode(encoding='UTF-8')
dms_name_b = self.dms.dms_name.encode(encoding='UTF-8')
if create :
dms = obi_dms(dms_name_b)
self.dms = dms
if elements_names == None :
elements_names_b = column_name_b
else :
elements_names_b = elements_names.encode(encoding='UTF-8')
self.pointer = obi_create_column(self.dms, column_name_b, type, nb_lines, nb_elements_per_line, elements_names_b)
self.pointer = obi_create_column(self.dms.pointer, column_name_b, type, nb_lines, nb_elements_per_line, elements_names_b)
else :
dms = obi_open_dms(dms_name_b)
self.dms = dms
if clone :
self.pointer = obi_clone_column(self.dms, column_name_b, version_number, clone_data)
self.pointer = obi_clone_column(self.dms.pointer, column_name_b, version_number, clone_data)
else :
self.pointer = obi_open_column(self.dms, column_name_b, version_number)
self.pointer = obi_open_column(self.dms.pointer, column_name_b, version_number)
def __iter__(self):
elements_names = self.get_elements_names()
......@@ -53,10 +50,10 @@ cdef class OBIDMS_column:
line = self.get_item(line_nb, element_name)
yield line
def __setitem__(self, line_nb, value):
def __setitem__(self, int line_nb, value):
self.set_item(line_nb, "", value)
def __getitem__(self, line_nb):
def __getitem__(self, int line_nb):
return self.get_item(line_nb, "")
def get_elements_names(self):
......@@ -69,84 +66,6 @@ cdef class OBIDMS_column:
def get_nb_lines_used(self):
return obi_column_get_nb_lines_used(self.pointer)
@staticmethod
def open(dms_name, column_name,
create=False, clone=False, clone_data=True,
version_number=-1, type=None,
nb_lines=None, nb_elements_per_line=1,
elements_names=None):
column_name_b = column_name.encode(encoding='UTF-8')
dms_name_b = dms_name.encode(encoding='UTF-8')
dms = obi_dms(dms_name_b)
if type is None :
if create :
print("A data type must be specified")
else :
type = obi_column_get_data_type_from_name(dms, column_name_b)
if type == 1 :
if (create or clone) :
column = OBIDMS_column_int_writable(dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_int_read(dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
elif type == 2 :
if (create or clone) :
column = OBIDMS_column_float_writable(dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_float_read(dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
elif type == 3 :
if (create or clone) :
column = OBIDMS_column_bool_writable(dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_bool_read(dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
elif type == 4 :
if (create or clone) :
column = OBIDMS_column_char_writable(dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
column = OBIDMS_column_char_read(dms_name, column_name,
create, clone, clone_data,
version_number, type,
nb_lines, nb_elements_per_line,
elements_names)
else :
"Problem with the data type"
return column
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment