pypet/storageservice.py
def _tree_load_nodes_dfs(self, parent_traj_node, load_data, with_links, recursive,
                         max_depth, current_depth, trajectory, as_new, hdf5_group):
        """Loads a node from hdf5 file and if desired recursively everything below

        :param parent_traj_node: The parent node whose child should be loaded
        :param load_data: How to load the data
        :param with_links: If links should be loaded
        :param recursive: Whether loading recursively below hdf5_group
        :param max_depth: Maximum depth
        :param current_depth: Current depth
        :param trajectory: The trajectory object
        :param as_new: If trajectory is loaded as new
        :param hdf5_group: The hdf5 group containing the child to be loaded

        """
        if max_depth is None:
            max_depth = float('inf')

        loading_list = [(parent_traj_node, current_depth, hdf5_group)]

        while loading_list:
            parent_traj_node, current_depth, hdf5_group = loading_list.pop()

            if isinstance(hdf5_group, pt.link.SoftLink):
                if with_links:
                    # We end up here when auto-loading a soft link
                    self._tree_load_link(parent_traj_node, load_data=load_data, traj=trajectory,
                                         as_new=as_new, hdf5_soft_link=hdf5_group)
                continue


            name = hdf5_group._v_name
            is_leaf = self._all_get_from_attrs(hdf5_group, HDF5StorageService.LEAF)
            in_trajectory = name in parent_traj_node._children

            if is_leaf:
                # In case we have a leaf node, we need to check if we have to create a new
                # parameter or result

                if in_trajectory:
                    instance = parent_traj_node._children[name]
                # Otherwise we need to create a new instance
                else:
                    instance = self._tree_create_leaf(name, trajectory, hdf5_group)

                    # Add the instance to the trajectory tree
                    parent_traj_node._add_leaf_from_storage(args=(instance,), kwargs={})

                self._prm_load_parameter_or_result(instance, load_data=load_data,
                                                   _hdf5_group=hdf5_group)
                if as_new:
                    instance._stored = False

            else:
                if in_trajectory:
                    traj_group = parent_traj_node._children[name]

                    if load_data == pypetconstants.OVERWRITE_DATA:
                        traj_group.v_annotations.f_empty()
                        traj_group.v_comment = ''
                else:
                    if HDF5StorageService.CLASS_NAME in hdf5_group._v_attrs:
                        class_name = self._all_get_from_attrs(hdf5_group,
                                                              HDF5StorageService.CLASS_NAME)
                        class_constructor = trajectory._create_class(class_name)
                        instance = trajectory._construct_instance(class_constructor, name)
                        args = (instance,)
                    else:
                        args = (name,)
                    # If the group does not exist create it'
                    traj_group = parent_traj_node._add_group_from_storage(args=args, kwargs={})

                # Load annotations and comment
                self._grp_load_group(traj_group, load_data=load_data, with_links=with_links,
                                     recursive=False, max_depth=max_depth,
                                     _traj=trajectory, _as_new=as_new,
                                     _hdf5_group=hdf5_group)

                if recursive and current_depth < max_depth:
                    new_depth = current_depth + 1
                    for children in (hdf5_group._v_groups, hdf5_group._v_links):
                        for new_hdf5_group_name in children:
                            new_hdf5_group = children[new_hdf5_group_name]
                            loading_list.append((traj_group, new_depth, new_hdf5_group))
def _tree_load_nodes_dfs(self, parent_traj_node, load_data, with_links, recursive,
                         max_depth, current_depth, trajectory, as_new, hdf5_group):
        """Loads a node from hdf5 file and if desired recursively everything below

        :param parent_traj_node: The parent node whose child should be loaded
        :param load_data: How to load the data
        :param with_links: If links should be loaded
        :param recursive: Whether loading recursively below hdf5_group
        :param max_depth: Maximum depth
        :param current_depth: Current depth
        :param trajectory: The trajectory object
        :param as_new: If trajectory is loaded as new
        :param hdf5_group: The hdf5 group containing the child to be loaded

        """
        if max_depth is None:
            max_depth = float('inf')

        loading_list = [(parent_traj_node, current_depth, hdf5_group)]

        while loading_list:
            parent_traj_node, current_depth, hdf5_group = loading_list.pop()

            if isinstance(hdf5_group, pt.link.SoftLink):
                if with_links:
                    # We end up here when auto-loading a soft link
                    self._tree_load_link(parent_traj_node, load_data=load_data, traj=trajectory,
                                         as_new=as_new, hdf5_soft_link=hdf5_group)
                continue


            name = hdf5_group._v_name
            is_leaf = self._all_get_from_attrs(hdf5_group, HDF5StorageService.LEAF)
            in_trajectory = name in parent_traj_node._children

            if is_leaf:
                # In case we have a leaf node, we need to check if we have to create a new
                # parameter or result

                if in_trajectory:
                    instance = parent_traj_node._children[name]
                # Otherwise we need to create a new instance
                else:
                    instance = self._tree_create_leaf(name, trajectory, hdf5_group)

                    # Add the instance to the trajectory tree
                    parent_traj_node._add_leaf_from_storage(args=(instance,), kwargs={})

                self._prm_load_parameter_or_result(instance, load_data=load_data,
                                                   _hdf5_group=hdf5_group)
                if as_new:
                    instance._stored = False

            else:
                if in_trajectory:
                    traj_group = parent_traj_node._children[name]

                    if load_data == pypetconstants.OVERWRITE_DATA:
                        traj_group.v_annotations.f_empty()
                        traj_group.v_comment = ''
                else:
                    if HDF5StorageService.CLASS_NAME in hdf5_group._v_attrs:
                        class_name = self._all_get_from_attrs(hdf5_group,
                                                              HDF5StorageService.CLASS_NAME)
                        class_constructor = trajectory._create_class(class_name)
                        instance = trajectory._construct_instance(class_constructor, name)
                        args = (instance,)
                    else:
                        args = (name,)
                    # If the group does not exist create it'
                    traj_group = parent_traj_node._add_group_from_storage(args=args, kwargs={})

                # Load annotations and comment
                self._grp_load_group(traj_group, load_data=load_data, with_links=with_links,
                                     recursive=False, max_depth=max_depth,
                                     _traj=trajectory, _as_new=as_new,
                                     _hdf5_group=hdf5_group)

                if recursive and current_depth < max_depth:
                    new_depth = current_depth + 1
                    for children in (hdf5_group._v_groups, hdf5_group._v_links):
                        for new_hdf5_group_name in children:
                            new_hdf5_group = children[new_hdf5_group_name]
                            loading_list.append((traj_group, new_depth, new_hdf5_group))
Loads a node from hdf5 file and if desired recursively everything below

        :param parent_traj_node: The parent node whose child should be loaded
        :param load_data: How to load the data
        :param with_links: If links should be loaded
        :param recursive: Whether loading recursively below hdf5_group
        :param max_depth: Maximum depth
        :param current_depth: Current depth
        :param trajectory: The trajectory object
        :param as_new: If trajectory is loaded as new
        :param hdf5_group: The hdf5 group containing the child to be loaded