From 8837d774014316c8b6478c9624bce0a4bcd6a263 Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Thu, 23 May 2024 08:55:33 +0200 Subject: [PATCH] --- config/variables.properties | 8 +-- devices/Time.properties | 11 ++++ script/archiver/short_term_archiver.py | 78 +++++++++++++++++--------- script/local.py | 15 +++-- script/pull.py | 3 + script/test/test_power_max.py | 6 ++ 6 files changed, 87 insertions(+), 34 deletions(-) create mode 100644 devices/Time.properties create mode 100644 script/pull.py create mode 100644 script/test/test_power_max.py diff --git a/config/variables.properties b/config/variables.properties index ffbda10..143bf9e 100644 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,4 +1,4 @@ -#Tue May 14 14:52:29 CEST 2024 -LastRunDate=240514 -DaySequentialNumber=30 -FileSequentialNumber=41 +#Thu May 23 00:00:00 CEST 2024 +LastRunDate=240523 +DaySequentialNumber=1 +FileSequentialNumber=104 diff --git a/devices/Time.properties b/devices/Time.properties new file mode 100644 index 0000000..29b3309 --- /dev/null +++ b/devices/Time.properties @@ -0,0 +1,11 @@ +#Fri May 17 16:39:43 CEST 2024 +minValue=NaN +unit=null +offset=0.0 +maxValue=NaN +rotation=false +precision=-1 +sign_bit=0 +scale=1.0 +description=null +resolution=NaN diff --git a/script/archiver/short_term_archiver.py b/script/archiver/short_term_archiver.py index d04ff44..2aacc77 100644 --- a/script/archiver/short_term_archiver.py +++ b/script/archiver/short_term_archiver.py @@ -1,21 +1,19 @@ +import java.io.IOException as IOException + 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/" + + +set_exec_pars(name="archiver", open=True) +DATA_PATH = get_exec_pars().path #expand_path("{data}/{date}/{name}") 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) + path = DATA_PATH channel = channel.replace(":", "_") #FILENAMES DO NOT SUPPORT : return path + "/"+ channel + ".txt" - if "stop_short_term_archiver" in globals(): stop_short_term_archiver() @@ -23,29 +21,33 @@ def _log(msg): print msg log(msg) +_log("Data path:" + str(DATA_PATH)) + 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) + monitored = interval is True + polling = 0 if monitored else int (interval * 1000) #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) - - + try: + with Channel(channel, monitored, polling) as ch: + filename = get_data_path(channel) + with open(filename, 'a') as data_file: + _log("Opened: " + filename + " monitor: " + str(monitored) + " polling: " + str(polling)) + 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) + except IOException: + _log("Error processing channel " + str(channel) + ": " + str( sys.exc_info()[1])) + time.sleep(60.0 * 10) """ class Timestamp(Readable): def read(self): @@ -66,19 +68,40 @@ def archive_channel(channel, interval): _log("Exit: " + str(channel)) +def archive_monitor(): + global DATA_PATH + _log("Start Monitor") + try: + while(True): + path = expand_path(get_context().config.dataPath) + if path != DATA_PATH: + _log("Day change") + set_exec_pars(open=False) + set_exec_pars(name="archiver", open=True) + DATA_PATH = path #get_exec_pars().path + _log("Data path:" + str(DATA_PATH)) + #os.makedirs(path) + time.sleep(1.0) + finally: + _log("Stop Monitor") + short_term_archiver_cfg = {} short_term_archiver_tasks=[] +short_term_archiver_monitor=None def start_short_term_archiver(metadata=False): global short_term_archiver_cfg global short_term_archiver_tasks + global short_term_archiver_monitor 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()]) + short_term_archiver_monitor = fork(archive_monitor)[0] def wait_short_term_archiver(): global short_term_archiver_tasks join(short_term_archiver_tasks) + join(short_term_archiver_monitor) def stop_short_term_archiver(): global short_term_archiver_tasks @@ -88,7 +111,10 @@ def stop_short_term_archiver(): task.cancel(True) except: pass - + try: + short_term_archiver_monitor.cancel(True) + except: + pass try: start_short_term_archiver() wait_short_term_archiver() diff --git a/script/local.py b/script/local.py index 66f811d..3eb675d 100644 --- a/script/local.py +++ b/script/local.py @@ -24,6 +24,7 @@ class Channel: self.channel=GenericChannel(self.channel_name,self.channel_name, True, InvalidValueAction.None) self.channel.setMonitored(self.monitored) self.channel.setPolling(self.polling) + #self.channel.setPolling(1000) self.channel.initialize() return self.channel @@ -67,13 +68,16 @@ class ChannelListener (DeviceListener): + def parse_archiver_config(metadata=True, file_name=None): + #path = expand_path("{script}/config") + path = "/sls/rf/data/SLS_Teststand/PShell/sls_archiver/config/RF" ret = {} if not file_name: - for file_name in os.listdir(expand_path("{script}/config")): + for file_name in os.listdir(path): 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))) + ret.update(parse_archiver_config(metadata, path + "/" + file_name)) else: with open(file_name, 'r') as f: for line in f: @@ -89,7 +93,7 @@ def parse_archiver_config(metadata=True, file_name=None): elif v=="Monitor": return True else: - return int(v) + return float(v) except Exception as e: print (e) return None @@ -104,7 +108,10 @@ def parse_archiver_config(metadata=True, file_name=None): def parse_short_term_archiver_config(metadata): ret = parse_archiver_config(metadata) - return {name:v[2] for name,v in ret.items()} + log("Initializing " + str(len(ret)) + " channels") + cfg = {name:v[0] for name,v in ret.items()} + log(str(cfg)) + return cfg diff --git a/script/pull.py b/script/pull.py new file mode 100644 index 0000000..28a9232 --- /dev/null +++ b/script/pull.py @@ -0,0 +1,3 @@ +import subprocess +ret = subprocess.check_output("git pull", shell=True, cwd="/sls/rf/data/SLS_Teststand/PShell/sls_archiver") +set_return(ret) \ No newline at end of file diff --git a/script/test/test_power_max.py b/script/test/test_power_max.py new file mode 100644 index 0000000..0a6e9a9 --- /dev/null +++ b/script/test/test_power_max.py @@ -0,0 +1,6 @@ +name='ATSRF-CAV:CO1i-POWER-MAX' +channel=GenericChannel(name,name, True, InvalidValueAction.None) +channel.setMonitored(True) +channel.initialize() +add_device(channel, True) +mscan (channel, channel, -1, 10.0) \ No newline at end of file