Skip to content
Open
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/__version__.py.in
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE
DESTINATION ${CMAKE_INSTALL_DOCDIR})

find_package(fmt 9 REQUIRED)

#--- project specific subdirectories -------------------------------------------
add_subdirectory(src)

Expand All @@ -222,8 +224,6 @@ if(BUILD_TESTING)
add_subdirectory(tests)
endif()

find_package(fmt 9 REQUIRED)

add_subdirectory(tools)
add_subdirectory(python)

Expand Down
1 change: 1 addition & 0 deletions cmake/podioConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if(NOT "@REQUIRE_PYTHON_VERSION@" STREQUAL "")
else()
find_dependency(Python3 COMPONENTS Interpreter Development)
endif()
find_dependency(fmt @fmt_VERSION@)

SET(PODIO_ENABLE_SIO @ENABLE_SIO@)
if(PODIO_ENABLE_SIO)
Expand Down
11 changes: 11 additions & 0 deletions include/podio/ObjectID.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifndef PODIO_OBJECTID_H
#define PODIO_OBJECTID_H

// Hide the fmt dependency from cling, so that ROOT does not need to be able to
// find the fmt headers when it parses the podio headers at runtime
#if !defined(__CLING__)
#include <fmt/ostream.h>
#endif

#include <compare>
#include <cstdint>
#include <functional>
Expand Down Expand Up @@ -66,4 +72,9 @@ struct std::hash<podio::ObjectID> {
}
};

#if !defined(__CLING__)
template <>
struct fmt::formatter<podio::ObjectID> : fmt::ostream_formatter {};
#endif

#endif
11 changes: 11 additions & 0 deletions include/podio/UserDataCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include "podio/detail/Pythonizations.h"
#include "podio/utilities/TypeHelpers.h"

// Hide the fmt dependency from cling, so that ROOT does not need to be able to
// find the fmt headers when it parses the podio headers at runtime
#if !defined(__CLING__)
#include <fmt/ostream.h>
#endif

#define PODIO_ADD_USER_TYPE(type) \
template <> \
consteval const char* userDataTypeName<type>() { \
Expand Down Expand Up @@ -354,4 +360,9 @@ constexpr std::string_view UserDataCollection<BasicType, U>::dataTypeName;

} // namespace podio

#if !defined(__CLING__)
template <typename BasicType>
struct fmt::formatter<podio::UserDataCollection<BasicType>> : fmt::ostream_formatter {};
#endif

#endif
15 changes: 13 additions & 2 deletions include/podio/detail/Link.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#include "nlohmann/json.hpp"
#endif

// Hide the fmt dependency from cling, so that ROOT does not need to be able to
// find the fmt headers when it parses the podio headers at runtime
#if !defined(__CLING__)
#include <fmt/ostream.h>
#endif

#include <functional>
#include <ostream>
#include <type_traits>
Expand Down Expand Up @@ -348,8 +354,8 @@ class LinkT {
podio::utils::MaybeSharedPtr<LinkObjT> m_obj{nullptr};
};

template <typename FromT, typename ToT>
std::ostream& operator<<(std::ostream& os, const Link<FromT, ToT>& link) {
template <typename FromT, typename ToT, bool Mutable>
std::ostream& operator<<(std::ostream& os, const LinkT<FromT, ToT, Mutable>& link) {
if (!link.isAvailable()) {
return os << "[not available]";
}
Expand Down Expand Up @@ -382,4 +388,9 @@ struct std::hash<podio::LinkT<FromT, ToT, Mutable>> {
}
};

#if !defined(__CLING__)
template <typename FromT, typename ToT, bool Mutable>
struct fmt::formatter<podio::LinkT<FromT, ToT, Mutable>> : fmt::ostream_formatter {};
#endif

#endif // PODIO_DETAIL_LINK_H
11 changes: 11 additions & 0 deletions include/podio/detail/LinkCollectionImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#include "nlohmann/json.hpp"
#endif

// Hide the fmt dependency from cling, so that ROOT does not need to be able to
// find the fmt headers when it parses the podio headers at runtime
#if !defined(__CLING__)
#include <fmt/ostream.h>
#endif

#include <iomanip>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -463,4 +469,9 @@ void to_json(nlohmann::json& j, const podio::LinkCollection<FromT, ToT>& collect

} // namespace podio

#if !defined(__CLING__)
template <typename FromT, typename ToT>
struct fmt::formatter<podio::LinkCollection<FromT, ToT>> : fmt::ostream_formatter {};
#endif

#endif // PODIO_DETAIL_LINKCOLLECTIONIMPL_H
11 changes: 11 additions & 0 deletions python/templates/Collection.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
#include <memory>
#include <cstddef>

// Hide the fmt dependency from cling, so that ROOT does not need to be able to
// find the fmt headers when it parses the podio headers at runtime
#if !defined(__CLING__)
#include <fmt/ostream.h>
#endif

namespace podio {
struct RelationNames;
}
Expand Down Expand Up @@ -280,6 +286,11 @@ void to_json(nlohmann::json& j, const {{ class.bare_type }}Collection& collectio

{{ utils.namespace_close(class.namespace) }}

#if !defined(__CLING__)
template <>
struct fmt::formatter<{% if class.namespace %}{{ class.namespace }}::{% endif %}{{ class.bare_type }}Collection> : fmt::ostream_formatter {};
#endif

{{ workarounds.ld_library_path(class, "Collection", ["valueTypeName", "dataTypeName"]) }}

#endif
13 changes: 13 additions & 0 deletions python/templates/Component.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
{% if generate_current_version %}
#include <ostream>

// Hide the fmt dependency from cling, so that ROOT does not need to be able to
// find the fmt headers when it parses the podio headers at runtime
#if !defined(__CLING__)
#include <fmt/ostream.h>
#endif

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json_fwd.hpp"
#endif
Expand Down Expand Up @@ -58,4 +64,11 @@ public:

{{ utils.namespace_close(class.namespace) }}

{% if generate_current_version %}
#if !defined(__CLING__)
template <>
struct fmt::formatter<{{ class.full_type }}> : fmt::ostream_formatter {};
#endif
{% endif %}

#endif
11 changes: 11 additions & 0 deletions python/templates/Interface.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#include "podio/utilities/TypeHelpers.h"
#include "podio/detail/OrderKey.h"

// Hide the fmt dependency from cling, so that ROOT does not need to be able to
// find the fmt headers when it parses the podio headers at runtime
#if !defined(__CLING__)
#include <fmt/ostream.h>
#endif

#include <memory>
#include <ostream>
#include <stdexcept>
Expand Down Expand Up @@ -190,4 +196,9 @@ struct std::hash<{{ class.full_type }}> {
}
};

#if !defined(__CLING__)
template <>
struct fmt::formatter<{{ class.full_type }}> : fmt::ostream_formatter {};
#endif

#endif
3 changes: 3 additions & 0 deletions python/templates/MutableObject.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ private:

{{ macros.std_hash(class, prefix='Mutable') }}

{{ macros.ostream_formatter(class, prefix='Mutable') }}


#endif
8 changes: 8 additions & 0 deletions python/templates/Object.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
#include "podio/utilities/MaybeSharedPtr.h"
#include "podio/detail/OrderKey.h"

// Hide the fmt dependency from cling, so that ROOT does not need to be able to
// find the fmt headers when it parses the podio headers at runtime
#if !defined(__CLING__)
#include <fmt/ostream.h>
#endif

#include <ostream>
#include <cstdint>

Expand Down Expand Up @@ -79,6 +85,8 @@ std::ostream& operator<<(std::ostream& o, const {{ class.bare_type }}& value);

{{ macros.std_hash(class) }}

{{ macros.ostream_formatter(class) }}

{{ workarounds.ld_library_path(class) }}

#endif
8 changes: 8 additions & 0 deletions python/templates/macros/declarations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,11 @@ struct std::hash<{{ namespace }}{{ prefix }}{{ class.bare_type }}> {
}
};
{% endmacro %}

{% macro ostream_formatter(class, prefix='') %}
{% set namespace = class.namespace + '::' if class.namespace else '' %}
#if !defined(__CLING__)
template <>
struct fmt::formatter<{{ namespace }}{{ prefix }}{{ class.bare_type }}> : fmt::ostream_formatter {};
#endif
{% endmacro %}
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ SET(core_headers
PODIO_ADD_LIB_AND_DICT(podio "${core_headers}" "${core_sources}" selection.xml)
target_compile_options(podio PRIVATE -pthread)
target_link_libraries(podio PRIVATE Python3::Python)
target_link_libraries(podio PUBLIC fmt::fmt)
# For Frame.h
if (ROOT_VERSION VERSION_LESS 6.36)
target_compile_definitions(podio PUBLIC PODIO_ROOT_OLDER_6_36=1)
Expand Down
11 changes: 11 additions & 0 deletions tests/unittests/interface_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,14 @@ TEST_CASE("InterfaceType extension model", "[interface-types][extension]") {
REQUIRE(wrapper.isA<iextension::AnotherHit>());
REQUIRE(wrapper.as<iextension::AnotherHit>().energy() == 4.2f);
}

TEST_CASE("InterfaceType formatting", "[interface-types][basics][formatting]") {
auto iface = iextension::EnergyInterface::makeEmpty();
auto formatted = fmt::format("{}", iface);
REQUIRE(formatted == "[not available]");

iface = ExampleCluster{};
formatted = fmt::format("{}", iface);
REQUIRE_FALSE(formatted.empty());
REQUIRE(formatted != "[not available]");
}
31 changes: 31 additions & 0 deletions tests/unittests/links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "nlohmann/json.hpp"
#endif

#include <fmt/format.h>

#include <map>
#include <set>
#include <type_traits>
Expand Down Expand Up @@ -305,6 +307,22 @@ TEST_CASE("Links templated accessors", "[links]") {
}
}
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)

TEST_CASE("Link formatting", "[links]") {
TestL link;
auto formatted = fmt::format("{}", link);
REQUIRE_FALSE(formatted.empty());
REQUIRE(formatted != "[not available]");

auto emptyLink = TestL::makeEmpty();
auto emptyFmt = fmt::format("{}", emptyLink);
REQUIRE(emptyFmt == "[not available]");

TestMutL mutLink;
formatted = fmt::format("{}", mutLink);
REQUIRE(formatted != "[not avialable]");
}

TEST_CASE("LinkCollection collection concept", "[links][concepts]") {
STATIC_REQUIRE(podio::CollectionType<TestLColl>);
STATIC_REQUIRE(std::is_same_v<std::ranges::range_value_t<TestLColl>, TestL>);
Expand Down Expand Up @@ -449,6 +467,19 @@ TEST_CASE("LinkCollection basics", "[links]") {
}
}

TEST_CASE("LinkCollection formatting", "[links][formatting]") {
podio::LinkCollection<ExampleHit, ExampleCluster> links;

auto formatted = fmt::format("{}", links);
REQUIRE_FALSE(formatted.empty());

links.create();
links.create();

auto formatted2 = fmt::format("{}", links);
REQUIRE(formatted2.size() > formatted.size());
}

auto createLinkCollections(const size_t nElements = 3u) {
auto colls = std::make_tuple(TestLColl(), ExampleHitCollection(), ExampleClusterCollection());

Expand Down
Loading
Loading