Skip to content

Commit

Permalink
Merge pull request #66 from KaushikMalapati/alarm_formulas
Browse files Browse the repository at this point in the history
Making formula pvs in xml file out of certain spreadsheet pvs
  • Loading branch information
KaushikMalapati authored Feb 28, 2025
2 parents 6feeede + 6bacf0e commit c956074
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Scripts/alarm_csv2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from xml.dom import minidom

import click
import re


def csvtoxml(infile, outfile, cname):
Expand All @@ -28,11 +29,22 @@ def csvtoxml(infile, outfile, cname):
stack.append(sel)
else:
pv = ET.SubElement(stack[-1], 'pv')
pv.set('name', row['PV'])
pv_name = row['PV']
pv_tokens = pv_name.split('://', 1)
if len(pv_tokens) == 2:
protocol = pv_tokens[0].lower()
if protocol == 'ca' or protocol == 'pva':
pass
elif protocol == 'major' or protocol == 'minor':
calc_expression = pv_tokens[1]
pv_name = f'eq://{protocol}Alarm({calc_expression}, "")'
else:
raise ValueError(f'Got unsupported protocol "{protocol}" in {pv_name}')
pv.set('name', pv_name)
desc = ET.SubElement(pv, 'description')
desc.text = row['Description']
latch = ET.SubElement(pv, 'latching')
latch.text = row['Latch'].capitalize() if row['Latch'] else "True"
latch.text = row['Latch'].capitalize() if row['Latch'] else 'True'
delay = ET.SubElement(pv, 'delay')
delay.text = row['Delay']
if 'Filter' in row and row['Filter']:
Expand All @@ -48,7 +60,7 @@ def csvtoxml(infile, outfile, cname):
if outfile is None:
outfile = infile.rsplit('.', 1)[0] + '.xml'
with open(outfile, 'w', encoding='utf-8') as out:
out.write(xm.toprettyxml(indent=" "*3))
out.write(xm.toprettyxml(indent=' '*3))
click.echo(f'Conversion of {infile} complete. See {outfile}')


Expand Down
1 change: 1 addition & 0 deletions Spreadsheet/KFE/TMO-alarms.csv
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@
,,LM1K4:QADC:01:OUT0_EDGE2,QADC signal monitor,,,LM1K4:QADC:01:OUT0_EDGE2>0,
1,LASER PHASE MOTOR,,,,,,
,,LAS:LHN:LLG2:01:PHAS:ERROR,Laser phase feedback,,,,
,,major://(abs(SL1K0:POWER:ACTUAL_YWIDTH_RBV) * 1000) > AT1K0:GAS_MA_Y:MMS:1,slits too wide,,,,
5 changes: 5 additions & 0 deletions XML/KFE/TMO-alarms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@
<latching>True</latching>
<delay/>
</pv>
<pv name="eq://majorAlarm((abs(SL1K0:POWER:ACTUAL_YWIDTH_RBV) * 1000) &gt; AT1K0:GAS_MA_Y:MMS:1, &quot;&quot;)">
<description>slits too wide</description>
<latching>True</latching>
<delay/>
</pv>
</component>
</component>
</config>

0 comments on commit c956074

Please sign in to comment.