Exemplo n.º 1
0
/*-------------------------------------------------------------------------
 * test_append
 *
 * Tests appending packets to a FL packet table
 *
 *-------------------------------------------------------------------------
 */
static int test_append(hid_t fid)
{
    herr_t err;
    hid_t table;
    hsize_t count;

    TESTING("H5PTappend");

    /* Open the table */
    table = H5PTopen(fid, PT_NAME);
    if( H5PTis_valid(table) < 0)
        goto out;

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    /* There should be 0 records in the table */
    if( count != 0 )
        goto out;

    /* Append one particle */
    err = H5PTappend(table, (size_t)1, &(testPart[0]));
    if( err < 0)
        goto out;

    /* Append several particles */
    err = H5PTappend(table, (size_t)6, &(testPart[1]));
    if( err < 0)
        goto out;

    /* Append one more particle */
    err = H5PTappend(table, (size_t)1, &(testPart[7]));
    if( err < 0)
        goto out;

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    /* There should be 8 records in the table now */
    if( count != 8 )
        goto out;

    /* Close the table */
    err = H5PTclose(table);
    if( err < 0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    if( H5PTis_valid(table) < 0)
        H5PTclose(table);
    return -1;
}
Exemplo n.º 2
0
/*-------------------------------------------------------------------------
 * test_opaque
 *
 * Tests that the packet table works with an opaque datatype.
 *
 *-------------------------------------------------------------------------
 */
static int    test_opaque(hid_t fid)
{
    herr_t err;
    hid_t table;
    hid_t part_t;
    size_t c;
    particle_t readBuf[NRECORDS];

    TESTING("opaque data");

    /* Create an opaque datatype for the particle struct */
    if ((part_t = H5Tcreate (H5T_OPAQUE, sizeof(particle_t) )) < 0 )
        return -1;

    HDassert(part_t != -1);

    /* Tag the opaque datatype */
    if ( H5Tset_tag(part_t,  "Opaque Particle"  ) < 0)
        return -1;

    /* Create a new table */
    table = H5PTcreate_fl(fid, "Packet Test Dataset3", part_t, (hsize_t)100, -1);
    H5Tclose(part_t);
    if( H5PTis_valid(table) < 0)
        goto out;

    /* Append several particles, starting at particle 1 */
    err = H5PTappend(table, (size_t)(NRECORDS - 1), &(testPart[1]));
    if( err < 0)
        goto out;

    /* Read the particles back */
    err = H5PTread_packets(table, (hsize_t)0, 7, &(readBuf[0]));
    if( err < 0)
        goto out;

    /* Ensure that particles were read correctly */
    for(c=0; c<NRECORDS - 1; c++)
    {
        if( cmp_par(c+1, c, testPart, readBuf) != 0)
            goto out;
    }

    /* Close the table */
    err = H5PTclose(table);
    if( err < 0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    if( H5PTis_valid(table) < 0)
        H5PTclose(table);
    return -1;
}
Exemplo n.º 3
0
/* AppendPacket (variable-length)
 * Adds a single variable-length packet to the packet table.
 * Takes a pointer to the location of the data in memory and the length of the data
 * in bytes.
 * Returns 0 on success, negative on failure.
 */
int VL_PacketTable::AppendPacket(void * data, size_t length)
{
    hvl_t packet;

    packet.len = length;
    packet.p = data;

    return H5PTappend(table_id, 1, &packet);
}
Exemplo n.º 4
0
extern int acct_gather_profile_p_add_sample_data(int table_id, void *data,
						 time_t sample_time)
{
	table_t *ds = &tables[table_id];
	uint8_t send_data[ds->type_size];
	int header_size = 0;
	debug("acct_gather_profile_p_add_sample_data %d", table_id);

	if (file_id < 0) {
		debug("PROFILE: Trying to add data but profiling is over");
		return SLURM_SUCCESS;
	}

	if (table_id < 0 || table_id >= tables_cur_len) {
		error("PROFILE: trying to add samples to an invalid table %d",
		      table_id);
		return SLURM_ERROR;
	}

	/* ensure that we have to record something */
	xassert(_run_in_daemon());
	xassert(g_job);
	xassert(g_profile_running != ACCT_GATHER_PROFILE_NOT_SET);

	if (g_profile_running <= ACCT_GATHER_PROFILE_NONE)
		return SLURM_ERROR;

	/* prepend timestampe and relative time */
	((uint64_t *)send_data)[0] = difftime(sample_time, step_start_time);
	header_size += sizeof(uint64_t);
	((uint64_t *)send_data)[1] = sample_time;
	header_size += sizeof(uint64_t);

	memcpy(send_data + header_size, data, ds->type_size - header_size);

	/* append the record to the table */
	if (H5PTappend(ds->table_id, 1, send_data) < 0) {
		error("PROFILE: Impossible to add data to the table %d; "
		      "maybe the table has not been created?", table_id);
		return SLURM_ERROR;
	}

	return SLURM_SUCCESS;
}
Exemplo n.º 5
0
/**
@details
-# Snapshot the index of the most recent temporary memory buffer to write to disk to curr_buffer_num
-# For each parameter to be recorded
   -# Point a pointer to the beginning of the data in the memory buffer to be written to disk
   -# Append one packet to the packet table.
*/
int Trick::DRHDF5::format_specific_write_data(unsigned int writer_offset __attribute__((unused))) {

#ifdef HDF5
    unsigned int ii;
    char *buf = 0;

    /* Loop through each parameter. */
    for (ii = 0; ii < parameters.size(); ii++) {

        /* Each parameters[] element contains a DataRecordBuffer class.
         * So there is a seperate DataRecordBuffer per variable.
         * Point to the value to be recorded. */
        HDF5_INFO * hi = parameters[ii] ;
        buf = hi->drb->buffer + (writer_offset * hi->drb->ref->attr->size) ;

        /* Append 1 value to the packet table. */
        H5PTappend( hi->dataset, 1, buf );

    }
#endif

    return(0);
}
Exemplo n.º 6
0
void AccessTraceWriter::dump(bool cont) {
    hid_t fid = H5Fopen(fname.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
    if (fid == H5I_INVALID_HID) panic("Could not open HDF5 file %s", fname.c_str());
    hid_t table = H5PTopen(fid, "accs");
    if (table == H5I_INVALID_HID) panic("Could not open HDF5 packet table");
    herr_t err = H5PTappend(table, cur, buf);
    assert(err >= 0);

    if (!cont) {
        hid_t fAttr = H5Aopen(fid, "finished", H5P_DEFAULT);
        uint32_t finished = 1;
        H5Awrite(fAttr, H5T_NATIVE_UINT, &finished);
        H5Aclose(fAttr);

        gm_free(buf);
        buf = nullptr;
        max = 0;
    }

    cur = 0;
    H5PTclose(table);
    H5Fclose(fid);
}
Exemplo n.º 7
0
int main(void)
{
#ifdef VLPT_REMOVED
 hid_t          fid;        /* File identifier */
 hid_t          ptable;     /* Packet table identifier */

 herr_t         err;        /* Function return status */
 hsize_t        count;      /* Number of records in the table */
 int            x;          /* Loop variable */

    /* Buffers to hold data */
 hvl_t writeBuffer[5];
 hvl_t readBuffer[5];

    /* This example has two different sizes of "record": longs and shorts */
 long longBuffer[5];
 short shortBuffer[5];

   /* Initialize buffers */
 for(x=0; x<5; x++)
 {
     longBuffer[x] = -x;
     shortBuffer[x] = x;
 }

    /* Fill the write buffer with a mix of longs and shorts */
    /* We need to supply the length of each record and a pointer to */
    /* the beginning of each record. */
 writeBuffer[0].len = sizeof(long);
 writeBuffer[0].p = &(longBuffer[0]);
 writeBuffer[1].len = sizeof(short);
 writeBuffer[1].p = &(shortBuffer[1]);
 writeBuffer[2].len = sizeof(long);
 writeBuffer[2].p = &(longBuffer[2]);
 writeBuffer[3].len = sizeof(long);
 writeBuffer[3].p = &(longBuffer[3]);
 writeBuffer[4].len = sizeof(short);
 writeBuffer[4].p = &(shortBuffer[4]);

    /* Create a file using default properties */
 fid=H5Fcreate("packet_table_VLexample.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);

    /* Create a variable-length packet table within the file */
 ptable = H5PTcreate_vl(fid, "Packet Test Dataset", (hsize_t)1);
 if(ptable == H5I_INVALID_HID)
     goto out;

    /* Write the entire buffer to the packet table */
 err = H5PTappend(ptable, (hsize_t)5, writeBuffer );
 if(err < 0)
     goto out;

    /* Get the number of packets in the packet table.  This should be five. */
 err = H5PTget_num_packets(ptable, &count);
 if(err < 0)
     goto out;

 printf("Number of packets in packet table after five appends: %d\n", count);

    /* Read all five packets back */
 err = H5PTread_packets(ptable, (hsize_t)0, (hsize_t)5, readBuffer );
 if(err < 0)
    goto out;

 for(x=0; x<5; x++)
 {
    printf("Packet %d's length is %d\n", x, readBuffer[x].len);
    if(readBuffer[x].len == sizeof(long))
        printf("Packet %d's value is %d\n", x, *( (long *) readBuffer[x].p) );
    else
        printf("Packet %d's value is %d\n", x, *( (short *) readBuffer[x].p) );
 }

    /* Before we close the packet table, we must free the memory that */
    /* the pointers in readBuffer point to. */
 err = H5PTfree_vlen_readbuff(ptable, (hsize_t)5, readBuffer);
 if(err < 0)
     goto out;

    /* Close the packet table */
 err = H5PTclose(ptable);
 if(err < 0)
     goto out;

    /* Close the file */
 H5Fclose(fid);
#endif /* VLPT_REMOVED */

 return 0;

#ifdef VLPT_REMOVED
 out: /* An error has occurred.  Clean up and exit. */
    fprintf(stderr, "An error has occurred!\n");
    H5PTclose(ptable);
    H5Fclose(fid);
    return -1;
#endif /* VLPT_REMOVED */
}
Exemplo n.º 8
0
/*-------------------------------------------------------------------------
 * test_error
 *
 * ensures that the packet table API throws the correct errors used on
 * objects that are not packet tables.
 *
 *-------------------------------------------------------------------------
 */
static int test_error(hid_t fid)
{
    hid_t id = H5I_BADID;
    int id_open=0;
    particle_t readBuf[1];

    TESTING("error conditions");

    /* Create a HL table */
    if(create_hl_table(fid) < 0)
        goto out;

    /* Try to open things that are not packet tables */
    H5E_BEGIN_TRY
    if(H5PTopen(fid, "Bogus_name") >= 0)
        goto out;
    if(H5PTopen(fid, "group1") >= 0)
        goto out;
    H5E_END_TRY

    /* Try to execute packet table commands on an invalid ID */
    H5E_BEGIN_TRY
    if(H5PTis_valid(id) >= 0)
        goto out;
#ifdef VLPT_REMOVED
    if(H5PTis_varlen(id) >= 0)
        goto out;
#endif /* VLPT_REMOVED */
    if(H5PTclose(id) >= 0)
        goto out;
    if(H5PTappend(id, (size_t)1, testPart) >= 0)
        goto out;
    if(H5PTread_packets(id, (hsize_t)0, 1, readBuf) >= 0)
        goto out;
    if(H5PTcreate_index(id) >= 0)
        goto out;
    if(H5PTset_index(id, (hsize_t)1) >= 0)
        goto out;
    if(H5PTget_index(id, NULL) >= 0)
        goto out;
    H5E_END_TRY

    /* Open a high-level non-packet (H5TB) table and try to */
    /* execute commands on it. */
    if((id=H5Dopen2(fid, H5TB_TABLE_NAME, H5P_DEFAULT)) <0)
        goto out;
    id_open = 1;

    H5E_BEGIN_TRY
    if(H5PTis_valid(id) >= 0)
        goto out;
#ifdef VLPT_REMOVED
    if(H5PTis_varlen(id) >= 0)
        goto out;
#endif /* VLPT_REMOVED */
    if(H5PTclose(id) >= 0)
        goto out;
    if(H5PTappend(id, (size_t)1, testPart) >= 0)
        goto out;
    if(H5PTread_packets(id, (hsize_t)0, 1, readBuf) >= 0)
        goto out;
    if(H5PTcreate_index(id) >= 0)
        goto out;
    if(H5PTset_index(id, (hsize_t)1) >= 0)
        goto out;
    if(H5PTget_index(id, NULL) >= 0)
        goto out;
    H5E_END_TRY

    id_open=0;
    if(H5Dclose(id) <0)
        goto out;

    /* Open and close a packet table.  Try to execute */
    /* commands on the closed ID. */
    if((id=H5PTopen(fid, PT_NAME))<0)
        goto out;
    if(H5PTclose(id) <0)
        goto out;

    H5E_BEGIN_TRY
    if(H5PTis_valid(id) >= 0)
        goto out;
#ifdef VLPT_REMOVED
    if(H5PTis_varlen(id) >= 0)
        goto out;
#endif /* VLPT_REMOVED */
    if(H5PTclose(id) >= 0)
        goto out;
    if(H5PTappend(id, (size_t)1, testPart) >= 0)
        goto out;
    if(H5PTread_packets(id, (hsize_t)0, 1, readBuf) >= 0)
        goto out;
    if(H5PTcreate_index(id) >= 0)
        goto out;
    if(H5PTset_index(id, (hsize_t)1) >= 0)
        goto out;
    if(H5PTget_index(id, NULL) >= 0)
        goto out;
    H5E_END_TRY

    PASSED();
    return 0;

out:
    H5_FAILED();
    if(id_open)
        H5Dclose(id);
    return -1;
}
Exemplo n.º 9
0
/*-------------------------------------------------------------------------
 * test_compress
 *
 * Ensures that a FL packet table can be compressed.
 * This test creates a file named TEST_COMPRESS_FILE
 *
 *-------------------------------------------------------------------------
 */
static int
test_compress(void)
{
    hid_t fid1 = -1;
    herr_t err;
    hid_t table = -1;
    hid_t part_t = -1;
    hid_t dset_id = -1;
    hid_t plist_id = -1;
    size_t c;
    size_t num_elems = 1;
    unsigned filter_vals[1];
    particle_t readPart[1];
    hsize_t count;

    TESTING("packet table compression");

    /* Create a file. */
    if((fid1 = H5Fcreate(TEST_COMPRESS_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Create a datatype for the particle struct */
    part_t = make_particle_type();

    HDassert(part_t != -1);

    /* Create a new table with compression level 8 */
    table = H5PTcreate_fl(fid1, "Compressed Test Dataset", part_t, (hsize_t)80, 8);
    if( H5PTis_valid(table) < 0) TEST_ERROR;

    /* We can now use this table exactly the same way we use a normal uncompressed
     * packet table, and it should pass the same tests. */
    /* Add many particles */
    for(c = 0; c < BIG_TABLE_SIZE ; c+=8)
    {
        /* Append eight particles at once*/
        err = H5PTappend(table, (size_t)8, &(testPart[0]));
        if( err < 0) TEST_ERROR;
    }

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0) TEST_ERROR;
    if( count != BIG_TABLE_SIZE ) TEST_ERROR;

    /* Read particles to ensure that all of them were written correctly  */
    HDmemset(readPart, 0, sizeof(readPart));
    for(c = 0; c < BIG_TABLE_SIZE; c++)
    {
        err = H5PTget_next(table, 1, readPart);
        if(err < 0) TEST_ERROR;

        /* Ensure that particles were read correctly */
        if( cmp_par(c % 8, 0, testPart, readPart) != 0) TEST_ERROR;
    }

    /* Close the table */
    err = H5PTclose(table);
    if( err < 0) TEST_ERROR;

    /* Open the packet table as a regular dataset and make sure that the
     * compression filter is set.
     */
    dset_id = H5Dopen2(fid1, "Compressed Test Dataset", H5P_DEFAULT);
    if( dset_id < 0) TEST_ERROR;

    plist_id = H5Dget_create_plist(dset_id);
    if( plist_id < 0) TEST_ERROR;

    err = H5Pget_filter_by_id2(plist_id, H5Z_FILTER_DEFLATE, NULL, &num_elems,
                               filter_vals, 0, NULL, NULL);
    if( err < 0) TEST_ERROR;

    /* The compression level should be 8, the value we passed in */
    if(filter_vals[0] != 8) TEST_ERROR;

    /* Clean up */
    err = H5Pclose(plist_id);
    if( err < 0) TEST_ERROR;
    err = H5Dclose(dset_id);
    if( err < 0) TEST_ERROR;

    /* Create a new table without compression. */
    table = H5PTcreate_fl(fid1, "Uncompressed Dataset", part_t, (hsize_t)80, -1);
    if(table < 0) TEST_ERROR;

    /* Close the packet table */
    err = H5PTclose(table);
    if( err < 0) TEST_ERROR;

    /* Open the packet table as a regular dataset and make sure that the
     * compression filter is not set.
     */
    dset_id = H5Dopen2(fid1, "Uncompressed Dataset", H5P_DEFAULT);
    if( dset_id < 0) TEST_ERROR;

    plist_id = H5Dget_create_plist(dset_id);
    if( plist_id < 0) TEST_ERROR;

    H5E_BEGIN_TRY {
        err = H5Pget_filter_by_id2(plist_id, H5Z_FILTER_DEFLATE, NULL, &num_elems,
        filter_vals, 0, NULL, NULL);
        if( err >= 0) TEST_ERROR;
    } H5E_END_TRY

    /* Clean up */
    err = H5Pclose(plist_id);
    if( err < 0) TEST_ERROR;
    err = H5Dclose(dset_id);
    if( err < 0) TEST_ERROR;

    /* Close the datatype and the file */
    err = H5Tclose(part_t);
    if( err < 0) TEST_ERROR;
    err = H5Fclose(fid1);
    if( err < 0) TEST_ERROR;

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(plist_id);
        H5Dclose(dset_id);
        H5Tclose(part_t);
        H5PTclose(table);
        H5Fclose(fid1);
    } H5E_END_TRY
    H5_FAILED();
    return -1;
}
Exemplo n.º 10
0
/*-------------------------------------------------------------------------
 * test_rw_non-native_dt
 *
 * test reading and writing packet table using datatypes that are not
 * native.
 *
 *-------------------------------------------------------------------------
 */
static int test_rw_nonnative_dt(hid_t fid)
{
    hid_t          ptable;     /* Packet table identifier */

    herr_t         err;        /* Function return status */
    hsize_t        count;      /* Number of records in the table */

    int            x;          /* Loop variable */

    /* Buffers to hold data */
    int writeBuffer[5];
    int readBuffer[5];

    TESTING("reading/writing non-native packet table");

    /* Initialize buffers */
    for(x=0; x<5; x++) {
        writeBuffer[x]=x;
        readBuffer[x] = -1;
    }

    /* Create a fixed-length packet table within the file */
    /* This table's "packets" will be simple integers and it will use no compression */
    if(H5Tget_order(H5T_NATIVE_INT) == H5T_ORDER_LE) {
        ptable = H5PTcreate_fl(fid, "Packet Test Dataset, Non-native", H5T_STD_I32BE, (hsize_t)100, -1);
    } else {
        ptable = H5PTcreate_fl(fid, "Packet Test Dataset, Non-native", H5T_STD_I32LE, (hsize_t)100, -1);
    }
    if(ptable == H5I_INVALID_HID)
        goto out;

    /* Write one packet to the packet table */
    if( (err = H5PTappend(ptable, (hsize_t)1, &(writeBuffer[0]))) < 0 )
        goto out;

    /* Write several packets to the packet table */
    if( (err = H5PTappend(ptable, (hsize_t)4, &(writeBuffer[1]))) < 0)
        goto out;

    if( (err = H5PTclose(ptable)) < 0)
        goto out;

    /* Open the Packet table */
    if( (ptable = H5PTopen(fid, "Packet Test Dataset, Non-native")) < 0)
        goto out;

    /* Get the number of packets in the packet table.  This should be five. */
    if( (err = H5PTget_num_packets(ptable, &count)) < 0)
        goto out;

    if( (int)count != 5 )
        goto out;

    /* Initialize packet table's "current record" */
    if( (err = H5PTcreate_index(ptable)) < 0)
        goto out;

    /* Iterate through packets, read each one back */
    for(x=0; x<5; x++) {
        if( (err = H5PTget_next(ptable, (hsize_t)1, &(readBuffer[x]))) < 0)
            goto out;
        if( x != readBuffer[x])
            goto out;
    }

    /* Close the packet table */
    if( (err = H5PTclose(ptable)) < 0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    if( H5PTis_valid(ptable) < 0)
        H5PTclose(ptable);
    return -1;
}
Exemplo n.º 11
0
/*-------------------------------------------------------------------------
 * test_varlen
 *
 * Tests creation, opening, closing, writing, reading, etc. on a
 * variable-length packet table.
 *
 *-------------------------------------------------------------------------
 */
static int    test_varlen(hid_t fid)
{
    herr_t err;
    hid_t table=H5I_BADID;
    hsize_t count;

    /* Buffers to hold data */
    hvl_t writeBuffer[NRECORDS];
    hvl_t readBuffer[NRECORDS];

    /* This example has three different sizes of "record": longs, shorts, and particles */
    long longBuffer[NRECORDS];
    short shortBuffer[NRECORDS];
    int x;

    TESTING("variable-length packet tables");

    /* Initialize buffers */
    for(x=0; x<NRECORDS; x++)
    {
        longBuffer[x] = -x;
        shortBuffer[x] = x;
    }

    /* Fill the write buffer with a mix of variable types */
    for(x=0; x<8; x+=4)
    {
        writeBuffer[x].len = sizeof(long);
        writeBuffer[x].p = &(longBuffer[x]);
        writeBuffer[x+1].len = sizeof(short);
        writeBuffer[x+1].p = &(shortBuffer[x+1]);
        writeBuffer[x+2].len = sizeof(long);
        writeBuffer[x+2].p = &(longBuffer[x+2]);
        writeBuffer[x+3].len = sizeof(particle_t);
        writeBuffer[x+3].p = &(testPart[x+3]);
    }

    /* Create the table */
    table = H5PTcreate_vl(fid, VL_TABLE_NAME, (hsize_t)1001);
    if( H5PTis_valid(table) < 0)
        goto out;
    if( H5PTis_varlen(table) != 1)
        goto out;

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    if( count != 0 )
        goto out;

    /* Close the table */
    err = H5PTclose(table);
    if( err < 0)
        goto out;

    /* Re-open the table */
    table = H5PTopen(fid, VL_TABLE_NAME);
    if( H5PTis_valid(table) < 0)
        goto out;
    if( H5PTis_varlen(table) != 1)
        goto out;

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    if( count != 0 )
        goto out;

    /* Add several variable-length packets */
    err = H5PTappend(table, (size_t)8, writeBuffer );
    if(err < 0)
        goto out;

    /* Read them back */
    err = H5PTread_packets(table, (hsize_t)0, 4, &(readBuffer[0]));
    if( err < 0)
        goto out;
    err = H5PTread_packets(table, (hsize_t)4, 1, &(readBuffer[4]));
    if( err < 0)
        goto out;
    err = H5PTread_packets(table, (hsize_t)5, (NRECORDS - 5 ), &(readBuffer[5]));
    if( err < 0)
        goto out;

    /* Ensure that packets were read correctly */
    for(x=0; x<NRECORDS; x++)
    {
        if( readBuffer[x].len != writeBuffer[x%4].len)
            goto out;
        switch(x%4)
        {
        case 0:
        case 2:
            if( *((long*)(readBuffer[x].p)) != *((long*)(writeBuffer[x].p)))
                goto out;
            break;
        case 1:
            if( *((short*)(readBuffer[x].p)) != *((short*)(writeBuffer[x].p)))
                goto out;
            break;
        case 3:
            if( cmp_par(0, 0, readBuffer[x].p, writeBuffer[x].p) < 0)
                goto out;
            break;
        default:
            goto out;
        }
    }

    /* Free memory used by read buffer */
    if(H5PTfree_vlen_readbuff(table, NRECORDS, readBuffer) <0)
        goto out;

    /* Read packets back using get_next */
    for(x=0; x < NRECORDS; x++)
    {
        err = H5PTget_next(table, 1, &readBuffer[x]);
        if(err < 0)
            goto out;
    }

    /* Ensure that packets were read correctly */
    for(x=0; x<NRECORDS; x++)
    {
        if( readBuffer[x].len != writeBuffer[x%4].len)
            goto out;
        switch(x%4)
        {
        case 0:
        case 2:
            if( *((long*)(readBuffer[x].p)) != *((long*)(writeBuffer[x].p)))
                goto out;
            break;
        case 1:
            if( *((short*)(readBuffer[x].p)) != *((short*)(writeBuffer[x].p)))
                goto out;
            break;
        case 3:
            if( cmp_par(0, 0, readBuffer[x].p, writeBuffer[x].p) < 0)
                goto out;
            break;
        default:
            goto out;
        }
    }

    /* Free memory used by read buffer */
    if(H5PTfree_vlen_readbuff(table, NRECORDS, readBuffer) <0)
        goto out;

    /* Close the table */
    err = H5PTclose(table);
    if( err < 0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    H5E_BEGIN_TRY
    H5PTclose(table);
    H5E_END_TRY
    return -1;
}
Exemplo n.º 12
0
/* AppendPacket
 * Adds a single packet to the packet table.  Takes a pointer
 * to the location of the data in memory.
 * Returns 0 on success, negative on failure
 */
int FL_PacketTable::AppendPacket(void * data)
{
    return H5PTappend(table_id, 1, data);
}
Exemplo n.º 13
0
/*-------------------------------------------------------------------------
 * test_big_table
 *
 * Ensures that a FL packet table will not break when many (BIG_TABLE_SIZE)
 * packets are used.
 *
 *-------------------------------------------------------------------------
 */
static int    test_big_table(hid_t fid)
{
    herr_t err;
    hid_t table;
    hid_t part_t;
    size_t c;
    particle_t readPart;
    hsize_t count;

    TESTING("large packet table");

    /* Create a datatype for the particle struct */
    part_t = make_particle_type();

    HDassert(part_t != -1);

    /* Create a new table */
    table = H5PTcreate_fl(fid, "Packet Test Dataset2", part_t, (hsize_t)33, -1);
    H5Tclose(part_t);
    if( H5PTis_valid(table) < 0)
        goto out;

    /* Add many particles */
    for(c = 0; c < BIG_TABLE_SIZE ; c+=8)
    {
        /* Append eight particles at once*/
        err = H5PTappend(table, (size_t)8, &(testPart[0]));
        if( err < 0)
            goto out;
    }

    /* Count the number of packets in the table  */
    err = H5PTget_num_packets(table, &count);
    if( err < 0)
        goto out;
    if( count != BIG_TABLE_SIZE )
        goto out;

    /* Read particles to ensure that all of them were written correctly  */
    /* Also, ensure that H5PTcreate_fl set the current packet to */
    /* the first packet in the table                                     */
    for(c = 0; c < BIG_TABLE_SIZE; c++)
    {
        err = H5PTget_next(table, 1, &readPart);
        if(err < 0)
            goto out;

        /* Ensure that particles were read correctly */
        if( cmp_par(c % 8, 0, testPart, &readPart) != 0)
            goto out;
    }

    /* Close the table */
    err = H5PTclose(table);
    if( err < 0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    if( H5PTis_valid(table) < 0)
        H5PTclose(table);
    return -1;
}
Exemplo n.º 14
0
/**
@details
-# Set the file extension to ".h5"
-# Open the log file
-# Create the root directory in the HDF5 file
-# For each variable to be recorded
   -# Create a fixed length packet table
   -# Associate the packet table with the temporary memory buffer storing the simulation data
-# Declare the recording group to the memory manager so that the group can be checkpointed
   and restored.
*/
int Trick::DRHDF5::format_specific_init() {

#ifdef HDF5
    unsigned int ii ;
    HDF5_INFO *hdf5_info ;
    hsize_t chunk_size = 1024;
    hid_t byte_id ;
    hid_t file_names_id, param_types_id, param_units_id, param_names_id ;
    hid_t datatype ;
    herr_t ret_value ;
    hid_t s256 ;
    std::string buf;

    file_name.append(".h5") ;

    s256 = H5Tcopy(H5T_C_S1);
    H5Tset_size(s256, 256);

    // Create a new HDF5 file with the specified name; overwrite if it exists.
    if ((file = H5Fcreate(file_name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        message_publish(MSG_ERROR, "Can't open Data Record file %s.\n", file_name.c_str()) ;
        record = false ;
        return -1 ;
    }

    // All HDF5 objects live in the top-level "/" (root) group.
    root_group = H5Gopen(file, "/", H5P_DEFAULT);

    // Create a new group named "header" at the root ("/") level.
    header_group = H5Gcreate(file, "/header", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    // Create a packet table (PT) that stores byte order.
    byte_id = H5PTcreate_fl(header_group, "byte_order", s256, chunk_size, 1) ;
    // Add the byte order value to the byte packet table.
    H5PTappend( byte_id, 1, byte_order.c_str() );
    // Create a packet table (PT) that stores each parameter's file location.
    file_names_id = H5PTcreate_fl(header_group, "file_names", s256, chunk_size, 1) ;
    // Create a packet table (PT) that stores each parameter's type.
    param_types_id = H5PTcreate_fl(header_group, "param_types", s256, chunk_size, 1) ;
    // Create a packet table (PT) that stores each parameter's unit.
    param_units_id = H5PTcreate_fl(header_group, "param_units", s256, chunk_size, 1) ;
    // Create a packet table (PT) that stores each parameter's name.
    param_names_id =  H5PTcreate_fl(header_group, "param_names", s256, chunk_size, 1) ;

    // Create a table for each requested parameter.
    for (ii = 0; ii < rec_buffer.size(); ii++) {

        hdf5_info = (HDF5_INFO *)malloc(sizeof(HDF5_INFO));

        /* Case statements taken from "parameter_types.h."
         *  HDF5 Native types found in "H5Tpublic.h." */
        switch (rec_buffer[ii]->ref->attr->type) {
        case TRICK_CHARACTER:
            datatype = H5T_NATIVE_CHAR;
            break;
        case TRICK_UNSIGNED_CHARACTER:
            datatype = H5T_NATIVE_UCHAR;
            break;
        case TRICK_STRING:
            datatype = s256;
            break;
        case TRICK_SHORT:
            datatype = H5T_NATIVE_SHORT;
            break;
        case TRICK_UNSIGNED_SHORT:
            datatype = H5T_NATIVE_USHORT;
            break;
        case TRICK_ENUMERATED:
        case TRICK_INTEGER:
            datatype = H5T_NATIVE_INT;
            break;
        case TRICK_UNSIGNED_INTEGER:
            datatype = H5T_NATIVE_UINT;
            break;
        case TRICK_LONG:
            datatype = H5T_NATIVE_LONG;
            break;
        case TRICK_UNSIGNED_LONG:
            datatype = H5T_NATIVE_ULONG;
            break;
        case TRICK_FLOAT:
            datatype = H5T_NATIVE_FLOAT;
            break;
        case TRICK_DOUBLE:
            datatype = H5T_NATIVE_DOUBLE;
            break;
        case TRICK_BITFIELD:
            if (rec_buffer[ii]->ref->attr->size == sizeof(int)) {
                datatype = H5T_NATIVE_INT;
            } else if (rec_buffer[ii]->ref->attr->size == sizeof(short)) {
                datatype = H5T_NATIVE_SHORT;
            } else {
                datatype = H5T_NATIVE_CHAR;
            }
            break;
        case TRICK_UNSIGNED_BITFIELD:
            if (rec_buffer[ii]->ref->attr->size == sizeof(int)) {
                datatype = H5T_NATIVE_UINT;
            } else if (rec_buffer[ii]->ref->attr->size == sizeof(short)) {
                datatype = H5T_NATIVE_USHORT;
            } else {
                datatype = H5T_NATIVE_UCHAR;
            }
            break;
        case TRICK_LONG_LONG:
            datatype = H5T_NATIVE_LLONG;
            break;
        case TRICK_UNSIGNED_LONG_LONG:
            datatype = H5T_NATIVE_ULLONG;
            break;
        case TRICK_BOOLEAN:
#if ( __sun | __APPLE__ )
            datatype = H5T_NATIVE_INT;
#else
            datatype = H5T_NATIVE_UCHAR;
#endif
            break;
        default:
            free(hdf5_info);
            continue;
        }

        /* Create packet table(s) to store "fixed-length" packets.
         *  A separate packet table (PT) is created for each variable.
         * PARAMETERS:
         *     IN: Identifier of the file or group to create the table within.
         *     IN: The name of the dataset (i.e. variable).
         *     IN: The datatype of a packet.
         *     IN: The packet table uses HDF5 chunked storage to allow it to
         *         grow. This value allows the user to set the size of a chunk.
         *         The chunk size affects performance.
         *     IN: Compression level, a value of 0 through 9. Level 0 is faster
         *         but offers the least compression; level 9 is slower but
         *         offers maximum compression. A setting of -1 indicates that
         *         no compression is desired.
         * RETURN:
         *     Returns an identifier for the new packet table, or H5I_BADID on error.
         */
        hdf5_info->dataset = H5PTcreate_fl(root_group, rec_buffer[ii]->ref->reference, datatype, chunk_size, 1) ;

        hdf5_info->drb = rec_buffer[ii] ;
        /* Add the new parameter element to the end of the vector.
         *  This effectively increases the vector size by one. */
        parameters.push_back(hdf5_info);

        // As a bonus, add a header entry for each parameter.
        /* File Name */
        buf = "log_" + group_name ;
        H5PTappend( file_names_id, 1, buf.c_str() );
        /* Param Type */
        buf = type_string(rec_buffer[ii]->ref->attr->type, rec_buffer[ii]->ref->attr->size );
        H5PTappend( param_types_id, 1, buf.c_str() );
        /* Param Units */
        H5PTappend( param_units_id, 1, rec_buffer[ii]->ref->attr->units );
        /* Param Name */
        H5PTappend( param_names_id, 1, rec_buffer[ii]->ref->reference );

    }
    ret_value = H5PTclose( byte_id );
    ret_value = H5PTclose( file_names_id );
    ret_value = H5PTclose( param_types_id );
    ret_value = H5PTclose( param_units_id );
    ret_value = H5PTclose( param_names_id );
    ret_value = H5Gclose( header_group );
#endif

    return(0);
}
Exemplo n.º 15
0
/* AppendPackets (multiple packets)
 * Adds multiple packets to the packet table.  Takes the number of packets
 * to be added and a pointer to their location in memory.
 * Returns 0 on success, -1 on failure.
 */
int FL_PacketTable::AppendPackets(size_t numPackets, void * data)
{
    return H5PTappend(table_id, numPackets, data);
}
Exemplo n.º 16
0
int main(void)
{
 hid_t          fid;        /* File identifier */
 hid_t          ptable;     /* Packet table identifier */

 herr_t         err;        /* Function return status */
 hsize_t        count;      /* Number of records in the table */

 int            x;          /* Loop variable */

    /* Buffers to hold data */
 int writeBuffer[5];
 int readBuffer[5];

   /* Initialize buffers */
 for(x=0; x<5; x++)
 {
     writeBuffer[x]=x;
     readBuffer[x] = -1;
 }

    /* Create a file using default properties */
 fid=H5Fcreate("packet_table_FLexample.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);

    /* Create a fixed-length packet table within the file */
    /* This table's "packets" will be simple integers and it will use compression
     * level 5. */
 ptable = H5PTcreate_fl(fid, "Packet Test Dataset", H5T_NATIVE_INT, (hsize_t)100, 5);
 if(ptable == H5I_INVALID_HID)
     goto out;

    /* Write one packet to the packet table */
 err = H5PTappend(ptable, (hsize_t)1, &(writeBuffer[0]) );
 if(err < 0)
     goto out;

    /* Write several packets to the packet table */
 err = H5PTappend(ptable, (hsize_t)4, &(writeBuffer[1]) );
 if(err < 0)
     goto out;

    /* Get the number of packets in the packet table.  This should be five. */
 err = H5PTget_num_packets(ptable, &count);
 if(err < 0)
     goto out;

 printf("Number of packets in packet table after five appends: %d\n", (int)count);

    /* Initialize packet table's "current record" */
 err = H5PTcreate_index(ptable);
 if(err < 0)
     goto out;

    /* Iterate through packets, read each one back */
 for(x=0; x<5; x++)
 {
    err = H5PTget_next(ptable, (hsize_t)1, &(readBuffer[x]) );
    if(err < 0)
	goto out;

    printf("Packet %d's value is %d\n", x, readBuffer[x]);
 }

    /* Close the packet table */
 err = H5PTclose(ptable);
 if(err < 0)
     goto out;

    /* Close the file */
 H5Fclose(fid);

 return 0;

 out: /* An error has occurred.  Clean up and exit. */
    H5PTclose(ptable);
    H5Fclose(fid);
    return -1;
}
Exemplo n.º 17
0
/* AppendPackets (multiple packets)
 * Adds multiple variable-length packets to the packet table.  Takes the
 * number of
 * packets to be added and a pointer to an array of hvl_t structs in memory.
 * Returns 0 on success, negative on failure.
 */
int VL_PacketTable::AppendPackets(size_t numPackets, hvl_t * data)
{
    return H5PTappend(table_id, numPackets, data);
}