Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/standalone-sequence-4' into st…
Browse files Browse the repository at this point in the history
…andalone
  • Loading branch information
aliddell committed Sep 17, 2024
2 parents 58e1cc7 + 61a53bc commit b9bb72d
Show file tree
Hide file tree
Showing 55 changed files with 134 additions and 189 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_subdirectory(logger)
add_subdirectory(streaming)
add_subdirectory(driver)
2 changes: 1 addition & 1 deletion src/driver/zarr.storage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "device/kit/storage.h"

#include "zarr.h"
#include "acquire.zarr.h"

#include <string>

Expand Down
23 changes: 23 additions & 0 deletions src/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(tgt acquire-zarr-logger)

add_library(${tgt}
logger.hh
logger.cpp
)

set(PUBLIC_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include/)

target_include_directories(${tgt}
PUBLIC
$<BUILD_INTERFACE:${PUBLIC_INCLUDE_DIR}>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

set_target_properties(${tgt} PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)

install(TARGETS ${tgt}
LIBRARY DESTINATION lib
)
15 changes: 9 additions & 6 deletions src/streaming/logger.cpp → src/logger/logger.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#include "logger.hh"

#include <iostream>
#include <cstdarg>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <filesystem>
#include <string>
#include <thread>

ZarrLogLevel Logger::current_level = ZarrLogLevel_Info;
ZarrLogLevel Logger::current_level_ = ZarrLogLevel_Info;
std::mutex Logger::log_mutex_{};

void
Logger::set_log_level(ZarrLogLevel level)
{
current_level = level;
current_level_ = level;
}

ZarrLogLevel
Logger::get_log_level()
{
return current_level;
return current_level_;
}

std::string
Expand All @@ -28,7 +30,8 @@ Logger::log(ZarrLogLevel level,
const char* format,
...)
{
if (current_level == ZarrLogLevel_None || level < current_level) {
std::scoped_lock lock(log_mutex_);
if (current_level_ == ZarrLogLevel_None || level < current_level_) {
return {}; // Suppress logs
}

Expand Down
18 changes: 5 additions & 13 deletions src/streaming/logger.hh → src/logger/logger.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "zarr.h"
#include "zarr.types.h"

#include <string>
#include <mutex>

class Logger
{
Expand All @@ -16,23 +16,15 @@ class Logger
...);

private:
static ZarrLogLevel current_level;
static ZarrLogLevel current_level_;
static std::mutex log_mutex_;
};

#define LOG_DEBUG(...) \
Logger::log(ZarrLogLevel_Debug, __FILE__, __LINE__, __func__, __VA_ARGS__)
Logger::log(ZarrLogLevel_Debug, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define LOG_INFO(...) \
Logger::log(LogLevel_Info, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define LOG_WARNING(...) \
Logger::log(ZarrLogLevel_Warning, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define LOG_ERROR(...) \
Logger::log(ZarrLogLevel_Error, __FILE__, __LINE__, __func__, __VA_ARGS__)

#define EXPECT(e, ...) \
do { \
if (!(e)) { \
const std::string __err = LOG_ERROR(__VA_ARGS__); \
throw std::runtime_error(__err); \
} \
} while (0)
#define CHECK(e) EXPECT(e, "Expression evaluated as false:\n\t%s", #e)
4 changes: 2 additions & 2 deletions src/streaming/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
set(tgt acquire-zarr)

add_library(${tgt}
logger.hh
logger.cpp
stream.settings.hh
stream.settings.cpp
zarr.stream.hh
Expand Down Expand Up @@ -34,10 +32,12 @@ target_include_directories(${tgt}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src/logger>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

target_link_libraries(${tgt} PRIVATE
acquire-zarr-logger
blosc_static
miniocpp::miniocpp
)
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/array.writer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "macros.hh"
#include "array.writer.hh"
#include "zarr.common.hh"
#include "zarr.stream.hh"
#include "sink.creator.hh"
#include "logger.hh"

#include <cmath>
#include <functional>
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/blosc.compression.params.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "zarr.h"
#include "acquire.zarr.h"

#include <blosc.h>

Expand Down
2 changes: 1 addition & 1 deletion src/streaming/file.sink.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "macros.hh"
#include "file.sink.hh"
#include "logger.hh"

#include <filesystem>
#include <latch>
Expand Down
12 changes: 12 additions & 0 deletions src/streaming/macros.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "logger.hh"

#define EXPECT(e, ...) \
do { \
if (!(e)) { \
const std::string __err = LOG_ERROR(__VA_ARGS__); \
throw std::runtime_error(__err); \
} \
} while (0)
#define CHECK(e) EXPECT(e, "Expression evaluated as false:\n\t%s", #e)
2 changes: 1 addition & 1 deletion src/streaming/s3.connection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "macros.hh"
#include "s3.connection.hh"
#include "logger.hh"

#include <miniocpp/utils.h>

Expand Down
2 changes: 1 addition & 1 deletion src/streaming/s3.sink.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "macros.hh"
#include "s3.sink.hh"
#include "logger.hh"

#include <miniocpp/client.h>

Expand Down
4 changes: 2 additions & 2 deletions src/streaming/sink.creator.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "macros.hh"
#include "sink.creator.hh"
#include "file.sink.hh"
#include "s3.sink.hh"
#include "logger.hh"
#include "zarr.h"
#include "acquire.zarr.h"

#include <filesystem>
#include <latch>
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/stream.settings.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stream.settings.hh"
#include "zarr.h"
#include "acquire.zarr.h"
#include "logger.hh"

#include <blosc.h>
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/zarr.common.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "logger.hh"
#include "macros.hh"
#include "zarr.common.hh"

#include <stdexcept>
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/zarr.common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "stream.settings.hh"
#include "zarr.stream.hh"

#include "zarr.h"
#include "acquire.zarr.h"

namespace zarr {
using Dimension = ZarrDimension_s;
Expand Down
4 changes: 2 additions & 2 deletions src/streaming/zarr.stream.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "macros.hh"
#include "zarr.stream.hh"
#include "zarr.h"
#include "logger.hh"
#include "acquire.zarr.h"
#include "s3.connection.hh"
#include "zarrv2.array.writer.hh"
#include "zarrv3.array.writer.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/zarrv2.array.writer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "macros.hh"
#include "zarrv2.array.writer.hh"
#include "sink.creator.hh"
#include "logger.hh"
#include "zarr.common.hh"

#include <nlohmann/json.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/zarrv3.array.writer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "macros.hh"
#include "zarrv3.array.writer.hh"
#include "sink.creator.hh"
#include "logger.hh"
#include "zarr.common.hh"

#include <nlohmann/json.hpp>
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ set(tests

foreach (name ${tests})
set(tgt "${project}-${name}")
add_executable(${tgt} ${name}.cpp test.logger.hh test.logger.cpp)
add_executable(${tgt} ${name}.cpp)
target_compile_definitions(${tgt} PUBLIC "TEST=\"${tgt}\"")
set_target_properties(${tgt} PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
target_include_directories(${tgt} PRIVATE
"${CMAKE_SOURCE_DIR}/src/include")
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src/logger
)
target_link_libraries(${tgt} PRIVATE
acquire-zarr-logger
acquire-zarr
nlohmann_json::nlohmann_json
miniocpp::miniocpp
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/copy-settings.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <cstring>
#include <stdexcept>
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/create-and-destroy-stream.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "zarr.h"
#include "acquire.zarr.h"

#include <cstdio>
#include <cstring>
Expand Down
32 changes: 3 additions & 29 deletions tests/integration/test.logger.hh → tests/integration/macros.hh
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
#include "zarr.h"
#pragma once

#include <string>

class Logger
{
public:
static void set_log_level(ZarrLogLevel level);
static ZarrLogLevel get_log_level();

static std::string log(ZarrLogLevel level,
const char* file,
int line,
const char* func,
const char* format,
...);

private:
static ZarrLogLevel current_level;
};

#define LOG_DEBUG(...) \
Logger::log(LogLevel_Debug, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define LOG_INFO(...) \
Logger::log(LogLevel_Info, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define LOG_WARNING(...) \
Logger::log(ZarrLogLevel_Warning, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define LOG_ERROR(...) \
Logger::log(ZarrLogLevel_Error, __FILE__, __LINE__, __func__, __VA_ARGS__)
#include "logger.hh"

#define EXPECT(e, ...) \
do { \
Expand Down Expand Up @@ -64,4 +38,4 @@ class Logger
#b, \
a_.c_str(), \
b_.c_str()); \
} while (0)
} while (0)
2 changes: 1 addition & 1 deletion tests/integration/set-and-get-params.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "zarr.h"
#include "acquire.zarr.h"

#include <cstdio>
#include <string>
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/stream-zarr-v2-compressed-to-filesystem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <nlohmann/json.hpp>

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/stream-zarr-v2-compressed-to-s3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <nlohmann/json.hpp>
#include <miniocpp/client.h>
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/stream-zarr-v2-raw-to-filesystem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <nlohmann/json.hpp>

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/stream-zarr-v2-raw-to-s3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <nlohmann/json.hpp>
#include <miniocpp/client.h>
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/stream-zarr-v3-compressed-to-filesystem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <nlohmann/json.hpp>

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/stream-zarr-v3-compressed-to-s3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <nlohmann/json.hpp>
#include <miniocpp/client.h>
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/stream-zarr-v3-raw-to-filesystem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <nlohmann/json.hpp>

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/stream-zarr-v3-raw-to-s3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "zarr.h"
#include "test.logger.hh"
#include "acquire.zarr.h"
#include "macros.hh"

#include <nlohmann/json.hpp>
#include <miniocpp/client.h>
Expand Down
Loading

0 comments on commit b9bb72d

Please sign in to comment.