40def trySetFlagsFromIS(flags, partition=None):
41 '''Attempt to fill in run metadata from IS if available'''
42 from PyUtils.moduleExists import moduleExists
43 if not moduleExists('ipc') or not moduleExists('ispy'):
44 log.warning('TDAQ python modules to read from IS (ipc, ispy) are unavailable')
45 return
46
47 from ipc import IPCPartition
48 from ispy import ISObject
49
50 if not partition:
51 import os
52 partition = os.getenv('TDAQ_PARTITION') or 'ATLAS'
53 log.debug('Trying to read IS data for partition %s', partition)
54
55 def tryReadISObject(obj_name, type_name, part_name=partition):
56 try:
57 obj = ISObject(IPCPartition(part_name), obj_name, type_name)
58 obj.checkout()
59 return obj
60 except Exception as e:
61 log.warning('Cannot read %s from partition %s, exception: %s', obj_name, part_name, e)
62 return None
63
64 def tryReadFromISObject(obj, attr, default=None):
65 try:
66 return obj.getAttributeValue(attr)
67 except Exception as e:
68 log.warning('Cannot read attribute %s from ISObject %s, exception: %s', attr, obj.name(), e)
69 return default
70
71
72 runparams = tryReadISObject('RunParams.RunParams', 'RunParams')
73 if runparams:
74
75 run_number = tryReadFromISObject(runparams, 'run_number')
76 if run_number is not None:
77 flags.Input.RunNumbers = [run_number]
78
79 project_name = tryReadFromISObject(runparams, 'T0_project_tag')
80 if project_name is not None:
81 flags.Input.ProjectName = project_name
82
83 beam_type_num = tryReadFromISObject(runparams, 'beam_type')
84 if beam_type_num is not None:
85 flags.Beam.Type = BeamType.Collisions if beam_type_num > 0 else BeamType.Cosmics
86
87 beam_energy = tryReadFromISObject(runparams, 'beam_energy')
88 if beam_energy is not None:
89 flags.Beam.Energy = beam_energy*GeV
90
91
92 smk_is = tryReadISObject('RunParams.TrigConfSmKey', 'TrigConfSmKey')
93 l1psk_is = tryReadISObject('RunParams.TrigConfL1PsKey', 'TrigConfL1PsKey')
94 hltpsk_is = tryReadISObject('RunParams.TrigConfHltPsKey', 'TrigConfHltPsKey')
95 bgk_is = tryReadISObject('RunParams.TrigConfL1BgKey', 'TrigConfL1BgKey')
96 if smk_is and l1psk_is and hltpsk_is and bgk_is:
97 smk = tryReadFromISObject(smk_is, 'SuperMasterKey')
98 l1psk = tryReadFromISObject(l1psk_is, 'L1PrescaleKey')
99 hltpsk = tryReadFromISObject(hltpsk_is, 'HltPrescaleKey')
100 bgk = tryReadFromISObject(bgk_is, 'L1BunchGroupKey')
101 if all([v is not None for v in [smk, l1psk, hltpsk, bgk]]):
102 dbname = 'TRIGGERDB_RUN3'
103 flags.Trigger.triggerConfig = 'DB:{:s}:{:d},{:d},{:d},{:d}'.format(
104 dbname, smk, l1psk, hltpsk, bgk)
105
106
107 lbinfo = tryReadISObject('RunParams.LumiBlock', 'LumiBlock')
108 if lbinfo:
109
110 lb_number = tryReadFromISObject(lbinfo, 'LumiBlockNumber')
111 if lb_number is not None:
112 flags.Input.LumiBlockNumbers = [lb_number]
113
114 time_ns = tryReadFromISObject(lbinfo, 'Time')
115 if time_ns is not None:
116 flags.Input.TimeStamps = [int(time_ns / 1e9)]
117
118
119 solenoid_curr_is = tryReadISObject('DCS_GENERAL.MagnetSolenoidCurrent.value', 'DdcFloatInfo', part_name='initial')
120 if solenoid_curr_is:
121 solenoid_curr = tryReadFromISObject(solenoid_curr_is, 'value')
122 if solenoid_curr is not None:
123 flags.BField.solenoidOn = (solenoid_curr > 70)
124
125
126 toroid_curr_is = tryReadISObject('DCS_GENERAL.MagnetToroidsCurrent.value', 'DdcFloatInfo', part_name='initial')
127 if toroid_curr_is:
128 toroid_curr = tryReadFromISObject(toroid_curr_is, 'value')
129 if toroid_curr is not None:
130 flags.BField.barrelToroidOn = (toroid_curr > 70)
131 flags.BField.endcapToroidOn = (toroid_curr > 70)
132
133