Skip to content

Commit

Permalink
Merge branch 'improve-pineappl-hpp'
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Jan 30, 2024
2 parents 027c202 + 422d672 commit 746d77b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/object-oriented-cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CXXFLAGS = -std=c++11 -Wall -Wextra -O3
PINEAPPL_DEPS != pkg-config --cflags --libs pineappl_capi
LHAPDF_DEPS != pkg-config --cflags --libs lhapdf

dyaa: dyaa.cpp PineAPPL.hpp
dyaa: dyaa.cpp
$(CXX) $(CXXFLAGS) $< $(PINEAPPL_DEPS) $(LHAPDF_DEPS) -o $@

PHONY: clean
Expand Down
5 changes: 4 additions & 1 deletion pineappl_capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ itertools = "0.10.1"
capi = []

[package.metadata.capi]
min_version = "0.6.16+cargo-0.45"
min_version = "0.9.0"

[package.metadata.capi.install.include]
asset = [{from = "include/PineAPPL.hpp"}]
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* @file PineAPPL.hpp
* @brief object oriented interface to PineAPPL
* @brief Object oriented interface to PineAPPL.
*/
#ifndef PineAPPL_HPP_
#define PineAPPL_HPP_
Expand All @@ -13,16 +12,16 @@
#include <memory>
#include <algorithm>

/** @brief object oriented interface to PineAPPL */
/** @brief Object oriented interface to PineAPPL. */
namespace PineAPPL {

/** @brief Key-value storage for passing optional information during grid
* creation */
* creation. */
struct KeyVal {
/** @brief underlying raw object */
/** @brief Underlying raw object. */
pineappl_keyval *raw;

/** @brief constructor */
/** @brief Constructor. */
KeyVal() : raw(pineappl_keyval_new()) {}

KeyVal(const KeyVal &) = delete;
Expand All @@ -33,10 +32,10 @@ struct KeyVal {

KeyVal &operator=(KeyVal &&) = delete;

/** @brief destructor */
/** @brief Destructor. */
~KeyVal() { pineappl_keyval_delete(this->raw); }

/** @name setter */
/** @name Setter. */
///@{
void set_double(const std::string &key, const double value) const {
pineappl_keyval_set_double(this->raw, key.c_str(), value);
Expand All @@ -52,7 +51,7 @@ struct KeyVal {
}
///@}

/** @name getter */
/** @name Getter. */
///@{
double get_double(const std::string &key) const {
return pineappl_keyval_double(this->raw, key.c_str());
Expand All @@ -69,24 +68,24 @@ struct KeyVal {
///@}
};

/** @brief Entry in luminosity function */
/** @brief Entry in luminosity function. */
struct LumiEntry {
/** @brief first parton id */
/** @brief First parton id. */
std::int32_t pid1;

/** @brief second parton id */
/** @brief Second parton id. */
std::int32_t pid2;

/** @brief relative weight */
/** @brief Relative weight. */
double weight;
};

/** @brief Luminosity function */
/** @brief Luminosity function. */
struct Lumi {
/** @brief underlying raw object */
/** @brief Underlying raw object. */
pineappl_lumi *raw;

/** @brief constructor */
/** @brief Constructor. */
Lumi() : raw(pineappl_lumi_new()) {}

Lumi(const Lumi &) = delete;
Expand All @@ -97,14 +96,14 @@ struct Lumi {

Lumi &operator=(Lumi &&) = delete;

/** @brief destructor */
/** @brief Destructor. */
~Lumi() { pineappl_lumi_delete(this->raw); }

/** @brief number of elements */
/** @brief Number of elements. */
std::size_t count() const { return pineappl_lumi_count(this->raw); }

/**
* @brief add a luminosity function
* @brief Add a luminosity function.
* @param c luminosity function
*/
void add(const std::vector<LumiEntry> &c) const {
Expand Down Expand Up @@ -146,13 +145,14 @@ struct Order {
std::uint32_t logxif;
};

/** @brief The central grid object. */
struct Grid {

/** @brief underlying raw object */
/** @brief Underlying raw object. */
pineappl_grid *raw;

/**
* @brief constructor
* @brief Constructor.
* @param lumi luminosity
* @param orders orders
* @param bin_limits bin limits
Expand Down Expand Up @@ -184,25 +184,25 @@ struct Grid {

Grid &operator=(Grid &&) = delete;

/** @brief destructor */
/** @brief Destructor. */
~Grid() { pineappl_grid_delete(this->raw); }

/**
* @brief Number of orders
* @brief Number of orders.
* @return number of orders
*/
std::size_t order_count() const {
return pineappl_grid_order_count(this->raw);
}

/**
* @brief Number of bins
* @brief Number of bins.
* @return number of bins
*/
std::size_t bin_count() const { return pineappl_grid_bin_count(this->raw); }

/**
* @brief Fill grid for the given parameters
* @brief Fill grid for the given parameters.
* @param x1 first momentum fraction
* @param x2 second momentum fraction
* @param q2 scale
Expand All @@ -218,7 +218,7 @@ struct Grid {
}

/**
* @brief perform a convolution of the grid with PDFs
* @brief Perform a convolution of the grid with PDFs.
* @param pdg_id hadron ID
* @param pdf PDF
* @param xi_ren renormalization scale variation
Expand Down Expand Up @@ -260,15 +260,15 @@ struct Grid {
}

/**
* @brief Write grid to file
* @brief Write grid to file.
* @param filename file name
*/
void write(const std::string &filename) const {
pineappl_grid_write(this->raw, filename.c_str());
}

/**
* @brief Set a metadata entry
* @brief Set a metadata entry.
* @param key key
* @param value value
*/
Expand All @@ -277,7 +277,7 @@ struct Grid {
}

/**
* @brief Get a metadata entry
* @brief Get a metadata entry.
* @param key key
* @return value
*/
Expand All @@ -288,6 +288,22 @@ struct Grid {
pineappl_string_delete(value);
return res;
}

/**
* @brief Scale grid with a number.
* This multiplies all subgrids with the given number.
* @param s factor
*/
void scale(const double s) const {
pineappl_grid_scale(this->raw, s);
}

/**
* @brief Optimizes the grid representation for space efficiency.
*/
void optimize() const {
pineappl_grid_optimize(this->raw);
}
};

} // namespace PineAPPL
Expand Down

0 comments on commit 746d77b

Please sign in to comment.