Skip to content
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

Energy load file only when necessary #331

Closed
wants to merge 1 commit into from
Closed

Conversation

fannyzotter
Copy link
Collaborator

put an if condition for energyType Files
would that work for you?

@fannyzotter fannyzotter requested a review from Atraxus September 24, 2024 14:23
@fannyzotter fannyzotter closed this Oct 7, 2024
@fannyzotter fannyzotter reopened this Oct 8, 2024
Copy link
Collaborator

@Atraxus Atraxus left a comment

Choose a reason for hiding this comment

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

This needs some deeper restructuring to correctly handle the exceptional case of getting passed an incorrect DatFile path in the rml file. Depending on the rework, the case where the tracer is already running and the DatFile is missing needs to be handled still (currently not handled).

try
{
std::ifstream s(filename);
RAYX_VERB << filename;
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Reading in file: " << filename

return true;

} catch (const std::exception& e) {
RAYX_D_ERR << "Exception caught while loading DatFile \"" << filename << "\": " << e.what();
Copy link
Collaborator

Choose a reason for hiding this comment

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

RAYX_VERB << "Dat-File with name: " .... << " could not be parsed."

Copy link
Collaborator

Choose a reason for hiding this comment

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

Exiting here is problematic, takes agency away from the caller of the function, even if it's in debug. RAYX_D_ERR should probably be an assertion in general now that we do not use glsl anymore

Copy link
Collaborator

Choose a reason for hiding this comment

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

Reviewing the other code I believe a boolean return value cannot handle this exceptional behavior. The stack is too deep to use return values and an exception should be thrown.

Copy link
Collaborator

Choose a reason for hiding this comment

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

On further review I believe that lazy loading the energy file during the compile call creates quite a few problems. A broken DatFile path in the rml file should already be found (but not handled) during the importBeamline(...) function call. rayx could then exit with the error message, that the file could not be found at the given path or it could not be parsed. rayx-ui could prompt the user with a pop-up with a similar/the same error message


if (energyDistributionType == EnergyDistributionType::File) {
std::string filename = m_elementParameters["photonEnergyDistributionFile"].as_string();

std::cout << std::filesystem::current_path() << std::endl;
DatFile df;
DatFile::load(filename, &df);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Result returned by DatFile::load is not handled here. What should getEnergyDistribution return when the path cannot be parsed. The stack seems to be quite deep at this point, so it's hard to imagine that return values can handle this. My first impression here would be to use an exception

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