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
This commit is contained in:
celinemercier
2015-07-20 16:08:50 +02:00
parent 484fcca557
commit 5c674715ee
6 changed files with 66 additions and 55 deletions

View File

@ -7,7 +7,7 @@ cdef extern from "obidmscolumn.h" nogil:
ctypedef OBIDMS_column_t* OBIDMS_column_p 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: cdef class OBIDMS_column:

View File

@ -5,6 +5,9 @@ from .capidmscolumn cimport *
cdef class OBIDMS_column: 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.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)

View File

@ -530,7 +530,9 @@ size_t obi_get_platform_header_size()
OBIDMS_column_p obi_create_column(OBIDMS_p dms, OBIDMS_column_p obi_create_column(OBIDMS_p dms,
const char *column_name, const char *column_name,
OBIType_t type, 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_p new_column;
OBIDMS_column_directory_p column_directory; OBIDMS_column_directory_p column_directory;
@ -561,7 +563,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
// Calculate the size needed // Calculate the size needed
header_size = obi_get_platform_header_size(); 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; file_size = header_size + data_size;
// Get the latest version number // Get the latest version number
@ -618,7 +620,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
// Fill the column structure // Fill the column structure
new_column->dms = dms; new_column->dms = dms;
new_column->column_directory = column_directory; new_column->column_directory = column_directory;
new_column->header = mmap(NULL, new_column->header = mmap(NULL,
header_size, header_size,
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
@ -660,15 +662,20 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
new_column->writable = true; new_column->writable = true;
header = new_column->header; header = new_column->header;
header->little_endian = obi_is_little_endian(); header->little_endian = obi_is_little_endian();
header->header_size = header_size; header->header_size = header_size;
header->line_count = nb_elements; header->line_count = nb_elements;
header->lines_used = 0; header->lines_used = 0;
header->data_type = type; header->nb_elements_per_line = nb_elements_per_line;
header->creation_date = time(NULL); header->data_type = type;
header->version = version_number; header->creation_date = time(NULL);
header->comments[0] = 0x0; 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); strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
free(column_file_name); free(column_file_name);

View File

@ -33,23 +33,25 @@ typedef int32_t obiversion_t; /**< Used to store the column version number
*/ */
typedef struct OBIDMS_column_header { typedef struct OBIDMS_column_header {
bool little_endian; /**< endianness of the column: bool little_endian; /**< endianness of the column:
- `true` on little endian platforms * - `true` on little endian platforms
- `false` on big endian platforms * - `false` on big endian platforms
*
@see obi_is_little_end() * @see obi_is_little_endian()
*/ */
int header_size; /**< size of the header in bytes */ int header_size; /**< size of the header in bytes */
size_t line_count; /**< number of lines of data */ size_t line_count; /**< number of lines of data */
size_t lines_used; /**< number of lines of data used*/ size_t lines_used; /**< number of lines of data used */
OBIType_t data_type; /**< type of the data */ size_t nb_elements_per_line; /**< number of elements per line (default : 1) */
time_t creation_date; /**< date of creation of the file */ char* elements_names; /**< names of the line elements (default : "["column_name"]") */
obiversion_t version; /**< version of the OBIColumn */ 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 char name[OBIDMS_MAX_COLNAME+1]; /**< The column name as a NULL
* terminated string. * terminated string.
*/ */
char comments[1]; /**< comments stored as a classical 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 The size of the comment is only limited
by the header size by the header size
*/ */
@ -63,27 +65,24 @@ typedef struct OBIDMS_column_header {
* creating, opening or cloning an OBIDMS_column. * creating, opening or cloning an OBIDMS_column.
*/ */
typedef struct OBIDMS_column { typedef struct OBIDMS_column {
OBIDMS_p dms; /**< A pointer to a DMS instance 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_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
OBIDMS_column_header_p header; /**< A pointer to the header of the column * data.
*/ *
void* data; /**< A `void` pointer to the beginning of the * @warning never use this member directly
* data. * outside of the code of the
* * low level functions
* @warning never use this member directly * of the OBITools DMS
* outside of the code of the */
* low level functions bool writable; /**< Indicates if the column is writable or not.
* of the OBITools DMS * - `true` the column is writable
*/ * - `false` the column is read-only
bool writable; /**< Indicates if the column is writable or not. *
* - `true` the column is writable * A column is writable only by its creator
* - `false` the column is read-only * until it closes it.
* */
* A column is writable only by its creator
* until it closes it.
*/
} OBIDMS_column_t, *OBIDMS_column_p; } 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, OBIDMS_column_p obi_create_column(OBIDMS_p dms,
const char* column_name, const char* column_name,
OBIType_t type, OBIType_t type,
size_t nb_elements); size_t nb_elements,
size_t nb_elements_per_line,
const char* elements_names);
/** /**

View File

@ -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 size;
size_t rsize; size_t rsize;
size_t psize; size_t psize;
size = obi_sizeof(type) * nbelements; size = obi_sizeof(type) * nb_elements * nb_elements_per_line;
psize = getpagesize(); psize = getpagesize();
rsize = size % psize; rsize = size % psize;

View File

@ -73,6 +73,6 @@ size_t obi_sizeof(OBIType_t type);
* @since May 2015 * @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org) * @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_ */ #endif /* OBITYPES_H_ */