5 static U
convert(
const std::string& str) {
6 static_assert(std::is_same_v<U, void>,
"Unsupported conversion");
12 static double convert(
const std::string& str) {
14 return std::stod(str);
15 }
catch (
const std::invalid_argument&) {
16 throw std::runtime_error(
"Invalid double: '" + str +
"'");
17 }
catch (
const std::out_of_range&) {
18 throw std::runtime_error(
"Out-of-range double: '" + str +
"'");
26 static std::string
convert(
const std::string& str) {
31static inline void normalize_indices(
const Prototype& p,
32 const std::vector<std::string>& line,
33 size_t& vIdx,
int& sIdx,
int& rIdx,
int& bIdx)
35 vIdx = p.
valueIdx < line.size() ? p.
valueIdx : (line.empty() ? 0 : line.size() - 1);
38 rIdx = (p.
rgIdx >= 0 &&
static_cast<size_t>(p.
rgIdx) < line.size()) ? p.
rgIdx : -1;
46 size_t vIdx;
int sIdx, rIdx, bIdx;
47 normalize_indices(prototype, line, vIdx, sIdx, rIdx, bIdx);
50 if (line.empty())
throw std::runtime_error(
"Global-scale block: empty line in " + prototype.
blockName);
51 this->Q.emplace(std::stod(line.at(0)));
52 }
else if (sIdx != -1) {
53 this->Q.emplace(std::stod(line.at(sIdx)));
60 this->bin.emplace(std::pair(std::stod(line.at(bIdx)), std::stod(line.at(bIdx + 1))));
63 if (vIdx >= line.size())
64 throw std::runtime_error(
"valueIdx out of range in " + prototype.
blockName);
70 size_t vIdx;
int sIdx, rIdx, bIdx;
71 normalize_indices(prototype, line, vIdx, sIdx, rIdx, bIdx);
73 std::vector<long> sub_ids;
74 for (
size_t i = 0; i < line.size(); ++i) {
75 if (i == vIdx ||
static_cast<int>(i) == sIdx ||
static_cast<int>(i) == rIdx)
continue;
76 if (bIdx != -1 && (
static_cast<int>(i) == bIdx ||
static_cast<int>(i) == bIdx + 1))
continue;
79 const auto& s = line[i];
80 if (s.find_first_of(
".eEdD") != std::string::npos)
continue;
83 sub_ids.emplace_back(std::stol(s));
88 return LhaID(sub_ids);
93 std::stringstream stream;
94 stream << this->getId() <<
'\t' << this->getValue();
96 stream <<
'\t' << this->getScale();
98 if (rScheme.has_value()) {
99 stream << '\t' << static_cast<int>(this->getScheme());
108 node.
set(this->getValue(),
"central_value");
110 node.
set(this->getScale(),
"scale");
112 if (rScheme.has_value()) {
113 node.
set(
static_cast<int>(this->getScheme()),
"renormalization_scheme");
115 if (bin.has_value()) {
116 auto bin = this->getBinning();
117 node.
set(bin.first,
"bin_low");
118 node.
set(bin.second,
"bin_high");
120 return std::make_shared<DBNode>(node);
125 return std::make_shared<LhaElement<std::string>>(prototype, line);
127 return std::make_shared<LhaElement<double>>(prototype, line);
#define LOG_WARN(...)
Macro for logging warning messages.
Abstract base class for a single element of an LHA/FLHA block.
void set(T value, Key &&key, Rest &&... rest)
Sets a value in the node using a sequence of keys.
static std::shared_ptr< AbstractElement > createElement(const Prototype &prototype, const std::vector< std::string > &line)
Creates an element of the appropriate type for a given line.
Template concrete implementation of an LHA/FLHA block element.
std::string toString() const override
Returns a line-like string representation of the element.
LhaElement(const Prototype &prototype, const std::vector< std::string > &line)
Constructs an LhaElement from a prototype and a line of data.
std::shared_ptr< DBNode > toDBNode() const override
Converts the element to a DBNode representation.
RenormalizationScheme
Enumeration of possible renormalization schemes for LHA elements.
Hash specialization for SymbolId<Tag>.
Represents an identifier of a LHA element, possibly containing several sub-ids.
Represents the structure of an LHA block, specifying columns for values, scales, and renormalization ...
static double convert(const std::string &str)
static std::string convert(const std::string &str)
static U convert(const std::string &str)