Commit 4818b1d1 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Logger: Remove version string, remove message/error function, map index files

parent 80791350
......@@ -43,7 +43,6 @@ void header_print(const struct header *h) {
#ifdef SWIFT_DEBUG_CHECKS
message("Debug checks enabled");
#endif
message("Version: %s", h->version);
message("First Offset: %lu", h->offset_first_record);
message("Offset direction: %s", logger_offset_name[h->offset_direction]);
message("Number masks: %lu", h->number_mask);
......@@ -113,7 +112,7 @@ void header_read(struct header *h, struct logger_logfile *log) {
char file_format[STRING_SIZE];
offset = io_read_data(map, LOGGER_VERSION_SIZE, &file_format, offset);
if (strcmp(file_format, "SWIFT_LOGGER"))
error("Wrong file format");
error("Wrong file format (%s)", file_format);
/* Read major version number */
offset = io_read_data(map, sizeof(int), &h->major_version, offset);
......
......@@ -57,13 +57,10 @@ struct logger_logfile;
* The only function that modify the file is #header_change_offset_direction.
*/
struct header {
/* Logger version. */
char version[STRING_SIZE];
/* Dump major version */
/* Dump's major version */
int major_version;
/* Dump minor version */
/* Dump's minor version */
int minor_version;
/* Offset of the first record. */
......
......@@ -26,6 +26,7 @@
/* This object's header. */
#include "logger_index.h"
#include "logger_io.h"
#include "logger_tools.h"
/**
......@@ -39,17 +40,18 @@ void logger_index_init(struct logger_index *index, struct logger_reader *reader,
char *filename) {
/* Open file. */
FILE *f = NULL;
f = fopen(filename, "rb");
index->data = io_mmap_file(filename, &index->file_size);
/* Read the double time. */
fread(&index->time, sizeof(double), 1, f);
size_t offset = 0;
offset = io_read_data(index->data, sizeof(double), &index->time, offset);
/* Read the integer time. */
fread(&index->int_time, sizeof(integertime_t), 1, f);
offset = io_read_data(index->data, sizeof(integertime_t), &index->int_time, offset);
/* Read the number of particles. */
fread(index->number_particles, sizeof(long long), swift_type_count, f);
offset = io_read_data(index->data, swift_type_count * sizeof(long long),
&index->number_particles, offset);
/* Count total number of particles. */
long long N = 0;
......@@ -58,29 +60,17 @@ void logger_index_init(struct logger_index *index, struct logger_reader *reader,
}
index->total_number_particles = N;
/* Read the particles ids. */
if (posix_memalign((void**)&index->data, IO_BUFFER_ALIGNMENT,
N * sizeof(struct logger_index_data)) != 0)
error("Unable to allocate index data buffer");
fread(index->data, sizeof(struct logger_index_data), N, f);
/* Close the file. */
fclose(f);
}
/**
* @brief Free the memory allocated for current file.
* @brief Free the memory.
*
* @param index The #logger_index.
*/
void logger_index_free_current_file(struct logger_index *index) {
/* Free the index data */
if (index->data)
free(index->data);
index->data = NULL;
void logger_index_free(struct logger_index *index) {
/* unmap file */
io_munmap_file(index->data, index->file_size);
/* Set variables to default value. */
index->total_number_particles = 0;
......@@ -88,15 +78,5 @@ void logger_index_free_current_file(struct logger_index *index) {
for(int i = 0; i < swift_type_count; i++) {
index->number_particles[i] = 0;
}
}
/**
* @brief Free the memory.
*
* @param index The #logger_index.
*/
void logger_index_free(struct logger_index *index) {
/* Free the memory allocated for current file. */
logger_index_free_current_file(index);
}
......@@ -48,8 +48,11 @@ struct logger_index {
/* The reader */
struct logger_reader *reader;
/* Particles' ids and offsets */
struct logger_index_data *data;
/* memory map of the index file */
void *data;
/* Index file size */
size_t file_size;
/* Number of particles */
size_t total_number_particles;
......
......@@ -27,10 +27,11 @@
* @param log The #logger_logfile.
* @param filename the log's filename.
* @param reader The #logger_reader.
* @param only_header Read only the header.
*/
void logger_logfile_init(
struct logger_logfile *log, char *filename,
struct logger_reader *reader) {
struct logger_reader *reader, int only_header) {
/* Set the pointer to the reader. */
log->reader = reader;
......@@ -53,6 +54,11 @@ void logger_logfile_init(
header_print(&log->header);
}
/* No need to continue if only the
header is required */
if (only_header)
return;
/* Check if the offset are corrupted */
if (header_is_corrupted(&log->header)) {
error("The offsets have been corrupted");
......
......@@ -62,7 +62,8 @@ struct logger_logfile {
};
void logger_logfile_init(struct logger_logfile *log, char *filename, struct logger_reader *reader);
void logger_logfile_init(struct logger_logfile *log, char *filename, struct logger_reader *reader,
int only_header);
void logger_logfile_reverse_offset(struct logger_logfile *log);
void logger_logfile_free(struct logger_logfile *log);
......
......@@ -34,7 +34,8 @@ void logger_reader_init(struct logger_reader *reader, char *filename, int verbos
reader->verbose = verbose;
/* Initialize the log file */
logger_logfile_init(&reader->log, filename, reader);
logger_logfile_init(&reader->log, filename, reader,
/* only_header */ 0);
if (verbose > 1)
message("Initialization done.");
......
......@@ -29,6 +29,7 @@
#include "../src/inline.h"
#include "../src/logger.h"
#include "../src/part_type.h"
#include "../src/error.h"
#ifdef HAVE_PYTHON
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
......@@ -45,27 +46,6 @@
struct header;
struct logger_reader;
#define error(s, ...) \
({ \
fflush(stdout); \
fprintf(stderr, "%s:%s():%i: " s "\n", __FILE__, __FUNCTION__, __LINE__, \
##__VA_ARGS__); \
abort(); \
})
#ifdef SWIFT_DEBUG_CHECKS
#define message(s, ...) \
({ \
printf("%s:%s():%i: " s "\n", __FILE__, __FUNCTION__, __LINE__, \
##__VA_ARGS__); \
})
#else
({ \
printf("%s(): " s "\n", __FUNCTION__, \
##__VA_ARGS__); \
})
#endif
int tools_get_next_record(const struct header *h, void *map, size_t *offset,
size_t file_size);
int _tools_get_next_record_backward(const struct header *h, void *map,
......
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