Skip to content

fix #514, call_data_callbacks after shared the data#548

Open
jmorice91 wants to merge 5 commits intomainfrom
514-delay-data-events-in-multi_expose
Open

fix #514, call_data_callbacks after shared the data#548
jmorice91 wants to merge 5 commits intomainfrom
514-delay-data-events-in-multi_expose

Conversation

@jmorice91
Copy link
Copy Markdown
Contributor

@jmorice91 jmorice91 commented Mar 2, 2025

!!!INSERT YOUR DESCRIPTION HERE!!!

List of things to check before making a PR

Before merging your code, please check the following:

  • you have added a line describing your changes to the Changelog;
  • you have added unit tests for any new or improved feature;
  • In case you updated dependencies, you have checked pdi/docs/CheckList.md
  • you have checked your code format:
    • you have checked that you respect all conventions specified in CONTRIBUTING.md;
    • you have checked that the indentation and formatting conforms to the .clang-format;
    • you have documented with doxygen any new or changed function / class;
  • you have correctly updated the copyright headers:
    • your institution is in the copyright header of every file you (substantially) modified;
    • you have checked that the end-year of the copyright there is the current one;
  • you have updated the AUTHORS file:
    • you have added yourself to the AUTHORS file;
    • if this is a new contribution, you have added it to the AUTHORS file;
  • you have added everything to the user documentation:
    • any new CMake configuration option;
    • any change in the yaml config;
    • any change to the public or plugin API;
    • any other new or changed user-facing feature;
    • any change to the dependencies;
  • you have correctly linked your MR to one or more issues:
    • your MR solves an identified issue;
    • your commit contain the Fix #issue keyword to autoclose the issue when merged.

@jmorice91 jmorice91 linked an issue Mar 2, 2025 that may be closed by this pull request
@jmorice91 jmorice91 marked this pull request as draft March 2, 2025 21:48
@jmorice91 jmorice91 marked this pull request as ready for review March 13, 2025 21:43
@jmorice91 jmorice91 self-assigned this Mar 13, 2025
Copy link
Copy Markdown
Member

@benoitmartin88 benoitmartin88 left a comment

Choose a reason for hiding this comment

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

Great feature to add. Thanks !
Not much is needed to merge this PR.
I think this feature would require a unit test. Could you add this?

Comment thread pdi/include/pdi/data_descriptor.h Outdated
Comment thread pdi/include/pdi/data_descriptor.h Outdated
Comment thread pdi/src/pdi.cxx Outdated
Comment thread pdi/src/pdi.cxx Outdated
Comment thread pdi/src/pdi.cxx Outdated
Comment thread pdi/src/pdi.cxx Outdated
Comment thread pdi/src/data_descriptor_impl.h Outdated
Comment thread pdi/src/pdi.cxx Outdated
Comment thread pdi/src/pdi.cxx
Comment thread pdi/src/pdi.cxx
@jmorice91 jmorice91 marked this pull request as draft April 4, 2025 08:43
@jmorice91 jmorice91 force-pushed the 514-delay-data-events-in-multi_expose branch from 656e28b to 3e1d45f Compare April 4, 2025 09:23
@jmorice91 jmorice91 requested a review from JAuriac April 9, 2025 13:27
@jmorice91 jmorice91 marked this pull request as ready for review April 9, 2025 13:27
Copy link
Copy Markdown
Member

@benoitmartin88 benoitmartin88 left a comment

Choose a reason for hiding this comment

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

Almost ready to merge.
I do have a few questions that need answering concerning error handling, potentially superfluous functions and writing tests in C++.

Comment thread pdi/src/data_descriptor_impl.cxx Outdated
Comment thread pdi/src/data_descriptor_impl.h Outdated
Comment thread pdi/src/pdi.cxx Outdated
Comment thread tests/test_06_user_code_multi_expose.cxx
@jmorice91 jmorice91 marked this pull request as draft May 12, 2025 09:07
@jmorice91 jmorice91 force-pushed the 514-delay-data-events-in-multi_expose branch from f542e39 to 6806742 Compare May 12, 2025 09:18
@jmorice91 jmorice91 requested a review from benoitmartin88 May 12, 2025 09:45
@jmorice91 jmorice91 marked this pull request as ready for review May 12, 2025 09:46
Copy link
Copy Markdown
Member

@benoitmartin88 benoitmartin88 left a comment

Choose a reason for hiding this comment

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

I think this is almost ready to merge.
Could you make sure the indent and spacing of the modified files is correct ?
Thanks !

Comment thread pdi/src/data_descriptor_impl.cxx Outdated
Comment thread pdi/src/data_descriptor_impl.cxx Outdated
Yushan-Wang
Yushan-Wang previously approved these changes Jun 4, 2025
@jmorice91
Copy link
Copy Markdown
Contributor Author

I think this is almost ready to merge. Could you make sure the indent and spacing of the modified files is correct ? Thanks !

Is it normal that the action indent doesn't catch that?

@jmorice91 jmorice91 requested a review from benoitmartin88 June 5, 2025 10:12
Copy link
Copy Markdown
Member

@Yushan-Wang Yushan-Wang left a comment

Choose a reason for hiding this comment

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

Ready to merge

@Yushan-Wang
Copy link
Copy Markdown
Member

@jbigot Could you review this PR please?

Copy link
Copy Markdown
Member

@jbigot jbigot left a comment

Choose a reason for hiding this comment

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

This is a great submission! My main comment is about moving Var_to_reclaim of the provider side instead of expecting each user to implement it. Overall this is really nice though!

Comment thread pdi/include/pdi/data_descriptor.h Outdated
Comment thread pdi/include/pdi/data_descriptor.h Outdated
Comment thread pdi/src/pdi.cxx Outdated
Yushan-Wang
Yushan-Wang previously approved these changes Sep 12, 2025
@jbigot
Copy link
Copy Markdown
Member

jbigot commented Oct 28, 2025

What's the status for this one?

@jmorice91 jmorice91 force-pushed the 514-delay-data-events-in-multi_expose branch from c7b95b9 to b433600 Compare March 31, 2026 09:16
@jmorice91 jmorice91 marked this pull request as ready for review March 31, 2026 10:40
@jmorice91 jmorice91 requested review from Yushan-Wang and jbigot March 31, 2026 10:40
Comment thread pdi/src/data_descriptor_impl.cxx Outdated
Comment thread pdi/src/data_descriptor_impl.cxx
Comment thread pdi/src/pdi.cxx
Comment thread pdi/include/pdi/pdi_fwd.h Outdated
Comment thread pdi/src/delayed_data_callbacks.cxx Outdated
Comment thread pdi/src/pdi.cxx Outdated
Comment thread pdi/tests/PDI_callbacks.cxx Outdated
Comment thread pdi/tests/PDI_callbacks.cxx Outdated
@jmorice91 jmorice91 marked this pull request as draft April 8, 2026 14:46
@jmorice91 jmorice91 marked this pull request as ready for review April 9, 2026 11:59
Copy link
Copy Markdown
Member

@Yushan-Wang Yushan-Wang left a comment

Choose a reason for hiding this comment

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

Looks good to me!
However, I have difficulties understanding the test.
Could you please add a test with hdf5, where the name of the file is a variable?
Before, we had to expose first the filename_size, then the filename. With your change, the order of the expose is then irrelevant.
Or exposing a vector who's size is also a variable?

@jbigot
Copy link
Copy Markdown
Member

jbigot commented Apr 15, 2026

For Multiple_error, you could base your work on top of https://github.com/pdidev/pdi/tree/improved_errmsg
I'm waiting for the formatting & renaming of errors to be merged before I make a PR

@jmorice91 jmorice91 marked this pull request as draft April 16, 2026 07:22
@jbigot jbigot force-pushed the main branch 7 times, most recently from 41fed24 to b9ebda1 Compare April 24, 2026 09:13
add Delayed_data_callbacks class

remove cout

Adding some test how work delayed_data_callbacks class

fix comment

fix indent and word
@jmorice91 jmorice91 force-pushed the 514-delay-data-events-in-multi_expose branch from 0307623 to 6751514 Compare April 27, 2026 09:50
@jbigot jbigot marked this pull request as ready for review April 28, 2026 13:16
Comment thread pdi/include/pdi/data_descriptor.h Outdated
Comment thread pdi/include/pdi/data_descriptor.h Outdated
std::vector<std::string> m_datanames;

/// The context where the list of data is a part of
Global_context& m_context;
Copy link
Copy Markdown
Contributor

@JAuriac JAuriac Apr 30, 2026

Choose a reason for hiding this comment

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

Maybe shouldn't use a Global_context directly, and should remove the direct include to global_context.h, to go through Context instead with virtuals

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. We must not use Global_context directly. This variables is not defined in the "pdi/include"
We have three options:

    1. Use instead the class Context as you propose (implemented and tested but not commited yet).
    1. Do a virtual class Delayed_data_callbacks and put the implementation in the src as Data_descriptor
      and use Global_context in implementation
    1. Do a virtual class Delayed_data_callbacks and put the implementation in the src as Data_descriptor
      and use Context in the implementation

Comment thread pdi/src/delayed_data_callbacks.cxx Outdated
void Delayed_data_callbacks::add_dataname(const std::string& name)
{
// Comment: In case of a multi_expose, if the data is defined twice then the callback "on_data" are called twice also in PDI v1.10
// Therefore, we need to add the name to have the same behaviour.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the "same behaviour" here ? We need this emplace_back to reproduce the behaviour where we overwrite the data definition that is already available ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you call this function,

PDI_multi_expose("my_test", "pdi_var1", &var1, PDI_OUT, "pdi_var1", &var1, PDI_OUT, NULL);

The callback on data "pdi_var1" is called two times in pdi v1.10.
For example, if the callback corresponds to the user_code function my_func, we call two times the function my_func.

Comment thread pdi/src/pdi.cxx
Comment thread pdi/src/pdi.cxx
Comment thread pdi/tests/PDI_delayed_data_callbacks.cxx Outdated
Comment thread plugins/decl_hdf5/tests/decl_hdf5_tests.cxx Outdated

m_datanames.clear();

rethrow_with_context(trigger_data_errors, "`{}' error(s) while triggering data callbacks, ", number_of_elements);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may actually represent trigger_data_errors.size() (is it intentional ?), as if we have 3 triggers and only 1 throws, we get a report of 3 errors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here, number_of_elements correspond to trigger_data_errors.size().

// An exception is throwing before. Print simple message to avoid std::terminate.
m_context.logger().error("Error in the destructor of Delayed_data_callbacks, {}", e.what());
} else {
m_context.logger().info("{}", "Error in the destructor of Delayed_data_callbacks");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could use e.what() in the logger info branch ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I do that, in the final message, I have two times e.what()

const int var1 = 3;
const int var2 = 11;

PDI_multi_expose("my_test", "pdi_var1", &var1, PDI_OUT, "pdi_var1", &var2, PDI_OUT, NULL);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is writing over const variables intended here (technically ok because not constexpr) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, indeed I need to remove the const here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delay data events in multi_expose to when the last data is exposed

5 participants