-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eugene Tan
committed
Aug 6, 2018
0 parents
commit 41c3471
Showing
13,978 changed files
with
2,419,062 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
classdef ArchAppliance | ||
%ArchAppliance Interface to the SLAC Archiver Appliance | ||
% The Archiver Appliance (http://epicsarchiverap.sourceforge.net) | ||
% allows many operations via a REST-style HTTP interface. | ||
% This class makes these operations simple from Matlab. | ||
% | ||
% EXAMPLES | ||
% aa = ArchAppliance(); % Create default instance | ||
% data = aa.getData('mypv', '2013-10-14T08:00:00Z', '2013-10-15T08:00:00Z') | ||
% | ||
% PROPERTY INITIALIZATION: | ||
% The properties for this class may be set through an initialization | ||
% file (pointed to by $ARCHAPPL_INIFILE), environment variables, | ||
% and/or through arguments to the constructor. | ||
% The order of precedence follows this order, so parameters set | ||
% in the initialization file are overridden by individual | ||
% environment variables, and environment variables are overridden | ||
% by arguments to the constructor. | ||
% | ||
% The environment variables are: | ||
% ARCHAPPL_INIFILE: path/filename to the initialization file. The | ||
% file format is name=value, one per line, where the allowable names | ||
% are the remaining environment variables. | ||
% ARCHAPPL_HOSTNAME: DNS name (or ip address) of the server where | ||
% an archiver appliance can be contacted. The data retrieval and | ||
% management components must both be running on the host. | ||
% ARCHAPPL_RETRIEVALPORT: Port number at which the retrieval | ||
% component can be reached. Default = 17668. | ||
% ARCHAPPL_MGMTPORT: Port number at which the management | ||
% component can be reached. Default = 17665. | ||
% ARCHAPPL_RETRIEVALPATH: Base path to the retrieval component. | ||
% Default is "/retrieval/data/", and should not need to be changed. | ||
% ARCHAPPL_MGMTPATH: Base path to the management component. | ||
% Default is "/mgmt/bpl/", and should not need to be changed. | ||
% | ||
% See also getAAData | ||
% | ||
% Copyright (c) Lawrence Berkeley National Laboratory | ||
properties | ||
% The server name where the archiver appliance can be contacted | ||
hostname = 'arch02.als.lbl.gov'; | ||
% The port on which the retrieval engine runs | ||
retrievalport = 17668; | ||
% The URL base path for the retrieval component. This should never | ||
% need to be changed. | ||
retrievalpath = '/retrieval/data/'; | ||
% The URL base path for the management component. This should never | ||
% need to be changed. | ||
mgmtpath = '/mgmt/bpl/'; | ||
% The port on which the management component runs | ||
mgmtport = 17665; | ||
|
||
end | ||
|
||
methods | ||
function AA = ArchAppliance(hostname, retrievalport, mgmtport, retrievalpath, mgmtpath) | ||
%Constructor all arguments are optional | ||
% If any arguments are specified, they will override the environment variables | ||
% Arguments: | ||
% hostname: string the appliance server name | ||
% retrievalpath: string the base of the retrieval URL path | ||
% mgmtpath: string the base of the management URL path | ||
% retrievalport: integer the port of the retrieval component | ||
% mgmtport: integer the port of the management component | ||
narginchk(0,5); | ||
AA = AA.initializeEnvironment(); | ||
if nargin >= 1 | ||
AA.hostname = hostname; | ||
end | ||
if nargin >= 2 | ||
AA.retrievalport = retrievalport; | ||
end | ||
if nargin >= 3 | ||
AA.mgmtport = mgmtport; | ||
end | ||
if nargin >= 4 | ||
AA.retrievalpath = retrievalpath; | ||
end | ||
if nargin >= 5 | ||
AA.mgmtpath = mgmtpath; | ||
end | ||
end | ||
|
||
function dat = getData(AA, pvname, from, to) | ||
%getData Retrieve data for a pv from the archiver appliance | ||
%Retrieves data for pvname over the time period from:to | ||
%pvname: the name of the pv | ||
%from: the start date/time in ISO 8601 format | ||
%to: the end date/time in ISO 8601 format | ||
%Note on time format: Use YYYY-MM-DDTHH:MM:SS.FFFZ. The | ||
%timezone may replace Z, e.g. -08 for PST. | ||
%Returns a 1x1 struct containing subelements header and data. | ||
%These are each structs with the elements: | ||
% header: | ||
% source (e.g. "Archiver appliance") | ||
% pvName | ||
% from = startdate in UTC | ||
% to = enddate in UTC | ||
% data: (N = #samples retrieved) | ||
% values = Nx1 double, or NxM double if pv is a waveform | ||
% epochSeconds = Nx1 int64 | ||
% nanos = Nx1 int64 | ||
% isDST = Nx1 uint8 | ||
|
||
url = strcat('http://', AA.hostname, ... | ||
':', int2str(AA.retrievalport), ... | ||
AA.retrievalpath, ... | ||
'getData.mat'); | ||
urlwrite(url, 'AAtemp.mat', 'get', ... | ||
{'pv', pvname, ... | ||
'from', from, ... | ||
'to', to}); | ||
dat = load('AAtemp.mat'); | ||
delete('AAtemp.mat'); | ||
end | ||
|
||
function lst = getPVs(AA, wildcard) | ||
%getPVs Retrieve the list of pv names | ||
%Retrieves a 1xN array of pv names, limited by an optional | ||
%wildcard. | ||
%Examples: | ||
% lst = AA.getPVs() | ||
% Returns all pv names in the archiver appliance. Note | ||
% that this can return millions of pvs. | ||
% lst = AA.getPVs('cmm:*') | ||
% Returns all pv names that start with "cmm:" | ||
url = strcat('http://', AA.hostname, ... | ||
':', int2str(AA.mgmtport), ... | ||
AA.mgmtpath, ... | ||
'getAllPVs'); | ||
if nargin == 1 | ||
str = urlread(url); | ||
else | ||
str = urlread(url, 'get', {'pv', wildcard}); | ||
end | ||
% Giving up some flexibility by not using parse_json here | ||
% because it is potentially very slow if lots of pvs are | ||
% returned. | ||
if str(1) == '[' | ||
str2 = str(3:length(str)-3); | ||
lst = strsplit(str2, '","'); | ||
else | ||
lst = []; | ||
end | ||
end | ||
|
||
function stats = getPVStatus(AA, pvnames) | ||
%getPVStatus Get the status of a PV | ||
%Retrieves the archiving status of one or more pvs. | ||
%param pvnames: the name(s)of the pv for which status | ||
%is to be determined. If a pv is not being archived, | ||
%the returned status will be "Not being archived." | ||
%You can also pass in GLOB wildcards here and multiple | ||
%PVs as vector. | ||
url = strcat('http://', AA.hostname, ... | ||
':', int2str(AA.mgmtport), ... | ||
AA.mgmtpath, ... | ||
'getPVStatus'); | ||
if isa(pvnames, 'char') | ||
result = urlread(url, 'get', {'pv', pvnames}); | ||
else | ||
result = urlread(url, 'post', ... | ||
{'pv', strjoin(pvnames, ',')}); | ||
end | ||
stats = parse_json(result); | ||
end | ||
|
||
function info = getPVTypeInfo(AA, pvname) | ||
%getPVTypeInfo Get the type info for a given PV. | ||
%In the archiver appliance terminology, the PVTypeInfo | ||
%contains the various archiving parameters for a PV. | ||
url = strcat('http://', AA.hostname, ... | ||
':', int2str(AA.mgmtport), ... | ||
AA.mgmtpath, ... | ||
'getPVTypeInfo'); | ||
result = urlread(url, 'get', {'pv', pvname}); | ||
info = parse_json(result); | ||
end | ||
|
||
function info = getNeverConnectedPVs(AA) | ||
%getNeverConnectedPVs Get a list of PVs that have never | ||
%connected. | ||
url = strcat('http://', AA.hostname, ... | ||
':', int2str(AA.mgmtport), ... | ||
AA.mgmtpath, ... | ||
'getNeverConnectedPVs'); | ||
result = urlread(url); | ||
info = parse_json(result); | ||
end | ||
|
||
function info = getCurrentlyDisconnectedPVs(AA) | ||
%getCurrentlyDisconnectedPVs Get a list of PVs that are | ||
%currently disconnected. | ||
url = strcat('http://', AA.hostname, ... | ||
':', int2str(AA.mgmtport), ... | ||
AA.mgmtpath, ... | ||
'getCurrentlyDisconnectedPVs'); | ||
result = urlread(url); | ||
info = parse_json(result); | ||
end | ||
end | ||
|
||
methods (Access = private) | ||
function AA = initializeEnvironment(AA) | ||
%initializeEnvironment Initializes AA from environment variables | ||
%If ARCHAPPL_INIFILE is set, attempts to read settings from it first. | ||
%Other environment variables will override settings from ARCHAPPL_INIFILE. | ||
%If arguments are provided to the AA constructor, they will override | ||
%all settings from environment variables. | ||
path = getenv('ARCHAPPL_INIFILE'); | ||
if ~isempty(path) | ||
fid = fopen(path, 'r'); | ||
if fid == -1 | ||
exc = MException('ArchAppliance:InvalidPath', ... | ||
'ARCHAPPL_INIFILE env. variable points to a nonexistent path (%s)', path); | ||
throw(exc); | ||
end | ||
vars = textscan(fid, '%s %s', 'delimiter', '=', 'commentStyle', '#') | ||
AA = AA.setFromEnv(vars{1}, vars{2}); | ||
end | ||
end | ||
|
||
function AA = setFromEnv(AA, name, value) | ||
for i = 1:length(name) | ||
n = char(name{i}) | ||
v = char(value{i}) | ||
switch(n) | ||
case 'ARCHAPPL_SERVER' | ||
AA.hostname = v; | ||
case 'ARCHAPPL_RETRIEVALPORT' | ||
AA.retrievalport = str2double(v); | ||
case 'ARCHAPPL_RETRIEVALPATH' | ||
AA.retrievalpath = v; | ||
case 'ARCHAPPL_MGMTPORT' | ||
AA.mgmtport = str2double(v); | ||
case 'ARCHAPPL_MGMTPATH' | ||
AA.mgmtpath = v; | ||
otherwise | ||
warning('Unexpected environment variable name %s, skipping', n); | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
% MATLAB | ||
% | ||
% Files | ||
% ArchAppliance - ArchAppliance Interface to the SLAC Archiver Appliance | ||
% getAACurrentlyDisconnectedPVs - getAACurrentlyDisconnectedPVs Get a list of PVs that are | ||
% getAAData - getAAData Retrieves data from the archiver appliance | ||
% getAANeverConnectedPVs - getNeverConnectedPVs Get a list of PVs that have never | ||
% getAAPVs - getAAPVs Retrieves pv names from the archiver appliance | ||
% getAAPVStatus - getAAPVStatus Get the status of a PV | ||
% getAAPVTypeInfo - getAAPVTypeInfo Get the type info for a given PV. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function aa = aaepoch2datenum(aa) | ||
|
||
DateNumber1970 = 719529; %datenum('1-Jan-1970'); | ||
|
||
if isstruct(aa) | ||
TimeZoneDiff = (double(aa.data.isDST) - 8) / 24; | ||
|
||
SecondsDateNum = double(aa.data.epochSeconds)/60/60/24; | ||
nSecondsDateNum = double(aa.data.nanos)/1e9/60/60/24; | ||
aa.data.datenum = SecondsDateNum + nSecondsDateNum + DateNumber1970 + TimeZoneDiff; | ||
|
||
%datestr(aaDateNum(1), 'yyyy-mm-dd HH:MM:SS.FFF') | ||
%datestr(aaDateNum(end), 'yyyy-mm-dd HH:MM:SS.FFF') | ||
else | ||
|
||
end | ||
|
||
|
||
|
||
% This is what labca2datenum does. AA is already in local time. | ||
% TimeZoneDiff = getfamilydata('TimeZone') | ||
% | ||
% DateNumber1970 = 719529; %datenum('1-Jan-1970'); | ||
% | ||
% if isempty(TimeZoneDiff) | ||
% % The problem with doing this is if the PV wasn't processed in the last .5 hours, it will be treated like a time zone change!!! | ||
% t0 = clock; | ||
% days = datenum(t0(1:3)) - DateNumber1970; | ||
% t0_sec = 24*60*60*days + 60*60*t0(4) + 60*t0(5) + t0(6); | ||
% TimeZoneDiff = round((t0_sec - real(DataTime(1,1)))/60/60); | ||
% end | ||
% | ||
% DataTime = (real(DataTime)/60/60 + TimeZoneDiff)/24 + DateNumber1970 + imag(DataTime)/(1e9 * 60 * 60 * 24); |
Binary file not shown.
Binary file added
BIN
+916 KB
applications/ArchiverAppliance/docs/Shankar_Wednesday_Archiver_Appliance_Update.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
applications/ArchiverAppliance/getAACurrentlyDisconnectedPVs.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function info = getAACurrentlyDisconnectedPVs() | ||
%GETAACURRENTLYDISCONNECTEDPVS Get a list of PVs that are | ||
%currently disconnected. | ||
% Copyright (c) Lawrence Berkeley National Laboratory | ||
|
||
aa = ArchAppliance(); | ||
info = aa.getCurrentlyDisconnectedPVs(); | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function [ output_args ] = getAAData( pvname, startdate, enddate ) | ||
%getAAData Retrieves data from the archiver appliance | ||
% Archiver data are retrieved for a pv over a given | ||
% time range. | ||
% getAAData('mypv', '2008-01-01T00:00:00-08', '2008-12-31T23:59:59-08') | ||
% Retrieves data for the pv "mypv" for all of 2008, in Pacific | ||
% Standard Time | ||
% | ||
% @param pvname the pv name | ||
% @param startdate a string representing the start date/time in ISO 8601 | ||
% format | ||
% @param enddate a string representing the end date/time in ISO 8601 | ||
% format | ||
% @output a 1x1 struct containing subelements header and data. These are | ||
% each structs with the elements: | ||
% header: | ||
% source (e.g. "Archiver appliance") | ||
% pvName | ||
% from = startdate | ||
% to = enddate | ||
% data: (N = # samples) | ||
% values = Nx1 double, or NxM double if pv is a waveform | ||
% epochSeconds = Nx1 int64 | ||
% nanos = Nx1 int64 | ||
% isDST = Nx1 uint8 | ||
% | ||
% Formats for startdate, enddate: The ISO 8601 format is | ||
% YYYY-MM-DDTHH:MM:SS.UZ where: | ||
% YYYY-MM-DD = Year, month, date | ||
% T = Delimiter between date and time (a literal "T") | ||
% HH:MM:SS = Hour, minute, second | ||
% .F = Fractional part of second | ||
% Z = Optional timezone. If not specified, local time is used. If | ||
% specified and "Z", UTC time is used. May also be specified as | ||
% +/-HH, where HH is hours, e.g. -08 for Pacific Standard Time. | ||
% Examples of valid date/time representations: | ||
% 2000-07-04T00:00:00-07 July 4, 2000 midnight, PDT | ||
% 2013-11-22T08:00:00Z Nov. 22, 2013 at 08:00 am UTC (=midnight PST) | ||
% | ||
% See also ArchAppliance.getData | ||
% | ||
% Copyright (c) Lawrence Berkeley National Laboratory | ||
|
||
aa = ArchAppliance(); | ||
output_args = aa.getData(pvname, startdate, enddate); | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function [ output ] = getAANeverConnectedPVs() | ||
%getAANeverConnectedPVs Get a list of PVs that have never | ||
%connected. | ||
% Copyright (c) Lawrence Berkeley National Laboratory | ||
|
||
aa = ArchAppliance(); | ||
output = aa.getNeverConnectedPVs(); | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function [ output_args ] = getAAPVStatus( pvnames ) | ||
%getAAPVStatus Get the status of a PV | ||
%Retrieves the archiving status of one or more pvs. | ||
%param pvnames: the name(s)of the pv for which status | ||
%is to be determined. If a pv is not being archived, | ||
%the returned status will be "Not being archived." | ||
%You can also pass in GLOB wildcards here and | ||
%multiple PVs as vector. | ||
% See also ArchAppliance.getPVStatus | ||
|
||
aa = ArchAppliance(); | ||
output_args = aa.getPVStatus(pvnames); | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function [ output ] = getAAPVTypeInfo( pvname ) | ||
%GETAAPVTYPEINFO Get the type info for a given PV. | ||
%In the archiver appliance terminology, the PVTypeInfo | ||
%contains the various archiving parameters for a PV. | ||
% Copyright (c) Lawrence Berkeley National Laboratory | ||
|
||
aa = ArchAppliance(); | ||
output = aa.getPVTypeInfo(pvname); | ||
end | ||
|
Oops, something went wrong.