From dc2270c33bcc9d46947207985db3584df2cb2d2f Mon Sep 17 00:00:00 2001
From: loikki <loic.hausammann@protonmail.com>
Date: Mon, 23 Aug 2021 10:44:57 +0200
Subject: [PATCH] Fix compilation debugging checks

---
 src/logfile.cpp        | 17 +++++++----------
 src/logfile.hpp        |  3 ++-
 src/python_wrapper.cpp |  7 ++++---
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/logfile.cpp b/src/logfile.cpp
index 2884c65..85b5124 100644
--- a/src/logfile.cpp
+++ b/src/logfile.cpp
@@ -113,14 +113,11 @@ LogFile::LogFile(const string basename, bool only_header, int verbose)
  *
  * Compare the mask with the one pointed by the header.
  * if the record is a particle, check the id too.
- *
- * @param log The #csds_logfile
  * @param verbose The verbose level
  */
-void csds_logfile_check_record_consistency(ATTR_UNUSED LogFile &log,
-                                           ATTR_UNUSED int verbose) {
+void LogFile::CheckRecordConsistency(ATTR_UNUSED int verbose) {
 #ifdef CSDS_DEBUG_CHECKS
-  struct header *header = &log.header;
+  const Header &header = GetHeader();
 
   if (verbose > 0) {
     message("Check record's headers...");
@@ -132,12 +129,12 @@ void csds_logfile_check_record_consistency(ATTR_UNUSED LogFile &log,
   const high_resolution_clock::time_point init = high_resolution_clock::now();
 
   /* check that the record offset points to another record. */
-  for (size_t offset_debug = header->GetOffsetFirstRecord();
-       offset_debug < log.log->GetFileSize();
-       offset_debug = tools_check_record_consistency(&log, offset_debug)) {
+  for (size_t offset_debug = header.GetOffsetFirstRecord();
+       offset_debug < GetFileSize();
+       offset_debug = CheckCurrentRecordConsistency(offset_debug)) {
 
     /* Check if we should update the progress bar. */
-    float current = 100 * ((float)offset_debug) / log.log->GetFileSize();
+    float current = 100 * ((float)offset_debug) / GetFileSize();
     if (verbose > 0 && current > next_percentage) {
       /* Print the bar */
       tools_print_progress(current, init, "Checking offsets");
@@ -358,7 +355,7 @@ size_t LogFile::ReverseCurrentOffset(size_t offset) {
  *
  * @return position after the record.
  */
-size_t LogFile::CheckRecordConsistency(size_t offset) {
+size_t LogFile::CheckCurrentRecordConsistency(size_t offset) {
 #ifndef CSDS_DEBUG_CHECKS
   csds_error("Should not check in non debug mode.");
 #endif
diff --git a/src/logfile.hpp b/src/logfile.hpp
index e577079..f1351ef 100644
--- a/src/logfile.hpp
+++ b/src/logfile.hpp
@@ -107,8 +107,9 @@ class LogFile : public MappedFile {
   bool GetNextRecordForward(size_t &offset);
   void PopulateTimeArray(const std::string &basename, int verbose);
   void ReverseOffset(std::string filename, int verbose);
-  size_t CheckRecordConsistency(size_t offset);
+  size_t CheckCurrentRecordConsistency(size_t offset);
   size_t ReverseCurrentOffset(size_t offset);
+  void CheckRecordConsistency(int verbose);
 
   /* Information contained in the file header. */
   Header mHeader;
diff --git a/src/python_wrapper.cpp b/src/python_wrapper.cpp
index f0c36c7..8aabf66 100644
--- a/src/python_wrapper.cpp
+++ b/src/python_wrapper.cpp
@@ -405,7 +405,7 @@ bp::list PyReader::GetListFields(bp::object &part_type) {
       GetParticleTypesFromObject(part_type);
 
   /* Inputs are done, now get the fields */
-  const struct header *h = &mReader->mLog->header;
+  const Header &h = mReader->mLog->GetHeader();
 
   /* Find if the fields are present in all the types. */
   std::vector<int> field_present(field_enum_count, 1);
@@ -418,7 +418,7 @@ bp::list PyReader::GetListFields(bp::object &part_type) {
 
       /* Search among all the fields of the particle type */
       int found = 0;
-      for (auto const &field : h->fields[type]) {
+      for (auto const &field : h.GetFields()[type]) {
         if (field.GetField() == (field_enum)i) {
           found = 1;
           break;
@@ -459,6 +459,7 @@ bp::list PyReader::GetListFields(bp::object &part_type) {
  * @return The list of fields to read as enum.
  */
 std::vector<Field> PyReader::GetFieldsFromNames(bp::list &fields) {
+  const Header &header = mReader->mLog->GetHeader();
 
   /* Get the field enum from the header. */
   std::vector<Field> out;
@@ -474,7 +475,7 @@ std::vector<Field> PyReader::GetFieldsFromNames(bp::list &fields) {
     /* Get the field */
     bool found = false;
     for (int type = 0; type < csds_type_count; type++) {
-      for (auto const &field : mReader->mLog->header.fields[type]) {
+      for (auto const &field : header.GetFields()[type]) {
         if (field.GetName().compare(get_string()) == 0) {
           out.emplace_back(field);
           found = true;
-- 
GitLab