Skip to content

Commit 72c4ba7

Browse files
committed
DPL: streamline option building
- Avoid too nested if conditions - Do not propagate --ccdb-fetchers for backward compatibility in the on-the-fly generators - Avoid some copying
1 parent 1120c99 commit 72c4ba7

2 files changed

Lines changed: 61 additions & 44 deletions

File tree

Framework/Core/src/DeviceSpecHelpers.cxx

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,53 +1596,71 @@ void DeviceSpecHelpers::prepareArguments(bool defaultQuiet, bool defaultStopped,
15961596
}
15971597
};
15981598

1599-
for (const auto varit : varmap) {
1599+
for (const auto& varit : varmap) {
16001600
// find the option belonging to key, add if the option has been parsed
16011601
// and is not defaulted
16021602
const auto* description = odesc.find_nothrow(varit.first, false);
1603-
if (description && varmap.count(varit.first)) {
1604-
// check the semantics of the value
1605-
auto semantic = description->semantic();
1606-
const char* optarg = "";
1607-
if (semantic) {
1608-
// the value semantics allows different properties like
1609-
// multitoken, zero_token and composing
1610-
// currently only the simple case is supported
1611-
assert(semantic->min_tokens() <= 1);
1612-
// assert(semantic->max_tokens() && semantic->min_tokens());
1613-
if (semantic->min_tokens() > 0) {
1614-
std::string stringRep;
1615-
if (auto v = boost::any_cast<std::string>(&varit.second.value())) {
1616-
stringRep = *v;
1617-
} else if (auto v = boost::any_cast<EarlyForwardPolicy>(&varit.second.value())) {
1618-
std::stringstream tmp;
1619-
tmp << *v;
1620-
stringRep = fmt::format("{}", tmp.str());
1621-
}
1622-
if (varit.first == "channel-config") {
1623-
// FIXME: the parameter to channel-config can be a list of configurations separated
1624-
// by semicolon. The individual configurations will be separated and added individually.
1625-
// The device arguments can then contaoin multiple channel-config entries, but only
1626-
// one for the last configuration is added to control.options
1627-
processRawChannelConfig(stringRep);
1628-
optarg = tmpArgs.back().c_str();
1629-
} else {
1630-
std::string key(fmt::format("--{}", varit.first));
1631-
if (stringRep.length() == 0) {
1632-
// in order to identify options without parameter we add a string
1633-
// with one blank for the 'blank' parameter, it is filtered out
1634-
// further down and a zero-length string is added to argument list
1635-
stringRep = " ";
1636-
}
1637-
updateDeviceArguments(key, stringRep);
1638-
optarg = uniqueDeviceArgs[key].c_str();
1639-
}
1640-
} else if (semantic->min_tokens() == 0 && varit.second.as<bool>()) {
1641-
updateDeviceArguments(fmt::format("--{}", varit.first), "");
1603+
if (description == nullptr || varmap.count(varit.first) == 0) {
1604+
continue;
1605+
}
1606+
1607+
if ((varit.first == "ccdb-fetchers" || varit.first == "spawners") && varit.second.defaulted()) {
1608+
continue;
1609+
}
1610+
1611+
// check the semantics of the value
1612+
auto semantic = description->semantic();
1613+
const char* optarg = "";
1614+
if (!semantic) {
1615+
control.options.insert(std::make_pair(varit.first, optarg));
1616+
continue;
1617+
}
1618+
1619+
if (semantic->min_tokens() == 0 && varit.second.as<bool>()) {
1620+
updateDeviceArguments(fmt::format("--{}", varit.first), "");
1621+
control.options.insert(std::make_pair(varit.first, optarg));
1622+
continue;
1623+
}
1624+
1625+
// the value semantics allows different properties like
1626+
// multitoken, zero_token and composing
1627+
// currently only the simple case is supported
1628+
assert(semantic->min_tokens() <= 1);
1629+
// assert(semantic->max_tokens() && semantic->min_tokens());
1630+
if (semantic->min_tokens() == 0) {
1631+
control.options.insert(std::make_pair(varit.first, optarg));
1632+
continue;
1633+
}
1634+
1635+
if (semantic->min_tokens() > 0) {
1636+
std::string stringRep;
1637+
if (auto v = boost::any_cast<std::string>(&varit.second.value())) {
1638+
stringRep = *v;
1639+
} else if (auto v = boost::any_cast<EarlyForwardPolicy>(&varit.second.value())) {
1640+
std::stringstream tmp;
1641+
tmp << *v;
1642+
stringRep = fmt::format("{}", tmp.str());
1643+
}
1644+
if (varit.first == "channel-config") {
1645+
// FIXME: the parameter to channel-config can be a list of configurations separated
1646+
// by semicolon. The individual configurations will be separated and added individually.
1647+
// The device arguments can then contaoin multiple channel-config entries, but only
1648+
// one for the last configuration is added to control.options
1649+
processRawChannelConfig(stringRep);
1650+
optarg = tmpArgs.back().c_str();
1651+
} else {
1652+
std::string key(fmt::format("--{}", varit.first));
1653+
if (stringRep.length() == 0) {
1654+
// in order to identify options without parameter we add a string
1655+
// with one blank for the 'blank' parameter, it is filtered out
1656+
// further down and a zero-length string is added to argument list
1657+
stringRep = " ";
16421658
}
1659+
updateDeviceArguments(key, stringRep);
1660+
optarg = uniqueDeviceArgs[key].c_str();
16431661
}
1644-
control.options.insert(std::make_pair(varit.first, optarg));
16451662
}
1663+
control.options.insert(std::make_pair(varit.first, optarg));
16461664
}
16471665
};
16481666

@@ -1653,11 +1671,11 @@ void DeviceSpecHelpers::prepareArguments(bool defaultQuiet, bool defaultStopped,
16531671

16541672
// Add the channel configuration
16551673
for (auto& channel : spec.outputChannels) {
1656-
tmpArgs.emplace_back(std::string("--channel-config"));
1674+
tmpArgs.emplace_back("--channel-config");
16571675
tmpArgs.emplace_back(outputChannel2String(channel));
16581676
}
16591677
for (auto& channel : spec.inputChannels) {
1660-
tmpArgs.emplace_back(std::string("--channel-config"));
1678+
tmpArgs.emplace_back("--channel-config");
16611679
tmpArgs.emplace_back(inputChannel2String(channel));
16621680
}
16631681

Framework/Core/src/runDataProcessing.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,6 @@ int runStateMachine(DataProcessorSpecs const& workflow,
20552055
"--driver-client-backend",
20562056
"--fairmq-ipc-prefix",
20572057
"--readers",
2058-
"--ccdb-fetchers",
20592058
"--resources-monitoring",
20602059
"--resources-monitoring-file",
20612060
"--resources-monitoring-dump-interval",

0 commit comments

Comments
 (0)