Commit 226532a9 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Logger: check masks at the end

parent 0c5c2555
......@@ -217,12 +217,6 @@ void logger_copy_part_fields(const struct part *p, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const uint32_t special_flags) {
#ifdef SWIFT_DEBUG_CHECKS
/* Make sure we're not writing a timestamp. */
if (mask & logger_mask_data[logger_timestamp].mask)
error("You should not log particles as timestamps.");
#endif
/* Write the header. */
buff = logger_write_chunk_header(buff, &mask, offset, offset_new);
......@@ -230,18 +224,21 @@ void logger_copy_part_fields(const struct part *p, unsigned int mask,
if (mask & logger_mask_data[logger_x].mask) {
memcpy(buff, p->x, logger_mask_data[logger_x].size);
buff += logger_mask_data[logger_x].size;
mask &= ~logger_mask_data[logger_x].mask;
}
/* Particle velocity as three floats. */
if (mask & logger_mask_data[logger_v].mask) {
memcpy(buff, p->v, logger_mask_data[logger_v].size);
buff += logger_mask_data[logger_v].size;
mask &= ~logger_mask_data[logger_v].mask;
}
/* Particle accelleration as three floats. */
if (mask & logger_mask_data[logger_a].mask) {
memcpy(buff, p->a_hydro, logger_mask_data[logger_a].size);
buff += logger_mask_data[logger_a].size;
mask &= ~logger_mask_data[logger_a].mask;
}
#if defined(GADGET2_SPH)
......@@ -250,18 +247,21 @@ void logger_copy_part_fields(const struct part *p, unsigned int mask,
if (mask & logger_mask_data[logger_u].mask) {
memcpy(buff, &p->entropy, logger_mask_data[logger_u].size);
buff += logger_mask_data[logger_u].size;
mask &= ~logger_mask_data[logger_u].mask;
}
/* Particle smoothing length as a single float. */
if (mask & logger_mask_data[logger_h].mask) {
memcpy(buff, &p->h, logger_mask_data[logger_h].size);
buff += logger_mask_data[logger_h].size;
mask &= ~logger_mask_data[logger_h].mask;
}
/* Particle density as a single float. */
if (mask & logger_mask_data[logger_rho].mask) {
memcpy(buff, &p->rho, logger_mask_data[logger_rho].size);
buff += logger_mask_data[logger_rho].size;
mask &= ~logger_mask_data[logger_rho].mask;
}
/* Particle constants, which is a bit more complicated. */
......@@ -272,6 +272,7 @@ void logger_copy_part_fields(const struct part *p, unsigned int mask,
const int64_t id = p->id;
memcpy(buff, &id, sizeof(int64_t));
buff += sizeof(int64_t);
mask &= ~logger_mask_data[logger_consts].mask;
}
#endif
......@@ -280,7 +281,14 @@ void logger_copy_part_fields(const struct part *p, unsigned int mask,
if (mask & logger_mask_data[logger_special_flags].mask) {
memcpy(buff, &special_flags, logger_mask_data[logger_special_flags].size);
buff += logger_mask_data[logger_special_flags].size;
mask &= ~logger_mask_data[logger_special_flags].mask;
}
#ifdef SWIFT_DEBUG_CHECKS
if (mask) {
error("Requested logging of values not present in parts. %u", mask);
}
#endif
}
/**
......@@ -345,18 +353,6 @@ void logger_copy_spart_fields(const struct spart *sp, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const uint32_t special_flags) {
#ifdef SWIFT_DEBUG_CHECKS
/* Make sure we're not writing a timestamp. */
if (mask & logger_mask_data[logger_timestamp].mask)
error("You should not log particles as timestamps.");
/* Make sure we're not looging fields not supported by sparts. */
if (mask &
(logger_mask_data[logger_u].mask | logger_mask_data[logger_rho].mask |
logger_mask_data[logger_a].mask))
error("Can't log SPH quantities for sparts.");
#endif
/* Write the header. */
buff = logger_write_chunk_header(buff, &mask, offset, offset_new);
......@@ -364,12 +360,14 @@ void logger_copy_spart_fields(const struct spart *sp, unsigned int mask,
if (mask & logger_mask_data[logger_x].mask) {
memcpy(buff, sp->x, logger_mask_data[logger_x].size);
buff += logger_mask_data[logger_x].size;
mask &= ~logger_mask_data[logger_x].mask;
}
/* Particle velocity as three floats. */
if (mask & logger_mask_data[logger_v].mask) {
memcpy(buff, sp->v, logger_mask_data[logger_v].size);
buff += logger_mask_data[logger_v].size;
mask &= ~logger_mask_data[logger_v].mask;
}
/* Particle constants, which is a bit more complicated. */
......@@ -380,13 +378,21 @@ void logger_copy_spart_fields(const struct spart *sp, unsigned int mask,
const int64_t id = sp->id;
memcpy(buff, &id, sizeof(int64_t));
buff += sizeof(int64_t);
mask &= ~logger_mask_data[logger_consts].mask;
}
/* Special flags */
if (mask & logger_mask_data[logger_special_flags].mask) {
memcpy(buff, &special_flags, logger_mask_data[logger_special_flags].size);
buff += logger_mask_data[logger_special_flags].size;
mask &= ~logger_mask_data[logger_special_flags].mask;
}
#ifdef SWIFT_DEBUG_CHECKS
if (mask) {
error("Requested logging of values not present in sparts. %u", mask);
}
#endif
}
/**
......@@ -448,21 +454,6 @@ void logger_copy_gpart_fields(const struct gpart *gp, unsigned int mask,
size_t *offset, size_t offset_new, char *buff,
const uint32_t special_flags) {
#ifdef SWIFT_DEBUG_CHECKS
if (gp->id_or_neg_offset < 0) {
error("Cannot log a gpart attached to another particle");
}
/* Make sure we're not writing a timestamp. */
if (mask & logger_mask_data[logger_timestamp].mask)
error("You should not log particles as timestamps.");
/* Make sure we're not looging fields not supported by gparts. */
if (mask &
(logger_mask_data[logger_u].mask | logger_mask_data[logger_rho].mask))
error("Can't log SPH quantities for gparts.");
#endif
/* Write the header. */
buff = logger_write_chunk_header(buff, &mask, offset, offset_new);
......@@ -470,18 +461,21 @@ void logger_copy_gpart_fields(const struct gpart *gp, unsigned int mask,
if (mask & logger_mask_data[logger_x].mask) {
memcpy(buff, gp->x, logger_mask_data[logger_x].size);
buff += logger_mask_data[logger_x].size;
mask &= ~logger_mask_data[logger_x].mask;
}
/* Particle velocity as three floats. */
if (mask & logger_mask_data[logger_v].mask) {
memcpy(buff, gp->v_full, logger_mask_data[logger_v].size);
buff += logger_mask_data[logger_v].size;
mask &= ~logger_mask_data[logger_v].mask;
}
/* Particle accelleration as three floats. */
if (mask & logger_mask_data[logger_a].mask) {
memcpy(buff, gp->a_grav, logger_mask_data[logger_a].size);
buff += logger_mask_data[logger_a].size;
mask &= ~logger_mask_data[logger_a].mask;
}
/* Particle constants, which is a bit more complicated. */
......@@ -492,13 +486,21 @@ void logger_copy_gpart_fields(const struct gpart *gp, unsigned int mask,
const int64_t id = gp->id_or_neg_offset;
memcpy(buff, &id, sizeof(int64_t));
buff += sizeof(int64_t);
mask &= ~logger_mask_data[logger_consts].mask;
}
/* Special flags */
if (mask & logger_mask_data[logger_special_flags].mask) {
memcpy(buff, &special_flags, logger_mask_data[logger_special_flags].size);
buff += logger_mask_data[logger_special_flags].size;
mask &= ~logger_mask_data[logger_special_flags].mask;
}
#ifdef SWIFT_DEBUG_CHECKS
if (mask) {
error("Requested logging of values not present in gparts. %u", mask);
}
#endif
}
/**
......
......@@ -27,6 +27,7 @@
/* Includes. */
#include "common_io.h"
#include "dump.h"
#include "error.h"
#include "inline.h"
#include "timeline.h"
#include "units.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