-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirradiate.py
91 lines (74 loc) · 2.65 KB
/
irradiate.py
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
'''
irradiatet.py - by [email protected] 2023
This script is used to declare irradiations. It is rather 'manual', since this is not
a routine operation and it does not worth writing a complex script.
'''
from mtdConstructionDBTools import mtdcdb
import getopt
import sys
runs = ['BAR400017_POSTIRR_0',
'BAR400019_POSTIRR_0',
'BAR400021_POSTIRR_0',
'BAR400023_POSTIRR_0',
'BAR400025_POSTIRR_0',
'BAR400027_POSTIRR_0',
'BAR400030_POSTIRR_0',
'BAR400031_POSTIRR_0'
]
barcodes = ['321100001400017',
'321100001400019',
'321100001400021',
'321100001400023',
'321100001400025',
'321100001400027',
'321100001400030',
'321100001400031'
]
# despite this is a quick & dirty script, we use the standard approach also to provide
# a documented example
hlp = (f'DECLARE IRRADIATIONS.\n')
logger, logginglevel = mtdcdb.createLogger()
shrtOpts, longOpts, helpOpts = mtdcdb.stdOptions()
shrtOpts += 'r:'
longOpts += 'run='
helpOpts += 'provides the run name/tag to be associated to this irradiation'
try:
opts, args = getopt.getopt(sys.argv[1:], shrtOpts, longOpts)
except Exception as excptn:
print("Unexpected exception: " + str(excptn))
mtdcdb.mtdhelp(shrtOpts, longOpts, helpOpts, -1, hlp)
barcode = None
run = None
for o, a in opts:
if o in ('-h', '--help'):
mtdcdb.mtdhelp(shrtOpts, longOpts, helpOpts, 0, hlp)
elif o in ('-x', '--barcode'):
barcode = a
elif o in ('-r', '--run'):
run = a
if barcode != None:
barcodes = []
barcodes.append(barcode)
if run != None:
runs = []
runs.append(run)
if len(runs) != len(barcodes):
logger.error('The number of runs is not equal to the number of barcodes')
exit(-1)
mtdcdb.initiateSession(user = 'organtin', port = 50022, write = True)
for run, barcode in zip(runs, barcodes):
run = { 'TYPE': 'IRRADIATION_AT_CALLIOPE',
'NAME': run}
conditionDataset = { barcode: [{"name": "RADIATION_TYPE", "value": "G"},
{"name": "DOSE", "value": "50"},
{"name": "DOSERATE", "value": "5.4"}]
}
run_begin = '2023-06-05 17:10:21'
root = mtdcdb.root()
condition = mtdcdb.newCondition(root, 'IRRADIATIONS', conditionDataset, run = run,
runBegin = run_begin)
print(mtdcdb.mtdxml(condition))
xmlfile = open(f'{barcode}-irr.xml', 'w')
xmlfile.write(mtdcdb.mtdxml(condition))
xmlfile.close()
# mtdcdb.writeToDB(filename = f'{barcode}-irr.xml', dryrun = False, user = 'organtin', wait = 3)