hasyutils 2.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. HasyUtils/MgUtils.py +722 -0
  2. HasyUtils/MsUtils.py +1283 -0
  3. HasyUtils/OtherUtils.py +1097 -0
  4. HasyUtils/TgUtils.py +6712 -0
  5. HasyUtils/__init__.py +11 -0
  6. HasyUtils/fastscananalysis.py +476 -0
  7. HasyUtils/fioReader.py +714 -0
  8. HasyUtils/nxIO.py +309 -0
  9. HasyUtils/nxsReader.py +697 -0
  10. HasyUtils/nxsconftools.py +144 -0
  11. HasyUtils/pooltools.py +2648 -0
  12. HasyUtils/pyqtSelector.py +49 -0
  13. HasyUtils/spectraDoor.py +1549 -0
  14. HasyUtils/ssa.py +223 -0
  15. HasyUtils/tngMonitorAttrs.py +567 -0
  16. hasyutils-2.0.0.data/scripts/ECMonitor.py +85 -0
  17. hasyutils-2.0.0.data/scripts/HasyUtilsMain.py +44 -0
  18. hasyutils-2.0.0.data/scripts/MotorLogger.py +439 -0
  19. hasyutils-2.0.0.data/scripts/SardanaAIO.py +140 -0
  20. hasyutils-2.0.0.data/scripts/SardanaAdjustLimits.py +63 -0
  21. hasyutils-2.0.0.data/scripts/SardanaAlarmMonitor.py +129 -0
  22. hasyutils-2.0.0.data/scripts/SardanaChMg.py +289 -0
  23. hasyutils-2.0.0.data/scripts/SardanaChat.py +58 -0
  24. hasyutils-2.0.0.data/scripts/SardanaCheckOnlineXml.py +108 -0
  25. hasyutils-2.0.0.data/scripts/SardanaClearSCAs.py +22 -0
  26. hasyutils-2.0.0.data/scripts/SardanaConvert.py +1847 -0
  27. hasyutils-2.0.0.data/scripts/SardanaDeleteMotorGroups.py +32 -0
  28. hasyutils-2.0.0.data/scripts/SardanaDiag.py +149 -0
  29. hasyutils-2.0.0.data/scripts/SardanaIVP.py +767 -0
  30. hasyutils-2.0.0.data/scripts/SardanaInfoViewer.py +165 -0
  31. hasyutils-2.0.0.data/scripts/SardanaLimitsFromTS2Pool.py +31 -0
  32. hasyutils-2.0.0.data/scripts/SardanaMacroExecutor.py +51 -0
  33. hasyutils-2.0.0.data/scripts/SardanaMacroTester.py +256 -0
  34. hasyutils-2.0.0.data/scripts/SardanaMotorMonitor.py +318 -0
  35. hasyutils-2.0.0.data/scripts/SardanaRestartBoth.py +36 -0
  36. hasyutils-2.0.0.data/scripts/SardanaRestartMacroServer.py +51 -0
  37. hasyutils-2.0.0.data/scripts/SardanaRestartPool.py +40 -0
  38. hasyutils-2.0.0.data/scripts/SardanaShutdown.py +80 -0
  39. hasyutils-2.0.0.data/scripts/SardanaStartMacroServer.py +39 -0
  40. hasyutils-2.0.0.data/scripts/SardanaStartPool.py +40 -0
  41. hasyutils-2.0.0.data/scripts/SardanaStartup.py +245 -0
  42. hasyutils-2.0.0.data/scripts/SardanaStatus.py +63 -0
  43. hasyutils-2.0.0.data/scripts/SardanaStopBoth.py +28 -0
  44. hasyutils-2.0.0.data/scripts/SardanaStopMacro.py +57 -0
  45. hasyutils-2.0.0.data/scripts/SardanaStopMacroServer.py +36 -0
  46. hasyutils-2.0.0.data/scripts/SardanaStopPool.py +38 -0
  47. hasyutils-2.0.0.data/scripts/TngEigerCLI.py +277 -0
  48. hasyutils-2.0.0.data/scripts/TngMonitorAttrs.py +83 -0
  49. hasyutils-2.0.0.data/scripts/TngUtility.py +1445 -0
  50. hasyutils-2.0.0.data/scripts/alarm.ui +54 -0
  51. hasyutils-2.0.0.data/scripts/nxs_ifc.py +50 -0
  52. hasyutils-2.0.0.data/scripts/nxsclient.py +51 -0
  53. hasyutils-2.0.0.data/scripts/nxsreader.py +62 -0
  54. hasyutils-2.0.0.dist-info/AUTHORS +7 -0
  55. hasyutils-2.0.0.dist-info/LICENSE +34 -0
  56. hasyutils-2.0.0.dist-info/METADATA +9 -0
  57. hasyutils-2.0.0.dist-info/RECORD +59 -0
  58. hasyutils-2.0.0.dist-info/WHEEL +6 -0
  59. hasyutils-2.0.0.dist-info/top_level.txt +1 -0
HasyUtils/MgUtils.py ADDED
@@ -0,0 +1,722 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ import string
4
+ import sys, os
5
+ try:
6
+ from PyTango import *
7
+ except:
8
+ pass
9
+ import json
10
+ import pprint
11
+ from . import TgUtils
12
+ import platform
13
+
14
+ pp = pprint.PrettyPrinter()
15
+
16
+ #
17
+ #
18
+ #
19
+ class MgConf:
20
+ '''
21
+ poolName: if None, the first pool is taken
22
+ mntgrpName: the group name
23
+ flagClear: if True, the MG is cleared
24
+
25
+ Example:
26
+
27
+ mg = HasyUtils.MgUtils.MgConf( None, "mg1", True)
28
+ create mg1, in the default pool and clear it
29
+ mg.addTimer( "eh_t01")
30
+ mg.addCounter( "eh_c01", True)
31
+ flagDisplay == True
32
+ mg.addMCA( "eh_mca01")
33
+
34
+ mg.updateConfiguration()
35
+
36
+ '''
37
+ def __init__(self, poolName, mntgrpName, flagClear = False):
38
+ self.db = Database()
39
+
40
+ poolNames = TgUtils.getLocalPoolNames()
41
+ if poolName is None:
42
+ if len( poolNames) > 0:
43
+ poolName = poolNames[0]
44
+ else:
45
+ raise ValueError( "MgConf.__init__(): no pool")
46
+ #
47
+ # the pool for the Mg
48
+ #
49
+ try:
50
+ self.poolMg = DeviceProxy( poolName)
51
+ except DevFailed as e:
52
+ Except.print_exception( e)
53
+ print( "failed to get proxy to %s " % poolName)
54
+ sys.exit(255)
55
+ if not TgUtils.proxyHasAttribute( self.poolMg, 'ControllerList'):
56
+ print( "MgUtils.MgConf.__init__: %s is not a pool" % poolName)
57
+ sys.exit(255)
58
+
59
+ #
60
+ # note: getLocalPoolNames() returns only the local pools
61
+ # that have been exported at least once.
62
+ #
63
+ poolNames = TgUtils.getLocalPoolNames()
64
+ self.pools = []
65
+ for pool in poolNames:
66
+ if not checkPoolNameValid( pool):
67
+ print( "*** MgUtils.MgConf: ignoring pool %s" % pool)
68
+ continue
69
+ try:
70
+ self.pools.append( DeviceProxy( pool))
71
+ except:
72
+ Except.print_exception( e)
73
+ print( "failed to get proxy to %s" % pool)
74
+ sys.exit(255)
75
+ #
76
+ # find the MG
77
+ #
78
+ self.mntgrpName = mntgrpName
79
+ try:
80
+ self.mg = DeviceProxy( mntgrpName)
81
+ except:
82
+ timers = TgUtils.getTimerAliases()
83
+ if timers is None:
84
+ print( "MgConf: %s does not exist and cannot be created " % mntgrpName)
85
+ lst = [ mntgrpName, timers[0]]
86
+ try:
87
+ self.poolMg.command_inout( 'CreateMeasurementGroup', lst)
88
+ except Exception as e:
89
+ print( "MgUtils.MgConf.__init__(): CreateMeasurementGroup failed on %s" % self.poolMg.name())
90
+ print( "MgUtils.MgConf.__init__(): %s" % repr( lst))
91
+ self.mg = DeviceProxy( mntgrpName)
92
+
93
+ if not flagClear:
94
+ self.hsh = json.loads( self.mg.Configuration)
95
+ self.masterTimer = self.findMasterTimer()
96
+ self.index = len(self.mg.ElementList)
97
+ #TgUtils.dct_print( self.hsh)
98
+ else:
99
+ self.hsh = {}
100
+ self.hsh[ 'controllers'] = {}
101
+ self.hsh[ 'description'] = "Measurement Group"
102
+ self.hsh[ 'label'] = mntgrpName
103
+ self.index = 0
104
+ #print( "+++MgUtils.__init()__\n%s" % TgUtils.dct_print2str( self.hsh))
105
+
106
+ def updateConfiguration( self):
107
+ """
108
+ json-dump the dictionary self.hsh to the Mg configuration
109
+ """
110
+ #print( "+++MgUtils.updateConfiguration:\n%s" % TgUtils.dct_print2str( self.hsh))
111
+ self.mg.Configuration = json.dumps( self.hsh)
112
+
113
+ def findMasterTimer( self):
114
+
115
+ for ctrl in self.hsh[ 'controllers']:
116
+ if 'units' in self.hsh['controllers'][ctrl]:
117
+ Channels = self.hsh[ 'controllers'][ctrl][ 'units'][ '0'][ 'channels']
118
+ else:
119
+ Channels = self.hsh[ 'controllers'][ctrl][ 'channels']
120
+ for chan in Channels:
121
+ # dgg8 is also a dgg2 (interface-wise)
122
+ if chan.find( 'dgg2') > 0:
123
+ temp = chan
124
+ #
125
+ # Debian-8: haso107d1:10000/expchan/dgg2_d1_01/1 -> expchan/dgg2_d1_01/1
126
+ # Debian-9: tango://hasep212lab.desy.de:10000/expchan/dgg2__lab01/1
127
+ #
128
+ pos = temp.find( '0000')
129
+ if pos > 0:
130
+ temp = temp[pos+5:]
131
+ masterTimer = self.db.get_alias( str(temp))
132
+ return masterTimer
133
+ raise Exception( 'MgUtils.findMasterTimer', "No timer found")
134
+
135
+
136
+ def findDeviceController( self, device):
137
+ """
138
+ returns the controller that belongs to a device
139
+ """
140
+ lst = []
141
+ for pool in self.pools:
142
+ try:
143
+ if not pool.ExpChannelList is None:
144
+ lst += pool.ExpChannelList
145
+ except Exception as e:
146
+ print("MgUtils.findDeviceController: something is wrong with %s" % pool.dev_name())
147
+ print( "%s" % repr( e))
148
+ sys.exit(255)
149
+
150
+ ctrl = None
151
+ for elm in lst:
152
+ chan = json.loads( elm)
153
+ # chan:
154
+ #{
155
+ # 'axis': 17,
156
+ # 'controller': 'haso107klx:10000/controller/sis3820ctrl/sis3820_exp',
157
+ # 'full_name': 'haso107klx:10000/expchan/sis3820_exp/17',
158
+ # 'id': 146,
159
+ # 'instrument': '',
160
+ # 'interfaces': ['Object', 'PoolObject', 'Element', 'ExpChannel', 'PoolElement', 'CTExpChannel', 'Acquirable'],
161
+ # 'manager': 'exp_pool01',
162
+ # 'name': 'exp_c17',
163
+ # 'parent': 'sis3820_exp',
164
+ # 'pool': 'exp_pool01',
165
+ # 'source': 'haso107klx:10000/expchan/sis3820_exp/17/value',
166
+ # 'type': 'CTExpChannel',
167
+ # 'unit': '0',
168
+ #}
169
+ if device == chan['name']:
170
+ ctrl = chan['controller']
171
+ break
172
+ if ctrl is None and device.find("adc") >= 0:
173
+ ctrl = os.getenv("TANGO_HOST") + "/" + "controller/hasylabadcctrl/hasyadcctrl"
174
+ elif ctrl is None and device.find("vfc") >= 0:
175
+ ctrl = os.getenv("TANGO_HOST") + "/" + "controller/vfcadccontroller/hasyvfcadcctrl"
176
+ return ctrl
177
+
178
+
179
+ def findFullDeviceName( self, device):
180
+ """
181
+ input: exp_c01
182
+ returns: expchan/hasylabvirtualcounterctrl/1
183
+ """
184
+ lst = []
185
+ for pool in self.pools:
186
+ lst += pool.AcqChannelList
187
+ argout = None
188
+ for elm in lst:
189
+ chan = json.loads( elm)
190
+ if device == chan['name']:
191
+ #
192
+ # from: expchan/hasysis3820ctrl/1/value
193
+ # to: expchan/hasysis3820ctrl/1
194
+ #
195
+ arr = chan['full_name'].split("/")
196
+ argout = "/".join(arr[0:-1])
197
+ if argout is None:
198
+ raise Exception( 'MgUUtils.findFullDeviceName, %s' % device, "failed to find %s" % device)
199
+ return argout
200
+
201
+
202
+ def addTimer( self, device):
203
+ """
204
+ add a timer to the Mg
205
+ device: exp_t01
206
+ """
207
+ ctrl = self.findDeviceController( device)
208
+
209
+ if ctrl not in self.hsh[ 'controllers']:
210
+ self.masterTimer = device
211
+ self.hsh[ 'monitor'] = self.findFullDeviceName( device)
212
+ self.hsh[ 'timer'] = self.findFullDeviceName( device)
213
+ self.hsh[ 'controllers'][ ctrl] = {}
214
+ self.hsh[ 'controllers'][ ctrl][ 'synchronizer'] = "software"
215
+ self.hsh[ 'controllers'][ ctrl][ 'channels'] = {}
216
+ self.hsh[ 'controllers'][ ctrl][ 'monitor'] = self.findFullDeviceName(device)
217
+ self.hsh[ 'controllers'][ ctrl][ 'timer'] = self.findFullDeviceName(device)
218
+ self.hsh[ 'controllers'][ ctrl][ 'trigger_type'] = 0
219
+
220
+ ctrlChannels = self.hsh[ 'controllers'][ctrl][ 'channels']
221
+
222
+ fullDeviceName = self.findFullDeviceName( device)
223
+ if not fullDeviceName in list( ctrlChannels.keys()):
224
+ dct = {}
225
+ dct['conditioning'] = ''
226
+ dct['enabled'] = True
227
+ dct['full_name'] = fullDeviceName
228
+ dct['index'] = self.index
229
+ self.index += 1
230
+ dct['label'] = str( device)
231
+ dct['name'] = str( device)
232
+ dct['ndim'] = 0
233
+ dct['normalization'] = 0
234
+ dct['output'] = True
235
+ dct['plot_axes'] = ['<mov>']
236
+ dct['plot_type'] = 0
237
+ dct['source'] = dct['full_name'] + "/Value"
238
+ ctrlChannels[fullDeviceName] = dct
239
+
240
+ #
241
+ # add an extra timer to the measurement group
242
+ #
243
+ def addExtraTimer( self, device):
244
+ """ device: exp_t01"""
245
+ ctrl = self.findDeviceController( device)
246
+
247
+ if ctrl not in self.hsh[ 'controllers']:
248
+ self.hsh[ 'controllers'][ ctrl] = {}
249
+ self.hsh[ 'controllers'][ ctrl][ 'synchronizer'] = "software"
250
+ self.hsh[ 'controllers'][ ctrl][ 'channels'] = {}
251
+ self.hsh[ 'controllers'][ ctrl][ 'monitor'] = self.findFullDeviceName(device)
252
+ self.hsh[ 'controllers'][ ctrl][ 'timer'] = self.findFullDeviceName(device)
253
+ self.hsh[ 'controllers'][ ctrl][ 'trigger_type'] = 0
254
+
255
+ ctrlChannels = self.hsh[ 'controllers'][ctrl][ 'channels']
256
+
257
+ fullDeviceName = self.findFullDeviceName( device)
258
+ if not fullDeviceName in list( ctrlChannels.keys()):
259
+ dct = {}
260
+ dct['conditioning'] = ''
261
+ dct['enabled'] = True
262
+ dct['full_name'] = fullDeviceName
263
+ dct['index'] = self.index
264
+ self.index += 1
265
+ dct['label'] = str( device)
266
+ dct['name'] = str( device)
267
+ dct['ndim'] = 0
268
+ dct['normalization'] = 0
269
+ dct['output'] = True
270
+ dct['plot_axes'] = ['<mov>']
271
+ dct['plot_type'] = 0
272
+ dct['source'] = dct['full_name'] + "/Value"
273
+ ctrlChannels[fullDeviceName] = dct
274
+ #
275
+ # add a counter to the measurement group
276
+ #
277
+ def addCounter( self, device, flagDisplay, flagOutput = 1):
278
+
279
+ if device.find( 'sca_') == 0:
280
+ return self.addSCA( device, flagDisplay, flagOutput)
281
+
282
+ ctrl = self.findDeviceController( device)
283
+ fullDeviceName = self.findFullDeviceName( device)
284
+
285
+ if ctrl not in self.hsh[ 'controllers']:
286
+ self.hsh[ 'controllers'][ ctrl] = {}
287
+ self.hsh[ 'controllers'][ ctrl][ 'synchronization'] = 0
288
+ self.hsh[ 'controllers'][ ctrl][ 'synchronizer'] = "software"
289
+ self.hsh[ 'controllers'][ ctrl][ 'channels'] = {}
290
+ self.hsh[ 'controllers'][ ctrl][ 'monitor'] = fullDeviceName
291
+ self.hsh[ 'controllers'][ ctrl][ 'timer'] = fullDeviceName
292
+ self.hsh[ 'controllers'][ ctrl][ 'trigger_type'] = 0
293
+
294
+ ctrlChannels = self.hsh['controllers'][ctrl]['channels']
295
+
296
+ if not fullDeviceName in list( ctrlChannels.keys()):
297
+ dct = {}
298
+ dct['conditioning'] = ''
299
+ dct['enabled'] = True
300
+ dct['full_name'] = fullDeviceName
301
+ dct['index'] = self.index
302
+ self.index += 1
303
+ dct['label'] = str( device)
304
+ dct['name'] = str( device)
305
+ dct['ndim'] = 0
306
+ dct['normalization'] = 0
307
+ if flagOutput:
308
+ dct['output'] = True
309
+ else:
310
+ dct['output'] = False
311
+ dct['plot_axes'] = ['<mov>']
312
+ if flagDisplay:
313
+ dct['plot_type'] = 1
314
+ else:
315
+ dct['plot_type'] = 0
316
+ dct['source'] = dct['full_name'] + "/Value"
317
+ ctrlChannels[fullDeviceName] = dct
318
+ #
319
+ # add a MCA to the measurement group
320
+ #
321
+ def addMCA( self, device):
322
+ ctrl = self.findDeviceController( device)
323
+ fullDeviceName = self.findFullDeviceName( device)
324
+
325
+ #
326
+ # tango://haso107tk.desy.de:10000/controller/hasyonedctrl/mca8701_eh
327
+ #
328
+ if ctrl not in self.hsh[ 'controllers']:
329
+ # print( "MgUtils.addMCA adding controller %s" % ctrl)
330
+ self.hsh[ 'controllers'][ ctrl] = {}
331
+ self.hsh[ 'controllers'][ ctrl][ 'synchronizer'] = "software"
332
+ self.hsh[ 'controllers'][ ctrl][ 'channels'] = {}
333
+ self.hsh[ 'controllers'][ ctrl][ 'monitor'] = fullDeviceName
334
+ self.hsh[ 'controllers'][ ctrl][ 'timer'] = fullDeviceName
335
+ #self.hsh[ 'controllers'][ ctrl][ 'monitor'] = self.findFullDeviceName(self.masterTimer)
336
+ #self.hsh[ 'controllers'][ ctrl][ 'timer'] = self.findFullDeviceName(self.masterTimer)
337
+ self.hsh[ 'controllers'][ ctrl][ 'trigger_type'] = 0
338
+
339
+ ctrlChannels = self.hsh['controllers'][ctrl]['channels']
340
+
341
+ if not fullDeviceName in list( ctrlChannels.keys()):
342
+ dct = {}
343
+ dct['conditioning'] = ''
344
+ dct['enabled'] = True
345
+ dct['full_name'] = fullDeviceName
346
+ dct['index'] = self.index
347
+ self.index += 1
348
+ dct['label'] = str( device)
349
+ dct['name'] = str( device)
350
+ dct['ndim'] = 0
351
+ dct['normalization'] = 0
352
+ dct['output'] = True
353
+ dct['plot_axes'] = ['<mov>']
354
+ dct['plot_type'] = 0
355
+ dct['source'] = dct['full_name'] + "/Value"
356
+ ctrlChannels[fullDeviceName] = dct
357
+ #
358
+ # add a MCA to the measurement group
359
+ #
360
+ def addPilatus( self, device):
361
+ ctrl = self.findDeviceController( device)
362
+ fullDeviceName = self.findFullDeviceName( device)
363
+
364
+ if ctrl not in self.hsh[ 'controllers']:
365
+ #print( "MgUtils.addPilatus adding controller %s" % ctrl)
366
+ self.hsh[ 'controllers'][ ctrl] = {}
367
+ self.hsh[ 'controllers'][ ctrl][ 'synchronization'] = 0
368
+ self.hsh[ 'controllers'][ ctrl][ 'synchronizer'] = "software"
369
+ self.hsh[ 'controllers'][ ctrl][ 'channels'] = {}
370
+ self.hsh[ 'controllers'][ ctrl][ 'monitor'] = fullDeviceName
371
+ self.hsh[ 'controllers'][ ctrl][ 'timer'] = fullDeviceName
372
+ #self.hsh[ 'controllers'][ ctrl][ 'monitor'] = self.findFullDeviceName(self.masterTimer)
373
+ #self.hsh[ 'controllers'][ ctrl][ 'timer'] = self.findFullDeviceName(self.masterTimer)
374
+ self.hsh[ 'controllers'][ ctrl][ 'trigger_type'] = 0
375
+
376
+ ctrlChannels = self.hsh['controllers'][ctrl]['channels']
377
+
378
+ if not fullDeviceName in list( ctrlChannels.keys()):
379
+ dct = {}
380
+ dct['conditioning'] = ''
381
+ dct['enabled'] = True
382
+ dct['full_name'] = fullDeviceName
383
+ dct['index'] = self.index
384
+ self.index += 1
385
+ dct['label'] = str( device)
386
+ dct['name'] = str( device)
387
+ dct['ndim'] = 2
388
+ dct['normalization'] = 0
389
+ dct['output'] = True
390
+ dct['plot_axes'] = ['<mov>']
391
+ dct['plot_type'] = 0
392
+ dct['source'] = dct['full_name'] + "/Value"
393
+ ctrlChannels[fullDeviceName] = dct
394
+ #
395
+ # other: pilatus, lambda,
396
+ #
397
+ def addOther( self, device):
398
+ ctrl = self.findDeviceController( device)
399
+ fullDeviceName = self.findFullDeviceName( device)
400
+
401
+ if ctrl not in self.hsh[ 'controllers']:
402
+ self.hsh[ 'controllers'][ ctrl] = {}
403
+ self.hsh[ 'controllers'][ ctrl][ 'synchronizer'] = "software"
404
+ self.hsh[ 'controllers'][ ctrl][ 'channels'] = {}
405
+ self.hsh[ 'controllers'][ ctrl][ 'monitor'] = fullDeviceName
406
+ self.hsh[ 'controllers'][ ctrl][ 'timer'] = fullDeviceName
407
+ #self.hsh[ 'controllers'][ ctrl][ 'monitor'] = self.findFullDeviceName(self.masterTimer)
408
+ #self.hsh[ 'controllers'][ ctrl][ 'timer'] = self.findFullDeviceName(self.masterTimer)
409
+ self.hsh[ 'controllers'][ ctrl][ 'trigger_type'] = 0
410
+
411
+ ctrlChannels = self.hsh['controllers'][ctrl]['channels']
412
+
413
+ if not fullDeviceName in list( ctrlChannels.keys()):
414
+ dct = {}
415
+ dct['conditioning'] = ''
416
+ dct['enabled'] = True
417
+ dct['full_name'] = fullDeviceName
418
+ dct['index'] = self.index
419
+ self.index += 1
420
+ dct['label'] = str( device)
421
+ dct['name'] = str( device)
422
+ dct['ndim'] = 2
423
+ dct['normalization'] = 0
424
+ dct['output'] = True
425
+ dct['plot_axes'] = []
426
+ dct['plot_type'] = 0
427
+ dct['source'] = dct['full_name'] + "/Value"
428
+ ctrlChannels[fullDeviceName] = dct
429
+
430
+
431
+ def parseSCA( self, name):
432
+ """
433
+ name: sca_exp_mca01_100_200, returns [ 'exp_mca01', '100', '200']
434
+ """
435
+ lst = name.split('_')
436
+ return [ lst[1] + '_' + lst[2], lst[3], lst[4]]
437
+
438
+
439
+ def _getMcaName( self, mcaSardanaDeviceAlias):
440
+ """
441
+ input: sardana device name alias
442
+ output: the MCA Tango server name which is used by the Sardana device
443
+ """
444
+ try:
445
+ proxy = DeviceProxy( mcaSardanaDeviceAlias)
446
+ except DevFailed as e:
447
+ Except.re_throw_exception( e,
448
+ "MgUtils",
449
+ "failed to create proxy to %s " % mcaSardanaDeviceAlias,
450
+ "MgUtils._gHeMcaName")
451
+ return proxy.TangoDevice
452
+
453
+ def _addSca( self, device):
454
+ """
455
+ Input: device: sca_exp_mca01_100_200
456
+ Returns full controller name as e.g.: haso107klx:10000/controller/hasscactrl/sca_exp_mca01_100_200
457
+ Creates a HasySca controller and creates a device for this controller, There
458
+ is only one device per controller
459
+ """
460
+ mca, roiMin, roiMax = self.parseSCA( device)
461
+ #
462
+ # find the tango device name which is used my the sardana device
463
+ #
464
+ tgMca = self._getMcaName( mca)
465
+ #
466
+ # sca_exp_mca01_100_200_ctrl
467
+ #
468
+ ctrlAlias = device + "_ctrl"
469
+ #
470
+ # see whether the controller exists already
471
+ #
472
+ lst = []
473
+ for pool in self.pools:
474
+ lst += pool.ControllerList
475
+ ctrlFullName = None
476
+ for elm in lst:
477
+ chan = json.loads( elm)
478
+ if ctrlAlias == chan['name']:
479
+ ctrlFullName = chan['full_name']
480
+ break
481
+ #
482
+ # if the controller does not exist, create it
483
+ #
484
+ proxy = DeviceProxy( tgMca)
485
+ dataLength = proxy.DataLength
486
+ if int(roiMax) >= dataLength:
487
+ raise Exception( "MgUtils._addSca %s " % device,
488
+ "roiMax %d >= datalength %d " % (int(roiMax), int(dataLength)))
489
+ if int(roiMin) >= dataLength:
490
+ raise Exception( "MgUtils._addSca %s " % device,
491
+ "roiMin %d >= datalength %d " % (int(roiMin), dataLength))
492
+
493
+
494
+ if ctrlFullName is None:
495
+ lst = [ 'CTExpChannel', 'HasyScaCtrl.py', 'HasyScaCtrl', ctrlAlias, "mca", tgMca, "roi1", roiMin, "roi2", roiMax]
496
+ try:
497
+ self.poolMg.CreateController( lst)
498
+ except DevFailed as e:
499
+ Except.print_exception( e)
500
+ print( "poolMg.CreateController failed for %s" % str(lst))
501
+ sys.exit(255)
502
+
503
+ lst = self.poolMg.ControllerList
504
+ for elm in lst:
505
+ chan = json.loads( elm)
506
+ if ctrlAlias == chan['name']:
507
+ ctrlFullName = chan['full_name']
508
+ break
509
+ if ctrlFullName is None:
510
+ raise Exception( 'MgUtils._addSca', "failed to make controller for %s" % device)
511
+
512
+ #
513
+ # see whether the SCA device exists
514
+ #
515
+ lst = []
516
+ for pool in self.pools:
517
+ lst += pool.ExpChannelList
518
+ flag = False
519
+ for elm in lst:
520
+ chan = json.loads( elm)
521
+ if device == chan['name']:
522
+ flag = True
523
+ break
524
+
525
+ if not flag:
526
+ #
527
+ # "CTExpChannel","HasyScaCtrl","1","sca_exp_mca01_100_200"
528
+ #
529
+ lst = [ "CTExpChannel", ctrlAlias, "1", device]
530
+ self.poolMg.CreateElement( lst)
531
+
532
+ return ctrlFullName
533
+
534
+ def makeScaControllerForPseudoCounter( self, device):
535
+ """
536
+ Input: device: sca_exp_mca01_100_200
537
+ Returns full controller name, e.g.: haso107klx:10000/controller/mca2scactrl/sca_exp_mca01_100_200_ctrl
538
+ """
539
+ mca, roiMin, roiMax = self.parseSCA( device)
540
+
541
+ ctrlAlias = device + "_ctrl"
542
+ #
543
+ # see whether the controller exists already
544
+ #
545
+ lst = []
546
+ for pool in self.pools:
547
+ lst += pool.ControllerList
548
+ for elm in lst:
549
+ chan = json.loads( elm)
550
+ if ctrlAlias == chan['name']:
551
+ return chan['full_name']
552
+ lst = [ 'PseudoCounter', 'MCA2SCACtrl.py', 'MCA2SCACtrl', device + "_ctrl",
553
+ 'mca=' + self.findFullDeviceName( mca), 'sca=' + device]
554
+
555
+ self.poolMg.CreateController( lst)
556
+ #
557
+ # now it has been created. go through the list again an return the full controller name
558
+ #
559
+ lst = self.poolMg.ControllerList
560
+ for elm in lst:
561
+ chan = json.loads( elm)
562
+ if ctrlAlias == chan['name']:
563
+ # TgUtils.dct_print( chan)
564
+ #
565
+ # set the ROIs
566
+ #
567
+ proxy = DeviceProxy( device)
568
+ proxy.Roi1 = int(roiMin)
569
+ proxy.Roi2 = int(roiMax)
570
+ return chan['full_name']
571
+ raise Exception( 'MgUtils.makeController', "failed to make controller for %s" % device)
572
+
573
+
574
+ def addSCA( self, device, flagDisplay, flagOutput):
575
+ """
576
+ add a SCA to the measurement group
577
+ input: device, e.g. sca_exp_mca01_100_200
578
+
579
+ SardanaChMg.py -g tktest -t eh_t01 -c eh_c01,sca_eh_mca01_100_200 -m eh_mca01
580
+
581
+ """
582
+ if device.find('sca_') != 0:
583
+ print( "MgUtils.addSCA: '%s' does not begin with 'sca_'," % device)
584
+ return False
585
+
586
+ #
587
+ # there is one element per controller
588
+ #
589
+ ctrl = self._addSca( device)
590
+ fullDeviceName = self.findFullDeviceName( device)
591
+
592
+ if ctrl not in self.hsh[ 'controllers']:
593
+ #print( "MgUtils.addSca adding controller %s " % fullCtrlName)
594
+ self.hsh[ 'controllers'][ ctrl] = {}
595
+ self.hsh[ 'controllers'][ ctrl][ 'synchronizer'] = "software"
596
+ self.hsh[ 'controllers'][ ctrl][ 'channels'] = {}
597
+ self.hsh[ 'controllers'][ ctrl][ 'monitor'] = fullDeviceName
598
+ self.hsh[ 'controllers'][ ctrl][ 'timer'] = fullDeviceName
599
+ self.hsh[ 'controllers'][ ctrl][ 'trigger_type'] = 0
600
+
601
+ ctrlChannels = self.hsh['controllers'][ctrl]['channels']
602
+
603
+ if not fullDeviceName in list( ctrlChannels.keys()):
604
+ dct = {}
605
+ dct['conditioning'] = ''
606
+ dct['enabled'] = True
607
+ dct['full_name'] = fullDeviceName
608
+ dct['index'] = self.index
609
+ self.index += 1
610
+ dct['label'] = str( device)
611
+ dct['name'] = str( device)
612
+ dct['ndim'] = 0
613
+ dct['normalization'] = 0
614
+ if flagOutput:
615
+ dct['output'] = True
616
+ else:
617
+ dct['output'] = False
618
+ dct['plot_axes'] = ['<mov>']
619
+ if flagDisplay:
620
+ dct['plot_type'] = 1
621
+ else:
622
+ dct['plot_type'] = 0
623
+ dct['source'] = dct['full_name'] + "/Value"
624
+ ctrlChannels[fullDeviceName] = dct
625
+
626
+ return True
627
+
628
+
629
+ def setMg( poolName = None, mgName = None,
630
+ timer = None, extraTimers = None,
631
+ counters = None, countersNodisplay = None,
632
+ mcas = None, others = None):
633
+ """
634
+ fill timer, extraTimers, counters, mcas, pilatus, lambda, into a MG
635
+
636
+ Example:
637
+ HasyUtils.MgUtils.setMg( mgName= "mg_tnggui", timer = "eh_t01", mcas = "eh_mca01,eh_mca02")
638
+ """
639
+
640
+ if mgName is None:
641
+ raise ValueError( "MgUtils.setMg: MG name is missing")
642
+
643
+ if timer is None:
644
+ raise ValueError( "MgUtils.setMg: master timer is missing")
645
+
646
+ # if poolName is not supplied and only one pool exists, take this one
647
+ #
648
+ if poolName is None:
649
+ lst = TgUtils.getPoolNames()
650
+ if len( lst) == 0:
651
+ raise ValueError( "MgUtils.setMg: no pool")
652
+ poolName = lst[0]
653
+
654
+ flagClear = True
655
+ mgConf = MgConf( poolName, mgName, flagClear)
656
+
657
+ mgConf.addTimer( timer)
658
+
659
+ if extraTimers is not None and len( extraTimers) > 0:
660
+ for timer in extraTimers.split(','):
661
+ mgConf.addExtraTimer( timer)
662
+
663
+ if mcas is not None and len( mcas) > 0:
664
+ for mca in mcas.split(','):
665
+ if mca:
666
+ mgConf.addMCA( mca)
667
+
668
+ if counters is not None and len( counters) > 0:
669
+ for counter in counters.split(','):
670
+ if counter:
671
+ mgConf.addCounter( counter, 1, 1)
672
+
673
+ if countersNodisplay is not None and len( countersNodisplay) > 0:
674
+ for counter in countersNodisplay.split(','):
675
+ if counter:
676
+ mgConf.addCounter( counter, 0, 1)
677
+
678
+ if others is not None and len( others) > 0:
679
+ for other in others.split(','):
680
+ if other:
681
+ mgConf.addOther( other)
682
+
683
+ mgConf.updateConfiguration()
684
+ return
685
+
686
+
687
+ def checkPoolNameValid( deviceName):
688
+ """
689
+ check whether a MacroServer is using this pool
690
+
691
+ deviceName: 'p09/pool/haso107tk'
692
+
693
+ return False
694
+ if the alias of the device name is 'NoAlias'
695
+ if no MacroServer is pointing to this Pool, property PoolNames
696
+
697
+ """
698
+ alias = TgUtils.getAlias( deviceName)
699
+ if alias.lower() == 'noalias':
700
+ #print( "MgUtils.checkPoolNameValid: NoAlias for %s, return False" % str( deviceName))
701
+ return False
702
+
703
+ msNames = TgUtils.getMacroServerNames()
704
+
705
+ if len( msNames) == 0:
706
+ print( "MgUtils.checkPoolNameValid: len( msNames) == 0")
707
+ sys.exit( 255)
708
+ elif len( msNames) > 1:
709
+ print( "MgUtils.checkPoolNameValid: len( msNames) > 1: %s" % str( msNames))
710
+ sys.exit( 255)
711
+
712
+ lst = TgUtils.getDeviceProperty( msNames[0], 'PoolNames')
713
+
714
+ for elm in lst:
715
+ if elm == alias:
716
+ #print( "MgUtils.checkPoolNameValid: Macroserver %s is using %s, OK" % (msNames[0], alias))
717
+ return True
718
+
719
+ print( "MgUtils.checkPoolNameValid: Macroserver %s is NOT using %s, BAD" % (msNames[0], alias))
720
+ return False
721
+
722
+