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

Update reader read methods to include pre/post read checks #86

Closed
drewejohnson opened this issue Feb 6, 2018 · 5 comments
Closed

Update reader read methods to include pre/post read checks #86

drewejohnson opened this issue Feb 6, 2018 · 5 comments

Comments

@drewejohnson
Copy link
Collaborator

Implement reader-specific methods for inspections before and after reading. Pre-checks could include ensuring the file exists, simple validation that the file is of the correct type (e.g. not reading a detector file with a depletion reader), or counting the number of time steps present in the results file #7. Post-read checks could include verifying that data was indeed stored. If nothing is stored, Exceptions should be raised, perhaps a new one like EmptyReader that inherits from SerpentToolsException

In order to accomplish this, I propose refactoring the public read methods for all readers to private _read methods. The base reader will contain the public read method, and seek for precheck and postcheck methods specific to each file type. These do not have to be overwritten for each reader.

Implementation Suggestion

class BaseReader(object):

    def read(self):
        self._precheck()
        # maybe some debug/info statements
        self._read()
        self._postcheck()
    def _precheck():
         pass
    def _postcheck():
        pass
    def _read():
        raise NotImplementedError

class SubClass(BaseReader):

    def _read():
        # do the things
    def _postcheck():
        assert thingsWereDone

Pre/post check functions should log errors/warnings accordingly, such as an error if the word DET does not appear in the first fuel lines of a supposed detector file. When applicable, Exceptions should be raised if things go really poorly.

@gridley
Copy link
Contributor

gridley commented Feb 6, 2018

I tried parsing a COE file the other day which only finished partially. Seems that this doesn’t get caught as-is.

@drewejohnson
Copy link
Collaborator Author

Agreed. I read a handful of depletion files as detectors and nothing was mentioned/raised 🙁 This will definitely help

@gridley
Copy link
Contributor

gridley commented Feb 6, 2018

I would absolutely be willing to take this issue, if you want.

@drewejohnson
Copy link
Collaborator Author

Sounds great! All yours

@drewejohnson
Copy link
Collaborator Author

Closed with #88

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

No branches or pull requests

2 participants