ATLAS Offline Software
Loading...
Searching...
No Matches
sct.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3from pkg_resources import resource_string
4
5from ..lib import (DCSC_DefectTranslate_Subdetector, DCSC_Variable, GoodIOV,
6 OUT_OF_CONFIG, DCSC_Variable_With_Mapping)
7
8from DQUtils.sugar import IOVSet
9
11 """
12 Specialisation for the /SCT/DAQ/Configuration/Module folder.
13
14 CoraCOOL stores multiple elements per iov. This folder only ever contains
15 zero or one elements.
16 """
17
18 input_db = "COOLONL_SCT/CONDBR2"
19 is_config_variable = True
20
21 # This is an instruction to fetch_iovs to get the "group" and "id"
22 # variables from CoraCOOL
23 fetch_args = dict(what=["group", "id"])
24
25 def make_good_iovs(self, iovs):
26 """
27 Beware, deceptive function name. Here we are really
28 making OUT_OF_CONFIG iovs, rather than 'good' ones.
29
30 The resulting IoVs are in terms of detector serial number. These get
31 mapped onto the HV channel IDs with the `sct_sn_to_cool_ids` mapping.
32 """
33 iovs = [iov for iov in iovs if iov.elements]
34 #assert all(len(iov.elements) == 1 for iov in iovs)
35 iovs = [GoodIOV(iov.since, iov.until, iov.elements[0].id, OUT_OF_CONFIG)
36 for iov in iovs if iov.elements[0].group == -1]
37
38 return IOVSet(iovs)
39
41 """
42 Generate a mapping for the channelids in /SCT/DCS/HV to DCSOFL output
43 channel ids. The highest two bits can be used to determine the system.
44 (see `subdets`)
45 """
46 from DQUtils.db import Databases
47 from DQUtils.channel_mapping import get_channel_ids_names
48 f = Databases.get_folder("/SCT/DCS/HV", "COOLOFL_DCS/CONDBR2")
49 cids, cnames, cmap = get_channel_ids_names(f)
50
51 mapping = {}
52
53 subdets = {0: 114, 1: 111, 2: 115}
54
55 for cid in cids:
56 # The highest-two bits of cid specify which DQ region we're in
57 output_subdet = subdets[(cid >> 25) & 0x3]
58 mapping.setdefault(output_subdet, []).append(cid)
59
60 return mapping
61
62def hi_nibble(x): return (x & 0xF0) >> 4
63def lo_nibble(x): return (x & 0x0F)
64
65# Documented at: (Visited 20/05/2010)
66# https://twiki.cern.ch/twiki/bin/view/Atlas/SctDCSSoftware#FSM_Channel_Status_Byte
67C_GOOD, C_MANUAL = 0x1, 0x3
68good_states = [C_GOOD, C_MANUAL]
69
71 """
72 Determine whether CHANSTAT iov is good or bad.
73 """
74 return (hi_nibble(iov.STATE) in good_states and
75 lo_nibble(iov.STATE) in good_states)
76
78
79 folder_base = "/SCT/DCS"
80
81 def __init__(self, *args, **kwargs):
82 """
83 Initialise two mappings: Input COOL ids to output ids, and serial
84 numbers for the configuration need mapping onto input ids.
85 """
87 #if 'keep_dcsofl' not in kwargs:
88 # kwargs['keep_dcsofl'] = True
89 super(SCT, self).__init__(*args, **kwargs)
90
91 sct_sn_to_cool_ids = resource_string("DCSCalculator2.subdetectors.data",
92 "sct_module_ids.dat").decode()
93 sct_sn_to_cool_ids = sct_sn_to_cool_ids.strip().split("\n")
94 sn_mapping = dict(map(int, l.split()) for l in sct_sn_to_cool_ids if l)
95 self.set_input_mapping("/SCT/DAQ/Configuration/Module", sn_mapping)
96 self.translators = [SCT.sct_color_to_defect_translator]
97
98 @staticmethod
100 defectmap = { 111: 'B', 114: 'EA', 115: 'EC' }
101 from DCSCalculator2.consts import GREEN
102 from DCSCalculator2.variable import DefectIOV
103 from DQUtils import process_iovs
104 rv = []
105 for since, until, states in process_iovs(*flag_iovs.by_channel.values()):
106 if (any(state.Code != GREEN for state in states)
107 and not any(state.Code is None for state in states)):
108 # This line of code is awful!
109 badfrac = 'Bad fractions: ' + ', '.join('%s %.3f' % (defectmap[state.channel], state.deadFrac) for state in sorted(states, key=lambda x: x.channel))
110 rv.append(DefectIOV(since=since, until=until,
111 channel='SCT_GLOBAL_STANDBY', present=True,
112 comment = badfrac))
113 return rv
114
115 dead_fraction_caution = 0.1
116 dead_fraction_bad = 0.5
117
118 variables = [
119 DCSC_Variable("HV", lambda iov: 55 < iov.HVCHVOLT_RECV < 3000),
120 DCSC_Variable("CHANSTAT", check_good_chanstat),
121
122 # Evaluator not required because make_good_iovs overloaded
123 DCSC_Variable_SCT_Config("/SCT/DAQ/Configuration/Module", None),
124 ]
STL class.
set_input_mapping(self, what, mapping)
sct_color_to_defect_translator(flag_iovs)
Definition sct.py:99
__init__(self, *args, **kwargs)
Definition sct.py:81
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
check_good_chanstat(iov)
Definition sct.py:70