Skip to content
Snippets Groups Projects
Commit eb39c415 authored by Katy Saintin's avatar Katy Saintin
Browse files

CEA : Update IRFU plugin for EPICS and Appliance plugins see issue...

CEA : Update IRFU plugin for EPICS and Appliance plugins see issue https://drf-gitlab.cea.fr/LDISC/rdepics/-/issues/592
parent 56806a63
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,6 @@ import fr.cea.irfu.interfaces.AbstractIrfuDataSource; ...@@ -15,7 +15,6 @@ import fr.cea.irfu.interfaces.AbstractIrfuDataSource;
import fr.cea.irfu.interfaces.ParameterAccessor; import fr.cea.irfu.interfaces.ParameterAccessor;
import fr.soleil.data.service.IKey; import fr.soleil.data.service.IKey;
import heps.epics.ca.client.ProcessVariableManager; import heps.epics.ca.client.ProcessVariableManager;
import heps.epics.ca.interfaces.ICafeProcessVariable;
public abstract class AbstractEpicsDataSource<T> extends AbstractIrfuDataSource<T> { public abstract class AbstractEpicsDataSource<T> extends AbstractIrfuDataSource<T> {
...@@ -37,11 +36,7 @@ public abstract class AbstractEpicsDataSource<T> extends AbstractIrfuDataSource< ...@@ -37,11 +36,7 @@ public abstract class AbstractEpicsDataSource<T> extends AbstractIrfuDataSource<
@Override @Override
protected Object readData() { protected Object readData() {
Object readValue = null; Object readValue = EpicsDataSourceProducer.getValue(pvName);
ICafeProcessVariable<?> pv = ProcessVariableManager.getInstance().getPv(pvName);
if(pv != null ) {
readValue = pv.getValue();
}
return readValue; return readValue;
} }
...@@ -57,5 +52,4 @@ public abstract class AbstractEpicsDataSource<T> extends AbstractIrfuDataSource< ...@@ -57,5 +52,4 @@ public abstract class AbstractEpicsDataSource<T> extends AbstractIrfuDataSource<
} }
} }
...@@ -16,22 +16,27 @@ import java.util.HashMap; ...@@ -16,22 +16,27 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import fr.soleil.data.exception.UnhandledDataTypeException;
import fr.soleil.data.service.IConstantSourceProducer;
import fr.soleil.data.service.IDataSourceProducer; import fr.soleil.data.service.IDataSourceProducer;
import fr.soleil.data.service.IKey; import fr.soleil.data.service.IKey;
import fr.soleil.data.source.AbstractDataSource; import fr.soleil.data.source.AbstractDataSource;
import heps.epics.ca.client.ProcessVariableManager; import heps.epics.ca.client.ProcessVariableManager;
import heps.epics.ca.interfaces.DataType; import heps.epics.ca.interfaces.DataType;
import heps.epics.ca.interfaces.ICafeArrayProcessVariable;
import heps.epics.ca.interfaces.ICafeProcessVariable;
import heps.epics.ca.interfaces.ICafeProcessVariableListener; import heps.epics.ca.interfaces.ICafeProcessVariableListener;
import heps.epics.ca.interfaces.IRecord; import heps.epics.ca.interfaces.IRecord;
import heps.epics.ca.interfaces.ISimpleRecord; import heps.epics.ca.interfaces.ISimpleRecord;
import heps.epics.ca.interfaces.IocEvent; import heps.epics.ca.interfaces.IocEvent;
public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProcessVariableListener { public class EpicsDataSourceProducer implements IDataSourceProducer, IConstantSourceProducer, ICafeProcessVariableListener {
public static final String EPICS_ID = "EPICS_ID"; public static final String EPICS_ID = "EPICS_ID";
private static final Map<IKey, AbstractEpicsDataSource<?>> dataSourceMap = new HashMap<IKey, AbstractEpicsDataSource<?>>(); private static final Map<IKey, AbstractEpicsDataSource<?>> dataSourceMap = new HashMap<IKey, AbstractEpicsDataSource<?>>();
private static final Map<String, IKey> keyMap = new HashMap<>(); private static final Map<String, IKey> keyMap = new HashMap<>();
private static List<String> pvList = new ArrayList<>(); private static List<String> pvList = new ArrayList<>();
private static Map<String, Object> valueMap = new HashMap<>();
@Override @Override
public AbstractDataSource<?> createDataSource(IKey arg0) { public AbstractDataSource<?> createDataSource(IKey arg0) {
...@@ -40,6 +45,11 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces ...@@ -40,6 +45,11 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces
if (dataSource == null) { if (dataSource == null) {
IKey parseKey = parseKey(arg0); IKey parseKey = parseKey(arg0);
if (parseKey != null) { if (parseKey != null) {
// Manage spectrum data https://drf-gitlab.cea.fr/LDISC/rdepics/-/issues/592
org.cdma.gui.databrowser.interfaces.DataType dataType2 = EpicsKey.getDataType(arg0);
if (dataType2 == org.cdma.gui.databrowser.interfaces.DataType.SPECTRUM) {// SPECTRUM
dataSource = new EpicsDoubleArrayDataSource(parseKey);
} else {
ISimpleRecord record = EpicsKey.getRecord(parseKey); ISimpleRecord record = EpicsKey.getRecord(parseKey);
if (record.isBoolean()) { if (record.isBoolean()) {
dataSource = new EpicsBooleanDataSource(parseKey); dataSource = new EpicsBooleanDataSource(parseKey);
...@@ -89,6 +99,8 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces ...@@ -89,6 +99,8 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces
break; break;
} }
} }
}
dataSourceMap.put(parseKey, dataSource); dataSourceMap.put(parseKey, dataSource);
String pvName = EpicsKey.getKeyName(arg0); String pvName = EpicsKey.getKeyName(arg0);
keyMap.put(pvName, parseKey); keyMap.put(pvName, parseKey);
...@@ -96,6 +108,7 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces ...@@ -96,6 +108,7 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces
pvList.add(pvName); pvList.add(pvName);
} }
ProcessVariableManager.GENERATE_LOGS = false;
ProcessVariableManager.getInstance().readAsynchroneValue(this, pvList); ProcessVariableManager.getInstance().readAsynchroneValue(this, pvList);
} }
} }
...@@ -136,7 +149,8 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces ...@@ -136,7 +149,8 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces
public boolean isSourceSettable(IKey key) { public boolean isSourceSettable(IKey key) {
boolean settable = false; boolean settable = false;
ISimpleRecord record = EpicsKey.getRecord(key); ISimpleRecord record = EpicsKey.getRecord(key);
settable = record != null && (!record.isReadOnly() || (record instanceof IRecord && ((IRecord)record).getLinkedRecord() != null)); settable = record != null && (!record.isReadOnly()
|| (record instanceof IRecord && ((IRecord) record).getLinkedRecord() != null));
return settable; return settable;
} }
...@@ -154,7 +168,24 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces ...@@ -154,7 +168,24 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces
@Override @Override
public void processVariableChange(IocEvent event) { public void processVariableChange(IocEvent event) {
String message = event.getMessage(); String message = event.getMessage();
//System.out.println("processVariableChange " + message);
Object source = event.getSource();
//System.out.println("processVariableChange " + source);
if(source instanceof ICafeProcessVariable) {
if (source instanceof ICafeArrayProcessVariable) {
ICafeArrayProcessVariable arrayPV = (ICafeArrayProcessVariable) source;
double[] readValue = arrayPV.getValueAsDoubleArray();
if (readValue != null && readValue.length > 0) {
valueMap.put(message, readValue);
}
}
else {
Object readValue = ((ICafeProcessVariable<?>)source).getValue();
valueMap.put(message, readValue);
}
}
IKey iKey = keyMap.get(message); IKey iKey = keyMap.get(message);
if (iKey != null) { if (iKey != null) {
AbstractEpicsDataSource<?> abstractEpicsDataSource = dataSourceMap.get(iKey); AbstractEpicsDataSource<?> abstractEpicsDataSource = dataSourceMap.get(iKey);
...@@ -164,12 +195,56 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces ...@@ -164,12 +195,56 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces
} }
} }
public static Object getValue(String pvName) {
return valueMap.get(pvName);
}
public static boolean isDataSourceOpened(IKey key) { public static boolean isDataSourceOpened(IKey key) {
boolean opened = false; boolean opened = false;
String keyName = EpicsKey.getKeyName(key); ISimpleRecord record = EpicsKey.getRecord(key);
opened = keyName != null && keyMap.containsKey(keyName); String name = record != null ? record.getName() : null;
opened = name != null && keyMap.containsKey(name);
return opened; return opened;
} }
public static void closeDataSource(IKey key) {
if (isDataSourceOpened(key)) {
ISimpleRecord record = EpicsKey.getRecord(key);
String keyName = record != null ? record.getName() : null;
if (keyName != null) {
IKey iKey = keyMap.get(keyName);
// AbstractEpicsDataSource<?> abstractEpicsDataSource = dataSourceMap.get(iKey);
dataSourceMap.remove(iKey);
pvList.remove(keyName);
keyMap.remove(keyName);
ProcessVariableManager.getInstance().deleteRecord(keyName);
}
}
}
@Override
public AbstractDataSource<?> createDataSource(IKey arg0, boolean arg1) throws UnhandledDataTypeException {
return createDataSource( arg0);
}
@Override
public AbstractDataSource<?> getExistingSource(IKey arg0) {
AbstractDataSource<?> datasource = null;
if (isDataSourceOpened(arg0)) {
ISimpleRecord record = EpicsKey.getRecord(arg0);
String keyName = record != null ? record.getName() : null;
if (keyName != null) {
IKey iKey = keyMap.get(keyName);
datasource = dataSourceMap.get(iKey);
}
}
return datasource;
}
@Override
public void removeDataSource(IKey arg0) {
closeDataSource(arg0);
}
} }
/*******************************************************************************
* Copyright (c) 2019 by CEA .
* The full license specifying the redistribution, modification, usage and other rights
* and obligations is included with the distribution of this project in the file "license.txt"
*
* THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN
*
* THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE
* ASSUMES NO RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE USE,
* MODIFICATION,OR REDISTRIBUTION OF THIS SOFTWARE.
******************************************************************************/
package fr.cea.irfu.epics;
import fr.soleil.data.container.matrix.AbstractNumberMatrix;
import fr.soleil.data.container.matrix.DoubleMatrix;
import fr.soleil.data.service.GenericDescriptor;
import fr.soleil.data.service.IKey;
public class EpicsDoubleArrayDataSource extends AbstractEpicsDataSource<AbstractNumberMatrix<?>> {
private AbstractNumberMatrix<?> matrix = null;
protected static final GenericDescriptor DEFAULT_DATA_TYPE = new GenericDescriptor(AbstractNumberMatrix.class,
new GenericDescriptor(Number.class));
public EpicsDoubleArrayDataSource(IKey key) {
super(key);
}
public String getFormat() {
return "%5.2f";
}
@Override
public GenericDescriptor getDataType() {
return DEFAULT_DATA_TYPE;
}
@Override
protected AbstractNumberMatrix<?> convertValue(Object value) {
if (matrix == null) {
// TODO manage other format
matrix = new DoubleMatrix(Double.TYPE);
matrix.setName(pvName);
}
// See issue https://drf-gitlab.cea.fr/LDISC/rdepics/issues/420
double[] fullPvValues = value instanceof double[] ? (double[]) value : null;
//System.out.println("fullPvValues =" + Arrays.toString(fullPvValues));
if (fullPvValues != null && fullPvValues.length > 0) {
try {
matrix.setFlatValue(fullPvValues, 1, fullPvValues.length);
} catch (Exception e) {
}
}
return matrix;
}
}
...@@ -13,6 +13,7 @@ package fr.cea.irfu.epics; ...@@ -13,6 +13,7 @@ package fr.cea.irfu.epics;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -21,14 +22,14 @@ import fr.soleil.data.service.IKey; ...@@ -21,14 +22,14 @@ import fr.soleil.data.service.IKey;
import heps.epics.ca.interfaces.DataType; import heps.epics.ca.interfaces.DataType;
import heps.epics.ca.interfaces.IRecord; import heps.epics.ca.interfaces.IRecord;
import heps.epics.ca.interfaces.ISimpleRecord; import heps.epics.ca.interfaces.ISimpleRecord;
import heps.epics.ca.ioc.FieldEnumeration.RecordType;
public class EpicsKey extends IrfuKey { public class EpicsKey extends IrfuKey {
private static final String RECORD_PROP = "record"; private static final String RECORD_PROP = "record";
private static final String WRITE_KEY = "writeKey"; private static final String WRITE_KEY = "writeKey";
private static final String producerId = EpicsDataSourceProducer.EPICS_ID; private static final String producerId = EpicsDataSourceProducer.EPICS_ID;
private static final Map<String, org.cdma.gui.databrowser.interfaces.DataType> recordTypeMap = new HashMap<>();
public EpicsKey() { public EpicsKey() {
super(producerId); super(producerId);
...@@ -75,7 +76,8 @@ public class EpicsKey extends IrfuKey { ...@@ -75,7 +76,8 @@ public class EpicsKey extends IrfuKey {
for (ISimpleRecord param : paramList) { for (ISimpleRecord param : paramList) {
createParameterKey = createParameterKey(deviceKey, param); createParameterKey = createParameterKey(deviceKey, param);
if (!aparameterList.contains(createParameterKey)) { if (!aparameterList.contains(createParameterKey)) {
boolean simpleKey = (param instanceof IRecord && ((IRecord)param).getGeneratedRecord() == null) || !(param instanceof IRecord); boolean simpleKey = (param instanceof IRecord && ((IRecord) param).getGeneratedRecord() == null)
|| !(param instanceof IRecord);
if (param.isReadOnly() || simpleKey) { if (param.isReadOnly() || simpleKey) {
aparameterList.add(createParameterKey); aparameterList.add(createParameterKey);
...@@ -91,6 +93,34 @@ public class EpicsKey extends IrfuKey { ...@@ -91,6 +93,34 @@ public class EpicsKey extends IrfuKey {
} }
} }
public static org.cdma.gui.databrowser.interfaces.DataType getDataType(final IKey key) {
org.cdma.gui.databrowser.interfaces.DataType dataType = org.cdma.gui.databrowser.interfaces.DataType.SCALAR;
// Manage spectrum format see issue
// https://drf-gitlab.cea.fr/LDISC/rdepics/-/issues/592
ISimpleRecord record = getRecord(key);
String pvName = record != null ? record.getName() : null;
if (pvName != null && !pvName.trim().isEmpty()) {
dataType = recordTypeMap.get(pvName);
if (dataType == null) {
// Read the value
try {
// System.out.println("variableName=" + variableName);
//Can take a while and freeze the application
RecordType recordType = record.getRecordType();
//System.out.println("recordType=" + recordType);
dataType = recordType == RecordType.waveForm ? org.cdma.gui.databrowser.interfaces.DataType.SPECTRUM : org.cdma.gui.databrowser.interfaces.DataType.SCALAR;
} catch (Exception e) {
dataType = org.cdma.gui.databrowser.interfaces.DataType.SCALAR;
}
if(dataType != null) {
recordTypeMap.put(pvName, dataType);
}
}
}
return dataType;
}
public static String getKeyName(final IKey key) { public static String getKeyName(final IKey key) {
String name = null; String name = null;
if (key != null && key.containProperty(NAME_PROP)) { if (key != null && key.containProperty(NAME_PROP)) {
...@@ -115,7 +145,6 @@ public class EpicsKey extends IrfuKey { ...@@ -115,7 +145,6 @@ public class EpicsKey extends IrfuKey {
return rec; return rec;
} }
public static IKey getDeviceKey(final IKey key) { public static IKey getDeviceKey(final IKey key) {
IKey deviceKey = null; IKey deviceKey = null;
if (key instanceof EpicsKey) { if (key instanceof EpicsKey) {
......
...@@ -18,7 +18,7 @@ import java.util.Map; ...@@ -18,7 +18,7 @@ import java.util.Map;
import fr.soleil.data.service.BasicKey; import fr.soleil.data.service.BasicKey;
import fr.soleil.data.service.IKey; import fr.soleil.data.service.IKey;
public class IrfuKey extends BasicKey { public class IrfuKey extends BasicKey implements Comparable<IKey> {
// ProducerId // ProducerId
private final static Map<String, Map<String, IKey>> deviceKeyMap = new HashMap<>(); private final static Map<String, Map<String, IKey>> deviceKeyMap = new HashMap<>();
...@@ -83,6 +83,7 @@ public class IrfuKey extends BasicKey { ...@@ -83,6 +83,7 @@ public class IrfuKey extends BasicKey {
@Override @Override
public String getInformationKey() { public String getInformationKey() {
//new Exception("getInformationKey").printStackTrace();
String informationKey = ""; String informationKey = "";
// IKey deviceKey = getDeviceKey(this); // IKey deviceKey = getDeviceKey(this);
String keyName = getKeyName(this); String keyName = getKeyName(this);
...@@ -94,4 +95,12 @@ public class IrfuKey extends BasicKey { ...@@ -94,4 +95,12 @@ public class IrfuKey extends BasicKey {
return informationKey; return informationKey;
} }
@Override
public int compareTo(IKey o) {
String tmpInformation = this.getInformationKey();
return tmpInformation.compareTo(o.getInformationKey());
}
} }
...@@ -107,9 +107,8 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser { ...@@ -107,9 +107,8 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser {
ITreeNode parameterNode = new GroupTreeNode(); ITreeNode parameterNode = new GroupTreeNode();
parameterNode.setName("records"); parameterNode.setName("records");
sourceNode.addNodes(parameterNode); sourceNode.addNodes(parameterNode);
ITreeNode trendsNode = new GroupTreeNode(); ITreeNode trendsNode = null;
trendsNode.setName("trends");
sourceNode.addNodes(trendsNode);
// TODO Gestion des trends plus tard // TODO Gestion des trends plus tard
// ITreeNode trendNode = new GroupTreeNode(); // ITreeNode trendNode = new GroupTreeNode();
// trendNode.setName("trend"); // trendNode.setName("trend");
...@@ -130,13 +129,21 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser { ...@@ -130,13 +129,21 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser {
child.setData(paramKey); child.setData(paramKey);
parameterNode.addNodes(child); parameterNode.addNodes(child);
DataType keyType = getKeyType(paramKey);
//Do not create trend for spectrum
if (keyType == DataType.SCALAR) {
historicKey = new HistoryKey(paramKey); historicKey = new HistoryKey(paramKey);
child = new ItemTreeNode(); child = new ItemTreeNode();
child.setName(paramName + "_trend"); child.setName(paramName + "_trend");
child.setData(historicKey); child.setData(historicKey);
if (trendsNode == null) {
trendsNode = new GroupTreeNode();
trendsNode.setName("trends");
sourceNode.addNodes(trendsNode);
}
trendsNode.addNodes(child); trendsNode.addNodes(child);
} }
}
} }
} }
...@@ -225,25 +232,26 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser { ...@@ -225,25 +232,26 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser {
@Override @Override
public boolean isSourceOpened(IKey sourceKey) { public boolean isSourceOpened(IKey sourceKey) {
// TODO Auto-generated method stub
return EpicsDataSourceProducer.isDataSourceOpened(sourceKey); return EpicsDataSourceProducer.isDataSourceOpened(sourceKey);
} }
@Override @Override
public void closeSource(IKey sourceKey) { public void closeSource(IKey sourceKey) {
// TODO Auto-generated method stub // Close refreshing
EpicsDataSourceProducer.closeDataSource(sourceKey);
} }
@Override @Override
public DataType getKeyType(IKey key) { public DataType getKeyType(IKey key) {
// TODO gerer les autres formats // Manage waveform see https://drf-gitlab.cea.fr/LDISC/rdepics/-/issues/592
DataType dataType = DataType.SCALAR; DataType dataType = DataType.SCALAR;
if (key instanceof HistoryKey) { if (key instanceof HistoryKey) {
IKey history = ((HistoryKey) key).getHistory(); IKey history = ((HistoryKey) key).getHistory();
if (producer.isSourceCreatable(history)) { if (producer.isSourceCreatable(history)) {
dataType = DataType.SPECTRUM; dataType = DataType.SPECTRUM;
} }
} else {
dataType = EpicsKey.getDataType(key);
} }
return dataType; return dataType;
} }
......
...@@ -102,7 +102,7 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker { ...@@ -102,7 +102,7 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker {
// Creation d'une cle parent avec le host // Creation d'une cle parent avec le host
String text = hostField.getText(); String text = hostField.getText();
String host = text != null && !text.isEmpty() ? text : LOCAL_HOST; String host = text != null && !text.isEmpty() ? text.trim() : LOCAL_HOST;
File selectedFile = getFileChooser().getSelectedFile(); File selectedFile = getFileChooser().getSelectedFile();
if (acceptFile(selectedFile)) { if (acceptFile(selectedFile)) {
...@@ -136,11 +136,11 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker { ...@@ -136,11 +136,11 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker {
String userSourceName = null; String userSourceName = null;
Map<String, ISimpleRecord> recordMap = null; Map<String, ISimpleRecord> recordMap = null;
for (String recordname : split) { for (String recordname : split) {
if (!foundPV(recordname)) { if (!foundPV(recordname.trim())) {
recordForName = PlcParserApi.getRecordForName(recordname); recordForName = PlcParserApi.getRecordForName(recordname.trim());
if (recordForName == null) { if (recordForName == null) {
ProcessVariableManager.getInstance(host);//Init cacontext with host ProcessVariableManager.getInstance(host);//Init cacontext with host
ISimpleRecord createRecord = ProcessVariableManager.getInstance().createRecord(recordname); ISimpleRecord createRecord = ProcessVariableManager.getInstance().createRecord(recordname.trim());
if(createRecord != null) { if(createRecord != null) {
if (userSourceKey == null) { if (userSourceKey == null) {
userSourceName = USER_PVLIST + lastIndex; userSourceName = USER_PVLIST + lastIndex;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment