From 5926f032dd62f5ee764a700b4dba6327d24b7103 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Wed, 6 Dec 2023 11:53:06 +0200 Subject: [PATCH 1/4] Expose scale and optimize to OO C++ --- examples/object-oriented-cpp/PineAPPL.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/object-oriented-cpp/PineAPPL.hpp b/examples/object-oriented-cpp/PineAPPL.hpp index f27dbb9f..6b5d0f14 100644 --- a/examples/object-oriented-cpp/PineAPPL.hpp +++ b/examples/object-oriented-cpp/PineAPPL.hpp @@ -146,6 +146,7 @@ struct Order { std::uint32_t logxif; }; +/** @brief The central grid object */ struct Grid { /** @brief underlying raw object */ @@ -288,6 +289,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 From e72a5d6de1e79086f9f36e9a697235f5aa4ef986 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 30 Jan 2024 15:37:41 +0200 Subject: [PATCH 2/4] Make OO docs consistent --- examples/object-oriented-cpp/PineAPPL.hpp | 61 +++++++++++------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/examples/object-oriented-cpp/PineAPPL.hpp b/examples/object-oriented-cpp/PineAPPL.hpp index 6b5d0f14..56123711 100644 --- a/examples/object-oriented-cpp/PineAPPL.hpp +++ b/examples/object-oriented-cpp/PineAPPL.hpp @@ -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_ @@ -13,16 +12,16 @@ #include #include -/** @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; @@ -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); @@ -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()); @@ -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; @@ -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 &c) const { @@ -146,14 +145,14 @@ struct Order { std::uint32_t logxif; }; -/** @brief The central grid object */ +/** @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 @@ -185,11 +184,11 @@ 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 { @@ -197,13 +196,13 @@ struct Grid { } /** - * @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 @@ -219,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 @@ -261,7 +260,7 @@ struct Grid { } /** - * @brief Write grid to file + * @brief Write grid to file. * @param filename file name */ void write(const std::string &filename) const { @@ -269,7 +268,7 @@ struct Grid { } /** - * @brief Set a metadata entry + * @brief Set a metadata entry. * @param key key * @param value value */ @@ -278,7 +277,7 @@ struct Grid { } /** - * @brief Get a metadata entry + * @brief Get a metadata entry. * @param key key * @return value */ @@ -291,7 +290,7 @@ struct Grid { } /** - * @brief Scale grid with a number + * @brief Scale grid with a number. * This multiplies all subgrids with the given number. * @param s factor */ From d1ee9868f39df9320e07e49f61f7a19734a7e989 Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Tue, 30 Jan 2024 14:47:51 +0100 Subject: [PATCH 3/4] Fix broken codecov action --- .github/workflows/capi.yaml | 3 ++- .github/workflows/rust.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/capi.yaml b/.github/workflows/capi.yaml index a1f3f972..fb68e879 100644 --- a/.github/workflows/capi.yaml +++ b/.github/workflows/capi.yaml @@ -52,7 +52,8 @@ jobs: --format lcov > lcov.info - name: Upload to codecov.io - uses: codecov/codecov-action@v3 + # version 3.1.5 upgrades to Node 20 (https://github.com/codecov/codecov-action/issues/1230), which breaks inside our container + uses: codecov/codecov-action@v3.1.4 with: token: ${{secrets.CODECOV_TOKEN}} flags: capi diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d2dd409e..8e84db28 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -82,7 +82,8 @@ jobs: --format lcov > lcov.info - name: Upload to codecov.io - uses: codecov/codecov-action@v3 + # version 3.1.5 upgrades to Node 20 (https://github.com/codecov/codecov-action/issues/1230), which breaks inside our container + uses: codecov/codecov-action@v3.1.4 with: token: ${{secrets.CODECOV_TOKEN}} flags: rust From 422d6723ea3d1ee57f2db3f386ea40332f9c97fe Mon Sep 17 00:00:00 2001 From: Christopher Schwan Date: Tue, 30 Jan 2024 14:50:40 +0100 Subject: [PATCH 4/4] Move `PineAPPL.hpp` into `pineappl_capi` and install it --- examples/object-oriented-cpp/Makefile | 2 +- pineappl_capi/Cargo.toml | 5 ++++- .../include}/PineAPPL.hpp | 0 3 files changed, 5 insertions(+), 2 deletions(-) rename {examples/object-oriented-cpp => pineappl_capi/include}/PineAPPL.hpp (100%) diff --git a/examples/object-oriented-cpp/Makefile b/examples/object-oriented-cpp/Makefile index af948c23..bbcd2ffb 100644 --- a/examples/object-oriented-cpp/Makefile +++ b/examples/object-oriented-cpp/Makefile @@ -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 diff --git a/pineappl_capi/Cargo.toml b/pineappl_capi/Cargo.toml index 485d4deb..2787080d 100644 --- a/pineappl_capi/Cargo.toml +++ b/pineappl_capi/Cargo.toml @@ -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"}] diff --git a/examples/object-oriented-cpp/PineAPPL.hpp b/pineappl_capi/include/PineAPPL.hpp similarity index 100% rename from examples/object-oriented-cpp/PineAPPL.hpp rename to pineappl_capi/include/PineAPPL.hpp