Creation
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
if get_context().localMode:
|
||||
raise Exception ("Must run in exclusive mode")
|
||||
|
||||
set_exec_pars(name="archiver", open=True)
|
||||
|
||||
#data_path = "/sls/rf/data/SLS_Teststand/PShell/data/"
|
||||
|
||||
def get_data_path(channel):
|
||||
#path = data_path + expand_path("{date}")
|
||||
#path = expand_path("{data}/{date}/archiver")
|
||||
path = get_exec_pars().path
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
channel = channel.replace(":", "_") #FILENAMES DO NOT SUPPORT :
|
||||
return path + "/"+ channel + ".txt"
|
||||
|
||||
|
||||
|
||||
if "stop_short_term_archiver" in globals():
|
||||
stop_short_term_archiver()
|
||||
|
||||
def _log(msg):
|
||||
print msg
|
||||
log(msg)
|
||||
|
||||
|
||||
def archive_channel(channel, interval):
|
||||
_log("Enter: " + str(channel))
|
||||
|
||||
try:
|
||||
monitored = interval == True
|
||||
polling = 0 if monitored else int (interval)
|
||||
filename = get_data_path(channel)
|
||||
#dev = "ca://" + channel + ("?monitored=true" if monitored else ")
|
||||
while True:
|
||||
with Channel(channel, monitored, polling) as ch:
|
||||
with open(filename, 'a') as data_file:
|
||||
_log("Opened: " + filename)
|
||||
channel_listener = ChannelListener(data_file)
|
||||
ch.addListener(channel_listener)
|
||||
ch.update()
|
||||
while True:
|
||||
if filename != get_data_path(channel):
|
||||
_log("Closing: " + filename)
|
||||
break
|
||||
time.sleep(1.0)
|
||||
|
||||
|
||||
"""
|
||||
class Timestamp(Readable):
|
||||
def read(self):
|
||||
timestamp = ch.takeTimestamped().timestamp
|
||||
return timestamp
|
||||
timestamp = Timestamp()
|
||||
devices = (ch, timestamp)
|
||||
if monitored:
|
||||
mscan(channel, devices, take_initial=True, display=False, keep=False, tag=channel)
|
||||
else:
|
||||
tscan(devices, -1, interval*100, display=False, keep=False, tag=channel)
|
||||
"""
|
||||
|
||||
except Exception as ex:
|
||||
_log("ERROR: " + str( sys.exc_info()[1]))
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
_log("Exit: " + str(channel))
|
||||
|
||||
|
||||
short_term_archiver_cfg = {}
|
||||
short_term_archiver_tasks=[]
|
||||
|
||||
def start_short_term_archiver(metadata=False):
|
||||
global short_term_archiver_cfg
|
||||
global short_term_archiver_tasks
|
||||
print "Starting Short Term Archiver"
|
||||
short_term_archiver_cfg = parse_short_term_archiver_config(metadata)
|
||||
short_term_archiver_tasks = fork(* [[archive_channel,[channel, interval,]] for channel,interval in short_term_archiver_cfg.items()])
|
||||
|
||||
def wait_short_term_archiver():
|
||||
global short_term_archiver_tasks
|
||||
join(short_term_archiver_tasks)
|
||||
|
||||
def stop_short_term_archiver():
|
||||
global short_term_archiver_tasks
|
||||
print "Stopping Short Term Archiver"
|
||||
for task in short_term_archiver_tasks:
|
||||
try:
|
||||
task.cancel(True)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
start_short_term_archiver()
|
||||
wait_short_term_archiver()
|
||||
finally:
|
||||
stop_short_term_archiver()
|
||||
@@ -0,0 +1,35 @@
|
||||
#PVs from the RF Booster / Teststand HV Modulator VME IOC
|
||||
###################################################################
|
||||
ABORF-A0:FirstError None None Monitor
|
||||
ABORF-CAV0:Vcav 1 10 150
|
||||
ABORF-A0-D50W:Pi 1 10 600
|
||||
ABORF-A0-D50W:Pi.EGU None None Monitor
|
||||
ABORF-A0-D50W:Pi-C 1 10 600
|
||||
ABORF-A0-D50W:Pi-C.EGU None None Monitor
|
||||
ABORF-A0-D50W:Pr-C 1 10 600
|
||||
ABORF-A0-D50W:Pr-C.EGU None None Monitor
|
||||
ABORF-A0-AMLP:Vlim-R 6 30 600
|
||||
ABORF-A0-AMLP:Vlim-R.EGU None None Monitor
|
||||
ABORF-A0:ARCS None None Monitor
|
||||
ABORF-WG0-CO1:Pki 1 10 600
|
||||
ABORF-WG0-CO1:Pki.EGU None None Monitor
|
||||
ABORF-WG0-CO1:Pki-C 1 10 600
|
||||
ABORF-WG0-CO1:Pki-C.EGU None None Monitor
|
||||
ABORF-WG0-CO1:Pkr 1 10 600
|
||||
ABORF-WG0-CO1:Pkr.EGU None None Monitor
|
||||
ABORF-WG0-CO1:Pkr-C 1 10 600
|
||||
ABORF-WG0-CO1:Pkr-C.EGU None None Monitor
|
||||
ABORF-A0-HVPS:I 1 10 600
|
||||
ABORF-A0-HVPS:I.EGU None None Monitor
|
||||
ABORF-A0-FIL:I 1 10 600
|
||||
ABORF-A0-FIL:I.EGU None None Monitor
|
||||
ABORF-A0-MOD:I 1 10 600
|
||||
ABORF-A0-MOD:I.EGU None None Monitor
|
||||
ABORF-A0-IPS1:V 1 10 600
|
||||
ABORF-A0-IPS1:V.EGU None None Monitor
|
||||
ABORF-CAV0-CLRK:FlowPr 1 10 600
|
||||
ABORF-CAV0-CLRK:FlowPr.EGU None None Monitor
|
||||
ABORF-CAV0-CLRK:ValvPos 1 10 600
|
||||
ABORF-CAV0-CLRK:ValvPos.EGU None None Monitor
|
||||
ABORF-CIR0TCU:COIL_CURRENT 1 10 600
|
||||
ABORF-CIR0TCU:COIL_CURRENT.EGU None None Monitor
|
||||
@@ -0,0 +1,82 @@
|
||||
#PVs from the RF Teststand Cooling PLC
|
||||
###################################################################
|
||||
#mbbi
|
||||
ATSRF-CAVR:EndDiscIn-Water-Flowswitch1 None None Monitor
|
||||
ATSRF-CAVR:EndDiscIn-Water-Flowswitch2 None None Monitor
|
||||
ATSRF-CAVR:EndDiscOut-Water-Flowswitchw1 None None Monitor
|
||||
ATSRF-CAVR:EndDiscOut-Water-Flowswitchw2 None None Monitor
|
||||
ATSRF-CAVR:Wedge-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:TuningPlunger-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:TopWG-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:LeftWG-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:RightWG-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:Coupler-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:BodyRidge1-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:BodyRidge2-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:Body-Water-Flowswitch1 None None Monitor
|
||||
ATSRF-CAVR:Body-Water-Flowswitch2 None None Monitor
|
||||
ATSRF-CAVR:Body-Water-Flowswitch3 None None Monitor
|
||||
ATSRF-CAVR:Coupler-Plunger-Water-Flowswitch None None Monitor
|
||||
ATSRF-CAVR:Coupler-Air-Pressureswitch None None Monitor
|
||||
###################################################################
|
||||
#bi
|
||||
ATSRF-CAV:Water-Leak None None Monitor
|
||||
ATSRF-CAV:Vacuum-SumILK None None Monitor
|
||||
ATSRF-CAVR:Inlet-Watervalve-Open None None Monitor
|
||||
ATSRF-CAVR:Inlet-Valvevalve-Closed None None Monitor
|
||||
ATSRF-CAVR:Outlet-Watervalve-Open None None Monitor
|
||||
ATSRF-CAVR:Outlet-Watervalve-Closed None None Monitor
|
||||
ATSRF-CAVR:Inlet-Watervalve None None Monitor
|
||||
ATSRF-CAVR:Outlet-Watervalve None None Monitor
|
||||
ATSRF-CAVR:Outlet-Airvalve None None Monitor
|
||||
###################################################################
|
||||
#ai
|
||||
ATSRF-CAVR:Water-Flow None 60 3600
|
||||
ATSRF-CAVR:Water-Flow.EGU None None Monitor
|
||||
ATSRF-CAVR:Water-Flow.HIHI None None Monitor
|
||||
ATSRF-CAVR:Water-Flow.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Coupler-Air-Flow None 60 3600
|
||||
ATSRF-CAVR:Coupler-Air-Flow.EGU None None Monitor
|
||||
ATSRF-CAVR:Coupler-Air-Flow.HIHI None None Monitor
|
||||
ATSRF-CAVR:Coupler-Air-Flow.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Water-Pressure-Inlet None 60 3600
|
||||
ATSRF-CAVR:Water-Pressure-Inlet.EGU None None Monitor
|
||||
ATSRF-CAVR:Water-Pressure-Inlet.HIHI None None Monitor
|
||||
ATSRF-CAVR:Water-Pressure-Inlet.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Water-Pressure-Outlet None 60 3600
|
||||
ATSRF-CAVR:Water-Pressure-Outlet.EGU None None Monitor
|
||||
ATSRF-CAVR:Water-Pressure-Outlet.HIHI None None Monitor
|
||||
ATSRF-CAVR:Water-Pressure-Outlet.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Inlet-Watervalve-Temp None 60 3600
|
||||
ATSRF-CAVR:Inlet-Watervalve-Temp.EGU None None Monitor
|
||||
ATSRF-CAVR:Inlet-Watervalve-Temp.HIHI None None Monitor
|
||||
ATSRF-CAVR:Inlet-Watervalve-Temp.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Outlet-Watervalve-Temp None 60 3600
|
||||
ATSRF-CAVR:Outlet-Watervalve-Temp.EGU None None Monitor
|
||||
ATSRF-CAVR:Outlet-Watervalve-Temp.HIHI None None Monitor
|
||||
ATSRF-CAVR:Outlet-Watervalve-Temp.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Wedge-Water-Temp None 60 3600
|
||||
ATSRF-CAVR:Wedge-Water-Temp.EGU None None Monitor
|
||||
ATSRF-CAVR:Wedge-Water-Temp.HIHI None None Monitor
|
||||
ATSRF-CAVR:Wedge-Water-Temp.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Tuner-Water-Temp None 60 3600
|
||||
ATSRF-CAVR:Tuner-Water-Temp.EGU None None Monitor
|
||||
ATSRF-CAVR:Tuner-Water-Temp.HIHI None None Monitor
|
||||
ATSRF-CAVR:Tuner-Water-Temp.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Coupler-Water-Temp None 60 3600
|
||||
ATSRF-CAVR:Coupler-Water-Temp.EGU None None Monitor
|
||||
ATSRF-CAVR:Coupler-Water-Temp.HIHI None None Monitor
|
||||
ATSRF-CAVR:Coupler-Water-Temp.LOLO None None Monitor
|
||||
#
|
||||
ATSRF-CAVR:Coupler-Air-Temp None 60 3600
|
||||
ATSRF-CAVR:Coupler-Air-Temp.EGU None None Monitor
|
||||
ATSRF-CAVR:Coupler-Air-Temp.HIHI None None Monitor
|
||||
ATSRF-CAVR:Coupler-Air-Temp.LOLO None None Monitor
|
||||
@@ -0,0 +1,3 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Deployment specific global definitions - executed after startup.groovy
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -0,0 +1,4 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Deployment specific global definitions - executed after startup.js
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
###################################################################################################
|
||||
# Deployment specific global definitions - executed after startup.py
|
||||
###################################################################################################
|
||||
|
||||
|
||||
import java.time.format.DateTimeFormatter as DateTimeFormatter
|
||||
import java.time.Instant as Instant
|
||||
import java.time.LocalDateTime as LocalDateTime
|
||||
import java.time.ZoneOffset as ZoneOffset
|
||||
import org.jfree.chart.axis.DateAxis as DateAxis
|
||||
import traceback
|
||||
import ch.psi.pshell.epics.InvalidValueAction as InvalidValueAction
|
||||
|
||||
#with Channel("ABORF-A0-HVPS:I", monitored=False) as ch:
|
||||
# print ch.read()
|
||||
|
||||
class Channel:
|
||||
def __init__(self,channel_name, monitored, polling):
|
||||
self.channel_name=channel_name
|
||||
self.monitored= monitored
|
||||
self.polling = polling
|
||||
|
||||
def __enter__(self):
|
||||
self.channel=GenericChannel(self.channel_name,self.channel_name, True, InvalidValueAction.None)
|
||||
self.channel.setMonitored(self.monitored)
|
||||
self.channel.setPolling(self.polling)
|
||||
self.channel.initialize()
|
||||
return self.channel
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.channel.close()
|
||||
|
||||
|
||||
#timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
|
||||
timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS")
|
||||
|
||||
def get_time_str(timestamp):
|
||||
#instant = Instant.ofEpochMilli(timestamp)
|
||||
#currentTime = LocalDateTime.ofInstant(instant, ZoneOffset.systemDefault())
|
||||
#return currentTime.format(timeFormatter);
|
||||
return str(timestamp)
|
||||
|
||||
ITEM_SEPARATOR = "; "
|
||||
|
||||
def init_archiver(f, cls = None):
|
||||
if cls is None:
|
||||
cls = "java.lang.Double"
|
||||
f.write ("#Timestamp" + ITEM_SEPARATOR + "Value" + ITEM_SEPARATOR + "\n")
|
||||
f.write ("#java.lang.Long" + ITEM_SEPARATOR + Class.getName(cls) + ITEM_SEPARATOR + "\n")
|
||||
f.flush()
|
||||
|
||||
def write_archive(f, timestamp, value):
|
||||
v = get_time_str(timestamp) + ITEM_SEPARATOR+ str(value) + ITEM_SEPARATOR
|
||||
f.write (v+ "\n")
|
||||
f.flush()
|
||||
|
||||
|
||||
class ChannelListener (DeviceListener):
|
||||
def __init__(self, f):
|
||||
self.f = f
|
||||
|
||||
def onCacheChanged(self, ch, value, former, timestamp, valueChange):
|
||||
if self.f.tell() == 0:
|
||||
cls=ch.getElementType()
|
||||
init_archiver(self.f, cls)
|
||||
write_archive(self.f, timestamp, value)
|
||||
|
||||
|
||||
|
||||
def parse_archiver_config(metadata=True, file_name=None):
|
||||
ret = {}
|
||||
if not file_name:
|
||||
for file_name in os.listdir(expand_path("{script}/config")):
|
||||
if file_name.endswith(".config"):
|
||||
# If the file has the desired extension, add it to the list
|
||||
ret.update(parse_archiver_config(metadata, expand_path("{script}/config/" + file_name)))
|
||||
else:
|
||||
with open(file_name, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line.startswith('#'):
|
||||
continue # Skip lines starting with '#'
|
||||
parts = line.split() # Split the line by whitespace
|
||||
if len(parts) >= 4:
|
||||
def adjust(v):
|
||||
try:
|
||||
if v=="None":
|
||||
return False
|
||||
elif v=="Monitor":
|
||||
return True
|
||||
else:
|
||||
return int(v)
|
||||
except Exception as e:
|
||||
print (e)
|
||||
return None
|
||||
name = parts[0]
|
||||
if metadata or not "." in name:
|
||||
v1 = adjust(parts[1])
|
||||
v2 = adjust(parts[2])
|
||||
v3 = adjust(parts[3])
|
||||
ret[name] = [v1, v2, v3]
|
||||
return ret
|
||||
|
||||
|
||||
def parse_short_term_archiver_config(metadata):
|
||||
ret = parse_archiver_config(metadata)
|
||||
return {name:v[2] for name,v in ret.items()}
|
||||
|
||||
|
||||
|
||||
|
||||
def plot_channel(channel, day, title=None):
|
||||
path="/"+day+"/archiver|/" + channel.replace(":", "_")
|
||||
data =load_data(path)
|
||||
tm = [i[0]for i in data]
|
||||
val = [i[1]for i in data]
|
||||
p=plot(val, name=channel + " [" + day + "]", xdata=tm, title=title)[0]
|
||||
axis = DateAxis(None)
|
||||
axis.setTickLabelPaint(p.getAxisTextColor())
|
||||
p.getChart().getXYPlot().setDomainAxis(axis)
|
||||
|
||||
|
||||
#channels = parse_short_term_archiver_config(False)
|
||||
#for c in channels.keys():
|
||||
# print c, caget(c)
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import java.time.format.DateTimeFormatter as DateTimeFormatter
|
||||
import java.time.Instant as Instant
|
||||
import java.time.LocalDateTime as LocalDateTime
|
||||
import java.time.ZoneOffset as ZoneOffset
|
||||
|
||||
#with Channel("ABORF-A0-HVPS:I", monitored=False) as ch:
|
||||
# print ch.read()
|
||||
|
||||
class Channel:
|
||||
def __init__(self,channel_name, monitored, polling):
|
||||
self.channel_name=channel_name
|
||||
self.monitored= monitored
|
||||
self.polling = polling
|
||||
|
||||
def __enter__(self):
|
||||
self.channel=GenericChannel(self.channel_name,self.channel_name)
|
||||
self.channel.setMonitored(self.monitored)
|
||||
self.channel.setPolling(self.polling)
|
||||
self.channel.initialize()
|
||||
return self.channel
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.channel.close()
|
||||
|
||||
|
||||
timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
|
||||
|
||||
def get_time_str(timestamp):
|
||||
instant = Instant.ofEpochMilli(timestamp)
|
||||
currentTime = LocalDateTime.ofInstant(instant, ZoneOffset.systemDefault())
|
||||
return currentTime.format(timeFormatter);
|
||||
|
||||
|
||||
def write_archive(f, timestamp, value):
|
||||
print f + " " + get_time_str(timestamp) + " " + str(value)
|
||||
|
||||
|
||||
class ChannelListener (DeviceListener):
|
||||
def onCacheChanged(self, ch, value, former, timestamp, valueChange):
|
||||
write_archive(ch.name, timestamp, value)
|
||||
|
||||
val=None
|
||||
with Channel("ABORF-A0-HVPS:I", True, 0) as ch:
|
||||
#val = ch.update()
|
||||
#val=ch.takeTimestamped()
|
||||
#write_archive(ch.name, val.timestamp, val.value)
|
||||
channel_listener = ChannelListener()
|
||||
ch.addListener(channel_listener)
|
||||
ch.update()
|
||||
val=ch.take()
|
||||
time.sleep(10.0)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import org.jfree.chart.axis.DateAxis as DateAxis
|
||||
|
||||
|
||||
def plot_channel(channel, day, title=None):
|
||||
path=day+"/archiver|/" + channel.replace(":", "_")
|
||||
print(path)
|
||||
data =load_data(path)
|
||||
tm = [i[0]for i in data]
|
||||
val = [i[1]for i in data]
|
||||
p=plot(val, name=channel + " [" + day + "]", xdata=tm, title=title)[0]
|
||||
axis = DateAxis(None)
|
||||
axis.setTickLabelPaint(p.getAxisTextColor())
|
||||
p.getChart().getXYPlot().setDomainAxis(axis)
|
||||
|
||||
|
||||
plot_channel("ATSRF-CAVR:Water-Pressure-Inlet","20240514")
|
||||
Reference in New Issue
Block a user