Source code for km3dq_common.grl_library

#! /usr/bin/env python
########################################################################################

from km3dq_common.config_library import configure_dataquality_tag
from km3dq_common.config_library import configure_var_name
from km3dq_common.config_library import configure_var_bit
from km3dq_common.config_library import configure_var_thresholds
from km3dq_common.common_library import create_ttree_from_qaqc
from km3dq_common.lw_db_defect_library import decode_defect_diag_byte
import numpy as np


########################################################################################
[docs] def get_good_run_list(det, dq_tag_name, add_info=[], qaqc_input="qaqc_sftp"): """ Production of good run lists === Arguments === - det : detector name - [string] - Ex: "D0ARCA021", "D0ORCA018"... - dq_tag_name : data-quality tag name - [string] - add_info : list of additional informations (qaqc variables or defect) to be retrieved in the same time as the GRL - [array of strings] - Ex: ["livetime", "def_operation/partly", "sign_off/run_coordinator"] - source : QAQC source, a priori "qaqc_sftp" - [string] === Output === - GRL dictionnary including the additional info. """ dq_tag_0 = configure_dataquality_tag(dq_tag_name) grl_0 = { "var_prop": {}, "good": {}, "poor": {}, "bad": {}, "discard": {}, "add_info": {}, } configure_var_name(grl_0["var_prop"]) configure_var_bit(grl_0["var_prop"]) configure_var_thresholds(grl_0["var_prop"], det, dq_tag_0) # The TTree must contain: # - the run number and livetime # - the variables (QAQC + defects) used in the Veto / Qscore computation # (required by create_ttree_from_qaqc) # - the variables (QAQC + defects) used in the GRL generation # - the additional variables to be reported var_to_store = ["run", "livetime_s"] var_to_store += list(grl_0["var_prop"]["veto_thresholds"].keys()) var_to_store += list(grl_0["var_prop"]["qsco_thresholds"].keys()) for i_q in ("good", "poor", "bad", "discard"): var_to_store += list(grl_0["var_prop"][f"{i_q}_thresholds"].keys()) for i_var in add_info: if i_var.startswith("def_"): # Extract the defect type to be included in the tree i_var_def_type = i_var.split("/")[0] var_to_store.append(i_var_def_type) grl_0["add_info"][i_var] = [] else: grl_0["add_info"][i_var] = {} var_to_store = set(var_to_store) var_to_store.discard("veto") var_to_store.discard("qsco") (n1, _) = create_ttree_from_qaqc(det, var_to_store, qaqc_input, dq_tag_0, True) masks = {} for quality in ("good", "poor", "bad", "discard"): mask = np.ones(len(n1), dtype=bool) for variable, (lower, upper) in grl_0["var_prop"][ f"{quality}_thresholds" ].items(): mask = mask & (n1[variable] >= lower) & (n1[variable] <= upper) if quality == "discard": # Discard is True when excluded mask = ~mask grl_0[quality]["run_list"] = n1.run[mask].values grl_0[quality]["livetime_s"] = np.sum(n1.livetime_s[mask]) for variable in add_info: grl_0["add_info"][variable] = dict(zip(n1.run, n1[variable])) return grl_0