From bdb397456e9bce8657bcf4e66e7b61b8475dbd1e Mon Sep 17 00:00:00 2001
From: lhausamm <loic_hausammann@hotmail.com>
Date: Sun, 27 May 2018 20:27:13 +0200
Subject: [PATCH] refactoring log part functions

---
 src/hydro/Gadget2/hydro.h    |  4 ++--
 src/hydro/Gadget2/hydro_io.h |  2 +-
 src/logger.c                 | 18 ++++++++----------
 src/logger.h                 | 14 +++++++-------
 src/logger_struct.h          |  6 +++---
 src/runner.c                 |  4 ++--
 6 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/src/hydro/Gadget2/hydro.h b/src/hydro/Gadget2/hydro.h
index 2eaf237d02..892fb4dd9b 100644
--- a/src/hydro/Gadget2/hydro.h
+++ b/src/hydro/Gadget2/hydro.h
@@ -753,7 +753,7 @@ __attribute__((always_inline)) INLINE static void hydro_first_init_part(
   xp->entropy_full = p->entropy;
 
 #ifdef WITH_LOGGER
-  logger_part_data_init(xp->logger_data);
+  logger_part_data_init(&xp->logger_data);
 #endif
 
   hydro_reset_acceleration(p);
@@ -788,7 +788,7 @@ hydro_set_init_internal_energy(struct part *p, float u_init) {
 __attribute__((always_inline)) INLINE static int xpart_should_write(
     const struct xpart *xp, const struct engine *e) {
 
-  return (xp->logger.last_output > e->log->delta_step);  
+  return (xp->logger_data.last_output > e->log->delta_step);  
 }
 #endif
 
diff --git a/src/hydro/Gadget2/hydro_io.h b/src/hydro/Gadget2/hydro_io.h
index 0f8dc9e664..a3828b0b41 100644
--- a/src/hydro/Gadget2/hydro_io.h
+++ b/src/hydro/Gadget2/hydro_io.h
@@ -211,7 +211,7 @@ __attribute__((always_inline)) INLINE static void hydro_write_index(
                                  UNIT_CONV_NO_UNITS, parts, id);
 
   list[1] = io_make_output_field("Offset", ULONGLONG, 1,
-                                 UNIT_CONV_NO_UNITS, xparts, logger.last_offset);
+                                 UNIT_CONV_NO_UNITS, xparts, logger_data.last_offset);
 #else
   error("Cannot write index without logger");
 #endif
diff --git a/src/logger.c b/src/logger.c
index 48061218d3..0e50cc427e 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -187,8 +187,8 @@ void logger_log_all(struct logger *log, struct engine *e) {
     logger_mask_consts;
   
   for(long long i=0; i < e->total_nr_parts; i++) {
-    logger_log_part(&s->parts[i], mask, &s->xparts[i].logger_data.last_offset, log->dump);
-    xparts[i].logger_data.last_output = 0;
+    logger_log_part(log, &s->parts[i], mask, &s->xparts[i].logger_data.last_offset);
+    s->xparts[i].logger_data.last_output = 0;
   }
 
   if (e->total_nr_gparts > 0)
@@ -199,13 +199,12 @@ void logger_log_all(struct logger *log, struct engine *e) {
 /**
  * @brief Dump a #part to the log.
  *
+ * @param log The #logger
  * @param p The #part to dump.
  * @param mask The mask of the data to dump.
  * @param offset Pointer to the offset of the previous log of this particle.
- * @param dump The #dump in which to log the particle data.
  */
-void logger_log_part(const struct part *p, const unsigned int mask, size_t *offset,
-                     struct dump *dump) {
+void logger_log_part(struct logger *log, const struct part *p, const unsigned int mask, size_t *offset) {
 
   /* Make sure we're not writing a timestamp. */
   if (mask & logger_mask_timestamp)
@@ -216,7 +215,7 @@ void logger_log_part(const struct part *p, const unsigned int mask, size_t *offs
 
   /* Allocate a chunk of memory in the dump of the right size. */
   size_t offset_new;
-  char *buff = (char *)dump_get(dump, size, &offset_new);
+  char *buff = (char *)dump_get(log->dump, size, &offset_new);
 
   /* Write the header. */
   buff = logger_write_chunk_header(buff, &mask, offset, offset_new);
@@ -276,13 +275,12 @@ void logger_log_part(const struct part *p, const unsigned int mask, size_t *offs
 /**
  * @brief Dump a #gpart to the log.
  *
+ * @param log The #logger
  * @param p The #gpart to dump.
  * @param mask The mask of the data to dump.
  * @param offset Pointer to the offset of the previous log of this particle.
- * @param dump The #dump in which to log the particle data.
  */
-void logger_log_gpart(const struct gpart *p, const unsigned int mask, size_t *offset,
-                      struct dump *dump) {
+void logger_log_gpart(struct logger *log, const struct gpart *p, const unsigned int mask, size_t *offset) {
 
   /* Make sure we're not writing a timestamp. */
   if (mask & logger_mask_timestamp)
@@ -297,7 +295,7 @@ void logger_log_gpart(const struct gpart *p, const unsigned int mask, size_t *of
 
   /* Allocate a chunk of memory in the dump of the right size. */
   size_t offset_new;
-  char *buff = (char *)dump_get(dump, size, &offset_new);
+  char *buff = (char *)dump_get(log->dump, size, &offset_new);
 
   /* Write the header. */
   buff = logger_write_chunk_header(buff, &mask, offset, offset_new);
diff --git a/src/logger.h b/src/logger.h
index 26a2474588..2014cca12f 100644
--- a/src/logger.h
+++ b/src/logger.h
@@ -123,22 +123,22 @@ extern const unsigned int logger_data_size[];
 /* Function prototypes. */
 int logger_compute_chunk_size(unsigned int mask);
 void logger_log_all(struct logger *log, struct engine *e);
-void logger_log_part(const struct part *p, const unsigned int mask, size_t *offset,
-                     struct dump *dump);
-void logger_log_gpart(const struct gpart *p, const unsigned int mask, size_t *offset,
-                      struct dump *dump);
+void logger_log_part(struct logger *log, const struct part *p, const unsigned int mask, size_t *offset);
+void logger_log_gpart(struct logger *log, const struct gpart *p, const unsigned int mask, size_t *offset);
 void logger_init(struct logger *log, const struct swift_params *params, const struct engine *e);
 void logger_clean(struct logger *log);
 void logger_log_timestamp(struct logger *log, integertime_t t, size_t *offset);
+void logger_ensure_size(struct logger *log, size_t total_nr_parts,
+    size_t total_nr_gparts, size_t total_nr_sparts);
+void logger_write_file_header(struct logger *log, const struct engine* e);
+
 int logger_read_part(struct part *p, size_t *offset, const char *buff);
 int logger_read_gpart(struct gpart *p, size_t *offset, const char *buff);
 int logger_read_timestamp(unsigned long long int *t, size_t *offset,
                           const char *buff);
-void logger_write_file_header(struct logger *log, const struct engine* e);
+
 void logger_const_init(struct logger_const* log_const);
 void logger_const_free(struct logger_const* log_const);
-void logger_ensure_size(struct logger *log, size_t total_nr_parts,
-    size_t total_nr_gparts, size_t total_nr_sparts);
 
 #endif /* WITH_LOGGER */
 
diff --git a/src/logger_struct.h b/src/logger_struct.h
index c21a6aea8e..11c5d3e7c2 100644
--- a/src/logger_struct.h
+++ b/src/logger_struct.h
@@ -53,9 +53,9 @@ struct logger_part_data {
 };
 
 __attribute__((always_inline)) INLINE static  void logger_part_data_init(
-    struct logger_part_data) {
-  xp->logger.last_offset = 0;
-  xp->logger.last_output = SHRT_MAX;
+    struct logger_part_data *logger ) {
+  logger->last_offset = 0;
+  logger->last_output = SHRT_MAX;
 }
 
 #endif // WITH_LOGGER
diff --git a/src/runner.c b/src/runner.c
index 7ba150fa00..a4cee98014 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -2735,10 +2735,10 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
 	if (xpart_should_write(xp, e))
 	  {
 	    /* Write particle */
-	    logger_log_part(p, logger_mask_x | logger_mask_v | logger_mask_a |
+	    logger_log_part(e->log, p, logger_mask_x | logger_mask_v | logger_mask_a |
 			    logger_mask_u | logger_mask_h | logger_mask_rho |
 			    logger_mask_consts,
-			    &xp->logger_data.last_offset, e->log->dump);
+			    &xp->logger_data.last_offset);
 	    //message("Offset: %lu", p->last_offset);
 	    /* Set counter back to zero */
 	    xp->logger_data.last_output = 0;
-- 
GitLab