Skip to content

Add action builder#203

Open
gonzaponte wants to merge 3 commits into
jacg:masterfrom
gonzaponte:actions
Open

Add action builder#203
gonzaponte wants to merge 3 commits into
jacg:masterfrom
gonzaponte:actions

Conversation

@gonzaponte
Copy link
Copy Markdown
Collaborator

A partial implementation of #30. The idea is simple: create a more comfortable interface for setting actions. A complete configuration would look like:

n4::action_builder{a_generator}
  .run_begin          (...)
  .run_end            (...)
  .event_begin        (...)
  .event_end          (...)
  .stacking_classify  (...)
  .stacking_next_stage(...)
  .stacking_next_event(...)
  .tracking_pre       (...)
  .tracking_post      (...)
  .stepping           (...)
  .done               ();

But all of these actions are optional.

In this implementation, it was quite natural to include another perk: the possibility of combining multiple actions of the same kind. In my experience, this can be quite useful. It allows the user to create small, well-defined functions that do something very specific, very clearly. Giving these functions meaningful names can result in a self-explanatory workflow. For instance:

n4::action_builder{isotropic_2614keV_gammas_from_origin}
  .event_begin (print_event_number)
  .event_begin (initialize_something)
  .tracking_pre(count_compton)
  .tracking_pre(count_pair_production)
  .tracking_pre(count_photoelectric)
  .tracking_pre(kill_positrons_because_they_are_too_positive)
  .etc

The current implementation does not allow for classes to be passed to this builder, but I believe it is feasible to implement a version that does. In any case, I first wanted to hear your thoughts (@jacg) on the current approach, if you have any.

@jacg
Copy link
Copy Markdown
Owner

jacg commented Dec 10, 2025

You've caught me in a bad week ... or two. I won't be able to give this the attention it deserves for a while. Is it urgent?

@gonzaponte
Copy link
Copy Markdown
Collaborator Author

Not at all.

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.

2 participants