blisslima.mac 11.9 KB
Newer Older
1
2
3
4
5
6
7
8
need bliss

#################################
# Lima/CCD detector settings
#################################

# <lima-name>
def limasettingssetup '{
9
    local lima_name lima_class first_time
10
11
12
13
14
15
16
17
18
19

    if (!BLISS["device"])
        blisssetup

    lima_name = ($# > 0) ? "$1" : getval("Enter the Lima detector name", "det1")
    if (list_check(LIMA_DEV, lima_name) <= 0) {
        printf("Invalid Lima detector name: %s\n", lima_name)
        exit
    }

20
21
22
23
24
25
26
    first_time = !bliss_settings_class_is_registered("lima.common")
    if (first_time) {
        # TODO: Add global lima settings: CCD_U, NO_CCDS

    }

    lima_class = lima_get_settings_class(lima_name)
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    bliss_register_settings_class(lima_class, "lima_dump_object_settings", \
                                              "lima_load_object_settings")
    bliss_add_settings_object(lima_class, lima_name)
    setup_tail("limasettings", lima_name)
}'

def limasettingsunsetup '{
    local lima_name lima_class
    lima_name = "$1"
    lima_class = lima_get_settings_class(lima_name)
    if (bliss_del_settings_object(lima_class, lima_name))
        bliss_unregister_settings_class(lima_class)
}'

def lima_get_settings_class(lima_name) '{
    return sprintf("lima.%s", LIMA_DEV[lima_name]["type"])
}'

def lima_dump_object_settings(lima_class, lima_name) '{
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
    local ccd_u obj_settings[] has_roi cbeg rbeg cend rend width height set_str

    ccd_u = lima_ccd_unit(lima_name)

    obj_settings["active_on_ct"] = CCD_ON[ccd_u]
    set_str = sprintf("%s,%s", CCD_BIN[ccd_u]["col_bin"], \
                               CCD_BIN[ccd_u]["row_bin"])
    obj_settings["image_bin"] = set_str

    CCD_FLIP[ccd_u]["col_flip"] = _limapar_get(lima_name, "image_flip", 0)
    CCD_FLIP[ccd_u]["row_flip"] = _limapar_get(lima_name, "image_flip", 1)
    set_str = sprintf("%s,%s", CCD_FLIP[ccd_u]["col_flip"], \
                               CCD_FLIP[ccd_u]["row_flip"])
    obj_settings["image_flip"] = set_str

    width = image_par(ccd_u, "cols") / CCD_BIN[ccd_u]["col_bin"]
    height = image_par(ccd_u, "rows") / CCD_BIN[ccd_u]["row_bin"]
    cbeg = CCD_ROI[ccd_u]["col_beg"]
    cend = CCD_ROI[ccd_u]["col_end"]
    rbeg = CCD_ROI[ccd_u]["row_beg"]
    rend = CCD_ROI[ccd_u]["row_end"]
    has_roi = (ROI_ACTIVE[ccd_u] && !((cbeg == 0) && (cend == width - 1) && \
                                      (rbeg == 0) && (rend == height - 1)))
    if (has_roi) {
        width = cend + 1 - cbeg
        height = rend + 1 - rbeg
    } else {
        cbeg = rbeg = 0
    }
    set_str = sprintf("%s,%s,%s,%s", cbeg, rbeg, width, height)
    obj_settings["image_roi"] = set_str
    
    if (CCD_TRIG[ccd_u] == 0) {
        set_str = "INTERNAL_TRIGGER"
    } else if (CCD_TRIG[ccd_u] == 1) {
        set_str = CCD_SOFT_PRESET[ccd_u] ? "EXTERNAL_TRIGGER" : \
                                           "EXTERNAL_GATE"
    } else {
        set_str = "EXTERNAL_TRIGGER_MULTI"
    }
    obj_settings["acq_trigger_mode"] = set_str

    set_str = CCDREAD_MODE[ccd_u] ? "NEVER" : "ALWAYS"
    obj_settings["spec_read_mode"] = set_str

    if (CCDSAVE[ccd_u] == 0) {
        set_str = "MANUAL"
    } else if (CCDSAVE_MODE[ccd_u] == 0) {
        set_str = "SPEC"
    } else if (CCDSAVE_MODE[ccd_u] == 1) {
        set_str = "DSERVER"
    } else if (CCDSAVE_MODE[ccd_u] == 2) {
        set_str = "SPEC_CONCAT"
    } else if (CCDSAVE_MODE[ccd_u] == 3) {
        set_str = "DSERVER_CONCAT"
    } else if (CCDSAVE_MODE[ccd_u] == 4) {
        set_str = "DSERVER_AUTO_FRAME"
    }
    obj_settings["spec_saving_mode"] = set_str
    obj_settings["saving_mode"] = _limapar_get(lima_name, "saving_mode")
    
    CCD_DIR[ccd_u] = _limapar_get(lima_name, "saving_directory")
    CCD_PREFIX[ccd_u] = _limapar_get(lima_name, "saving_prefix")
    CCD_SUFFIX[ccd_u] = _limapar_get(lima_name, "saving_suffix")
    CCD_N[ccd_u] = _limapar_get(lima_name, "saving_next_number")
    obj_settings["saving_directory"] = CCD_DIR[ccd_u] 
    obj_settings["saving_prefix"] = CCD_PREFIX[ccd_u] 
    obj_settings["saving_suffix"] = CCD_SUFFIX[ccd_u] 
    obj_settings["saving_next_number"] = CCD_N[ccd_u]
    set_str = _limapar_get(lima_name, "saving_overwrite_policy")
    obj_settings["saving_overwrite_policy"] = set_str

    obj_settings["spec_roi_cnt_act"] = CCD_INTEG[ccd_u]
    if (CCD_NORM[ccd_u] == 0) {
        set_str = "INTEGRATE"
    } else if (CCD_NORM[ccd_u] == 1) {
        set_str = "AVERAGE"
    } else if (CCD_NORM[ccd_u] == 2) {
        set_str = "AVERAGE_STD_DEV"
    }
    obj_settings["spec_roi_cnt_mode"] = set_str

    obj_settings["spec_roi_cnt_mne1"] = CCD_MNE[ccd_u]
    obj_settings["spec_roi_cnt_mne2"] = CCD_MNE2[ccd_u]

    cbeg = CCD_CNTROI[ccd_u]["col_beg"]
    cend = CCD_CNTROI[ccd_u]["col_end"]
    rbeg = CCD_CNTROI[ccd_u]["row_beg"]
    rend = CCD_CNTROI[ccd_u]["row_end"]
    has_roi = (CCD_CNTROI[ccd_u]["active"] && \
               !((cbeg == 0) && (cend == width - 1) && \
                 (rbeg == 0) && (rend == height - 1)))
    if (has_roi) {
        width = cend + 1 - cbeg
        height = rend + 1 - rbeg
    } else {
        cbeg = rbeg = 0
    }
    set_str = sprintf("%s,%s,%s,%s", cbeg, rbeg, width, height)
    obj_settings["spec_roi_cnt_region"] = set_str

    obj_settings["spec_save_counters"] = CCD_SAVE_COUNTERS

    set_str = CCD_EXT_HEADER ? MY_EXT_HEADER : ""
    obj_settings["external_header"] = set_str

    if (CCD_GUI[ccd_u]["on"] == 0) {
        set_str = "NONE"
    } else if (CCD_GUI[ccd_u]["guiconf"] == 0) {
        set_str = "ONZE"
    } else if (CCD_GUI[ccd_u]["guiconf"] == 1) {
        set_str = "OXIDIS"
    }
    obj_settings["online_gui"] = set_str

161
162
163
    return obj_settings
}'

164
165
def lima_load_object_settings(lima_class, lima_name, obj_settings) '{
    local _ccd_u
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    _ccd_u = lima_ccd_unit(lima_name)
    _ccd_globals
    global CCD_FLIP
    _ccd_cdef()

    if (bliss_is_default_settings(obj_settings))
        lima_load_default_settings(lima_name)
    else
        lima_load_ext_settings(lima_name, obj_settings)

    lima_resetup(lima_name)

}'

def lima_ccd_unit(lima_name) '{
    return LIMA_DEV[lima_name]["unit"]
}'

def lima_load_default_settings(lima_name) '{
    local ccd_u

    ccd_u = lima_ccd_unit(lima_name)
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
    CCD_DEPTH[ccd_u] = image_par(ccd_u, "bytes_pixel")

    CCD_ON[ccd_u] = 1

    CCD_BIN[ccd_u]["col_bin"] = 1
    CCD_BIN[ccd_u]["row_bin"] = 1

    CCD_FLIP[ccd_u]["col_flip"] = 0
    CCD_FLIP[ccd_u]["row_flip"] = 0

    ROI_ACTIVE[ccd_u] = 0
    CCD_ROI[ccd_u]["col_beg"] = 0
    CCD_ROI[ccd_u]["col_end"] = image_par(ccd_u, "cols") - 1
    CCD_ROI[ccd_u]["row_beg"] = 0
    CCD_ROI[ccd_u]["row_end"] = image_par(ccd_u, "rows") - 1

    CCD_TRIG[ccd_u] = 0
    CCD_PRESET[ccd_u] = 0
    CCD_SOFT_PRESET[ccd_u] = 1
    CCD_ADD_TIME[ccd_u] = 0
    CCD_SOFT_INIT[ccd_u] = 0

    CCDREAD_MODE[ccd_u] = 0

    CCDSAVE[ccd_u] = 0
    CCDSAVE_MODE[ccd_u] = 0
    CCD_DIR[ccd_u] = ""
    CCD_PREFIX[ccd_u] = ""
    CCD_SUFFIX[ccd_u] = ".edf"
    CCD_N[ccd_u] = 0

    CCD_INTEG[ccd_u] = 0
    CCD_NORM[ccd_u] = 0
    CCD_MNE[ccd_u] = ""
    CCD_MNE2[ccd_u] = ""
    CCD_CNTROI[ccd_u]["active"] = 0
    CCD_CNTROI[ccd_u]["col_beg"] = 0
    CCD_CNTROI[ccd_u]["col_end"] = image_par(ccd_u, "cols") - 1
    CCD_CNTROI[ccd_u]["row_beg"] = 0
    CCD_CNTROI[ccd_u]["row_end"] = image_par(ccd_u, "rows") - 1

    CCD_SAVE_COUNTERS = 0

    CCD_EXT_HEADER = 0
    MY_EXT_HEADER = ""
 
    CCD_GUI[ccd_u]["on"] = 0
    CCD_GUI[ccd_u]["guiconf"] = 1
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
def lima_load_ext_settings(lima_name, obj_settings) '{
    local ccd_u has_roi cbeg rbeg cend rend width height set_str sarr[]

    ccd_u = lima_ccd_unit(lima_name)

    CCD_ON[ccd_u] = obj_settings["active_on_ct"]

    split(obj_settings["image_bin"], sarr, ",")
    CCD_BIN[ccd_u]["col_bin"] = int(sarr[0])
    CCD_BIN[ccd_u]["row_bin"] = int(sarr[1])

    split(obj_settings["image_flip"], sarr, ",")
    CCD_FLIP[ccd_u]["col_flip"] = int(sarr[0])
    CCD_FLIP[ccd_u]["row_flip"] = int(sarr[1])

    width = image_par(ccd_u, "cols") / CCD_BIN[ccd_u]["col_bin"]
    height = image_par(ccd_u, "rows") / CCD_BIN[ccd_u]["row_bin"]

    split(obj_settings["image_roi"], sarr, ",")
    cbeg = int(sarr[0])
    rbeg = int(sarr[1])
    cend = int(sarr[0]) + int(sarr[2]) - 1
    rend = int(sarr[1]) + int(sarr[3]) - 1
    CCD_ROI[ccd_u]["col_beg"] = cbeg
    CCD_ROI[ccd_u]["col_end"] = cend
    CCD_ROI[ccd_u]["row_beg"] = rbeg
    CCD_ROI[ccd_u]["row_end"] = rend
    ROI_ACTIVE[ccd_u] = !((cbeg == 0) && (cend == width - 1) && \
                          (rbeg == 0) && (rend == height - 1))
    width = cend - cbeg + 1
    height = rend - rbeg + 1
    set_str = obj_settings["acq_trigger_mode"]
    if (set_str == "INTERNAL_TRIGGER") {
        CCD_TRIG[ccd_u] = 0
    } else if (set_str == "EXTERNAL_TRIGGER") {
        CCD_TRIG[ccd_u] = 1
        CCD_SOFT_PRESET[ccd_u] = 1
    } else if (set_str == "EXTERNAL_GATE") {
        CCD_TRIG[ccd_u] = 1
        CCD_SOFT_PRESET[ccd_u] = 0
    } else if (set_str == "EXTERNAL_TRIGGER_MULTI") {
        CCD_TRIG[ccd_u] = 2
        CCD_SOFT_PRESET[ccd_u] = 1
    }

    set_str = obj_settings["spec_read_mode"]
    CCDREAD_MODE[ccd_u] = (set_str == "NEVER")

    set_str = obj_settings["spec_saving_mode"]
    if (set_str == "MANUAL") {
        CCDSAVE[ccd_u] = 0
    } else if (set_str == "SPEC") {
        CCDSAVE_MODE[ccd_u] = 0
    } else if (set_str == "DSERVER") {
        CCDSAVE_MODE[ccd_u] = 1
    } else if (set_str == "SPEC_CONCAT") {
        CCDSAVE_MODE[ccd_u] = 2
    } else if (set_str == "DSERVER_CONCAT") {
        CCDSAVE_MODE[ccd_u] = 3
    } else if (set_str = "DSERVER_AUTO_FRAME") {
        CCDSAVE_MODE[ccd_u] = 4
    }
    _limapar_set(lima_name, "saving_mode", obj_settings["saving_mode"])
    
    CCD_DIR[ccd_u] = obj_settings["saving_directory"]
    CCD_PREFIX[ccd_u] = obj_settings["saving_prefix"]
    CCD_SUFFIX[ccd_u] = obj_settings["saving_suffix"]
    CCD_N[ccd_u] = obj_settings["saving_next_number"]

    set_str = obj_settings["saving_overwrite_policy"]
    _limapar_set(lima_name, "saving_overwrite_policy", set_str)

    CCD_INTEG[ccd_u] = obj_settings["spec_roi_cnt_act"]
    set_str = obj_settings["spec_roi_cnt_mode"]
    if (set_str == "INTEGRATE") {
        CCD_NORM[ccd_u] = 0
    } else if (set_str == "AVERAGE") {
        CCD_NORM[ccd_u] = 1
    } else if (set_str == "AVERAGE_STD_DEV") {
        CCD_NORM[ccd_u] = 2
    }

    CCD_MNE[ccd_u] = obj_settings["spec_roi_cnt_mne1"]
    CCD_MNE2[ccd_u] = obj_settings["spec_roi_cnt_mne2"]

    split(obj_settings["spec_roi_cnt_region"], sarr, ",")
    cbeg = int(sarr[0])
    rbeg = int(sarr[1])
    cend = int(sarr[0]) + int(sarr[2]) - 1
    rend = int(sarr[1]) + int(sarr[3]) - 1
    CCD_CNTROI[ccd_u]["col_beg"] = cbeg
    CCD_CNTROI[ccd_u]["col_end"] = cend
    CCD_CNTROI[ccd_u]["row_beg"] = rbeg
    CCD_CNTROI[ccd_u]["row_end"] = rend
    CCD_CNTROI[ccd_u]["active"] = !((cbeg == 0) && (cend == width - 1) && \
                                    (rbeg == 0) && (rend == height - 1))

    CCD_SAVE_COUNTERS = obj_settings["spec_save_counters"]

    MY_EXT_HEADER = obj_settings["external_header"]
    CCD_EXT_HEADER = (MY_EXT_HEADER == "")

    set_str = obj_settings["online_gui"]
    if (set_str == "NONE") {
        CCD_GUI[ccd_u]["on"] = 0
    } else if (set_str == "ONZE") {
        CCD_GUI[ccd_u]["on"] = 1
        CCD_GUI[ccd_u]["guiconf"] = 0
    } else if (set_str == "OXIDIS") {
        CCD_GUI[ccd_u]["on"] = 1
        CCD_GUI[ccd_u]["guiconf"] = 1
    }
352
353
}'

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
def lima_resetup(lima_name) '{
    local ccd_u gui_on gui_conf

    ccd_u = lima_ccd_unit(lima_name)
    ccdresetup ccd_u    

    _limapar_set(lima_name, "image_flip", CCD_FLIP[ccd_u]["col_flip"], 0)
    _limapar_set(lima_name, "image_flip", CCD_FLIP[ccd_u]["row_flip"], 1)

    _limapar_set(lima_name, "saving_directory", CCD_DIR[ccd_u])
    _limapar_set(lima_name, "saving_prefix", CCD_PREFIX[ccd_u])
    _limapar_set(lima_name, "saving_suffix", CCD_SUFFIX[ccd_u])
    _limapar_set(lima_name, "saving_next_number", CCD_N[ccd_u])

    ccd_u = CCD_U
    gui_on = CCD_GUI[CCD_U]["on"]
    gui_conf = CCD_GUI[CCD_U]["guiconf"]
    ccdgui gui_on gui_conf
    CCD_U = ccd_u
373
374
375

}'