Commit 28cec243 authored by Matthieu Schaller's avatar Matthieu Schaller

Merge branch 'logger_remove_string' into 'master'

Remove string argument in some logger function

See merge request !1125
parents d00218b6 7b19ce53
...@@ -44,8 +44,7 @@ static const char *gravity_logger_field_names[gravity_logger_field_count] = { ...@@ -44,8 +44,7 @@ static const char *gravity_logger_field_names[gravity_logger_field_count] = {
/** /**
* @brief Initialize the logger. * @brief Initialize the logger.
* *
* WARNING: this should be done in the same order than * WARNING: The order should be the same in all the functions!
* #gravity_logger_write_particle.
* *
* @param mask_data Data for each type of mask. * @param mask_data Data for each type of mask.
* *
...@@ -78,6 +77,8 @@ INLINE static int gravity_logger_populate_mask_data( ...@@ -78,6 +77,8 @@ INLINE static int gravity_logger_populate_mask_data(
/** /**
* @brief Generates the mask and compute the size of the record. * @brief Generates the mask and compute the size of the record.
* *
* WARNING: The order should be the same in all the functions!
*
* @param masks The list of masks (same order than in #gravity_logger_init). * @param masks The list of masks (same order than in #gravity_logger_init).
* @param part The #gpart that will be written. * @param part The #gpart that will be written.
* @param write_all Are we forcing to write all the fields? * @param write_all Are we forcing to write all the fields?
...@@ -92,37 +93,31 @@ INLINE static void gravity_logger_compute_size_and_mask( ...@@ -92,37 +93,31 @@ INLINE static void gravity_logger_compute_size_and_mask(
/* Here you can decide your own writing logic */ /* Here you can decide your own writing logic */
/* Add the coordinates. */ /* Add the coordinates. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[gravity_logger_field_coordinates],
masks[gravity_logger_field_coordinates], buffer_size);
gravity_logger_field_names[gravity_logger_field_coordinates],
buffer_size);
/* Add the velocities. */ /* Add the velocities. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[gravity_logger_field_velocities],
masks[gravity_logger_field_velocities], buffer_size);
gravity_logger_field_names[gravity_logger_field_velocities], buffer_size);
/* Add the accelerations. */ /* Add the accelerations. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[gravity_logger_field_accelerations],
masks[gravity_logger_field_accelerations], buffer_size);
gravity_logger_field_names[gravity_logger_field_accelerations],
buffer_size);
/* Add the masses. */ /* Add the masses. */
*mask |= logger_add_field_to_mask( *mask |=
masks[gravity_logger_field_masses], logger_add_field_to_mask(masks[gravity_logger_field_masses], buffer_size);
gravity_logger_field_names[gravity_logger_field_masses], buffer_size);
/* Add the ID. */ /* Add the ID. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[gravity_logger_field_particle_ids],
masks[gravity_logger_field_particle_ids], buffer_size);
gravity_logger_field_names[gravity_logger_field_particle_ids],
buffer_size);
} }
/** /**
* @brief Write a particle to the logger. * @brief Write a particle to the logger.
* *
* WARNING: The order should be the same in all the functions!
*
* @param masks The list of masks (same order than in #gravity_logger_init). * @param masks The list of masks (same order than in #gravity_logger_init).
* @param p The #gpart to write. * @param p The #gpart to write.
* @param mask The mask to use for this record. * @param mask The mask to use for this record.
...@@ -135,41 +130,35 @@ INLINE static char *gravity_logger_write_particle( ...@@ -135,41 +130,35 @@ INLINE static char *gravity_logger_write_particle(
unsigned int *mask, char *buff) { unsigned int *mask, char *buff) {
/* Write the coordinate. */ /* Write the coordinate. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[gravity_logger_field_coordinates],
mask_data[gravity_logger_field_coordinates], mask, mask)) {
gravity_logger_field_names[gravity_logger_field_coordinates])) {
memcpy(buff, p->x, 3 * sizeof(double)); memcpy(buff, p->x, 3 * sizeof(double));
buff += 3 * sizeof(double); buff += 3 * sizeof(double);
} }
/* Write the velocity. */ /* Write the velocity. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[gravity_logger_field_velocities],
mask_data[gravity_logger_field_velocities], mask, mask)) {
gravity_logger_field_names[gravity_logger_field_velocities])) {
memcpy(buff, p->v_full, 3 * sizeof(float)); memcpy(buff, p->v_full, 3 * sizeof(float));
buff += 3 * sizeof(float); buff += 3 * sizeof(float);
} }
/* Write the acceleration. */ /* Write the acceleration. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[gravity_logger_field_accelerations],
mask_data[gravity_logger_field_accelerations], mask, mask)) {
gravity_logger_field_names[gravity_logger_field_accelerations])) {
memcpy(buff, p->a_grav, 3 * sizeof(float)); memcpy(buff, p->a_grav, 3 * sizeof(float));
buff += 3 * sizeof(float); buff += 3 * sizeof(float);
} }
/* Write the mass. */ /* Write the mass. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[gravity_logger_field_masses], mask)) {
mask_data[gravity_logger_field_masses], mask,
gravity_logger_field_names[gravity_logger_field_masses])) {
memcpy(buff, &p->mass, sizeof(float)); memcpy(buff, &p->mass, sizeof(float));
buff += sizeof(float); buff += sizeof(float);
} }
/* Write the Id. */ /* Write the Id. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[gravity_logger_field_particle_ids],
mask_data[gravity_logger_field_particle_ids], mask, mask)) {
gravity_logger_field_names[gravity_logger_field_particle_ids])) {
memcpy(buff, &p->id_or_neg_offset, sizeof(long long)); memcpy(buff, &p->id_or_neg_offset, sizeof(long long));
buff += sizeof(long long); buff += sizeof(long long);
} }
......
...@@ -47,8 +47,7 @@ static const char *hydro_logger_field_names[hydro_logger_field_count] = { ...@@ -47,8 +47,7 @@ static const char *hydro_logger_field_names[hydro_logger_field_count] = {
/** /**
* @brief Initialize the logger. * @brief Initialize the logger.
* *
* WARNING: this should be done in the same order than * WARNING: The order should be the same in all the functions!
* #hydro_logger_write_particle.
* *
* @param mask_data Data for each type of mask. * @param mask_data Data for each type of mask.
* *
...@@ -90,6 +89,8 @@ INLINE static int hydro_logger_populate_mask_data(struct mask_data *mask_data) { ...@@ -90,6 +89,8 @@ INLINE static int hydro_logger_populate_mask_data(struct mask_data *mask_data) {
/** /**
* @brief Generates the mask and compute the size of the record. * @brief Generates the mask and compute the size of the record.
* *
* WARNING: The order should be the same in all the functions!
*
* @param masks The list of masks (same order than in #hydro_logger_init). * @param masks The list of masks (same order than in #hydro_logger_init).
* @param part The #part that will be written. * @param part The #part that will be written.
* @param xpart The #xpart that will be written. * @param xpart The #xpart that will be written.
...@@ -106,50 +107,43 @@ INLINE static void hydro_logger_compute_size_and_mask( ...@@ -106,50 +107,43 @@ INLINE static void hydro_logger_compute_size_and_mask(
/* Here you can decide your own writing logic */ /* Here you can decide your own writing logic */
/* Add the coordinates. */ /* Add the coordinates. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[hydro_logger_field_coordinates],
masks[hydro_logger_field_coordinates], buffer_size);
hydro_logger_field_names[hydro_logger_field_coordinates], buffer_size);
/* Add the velocities. */ /* Add the velocities. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[hydro_logger_field_velocities],
masks[hydro_logger_field_velocities], buffer_size);
hydro_logger_field_names[hydro_logger_field_velocities], buffer_size);
/* Add the accelerations. */ /* Add the accelerations. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[hydro_logger_field_accelerations],
masks[hydro_logger_field_accelerations], buffer_size);
hydro_logger_field_names[hydro_logger_field_accelerations], buffer_size);
/* Add the masses. */ /* Add the masses. */
*mask |= logger_add_field_to_mask( *mask |=
masks[hydro_logger_field_masses], logger_add_field_to_mask(masks[hydro_logger_field_masses], buffer_size);
hydro_logger_field_names[hydro_logger_field_masses], buffer_size);
/* Add the smoothing lengths. */ /* Add the smoothing lengths. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[hydro_logger_field_smoothing_lengths],
masks[hydro_logger_field_smoothing_lengths], buffer_size);
hydro_logger_field_names[hydro_logger_field_smoothing_lengths],
buffer_size);
/* Add the entropies. */ /* Add the entropies. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[hydro_logger_field_entropies],
masks[hydro_logger_field_entropies], buffer_size);
hydro_logger_field_names[hydro_logger_field_entropies], buffer_size);
/* Add the ID. */ /* Add the ID. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[hydro_logger_field_particle_ids],
masks[hydro_logger_field_particle_ids], buffer_size);
hydro_logger_field_names[hydro_logger_field_particle_ids], buffer_size);
/* Add the density. */ /* Add the density. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[hydro_logger_field_densities],
masks[hydro_logger_field_densities], buffer_size);
hydro_logger_field_names[hydro_logger_field_densities], buffer_size);
} }
/** /**
* @brief Write a particle to the logger. * @brief Write a particle to the logger.
* *
* WARNING: The order should be the same in all the functions!
*
* @param masks The list of masks (same order than in #hydro_logger_init). * @param masks The list of masks (same order than in #hydro_logger_init).
* @param p The #part to write. * @param p The #part to write.
* @param xp The #xpart to write. * @param xp The #xpart to write.
...@@ -163,25 +157,22 @@ INLINE static char *hydro_logger_write_particle( ...@@ -163,25 +157,22 @@ INLINE static char *hydro_logger_write_particle(
const struct xpart *xp, unsigned int *mask, char *buff) { const struct xpart *xp, unsigned int *mask, char *buff) {
/* Write the coordinate. */ /* Write the coordinate. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[hydro_logger_field_coordinates],
mask_data[hydro_logger_field_coordinates], mask, mask)) {
hydro_logger_field_names[hydro_logger_field_coordinates])) {
memcpy(buff, p->x, 3 * sizeof(double)); memcpy(buff, p->x, 3 * sizeof(double));
buff += 3 * sizeof(double); buff += 3 * sizeof(double);
} }
/* Write the velocity. */ /* Write the velocity. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[hydro_logger_field_velocities],
mask_data[hydro_logger_field_velocities], mask, mask)) {
hydro_logger_field_names[hydro_logger_field_velocities])) {
memcpy(buff, p->v, 3 * sizeof(float)); memcpy(buff, p->v, 3 * sizeof(float));
buff += 3 * sizeof(float); buff += 3 * sizeof(float);
} }
/* Write the acceleration. */ /* Write the acceleration. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[hydro_logger_field_accelerations],
mask_data[hydro_logger_field_accelerations], mask, mask)) {
hydro_logger_field_names[hydro_logger_field_accelerations])) {
/* Compute the acceleration due to hydro and gravity */ /* Compute the acceleration due to hydro and gravity */
float *acc = (float *)buff; float *acc = (float *)buff;
...@@ -194,41 +185,35 @@ INLINE static char *hydro_logger_write_particle( ...@@ -194,41 +185,35 @@ INLINE static char *hydro_logger_write_particle(
} }
/* Write the mass. */ /* Write the mass. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[hydro_logger_field_masses], mask)) {
mask_data[hydro_logger_field_masses], mask,
hydro_logger_field_names[hydro_logger_field_masses])) {
memcpy(buff, &p->mass, sizeof(float)); memcpy(buff, &p->mass, sizeof(float));
buff += sizeof(float); buff += sizeof(float);
} }
/* Write the smoothing length. */ /* Write the smoothing length. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[hydro_logger_field_smoothing_lengths],
mask_data[hydro_logger_field_smoothing_lengths], mask, mask)) {
hydro_logger_field_names[hydro_logger_field_smoothing_lengths])) {
memcpy(buff, &p->h, sizeof(float)); memcpy(buff, &p->h, sizeof(float));
buff += sizeof(float); buff += sizeof(float);
} }
/* Write the entropy. */ /* Write the entropy. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[hydro_logger_field_entropies],
mask_data[hydro_logger_field_entropies], mask, mask)) {
hydro_logger_field_names[hydro_logger_field_entropies])) {
memcpy(buff, &p->entropy, sizeof(float)); memcpy(buff, &p->entropy, sizeof(float));
buff += sizeof(float); buff += sizeof(float);
} }
/* Write the Id. */ /* Write the Id. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[hydro_logger_field_particle_ids],
mask_data[hydro_logger_field_particle_ids], mask, mask)) {
hydro_logger_field_names[hydro_logger_field_particle_ids])) {
memcpy(buff, &p->id, sizeof(long long)); memcpy(buff, &p->id, sizeof(long long));
buff += sizeof(long long); buff += sizeof(long long);
} }
/* Write the density. */ /* Write the density. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[hydro_logger_field_densities],
mask_data[hydro_logger_field_densities], mask, mask)) {
hydro_logger_field_names[hydro_logger_field_densities])) {
memcpy(buff, &p->rho, sizeof(float)); memcpy(buff, &p->rho, sizeof(float));
buff += sizeof(float); buff += sizeof(float);
} }
......
...@@ -80,22 +80,13 @@ INLINE static struct mask_data logger_create_mask_entry(const char* name, ...@@ -80,22 +80,13 @@ INLINE static struct mask_data logger_create_mask_entry(const char* name,
* *
* @param mask_data The mask_data corresponding to the field that we wish to * @param mask_data The mask_data corresponding to the field that we wish to
* write. * write.
* @param name The name of the field.
* @param buffer_size (in) The current size of the future buffer. (out) The * @param buffer_size (in) The current size of the future buffer. (out) The
* updated size. * updated size.
* *
* @return The mask of the current field. * @return The mask of the current field.
*/ */
INLINE static size_t logger_add_field_to_mask(struct mask_data mask_data, INLINE static size_t logger_add_field_to_mask(struct mask_data mask_data,
const char* name,
size_t* buffer_size) { size_t* buffer_size) {
#ifdef SWIFT_DEBUG_CHECKS
/* Check that we are writing the requested field. */
if (strcmp(name, mask_data.name) != 0) {
error("Mismatch between the requested field (%s) and the mask (%s)", name,
mask_data.name);
}
#endif
*buffer_size += mask_data.size; *buffer_size += mask_data.size;
return mask_data.mask; return mask_data.mask;
...@@ -106,19 +97,10 @@ INLINE static size_t logger_add_field_to_mask(struct mask_data mask_data, ...@@ -106,19 +97,10 @@ INLINE static size_t logger_add_field_to_mask(struct mask_data mask_data,
* #logger_add_field_to_mask. * #logger_add_field_to_mask.
* *
* @param mask_data The mask_data corresponding to the current field. * @param mask_data The mask_data corresponding to the current field.
* @param name The name of the field that we are checking.
* @param mask The mask used for the current record. * @param mask The mask used for the current record.
*/ */
INLINE static int logger_should_write_field(struct mask_data mask_data, INLINE static int logger_should_write_field(struct mask_data mask_data,
unsigned int* mask, unsigned int* mask) {
const char* name) {
#ifdef SWIFT_DEBUG_CHECKS
/* Check that we are writing the requested field. */
if (strcmp(name, mask_data.name) != 0) {
error("Mismatch between the requested field (%s) and the mask (%s)", name,
mask_data.name);
}
#endif
const int test = mask_data.mask & *mask; const int test = mask_data.mask & *mask;
if (test) { if (test) {
......
...@@ -44,8 +44,7 @@ static const char *stars_logger_field_names[stars_logger_field_count] = { ...@@ -44,8 +44,7 @@ static const char *stars_logger_field_names[stars_logger_field_count] = {
/** /**
* @brief Initialize the logger. * @brief Initialize the logger.
* *
* WARNING: this should be done in the same order than * WARNING: The order should be the same in all the functions!
* #stars_logger_write_particle.
* *
* @param mask_data Data for each type of mask. * @param mask_data Data for each type of mask.
* *
...@@ -81,6 +80,8 @@ INLINE static int stars_logger_populate_mask_data(struct mask_data *mask_data) { ...@@ -81,6 +80,8 @@ INLINE static int stars_logger_populate_mask_data(struct mask_data *mask_data) {
/** /**
* @brief Generates the mask and compute the size of the record. * @brief Generates the mask and compute the size of the record.
* *
* WARNING: The order should be the same in all the functions!
*
* @param masks The list of masks (same order than in #stars_logger_init). * @param masks The list of masks (same order than in #stars_logger_init).
* @param part The #spart that will be written. * @param part The #spart that will be written.
* @param write_all Are we forcing to write all the fields? * @param write_all Are we forcing to write all the fields?
...@@ -95,40 +96,35 @@ INLINE static void stars_logger_compute_size_and_mask( ...@@ -95,40 +96,35 @@ INLINE static void stars_logger_compute_size_and_mask(
/* Here you can decide your own writing logic */ /* Here you can decide your own writing logic */
/* Add the coordinates. */ /* Add the coordinates. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[stars_logger_field_coordinates],
masks[stars_logger_field_coordinates], buffer_size);
stars_logger_field_names[stars_logger_field_coordinates], buffer_size);
/* Add the velocities. */ /* Add the velocities. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[stars_logger_field_velocities],
masks[stars_logger_field_velocities], buffer_size);
stars_logger_field_names[stars_logger_field_velocities], buffer_size);
/* Add the accelerations. */ /* Add the accelerations. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[stars_logger_field_accelerations],
masks[stars_logger_field_accelerations], buffer_size);
stars_logger_field_names[stars_logger_field_accelerations], buffer_size);
/* Add the masses. */ /* Add the masses. */
*mask |= logger_add_field_to_mask( *mask |=
masks[stars_logger_field_masses], logger_add_field_to_mask(masks[stars_logger_field_masses], buffer_size);
stars_logger_field_names[stars_logger_field_masses], buffer_size);
/* Add the smoothing lengths. */ /* Add the smoothing lengths. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[stars_logger_field_smoothing_lengths],
masks[stars_logger_field_smoothing_lengths], buffer_size);
stars_logger_field_names[stars_logger_field_smoothing_lengths],
buffer_size);
/* Add the ID. */ /* Add the ID. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(masks[stars_logger_field_particle_ids],
masks[stars_logger_field_particle_ids], buffer_size);
stars_logger_field_names[stars_logger_field_particle_ids], buffer_size);
} }
/** /**
* @brief Write a particle to the logger. * @brief Write a particle to the logger.
* *
* WARNING: The order should be the same in all the functions!
*
* @param masks The list of masks (same order than in #stars_logger_init). * @param masks The list of masks (same order than in #stars_logger_init).
* @param p The #spart to write. * @param p The #spart to write.
* @param mask The mask to use for this record. * @param mask The mask to use for this record.
...@@ -141,49 +137,42 @@ INLINE static char *stars_logger_write_particle( ...@@ -141,49 +137,42 @@ INLINE static char *stars_logger_write_particle(
unsigned int *mask, char *buff) { unsigned int *mask, char *buff) {
/* Write the coordinate. */ /* Write the coordinate. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[stars_logger_field_coordinates],
mask_data[stars_logger_field_coordinates], mask, mask)) {
stars_logger_field_names[stars_logger_field_coordinates])) {
memcpy(buff, p->x, 3 * sizeof(double)); memcpy(buff, p->x, 3 * sizeof(double));
buff += 3 * sizeof(double); buff += 3 * sizeof(double);
} }
/* Write the velocity. */ /* Write the velocity. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[stars_logger_field_velocities],
mask_data[stars_logger_field_velocities], mask, mask)) {
stars_logger_field_names[stars_logger_field_velocities])) {
memcpy(buff, p->v, 3 * sizeof(float)); memcpy(buff, p->v, 3 * sizeof(float));
buff += 3 * sizeof(float); buff += 3 * sizeof(float);
} }
/* Write the acceleration. */ /* Write the acceleration. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[stars_logger_field_accelerations],
mask_data[stars_logger_field_accelerations], mask, mask)) {
stars_logger_field_names[stars_logger_field_accelerations])) {
memcpy(buff, p->gpart->a_grav, 3 * sizeof(float)); memcpy(buff, p->gpart->a_grav, 3 * sizeof(float));
buff += 3 * sizeof(float); buff += 3 * sizeof(float);
} }
/* Write the mass. */ /* Write the mass. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[stars_logger_field_masses], mask)) {
mask_data[stars_logger_field_masses], mask,
stars_logger_field_names[stars_logger_field_masses])) {
memcpy(buff, &p->mass, sizeof(float)); memcpy(buff, &p->mass, sizeof(float));
buff += sizeof(float); buff += sizeof(float);
} }
/* Write the smoothing length. */ /* Write the smoothing length. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[stars_logger_field_smoothing_lengths],
mask_data[stars_logger_field_smoothing_lengths], mask, mask)) {
stars_logger_field_names[stars_logger_field_smoothing_lengths])) {
memcpy(buff, &p->h, sizeof(float)); memcpy(buff, &p->h, sizeof(float));
buff += sizeof(float); buff += sizeof(float);
} }
/* Write the Id. */ /* Write the Id. */
if (logger_should_write_field( if (logger_should_write_field(mask_data[stars_logger_field_particle_ids],
mask_data[stars_logger_field_particle_ids], mask, mask)) {
stars_logger_field_names[stars_logger_field_particle_ids])) {
memcpy(buff, &p->id, sizeof(long long)); memcpy(buff, &p->id, sizeof(long long));
buff += sizeof(long long); buff += sizeof(long long);
} }
......
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