Skip to content

Commit

Permalink
Add io concepts and restructure backend folder
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Jan 12, 2025
1 parent b4abb48 commit 5e89f23
Show file tree
Hide file tree
Showing 29 changed files with 552 additions and 443 deletions.
46 changes: 46 additions & 0 deletions core/include/detray/core/concepts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s)
#include "detray/core/detail/type_traits.hpp"

namespace detray::concepts {

/// Check for the the presence of any type of grids in a detector definition
template <class detector_t>
concept has_grids = detail::contains_grids_v<typename detector_t::accel> ||
detail::contains_grids_v<typename detector_t::materials>;

/// Check for the the presence of surface grids in a detector definition
template <class detector_t>
concept has_surface_grids =
detail::contains_surface_grids_v<typename detector_t::accel>;

/// Check for the the presence of material slabs in a detector definition
template <class detector_t>
concept has_material_slabs =
detail::contains_material_slabs_v<typename detector_t::materials>;

/// Check for the the presence of material rods in a detector definition
template <class detector_t>
concept has_material_rods =
detail::contains_material_rods_v<typename detector_t::materials>;

/// Check for the the presence of homogeneous material types in a detector
/// definition
template <class detector_t>
concept has_homogeneous_material =
detail::contains_homogeneous_material_v<typename detector_t::materials>;

/// Check for the the presence of material maps in a detector definition
template <class detector_t>
concept has_material_maps =
detail::contains_material_maps_v<typename detector_t::materials>;

} // namespace detray::concepts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2023-2024 CERN for the benefit of the ACTS project
* (c) 2022-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s)
#include "detray/core/detail/type_traits.hpp"
#include "detray/definitions/detail/indexing.hpp"
#include "detray/materials/detail/concepts.hpp"
#include "detray/materials/material_rod.hpp"
#include "detray/materials/material_slab.hpp"
#include "detray/navigation/accelerators/concepts.hpp"
#include "detray/utils/grid/detail/concepts.hpp"
#include "detray/utils/type_registry.hpp"
#include "detray/utils/type_traits.hpp"

// System include(s)
#include <type_traits>

namespace detray {

namespace detail {
namespace detray::detail {

/// Check for grid types in a data store
/// @{
Expand Down Expand Up @@ -115,41 +114,4 @@ inline constexpr bool contains_material_maps_v =
contains_material_maps<T>::value;
/// @}

} // namespace detail

namespace concepts {

/// Check for the the presence of any type of grids in a detector definition
template <class detector_t>
concept has_grids = detail::contains_grids_v<typename detector_t::accel> ||
detail::contains_grids_v<typename detector_t::materials>;

/// Check for the the presence of surface grids in a detector definition
template <class detector_t>
concept has_surface_grids =
detail::contains_surface_grids_v<typename detector_t::accel>;

/// Check for the the presence of material slabs in a detector definition
template <class detector_t>
concept has_material_slabs =
detail::contains_material_slabs_v<typename detector_t::materials>;

/// Check for the the presence of material rods in a detector definition
template <class detector_t>
concept has_material_rods =
detail::contains_material_rods_v<typename detector_t::materials>;

/// Check for the the presence of homogeneous material types in a detector
/// definition
template <class detector_t>
concept has_homogeneous_material =
detail::contains_homogeneous_material_v<typename detector_t::materials>;

/// Check for the the presence of material maps in a detector definition
template <class detector_t>
concept has_material_maps =
detail::contains_material_maps_v<typename detector_t::materials>;

} // namespace concepts

} // namespace detray
} // namespace detray::detail
5 changes: 3 additions & 2 deletions io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ detray_add_library( detray_io_utils io_utils
file(
GLOB _detray_io_public_headers
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"include/detray/io/common/*.hpp"
"include/detray/io/backend/*.hpp"
"include/detray/io/backend/detail/*.hpp"
"include/detray/io/covfie/*.hpp"
"include/detray/io/frontend/*.hpp"
"include/detray/io/frontend/detail/*.hpp"
"include/detray/io/frontend/implementation/*.hpp"
"include/detray/io/frontend/impl/*.hpp"
"include/detray/io/json/*.hpp"
)
detray_add_library( detray_io io
Expand Down
52 changes: 52 additions & 0 deletions io/include/detray/io/backend/concepts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s)
#include "detray/builders/detector_builder.hpp"
#include "detray/utils/type_traits.hpp"

// System include(s)
#include <concepts>
#include <string_view>

namespace detray::io::concepts {

/// Concept for detray io reader backends
template <typename D, typename R>
concept reader_backend =
requires(const R rb, detector_builder<typename D::metadata> det_builder,
typename D::name_map names) {

typename R::payload_type;

{ R::tag }
->std::same_as<const std::string_view&>;

{
R::template from_payload<D>(det_builder, names,
typename R::payload_type())
}
->std::same_as<void>;
};

/// Concept for detray io writer backends
template <typename D, typename W>
concept writer_backend = requires(const W wb, D det,
typename D::name_map names) {

typename W::payload_type;

{ W::tag }
->std::same_as<const std::string_view&>;

{ W::to_payload(det, names) }
->std::same_as<typename W::payload_type>;
};

} // namespace detray::io::concepts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2023-2024 CERN for the benefit of the ACTS project
* (c) 2023-2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Project include(s)
#include "detray/io/frontend/detail/io_metadata.hpp"
#include "detray/io/frontend/payloads.hpp"
#include "detray/io/utils/io_metadata.hpp"

// System include(s)
#include <string_view>

// Convert basic information like links and header data
// Convert basic information like links and header data to and from payloads
namespace detray::io::detail::basic_converter {

/// @returns a link from its io payload @param link_data
inline dindex convert(const single_link_payload& link_data) {
inline dindex from_payload(const single_link_payload& link_data) {
return static_cast<dindex>(link_data.link);
}

/// Convert a link @param idx into its io payload
inline single_link_payload convert(const std::size_t idx) {
inline single_link_payload to_payload(const std::size_t idx) {
single_link_payload link_data;
link_data.link = idx;

Expand All @@ -33,8 +33,8 @@ inline single_link_payload convert(const std::size_t idx) {
/// Convert a typed link with a type id @param id and index @param idx into its
/// io payload
template <typename type_id>
inline typed_link_payload<type_id> convert(const type_id id,
const std::size_t idx) {
inline typed_link_payload<type_id> to_payload(const type_id id,
const std::size_t idx) {
typed_link_payload<type_id> link_data;

link_data.type = id;
Expand All @@ -46,8 +46,8 @@ inline typed_link_payload<type_id> convert(const type_id id,
/// Convert the common header information using the detector name
/// @param det_name and the file tag @param tag that describes the data file
/// content
inline common_header_payload convert(const std::string_view det_name,
const std::string_view tag) {
inline common_header_payload to_payload(const std::string_view det_name,
const std::string_view tag) {
common_header_payload header_data;

header_data.version = io::detail::get_detray_version();
Expand Down
Loading

0 comments on commit 5e89f23

Please sign in to comment.