use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.
the class ExportJob method printItemInfo.
/**
* Print info about item
* @param out PrintStream for output
* @param item ModelItem
*/
protected void printItemInfo(final PrintStream out, final ModelItem item) {
out.println(comment + "Channel: " + item.getName());
// If display name differs from PV, show the _resolved_ version
if (!item.getName().equals(item.getDisplayName()))
out.println(comment + "Name : " + item.getResolvedDisplayName());
if (item instanceof PVItem) {
final PVItem pv = (PVItem) item;
out.println(comment + "Archives:");
final ArchiveDataSource[] archives = pv.getArchiveDataSources();
for (int i = 0; i < archives.length; ++i) {
out.println(comment + (i + 1) + ") " + archives[i].getName());
out.println(comment + " URL: " + archives[i].getUrl());
out.println(comment + " Key: " + archives[i].getKey());
}
}
out.println(comment);
}
use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.
the class SampleImportAction method run.
@Override
public void run() {
// Prompt for file
final IPath path = SingleSourcePlugin.getUIHelper().openDialog(shell, SWT.OPEN, null, "*", NLS.bind(Messages.ImportActionFileSelectorTitleFmt, description));
if (path == null)
return;
try {
// Add to first empty axis, or create new axis
final AxisConfig axis = model.getEmptyAxis().orElseGet(() -> new AddAxisCommand(op_manager, model).getAxis());
// Add archivedatasource for "import:..." and let that load the file
final String url = ImportArchiveReaderFactory.createURL(type, path.toString());
final ArchiveDataSource imported = new ArchiveDataSource(url, 1, type);
// Add PV Item with data to model
AddModelItemCommand.forPV(shell, op_manager, model, type, Preferences.getScanPeriod(), axis, imported);
} catch (Exception ex) {
ExceptionDetailsErrorDialog.openError(shell, Messages.Error, ex);
}
}
use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.
the class Preferences method getArchives.
public static ArchiveDataSource[] getArchives() {
final ArrayList<ArchiveDataSource> archives = new ArrayList<ArchiveDataSource>();
final IPreferencesService prefs = Platform.getPreferencesService();
final String urls = prefs.getString(Activator.PLUGIN_ID, ARCHIVES, "", null);
// data source specs are separated by '*'
final String[] specs = urls.split(ITEM_SEPARATOR_RE);
for (String spec : specs) {
// Each spec is "<name>|<key>|<url>"
if (spec.length() <= 0)
continue;
try {
final String[] segs = spec.split(COMPONENT_SEPARATOR_RE);
final String name = segs[0];
final int key = Integer.parseInt(segs[1]);
final String url = segs[2];
archives.add(new ArchiveDataSource(url, key, name));
} catch (Throwable ex) {
throw new Error("Error in archive preference '" + spec + "'");
}
}
return archives.toArray(new ArchiveDataSource[archives.size()]);
}
use of org.csstudio.trends.databrowser3.model.ArchiveDataSource 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()]));
}
use of org.csstudio.trends.databrowser3.model.ArchiveDataSource in project org.csstudio.display.builder by kasemir.
the class SearchJob method run.
/**
* {@inheritDoc}
*/
@Override
protected IStatus run(final IProgressMonitor monitor) {
final ArrayList<ChannelInfo> channels = new ArrayList<>();
monitor.beginTask(Messages.Search, archives.length);
for (ArchiveDataSource archive : archives) {
try (final ArchiveReader reader = ArchiveRepository.getInstance().getArchiveReader(archive.getUrl())) {
monitor.subTask(archive.getName());
final String[] names;
if (pattern_is_glob)
names = reader.getNamesByPattern(archive.getKey(), pattern);
else
names = reader.getNamesByRegExp(archive.getKey(), pattern);
for (String name : names) channels.add(new ChannelInfo(name, archive));
monitor.worked(1);
} catch (final Exception ex) {
monitor.setCanceled(true);
monitor.done();
archiveServerError(archive.getUrl(), ex);
return Status.CANCEL_STATUS;
}
}
receivedChannelInfos((ChannelInfo[]) channels.toArray(new ChannelInfo[channels.size()]));
monitor.done();
return Status.OK_STATUS;
}
Aggregations