def prepare_indexes_for_simulation_results(self, operation,
                                            result_filenames, burst):
     indexes = list()
     self.logger.debug(
         "Preparing indexes for simulation results in operation {}...".
         format(operation.id))
     for filename in result_filenames:
         index = h5.index_for_h5_file(filename)()
         # TODO: don't load full TS in memory and make this read nicer
         datatype, ga = h5.load_with_references(filename)
         index.fill_from_has_traits(datatype)
         index.fill_from_generic_attributes(ga)
         index.fk_parent_burst = burst.gid
         index.fk_from_operation = operation.id
         if operation.fk_operation_group:
             datatype_group = dao.get_datatypegroup_by_op_group_id(
                 operation.fk_operation_group)
             self.logger.debug(
                 "Found DatatypeGroup with id {} for operation {}".format(
                     datatype_group.id, operation.id))
             index.fk_datatype_group = datatype_group.id
         self.logger.debug(
             "Prepared index {} for file {} in operation {}".format(
                 index.summary_info, filename, operation.id))
         indexes.append(index)
     self.logger.debug(
         "Prepared {} indexes for results in operation {}...".format(
             len(indexes), operation.id))
     return indexes
    def load_datatype_from_file(self, storage_folder, file_name, op_id, datatype_group=None,
                                move=True, final_storage=None):
        """
        Creates an instance of datatype from storage / H5 file 
        :returns: DatatypeIndex
        """
        self.logger.debug("Loading DataType from file: %s" % file_name)
        datatype, generic_attributes = h5.load_with_references(os.path.join(storage_folder, file_name))
        index_class = h5.REGISTRY.get_index_for_datatype(datatype.__class__)
        datatype_index = index_class()
        datatype_index.fill_from_has_traits(datatype)
        datatype_index.fill_from_generic_attributes(generic_attributes)

        # Add all the required attributes
        if datatype_group is not None:
            datatype_index.fk_datatype_group = datatype_group.id
        datatype_index.fk_from_operation = op_id

        associated_file = h5.path_for_stored_index(datatype_index)
        if os.path.exists(associated_file):
            datatype_index.disk_size = FilesHelper.compute_size_on_disk(associated_file)

        # Now move storage file into correct folder if necessary
        if move and final_storage is not None:
            current_file = os.path.join(storage_folder, file_name)
            h5_type = h5.REGISTRY.get_h5file_for_datatype(datatype.__class__)
            final_path = h5.path_for(final_storage, h5_type, datatype.gid)
            if final_path != current_file and move:
                shutil.move(current_file, final_path)

        return datatype_index
Exemple #3
0
 def load_with_references(dt_gid):
     # type: (uuid.UUID) -> HasTraits
     dt_index = load_entity_by_gid(dt_gid)
     h5_path = h5.path_for_stored_index(dt_index)
     dt, _ = h5.load_with_references(h5_path)
     return dt
Exemple #4
0
 def load_with_references(self, dt_gid):
     # type: (typing.Union[uuid.UUID, str]) -> HasTraits
     dt_index = self.load_entity_by_gid(dt_gid)
     h5_path = h5.path_for_stored_index(dt_index)
     dt, _ = h5.load_with_references(h5_path)
     return dt
Exemple #5
0
 def load_with_references(self, dt_gid, dt_class=None):
     # type: (typing.Union[uuid.UUID, str], typing.Type[HasTraits]) -> HasTraits
     dt_index = ABCAdapter.load_entity_by_gid(dt_gid)
     h5_path = h5.path_for_stored_index(dt_index)
     dt, _ = h5.load_with_references(h5_path)
     return dt