Search in sources :

Example 6 with ArchiveDataSource

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);
}
Also used : ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 7 with ArchiveDataSource

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);
    }
}
Also used : AddAxisCommand(org.csstudio.trends.databrowser3.propsheet.AddAxisCommand) IPath(org.eclipse.core.runtime.IPath) AxisConfig(org.csstudio.trends.databrowser3.model.AxisConfig) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource)

Example 8 with ArchiveDataSource

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()]);
}
Also used : ArrayList(java.util.ArrayList) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 9 with ArchiveDataSource

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

Example 10 with ArchiveDataSource

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;
}
Also used : ArchiveReader(org.csstudio.archive.reader.ArchiveReader) ArrayList(java.util.ArrayList) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo)

Aggregations

ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)17 PVItem (org.csstudio.trends.databrowser3.model.PVItem)8 ArrayList (java.util.ArrayList)6 ChannelInfo (org.csstudio.trends.databrowser3.model.ChannelInfo)4 TestProperties (org.csstudio.apputil.test.TestProperties)3 Test (org.junit.Test)3 ArchiveReader (org.csstudio.archive.reader.ArchiveReader)2 AxisConfig (org.csstudio.trends.databrowser3.model.AxisConfig)2 FormulaItem (org.csstudio.trends.databrowser3.model.FormulaItem)2 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)2 AddAxisCommand (org.csstudio.trends.databrowser3.propsheet.AddAxisCommand)2 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2 ViewerCell (org.eclipse.jface.viewers.ViewerCell)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 PartInitException (org.eclipse.ui.PartInitException)2 PrintWriter (java.io.PrintWriter)1