Skip to content

DPL: streamline DataAllocator::make - #1970

Merged
ktf merged 2 commits into
AliceO2Group:devfrom
ktf:streamline-make
Jul 15, 2019
Merged

DPL: streamline DataAllocator::make#1970
ktf merged 2 commits into
AliceO2Group:devfrom
ktf:streamline-make

Conversation

@ktf

@ktf ktf commented May 14, 2019

Copy link
Copy Markdown
Member

No description provided.

@ktf
ktf requested a review from matthiasrichter May 14, 2019 12:50
@ktf

ktf commented May 14, 2019

Copy link
Copy Markdown
Member Author

@matthiasrichter this is how I would streamline the DataAllocator::make API using C++17 if constexpr in place of all the std::enable_if. It would also have the advantage that we can probably separate the various implementations (boost, arrow, ROOT) in different headerfiles with a bit more gymnastic.

This is WIP because there is something which needs to change in order to be able to use auto& everywhere (right now it would segfault for one of the cases) and because I think it can be simplifies even further.

@matthiasrichter matthiasrichter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very nice, I have nothing to add for the moment.

@matthiasrichter

Copy link
Copy Markdown
Collaborator

@ktf, think we should push this forward. I have rebased the branch and included the patch for running also the workflow unit tests (PR #2140).

What is needed to be changed to get this PR ready for merging?

@ktf

ktf commented Jun 27, 2019

Copy link
Copy Markdown
Member Author

As discussed privately, there is an issue with references, IIRC. We should resolve that before merging this.

@matthiasrichter

Copy link
Copy Markdown
Collaborator

I think we also see it in the CI, will try to have a look

.../Framework/Core/include/Framework/DataAllocator.h: In instantiation of 'auto& o2::framework::DataAllocator::make(const o2::framework::Output&, Args ...) [with T = arrow::ipc::RecordBatchWriter; Args = {std::shared_ptr<arrow::Schema>}]':
.../Framework/Core/src/AODReaderHelpers.cxx:209:110:   required from here
.../Framework/Core/include/Framework/DataAllocator.h:145:58: error: reference to local variable 'writer' returned [-Werror=return-local-addr]
           std::shared_ptr<arrow::ipc::RecordBatchWriter> writer;
                                                          ^~~~~~

@ktf

ktf commented Jun 27, 2019

Copy link
Copy Markdown
Member Author

yes, exactly.

@matthiasrichter matthiasrichter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using decltype(auto) allows to deduce from the expression whether to return reference or value.

This supports the current case for the arrow::ipc::RecordBatchWriter and will enable to return unique_ptr or similar objects by move in the future.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ktf that seems to do the trick

Using `decltype(auto)` to deduce the return type from the expression. It
will be lvalue reference for the framework-owned objects. Instances of local
variables like shared_ptr will be returned by value/move/return value optimization.

Not all branches of allocator API function `make` will return references to
objects owned by an allocator context. E.g. shared_ptr objects are returned
by return value optimization. Currently there is one use case for the arrow
schema, but similar arguments apply if unique_ptr with custom dealloator will
be used in the future to control the scope of the objects in the code and allow
immediate sending once an object goes out of scope
@ktf ktf changed the title [WIP] DPL: streamline DataAllocator::make DPL: streamline DataAllocator::make Jul 15, 2019
@ktf

ktf commented Jul 15, 2019

Copy link
Copy Markdown
Member Author

Look good to me. Thanks. I am merging this.

@ktf
ktf merged commit 6025607 into AliceO2Group:dev Jul 15, 2019
@ktf
ktf deleted the streamline-make branch July 15, 2019 07:24
MichaelLettrich pushed a commit that referenced this pull request Jul 24, 2019
This uses C++ if constexpr to simplify and unify the `DataAllocator::make` logic, hopefully resulting in more readable code. Notice how it uses `decltype(auto)` to deduce the return type from the expression. The original commit 6b82ff3 has an exhaustive description of why this is needed.
knopers8 pushed a commit to knopers8/AliceO2 that referenced this pull request Oct 23, 2019
This uses C++ if constexpr to simplify and unify the `DataAllocator::make` logic, hopefully resulting in more readable code. Notice how it uses `decltype(auto)` to deduce the return type from the expression. The original commit 6b82ff3 has an exhaustive description of why this is needed.
carlos-soncco pushed a commit to carlos-soncco/AliceO2 that referenced this pull request Oct 28, 2019
This uses C++ if constexpr to simplify and unify the `DataAllocator::make` logic, hopefully resulting in more readable code. Notice how it uses `decltype(auto)` to deduce the return type from the expression. The original commit 6b82ff3 has an exhaustive description of why this is needed.
EmilGorm pushed a commit to EmilGorm/AliceO2 that referenced this pull request Apr 15, 2023
…eO2Group#1970)

* Added gamma trigger

* Added gamma, allows qa to only consider jets in EMCAL

Added max spectra

---------

Co-authored-by: Gijs van Weelden <g.van.weelden@nikhef.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants