Search in sources :

Example 1 with MergingValueIterator

use of org.csstudio.archive.reader.MergingValueIterator in project org.csstudio.display.builder by kasemir.

the class ExportJob method createValueIterator.

/**
 * @param item ModelItem
 *  @return ValueIterator for samples in the item
 *  @throws Exception on error
 */
protected ValueIterator createValueIterator(final ModelItem item) throws Exception {
    if (source == Source.PLOT || !(item instanceof PVItem))
        return new ModelSampleIterator(item, start, end);
    // Start ValueIterator for each sub-archive
    final ArchiveDataSource[] archives = ((PVItem) item).getArchiveDataSources();
    final List<ValueIterator> iters = new ArrayList<>();
    Exception error = null;
    for (ArchiveDataSource archive : archives) {
        // Create reader, remember to close it when done
        final ArchiveReader reader = ArchiveRepository.getInstance().getArchiveReader(archive.getUrl());
        archive_readers.add(reader);
        // Create ValueIterator
        try {
            ValueIterator iter;
            if (source == Source.OPTIMIZED_ARCHIVE && optimize_parameter > 1)
                iter = reader.getOptimizedValues(archive.getKey(), item.getName(), start, end, (int) optimize_parameter);
            else {
                iter = reader.getRawValues(archive.getKey(), item.getName(), start, end);
                if (source == Source.LINEAR_INTERPOLATION && optimize_parameter >= 1)
                    iter = new LinearValueIterator(iter, TimeDuration.ofSeconds(optimize_parameter));
            }
            iters.add(iter);
        } catch (Exception ex) {
            Logger.getLogger(getClass().getName()).log(Level.FINE, "Export error for " + item.getName(), ex);
            if (error == null)
                error = ex;
        }
    }
    // If none of the iterators work out, report the first error that we found
    if (iters.isEmpty() && error != null)
        throw error;
    // Return a merging iterator
    return new MergingValueIterator(iters.toArray(new ValueIterator[iters.size()]));
}
Also used : ArchiveReader(org.csstudio.archive.reader.ArchiveReader) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) ValueIterator(org.csstudio.archive.reader.ValueIterator) MergingValueIterator(org.csstudio.archive.reader.MergingValueIterator) LinearValueIterator(org.csstudio.archive.reader.LinearValueIterator) MergingValueIterator(org.csstudio.archive.reader.MergingValueIterator) PVItem(org.csstudio.trends.databrowser3.model.PVItem) LinearValueIterator(org.csstudio.archive.reader.LinearValueIterator)

Aggregations

ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ArchiveReader (org.csstudio.archive.reader.ArchiveReader)1 LinearValueIterator (org.csstudio.archive.reader.LinearValueIterator)1 MergingValueIterator (org.csstudio.archive.reader.MergingValueIterator)1 ValueIterator (org.csstudio.archive.reader.ValueIterator)1 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)1 PVItem (org.csstudio.trends.databrowser3.model.PVItem)1