159 int rateLimitingIPCID = std::stoi(ctx.
options().
get<std::string>(
"timeframes-rate-limit-ipcid"));
161 .
name =
"internal-dpl-ccdb-backend",
164 {
"condition-not-before",
VariantType::Int64, 0ll, {
"do not fetch from CCDB objects created before provide timestamp"}},
165 {
"condition-not-after",
VariantType::Int64, 3385078236000ll, {
"do not fetch from CCDB objects created after the timestamp"}},
166 {
"condition-remap",
VariantType::String,
"", {
"remap condition path in CCDB based on the provided string."}},
169 {
"condition-use-slice-for-prescaling",
VariantType::Int, 0, {
"use TFslice instead of TFcounter to control validation frequency. If > query rate, do not allow TFCounter excursion exceeding it"}},
170 {
"condition-time-tolerance",
VariantType::Int64, 5000ll, {
"prefer creation time if its difference to orbit-derived time exceeds threshold (ms), impose if <0"}},
171 {
"orbit-offset-enumeration",
VariantType::Int64, 0ll, {
"initial value for the orbit"}},
172 {
"orbit-multiplier-enumeration",
VariantType::Int64, 0ll, {
"multiplier to get the orbit from the counter"}},
173 {
"start-value-enumeration",
VariantType::Int64, 0ll, {
"initial value for the enumeration"}},
174 {
"end-value-enumeration",
VariantType::Int64, -1ll, {
"final value for the enumeration"}},
175 {
"step-value-enumeration",
VariantType::Int64, 1ll, {
"step between one value and the other"}}},
178 .
name =
"internal-dpl-aod-ccdb",
183 {
"condition-not-before",
VariantType::Int64, 0ll, {
"do not fetch from CCDB objects created before provide timestamp"}},
184 {
"condition-not-after",
VariantType::Int64, 3385078236000ll, {
"do not fetch from CCDB objects created after the timestamp"}},
185 {
"condition-remap",
VariantType::String,
"", {
"remap condition path in CCDB based on the provided string."}},
188 {
"condition-use-slice-for-prescaling",
VariantType::Int, 0, {
"use TFslice instead of TFcounter to control validation frequency. If > query rate, do not allow TFCounter excursion exceeding it"}},
189 {
"condition-time-tolerance",
VariantType::Int64, 5000ll, {
"prefer creation time if its difference to orbit-derived time exceeds threshold (ms), impose if <0"}},
190 {
"start-value-enumeration",
VariantType::Int64, 0ll, {
"initial value for the enumeration"}},
191 {
"end-value-enumeration",
VariantType::Int64, -1ll, {
"final value for the enumeration"}},
192 {
"step-value-enumeration",
VariantType::Int64, 1ll, {
"step between one value and the other"}}}};
213 auto aodLifetime = Lifetime::Enumeration;
216 .
name =
"internal-dpl-aod-reader",
237 std::vector<InputSpec> requestedCCDBs;
238 std::vector<OutputSpec> providedCCDBs;
240 for (
size_t wi = 0; wi < workflow.size(); ++wi) {
241 auto& processor = workflow[wi];
242 auto name = processor.name;
244 dec.outTskMap.push_back({
hash,
name});
246 std::string prefix =
"internal-dpl-";
247 if (processor.inputs.empty() && processor.name.compare(0, prefix.size(), prefix) != 0) {
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; });
260 bool timeframeSink = hasTimeframeInputs && !hasTimeframeOutputs;
261 if (rateLimitingIPCID != -1) {
262 if (timeframeSink && processor.name.find(
"internal-dpl-injected-dummy-sink") == std::string::npos) {
264 bool hasMatch =
false;
266 auto summaryOutput = std::ranges::find_if(processor.outputs, [&summaryMatcher](
auto const&
output) { return DataSpecUtils::match(output, summaryMatcher); });
267 if (summaryOutput != processor.outputs.end()) {
268 O2_SIGNPOST_EVENT_EMIT(workflow_helpers, sid,
"output enumeration",
"%{public}s already there in %{public}s",
274 O2_SIGNPOST_EVENT_EMIT(workflow_helpers, sid,
"output enumeration",
"Adding DPL/SUMMARY/%d to %{public}s",
hash, processor.name.c_str());
279 bool hasConditionOption =
false;
280 for (
size_t ii = 0; ii < processor.inputs.size(); ++ii) {
281 auto& input = processor.inputs[ii];
282 bool hasProjectors =
false;
283 bool hasIndexRecords =
false;
284 bool hasCCDBURLs =
false;
286 for (
auto const& p : input.metadata) {
287 if (
p.name.compare(
"projectors") == 0) {
288 hasProjectors =
true;
291 if (
p.name.compare(
"index-records") == 0) {
292 hasIndexRecords =
true;
295 if (
p.name.starts_with(
"ccdb:")) {
300 switch (input.lifetime) {
301 case Lifetime::Timer: {
303 auto hasOption = std::ranges::any_of(processor.options, [&input](
auto const& option) { return (option.name ==
"period-" + input.binding); });
304 if (hasOption ==
false) {
305 processor.options.push_back(ConfigParamSpec{
"period-" + input.binding,
VariantType::Int, 1000, {
"period of the timer in milliseconds"}});
307 timer.outputs.emplace_back(
OutputSpec{concrete.origin, concrete.description, concrete.subSpec, Lifetime::Timer});
309 case Lifetime::Signal: {
311 timer.outputs.emplace_back(
OutputSpec{concrete.origin, concrete.description, concrete.subSpec, Lifetime::Signal});
313 case Lifetime::Enumeration: {
315 timer.outputs.emplace_back(
OutputSpec{concrete.origin, concrete.description, concrete.subSpec, Lifetime::Enumeration});
317 case Lifetime::Condition: {
318 requestedCCDBs.emplace_back(input);
319 if ((hasConditionOption ==
false) && std::ranges::none_of(processor.options, [](
auto const& option) { return (option.name.compare(
"condition-backend") == 0); })) {
321 processor.options.emplace_back(ConfigParamSpec{
"condition-timestamp",
VariantType::Int64, 0ll, {
"Force timestamp for CCDB lookup"}});
322 hasConditionOption =
true;
325 case Lifetime::OutOfBand: {
327 auto hasOption = std::ranges::any_of(processor.options, [&input](
auto const& option) { return (option.name ==
"out-of-band-channel-name-" + input.binding); });
328 if (hasOption ==
false) {
329 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"}});
331 timer.outputs.emplace_back(
OutputSpec{concrete.origin, concrete.description, concrete.subSpec, Lifetime::Enumeration});
334 case Lifetime::Transient:
335 case Lifetime::Timeframe:
336 case Lifetime::Optional:
341 }
else if (hasIndexRecords) {
343 }
else if (hasCCDBURLs) {
350 std::ranges::stable_sort(timer.outputs, [](
OutputSpec const&
a,
OutputSpec const&
b) { return *DataSpecUtils::getOptionalSubSpec(a) < *DataSpecUtils::getOptionalSubSpec(b); });
352 for (
auto&
output : processor.outputs) {
353 bool hasProjectors =
false;
354 bool hasIndexRecords =
false;
355 bool hasCCDBURLs =
false;
357 for (
auto const& p :
output.metadata) {
358 if (
p.name.compare(
"projectors") == 0) {
359 hasProjectors =
true;
362 if (
p.name.compare(
"index-records") == 0) {
363 hasIndexRecords =
true;
366 if (
p.name.starts_with(
"ccdb:")) {
372 dec.providedDYNs.emplace_back(
output);
373 }
else if (hasCCDBURLs) {
374 dec.providedTIMs.emplace_back(
output);
375 }
else if (hasIndexRecords) {
376 dec.providedIDXs.emplace_back(
output);
378 dec.providedAODs.emplace_back(
output);
380 dec.providedOutputObjHist.emplace_back(
output);
381 auto it = std::ranges::find_if(dec.outObjHistMap, [&](
auto&&
x) { return x.id == hash; });
382 if (it == dec.outObjHistMap.end()) {
383 dec.outObjHistMap.push_back({
hash, {
output.binding.value}});
385 it->bindings.push_back(
output.binding.value);
389 if (
output.lifetime == Lifetime::Condition) {
390 providedCCDBs.push_back(
output);
399 "internal-dpl-aod-index-builder",
404 std::ranges::sort(dec.requestedIDXs, inputSpecLessThan);
405 std::ranges::sort(dec.providedIDXs, outputSpecLessThan);
406 dec.requestedIDXs | views::filter_not_matching(dec.providedIDXs) | sinks::append_to{dec.builderInputs};
409 std::ranges::sort(dec.requestedTIMs, inputSpecLessThan);
410 std::ranges::sort(dec.providedTIMs, outputSpecLessThan);
411 dec.requestedTIMs | views::filter_not_matching(dec.providedTIMs) | sinks::append_to{dec.analysisCCDBInputs};
414 std::ranges::sort(dec.requestedDYNs, inputSpecLessThan);
415 std::ranges::sort(dec.providedDYNs, outputSpecLessThan);
416 dec.requestedDYNs | views::filter_not_matching(dec.providedDYNs) | sinks::append_to{dec.spawnerInputs};
419 "internal-dpl-aod-spawner",
426 std::ranges::sort(dec.requestedAODs, inputSpecLessThan);
427 std::ranges::sort(dec.providedAODs, outputSpecLessThan);
430 std::ranges::sort(requestedCCDBs, inputSpecLessThan);
431 std::ranges::sort(providedCCDBs, outputSpecLessThan);
434 std::vector<DataProcessorSpec> extraSpecs;
436 if (transientStore.outputs.empty() ==
false) {
437 extraSpecs.push_back(transientStore);
439 if (qaStore.outputs.empty() ==
false) {
440 extraSpecs.push_back(qaStore);
443 if (aodSpawner.outputs.empty() ==
false) {
447 if (indexBuilder.outputs.empty() ==
false) {
448 extraSpecs.push_back(indexBuilder);
453 if (deploymentMode != DeploymentMode::OnlineDDS && deploymentMode != DeploymentMode::OnlineECS) {
454 if (analysisCCDBBackend.outputs.empty() ==
false) {
455 extraSpecs.push_back(analysisCCDBBackend);
460 if (aodReader.outputs.empty() ==
false) {
461 auto mctracks2aod = std::ranges::find_if(workflow, [](
auto const&
x) {
return x.name ==
"mctracks-to-aod"; });
462 if (mctracks2aod == workflow.end()) {
464 aodReader.outputs.emplace_back(
OutputSpec{
"TFN",
"TFNumber"});
465 aodReader.outputs.emplace_back(
OutputSpec{
"TFF",
"TFFilename"});
468 aodReader.algorithm = AlgorithmSpec{
470 [](DeviceSpec
const& spec) {
471 LOGP(warn,
"Workflow with injected AODs has unsatisfied inputs:");
472 for (
auto const&
output : spec.outputs) {
475 LOGP(fatal,
"Stopping.");
481 timer.outputs.emplace_back(concrete.origin, concrete.description, concrete.subSpec, Lifetime::Enumeration);
486 auto& dstf = std::get<ConcreteDataMatcher>(
matcher.matcher);
489 bool providesDISTSTF = std::ranges::any_of(workflow,
490 [&matcher](
auto const& dp) {
491 return std::any_of(dp.outputs.begin(), dp.outputs.end(), [&matcher](
auto const&
output) {
492 return DataSpecUtils::match(matcher, output);
499 bool requiresDISTSUBTIMEFRAME = std::ranges::any_of(workflow,
500 [&dstf](
auto const& dp) {
501 return std::any_of(dp.inputs.begin(), dp.inputs.end(), [&dstf](
auto const& input) {
502 return DataSpecUtils::match(input, dstf);
510 int enumCandidate = -1;
511 int timerCandidate = -1;
512 for (
auto wi = 0U; wi < workflow.size(); ++wi) {
513 auto& dp = workflow[wi];
514 if (dp.inputs.size() != 1) {
517 auto lifetime = dp.inputs[0].lifetime;
518 if (lifetime == Lifetime::Enumeration && (enumCandidate == -1 || workflow[enumCandidate].
name > dp.name)) {
521 if (lifetime == Lifetime::Timer && (timerCandidate == -1 || workflow[timerCandidate].
name > dp.name)) {
532 if (ccdbBackend.outputs.empty() ==
false) {
533 if (aodReader.outputs.empty() ==
false) {
535 ccdbBackend.inputs.push_back(
InputSpec{
"tfn",
"TFN",
"TFNumber"});
536 }
else if (providesDISTSTF) {
538 ccdbBackend.inputs.push_back(
InputSpec{
"tfn", dstf, Lifetime::Timeframe});
540 if (enumCandidate != -1) {
544 ccdbBackend.inputs.push_back(
InputSpec{
"tfn", dstf, Lifetime::Timeframe});
545 }
else if (timerCandidate != -1) {
548 ccdbBackend.inputs.push_back(
InputSpec{
"tfn", timer_dstf, Lifetime::Timeframe});
552 ccdbBackend.outputs.push_back(
OutputSpec{
"CTP",
"OrbitReset", 0});
555 extraSpecs.push_back(
timePipeline(ccdbBackend, ctx.options().get<
int64_t>(
"ccdb-fetchers")));
556 }
else if (requiresDISTSUBTIMEFRAME && enumCandidate != -1) {
562 if (timer.outputs.empty() ==
false) {
563 extraSpecs.push_back(timer);
568 if (dec.providedOutputObjHist.empty() ==
false) {
570 extraSpecs.push_back(rootSink);
573 workflow.insert(workflow.end(), extraSpecs.begin(), extraSpecs.end());
576 injectAODWriter(workflow, ctx);
579 std::vector<InputSpec> redirectedOutputsInputs;
580 for (
auto ii = 0u; ii < dec.outputsInputs.size(); ii++) {
581 if (ctx.options().get<std::string>(
"forwarding-policy") ==
"none") {
586 if (!dec.isDangling[ii] && (ctx.options().get<std::string>(
"forwarding-policy") !=
"all")) {
593 redirectedOutputsInputs.emplace_back(dec.outputsInputs[ii]);
596 std::vector<InputSpec> unmatched;
597 auto forwardingDestination = ctx.options().get<std::string>(
"forwarding-destination");
598 if (redirectedOutputsInputs.size() > 0 && forwardingDestination ==
"file") {
600 if (unmatched.size() != redirectedOutputsInputs.size()) {
601 extraSpecs.push_back(fileSink);
603 }
else if (redirectedOutputsInputs.size() > 0 && forwardingDestination ==
"fairmq") {
605 extraSpecs.push_back(fairMQSink);
606 }
else if (forwardingDestination !=
"drop") {
607 throw runtime_error_f(
"Unknown forwarding destination %s", forwardingDestination.c_str());
609 if (unmatched.size() > 0 || redirectedOutputsInputs.size() > 0) {
610 std::vector<InputSpec> ignored = unmatched;
611 ignored.insert(ignored.end(), redirectedOutputsInputs.begin(), redirectedOutputsInputs.end());
612 for (
auto& ignoredInput : ignored) {
613 ignoredInput.lifetime = Lifetime::Sporadic;
618 if (aodReader.outputs.empty() ==
false) {
622 O2_SIGNPOST_EVENT_EMIT(workflow_helpers, sid,
"injectServiceDevices",
"Injecting rate limited dummy sink");
623 std::string rateLimitingChannelConfigOutput;
624 if (rateLimitingIPCID != -1) {
625 rateLimitingChannelConfigOutput = fmt::format(
"name=metric-feedback,type=push,method=bind,address=ipc://{}metric-feedback-{},transport=shmem,rateLogging=0",
ChannelSpecHelpers::defaultIPCFolder(), rateLimitingIPCID);
631 workflow.insert(workflow.end(), extraSpecs.begin(), extraSpecs.end());
749 std::vector<DeviceConnectionEdge>& logicalEdges,
750 std::vector<OutputSpec>& outputs,
751 std::vector<LogicalForwardInfo>& forwardedInputsInfo)
754 if (workflow.empty()) {
759 std::vector<LogicalOutputInfo> availableOutputsInfo;
760 auto const& constOutputs = outputs;
762 std::vector<LogicalOutputInfo> forwards;
766 auto enumerateAvailableOutputs = [&workflow, &outputs, &availableOutputsInfo]() {
768 for (
size_t wi = 0; wi < workflow.size(); ++wi) {
769 auto& producer = workflow[wi];
770 if (producer.outputs.empty()) {
771 O2_SIGNPOST_EVENT_EMIT(workflow_helpers, sid,
"output enumeration",
"No outputs for [%zu] %{public}s", wi, producer.name.c_str());
773 O2_SIGNPOST_START(workflow_helpers, sid,
"output enumeration",
"Enumerating outputs for producer [%zu] %{}s public", wi, producer.name.c_str());
775 for (
size_t oi = 0; oi < producer.outputs.size(); ++oi) {
776 auto& out = producer.outputs[oi];
777 auto uniqueOutputId = outputs.size();
781 outputs.push_back(out);
787 auto errorDueToMissingOutputFor = [&workflow, &constOutputs](
size_t ci,
size_t ii) {
788 auto input = workflow[ci].inputs[ii];
789 std::ostringstream
str;
790 str <<
"No matching output found for "
791 <<
DataSpecUtils::describe(input) <<
" as requested by data processor \"" << workflow[ci].name <<
"\". Candidates:\n";
793 for (
auto&
output : constOutputs) {
797 throw std::runtime_error(
str.str());
811 enumerateAvailableOutputs();
813 std::vector<bool> matches(constOutputs.size());
814 for (
size_t consumer = 0; consumer < workflow.size(); ++consumer) {
816 O2_SIGNPOST_START(workflow_helpers, sid,
"input matching",
"Matching inputs of consumer [%zu] %{}s public", consumer, workflow[consumer].
name.c_str());
817 for (
size_t input = 0; input < workflow[consumer].inputs.size(); ++input) {
819 for (
size_t i = 0;
i < constOutputs.size();
i++) {
828 for (
size_t i = 0;
i < availableOutputsInfo.size();
i++) {
830 if (!matches[availableOutputsInfo[
i].outputGlobalIndex]) {
833 auto* oif = &availableOutputsInfo[
i];
837 auto producer = oif->specIndex;
838 auto uniqueOutputId = oif->outputGlobalIndex;
839 for (
size_t tpi = 0; tpi < workflow[consumer].maxInputTimeslices; ++tpi) {
840 for (
size_t ptpi = 0; ptpi < workflow[producer].maxInputTimeslices; ++ptpi) {
841 O2_SIGNPOST_EVENT_EMIT(workflow_helpers, sid,
"output",
"Adding edge between %{public}s and %{public}s", workflow[consumer].
name.c_str(),
842 workflow[producer].name.c_str());
843 logicalEdges.emplace_back(
DeviceConnectionEdge{producer, consumer, tpi, ptpi, uniqueOutputId, input, oif->forward});
848 oif->enabled =
false;
850 if (forwards.empty()) {
851 errorDueToMissingOutputFor(consumer, input);
853 availableOutputsInfo.erase(std::remove_if(availableOutputsInfo.begin(), availableOutputsInfo.end(), [](
auto const& info) { return info.enabled == false; }), availableOutputsInfo.end());
854 std::ranges::copy(forwards, std::back_inserter(availableOutputsInfo));