3 from pkg_resources 
import resource_string
 
    5 from ..lib 
import (DCSC_DefectTranslate_Subdetector, DCSC_Variable, GoodIOV,
 
    6                    OUT_OF_CONFIG, DCSC_Variable_With_Mapping)
 
    8 from DQUtils.sugar 
import IOVSet
 
   12     Specialisation for the /SCT/DAQ/Configuration/Module folder. 
   14     CoraCOOL stores multiple elements per iov. This folder only ever contains  
   18     input_db = 
"COOLONL_SCT/CONDBR2" 
   19     is_config_variable = 
True 
   23     fetch_args = dict(what=[
"group", 
"id"])
 
   27         Beware, deceptive function name. Here we are really  
   28         making OUT_OF_CONFIG iovs, rather than 'good' ones. 
   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. 
   33         iovs = [iov 
for iov 
in iovs 
if iov.elements]
 
   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]
 
   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. 
   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")
 
   53     subdets = {0: 114, 1: 111, 2: 115}
 
   57         output_subdet = subdets[(cid >> 25) & 0x3]
 
   58         mapping.setdefault(output_subdet, []).
append(cid)
 
   67 C_GOOD, C_MANUAL = 0x1, 0x3
 
   68 good_states = [C_GOOD, C_MANUAL]
 
   72     Determine whether CHANSTAT iov is good or bad. 
   74     return (
hi_nibble(iov.STATE) 
in good_states 
and 
   79     folder_base = 
"/SCT/DCS" 
   83         Initialise two mappings: Input COOL ids to output ids, and serial 
   84         numbers for the configuration need mapping onto input ids. 
   89         super(SCT, self).
__init__(*args, **kwargs)
 
   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)
 
  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
 
  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)):
 
  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,
 
  115     dead_fraction_caution = 0.1
 
  116     dead_fraction_bad = 0.5
 
  119         DCSC_Variable(
"HV", 
lambda iov: 55 < iov.HVCHVOLT_RECV < 3000),