Commit 45133d8a authored by Maximilian Schuette's avatar Maximilian Schuette 🌃
Browse files

Some pep formatting

parent 8aef2f07
......@@ -4,112 +4,111 @@ from struct import pack, unpack
import numpy as np
import DAQbasic as dqb
SASE_info = {'FLASH':[{'Bits':list(range(0,4)), 'Name':'Charge', 'Op':'Abs',
'Value':{'0':0, '1':0.02, '2':0.03, '3':0.04,
'4':0.06, '5':0.09, '6':0.13, '7':0.18,
'8':0.25, '9':0.36, '10':0.50, '11':0.71,
'12':1.00, '13':1.42, '14':2.00, '15':4.00}},
{'Bits':list(range(4,8)), 'Name':'Injector Laser', 'Op':'Bits',
'Value':{'4':'Laser1', '5':'Laser2', '6':'Laser3', '7':'Laser4'}},
{'Bits':list(range(8,14)), 'Name':'User Laser', 'Op':'Bits',
'Value':{'8':'Seed1',
'9':'Seed2',
'10':'Seed3',
'11':'PP1',
'12':'PP2',
'13':'PP3'}},
{'Bits':list(range(14,18)), 'Name':'Not used', 'Op':'Bits',
'Value':{'14':'Not used bit 14',
'15':'Not used bit 15',
'16':'Not used bit 16',
'17':'Not used bit 17'}},
{'Bits':list(range(18,22)), 'Name':'Destination', 'Op':'Abs',
'Value':{'0':'None',
'1':'LSt (Laser stand-alone)',
'2':'FL2D (FLASH2 dump)',
'3':'GnD (Gun dump/IDUMP)',
'4':'FL1D (FLASH1 dump)',
'5':'Not used value 5',
'6':'Not used value 6',
'7':'Not used value 7',
'8':'FFwD (FLASH3 dump)' }},
{'Bits':list(range(22,23)), 'Name':'Event trigger 25', 'Op':'Bits',
'Value':{'22':'Reduced rep rate' }},
{'Bits':list(range(23,27)), 'Name':'Not used', 'Op':'Bits',
'Value':{'23':'Not used bit 23',
'24':'Not used bit 24',
'25':'Not used bit 25',
'26':'Not used bit 26' }},
{'Bits':list(range(27,32)), 'Name':'Special Flags', 'Op':'Bits',
'Value':{'27':'Photon mirror',
'28':'Wire scanner',
'29':'LOLA',
'30':'CRISP kicker',
'31':'Undefined bit 31'}}],
'XFEL':[{'Bits':list(range(0,4)), 'Name':'Charge', 'Op':'Abs',
'Value':{'0':0, '1':0.02, '2':0.03, '3':0.04,
'4':0.06, '5':0.09, '6':0.13, '7':0.18,
'8':0.25, '9':0.36, '10':0.50, '11':0.71,
'12':1.00, '13':1.42, '14':2.00, '15':4.00}},
{'Bits':list(range(4,8)), 'Name':'Injector Laser', 'Op':'Bits',
'Value':{'4':'I1.Laser1', '5':'I1.Laser2', '6':'I1.Laser3', '7':'I2.Laser1'}},
{'Bits':list(range(8,17)), 'Name':'Seed/user Laser', 'Op':'Bits',
'Value':{'8':'Seed/user Laser1',
'9':'Seed/user Laser2',
'10':'Seed/user Laser3',
'11':'Seed/user Laser4',
'12':'Seed/user Laser5',
'13':'Seed/user Laser6',
'14':'Seed/user Laser7',
'15':'Seed/user Laser8',
'16':'Seed/user Laser9'}},
{'Bits':list(range(18,22)), 'Name':'Destination', 'Op':'Abs',
'Value':{'0':'None',
'1':'I1lSt (Laser stand-alone)',
'2':'T5D (SASE2 dump)',
'3':'G1D (Gun dump/valve)',
'4':'T4D (SASE1/3 dump)',
'5':'I1D (Injector dump)',
'6':'B1D (B1 dump)',
'7':'B2D (B2 dump)',
'8':'TLD' }},
{'Bits':list(range(22,25)), 'Name':'Not used', 'Op':'Bits',
'Value':{'22':'Not used bit 22',
'23':'Not used bit 23',
'24':'Not used bit 24' }},
{'Bits':list(range(25,32)), 'Name':'Special Flags', 'Op':'Bits',
'Value':{'25':'SASE3 soft kick (T4)',
'26':'Beam distribution kicker (T1)',
'27':'Soft kick (e.g.SA3)',
'28':'Wire scanner',
'29':'TDS BC2',
'30':'TDS BC1',
'31':'TDS Inj'}}]
}
SASE_info = {'FLASH': [{'Bits': list(range(0, 4)), 'Name': 'Charge', 'Op': 'Abs',
'Value': {'0': 0, '1': 0.02, '2': 0.03, '3': 0.04,
'4': 0.06, '5': 0.09, '6': 0.13, '7': 0.18,
'8': 0.25, '9': 0.36, '10': 0.50, '11': 0.71,
'12': 1.00, '13': 1.42, '14': 2.00, '15': 4.00}},
{'Bits': list(range(4, 8)), 'Name': 'Injector Laser', 'Op': 'Bits',
'Value': {'4': 'Laser1', '5': 'Laser2', '6': 'Laser3', '7': 'Laser4'}},
{'Bits': list(range(8, 14)), 'Name': 'User Laser', 'Op': 'Bits',
'Value': {'8': 'Seed1',
'9': 'Seed2',
'10': 'Seed3',
'11': 'PP1',
'12': 'PP2',
'13': 'PP3'}},
{'Bits': list(range(14, 18)), 'Name': 'Not used', 'Op': 'Bits',
'Value': {'14': 'Not used bit 14',
'15': 'Not used bit 15',
'16': 'Not used bit 16',
'17': 'Not used bit 17'}},
{'Bits': list(range(18, 22)), 'Name': 'Destination', 'Op': 'Abs',
'Value': {'0': 'None',
'1': 'LSt (Laser stand-alone)',
'2': 'FL2D (FLASH2 dump)',
'3': 'GnD (Gun dump/IDUMP)',
'4': 'FL1D (FLASH1 dump)',
'5': 'Not used value 5',
'6': 'Not used value 6',
'7': 'Not used value 7',
'8': 'FFwD (FLASH3 dump)'}},
{'Bits': list(range(22, 23)), 'Name': 'Event trigger 25', 'Op': 'Bits',
'Value': {'22': 'Reduced rep rate'}},
{'Bits': list(range(23, 27)), 'Name': 'Not used', 'Op': 'Bits',
'Value': {'23': 'Not used bit 23',
'24': 'Not used bit 24',
'25': 'Not used bit 25',
'26': 'Not used bit 26'}},
{'Bits': list(range(27, 32)), 'Name': 'Special Flags', 'Op': 'Bits',
'Value': {'27': 'Photon mirror',
'28': 'Wire scanner',
'29': 'LOLA',
'30': 'CRISP kicker',
'31': 'Undefined bit 31'}}],
'XFEL': [{'Bits': list(range(0, 4)), 'Name': 'Charge', 'Op': 'Abs',
'Value': {'0': 0, '1': 0.02, '2': 0.03, '3': 0.04,
'4': 0.06, '5': 0.09, '6': 0.13, '7': 0.18,
'8': 0.25, '9': 0.36, '10': 0.50, '11': 0.71,
'12': 1.00, '13': 1.42, '14': 2.00, '15': 4.00}},
{'Bits': list(range(4, 8)), 'Name': 'Injector Laser', 'Op': 'Bits',
'Value': {'4': 'I1.Laser1', '5': 'I1.Laser2', '6': 'I1.Laser3', '7': 'I2.Laser1'}},
{'Bits': list(range(8, 17)), 'Name': 'Seed/user Laser', 'Op': 'Bits',
'Value': {'8': 'Seed/user Laser1',
'9': 'Seed/user Laser2',
'10': 'Seed/user Laser3',
'11': 'Seed/user Laser4',
'12': 'Seed/user Laser5',
'13': 'Seed/user Laser6',
'14': 'Seed/user Laser7',
'15': 'Seed/user Laser8',
'16': 'Seed/user Laser9'}},
{'Bits': list(range(18, 22)), 'Name': 'Destination', 'Op': 'Abs',
'Value': {'0': 'None',
'1': 'I1lSt (Laser stand-alone)',
'2': 'T5D (SASE2 dump)',
'3': 'G1D (Gun dump/valve)',
'4': 'T4D (SASE1/3 dump)',
'5': 'I1D (Injector dump)',
'6': 'B1D (B1 dump)',
'7': 'B2D (B2 dump)',
'8': 'TLD'}},
{'Bits': list(range(22, 25)), 'Name': 'Not used', 'Op': 'Bits',
'Value': {'22': 'Not used bit 22',
'23': 'Not used bit 23',
'24': 'Not used bit 24'}},
{'Bits': list(range(25, 32)), 'Name': 'Special Flags', 'Op': 'Bits',
'Value': {'25': 'SASE3 soft kick (T4)',
'26': 'Beam distribution kicker (T1)',
'27': 'Soft kick (e.g.SA3)',
'28': 'Wire scanner',
'29': 'TDS BC2',
'30': 'TDS BC1',
'31': 'TDS Inj'}}]
}
class DAQBunchPattern:
class DAQBunchPattern:
def __init__(self, linac='XFEL'):
# constants for Scan Mode
self.linacs = SASE_info.keys()
self.linac = None
self.bunch_info = None
list_out = []
for lin in self.linacs:
for lin in self.linacs:
linc = linac.upper()
list_out.append(lin)
list_out.append(lin)
if linc == lin:
self.bunch_info = SASE_info[lin]
self.linac = linc
if not self.bunch_info:
if not self.bunch_info:
out = "Unknown LINAC name " + linac + ' (must be one of'
for l in list_out:
out += ' ' + l
out += ')'
raise Exception(out)
def get_names_of_all_linac(self):
out = []
for entry in self.linacs:
......@@ -117,65 +116,76 @@ class DAQBunchPattern:
return out
def print_all_patterns(self):
print('LINAC->%s'%self.linac)
print('LINAC->%s' % self.linac)
for entry in self.bunch_info:
print('\t%s:'% entry['Name'].strip('"\''), end='')
print('\t%s:' % entry['Name'].strip('"\''), end='')
for val in entry['Value'].values():
print('\n\t\t%s'% str(val).strip('"\''), end='')
print('\n\t\t%s' % str(val).strip('"\''), end='')
print()
def get_bunch_pattern_info(self, mode, debug):
if isinstance(mode, int):
pass
elif isinstance(mode, float) or isinstance(mode, np.float32):
mode = dqb.float2int(mode)
else:
raise Exception("Invalid data type %s (must be int or float) "%(type(mode)))
raise Exception(
"Invalid data type %s (must be int or float) " % (type(mode)))
result = []
if debug: print('mode: 0x%X'%mode)
if debug:
print('mode: 0x%X' % mode)
for entry in self.bunch_info:
bits = entry['Bits']
bits = entry['Bits']
op = entry['Op']
name = entry['Name']
values= entry['Value']
values = entry['Value']
mask = (2**(len(bits))) - 1
shift = bits[0]
if debug: print('Name: %s Op:%s Bits Total: %d Shift:%d Mask:%d'%(name, op, len(bits), shift, mask))
if debug:
print('Name: %s Op:%s Bits Total: %d Shift:%d Mask:%d' %
(name, op, len(bits), shift, mask))
if op == 'Abs':
rest = (mode>>shift) & mask
rest = (mode >> shift) & mask
for val in values.keys():
if int(val) == rest:
if debug : print('%s -> %s '%(name, values[val]))
result.append({name:values[val]})
if debug:
print('%s -> %s ' % (name, values[val]))
result.append({name: values[val]})
break
if op == 'Bits':
out = []
for val in values.keys():
if 1<<int(val) & mode:
if 1 << int(val) & mode:
#print('Comparing 0x%X 0x%X'%(1<<int(val), mode))
if debug : print('%s -> %s '%(name, values[val]))
result.append({name:values[val]})
if debug:
print('%s -> %s ' % (name, values[val]))
result.append({name: values[val]})
#if out != []:
# if out != []:
# if debug: print('%s -> '%(name), out)
# result.append(out)
if debug: print('result:', result)
# result.append(out)
if debug:
print('result:', result)
return result
def check_bunch_pattern(self, value, pattern, logic, debug):
if not isinstance(pattern, list):
raise Exception("Invalid data type %s (must be list) "(type(pattern)))
if not isinstance(pattern, list):
raise Exception(
"Invalid data type %s (must be list) "(type(pattern)))
res = self.get_bunch_pattern_info(value, debug)
if pattern == []: return True, res
if pattern == []:
return True, res
found = 0
for item in pattern:
for entry in res:
ks = item.keys()
for t in ks:
if t in entry and (entry[t] == item[t]):
if t in entry and (entry[t] == item[t]):
found += 1
if logic == 'AND' and found == len(pattern): return True, res
if logic == 'OR' and found: return True, res
if logic == 'AND' and found == len(pattern):
return True, res
if logic == 'OR' and found:
return True, res
return False, res
......@@ -9,69 +9,88 @@
# where n - bit index (0...)
# variable for XML channel description file parsing
tags = {'STREAM':0, 'EVTYPE':'', 'DTYPE':'', 'COUNT':0, 'SB_NAME':'None', 'DB_KEY':0, 'PROP':'', 'NAME':'', 'SETPOINT':0, 'SUBSYSTEM':'', 'UNITS':'', 'DESC':'', 'SIZE':0, 'DIM':{}, 'BIT':{}}
tagstoattr = { 'EVTYPE': 'EventTypeMask', 'DTYPE':'DAQdatatype', 'DB_KEY':'RCDBkey', 'SB_NAME':'ServerBlockName', 'PROP':'DOOCSproperty', 'NAME':'DAQchannel', 'SETPOINT':'Setpoint', 'SUBSYSTEM':'Subsystem', 'UNITS':'Units', 'DESC':'Description'}
tagstoattrsubch = {'DIM':{'DIM_NAME':'SubchannelName', 'DIM_UNITS':'SubchanelUnits', 'DIM_DESCR':'SubchannelDescription'}, 'BIT':{'BIT_NAME':'BitName', 'BIT_DESCR':'BitDescription'}}
tags = {'STREAM': 0, 'EVTYPE': '', 'DTYPE': '', 'COUNT': 0, 'SB_NAME': 'None', 'DB_KEY': 0, 'PROP': '',
'NAME': '', 'SETPOINT': 0, 'SUBSYSTEM': '', 'UNITS': '', 'DESC': '', 'SIZE': 0, 'DIM': {}, 'BIT': {}}
tagstoattr = {'EVTYPE': 'EventTypeMask', 'DTYPE': 'DAQdatatype', 'DB_KEY': 'RCDBkey', 'SB_NAME': 'ServerBlockName',
'PROP': 'DOOCSproperty', 'NAME': 'DAQchannel', 'SETPOINT': 'Setpoint', 'SUBSYSTEM': 'Subsystem', 'UNITS': 'Units', 'DESC': 'Description'}
tagstoattrsubch = {'DIM': {'DIM_NAME': 'SubchannelName', 'DIM_UNITS': 'SubchanelUnits',
'DIM_DESCR': 'SubchannelDescription'}, 'BIT': {'BIT_NAME': 'BitName', 'BIT_DESCR': 'BitDescription'}}
internaltags = {'DIM', 'BIT'}
dimtags = {'DIM_NAME':None, 'DIM_UNITS':None, 'DIM_DESCR':None, 'DIM_START':None, 'DIM_INC':None, 'DIM_NDATA':None , 'DIM_GROUPS':None, 'DIM_GROUP_INC':None, 'DIM_XSTART':None, 'DIM_WIDTH':None, 'DIM_XBIN':None, 'DIM_YSTART':None, 'DIM_HEIGHT':None, 'DIM_YBIN':None, 'DIM_BPP':None, 'DIM_EBITPP':None, 'DIM_UNSIGNED':None}
dimtags = {'DIM_NAME': None, 'DIM_UNITS': None, 'DIM_DESCR': None, 'DIM_START': None, 'DIM_INC': None, 'DIM_NDATA': None, 'DIM_GROUPS': None, 'DIM_GROUP_INC': None,
'DIM_XSTART': None, 'DIM_WIDTH': None, 'DIM_XBIN': None, 'DIM_YSTART': None, 'DIM_HEIGHT': None, 'DIM_YBIN': None, 'DIM_BPP': None, 'DIM_EBITPP': None, 'DIM_UNSIGNED': None}
# table for mapping TAGS to attributes
dimtagstoattr ={'DIM_UNITS':'Units', 'DIM_DESCR':'Description', 'DIM_START':'Start', 'DIM_INC':'Inc', 'DIM_NDATA':'GroupSamples', 'DIM_GROUPS':'Groups', 'DIM_GROUP_INC':'GroupInc', 'DIM_XSTART':'Xstart', 'DIM_WIDTH':'Width', 'DIM_XBIN':'Xbin', 'DIM_YSTART':'Ystart', 'DIM_HEIGHT':'Height', 'DIM_YBIN':'Ybin', 'DIM_BPP':'Bytesperpixel', 'DIM_EBITPP':'Bitsperpixel', 'DIM_UNSIGNED':'Unsigned'}
dimtagstoattr = {'DIM_UNITS': 'Units', 'DIM_DESCR': 'Description', 'DIM_START': 'Start', 'DIM_INC': 'Inc', 'DIM_NDATA': 'GroupSamples', 'DIM_GROUPS': 'Groups', 'DIM_GROUP_INC': 'GroupInc', 'DIM_XSTART': 'Xstart',
'DIM_WIDTH': 'Width', 'DIM_XBIN': 'Xbin', 'DIM_YSTART': 'Ystart', 'DIM_HEIGHT': 'Height', 'DIM_YBIN': 'Ybin', 'DIM_BPP': 'Bytesperpixel', 'DIM_EBITPP': 'Bitsperpixel', 'DIM_UNSIGNED': 'Unsigned'}
# Tags that can have sub-tags
bittags = {'BIT_NAME':'', 'BIT_DESCR':''}
bittags = {'BIT_NAME': '', 'BIT_DESCR': ''}
# tags containig integers
inttags = ['STREAM', 'DB_KEY', 'COUNT', 'SETPOINT', 'SIZE', 'DIM_NDATA', 'DIM_GROUPS', 'DIM_XSTART', 'DIM_WIDTH', 'DIM_XBIN', 'DIM_YSTART', 'DIM_HEIGHT', 'DIM_YBIN', 'DIM_BPP', 'DIM_EBITPP', 'DIM_UNSIGNED']
inttags = ['STREAM', 'DB_KEY', 'COUNT', 'SETPOINT', 'SIZE', 'DIM_NDATA', 'DIM_GROUPS', 'DIM_XSTART',
'DIM_WIDTH', 'DIM_XBIN', 'DIM_YSTART', 'DIM_HEIGHT', 'DIM_YBIN', 'DIM_BPP', 'DIM_EBITPP', 'DIM_UNSIGNED']
# tags containig floats
floattags = ['DIM_START', 'DIM_INC', 'DIM_GROUP_INC']
def clean_dimtags():
global dimtags
dimtags = {'DIM_NAME':None, 'DIM_UNITS':None, 'DIM_DESCR':None, 'DIM_START':None, 'DIM_INC':None, 'DIM_NDATA':None , 'DIM_GROUPS':None, 'DIM_GROUP_INC':None, 'DIM_XSTART':None, 'DIM_WIDTH':None, 'DIM_XBIN':None, 'DIM_YSTART':None, 'DIM_HEIGHT':None, 'DIM_YBIN':None, 'DIM_BPP':None, 'DIM_EBITPP':None, 'DIM_UNSIGNED':None}
dimtags = {'DIM_NAME': None, 'DIM_UNITS': None, 'DIM_DESCR': None, 'DIM_START': None, 'DIM_INC': None, 'DIM_NDATA': None, 'DIM_GROUPS': None, 'DIM_GROUP_INC': None,
'DIM_XSTART': None, 'DIM_WIDTH': None, 'DIM_XBIN': None, 'DIM_YSTART': None, 'DIM_HEIGHT': None, 'DIM_YBIN': None, 'DIM_BPP': None, 'DIM_EBITPP': None, 'DIM_UNSIGNED': None}
def clean_bittags():
global bittags
bittags = {'BIT_NAME':'', 'BIT_DESCR':''}
bittags = {'BIT_NAME': '', 'BIT_DESCR': ''}
def allcleanup():
global tags
tags = {'STREAM':0, 'EVTYPE':'', 'DTYPE':'', 'COUNT':0, 'SB_NAME':'None', 'DB_KEY':0, 'PROP':'', 'NAME':'', 'SETPOINT':0, 'SUBSYSTEM':'', 'UNITS':'', 'DESC':'', 'SIZE':0, 'DIM':{}, 'BIT':{}}
tags = {'STREAM': 0, 'EVTYPE': '', 'DTYPE': '', 'COUNT': 0, 'SB_NAME': 'None', 'DB_KEY': 0, 'PROP': '',
'NAME': '', 'SETPOINT': 0, 'SUBSYSTEM': '', 'UNITS': '', 'DESC': '', 'SIZE': 0, 'DIM': {}, 'BIT': {}}
clean_dimtags()
clean_bittags()
def get_xml_tag(pat):
return '<'+pat+'>'
def get_xml_tagn(pat):
return '<'+pat+'>\n'
def get_xml_endtag(pat):
return '</'+pat+'>'
def get_xml_endtagn(pat):
return '</'+pat+'>\n'
class DAQChanDescr:
def __init__(self, dtype = 0, sb_name = "", prop = "", name = "", chan={}):
self.chan = {'STREAM':0, 'EVTYPE':'', 'DTYPE':'', 'DB_KEY':0, 'COUNT':0, 'SB_NAME':'None', 'PROP':'', 'NAME':'', 'SETPOINT':0, 'SUBSYSTEM':'', 'UNITS':'', 'DESC':'', 'SIZE':0, 'DIM':{}, 'BIT':{}}
class DAQChanDescr:
def __init__(self, dtype=0, sb_name="", prop="", name="", chan={}):
self.chan = {'STREAM': 0, 'EVTYPE': '', 'DTYPE': '', 'DB_KEY': 0, 'COUNT': 0, 'SB_NAME': 'None', 'PROP': '',
'NAME': '', 'SETPOINT': 0, 'SUBSYSTEM': '', 'UNITS': '', 'DESC': '', 'SIZE': 0, 'DIM': {}, 'BIT': {}}
if chan != {}:
for key in chan.keys():
if key in self.chan:
self.chan[key] = chan[key]
if sb_name != '':
if sb_name != '':
self.chan['SB_NAME'] = sb_name
if prop != '':
if prop != '':
self.chan['PROP'] = prop
if name != '':
if name != '':
self.chan['NAME'] = name
def get_attr(self, nm):
if nm in self.chan.keys():
return self.chan[nm]
else:
return None
if nm in self.chan.keys():
return self.chan[nm]
else:
return None
def is_it_you(self, nm):
if self.chan['NAME'] == nm:
......@@ -81,23 +100,23 @@ class DAQChanDescr:
def get_dims(self, index):
tag = "DIM"+str(index)
#print(index, self.chan)
for hash in self.chan["DIM"]:
for hash in self.chan["DIM"]:
#print('index', index,'tag', tag, 'hash',hash)
if tag in hash:
return self.chan["DIM"][hash]
#return hash[tag]
# return hash[tag]
return None
def get_bits(self, index):
tag = "BIT"+str(index)
for hash in self.chan["BIT"]:
for hash in self.chan["BIT"]:
if tag in hash:
return hash[tag]
return None
def get_name(self):
return self.chan['NAME']
def print(self):
print(self.chan)
......@@ -106,26 +125,29 @@ class DAQChanDescr:
for key in self.chan.keys():
if key == 'DIM' or key == 'BIT':
if self.chan[key] != {}:
if key == 'DIM':
if key == 'DIM':
n = self.chan[key]['DIMS']
else: n = self.chan[key]['BITS']
else:
n = self.chan[key]['BITS']
total = 0
index = 0
while total < n and index < 64:
lkey = key + str(index)
if lkey in self.chan[key]:
if lkey in self.chan[key]:
out += get_xml_tag(key) + str(index) + '\n'
lkey = key + str(index)
for dkey in self.chan[key][lkey]:
if dkey != 'DIMS' and dkey != 'BITS':
out += get_xml_tag(dkey)
if self.chan[key][lkey][dkey] != None: out += str(self.chan[key][lkey][dkey]).replace('\n', '')
if self.chan[key][lkey][dkey] != None:
out += str(self.chan[key][lkey]
[dkey]).replace('\n', '')
out += get_xml_endtagn(dkey)
out += get_xml_endtagn(key)
total += 1
index += 1
else:
out += get_xml_tag(key)
out += get_xml_tag(key)
if self.chan[key] == 0 or self.chan[key] == '':
out += str(0)
elif self.chan[key] == 'None':
......@@ -134,7 +156,7 @@ class DAQChanDescr:
out += str(self.chan[key])
out += get_xml_endtagn(key)
out += get_xml_endtagn('CHANNEL')
return out
return out
'''
<CHANNEL>
<STREAM>0</STREAM>
......@@ -171,4 +193,4 @@ class DAQChanDescr:
</BIT>
</CHANNEL>
'''
\ No newline at end of file
'''
......@@ -6,38 +6,37 @@ import DAQChanDescr
import datetime
class ChanDescrList:
class ChanDescrList:
def __init__(self, xmlfile = "", chans=[], chandescrlst=[]):
def __init__(self, xmlfile="", chans=[], chandescrlst=[]):
self.chans = chans # channels to extract, if [] - all
self.xmlfile = xmlfile
self.chandescrlst = []
if chandescrlst == [] and ((self.xmlfile == '' or not os.path.exists(self.xmlfile)) or (not os.access(self.xmlfile, os.R_OK) )):
raise Exception("Something wrong with XML file OR channel description list is empty" + self.xmlfile)
self.chandescrlst = []
if chandescrlst == [] and ((self.xmlfile == '' or not os.path.exists(self.xmlfile)) or (not os.access(self.xmlfile, os.R_OK))):
raise Exception(
"Something wrong with XML file OR channel description list is empty" + self.xmlfile)
if chandescrlst != []:
self.chandescrlst = chandescrlst
return
tree = ET.parse(self.xmlfile)
root = tree.getroot()
root = tree.getroot()
dims = 0
bits = 0
bits = 0
for elem in root:
#print(elem.tag)
# print(elem.tag)
if elem.tag == 'CHANNEL':
if DAQChanDescr.tags['NAME'] != '':
#creating a new chan description
if DAQChanDescr.tags['NAME'] != '':
# creating a new chan description
#tags['DIM'] = dims
#tags['BIT'] = bits
if dims:
DAQChanDescr.tags['DIM'].update({'DIMS':dims})
DAQChanDescr.tags['DIM'].update({'DIMS': dims})
if bits:
DAQChanDescr.tags['BIT'].update({'BITS':bits})
DAQChanDescr.tags['BIT'].update({'BITS': bits})
dims = 0
bits = 0
chd = DAQChanDescr.DAQChanDescr(chan = DAQChanDescr.tags)
bits = 0
chd = DAQChanDescr.DAQChanDescr(chan=DAQChanDescr.tags)
if self.chans == [] or chd.get_name() in self.chans:
self.chandescrlst.append(chd)
DAQChanDescr.allcleanup()
......@@ -46,87 +45,95 @@ class ChanDescrList:
#print(subelem.tag, ":",subelem.text )
if subelem.tag not in DAQChanDescr.internaltags:
if subelem.tag in DAQChanDescr.inttags:
DAQChanDescr.tags[subelem.tag] = int(subelem.text)
DAQChanDescr.tags[subelem.tag] = int(subelem.text)
elif subelem.tag in DAQChanDescr.floattags:
DAQChanDescr.tags[subelem.tag] = float(subelem.text)
DAQChanDescr.tags[subelem.tag] = float(
subelem.text)
else:
DAQChanDescr.tags[subelem.tag] = subelem.text
if subelem.tag in DAQChanDescr.internaltags: # checking for DIM or BIT
DAQChanDescr.tags[subelem.tag] = subelem.text
if subelem.tag in DAQChanDescr.internaltags: # checking for DIM or BIT
DAQChanDescr.clean_dimtags()
DAQChanDescr.clean_bittags()
index = subelem.text.strip() # DIM or BIT index
# DIM or BIT index
index = subelem.text.strip()
for inelem in subelem:
if inelem.tag in DAQChanDescr.dimtags:
#print(inelem.tag, " " , type(inelem.text), " ", inelem.text)
#print(inelem.tag, " " , type(inelem.text), " ", inelem.text)
if inelem.text != None and inelem.text != 'None':
if inelem.tag in DAQChanDescr.inttags: