예제 #1
0
    def _check_events(self, file_location):
        """
        Checks the events to ensure that the number of particles match the
        number declared by the event.

        Raises:
            PyPWA.libs.data.exceptions.IncompatibleData:
                Raised when the tests fail for this object and the data.
        """
        the_file = io.open(file_location)
        count = 0
        while True:
            # Limit how much of the file is tested
            if count == 100:
                break
            number = the_file.readline().strip("\n").strip()

            # If the test has run at least once and has reached the end
            # then end the test
            if count and number == "":
                break

            # If we failed to find the particle count when it was
            # expected end the test with a fail.
            try:
                int(number)
            except ValueError as Error:
                raise exceptions.IncompatibleData(
                    "Expected particle count. Found " + repr(Error) +
                    str(count))

            # If we failed to find all the particle data where it was
            # expected then end the test with a fail
            try:
                for index in range(int(number)):
                    data_length = len(the_file.readline().split(" "))
                    if data_length != 6:
                        raise ValueError(
                            "Particle doesn't have all the data "
                            "required by the gamp standard. Has " +
                            repr(data_length) + " at index " + repr(index))

            except Exception as Error:
                raise exceptions.IncompatibleData(
                    "Unexpected exception raised, caught " + repr(Error) +
                    " where it wasn't expected.")

            count += 1
예제 #2
0
    def _check_data_type(self, file_location):
        """
        Performs a really simple test to see if its a support format.

        Raises:
            PyPWA.libs.data.exceptions.IncompatibleData:
                Raised when the test fails to find a supported format.
        """
        the_file = io.open(file_location)
        test_data = the_file.readline().strip("\n")
        if "=" in test_data:
            self._evil_type = "DictOfArrays"
        elif "." in test_data and len(test_data) > 1:
            self._evil_type = "ListOfFloats"
        elif len(test_data) == 1:
            self._evil_type = "ListOfBools"
        else:
            raise exceptions.IncompatibleData("Failed to find a data")
예제 #3
0
    def _test_length(file_location):
        """
        Tests to make sure that the first number matches the number of
        events. I know that this can be made to be better, however it
        alludes me at this moment.

        Raises:
            PyPWA.libs.data.exceptions.IncompatibleData:
                Raised when the tests fail for this object and the data.
        """
        the_file = io.open(file_location)
        while True:
            number = the_file.readline().strip().strip("\n")
            try:
                if number == "":
                    break
                for index in range(int(number)):
                    the_file.readline()
            except Exception as Error:
                raise exceptions.IncompatibleData(
                    "Unexpected exception raised, caught " + str(Error) +
                    " where it wasn't expected.")
예제 #4
0
 def __header_test(self):
     if not self.__has_a_header():
         raise exceptions.IncompatibleData(
             "CSV Module failed to find the files header in " +
             str(HEADER_SEARCH_BITS) + " characters!")