Exporting to a layout class for the onlinemodel debugged and cross checked with the holy list package

This commit is contained in:
2026-08-06 16:49:37 +02:00
parent 1b84445d9f
commit bb0d49eaee
2 changed files with 41 additions and 11 deletions
+20 -6
View File
@@ -3,7 +3,7 @@ from elements import *
class Exporter:
def __init__(self,version='11.1.2'):
self.path = '../Heilige Liste/Python_Code/onlinemodel/layout/layout.py'
self.path = 'onlinemodel/exportedlayouts/layout.py'
self.fid = None
self.lattice=version
@@ -69,9 +69,7 @@ class Exporter:
self.fid.write('\t\t%s.append(%s(prop),%f,"%s")\n' % (Container, typename, off, relative))
def getProp(self,Element):
if isinstance(Element, Marker):
if not 'MKBR' in Element.Name:
return None,1,1,1
if isinstance(Element, VariableContainer):
return None,1,1,1
prop= '{"Tag":"%s","index":%d,"Baugruppe":"%s","Length":%f' % (Element.Tag,Element.index,Element.Baugruppe, Element.Length)
@@ -79,6 +77,11 @@ class Exporter:
prop+=',"LengthRes":%f' % Element.LengthRes
if Element.Tilt>0:
prop+=',"Tilt":%13.10f' % (Element.Tilt*np.pi/180.)
if isinstance(Element, Marker):
if not 'MKBR' in Element.Name and not 'MREF' in Element.Name:
return None,1,1,1
elif 'MREF' in Element.Name:
prop+=',"Baugruppe":"Reference Point"'
if isinstance(Element,Alignment):
prop = '{"Tag":"ALIG","index":%d,"dy":%f' % (Element.index,Element.dy)
if isinstance(Element, RF):
@@ -97,12 +100,18 @@ class Exporter:
if Element.PSChannels > 1:
prop+=',"cor":0'
if isinstance(Element,Corrector):
if Element.PSChannels >0:
if Element.PSChannels >1:
prop+=',"corx":0,"cory":0'
elif Element.PSChannels == 1:
prop+=',"cor":0'
if isinstance(Element, Diagnostic):
if Element.Seval > 0:
prop+=',"Seval":%f' % Element.seval
if isinstance(Element,Undulator):
if Element.Baugruppe == 'U15':
prop+=',"cor":0'
if Element.Baugruppe == 'UE38':
prop+=',"corx":0,"cory":0'
prop+=',"K":%f,"ku":%f' % (Element.K,2*np.pi/Element.lambdau)
prop+='}'
pos = 'absolute'
@@ -130,7 +139,12 @@ class Exporter:
self.fid.write('\t\tPartsList = [[Injector, -1, 0, "SwissFEL Injector"],\n')
self.fid.write('\t\t [Linac, 0, -1, "SwissFEL Linac"],\n')
self.fid.write('\t\t [Aramis, 1, -1, "Aramis beamline"],\n')
self.fid.write('\t\t [Athos, 1, 2, "Athos beamline"]]\n')
self.fid.write('\t\t [Athos, 1, 2, "Athos beamline"],\n')
self.fid.write('\t\t [Porthos, 1, 3, "Porthos beamline"],\n')
self.fid.write('\t\t [InjectorDump, 0, 1, "Athos beamline"],\n')
self.fid.write('\t\t [Linac1Dump, 1, 1, "Athos beamline"],\n')
self.fid.write('\t\t [AramisDump, 2, 1, "Athos beamline"],\n')
self.fid.write('\t\t [AthosDump, 3, 1, "Athos beamline"]]\n')
self.fid.write('\t\treturn PartsList\n\n')
# PartsList = [[Injector, -1, 0, 'SwissFEL Injector'], # 0
+21 -5
View File
@@ -166,9 +166,20 @@ class BeamlineEditor(QtWidgets.QMainWindow, Ui_BeamlineGUI):
def exportOnlineModelCase(self,alt):
self.exporter.buildCaseHeader(alt)
secs=['IN','10','20','30','AR','AT']
branches={'IN':'Injector','10':'Linac10','20':'Linac20','30':'Linac30','AR':'Aramis','AT':'Athos'}
for sec in secs:
secs=['IN','10','20','30','AR','AT','PO','IN2nd','102nd','AR2nd','AT2nd']
branches={'IN':'Injector','10':'Linac10','20':'Linac20','30':'Linac30','AR':'Aramis','AT':'Athos','PO':'Porthos'}
branches['IN2nd'] = 'InjectorDump'
branches['102nd'] = 'Linac1Dump'
branches['AR2nd'] = 'AramisDump'
branches['AT2nd'] = 'AthosDump'
for sec0 in secs:
if len(sec0) > 2:
sec=sec0[:2]
branch=True
else:
sec=sec0
branch=False
# find section element in database
id0 = None
for id in self.elementDB.keys():
@@ -176,7 +187,10 @@ class BeamlineEditor(QtWidgets.QMainWindow, Ui_BeamlineGUI):
if isinstance(ele, LineContainer) and ele.Name == sec:
id0=id
if id0:
print('Found Kingdom:','S'+sec)
altcomment=''
if len(sec0)>2:
altcomment='(Dump)'
print('Found Kingdom:','S'+sec,altcomment)
else:
continue #skip to next entry
# now loop through the subsections:
@@ -185,6 +199,8 @@ class BeamlineEditor(QtWidgets.QMainWindow, Ui_BeamlineGUI):
sectionList=[]
if kingEle.firstElementID in self.elementDB.keys(): # start Marker, which holds all section of the kingdom
tree = self.editor.flatten(kingEle.firstElementID, alt+1)
if branch:
tree = self.editor.flatten(tree.secondary.node_id, alt+1)
for ele in tree.path:
type = self.editor.getElementType(ele)
if type =='Start':
@@ -206,7 +222,7 @@ class BeamlineEditor(QtWidgets.QMainWindow, Ui_BeamlineGUI):
sectionList.append(section.Name)
self.exportOnlineModelSection(section.Name, section.LengthRes, section.firstElementID,
alt + 1)
self.exporter.writeDomain(branches[sec], sec, kingEle.LengthRes, sectionList)
self.exporter.writeDomain(branches[sec0], sec, kingEle.LengthRes, sectionList)
self.exporter.buildCaseFooter()
return