pypet/naturalnaming.py
def _perform_get(self, node, split_name, fast_access,
                     shortcuts, max_depth, auto_load, with_links,
                     try_auto_load_directly):
        """Searches for an item (parameter/result/group node) with the given `name`.

        :param node: The node below which the search is performed

        :param split_name: Name split into list according to '.'

        :param fast_access: If the result is a parameter, whether fast access should be applied.

        :param max_depth:

            Maximum search depth relative to start node.

        :param auto_load:

            If data should be automatically loaded

        :param with_links:

            If links should be considered.

        :param try_auto_load_directly:

            If one should skip search and directly try auto_loading

        :return:

            The found instance (result/parameter/group node) or if fast access is True and you
            found a parameter or result that supports fast access, the contained value is returned.

        :raises:

            AttributeError if no node with the given name can be found
            Raises errors that are raiesd by the storage service if `auto_load=True`

        """

        result = None
        name = '.'.join(split_name)

        if len(split_name) > max_depth:
            raise AttributeError('The node or param/result `%s`, cannot be found under `%s`'
                                 'The name you are looking for is larger than the maximum '
                                 'search depth.' %
                                 (name, node.v_full_name))

        if shortcuts and not try_auto_load_directly:
            first = split_name[0]

            if len(split_name) == 1 and first in node._children and (with_links or
                                                                    first not in node._links):
                result = node._children[first]
            else:

                result = self._check_flat_dicts(node, split_name)

                if result is None:
                    # Check in O(N) with `N` number of groups and nodes
                    # [Worst Case O(N), average case is better
                    # since looking into a single dict costs O(1)].
                    result = node
                    crun = None
                    for key in split_name:
                        if key in self._root_instance._run_information:
                            crun = key
                        result, depth = self._search(result, key, max_depth, with_links, crun)
                        max_depth -= depth
                        if result is None:
                            break

        elif not try_auto_load_directly:
            result = node
            for name in split_name:
                if name in result._children and (with_links or not name in result._links):
                    result = result._children[name]
                else:
                    raise AttributeError(
                        'You did not allow for shortcuts and `%s` was not directly '
                        'found  under node `%s`.' % (name, result.v_full_name))

        if result is None and auto_load:
            try:
                result = node.f_load_child('.'.join(split_name),
                                           load_data=pypetconstants.LOAD_DATA)
                if (self._root_instance.v_idx != -1 and
                            result.v_is_leaf and
                            result.v_is_parameter and
                            result.v_explored):
                    result._set_parameter_access(self._root_instance.v_idx)
            except:
                self._logger.error('Error while auto-loading `%s` under `%s`.' %
                                   (name, node.v_full_name))
                raise

        if result is None:
            raise AttributeError('The node or param/result `%s`, cannot be found under `%s`' %
                                 (name, node.v_full_name))
        if result.v_is_leaf:
            if auto_load and result.f_is_empty():

                try:
                    self._root_instance.f_load_item(result)
                    if (self._root_instance.v_idx != -1 and
                            result.v_is_parameter and
                            result.v_explored):
                        result._set_parameter_access(self._root_instance.v_idx)
                except:
                    self._logger.error('Error while auto-loading `%s` under `%s`. I found the '
                                       'item but I could not load the data.' %
                                       (name, node.v_full_name))
                    raise

            return self._apply_fast_access(result, fast_access)
        else:
            return result
def _perform_get(self, node, split_name, fast_access,
                     shortcuts, max_depth, auto_load, with_links,
                     try_auto_load_directly):
        """Searches for an item (parameter/result/group node) with the given `name`.

        :param node: The node below which the search is performed

        :param split_name: Name split into list according to '.'

        :param fast_access: If the result is a parameter, whether fast access should be applied.

        :param max_depth:

            Maximum search depth relative to start node.

        :param auto_load:

            If data should be automatically loaded

        :param with_links:

            If links should be considered.

        :param try_auto_load_directly:

            If one should skip search and directly try auto_loading

        :return:

            The found instance (result/parameter/group node) or if fast access is True and you
            found a parameter or result that supports fast access, the contained value is returned.

        :raises:

            AttributeError if no node with the given name can be found
            Raises errors that are raiesd by the storage service if `auto_load=True`

        """

        result = None
        name = '.'.join(split_name)

        if len(split_name) > max_depth:
            raise AttributeError('The node or param/result `%s`, cannot be found under `%s`'
                                 'The name you are looking for is larger than the maximum '
                                 'search depth.' %
                                 (name, node.v_full_name))

        if shortcuts and not try_auto_load_directly:
            first = split_name[0]

            if len(split_name) == 1 and first in node._children and (with_links or
                                                                    first not in node._links):
                result = node._children[first]
            else:

                result = self._check_flat_dicts(node, split_name)

                if result is None:
                    # Check in O(N) with `N` number of groups and nodes
                    # [Worst Case O(N), average case is better
                    # since looking into a single dict costs O(1)].
                    result = node
                    crun = None
                    for key in split_name:
                        if key in self._root_instance._run_information:
                            crun = key
                        result, depth = self._search(result, key, max_depth, with_links, crun)
                        max_depth -= depth
                        if result is None:
                            break

        elif not try_auto_load_directly:
            result = node
            for name in split_name:
                if name in result._children and (with_links or not name in result._links):
                    result = result._children[name]
                else:
                    raise AttributeError(
                        'You did not allow for shortcuts and `%s` was not directly '
                        'found  under node `%s`.' % (name, result.v_full_name))

        if result is None and auto_load:
            try:
                result = node.f_load_child('.'.join(split_name),
                                           load_data=pypetconstants.LOAD_DATA)
                if (self._root_instance.v_idx != -1 and
                            result.v_is_leaf and
                            result.v_is_parameter and
                            result.v_explored):
                    result._set_parameter_access(self._root_instance.v_idx)
            except:
                self._logger.error('Error while auto-loading `%s` under `%s`.' %
                                   (name, node.v_full_name))
                raise

        if result is None:
            raise AttributeError('The node or param/result `%s`, cannot be found under `%s`' %
                                 (name, node.v_full_name))
        if result.v_is_leaf:
            if auto_load and result.f_is_empty():

                try:
                    self._root_instance.f_load_item(result)
                    if (self._root_instance.v_idx != -1 and
                            result.v_is_parameter and
                            result.v_explored):
                        result._set_parameter_access(self._root_instance.v_idx)
                except:
                    self._logger.error('Error while auto-loading `%s` under `%s`. I found the '
                                       'item but I could not load the data.' %
                                       (name, node.v_full_name))
                    raise

            return self._apply_fast_access(result, fast_access)
        else:
            return result
Searches for an item (parameter/result/group node) with the given `name`.

        :param node: The node below which the search is performed

        :param split_name: Name split into list according to '.'

        :param fast_access: If the result is a parameter, whether fast access should be applied.

        :param max_depth:

            Maximum search depth relative to start node.

        :param auto_load:

            If data should be automatically loaded

        :param with_links:

            If links should be considered.

        :param try_auto_load_directly:

            If one should skip search and directly try auto_loading

        :return:

            The found instance (result/parameter/group node) or if fast access is True and you
            found a parameter or result that supports fast access, the contained value is returned.

        :raises:

            AttributeError if no node with the given name can be found
            Raises errors that are raiesd by the storage service if `auto_load=True`