-
Notifications
You must be signed in to change notification settings - Fork 499
Introduced 2d arrays in Variant #5132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a005b19
Introduced 2d arrays in Variant
aalkin d2389e7
Rename matrix to Array2D
aalkin 58b97c2
fixup! Rename matrix to Array2D
aalkin c4f9a5a
fix type string name check for ROOT-serialized 2d array
aalkin 5567f25
fixup! fix type string name check for ROOT-serialized 2d array
aalkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Copyright CERN and copyright holders of ALICE O2. This software is | ||
| // distributed under the terms of the GNU General Public License v3 (GPL | ||
| // Version 3), copied verbatim in the file "COPYING". | ||
| // | ||
| // See http://alice-o2.web.cern.ch/license for full licensing information. | ||
| // | ||
| // In applying this license CERN does not waive the privileges and immunities | ||
| // granted to it by virtue of its status as an Intergovernmental Organization | ||
| // or submit itself to any jurisdiction. | ||
| #ifndef FRAMEWORK_ARRAY2D_H | ||
| #define FRAMEWORK_ARRAY2D_H | ||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| namespace o2::framework | ||
| { | ||
| // matrix-like wrapper for std::vector | ||
| // has no range checks | ||
| template <typename T> | ||
| struct Array2D { | ||
| using element_t = T; | ||
|
|
||
| Array2D(T const* data_, uint32_t r, uint32_t c) | ||
| : rows{r}, cols{c} | ||
| { | ||
| data = new T[rows * cols]; | ||
| for (auto i = 0U; i < rows; ++i) { | ||
| for (auto j = 0U; j < cols; ++j) { | ||
| data[i * cols + j] = *(data_ + (i * cols + j)); | ||
| } | ||
| } | ||
| } | ||
| Array2D(std::vector<T> data_, uint32_t r, uint32_t c) | ||
| : rows{r}, cols{c} | ||
| { | ||
| data = new T[rows * cols]; | ||
| for (auto i = 0U; i < rows; ++i) { | ||
| for (auto j = 0U; j < cols; ++j) { | ||
| data[i * cols + j] = data_[i * cols + j]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Array2D(Array2D<T> const& other) | ||
| : rows{other.rows}, | ||
| cols{other.cols} | ||
| { | ||
| data = new T[rows * cols]; | ||
| for (auto i = 0U; i < rows; ++i) { | ||
| for (auto j = 0U; j < cols; ++j) { | ||
| data[i * cols + j] = *(other.data + (i * cols + j)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Array2D(Array2D<T>&& other) | ||
| : rows{other.rows}, | ||
| cols{other.cols} | ||
| { | ||
| data = other.data; | ||
| other.data = nullptr; | ||
| other.rows = 0; | ||
| other.cols = 0; | ||
| } | ||
|
|
||
| Array2D& operator=(Array2D<T> const& other) | ||
| { | ||
| this->rows = other.rows; | ||
| this->cols = other.cols; | ||
| data = new T[rows * cols]; | ||
| for (auto i = 0U; i < rows; ++i) { | ||
| for (auto j = 0U; j < cols; ++j) { | ||
| data[i * cols + j] = *(other.data + (i * cols + j)); | ||
| } | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| Array2D& operator=(Array2D<T>&& other) | ||
| { | ||
| this->rows = other.rows; | ||
| this->cols = other.cols; | ||
| data = other.data; | ||
| other.data = nullptr; | ||
| other.rows = 0; | ||
| other.cols = 0; | ||
| return *this; | ||
| } | ||
|
|
||
| ~Array2D() | ||
| { | ||
| if (data != nullptr) { | ||
| delete[] data; | ||
| } | ||
| } | ||
|
|
||
| T operator()(uint32_t y, uint32_t x) const | ||
| { | ||
| return data[y * cols + x]; | ||
| } | ||
| T* operator[](uint32_t y) const | ||
| { | ||
| return data + y * cols; | ||
| } | ||
|
|
||
| T* data = nullptr; | ||
| uint32_t rows = 0; | ||
| uint32_t cols = 0; | ||
| }; | ||
| } // namespace o2::framework | ||
|
|
||
| #endif // FRAMEWORK_ARRAY2D_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ struct ConfigParamsHelper { | |
| /// all options which are found in the vetos are skipped | ||
| static bool dpl2BoostOptions(const std::vector<ConfigParamSpec>& spec, | ||
| options_description& options, | ||
| options_description vetos = options_description()); | ||
| boost::program_options::options_description vetos = options_description()); | ||
|
|
||
| /// populate boost program options for a complete workflow | ||
| template <typename ContainerType> | ||
|
|
@@ -119,7 +119,10 @@ struct ConfigParamsHelper { | |
| V == VariantType::ArrayFloat || | ||
| V == VariantType::ArrayDouble || | ||
| V == VariantType::ArrayBool || | ||
| V == VariantType::ArrayString) { | ||
| V == VariantType::ArrayString || | ||
| V == VariantType::MatrixInt || | ||
| V == VariantType::MatrixFloat || | ||
| V == VariantType::MatrixDouble) { | ||
|
Comment on lines
+123
to
+125
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably be Array2DInt, etc. |
||
| auto value = boost::program_options::value<std::string>(); | ||
| value = value->default_value(spec.defaultValue.asString()); | ||
| if constexpr (V != VariantType::String) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be
extractArray2D, fine for now.