Skip to content

Commit 383912b

Browse files
committed
modernize WorkflowHelpers.cxx
1 parent 8a7db0b commit 383912b

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

Framework/Core/src/WorkflowHelpers.cxx

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ std::vector<TopoIndexInfo>
100100
// which have the current node as incoming.
101101
// nextEdges will contain all the edges which are not related
102102
// to the current node.
103-
for (auto& ei : remainingEdgesIndex) {
103+
for (auto const& ei : remainingEdgesIndex) {
104104
if (*(edgeIn + ei * stride) == node.index) {
105105
nextVertex.insert({*(edgeOut + ei * stride), node.layer + 1});
106106
} else {
@@ -112,7 +112,7 @@ std::vector<TopoIndexInfo>
112112
// Of all the vertices which have node as incoming,
113113
// check if there is any other incoming node.
114114
std::set<TopoIndexInfo> hasPredecessors;
115-
for (auto& ei : remainingEdgesIndex) {
115+
for (auto const& ei : remainingEdgesIndex) {
116116
for (auto& m : nextVertex) {
117117
if (m.index == *(edgeOut + ei * stride)) {
118118
hasPredecessors.insert({m.index, m.layer});
@@ -240,7 +240,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
240240
for (size_t wi = 0; wi < workflow.size(); ++wi) {
241241
auto& processor = workflow[wi];
242242
auto name = processor.name;
243-
auto hash = runtime_hash(name.c_str());
243+
uint32_t hash = runtime_hash(name.c_str());
244244
dec.outTskMap.push_back({hash, name});
245245

246246
std::string prefix = "internal-dpl-";
@@ -252,19 +252,18 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
252252
processor.options.push_back(ConfigParamSpec{"end-value-enumeration", VariantType::Int64, -1ll, {"final value for the enumeration"}});
253253
processor.options.push_back(ConfigParamSpec{"step-value-enumeration", VariantType::Int64, 1ll, {"step between one value and the other"}});
254254
}
255-
bool hasTimeframeInputs = std::any_of(processor.inputs.begin(), processor.inputs.end(), [](auto const& input) { return input.lifetime == Lifetime::Timeframe; });
256-
bool hasTimeframeOutputs = std::any_of(processor.outputs.begin(), processor.outputs.end(), [](auto const& output) { return output.lifetime == Lifetime::Timeframe; });
255+
bool hasTimeframeInputs = std::ranges::any_of(processor.inputs, [](auto const& input) { return input.lifetime == Lifetime::Timeframe; });
256+
bool hasTimeframeOutputs = std::ranges::any_of(processor.outputs, [](auto const& output) { return output.lifetime == Lifetime::Timeframe; });
257257

258258
// A timeframeSink consumes timeframes without creating new
259259
// timeframe data.
260260
bool timeframeSink = hasTimeframeInputs && !hasTimeframeOutputs;
261261
if (rateLimitingIPCID != -1) {
262262
if (timeframeSink && processor.name.find("internal-dpl-injected-dummy-sink") == std::string::npos) {
263263
O2_SIGNPOST_ID_GENERATE(sid, workflow_helpers);
264-
uint32_t hash = runtime_hash(processor.name.c_str());
265264
bool hasMatch = false;
266265
ConcreteDataMatcher summaryMatcher = ConcreteDataMatcher{"DPL", "SUMMARY", static_cast<DataAllocator::SubSpecificationType>(hash)};
267-
auto summaryOutput = std::find_if(processor.outputs.begin(), processor.outputs.end(), [&summaryMatcher](auto const& output) { return DataSpecUtils::match(output, summaryMatcher); });
266+
auto summaryOutput = std::ranges::find_if(processor.outputs, [&summaryMatcher](auto const& output) { return DataSpecUtils::match(output, summaryMatcher); });
268267
if (summaryOutput != processor.outputs.end()) {
269268
O2_SIGNPOST_EVENT_EMIT(workflow_helpers, sid, "output enumeration", "%{public}s already there in %{public}s",
270269
DataSpecUtils::describe(*summaryOutput).c_str(), processor.name.c_str());
@@ -283,7 +282,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
283282
switch (input.lifetime) {
284283
case Lifetime::Timer: {
285284
auto concrete = DataSpecUtils::asConcreteDataMatcher(input);
286-
auto hasOption = std::any_of(processor.options.begin(), processor.options.end(), [&input](auto const& option) { return (option.name == "period-" + input.binding); });
285+
auto hasOption = std::ranges::any_of(processor.options, [&input](auto const& option) { return (option.name == "period-" + input.binding); });
287286
if (hasOption == false) {
288287
processor.options.push_back(ConfigParamSpec{"period-" + input.binding, VariantType::Int, 1000, {"period of the timer in milliseconds"}});
289288
}
@@ -299,15 +298,15 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
299298
} break;
300299
case Lifetime::Condition: {
301300
requestedCCDBs.emplace_back(input);
302-
if ((hasConditionOption == false) && std::none_of(processor.options.begin(), processor.options.end(), [](auto const& option) { return (option.name.compare("condition-backend") == 0); })) {
301+
if ((hasConditionOption == false) && std::ranges::none_of(processor.options, [](auto const& option) { return (option.name.compare("condition-backend") == 0); })) {
303302
processor.options.emplace_back(ConfigParamSpec{"condition-backend", VariantType::String, defaultConditionBackend(), {"URL for CCDB"}});
304303
processor.options.emplace_back(ConfigParamSpec{"condition-timestamp", VariantType::Int64, 0ll, {"Force timestamp for CCDB lookup"}});
305304
hasConditionOption = true;
306305
}
307306
} break;
308307
case Lifetime::OutOfBand: {
309308
auto concrete = DataSpecUtils::asConcreteDataMatcher(input);
310-
auto hasOption = std::any_of(processor.options.begin(), processor.options.end(), [&input](auto const& option) { return (option.name == "out-of-band-channel-name-" + input.binding); });
309+
auto hasOption = std::ranges::any_of(processor.options, [&input](auto const& option) { return (option.name == "out-of-band-channel-name-" + input.binding); });
311310
if (hasOption == false) {
312311
processor.options.push_back(ConfigParamSpec{"out-of-band-channel-name-" + input.binding, VariantType::String, "out-of-band", {"channel to listen for out of band data"}});
313312
}
@@ -333,7 +332,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
333332
}
334333
}
335334

336-
std::stable_sort(timer.outputs.begin(), timer.outputs.end(), [](OutputSpec const& a, OutputSpec const& b) { return *DataSpecUtils::getOptionalSubSpec(a) < *DataSpecUtils::getOptionalSubSpec(b); });
335+
std::ranges::stable_sort(timer.outputs, [](OutputSpec const& a, OutputSpec const& b) { return *DataSpecUtils::getOptionalSubSpec(a) < *DataSpecUtils::getOptionalSubSpec(b); });
337336

338337
for (auto& output : processor.outputs) {
339338
if (DataSpecUtils::partialMatch(output, AODOrigins)) {
@@ -344,7 +343,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
344343
dec.providedTIMs.emplace_back(output);
345344
} else if (DataSpecUtils::partialMatch(output, header::DataOrigin{"ATSK"})) {
346345
dec.providedOutputObjHist.emplace_back(output);
347-
auto it = std::find_if(dec.outObjHistMap.begin(), dec.outObjHistMap.end(), [&](auto&& x) { return x.id == hash; });
346+
auto it = std::ranges::find_if(dec.outObjHistMap, [&](auto&& x) { return x.id == hash; });
348347
if (it == dec.outObjHistMap.end()) {
349348
dec.outObjHistMap.push_back({hash, {output.binding.value}});
350349
} else {
@@ -359,10 +358,10 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
359358

360359
auto inputSpecLessThan = [](InputSpec const& lhs, InputSpec const& rhs) { return DataSpecUtils::describe(lhs) < DataSpecUtils::describe(rhs); };
361360
auto outputSpecLessThan = [](OutputSpec const& lhs, OutputSpec const& rhs) { return DataSpecUtils::describe(lhs) < DataSpecUtils::describe(rhs); };
362-
std::sort(dec.requestedDYNs.begin(), dec.requestedDYNs.end(), inputSpecLessThan);
363-
std::sort(dec.requestedTIMs.begin(), dec.requestedTIMs.end(), inputSpecLessThan);
364-
std::sort(dec.providedDYNs.begin(), dec.providedDYNs.end(), outputSpecLessThan);
365-
std::sort(dec.providedTIMs.begin(), dec.providedTIMs.end(), outputSpecLessThan);
361+
std::ranges::sort(dec.requestedDYNs, inputSpecLessThan);
362+
std::ranges::sort(dec.requestedTIMs, inputSpecLessThan);
363+
std::ranges::sort(dec.providedDYNs, outputSpecLessThan);
364+
std::ranges::sort(dec.providedTIMs, outputSpecLessThan);
366365

367366
DataProcessorSpec indexBuilder{
368367
"internal-dpl-aod-index-builder",
@@ -389,8 +388,8 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
389388
AnalysisSupportHelpers::addMissingOutputsToSpawner({}, dec.spawnerInputs, dec.requestedAODs, aodSpawner);
390389
AnalysisSupportHelpers::addMissingOutputsToReader(dec.providedAODs, dec.requestedAODs, aodReader);
391390

392-
std::sort(requestedCCDBs.begin(), requestedCCDBs.end(), inputSpecLessThan);
393-
std::sort(providedCCDBs.begin(), providedCCDBs.end(), outputSpecLessThan);
391+
std::ranges::sort(requestedCCDBs, inputSpecLessThan);
392+
std::ranges::sort(providedCCDBs, outputSpecLessThan);
394393
AnalysisSupportHelpers::addMissingOutputsToReader(providedCCDBs, requestedCCDBs, ccdbBackend);
395394

396395
std::vector<DataProcessorSpec> extraSpecs;
@@ -412,7 +411,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
412411

413412
// add the reader
414413
if (aodReader.outputs.empty() == false) {
415-
auto mctracks2aod = std::find_if(workflow.begin(), workflow.end(), [](auto const& x) { return x.name == "mctracks-to-aod"; });
414+
auto mctracks2aod = std::ranges::find_if(workflow, [](auto const& x) { return x.name == "mctracks-to-aod"; });
416415
if (mctracks2aod == workflow.end()) {
417416
// add normal reader
418417
aodReader.outputs.emplace_back(OutputSpec{"TFN", "TFNumber"});
@@ -440,7 +439,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
440439
auto& dstf = std::get<ConcreteDataMatcher>(matcher.matcher);
441440
// Check if any of the provided outputs is a DISTSTF
442441
// Check if any of the requested inputs is for a 0xccdb message
443-
bool providesDISTSTF = std::any_of(workflow.begin(), workflow.end(),
442+
bool providesDISTSTF = std::ranges::any_of(workflow,
444443
[&matcher](auto const& dp) {
445444
return std::any_of(dp.outputs.begin(), dp.outputs.end(), [&matcher](auto const& output) {
446445
return DataSpecUtils::match(matcher, output);
@@ -450,7 +449,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
450449
// If there is no CCDB requested, but we still ask for a FLP/DISTSUBTIMEFRAME/0xccdb
451450
// we add to the first data processor which has no inputs (apart from
452451
// enumerations / timers) the responsibility to provide the DISTSUBTIMEFRAME
453-
bool requiresDISTSUBTIMEFRAME = std::any_of(workflow.begin(), workflow.end(),
452+
bool requiresDISTSUBTIMEFRAME = std::ranges::any_of(workflow,
454453
[&dstf](auto const& dp) {
455454
return std::any_of(dp.inputs.begin(), dp.inputs.end(), [&dstf](auto const& input) {
456455
return DataSpecUtils::match(input, dstf);
@@ -560,7 +559,7 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
560559
auto fileSink = AnalysisSupportHelpers::getGlobalAODSink(ctx);
561560
extraSpecs.push_back(fileSink);
562561

563-
auto it = std::find_if(dec.outputsInputs.begin(), dec.outputsInputs.end(), [](InputSpec& spec) -> bool {
562+
auto it = std::ranges::find_if(dec.outputsInputs, [](InputSpec& spec) -> bool {
564563
return DataSpecUtils::partialMatch(spec, o2::header::DataOrigin("TFN"));
565564
});
566565
size_t ii = std::distance(dec.outputsInputs.begin(), it);
@@ -694,15 +693,8 @@ void WorkflowHelpers::adjustTopology(WorkflowSpec& workflow, ConfigContext const
694693
}
695694

696695
if (distSTFCount > 0) {
697-
bool found = false;
698696
for (auto& spec : workflow) {
699-
for (auto& output : spec.outputs) {
700-
if (DataSpecUtils::match(output, ConcreteDataMatcher{"FLP", "DISTSUBTIMEFRAME", 0})) {
701-
found = true;
702-
break;
703-
}
704-
}
705-
if (found) {
697+
if (std::ranges::any_of(spec.outputs, [](auto const& output){ return DataSpecUtils::match(output, ConcreteDataMatcher{"FLP", "DISTSUBTIMEFRAME", 0}); })) {
706698
for (unsigned int i = 1; i < distSTFCount; ++i) {
707699
spec.outputs.emplace_back(OutputSpec{ConcreteDataMatcher{"FLP", "DISTSUBTIMEFRAME", i}, Lifetime::Timeframe});
708700
}
@@ -1005,7 +997,7 @@ std::tuple<std::vector<InputSpec>, std::vector<bool>> WorkflowHelpers::analyzeOu
1005997
input.binding = (snprintf(buf, 63, "output_%zu_%zu", output.workflowId, output.id), buf);
1006998

1007999
// make sure that entries are unique
1008-
if (std::find(results.begin(), results.end(), input) == results.end()) {
1000+
if (std::ranges::find(results, input) == results.end()) {
10091001
results.emplace_back(input);
10101002
isDangling.emplace_back(matched == false);
10111003
}

0 commit comments

Comments
 (0)