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()]));
}
Aggregations