Skip to content
Snippets Groups Projects
Commit 3629ccc3 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Remove string argument in some logger function

parent d00218b6
No related branches found
No related tags found
1 merge request!1125Remove string argument in some logger function
...@@ -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?
...@@ -94,35 +95,32 @@ INLINE static void gravity_logger_compute_size_and_mask( ...@@ -94,35 +95,32 @@ INLINE static void gravity_logger_compute_size_and_mask(
/* 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],
gravity_logger_field_names[gravity_logger_field_coordinates],
buffer_size); 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],
gravity_logger_field_names[gravity_logger_field_accelerations],
buffer_size); buffer_size);
/* Add the masses. */ /* Add the masses. */
*mask |= logger_add_field_to_mask( *mask |= logger_add_field_to_mask(
masks[gravity_logger_field_masses], 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],
gravity_logger_field_names[gravity_logger_field_particle_ids],
buffer_size); 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.
...@@ -136,40 +134,35 @@ INLINE static char *gravity_logger_write_particle( ...@@ -136,40 +134,35 @@ INLINE static char *gravity_logger_write_particle(
/* Write the coordinate. */ /* Write the coordinate. */
if (logger_should_write_field( if (logger_should_write_field(
mask_data[gravity_logger_field_coordinates], mask, mask_data[gravity_logger_field_coordinates], 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, mask_data[gravity_logger_field_velocities], 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, mask_data[gravity_logger_field_accelerations], 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, mask_data[gravity_logger_field_particle_ids], 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.
...@@ -107,49 +108,43 @@ INLINE static void hydro_logger_compute_size_and_mask( ...@@ -107,49 +108,43 @@ INLINE static void hydro_logger_compute_size_and_mask(
/* 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 |= logger_add_field_to_mask(
masks[hydro_logger_field_masses], 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],
hydro_logger_field_names[hydro_logger_field_smoothing_lengths],
buffer_size); 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.
...@@ -164,24 +159,21 @@ INLINE static char *hydro_logger_write_particle( ...@@ -164,24 +159,21 @@ INLINE static char *hydro_logger_write_particle(
/* Write the coordinate. */ /* Write the coordinate. */
if (logger_should_write_field( if (logger_should_write_field(
mask_data[hydro_logger_field_coordinates], mask, mask_data[hydro_logger_field_coordinates], 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, mask_data[hydro_logger_field_velocities], 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, mask_data[hydro_logger_field_accelerations], 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;
...@@ -195,40 +187,35 @@ INLINE static char *hydro_logger_write_particle( ...@@ -195,40 +187,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, mask_data[hydro_logger_field_smoothing_lengths], 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, mask_data[hydro_logger_field_entropies], 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, mask_data[hydro_logger_field_particle_ids], 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, mask_data[hydro_logger_field_densities], 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?
...@@ -96,39 +97,35 @@ INLINE static void stars_logger_compute_size_and_mask( ...@@ -96,39 +97,35 @@ INLINE static void stars_logger_compute_size_and_mask(
/* 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 |= logger_add_field_to_mask(
masks[stars_logger_field_masses], 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],
stars_logger_field_names[stars_logger_field_smoothing_lengths],
buffer_size); 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.
...@@ -142,48 +139,42 @@ INLINE static char *stars_logger_write_particle( ...@@ -142,48 +139,42 @@ INLINE static char *stars_logger_write_particle(
/* Write the coordinate. */ /* Write the coordinate. */
if (logger_should_write_field( if (logger_should_write_field(
mask_data[stars_logger_field_coordinates], mask, mask_data[stars_logger_field_coordinates], 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, mask_data[stars_logger_field_velocities], 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, mask_data[stars_logger_field_accelerations], 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, mask_data[stars_logger_field_smoothing_lengths], 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, mask_data[stars_logger_field_particle_ids], 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);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment