Skip to content

Commit

Permalink
Merge pull request #7 from jembishop/get-data-multiple-pvs
Browse files Browse the repository at this point in the history
Add support for fetching multiple PVs from archiver
  • Loading branch information
slacmshankar authored Mar 5, 2024
2 parents d2f28bc + 98b0e88 commit f4cec44
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@
package org.epics.archiverappliance.retrieval.client;

import java.sql.Timestamp;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* Main interface for client retrieving data using the PB/HTTP protocol.
* @author mshankar
*/
public interface DataRetrieval {
public abstract class DataRetrieval {
/**
* Get data for PV pvName from starttime to endtime. By default, we expect to get raw data.
* @param pvName The name of the pv
* @param startTime Start time of request
* @param endTime End time of request
* @return Return an iterator over the data.
*/
public GenMsgIterator getDataForPV(String pvName, Timestamp startTime, Timestamp endTime);
public final GenMsgIterator getDataForPV(String pvName, Timestamp startTime, Timestamp endTime) {
return getDataForPV(pvName, startTime, endTime, false);
};
/**
* Get data for PV pvName from starttime to endtime using the system defined sparsification operator.
* @param pvName The name of the pv
Expand All @@ -31,8 +35,10 @@ public interface DataRetrieval {
* @param useReducedDataSet - If true, use the server defined sparsification operator...
* @return Return an iterator over the data.
*/
public GenMsgIterator getDataForPV(
String pvName, Timestamp startTime, Timestamp endTime, boolean useReducedDataSet);
public final GenMsgIterator getDataForPV(
String pvName, Timestamp startTime, Timestamp endTime, boolean useReducedDataSet) {
return getDataForPV(pvName, startTime, endTime, useReducedDataSet, null);
}

/**
* Get data for PV pvName from starttime to endtime using the system defined sparsification operator; pass additional params in the HTTP call.
Expand All @@ -43,10 +49,30 @@ public GenMsgIterator getDataForPV(
* @param otherParams - Any other name/value pairs that are passed onto the server.
* @return Return an iterator over the data.
*/
public GenMsgIterator getDataForPV(
public final GenMsgIterator getDataForPV(
String pvName,
Timestamp startTime,
Timestamp endTime,
boolean useReducedDataSet,
Map<String, String> otherParams) {
return getDataForPVs(Collections.singletonList(pvName), startTime, endTime, useReducedDataSet, otherParams);
}

/**
* Get data for PVs in pvNames from starttime to endtime using the system defined sparsification operator; pass additional params in the HTTP call.
* NOTE: The data for all the PVs will be concatenated together. To identify which PV is currently being read, you must register your own
* {@code InfoChangeHandler} to the returned {@code GenMsgIterator} using {@code onInfoChange}.
* @param pvName The name of the pv
* @param startTime Start time of request
* @param endTime End time of request
* @param useReducedDataSet - If true, use the server defined sparsification operator...
* @param otherParams - Any other name/value pairs that are passed onto the server.
* @return Return an iterator over the data.
*/
public abstract GenMsgIterator getDataForPVs(
List<String> pvNames,
Timestamp startTime,
Timestamp endTime,
boolean useReducedDataSet,
Map<String, String> otherParams);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -23,7 +24,7 @@
*
* @author mshankar
*/
public class RawDataRetrieval implements DataRetrieval {
public class RawDataRetrieval extends DataRetrieval {
private static final Logger logger = Logger.getLogger(RawDataRetrieval.class.getName());
private final String accessURL;

Expand All @@ -36,31 +37,24 @@ private static String convertToUTC(Timestamp time) {
}

@Override
public GenMsgIterator getDataForPV(String pvName, Timestamp startTime, Timestamp endTime) {
return getDataForPV(pvName, startTime, endTime, false, null);
}

@Override
public GenMsgIterator getDataForPV(
String pvName, Timestamp startTime, Timestamp endTime, boolean useReducedDataSet) {
return getDataForPV(pvName, startTime, endTime, useReducedDataSet, null);
}

@Override
public GenMsgIterator getDataForPV(
String pvName,
public final GenMsgIterator getDataForPVs(
List<String> pvNames,
Timestamp startTime,
Timestamp endTime,
boolean useReducedDataSet,
Map<String, String> otherParams) {
// We'll use java.net for now.
StringWriter buf = new StringWriter();
String encode = URLEncoder.encode(pvName, StandardCharsets.UTF_8);
buf.append(accessURL);
// If the access url has no query parameters then start new query, else append to existing
var first_encoded = URLEncoder.encode(pvNames.get(0), StandardCharsets.UTF_8);
if (accessURL.contains("?")) {
buf.append("&pv=").append(encode);
buf.append("&pv=").append(first_encoded);
} else {
buf.append("?pv=").append(encode);
buf.append("?pv=").append(first_encoded);
}
for (var pvName: pvNames) {
buf.append("&pv=").append(URLEncoder.encode(pvName, StandardCharsets.UTF_8));
}
buf.append("&from=").append(convertToUTC(startTime)).append("&to=").append(convertToUTC(endTime));
if (useReducedDataSet) {
Expand Down

0 comments on commit f4cec44

Please sign in to comment.