Skip to content

Commit 3aec9e4

Browse files
committed
update addMissingOutputsToReader with ranges
1 parent c2798e9 commit 3aec9e4

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

Framework/Core/include/Framework/DataSpecViews.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ static auto filter_not_matching(auto const& provided)
3131
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); }); });
3232
}
3333

34+
static auto filter_matching(auto const& provided)
35+
{
36+
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); }); });
37+
}
3438
} // namespace o2::framework::views
3539
//
3640
namespace o2::framework::sinks
@@ -62,6 +66,21 @@ struct update_input_list {
6266
}
6367
};
6468

69+
template <class Container>
70+
struct update_output_list {
71+
Container& c;
72+
// ends the pipeline, returns the container
73+
template <std::ranges::input_range R>
74+
friend Container& operator|(R&& r, update_output_list self)
75+
{
76+
for (auto& item : r) {
77+
auto copy = item;
78+
DataSpecUtils::updateOutputList(self.c, std::move(copy));
79+
}
80+
return self.c;
81+
}
82+
};
83+
6584
} // namespace o2::framework::sinks
6685

6786
#endif // O2_FRAMEWORK_DATASPECVIEWS_H_

Framework/Core/src/AnalysisSupportHelpers.cxx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "Framework/AnalysisSupportHelpers.h"
1313
#include "Framework/DataOutputDirector.h"
14+
#include "Framework/DataSpecViews.h"
1415
#include "Framework/OutputObjHeader.h"
1516
#include "Framework/ControlService.h"
1617
#include "Framework/EndOfStreamContext.h"
@@ -129,30 +130,12 @@ void AnalysisSupportHelpers::addMissingOutputsToReader(std::vector<OutputSpec> c
129130
std::vector<InputSpec> const& requestedInputs,
130131
DataProcessorSpec& publisher)
131132
{
132-
auto matchingOutputFor = [](InputSpec const& requested) {
133-
return [&requested](OutputSpec const& provided) {
134-
return DataSpecUtils::match(requested, provided);
135-
};
136-
};
137-
for (InputSpec const& requested : requestedInputs) {
138-
auto provided = std::find_if(providedOutputs.begin(),
139-
providedOutputs.end(),
140-
matchingOutputFor(requested));
141-
142-
if (provided != providedOutputs.end()) {
143-
continue;
144-
}
145-
146-
auto inList = std::find_if(publisher.outputs.begin(),
147-
publisher.outputs.end(),
148-
matchingOutputFor(requested));
149-
if (inList != publisher.outputs.end()) {
150-
continue;
151-
}
152-
153-
auto concrete = DataSpecUtils::asConcreteDataMatcher(requested);
154-
publisher.outputs.emplace_back(concrete.origin, concrete.description, concrete.subSpec, requested.lifetime, requested.metadata);
155-
}
133+
requestedInputs |
134+
views::filter_not_matching(providedOutputs) | // filter the inputs that are already provided
135+
std::views::transform([](auto const& req){ // create outputspecs for unmatched inputs
136+
return DataSpecUtils::asOutputSpec(req);
137+
}) |
138+
sinks::update_output_list{publisher.outputs}; // append them to the publisher outputs
156139
}
157140

158141
void AnalysisSupportHelpers::addMissingOutputsToSpawner(std::vector<OutputSpec> const& providedSpecials,

0 commit comments

Comments
 (0)