Project
Loading...
Searching...
No Matches
DataSpecViews.h
Go to the documentation of this file.
1// Copyright 2019-2025 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef O2_FRAMEWORK_DATASPECVIEWS_H_
12#define O2_FRAMEWORK_DATASPECVIEWS_H_
13
15#include <ranges>
16
18{
19static auto has_params_with_name(std::string&& name)
20{
21 return [name](ConfigParamSpec const& p) { return p.name.compare(name) == 0; };
22}
23
24static auto has_params_with_name_starting(std::string&& name)
25{
26 return [name](ConfigParamSpec const& p) { return p.name.starts_with(name); };
27}
28} // namespace o2::framework::checks
29
31{
32static auto filter_with_params_by_name(std::string&& name)
33{
34 return std::views::filter([name = std::move(name)](auto const& spec) mutable { return std::ranges::any_of(spec.metadata, checks::has_params_with_name(std::move(name))); });
35}
36
37static auto filter_with_params_by_name_starting(std::string&& name)
38{
39 return std::views::filter([name = std::move(name)](auto const& spec) mutable { return std::ranges::any_of(spec.metadata, checks::has_params_with_name_starting(std::move(name))); });
40}
41
42static auto partial_match_filter(auto what)
43{
44 return std::views::filter([what](auto const& t) -> bool { return DataSpecUtils::partialMatch(t, what); });
45}
46
47static auto exclude_by_name(std::string name)
48{
49 return std::views::filter([name](auto const& t) -> bool { return t.name != name; });
50}
51
52static auto filter_not_matching(auto const& provided)
53{
54 return std::views::filter([&provided](auto const& input) { return std::none_of(provided.begin(), provided.end(), [&input](auto const& output) { return DataSpecUtils::match(input, output); }); });
55}
56
57static auto filter_matching(auto const& provided)
58{
59 return std::views::filter([&provided](auto const& input) { return std::any_of(provided.begin(), provided.end(), [&input](auto const& output) { return DataSpecUtils::match(input, output); }); });
60}
61
62static auto filter_string_params_with(std::string match)
63{
64 return std::views::filter([match](auto const& param) {
65 return (param.type == VariantType::String) && (param.name.find(match) != std::string::npos);
66 });
67}
68
69static auto filter_string_params_starts_with(std::string match)
70{
71 return std::views::filter([match](auto const& param) {
72 return (param.type == VariantType::String) && (param.name.starts_with(match));
73 });
74}
75
76static auto input_to_output_specs()
77{
78 return std::views::transform([](auto const& input) {
79 auto concrete = DataSpecUtils::asConcreteDataMatcher(input);
80 return OutputSpec{concrete.origin, concrete.description, concrete.subSpec, input.lifetime, input.metadata};
81 });
82}
83
84static auto params_to_input_specs()
85{
86 return std::views::transform([](auto const& param) {
87 return DataSpecUtils::fromMetadataString(param.defaultValue.template get<std::string>());
88 });
89}
90} // namespace o2::framework::views
91//
93{
94template <class Container>
95struct append_to {
96 Container& c;
97 // ends the pipeline, returns the container
98 template <std::ranges::input_range R>
99 friend Container& operator|(R&& r, append_to self)
100 {
101 std::ranges::copy(r, std::back_inserter(self.c));
102 return self.c;
103 }
104};
105
106template <class Container>
108 Container& c;
109 // ends the pipeline, returns the container
110 template <std::ranges::input_range R>
111 friend Container& operator|(R&& r, update_input_list self)
112 {
113 for (auto const& item : r) {
114 auto copy = item;
115 DataSpecUtils::updateInputList(self.c, std::move(copy));
116 }
117 return self.c;
118 }
119};
120
121template <class Container>
123 Container& c;
124 // ends the pipeline, returns the container
125 template <std::ranges::input_range R>
126 friend Container& operator|(R&& r, update_output_list self)
127 {
128 for (auto const& item : r) {
129 auto copy = item;
130 DataSpecUtils::updateOutputList(self.c, std::move(copy));
131 }
132 return self.c;
133 }
134};
135
136} // namespace o2::framework::sinks
137
138#endif // O2_FRAMEWORK_DATASPECVIEWS_H_
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
bool match(const std::vector< std::string > &queries, const char *pattern)
Definition dcs-ccdb.cxx:229
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean r
Definition glcorearb.h:1233
GLenum GLfloat param
Definition glcorearb.h:271
template std::string ConfigParamRegistry::get< std::string >(const char *key) const
static bool partialMatch(InputSpec const &spec, o2::header::DataOrigin const &origin)
static InputSpec fromMetadataString(std::string s)
Create an InputSpec from metadata string.
static void updateOutputList(std::vector< OutputSpec > &list, OutputSpec &&input)
Updates list of OutputSpecs by merging metadata (or adding output).
static ConcreteDataMatcher asConcreteDataMatcher(InputSpec const &input)
static void updateInputList(std::vector< InputSpec > &list, InputSpec &&input)
Updates list of InputSpecs by merging metadata.
friend Container & operator|(R &&r, append_to self)
friend Container & operator|(R &&r, update_input_list self)
friend Container & operator|(R &&r, update_output_list self)