Skip to content

Commit 00279c7

Browse files
committed
DPL CCDB: move helper initialisation to a separate function
1 parent 87ef0fc commit 00279c7

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

Framework/CCDBSupport/src/CCDBHelpers.cxx

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
#include "CCDB/CcdbApi.h"
2121
#include "CommonConstants/LHCConstants.h"
2222
#include "Framework/Signpost.h"
23-
#include <typeinfo>
2423
#include <TError.h>
2524
#include <TMemFile.h>
26-
#include <functional>
2725

2826
O2_DECLARE_DYNAMIC_LOG(ccdb);
2927

@@ -159,6 +157,55 @@ CCDBHelpers::ParserResult CCDBHelpers::parseRemappings(char const* str)
159157
}
160158
}
161159

160+
void initialiseHelper(CCDBFetcherHelper& helper, ConfigParamRegistry const& options, std::vector<o2::framework::OutputRoute> const& outputRoutes)
161+
{
162+
std::unordered_map<std::string, bool> accountedSpecs;
163+
auto defHost = options.get<std::string>("condition-backend");
164+
auto checkRate = options.get<int>("condition-tf-per-query");
165+
auto checkMult = options.get<int>("condition-tf-per-query-multiplier");
166+
helper.timeToleranceMS = options.get<int64_t>("condition-time-tolerance");
167+
helper.queryPeriodGlo = checkRate > 0 ? checkRate : std::numeric_limits<int>::max();
168+
helper.queryPeriodFactor = checkMult > 0 ? checkMult : 1;
169+
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}", defHost, helper.queryPeriodGlo, helper.queryPeriodFactor == 1 ? std::string{} : fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor));
170+
LOGP(info, "Hook to enable signposts for CCDB messages at {}", (void*)&private_o2_log_ccdb->stacktrace);
171+
auto remapString = options.get<std::string>("condition-remap");
172+
CCDBHelpers::ParserResult result = CCDBHelpers::parseRemappings(remapString.c_str());
173+
if (!result.error.empty()) {
174+
throw runtime_error_f("Error while parsing remapping string %s", result.error.c_str());
175+
}
176+
helper.remappings = result.remappings;
177+
helper.apis[""].init(defHost); // default backend
178+
LOGP(info, "Initialised default CCDB host {}", defHost);
179+
//
180+
for (auto& entry : helper.remappings) { // init api instances for every host seen in the remapping
181+
if (helper.apis.find(entry.second) == helper.apis.end()) {
182+
helper.apis[entry.second].init(entry.second);
183+
LOGP(info, "Initialised custom CCDB host {}", entry.second);
184+
}
185+
LOGP(info, "{} is remapped to {}", entry.first, entry.second);
186+
}
187+
helper.createdNotBefore = std::to_string(options.get<int64_t>("condition-not-before"));
188+
helper.createdNotAfter = std::to_string(options.get<int64_t>("condition-not-after"));
189+
190+
for (auto& route : outputRoutes) {
191+
if (route.matcher.lifetime != Lifetime::Condition) {
192+
continue;
193+
}
194+
auto specStr = DataSpecUtils::describe(route.matcher);
195+
if (accountedSpecs.find(specStr) != accountedSpecs.end()) {
196+
continue;
197+
}
198+
accountedSpecs[specStr] = true;
199+
helper.routes.push_back(route);
200+
LOGP(info, "The following route is a condition {}", DataSpecUtils::describe(route.matcher));
201+
for (auto& metadata : route.matcher.metadata) {
202+
if (metadata.type == VariantType::String) {
203+
LOGP(info, "- {}: {}", metadata.name, metadata.defaultValue.asString());
204+
}
205+
}
206+
}
207+
}
208+
162209
auto getOrbitResetTime(std::pmr::vector<char> const& v) -> Long64_t
163210
{
164211
Int_t previousErrorLevel = gErrorIgnoreLevel;
@@ -307,51 +354,7 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
307354
{
308355
return adaptStateful([](CallbackService& callbacks, ConfigParamRegistry const& options, DeviceSpec const& spec) {
309356
std::shared_ptr<CCDBFetcherHelper> helper = std::make_shared<CCDBFetcherHelper>();
310-
std::unordered_map<std::string, bool> accountedSpecs;
311-
auto defHost = options.get<std::string>("condition-backend");
312-
auto checkRate = options.get<int>("condition-tf-per-query");
313-
auto checkMult = options.get<int>("condition-tf-per-query-multiplier");
314-
helper->timeToleranceMS = options.get<int64_t>("condition-time-tolerance");
315-
helper->queryPeriodGlo = checkRate > 0 ? checkRate : std::numeric_limits<int>::max();
316-
helper->queryPeriodFactor = checkMult > 0 ? checkMult : 1;
317-
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}", defHost, helper->queryPeriodGlo, helper->queryPeriodFactor == 1 ? std::string{} : fmt::format(", (query for high-rate objects downscaled by {})", helper->queryPeriodFactor));
318-
LOGP(info, "Hook to enable signposts for CCDB messages at {}", (void*)&private_o2_log_ccdb->stacktrace);
319-
auto remapString = options.get<std::string>("condition-remap");
320-
ParserResult result = CCDBHelpers::parseRemappings(remapString.c_str());
321-
if (!result.error.empty()) {
322-
throw runtime_error_f("Error while parsing remapping string %s", result.error.c_str());
323-
}
324-
helper->remappings = result.remappings;
325-
helper->apis[""].init(defHost); // default backend
326-
LOGP(info, "Initialised default CCDB host {}", defHost);
327-
//
328-
for (auto& entry : helper->remappings) { // init api instances for every host seen in the remapping
329-
if (helper->apis.find(entry.second) == helper->apis.end()) {
330-
helper->apis[entry.second].init(entry.second);
331-
LOGP(info, "Initialised custom CCDB host {}", entry.second);
332-
}
333-
LOGP(info, "{} is remapped to {}", entry.first, entry.second);
334-
}
335-
helper->createdNotBefore = std::to_string(options.get<int64_t>("condition-not-before"));
336-
helper->createdNotAfter = std::to_string(options.get<int64_t>("condition-not-after"));
337-
338-
for (auto &route : spec.outputs) {
339-
if (route.matcher.lifetime != Lifetime::Condition) {
340-
continue;
341-
}
342-
auto specStr = DataSpecUtils::describe(route.matcher);
343-
if (accountedSpecs.find(specStr) != accountedSpecs.end()) {
344-
continue;
345-
}
346-
accountedSpecs[specStr] = true;
347-
helper->routes.push_back(route);
348-
LOGP(info, "The following route is a condition {}", DataSpecUtils::describe(route.matcher));
349-
for (auto& metadata : route.matcher.metadata) {
350-
if (metadata.type == VariantType::String) {
351-
LOGP(info, "- {}: {}", metadata.name, metadata.defaultValue.asString());
352-
}
353-
}
354-
}
357+
initialiseHelper(*helper, options, spec.outputs);
355358
/// Add a callback on stop which dumps the statistics for the caching per
356359
/// path
357360
callbacks.set<CallbackService::Id::Stop>([helper]() {

0 commit comments

Comments
 (0)