ATLAS Offline Software
sct.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 from pkg_resources import resource_string
4 
5 from ..lib import (DCSC_DefectTranslate_Subdetector, DCSC_Variable, GoodIOV,
6  OUT_OF_CONFIG, DCSC_Variable_With_Mapping)
7 
8 from 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 
62 def hi_nibble(x): return (x & 0xF0) >> 4
63 def 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
67 C_GOOD, C_MANUAL = 0x1, 0x3
68 good_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  ]
python.subdetectors.sct.lo_nibble
def lo_nibble(x)
Definition: sct.py:63
python.subdetectors.sct.SCT.__init__
def __init__(self, *args, **kwargs)
Definition: sct.py:81
python.subdetector.DCSC_DefectTranslate_Subdetector.translators
translators
Definition: subdetector.py:541
python.variable.DCSC_Variable
Definition: variable.py:33
python.variable.DefectIOV
def DefectIOV(channel, present, comment)
Definition: variable.py:26
python.channel_mapping.get_channel_ids_names
def get_channel_ids_names(folder)
Definition: channel_mapping.py:102
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.subdetectors.sct.make_sct_mapping
def make_sct_mapping()
Definition: sct.py:40
python.variable.GoodIOV
def GoodIOV(channel, good)
Definition: variable.py:18
python.subdetectors.sct.SCT
Definition: sct.py:77
python.subdetector.DCSC_DefectTranslate_Subdetector
Definition: subdetector.py:532
python.subdetectors.sct.check_good_chanstat
def check_good_chanstat(iov)
Definition: sct.py:70
python.subdetector.DCSC_Subdetector.set_input_mapping
def set_input_mapping(self, what, mapping)
Definition: subdetector.py:52
python.subdetectors.sct.SCT.sct_color_to_defect_translator
def sct_color_to_defect_translator(flag_iovs)
Definition: sct.py:99
python.subdetectors.sct.DCSC_Variable_SCT_Config.make_good_iovs
def make_good_iovs(self, iovs)
Definition: sct.py:25
python.events.process_iovs
def process_iovs(*iovsets)
Definition: events.py:30
python.subdetectors.sct.DCSC_Variable_SCT_Config
Definition: sct.py:10
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.PerfMonSerializer.decode
def decode(s)
Definition: PerfMonSerializer.py:388
python.subdetectors.sct.hi_nibble
def hi_nibble(x)
Definition: sct.py:62
python.variable.DCSC_Variable_With_Mapping
Definition: variable.py:225
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.subdetectors.sct.SCT.mapping
mapping
Definition: sct.py:86