Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
lha_blocks.cpp
Go to the documentation of this file.
1#include "lha_blocks.h"
2
4 LOG_DEBUG("Trying to retrieve element", id, "within block", this->prototype.blockName);
5 auto p = [id](const std::shared_ptr<AbstractElement>& e) {
6 return e->getId() == id;
7 };
8 auto element = std::find_if(entries.begin(), entries.end(), p);
9 return element != entries.end() ? (*element).get() : nullptr;
10}
11
12const std::vector<std::shared_ptr<AbstractElement>>* LhaBlock::getEntries() const {
13 return &(this->entries);
14}
15
16std::string LhaBlock::toString() const {
17 std::stringstream stream;
18 stream << "Block " << this->prototype.blockName << ":\n";
19 for (const auto& entry: entries) {
20 stream << entry->toString();
21 }
22
23 return stream.str();
24}
25
26std::shared_ptr<DBNode> LhaBlock::toDBNode() const {
27 DBNode node;
28 std::map<BlockName, DBNode::Value> elts_as_nodes;
29 for (const auto& elt : this->entries) {
30 elts_as_nodes.emplace(elt->getId().to_string(), elt->toDBNode());
31 }
32 if (!this->entries.empty() && this->prototype.globalScale) {
33 double scale = entries[0]->getScale();
34 node.set(scale, "scale");
35 }
36 node.setGroup({this->prototype.blockName}, elts_as_nodes);
37 return std::make_shared<DBNode>(node);
38}
39
40void LhaBlock::addElement(const std::vector<std::string> &line) {
41 auto elt = LhaElementFactory::createElement(this->prototype, line);
42 this->entries.emplace_back(std::move(elt));
43}
44
45void LhaBlock::readData(const std::vector<std::vector<std::string>> &lines) {
46 for (auto line : lines) {
47 if (!line.empty()) {
48 this->addElement(line);
49 }
50 }
51}
52
53bool LhaBlock::hasElement(const LhaID& id) const {
54 for (const auto& e : this->entries) {
55 if (e->getId() == id) return true;
56 }
57 return false;
58}
#define LOG_DEBUG(...)
Macro for logging debug messages.
Definition Logger.h:45
Abstract base class for a single element of an LHA/FLHA block.
void setGroup(const std::vector< BlockName > &keys, const std::map< BlockName, Value > &groupData)
Sets the content of a whole sub-tree from a map of values.
Definition DBNode.cpp:30
void set(T value, Key &&key, Rest &&... rest)
Sets a value in the node using a sequence of keys.
std::string toString() const
Serializes the block and all its entries to a string.
AbstractElement * get(const LhaID &id) const
Retrieves an element by its identifier.
Definition lha_blocks.cpp:3
const std::vector< std::shared_ptr< AbstractElement > > * getEntries() const
Returns a read-only view of all entries in the block.
bool hasElement(const LhaID &id) const
Checks whether an element is present in the block.
void addElement(const std::vector< std::string > &line)
Adds a new element to the block from a line of data.
void readData(const std::vector< std::vector< std::string > > &lines)
Reads data and populates the block with elements from raw lines.
std::shared_ptr< DBNode > toDBNode() const
Converts the block and its entries to a DBNode representation.
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.
Representation of a single LHA/FLHA block and its entries.
Represents an identifier of a LHA element, possibly containing several sub-ids.
Definition LhaID.h:56
BlockName blockName