Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++] Remove spdlog requirement #1852

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions apis/python/src/tiledbsoma/pytiledbsoma.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,9 @@ PYBIND11_MODULE(pytiledbsoma, m) {
reader.set_dim_points(
dim, coords.cast<std::vector<std::string>>());
} else {
throw TileDBSOMAError(fmt::format(
"[pytiledbsoma] set_dim_points: type={} not "
"supported",
arrow_schema.format));
throw TileDBSOMAError(
"[pytiledbsoma] set_dim_points: type=" + std::string(arrow_schema.format) + " not "
"supported");
}

// Release arrow schema
Expand Down
3 changes: 2 additions & 1 deletion libtiledbsoma/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ add_library(TILEDB_SOMA_OBJECTS OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dataframe.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dense_ndarray.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_sparse_ndarray.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/array_buffers.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/column_buffer.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/arrow_adapter.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/logger.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/stats.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/util.cc
Expand Down Expand Up @@ -201,7 +203,6 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/utils/arrow_adapter.h
${CMAKE_CURRENT_SOURCE_DIR}/utils/carrow.h
${CMAKE_CURRENT_SOURCE_DIR}/utils/common.h
${CMAKE_CURRENT_SOURCE_DIR}/utils/logger.h
${CMAKE_CURRENT_SOURCE_DIR}/utils/stats.h
${CMAKE_CURRENT_SOURCE_DIR}/utils/util.h
${CMAKE_CURRENT_SOURCE_DIR}/utils/version.h
Expand Down
2 changes: 2 additions & 0 deletions libtiledbsoma/src/cli/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "soma/enums.h"
#include "soma/soma_array.h"
#include "utils/arrow_adapter.h"
#include "utils/carrow.h"
#include "utils/logger.h"
Comment on lines +36 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these headers added?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.h is used for the LOG_* macros and fmt. carrow.h is used for ArrowSchema. soma_array.h use to include logger.h but that has now been removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But soma_array.h includes logger_public.h. Isn't it enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, logger_public.h does not expose fmt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW one can (somewhat poorly) drop in tinyfmt which is a less powerful than fmt but a single-header C++11 library. The key is, as @nguyenv points out, that the public logger only takes a string (or const char*, I forgot) to 'report' and does no formatting whatsoever itself.


using namespace tiledbsoma;

Expand Down
58 changes: 58 additions & 0 deletions libtiledbsoma/src/soma/array_buffers.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @file array_buffers.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2022 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* This file defines the ArrayBuffers class.
*/

#include "array_buffers.h"
#include "../utils/logger.h"

namespace tiledbsoma {

using namespace tiledb;

std::shared_ptr<ColumnBuffer> ArrayBuffers::at(const std::string& name) {
if (!contains(name)) {
throw TileDBSOMAError(
fmt::format("[ArrayBuffers] column '{}' does not exist", name));
}
return buffers_[name];
}

void ArrayBuffers::emplace(
const std::string& name, std::shared_ptr<ColumnBuffer> buffer) {
if (contains(name)) {
throw TileDBSOMAError(
fmt::format("[ArrayBuffers] column '{}' already exists", name));
}
names_.push_back(name);
buffers_.emplace(name, buffer);
}

} // namespace tiledbsoma
19 changes: 2 additions & 17 deletions libtiledbsoma/src/soma/array_buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <tiledb/tiledb>

#include "../utils/common.h"
#include "../utils/logger.h"
#include "column_buffer.h"

namespace tiledbsoma {
Expand All @@ -58,13 +57,7 @@ class ArrayBuffers {
* @param name Column name
* @return std::shared_ptr<ColumnBuffer> Column buffer
*/
std::shared_ptr<ColumnBuffer> at(const std::string& name) {
if (!contains(name)) {
throw TileDBSOMAError(
fmt::format("[ArrayBuffers] column '{}' does not exist", name));
}
return buffers_[name];
}
std::shared_ptr<ColumnBuffer> at(const std::string& name);

/**
* @brief Return true if a buffer with the given name exists.
Expand All @@ -83,15 +76,7 @@ class ArrayBuffers {
* @param name Column name
* @param buffer Column buffer
*/
void emplace(
const std::string& name, std::shared_ptr<ColumnBuffer> buffer) {
if (contains(name)) {
throw TileDBSOMAError(
fmt::format("[ArrayBuffers] column '{}' already exists", name));
}
names_.push_back(name);
buffers_.emplace(name, buffer);
}
void emplace(const std::string& name, std::shared_ptr<ColumnBuffer> buffer);

/**
* @brief Returns the ordered vector of names.
Expand Down
5 changes: 5 additions & 0 deletions libtiledbsoma/src/soma/column_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#include "column_buffer.h"
#include "../utils/logger.h"

namespace tiledbsoma {

Expand Down Expand Up @@ -152,6 +153,10 @@ ColumnBuffer::ColumnBuffer(
}
}

ColumnBuffer::~ColumnBuffer() {
LOG_TRACE(fmt::format("[ColumnBuffer] release '{}'", name_));
}

void ColumnBuffer::attach(Query& query) {
// We cannot use:
// `set_data_buffer(const std::string& name, std::vector<T>& buf)`
Expand Down
5 changes: 1 addition & 4 deletions libtiledbsoma/src/soma/column_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <tiledb/tiledb_experimental>

#include "../utils/common.h"
#include "../utils/logger.h"
#include "span/span.hpp"

namespace tiledbsoma {
Expand Down Expand Up @@ -128,9 +127,7 @@ class ColumnBuffer {
ColumnBuffer(const ColumnBuffer&) = delete;
ColumnBuffer(ColumnBuffer&&) = default;

~ColumnBuffer() {
LOG_TRACE(fmt::format("[ColumnBuffer] release '{}'", name_));
}
~ColumnBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? While trace is super-voluminous it can be helpful to see that dtors have been reached.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/single-cell-data/TileDB-SOMA/pull/1852/files#diff-e563ff857d3a241fa155b2c78fdd243bbe474e8bf28a7782d03f56f00d00f6b5R156-R158

It's because of fmt::format. I've moved it into column_buffer.cc, so we still do a get a log trace.


/**
* @brief Attach this ColumnBuffer to a TileDB query.
Expand Down
11 changes: 10 additions & 1 deletion libtiledbsoma/src/soma/managed_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "managed_query.h"
#include <tiledb/array_experimental.h>
#include <tiledb/attribute_experimental.h>
#include "logger_public.h"
#include "../utils/logger.h"
#include "utils/common.h"
namespace tiledbsoma {

Expand Down Expand Up @@ -220,4 +220,13 @@ std::shared_ptr<ArrayBuffers> ManagedQuery::submit_read() {
return buffers_;
}

void ManagedQuery::check_column_name(const std::string& name) {
if (!buffers_->contains(name)) {
throw TileDBSOMAError(fmt::format(
"[ManagedQuery] Column '{}' is not available in the query "
"results.",
name));
}
}

}; // namespace tiledbsoma
9 changes: 1 addition & 8 deletions libtiledbsoma/src/soma/managed_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,7 @@ class ManagedQuery {
*
* @param name Column name
*/
void check_column_name(const std::string& name) {
if (!buffers_->contains(name)) {
throw TileDBSOMAError(fmt::format(
"[ManagedQuery] Column '{}' is not available in the query "
"results.",
name));
}
}
void check_column_name(const std::string& name);

// TileDB array being queried.
std::shared_ptr<Array> array_;
Expand Down
2 changes: 1 addition & 1 deletion libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

#include "soma_array.h"
#include <tiledb/array_experimental.h>
#include "../utils/logger.h"
#include "../utils/util.h"
#include "logger_public.h"
namespace tiledbsoma {
using namespace tiledb;

Expand Down
41 changes: 21 additions & 20 deletions libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <tiledb/tiledb>
#include <tiledb/tiledb_experimental>
#include "enums.h"
#include "logger_public.h"
#include "managed_query.h"

namespace tiledbsoma {
Expand Down Expand Up @@ -251,12 +252,13 @@ class SOMAArray {
int partition_count) {
// Validate partition inputs
if (partition_index >= partition_count) {
throw TileDBSOMAError(fmt::format(
"[SOMAArray] partition_index ({}) must be < "
"partition_count "
"({})",
partition_index,
partition_count));
// TODO this use to be formatted with fmt::format which is part of
// internal header spd/log/fmt/fmt.h and should not be used.
// In C++20, this can be replaced with std::format.
std::ostringstream err;
err << "[SOMAArray] partition_index (" << partition_index
<< ") must be < partition_count (" << partition_count;
throw TileDBSOMAError(err.str());
}

if (partition_count > 1) {
Expand All @@ -268,19 +270,17 @@ class SOMAArray {
partition_size = points.size() - start;
}

LOG_DEBUG(fmt::format(
"[SOMAArray] set_dim_points partitioning: sizeof(T)={} "
"dim={} "
"index={} "
"count={} "
"range=[{}, {}] of {} points",
sizeof(T),
dim,
partition_index,
partition_count,
start,
start + partition_size - 1,
points.size()));
// TODO this use to be formatted with fmt::format which is part of
// internal header spd/log/fmt/fmt.h and should not be used.
// In C++20, this can be replaced with std::format.
std::ostringstream log_dbg;
log_dbg << "[SOMAArray] set_dim_points partitioning:"
<< " sizeof(T)=" << sizeof(T) << " dim=" << dim
<< " index=" << partition_index
<< " count=" << partition_count << " range =[" << start
<< ", " << start + partition_size - 1 << "] of "
<< points.size() << "points";
LOG_DEBUG(log_dbg.str());

mq_->select_points(
dim, tcb::span<T>{&points[start], partition_size});
Expand All @@ -301,7 +301,8 @@ class SOMAArray {
template <typename T>
void set_dim_points(const std::string& dim, const std::vector<T>& points) {
LOG_DEBUG(
fmt::format("[SOMAArray] set_dim_points: sizeof(T)={}", sizeof(T)));
"[SOMAArray] set_dim_points: sizeof(T)=" +
std::to_string(sizeof(T)));
mq_->select_points(dim, points);
}

Expand Down
Loading
Loading