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