blisslima.mac 14.8 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
    limaroisetup

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

    }

28
29
30
31
32
33
34
    NO_CCDS=0
    while ((controller=image_par(NO_CCDS,"controller"))!=-1){
        NO_CCDS++
    }
    #clean up the last printed line (the error message)
    printf("%c[%dA%c[0J", 27, 1, 27)

35
    lima_class = lima_get_settings_class(lima_name)
36
    bliss_register_settings_class(lima_class, "lima_dump_object_settings", \
37
38
                                              "lima_load_object_settings", \
                                              "lima_new_saving")
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    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) '{
56
    local ccd_u obj_settings[] has_roi cbeg rbeg cend rend width height set_str
57
58
    local rlist rmne i set_key
    
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
    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

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    rlist = bliss_list_string_init()
    for (i = 1; i <= list_n(LIMA_ROI); i++) {
        rmne = list_item(LIMA_ROI, i)
	if (LIMA_ROI[rmne]["ccdname"] == lima_name) {
            rlist = bliss_list_string_add(rlist, rmne)
	    set_key = sprintf("roi_%s", rmne)
	    set_str = sprintf("%s,%s,%s,%s,%s", LIMA_ROI[rmne]["xmin"], \
                                                LIMA_ROI[rmne]["xmax"], \
                                                LIMA_ROI[rmne]["ymin"], \
                                                LIMA_ROI[rmne]["ymax"], \
						LIMA_ROI[rmne]["type"])
            obj_settings[set_key] = set_str
        }
    }
    obj_settings["roi_list"] = rlist

188
189
190
    return obj_settings
}'

191
192
def lima_load_object_settings(lima_class, lima_name, obj_settings) '{
    local _ccd_u
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
    _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)

}'

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
def lima_new_saving(lima_class, lima_name, experiment, sample) '{
    local ccd_u label windows work_dir
    local saving_directory saving_prefix saving_suffix

    windows = 0
    if (index(lima_name, "pco") == 1) {
        label = "PCO"
	windows = 1
    }
    else if (index(lima_name, "perkin") == 1) {
        label = "PE"
	windows = 1
    }
    else if (index(lima_name, "dexela") == 1) {
        label = "DE"
    }
    else if (index(lima_name, "pilatus") == 1) {
        label = "P3"
    }
    else if (index(lima_name, "mpx") == 1) {
        label = "MPX"
    }
    else {
        print "Unknown detector: lima directory not set"
	return
    }

    saving_prefix = sample "_" label "_#n4_#p4"
    saving_suffix = ".edf"
    work_dir = session_get_working_dir()
    saving_directory = work_dir "/" label
    unix(sprintf("mkdir -p %s", saving_directory))
    if (windows) {
       saving_directory = sprintf("%s/%s", session_get_windows_working_dir(), label)
    }
    _limapar_set(lima_name, "saving_directory", saving_directory)
    _limapar_set(lima_name, "saving_prefix", saving_prefix)
    _limapar_set(lima_name, "saving_suffix", saving_suffix)
    lima_dump_object_settings(lima_class, lima_name)
}'

249
250
251
252
253
254
255
256
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)
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
    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
306
307

    _limaroi_load(lima_name, "")
308
309
}'

310
311
def lima_load_ext_settings(lima_name, obj_settings) '{
    local ccd_u has_roi cbeg rbeg cend rend width height set_str sarr[]
312
    local rlist rmne i set_key
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

    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")

359
    CCDSAVE[ccd_u] = 1
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
    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"]
412
    CCD_EXT_HEADER = (MY_EXT_HEADER != "")
413
414
415
416
417
418
419
420
421
422
423

    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
    }
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

    rlist = obj_settings["roi_list"]
    for (i = 1; i <= bliss_list_string_n(rlist); i++) {
        rmne = bliss_list_string_item(rlist, i)
        if (list_item(LIMA_ROI, rmne) == -1) 
            list_add(LIMA_ROI, rmne)
	LIMA_ROI[rmne]["ccdname"] = lima_name

        set_key = sprintf("roi_%s", rmne)
        split(obj_settings[set_key], sarr, ",")
        cbeg = int(sarr[0])
        cend = int(sarr[1])
        rbeg = int(sarr[2])
        rend = int(sarr[3])
        LIMA_ROI[rmne]["type"] = sarr[4]
	LIMA_ROI[rmne]["xmin"] = cbeg
        LIMA_ROI[rmne]["xmax"] = cend
	LIMA_ROI[rmne]["ymin"] = rbeg
        LIMA_ROI[rmne]["ymax"] = rend
    }
444
445
}'

446
447
448
449
450
451
452
453
454
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)

455
456
    if(CCD_DIR[ccd_u] != 0 && CCD_DIR[ccd_u] != "")
        _limapar_set(lima_name, "saving_directory", CCD_DIR[ccd_u])
457
458
459
460
    _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])

461
462
    _limaroi_server_send(lima_name)
    
463
464
465
466
467
    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
468

469

470
471
}'