-
Notifications
You must be signed in to change notification settings - Fork 1
/
limabpm.mac
624 lines (557 loc) · 17.1 KB
/
limabpm.mac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
#%TITLE% limabpm.mac
#%NAME% LIMA CCD intensity, position and FWHM pseudo counters
#%DESCRIPTION%
#Implements intensity, position and FWHM as pseudo counters for LIMA CCD
#
#%END%
#%CATEGORY% Detection, Ccd, Bpm
#%IU%
#%MDESC%
#Initialise associative array %B%__LIMA_BPM%B% and create user_getcounts cdef
#%BR% Automatically called from %B%limasetup%B%
#
def limabpmsetup '{
local ccdname, devname, bpmdev
global __LIMA_BPM[]
if ($#== 0 ) {
ccdname = LIMA_DEV["1"]
} else {
ccdname = "$1"
}
ccdname = _lima_checkccdname(ccdname)
devname = LIMA_DEV[ccdname]["control"]
bpmdev = _lima_get_plugin_devicename(ccdname, "bpm")
LIMA_DEV[ccdname]["bpmdev"] = bpmdev
tacodev = _lima_get_plugin_devicename(ccdname, "limatacoccds")
LIMA_DEV[ccdname]["tacodev"] = "tango:" tacodev
if (bpmdev == "") {
LIMA_DEV[ccdname]["bpmdev"] = 0
_lima_error ccdname ; printf("No BPM plugin exported\n")
} else {
LIMA_DEV[ccdname]["bpmdev"] = bpmdev
tango_io(bpmdev, "Start")
}
list_test __LIMA_BPM
if (__LIMA_BPM[0] == 0) { __LIMA_BPM[0] = 0 }
__LIMA_BPM["types"] = "x y intensity fwhm_x fwhm_y"
local ___LIMA_BPM_TYPES, x
split(__LIMA_BPM["types"], ___LIMA_BPM_TYPES)
for (x in ___LIMA_BPM_TYPES) {
__LIMA_BPM[___LIMA_BPM_TYPES[x]] = "bpmtype"
}
delete __LIMA_BPM["types"]
cdef("user_getcounts", "_limabpm_getcounts\n", "limabpm", 0x20)
}'
#%IU%
#%MDESC%
#Cleanup cdef and associative arrays used in limabpm
#
def limabpmunsetup '{
cdef("", "", "limabpm", "delete")
_limabpm_removeall()
unglobal __LIMA_BPM
}'
if (!(whatis("user_limabpm_add") & 2)) rdef user_limabpm_add \'#$*\'
if (!(whatis("user_limabpm_remove") & 2)) rdef user_limabpm_remove \'#$*\'
if (!(whatis("user2_limabpm_add") & 2)) rdef user2_limabpm_add \'#$*\'
if (!(whatis("user2_limabpm_remove") & 2)) rdef user2_limabpm_remove \'#$*\'
#%UU% <ccdname> <bpmmne> <x|y|intensity|fwhm_x|fwhm_y>
#%MDESC%
#Add or Modify a BPM
#
def limabpmadd '{
if ($#!= 3) {
print "Usage: $0 <ccdname> <bpmmne> <x|y|intensity|fwhm_x|fwhm_y>"
exit
}
_lima_checkccdname("$1")
_limabpm_add("$1", "$2", "$3")
}'
#%IU% (ccdname, mne, )
#%MDESC%
#Add or Modify a BPM
#
def _limabpm_add(ccdname, bpmmne, bpmtype) '{
if (cnt_mne(cnt_num(bpmmne)) != bpmmne) {
eprint "Counter", bpmmne, "is not recognised."
return
}
if (!(bpmtype in __LIMA_BPM)) {
eprint "type", bpmtype, "is not recognised. Use one of x|y|intensity|fwhm_x|fwhm_y"
return
}
if (list_item(__LIMA_BPM, bpmmne) == -1) {
list_add(__LIMA_BPM, bpmmne)
}
list_setpar(__LIMA_BPM, bpmmne, "ccdname", ccdname)
list_setpar(__LIMA_BPM, bpmmne, "type", bpmtype)
user_limabpm_add ccdname bpmmne
user2_limabpm_add ccdname bpmmne
}'
#%UU% <bpmmne>
#%MDESC%
#Remove the specified BPM
#
def limabpmremove '{
local bpmmne
if ($#!= 1) {
print "Usage: $0 <bpmmne>"
exit
}
if (cnt_num($1) != $1) {
eprint "Counter $2 is not recognised."
}
bpmmne = "$1"
if (list_check(__LIMA_BPM, bpmmne) <= 0) {
_lima_error ; printf("Unknown BPM <%s>\n", bpmmne)
} else {
_limabpm_remove(bpmmne)
}
}'
#%IU% (bpmmne)
#%MDESC%
# Remove the specified BPM
#
def _limabpm_remove(bpmmne) '{
local bpmnum ccdname
ccdname = __LIMA_BPM[bpmmne]["ccdname"]
if ((bpmnum = cnt_num(bpmmne)) != -1) {
S[bpmnum] = (1e1000/1e1000) #NaN
}
#clean associative arrays up in case someone is using them
#via the user_ hook macros (e.i zaplima.mac !!)
list_remove(__LIMA_BPM, bpmmne)
user_limabpm_remove ccdname bpmmne
user2_limabpm_remove ccdname bpmmne
}'
#%UU% <ccdname>
#%MDESC%
# Remove all BPMs for CCD <ccdname>
#%BR% if <ccdname> == %B%*%B%, remove all BPMs for all CCDs
#
def limabpmremoveall '{
local ccdname
if ($#!= 1) {
print "Usage: $0 <ccdname>"
print " If <ccdname> == \"*\", remove bpms on all ccds"
exit
}
ccdname = "$1"
if ((ccdname != "*") && (list_check(LIMA_DEV, ccdname) <= 0)) {
_lima_error ; printf("Unknown LIMA CCD <%s>\n", ccdname)
} else {
_limabpm_removeall(ccdname)
}
}'
#%IU%
#%MDESC%
def _limabpm_removeall(ccdname) '{
local ibpm bpmmne nbpm delbpm[]
if ((!ccdname)||(ccdname == "*")) {
for (ibpm = 1; ibpm <= list_n(__LIMA_BPM); ibpm++) {
bpmmne = list_item(__LIMA_BPM, ibpm)
_limabpm_remove(bpmmne)
}
} else {
nbpm = _limabpm_getbpms(ccdname, delbpm)
for (ibpm = 0; ibpm < nbpm; ibpm++) {
bpmmne = delbpm[ibpm]
_limabpm_remove(bpmmne)
}
}
}'
#%IU% (ccdname, bpms)
#%MDESC%
#Return the number of bpms and their mnemonic in input bpm array
#
def _limabpm_getbpms(ccdname, bpms) '{
local ibpm bpmmne nbpm
nbpm = 0
for (ibpm = 1; ibpm <= list_n(__LIMA_BPM); ibpm++) {
bpmmne = list_item(__LIMA_BPM, ibpm)
if (__LIMA_BPM[bpmmne]["ccdname"] == ccdname) {
bpms[nbpm++] = bpmmne
}
}
return (nbpm)
}'
#%IU% (ccdname, bpms)
#%MDESC%
#Return the number of configured and enabled bpms and their mnemonic in input bpms array
#
def _limabpm_getbpmactive(ccdname, bpms) '{
local ibpm bpmmne bpmnum nbpm
nbpm = 0
for (ibpm =1; ibpm <= list_n(__LIMA_BPM); ibpm++) {
bpmmne = list_item(__LIMA_BPM, ibpm)
if (__LIMA_BPM[bpmmne]["ccdname"] == ccdname) {
bpmnum = cnt_num(bpmmne)
if ((bpmnum != -1)&&(counter_par(bpmnum, "disable") != 1)) {
bpms[nbpm++] = bpmmne
}
}
}
return (nbpm)
}'
#%UU% <old_mne> <new_mne>
#%MDESC%
#Rename the BPM <old_mne> to <new_mne> keeping same BPM parameters
#
def limabpmrename '{
local oldmne newmne
if ($#!= 2) {
print "Usage: $0 <old_mne> <new_mne>"
exit
}
oldmne = "$1"
newmne = "$2"
if (list_check(__LIMA_BPM, oldmne) <= 0) {
_lima_error ; printf("Unknown BPM <%s>\n", oldmne)
} else {
_limabpm_rename(oldmne, newmne)
}
}'
#%IU% (old_mne, new_mne)
#%MDESC%
#Rename the BPM <old_mne> to <new_mne> keeping same BPM parameters
#
def _limabpm_rename(oldmne, newmne) '{
_limabpm_add(__LIMA_BPM[oldmne]["ccdname"], newmne, __LIMA_BPM[oldmne]["type"])
_limabpm_remove(oldmne)
}'
#%IU%
#%MDESC%
#Read bpmcounter device values and put then into corresponding spec counter.
def _limabpm_getcounts '{
local iccd ccdname
local nbpm ibpm bpms[]
local bpmmne bpmnum bpmtype
local bpmval, bpmnum
for (iccd = 1; iccd <= list_n(LIMA_DEV); iccd++) {
ccdname = list_item(LIMA_DEV, iccd)
ccdunit = LIMA_DEV[ccdname]["unit"]
if (CCD_ON[ccdunit] && LIMA_DEV[ccdname]["bpmdev"] && !tango_io(LIMA_DEV[ccdname]["bpmdev"], "State")) {
wait(21) # -- often the camera is not finished, when we get here.
nbpm = _limabpm_getbpmactive(ccdname, bpms)
if (nbpm > 0) {
for (ibpm = 1; ibpm <= list_n(__LIMA_BPM); ibpm++) {
bpmmne = __LIMA_BPM[ibpm]
bpmnum = cnt_num(bpmmne)
bpmtype = __LIMA_BPM[bpmmne]["type"]
bpmname = LIMA_DEV[__LIMA_BPM[bpmmne]["ccdname"]]["bpmdev"]
bpmval = tango_get(bpmname, bpmtype)
if (TANGO_ERR == "API_EmptyDeviceAttribute") {
bpmval = (1e1000/1e1000) #NaN
}
S[bpmnum] = bpmval
}
} else {
for (ibpm = 1; ibpm <= list_n(__LIMA_BPM); ibpm++) {
bpmmne = __LIMA_BPM[ibpm]
bpmnum = cnt_num(bpmmne)
S[bpmnum] = (1e1000/1e1000) #NaN
}
}
}
}
}'
#%UU% [<ccdname>]
#%MDESC%
#Show a menu allowing all modification on BPMs settings
#
def limabpm '{
local ccdname idev
if (whatis("spec_menu")) {
_limabpm_spec_menu()
exit
}
ccdname = ($#== 1) ? "$1" : 0
if (ccdname) {
if (list_check(LIMA_DEV, ccdname) <= 0) {
_lima_error ; printf("Unknown LIMA CCD <%s>\n", ccdname)
} else {
_limabpm_menu(ccdname)
}
} else {
if (list_n(LIMA_DEV) == 1) {
idev = 1
} else {
for (idev = 1; idev <= list_n(LIMA_DEV); idev++) {
ccdname = list_item(LIMA_DEV, idev)
printf(" (%d) %s (%s, %s)\n", idev, ccdname, \
LIMA_DEV[ccdname]["control"], LIMA_DEV[ccdname]["config"])
}
idev = getval(" >> Select one CCD", 0)
}
if ((idev>0)&&(idev <= list_n(LIMA_DEV)))
_limabpm_menu(list_item(LIMA_DEV, idev))
}
}'
#%IU% (ccdname)
#%MDESC%
#Menu to Add/Modify/Delete BPMs of CCD <ccdname>
#
def _limabpm_menu(ccdname)'{
local nb key
local cmne bpmtype
local ccdunit
local file
ccdunit = LIMA_DEV[ccdname]["unit"]
while (1) {
nb = _limabpm_menuhead(ccdname)
tty_move(0,nb++, "\[md\]A\[se\]dd/\[md\]R\[se\]emove/\[md\]M\[se\]odify BPM(s),")
tty_move(0,nb++, "or \[md\]Q\[se\]uit (0)? ")
while ((key = input(-1)) == "") { sleep(.1)}
key = substr(key,1,1)
printf("\n\n")
if (key == "q" || key == "Q" || asc(key) == 10) {
break
} else
if (key == "r" || key == "R") {
cmne = getval("Counter mnemonic",0)
if (cmne != "0") {
if (cmne == "*")
_limabpm_removeall(ccdname)
else
_limabpm_remove(cmne)
}
} else
if (key == "a" || key == "A") {
cmne = getval(" > Counter mnemonic ", 0)
if (cmne) {
bpmtype= getval(" > BPM type [intensity | x | y | fwhm_x | fwhm_y]", 0)
_limabpm_add(ccdname, cmne, bpmtype)
}
} else
if (key == "m" || key == "M") {
cmne= getval(" > Counter mnemonic ", 0)
if (list_check(__LIMA_BPM, cmne)>0) {
bpmtype= getval(" > BPM type [intensity | x | y | fwhm_x | fwhm_y]", __LIMA_BPM[cmne]["type"])
_limabpm_add(ccdname, cmne, bpmtype)
}
}
}
}'
#%IU% (ccdname)
#%MDESC%
#Menu to Add/Modify/Delete BPMs using spec_menu()
def _limabpm_spec_menu()'{
local bpmtype i j ccdname
if (COUNTERS == 0) {
print "No counters."
exit
}
local menu[], mne, cname, CNT_LIST, BPM_TYPES, x, bpmmne, bpmnum
local refer[], varvar
x = "intensity x y fwhm_x fwhm_y"
split(x, BPM_TYPES)
# attempt to setup a spec_menu to make input easier
# i = 2
menu[0]["title"] = "LIMA Beam Position Monitors"
menu[i++]["head"] = "Counter configuration menu"
menu[i++]["width"] = 90
for (i = j = 0, s = sep = ""; i < COUNTERS; i++, sep = " ") {
mne = cnt_mne(i)
cname = cnt_name(i)
if (mne == "sec" || mne == "mon" || mne == "det")
continue
if (counter_par(i, "disable"))
continue
else {
CNT_LIST = CNT_LIST " " mne
# if (mne in __LIMA_BPM) {
refer[__LIMA_BPM[mne]["ccdname"]][__LIMA_BPM[mne]["type"]] = mne
# }
j ++
}
}
CNT_LIST = CNT_LIST " none"
local x
i = 3
if (j == 0) {
print "All counters are disabled."
exit
}
for (x = 1; x <= LIMA_DEV["0"]; x++) {
ccdname = LIMA_DEV[x]
menu[i++]["subhead"] = sprintf("\tBPMs for %-15s", ccdname)
menu[i++]["desc"] = ""
for (j in BPM_TYPES) {
bpmtype = BPM_TYPES[j]
menu[i]["desc"] = sprintf("%-12s", bpmtype)
menu[i]["list"] = CNT_LIST
bpmmne = refer[ccdname][bpmtype]
varvar = "value" ccdname bpmtype
oldvarvar = "old" varvar
if ((bpmmne) && (__LIMA_BPM[bpmmne]["ccdname"] == ccdname)) {
@varvar = @oldvarvar = bpmmne
} else {
@varvar = @oldvarvar = "none"
}
menu[i]["@"] = varvar
menu[i]["info"] = "set counter for " ccdname " " bpmtype
i ++
}
menu[i++]["desc"] = ""
}
local mymodes
mymodes = 0
# only bit # 1 is set!
mymodes = spec_menu(menu)
for (x = 1; x <= LIMA_DEV["0"]; x++) {
ccdname = LIMA_DEV[x]
for (j in BPM_TYPES) {
bpmtype = BPM_TYPES[j]
bpmmne = refer[ccdname][bpmtype]
varvar = "value" ccdname bpmtype
oldvarvar = "old" varvar
if ((@varvar != @oldvarvar) && (@varvar != "none")) {
_limabpm_remove(bpmmne)
_limabpm_add(ccdname, @varvar, bpmtype)
}
}
}
}'
#%IU% (ccdname)
#%MDESC%
#Shows BPMs definition for CCD <ccdname>
#
def _limabpm_menuhead(ccdname) '{
local ibpm nb bpmmne
local cmne bpmtype status
clscreen()
tty_move(10,1,sprintf("\[md\]< LIMA BPM on %s >\[me\]", ccdname))
tty_move(0,3," Counter Type")
print
nb = 4
for (ibpm = 1; ibpm <= list_n(__LIMA_BPM); ibpm++) {
bpmmne = list_item(__LIMA_BPM, ibpm)
if (__LIMA_BPM[bpmmne]["ccdname"] == ccdname) {
status = (cnt_num(bpmmne) == -1)?" Not in config !!!":""
bpmtype = __LIMA_BPM[bpmmne]["type"]
tty_move(0, nb++, sprintf("\[md\]%18s %-8s \[me\] %s", bpmmne, bpmtype, status))
}
}
nb++
tty_move(0,nb++,"--------------------------------------------------------")
return (nb)
}'
#%IU%
#%MDESC%
#Return name of bpmcounter device if it exits.
#%BR% If not, return 0 and print an error message
#
def _limabpm_server_getds(ccdname) '{
local bpmsrv
bpmsrv = list_getpar(LIMA_DEV, ccdname, "bpmcounter")
if (!bpmsrv) {
_lima_error ccdname ; printf("No BPM counter device configured !!")
return (0)
}
return (bpmsrv)
}'
#%UU% <ccdname>
#%MDESC%
#Activate BPM plugin on lima server
#
def limabpmon '{
local ccdname bpmdev state
if ($#!= 1) {
print "Usage: $0 <ccdname>"
exit
}
ccdname = _lima_checkccdname("$1")
bpmdev = LIMA_DEV[ccdname]["bpmdev"]
state = tango_io(bpmdev, "State")
if (state) {
tango_io(bpmdev, "Start")
}
}'
#%UU% <ccdname>
#%MDESC%
#Switch off the bpm plugin on lima server
#
def limabpmoff '{
local ccdname bpmdev
if (!$#) {
print "Usage: $0 <ccdname>"
exit
}
ccdname = _lima_checkccdname("$1")
bpmdev = LIMA_DEV[ccdname]["bpmdev"]
tango_io(bpmdev, "Stop")
}'
#%UU% <ccdname> [take|reset|status]
#%MDESC%
# BPM background operation
#%BR% %B%take%B% : acquire one image and keep it for bpm background
#%BR% %B%reset%B% : remove background image on server
#%BR% %B%status%B% : is a background image present or not
#
def limabpmbackground '{
local ccdname bgcmd bpmdev state
if (!$#) {
print "Usage: $0 <ccdname> [\"take\"|\"reset\"|\"status\"]"
exit
}
ccdname= _lima_checkccdname("$1")
bgcmd= $#>1 ? "$2" : "status"
bpmdev= LIMA_DEV[ccdname]["bpmdev"]
state= tango_io(bpmdev, "State")
if (state != 0) {
_lima_error ccdname ; print "Activate BPM before using it !! (limabpmon)"
exit
}
if (bgcmd == "take") {
tango_io(bpmdev, "TakeBackground")
_lima_trace ccdname ; print "BPM background image acquired."
} else if (bgcmd == "reset") {
tango_io(bpmdev, "ResetBackground")
_lima_trace ccdname ; print "BPM background image removed."
} else if (bgcmd == "status") {
state= tango_io(bpmdev, "HasBackground")
_lima_trace ccdname
printf("BPM %s a background image\n", state==1?"has":"has NOT")
} else {
_lima_error ccdname; print "Invalid BPM background command"
}
}'
#%UU% <ccdname> [take|reset|status]
#%MDESC%
# BPM background operation
#%BR% %B%take%B% : acquire one image and keep it for bpm background
#%BR% %B%reset%B% : remove background image on server
#%BR% %B%status%B% : is a background image present or not
#
def limabpmbackground '{
local ccdname bgcmd bpmdev state
if (!$#) {
print "Usage: $0 <ccdname> [\"take\"|\"reset\"|\"status\"]"
exit
}
ccdname= _lima_checkccdname("$1")
bgcmd= $#>1 ? "$2" : "status"
bpmdev= LIMA_DEV[ccdname]["bpmdev"]
state= tango_io(bpmdev, "State")
if (state != 0) {
_lima_error ccdname ; print "Activate BPM before using it !! (limabpmon)"
exit
}
if (bgcmd == "take") {
tango_io(bpmdev, "TakeBackground")
_lima_trace ccdname ; print "BPM background image acquired."
} else if (bgcmd == "reset") {
tango_io(bpmdev, "ResetBackground")
_lima_trace ccdname ; print "BPM background image removed."
} else if (bgcmd == "status") {
state= tango_io(bpmdev, "HasBackground")
_lima_trace ccdname
printf("BPM %s a background image\n", state==1?"has":"has NOT")
} else {
_lima_error ccdname; print "Invalid BPM background command"
}
}'
#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% Copied from limaroi.mac by E.Papillon, H.Witsch