-
Notifications
You must be signed in to change notification settings - Fork 126
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
Fix bug in LoadNGEM where Min/MaxEventsPerFrame were not respected #38564
Fix bug in LoadNGEM where Min/MaxEventsPerFrame were not respected #38564
Conversation
In preparation for next frame
The condition ++numWordsSkipped is always true, but it will only get evaluated if !file.seekg(SKIP_WORD_SIZE, std::ios_base::cur).eof() is true which will indicate a word being skipped, so this does actually have a function!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working well, the correct counts are now shown in the output. Just a quick question about one of the changes from the CppCheck suppressions.
} while (!event.generic.check() && !file.seekg(SKIP_WORD_SIZE, std::ios_base::cur).eof() && ++numWordsSkipped); | ||
} while (!event.generic.check() && !file.seekg(SKIP_WORD_SIZE, std::ios_base::cur).eof()); | ||
if (file.eof()) { | ||
++numWordsSkipped; | ||
break; // we have either not read an event, or only read part of one | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these are equivalent. The numWordsSkipped
variable indicates the number of words (multiples of 4 bytes) that were skipped at the beginning of the file before the algorithm found a valid event. I think this will just mark a skipped word whenever the end of a file is reached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep sorry, I think I'm confused by this
!file.seekg(SKIP_WORD_SIZE, std::ios_base::cur).eof()
would this terminate the loop if the current position in the file is within SKIP_WROD_SIZE
of the end of the file?
i.e. would the do/while
loop end before eof?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at the docs for seekg
and am none the wiser! Not had to do much file IO in C++!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So its main check is if it was able to load an event into the EventUnion
object of some number of words (4 bytes) using event.generic.check()
. If it could do that, it exits the loop. If it couldn't create a valid event, it checks if it can skip 1 word forward file.seekg(SKIP_WORD_SIZE, std::ios_base::cur).eof()
and exits the loop if it would be unable to progress because you reached the end of the file. Otherwise, it increments the number of skipped words and then restarts the loop to try to create an event object from the next word. It repeats this until it is able to create an valid event object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah OK I see thanks, so the counter ++numWordsSkipped
represents the number of times file.seekg(SKIP_WORD_SIZE, std::ios_base::cur)
has been run without reaching the end of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think my last commit is now equivalent - seems a bit clunky (maybe could be improved) - but also happy to revert and keep the suppression. whatever you prefer!
af088c8
to
77aae45
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks good and this is probably easier to read than the original style, just a nitpick (sorry) on the variable naming:
bool is_event_invalid = true; | ||
bool is_not_eof_after_skip = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These want to be in camelCase as they're C++ variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, sorry too much time with python! Force pushed to fix this
77aae45
to
45eeeac
Compare
There was a problem hiding this 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 now. Min/Max now properly working as expected.
This is a squashed version of mantidproject#38564 Clear events in frame if not good frame In preparation for next frame Update cpp check suppression The condition ++numWordsSkipped is always true, but it will only get evaluated if !file.seekg(SKIP_WORD_SIZE, std::ios_base::cur).eof() is true which will indicate a word being skipped, so this does actually have a function! Update test to assert no events if min=max=0 Add release note Fix cpp check supression
This is a squashed version of mantidproject#38564 Clear events in frame if not good frame In preparation for next frame Update cpp check suppression The condition ++numWordsSkipped is always true, but it will only get evaluated if !file.seekg(SKIP_WORD_SIZE, std::ios_base::cur).eof() is true which will indicate a word being skipped, so this does actually have a function! Update test to assert no events if min=max=0 Add release note Fix cpp check supression
Description of work
Added loop to clear events in frame if the current frame is not good (i.e. number of events outside Min/Max limits set) in preparation for next frame (don't know if that is the best way to do it)..
The issue was here
mantid/Framework/DataHandling/src/LoadNGEM.cpp
Lines 74 to 88 in 22bed21
If the statement on L74 is false then
eventsInFrame
doesn't get cleared - such that the sum over alleventsInFrame[i].getNumberEvents()
is not equal toeventCountInFrame
Fixes #38558
Report to: draspi
To test:
(1) Follow instructions on the issue
(2) For
MinEventsPerFrame=0
andMaxEventsPerFrame=0
the workspace should have no counts (ws.getNumberEvents() = 0
)(3) If
MinEventsPerFrame
andMaxEventsPerFrame
are not set then the resulting figure should look like the one in the issue.Reviewer
Please comment on the points listed below (full description).
Your comments will be used as part of the gatekeeper process, so please comment clearly on what you have checked during your review. If changes are made to the PR during the review process then your final comment will be the most important for gatekeepers. In this comment you should make it clear why any earlier review is still valid, or confirm that all requested changes have been addressed.
Code Review
Functional Tests
Does everything look good? Mark the review as Approve. A member of
@mantidproject/gatekeepers
will take care of it.Gatekeeper
If you need to request changes to a PR then please add a comment and set the review status to "Request changes". This will stop the PR from showing up in the list for other gatekeepers.