def save_configuration_to_hdf5(register, configuration_file, name='<STR_LIT>'):
def save_conf():<EOL><INDENT>logging.info("<STR_LIT>" % h5_file.filename)<EOL>register.configuration_file = h5_file.filename<EOL>try:<EOL><INDENT>configuration_group = h5_file.create_group(h5_file.root, "<STR_LIT>")<EOL><DEDENT>except tb.NodeError:<EOL><INDENT>configuration_group = h5_file.root.configuration<EOL><DEDENT>if name:<EOL><INDENT>try:<EOL><INDENT>configuration_group = h5_file.create_group(configuration_group, name)<EOL><DEDENT>except tb.NodeError:<EOL><INDENT>configuration_group = h5_file.root.configuration.name<EOL><DEDENT><DEDENT>try:<EOL><INDENT>h5_file.remove_node(configuration_group, name='<STR_LIT>')<EOL><DEDENT>except tb.NodeError:<EOL><INDENT>pass<EOL><DEDENT>calibration_data_table = h5_file.create_table(configuration_group, name='<STR_LIT>', description=NameValue, title='<STR_LIT>')<EOL>calibration_data_row = calibration_data_table.row<EOL>for key, value in register.calibration_parameters.iteritems():<EOL><INDENT>calibration_data_row['<STR_LIT:name>'] = key<EOL>calibration_data_row['<STR_LIT:value>'] = str(value)<EOL>calibration_data_row.append()<EOL><DEDENT>calibration_data_table.flush()<EOL>try:<EOL><INDENT>h5_file.remove_node(configuration_group, name='<STR_LIT>')<EOL><DEDENT>except tb.NodeError:<EOL><INDENT>pass<EOL><DEDENT>miscellaneous_data_table = h5_file.create_table(configuration_group, name='<STR_LIT>', description=NameValue, title='<STR_LIT>')<EOL>miscellaneous_data_row = miscellaneous_data_table.row<EOL>miscellaneous_data_row['<STR_LIT:name>'] = '<STR_LIT>'<EOL>miscellaneous_data_row['<STR_LIT:value>'] = register.flavor<EOL>miscellaneous_data_row.append()<EOL>miscellaneous_data_row['<STR_LIT:name>'] = '<STR_LIT>'<EOL>miscellaneous_data_row['<STR_LIT:value>'] = register.chip_id<EOL>miscellaneous_data_row.append()<EOL>for key, value in register.miscellaneous.iteritems():<EOL><INDENT>miscellaneous_data_row['<STR_LIT:name>'] = key<EOL>miscellaneous_data_row['<STR_LIT:value>'] = value<EOL>miscellaneous_data_row.append()<EOL><DEDENT>miscellaneous_data_table.flush()<EOL>try:<EOL><INDENT>h5_file.remove_node(configuration_group, name='<STR_LIT>')<EOL><DEDENT>except tb.NodeError:<EOL><INDENT>pass<EOL><DEDENT>global_data_table = h5_file.create_table(configuration_group, name='<STR_LIT>', description=NameValue, title='<STR_LIT>')<EOL>global_data_table_row = global_data_table.row<EOL>global_regs = register.get_global_register_objects(readonly=False)<EOL>for global_reg in sorted(global_regs, key=itemgetter('<STR_LIT:name>')):<EOL><INDENT>global_data_table_row['<STR_LIT:name>'] = global_reg['<STR_LIT:name>']<EOL>global_data_table_row['<STR_LIT:value>'] = global_reg['<STR_LIT:value>']  <EOL>global_data_table_row.append()<EOL><DEDENT>global_data_table.flush()<EOL>for pixel_reg in register.pixel_registers.itervalues():<EOL><INDENT>try:<EOL><INDENT>h5_file.remove_node(configuration_group, name=pixel_reg['<STR_LIT:name>'])<EOL><DEDENT>except tb.NodeError:<EOL><INDENT>pass<EOL><DEDENT>data = pixel_reg['<STR_LIT:value>'].T<EOL>atom = tb.Atom.from_dtype(data.dtype)<EOL>ds = h5_file.create_carray(configuration_group, name=pixel_reg['<STR_LIT:name>'], atom=atom, shape=data.shape, title=pixel_reg['<STR_LIT:name>'])<EOL>ds[:] = data<EOL><DEDENT><DEDENT>if isinstance(configuration_file, tb.file.File):<EOL><INDENT>h5_file = configuration_file<EOL>save_conf()<EOL><DEDENT>else:<EOL><INDENT>with tb.open_file(configuration_file, mode="<STR_LIT:a>", title='<STR_LIT>') as h5_file:<EOL><INDENT>save_conf()<EOL><DEDENT><DEDENT>
Saving configuration to HDF5 file from register object

    Parameters
    ----------
    register : pybar.fei4.register object
    configuration_file : string, file
        Filename of the HDF5 configuration file or file object.
    name : string
        Additional identifier (subgroup). Useful when storing more than one configuration inside a HDF5 file.