예제 #1
0
// Try to determine the period and a good guess
// for the number of samples for a channel.
void determine_period_and_samples(IndexFile &index,
                                  const stdString &channel,
                                  double &period, size_t &num_samples)
{
    period      = 1.0; // initial guess
    num_samples = 10;
    // Whatever fails only means that there is no data,
    // so the initial guess remains OK.
    // Otherwise we peek into the last datablock.
    stdString directory;
    AutoPtr<RTree> tree(index.getTree(channel, directory));
    if (!tree)
        return;
    RTree::Node node(tree->getM(), false);
    RTree::Datablock block;
    int i;
    if (!tree->getLastDatablock(node, i, block))
        return;
    AutoPtr<DataHeader> header;
    if (!(header = get_dataheader(directory,
                                  block.data_filename, block.data_offset)))
        return;
    period = header->data.period;
    num_samples = header->data.num_samples;
    if (verbose > 2)
        printf("Last source buffer: Period %g, %lu samples.\n",
               period, (unsigned long) num_samples);
}
예제 #2
0
unsigned long dump_datablocks_for_channel(IndexFile &index,
                                          const stdString &channel_name,
                                          unsigned long &direct_count,
                                          unsigned long &chained_count)
{
    DataFile *datafile;
    AutoPtr<DataHeader> header;
    direct_count = chained_count = 0;
    stdString directory;
    AutoPtr<RTree> tree(index.getTree(channel_name, directory));
    if (! tree)
        return 0;
    RTree::Datablock block;
    RTree::Node node(tree->getM(), true);
    stdString start, end;
    int idx;
    bool ok;
    if (verbose > 1)
        printf("RTree M for channel '%s': %d\n", channel_name.c_str(),
               tree->getM());
    if (verbose > 2)
        printf("Datablocks for channel '%s':\n", channel_name.c_str());
    for (ok = tree->getFirstDatablock(node, idx, block);
         ok;
         ok = tree->getNextDatablock(node, idx, block))
    {
        ++direct_count;
        if (verbose > 2)
            printf("'%s' @ 0x%lX: Indexed range %s - %s\n",
                   block.data_filename.c_str(),
                   (unsigned long)block.data_offset,
                   epicsTimeTxt(node.record[idx].start, start),
                   epicsTimeTxt(node.record[idx].end, end));
        if (verbose > 3)
        {
            datafile = DataFile::reference(directory,
                                           block.data_filename,
                                           false);
            header = datafile->getHeader(block.data_offset);
            datafile->release();
            if (header)
            {
                header->show(stdout, true);
                header = 0;
            }
            else
                printf("Cannot read header in data file.\n");
        }
        bool first_hidden_block = true;
        while (tree->getNextChainedBlock(block))
        {
            if (first_hidden_block && verbose > 2)
            {
                first_hidden_block = false;
                printf("Hidden blocks with smaller time range:\n");
            }
            ++chained_count;
            if (verbose > 2)
            {
                printf("---  '%s' @ 0x%lX\n",
                       block.data_filename.c_str(),
                       (unsigned long)block.data_offset);
                if (verbose > 3)
                {
                    datafile = DataFile::reference(directory,
                                                   block.data_filename,
                                                   false);
                    header = datafile->getHeader(block.data_offset);
                    if (header)
                    {
                        header->show(stdout, false);
                        header = 0;
                    }
                    else
                        printf("Cannot read header in data file.\n");
                    datafile->release();
                }   
            }
        }
        printf("\n");
    }
    return direct_count + chained_count;
}