Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <optional> 7 : #include <string> 8 : #include <type_traits> 9 : 10 : #include "DataStructures/DataBox/DataBox.hpp" 11 : #include "IO/Observer/Tags.hpp" 12 : 13 : namespace observers { 14 : 15 : /// Retrieve the `observers::Tags::ObservationKey<SectionIdTag>`, or the empty 16 : /// string if `SectionIdTag` is void. This is useful to support sections in 17 : /// parallel algorithms. The return value can be used to construct a subfile 18 : /// path for observations, and to skip observations on elements that are not 19 : /// part of a section (`std::nullopt`). 20 : template <typename SectionIdTag, typename Box> 21 1 : std::optional<std::string> get_section_observation_key( 22 : [[maybe_unused]] const Box& box) { 23 : if constexpr (std::is_same_v<SectionIdTag, void>) { 24 : return ""; 25 : } else { 26 : using db::get; 27 : return get<observers::Tags::ObservationKey<SectionIdTag>>(box); 28 : } 29 : } 30 : 31 : } // namespace observers