Commit 5c674715 by celinemercier

added the idea of each line of a column corresponding to a vector, with

the added informations of the number of elements per line and the
elements' names in the column's header structure
parent 484fcca5
......@@ -7,7 +7,7 @@ cdef extern from "obidmscolumn.h" nogil:
ctypedef OBIDMS_column_t* OBIDMS_column_p
OBIDMS_column_p obi_create_column(OBIDMS_p dms, char* column_name, OBIType_t type, size_t nb_elements)
OBIDMS_column_p obi_create_column(OBIDMS_p dms, const char* column_name, OBIType_t type, size_t nb_elements, size_t nb_elements_per_line, const char* elements_names)
cdef class OBIDMS_column:
......
......@@ -5,6 +5,9 @@ from .capidmscolumn cimport *
cdef class OBIDMS_column:
def __init__(self, dms_name, column_name, type, nb_elements):
def __init__(self, dms_name, column_name, type, nb_elements, nb_elements_per_line=1, elements_names=None):
if elements_names == None :
elements_names = "[\""+column_name.decode('utf-8')+"\"]"
elements_names = bytes(elements_names, 'utf-8')
self.dms = obi_dms(dms_name)
self.pointer = obi_create_column(self.dms, column_name, type, nb_elements)
self.pointer = obi_create_column(self.dms, column_name, type, nb_elements, nb_elements_per_line, elements_names)
......@@ -530,7 +530,9 @@ size_t obi_get_platform_header_size()
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
const char *column_name,
OBIType_t type,
size_t nb_elements)
size_t nb_elements,
size_t nb_elements_per_line,
const char* elements_names)
{
OBIDMS_column_p new_column;
OBIDMS_column_directory_p column_directory;
......@@ -561,7 +563,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
// Calculate the size needed
header_size = obi_get_platform_header_size();
data_size = obi_array_sizeof(type, nb_elements);
data_size = obi_array_sizeof(type, nb_elements, nb_elements_per_line);
file_size = header_size + data_size;
// Get the latest version number
......@@ -618,7 +620,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
// Fill the column structure
new_column->dms = dms;
new_column->column_directory = column_directory;
new_column->column_directory = column_directory;
new_column->header = mmap(NULL,
header_size,
PROT_READ | PROT_WRITE,
......@@ -660,15 +662,20 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
new_column->writable = true;
header = new_column->header;
header->little_endian = obi_is_little_endian();
header->header_size = header_size;
header->line_count = nb_elements;
header->lines_used = 0;
header->data_type = type;
header->creation_date = time(NULL);
header->version = version_number;
header->comments[0] = 0x0;
header = new_column->header;
header->little_endian = obi_is_little_endian();
header->header_size = header_size;
header->line_count = nb_elements;
header->lines_used = 0;
header->nb_elements_per_line = nb_elements_per_line;
header->data_type = type;
header->creation_date = time(NULL);
header->version = version_number;
header->comments[0] = 0x0;
header->elements_names = malloc(strlen(elements_names)*sizeof(char) + 1);
strcpy(header->elements_names, elements_names);
strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
free(column_file_name);
......
......@@ -33,23 +33,25 @@ typedef int32_t obiversion_t; /**< Used to store the column version number
*/
typedef struct OBIDMS_column_header {
bool little_endian; /**< endianness of the column:
- `true` on little endian platforms
- `false` on big endian platforms
@see obi_is_little_end()
*/
int header_size; /**< size of the header in bytes */
size_t line_count; /**< number of lines of data */
size_t lines_used; /**< number of lines of data used*/
OBIType_t data_type; /**< type of the data */
time_t creation_date; /**< date of creation of the file */
obiversion_t version; /**< version of the OBIColumn */
bool little_endian; /**< endianness of the column:
* - `true` on little endian platforms
* - `false` on big endian platforms
*
* @see obi_is_little_endian()
*/
int header_size; /**< size of the header in bytes */
size_t line_count; /**< number of lines of data */
size_t lines_used; /**< number of lines of data used */
size_t nb_elements_per_line; /**< number of elements per line (default : 1) */
char* elements_names; /**< names of the line elements (default : "["column_name"]") */
OBIType_t data_type; /**< type of the data */
time_t creation_date; /**< date of creation of the file */
obiversion_t version; /**< version of the OBIColumn */
char name[OBIDMS_MAX_COLNAME+1]; /**< The column name as a NULL
* terminated string.
*/
* terminated string.
*/
char comments[1]; /**< comments stored as a classical
zero end C string. T
zero end C string.
The size of the comment is only limited
by the header size
*/
......@@ -63,27 +65,24 @@ typedef struct OBIDMS_column_header {
* creating, opening or cloning an OBIDMS_column.
*/
typedef struct OBIDMS_column {
OBIDMS_p dms; /**< A pointer to a DMS instance
*/
OBIDMS_column_directory_p column_directory; /**< A pointer to an OBIDMS column directory instance
*/
OBIDMS_column_header_p header; /**< A pointer to the header of the column
*/
void* data; /**< A `void` pointer to the beginning of the
* data.
*
* @warning never use this member directly
* outside of the code of the
* low level functions
* of the OBITools DMS
*/
bool writable; /**< Indicates if the column is writable or not.
* - `true` the column is writable
* - `false` the column is read-only
*
* A column is writable only by its creator
* until it closes it.
*/
OBIDMS_p dms; /**< A pointer to a DMS instance */
OBIDMS_column_directory_p column_directory; /**< A pointer to an OBIDMS column directory instance */
OBIDMS_column_header_p header; /**< A pointer to the header of the column */
void* data; /**< A `void` pointer to the beginning of the
* data.
*
* @warning never use this member directly
* outside of the code of the
* low level functions
* of the OBITools DMS
*/
bool writable; /**< Indicates if the column is writable or not.
* - `true` the column is writable
* - `false` the column is read-only
*
* A column is writable only by its creator
* until it closes it.
*/
} OBIDMS_column_t, *OBIDMS_column_p;
......@@ -115,7 +114,9 @@ size_t obi_get_platform_header_size();
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
const char* column_name,
OBIType_t type,
size_t nb_elements);
size_t nb_elements,
size_t nb_elements_per_line,
const char* elements_names);
/**
......
......@@ -35,13 +35,13 @@ size_t obi_sizeof(OBIType_t type)
}
size_t obi_array_sizeof(OBIType_t type, size_t nbelements)
size_t obi_array_sizeof(OBIType_t type, size_t nb_elements, size_t nb_elements_per_line)
{
size_t size;
size_t rsize;
size_t psize;
size = obi_sizeof(type) * nbelements;
size = obi_sizeof(type) * nb_elements * nb_elements_per_line;
psize = getpagesize();
rsize = size % psize;
......
......@@ -73,6 +73,6 @@ size_t obi_sizeof(OBIType_t type);
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
size_t obi_array_sizeof(OBIType_t type, size_t nbelements);
size_t obi_array_sizeof(OBIType_t type, size_t nbelements, size_t nb_elements_per_line);
#endif /* OBITYPES_H_ */
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