Skip to content

Initial version of gaus_hit_finder example#5

Open
wddgit wants to merge 1 commit intoFramework-R-D:mainfrom
wddgit:migrateGausHitFinder
Open

Initial version of gaus_hit_finder example#5
wddgit wants to merge 1 commit intoFramework-R-D:mainfrom
wddgit:migrateGausHitFinder

Conversation

@wddgit
Copy link

@wddgit wddgit commented Mar 6, 2026

This is an initial version of the result of the migration of the module defined in GausHitFinder_module.cc in the larreco repository of LArSoft from the existing version designed to run under the art framework to a version that will run under the phlex framework. The purpose of this code is to serve as an example for future migrations and also to be used in prototype testing. It is not intended to be used for reconstruction of data for use in physics analysis. That code should be placed in some other repository and maintained by other groups.

See the README.md (best viewed in GitHub) for more information.

@wddgit
Copy link
Author

wddgit commented Mar 6, 2026

This was from Beojan on SLACK.

What level of review are you looking for here?

For instance while the file you're printing has a CSV-style header, it isn't a CSV because it has a newline after each field. Is that to match a file produced by the existing GausHitFinder?

and

I'd suggest using fmt::print instead of iostreams, which can really clean up that code.

@wddgit
Copy link
Author

wddgit commented Mar 6, 2026

And my reply. Thanks. Beojan. I will change it to .txt and use fmt::print.

@wddgit wddgit force-pushed the migrateGausHitFinder branch from 9f38888 to b83228e Compare March 9, 2026 16:03
@wddgit
Copy link
Author

wddgit commented Mar 9, 2026

I force pushed a modification. The most significant part of implements Beojan's suggestions. It changes from using ofstream to fmt::print to print out the hits to be used in a comparison with the output of the existing LArSoft version of GausHitFinder. Also changes the suffix of that file to ".txt". There is some additional cleanup of some minor things also (making sure there is a newline at the end of files, fix some files with omitted header guards, improve a few comments, shorten some excessively long lines, order of includes improved).

@wddgit
Copy link
Author

wddgit commented Mar 9, 2026

FYI @beojan Just to make sure you are receiving comments on this PR.

Copy link
Member

@knoepfel knoepfel left a comment

Choose a reason for hiding this comment

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

Thanks, @wddgit, for the PR. Some comments for your consideration below.

std::ofstream out(filename, std::ios::binary);
if (!out) {
throw std::runtime_error("Failed to open file for writing: " + filename);
return false;
Copy link
Member

Choose a reason for hiding this comment

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

This return false; will not execute. Suggest removing

std::ifstream in(filename, std::ios::binary);
if (!in) {
throw std::runtime_error("Failed to open file for reading: " + filename);
return false;
Copy link
Member

Choose a reason for hiding this comment

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

This return false; will not execute. Suggest removing


void print_hits_to_file(std::vector<recob::Hit> const& hits,
std::string const& filename) {
std::FILE* file = std::fopen(filename.c_str(), "w");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::FILE* file = std::fopen(filename.c_str(), "w");
std::ofstream file{filename};

std::FILE* file = std::fopen(filename.c_str(), "w");
if (!file) {
throw std::runtime_error("Failed to open file for writing: " + filename);
return;
Copy link
Member

Choose a reason for hiding this comment

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

Suggest removing this return; statement as it will not be executed.

// hit.SignalType()
// hit.WireID()
}
std::fclose(file);
Copy link
Member

Choose a reason for hiding this comment

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

The explicit std::fclose(...) can be removed if using the std::ofstream approach above.

Comment on lines +61 to +62
bool read_wires_from_file(std::string const& filename,
std::vector<recob::Wire>& wires) {
Copy link
Member

@knoepfel knoepfel Mar 23, 2026

Choose a reason for hiding this comment

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

Instead of passing in an output argument, I suggest changing the interface:

std::optional<std::vector<recob::Wire>> read_wires_from_file(std::string const& filename)
{
  std::vector<recob::Wire> wires;
  ...
  return wires;
}

and then early returns (like return false;) are replaced with return std::nullopt;

Comment on lines +132 to +133
in.close();
return in.good();
Copy link
Member

Choose a reason for hiding this comment

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

See above suggestions, such that:

Suggested change
in.close();
return in.good();
return wires;

Comment on lines +32 to +37
std::vector<recob::Wire> wires;
bool status = read_wires_from_file(filename, wires);
if (!status) {
throw std::runtime_error("Failure while reading from file: " + filename);
}
return wires;
Copy link
Member

Choose a reason for hiding this comment

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

Given the above changes, this would change to:

Suggested change
std::vector<recob::Wire> wires;
bool status = read_wires_from_file(filename, wires);
if (!status) {
throw std::runtime_error("Failure while reading from file: " + filename);
}
return wires;
if (auto wires = read_wires_from_file(filename)) {
return *wires;
}
throw std::runtime_error("Failure while reading from file: " + filename);

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