ATLAS Offline Software
Loading...
Searching...
No Matches
global_system.py
Go to the documentation of this file.
1# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2
3from DCSCalculator2.lib import DCSC_Subdetector_DefectsOnly, DCSC_Defect_Global_Variable, connect_adjacent_iovs_defect
4from DCSCalculator2.variable import DefectIOV
5from DQUtils import process_iovs
6from DQUtils.sugar import IOVSet, RunLumi
7from DQUtils.iov_truncator import truncate_to_atlas_runs
8from logging import getLogger
9
10log = getLogger("DCSC2.global_system")
11
12class TDAQ_Ready(DCSC_Defect_Global_Variable):
13 """
14 Overloads calculate_good_iovs
15 """
16 input_db = 'COOLONL_TDAQ/CONDBR2'
17 timewise_folder = False
18 def make_good_iovs(self, iovs):
19 return IOVSet(list(self.tdaq_ready_generator(iovs)))
20
21 def tdaq_ready_generator(self, iovs):
22 #state = iovs.select_channels(0)
23
24 events = process_iovs(iovs)
25
26 for since, until, (state,) in events:
27
28 if state is not None:
29 if state.ReadyForPhysics == 1:
30 continue
31
32 yield DefectIOV(since, until, 'GLOBAL_NOTREADY', True,
33 comment='ReadyForPhysics not set')
34
35class TDAQ_Busy(DCSC_Defect_Global_Variable):
36 """
37 Overloads calculate_good_iovs & quantize
38 Latter because this is a strange COOL folder that is timewise but already quantized
39 as run-LB
40 """
41 input_db = 'COOLOFL_TRIGGER/CONDBR2'
42 fetch_args = dict(tag="OflLumiAcct-Run3-003")
43 deadfraction_threshold = 0.9
44
45 def make_good_iovs(self, iovs):
46 return IOVSet(list(connect_adjacent_iovs_defect(self.tdaq_busy_generator(iovs))))
47
48 def tdaq_busy_generator(self, iovs):
49 events = process_iovs(iovs)
50 counter=0
51
52 for since, until, (state,) in events:
53 if state.Run == 0 or state.Run is None: continue
54 if state is not None:
55 if state.LiveFraction is None:
56 deadfrac=1
57 log.warning('WARNING: LiveFraction is "None" for %d %d', state.Run, state.LumiBlock)
58 else:
59 deadfrac = 1-state.LiveFraction
60 if deadfrac < self.deadfraction_threshold:
61 continue
62 yield DefectIOV(RunLumi(state.Run, state.LumiBlock),
63 RunLumi(state.Run, state.LumiBlock+1),
64 'GLOBAL_BUSY', True,
65 comment='Average live fraction %.1f%%' % ((1-deadfrac)*100))
66 counter +=1
67
68 counter_max=counter
69 counter=0
70 events = process_iovs(iovs)
71 for since, until, (state,) in events:
72 if state is not None and state.Run is not None:
73 deadfrac = 1-state.LiveFraction
74 if deadfrac < self.deadfraction_threshold:
75 continue
76 counter +=1
77 if state.Run == 0 and counter <counter_max:
78 log.error('ERROR: Wrong run number in LumiAccounting; here is the IOV: ')
79 log.error(state)
80 continue
81
82 def quantize(self, lbtime, iovs):
83 return iovs
84
85class LUMI_EmittanceScan(DCSC_Defect_Global_Variable):
86 """
87 Overloads calculate_good_iovs & quantize
88 Latter because this is a strange COOL folder that is timewise but already quantized
89 as run-LB
90 """
91 input_db = 'COOLONL_TDAQ/CONDBR2'
92
93 def make_good_iovs(self, iovs):
94 return IOVSet(list(connect_adjacent_iovs_defect(self.emittance_generator(iovs))))
95
96 def emittance_generator(self, iovs):
97 events = process_iovs(_ for _ in iovs if _.channel == 1 and _.ScanningIP != 0)
98
99 for since, until, (state,) in events:
100 #print state, state.RunLB & 0xffffffff if state.RunLB else 0
101 if state is not None and state.RunLB is not None:
102 thisrun = state.RunLB >>32
103 # pseudo-LB and not to be trusted
104 if thisrun == 0: continue
105 thisLB = state.RunLB & 0xffffffff
106 yield DefectIOV(RunLumi(thisrun, thisLB),
107 RunLumi(thisrun, thisLB+1),
108 'LUMI_EMITTANCESCAN', True,
109 comment='Emittance scan'
110 )
111
112 def quantize(self, lbtime, iovs):
113 return iovs
114
115class Global(DCSC_Subdetector_DefectsOnly):
116 #__DISABLED__ = True
117 folder_base = ''
118
119 variables = [
120 TDAQ_Ready('/TDAQ/RunCtrl/DataTakingMode', lambda x: True),
121 #TDAQ_Busy('/TRIGGER/LUMI/PerBcidDeadtime', lambda x: True),
122 TDAQ_Busy('/TRIGGER/OFLLUMI/LumiAccounting', lambda x: True),
123 LUMI_EmittanceScan('/TDAQ/OLC/LHC/SCANDATA', lambda x: True), # restore once the SCANDATA folder is figured out by OLC
124 ]
125
126 def __init__(self, tolerance=2):
127 pass
128
129 def run(self, lbtime, run_iovs):
130 self.evaluate_inputs(lbtime)
131 return IOVSet(sum((truncate_to_atlas_runs(var.iovs)[0] if len(var.iovs) > 0 else []
132 for var in self.variables), []))
Definition run.py:1