def test_defect_insertion_retrieval_unicode(): if six.PY3: import ROOT if ROOT.gROOT.GetVersionInt() < 62000: # Passing str objects using multibyte encodings is broken # with pyroot up to 6.18. Should be fixed in 6.20? return ddb = DefectsDB(TEST_DATABASE, read_only=False) TEST_ID = 0 TEST_DEFECT_NAME = "DQD_TEST_DEFECT_%i" % TEST_ID TEST_COMMENT = u"First test defect with character: ±" TEST_USER = u"DQDefécts.tests" TEST_SINCE, TEST_UNTIL = 0, 100 TEST_DEFECT_DESCRIPTION = u"À test defect (%i)" % TEST_ID create_defect_type_unicode(ddb, TEST_ID, TEST_DEFECT_DESCRIPTION) ddb.insert(TEST_DEFECT_NAME, TEST_SINCE, TEST_UNTIL, TEST_COMMENT, TEST_USER) iovs = ddb.retrieve() assert len(iovs) == 1 iov = iovs[0] assert iov.present assert not iov.recoverable assert iov.user == TEST_USER assert iov.comment == TEST_COMMENT assert ddb.all_defect_descriptions[ TEST_DEFECT_NAME] == TEST_DEFECT_DESCRIPTION
def test_tagging_unicode(): ddb = DefectsDB(TEST_DATABASE, read_only=False) # Create two defects create_defect_type(ddb, 0) create_defect_type(ddb, 1) ddb.insert(u"DQD_TEST_DEFECT_0", 0, 100, u"", u"") ddb.insert(u"DQD_TEST_DEFECT_1", 100, 200, u"", u"") defects_tag = ddb.new_defects_tag("dqd-test", u"New iov tag") # Make a virtual defect whose result is the combination of the above ddb.new_virtual_defect(u"DQD_TEST_VIRTUAL_DEFECT", u"", u"DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1") original_tag = ddb.new_logics_tag() original_htag = ddb.new_hierarchical_tag(defects_tag, original_tag) what = {"channels": [u"DQD_TEST_VIRTUAL_DEFECT"]} orig_iovs = DefectsDB((TEST_DATABASE), tag=unicode(original_htag)).retrieve(**what) assert len(orig_iovs) == 2 assert (orig_iovs[0].since, orig_iovs[0].until) == ( 0, 100) assert (orig_iovs[1].since, orig_iovs[1].until) == (100, 200)
def main(): d = DefectsDB() iov_range = None, None # iov_range = 185000 << 32, 185500 << 32 #iov_range = 177682 << 32, 200000 << 32 with timer("Fetch defect info"): all_defects = d.retrieve(*iov_range) with timer("fetch peripheral information"): descriptions = d.all_defect_descriptions intolerable = d.get_intolerable_defects() virtual = d.virtual_defect_names with timer("Fetch lumi inputs"): lbs, lumis = fetch_lumi_inputs(iov_range, "ONLINE") d = build_defects(descriptions, virtual, intolerable, lbs, lumis, all_defects) target_dir = "/afs/cern.ch/user/p/pwaller/www/defects/test" art_dir = pjoin(target_dir, "extern") if not exists(art_dir): makedirs(art_dir) copy_art(art_dir) content = build_table(headings=heading_titles, defects=d) with open(pjoin(target_dir, "test.html"), "w") as fd: fd.write(content)
def test_ignore_defects(): ddb = DefectsDB(TEST_DATABASE, read_only=False) # Create two defects create_defect_type(ddb, 0) create_defect_type(ddb, 1) create_defect_type(ddb, 2) ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "", "") ddb.insert("DQD_TEST_DEFECT_1", 100, 200, "", "") ddb.insert("DQD_TEST_DEFECT_2", 200, 300, "", "") ddb.new_virtual_defect( "DQD_TEST_VIRTUAL_DEFECT", "", "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1 DQD_TEST_DEFECT_2") ignored_defects = set(["DQD_TEST_DEFECT_1"]) iovs = ddb.retrieve() assert iov_result_depends(iovs) & ignored_defects, "test is broken" iovs = ddb.retrieve(ignore=ignored_defects) assert not iov_result_depends( iovs) & ignored_defects, "result depends on ignored defects"
def BadLBFilterAlgCfg(inputFlags,name, defects, writekey, ignoreRecoverable=False, origDbTag=None): log = logging.getLogger('BadLBFilterAlgCfg') result=ComponentAccumulator() from DQDefects import DefectsDB ddb = DefectsDB('COOLOFL_GLOBAL/' + inputFlags.IOVDb.DatabaseInstance, tag=origDbTag or inputFlags.IOVDb.GlobalTag) primary_defects = set() for defect in defects: if defect in ddb.defect_names: primary_defects.add(defect) elif defect in ddb.virtual_defect_names: primary_defects |= ddb.virtual_defect_logics(defect).primary_defects else: raise ValueError('%s is not a known defect' % defect) log.info ("Algorithm %s configured with intolerable defects %s" % (name, list(primary_defects))) primary_defect_ids = [ddb.defect_id_map[id] for id in primary_defects] monFilterAlg =CompFactory.DQBadLBFilterAlg(name) monFilterAlg.defectList = primary_defect_ids monFilterAlg.ignoreRecoverable = ignoreRecoverable monFilterAlg.WriteKey = writekey from IOVDbSvc.IOVDbSvcConfig import addFolders if not inputFlags.Input.isMC: result.merge(addFolders(inputFlags,'/GLOBAL/DETSTATUS/DEFECTS',detDb='GLOBAL_OFL',className='CondAttrListCollection')) result.addCondAlgo(monFilterAlg) return result
def test_noncontiguous_defectid_creation(): """ Test that defects are inserted correctly into non-contiguous ranges """ ddb = DefectsDB(TEST_DATABASE, read_only=False) create_defect_type(ddb, 0) ddb._create_defect_with_id(2, "TEST_DEFECT_DQD_2", "") ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment", "DQD_TEST_DEFECT_0 TEST_DEFECT_DQD_2") ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_2", "Comment", "DQD_TEST_DEFECT_0 TEST_DEFECT_DQD_2") create_defect_type(ddb, 1) create_defect_type(ddb, 3) # assert primary and virtual defects are right ids, names, m = ddb.get_channels() assert m == { 0: 'DQD_TEST_DEFECT_0', 1: 'DQD_TEST_DEFECT_1', 2: 'TEST_DEFECT_DQD_2', 3: 'DQD_TEST_DEFECT_3', 'DQD_TEST_DEFECT_3': 3, 'DQD_TEST_DEFECT_0': 0, 'DQD_TEST_DEFECT_1': 1, 'TEST_DEFECT_DQD_2': 2 }, 'Primary defect problem' ids, names, m = ddb.get_virtual_channels() assert m == { 2147483648: 'DQD_TEST_VIRTUAL_DEFECT', 2147483649: 'DQD_TEST_VIRTUAL_DEFECT_2', 'DQD_TEST_VIRTUAL_DEFECT': 2147483648, 'DQD_TEST_VIRTUAL_DEFECT_2': 2147483649 }, 'Virtual defect problem'
def test_defect_insertion_retrieval(): ddb = DefectsDB(TEST_DATABASE, read_only=False) TEST_ID = 0 TEST_DEFECT_NAME = "DQD_TEST_DEFECT_%i" % TEST_ID TEST_COMMENT = "First test defect" TEST_USER = "******" TEST_SINCE, TEST_UNTIL = 0, 100 create_defect_type(ddb, TEST_ID) ddb.insert(TEST_DEFECT_NAME, TEST_SINCE, TEST_UNTIL, TEST_COMMENT, TEST_USER) iovs = ddb.retrieve() assert len(iovs) == 1 iov = iovs[0] assert iov.since == TEST_SINCE assert iov.until == TEST_UNTIL assert iov.channel == TEST_DEFECT_NAME assert iov.present assert not iov.recoverable assert iov.user == TEST_USER assert iov.comment == TEST_COMMENT
def GetBadLBFilterTool(name, defects, alwaysReturnTrue=False, ignoreRecoverable=False, autoconfigure=True, origDbTag=None): """ Configure an instance of the bad LB filter tool. If called twice with the same options, will return the same instance. Arguments: - name: name of instance to create - defects: the defects to use for LB rejection. Tool will return false if any of these defects is present. These may be virtual defects. NOTE: the value you pass must be a 'hashable' type. The best choice is to pass a tuple; you can create a tuple from any iterable object with tuple(obj). - alwaysReturnTrue (optional; default=False): if True, the tool will never reject any LBs. - ignoreRecoverable (optional; default=False): if True, the tool will ignore defects that are marked as recoverable - autoconfigure (optional; default=True): automatically handle certain cases, e.g. Monte Carlo, where we want to always return True - origDbTag (optional): if set, will override automatic configuration of database tag (only for testing) """ import operator from AthenaMonitoring.DQMonFlags import DQMonFlags from AthenaCommon.GlobalFlags import globalflags from AthenaCommon.AppMgr import ToolSvc from AthenaCommon.Logging import logging log = logging.getLogger('BadLBFilterTool') # if online or MC, we don't want to do any filtering, or even access # the DBs if autoconfigure and (DQMonFlags.monManEnvironment == 'online' or globalflags.DataSource.get_Value() == 'geant4' ): log.info('Disabling bad LB filter tool due to inappropriate environment; returning dummy') from AthenaMonitoring.AthenaMonitoringConf import DQDummyFilterTool monFilterTool = DQDummyFilterTool(name) ToolSvc += monFilterTool return monFilterTool from AthenaMonitoring.AthenaMonitoringConf import DQBadLBFilterTool from DQDefects import DefectsDB dbtag = _resolve_db_tag(origDbTag) dbname=_InstanceFromProjectName() ddb = DefectsDB('COOLOFL_GLOBAL/' + dbname, tag=dbtag) primary_defects = set() for defect in defects: if defect in ddb.defect_names: primary_defects.add(defect) elif defect in ddb.virtual_defect_names: primary_defects |= ddb.virtual_defect_logics(defect).primary_defects else: raise ValueError('%s is not a known defect' % defect) log.info ("Tool name %s to be configured with intolerable defects %s" % (name, list(primary_defects))) primary_defect_ids = [ddb.defect_id_map[id] for id in primary_defects] monFilterTool = DQBadLBFilterTool(name) monFilterTool.defectList = primary_defect_ids monFilterTool.alwaysReturnTrue = alwaysReturnTrue monFilterTool.ignoreRecoverable = ignoreRecoverable if globalflags.DataSource.get_Value() != 'geant4': from IOVDbSvc.CondDB import conddb if not conddb.folderRequested('/GLOBAL/DETSTATUS/DEFECTS'): conddb.addFolder('GLOBAL_OFL', '/GLOBAL/DETSTATUS/DEFECTS') ToolSvc += monFilterTool return monFilterTool
def test_many_sparse_channels(): "Testing many virtual channels with sparsely placed IoVs" ddb = DefectsDB(TEST_DATABASE, read_only=False) all_defects = [] for i in range(52): all_defects.append(create_defect_type(ddb, i * 2)) with ddb.storage_buffer: for i in all_defects: ddb.insert(i, 0, 100, "Test", "DQDefects.tests") queried_defects = all_defects[:-1] result = ddb.retrieve(channels=queried_defects) queried_defects_set = set(queried_defects) result_defects_set = set(i.channel for i in result) unwanted_defects_set = result_defects_set - queried_defects_set assert not unwanted_defects_set, "Unwanted defects: %r" % unwanted_defects_set ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment", " ".join(all_defects)) result = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"]) assert result.channels == set(["DQD_TEST_VIRTUAL_DEFECT"]) assert len(result) == 1 # This assumes evaluate_full == True assert result[0].comment == " ".join( sorted(all_defects)), result[0].comment result = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"], evaluate_full=False) assert result.channels == set(["DQD_TEST_VIRTUAL_DEFECT"]) assert len(result) == 1
def test_query_with_primary_dependencies_with_ignore(): """ Checking with_primary_dependencies + ignore Checks that the set of channels and iovs returned contains the correct number of channels and iovs when specifying both with_primary_dependencies and ignore to DQDefects.Retrieve """ ddb = DefectsDB(TEST_DATABASE, read_only=False) # Create two defects defect_names = [create_defect_type(ddb, i) for i in range(3)] for i, defect in enumerate(defect_names): ddb.insert(defect, i * 100, (i + 1) * 100, "", "") ignored = set(defect_names[:1]) ddb.new_virtual_defect("DQD_TEST_VDEFECT", "", " ".join(defect_names)) iovs = ddb.retrieve(channels=["DQD_TEST_VDEFECT"], ignore=ignored) assert iovs.channels == set(["DQD_TEST_VDEFECT"]) assert len(iovs) == len(defect_names) - 1 iovs = ddb.retrieve(channels=["DQD_TEST_VDEFECT"], ignore=ignored, with_primary_dependencies=True) assert iovs.channels == set(["DQD_TEST_VDEFECT"] + defect_names) - ignored, ("Check failed.") assert len(iovs) == len(defect_names[1:]) * 2
def show_defects_with_desc(connection_string, tag, get_defects, patterns, args): ddb = DefectsDB(connection_string, tag=tag) descriptions = ddb.all_defect_descriptions if args.descriptions else {} all_defects = get_defects(ddb) all_matching = [d for pat in patterns for d in fnmatch.filter(all_defects, pat)] if not all_matching: return get_virtuality = lambda defect: "" if args.show_virtuality: primary_defects = ddb.defect_names def get_virtuality(defect): if defect in primary_defects: return "[P] " return "[V] " ldl = longest_defect_length = max(len(d) for d in all_matching) for pattern in patterns: if len(patterns) != 1: print "%s:" % pattern for defect in sorted(fnmatch.filter(all_defects, pattern)): desc = descriptions.get(defect, "") print "{virtuality}{0:<{width}}: {1}".format( defect, desc, width=ldl, virtuality=get_virtuality(defect)) print
def test_virtual_defect_consistency(): """ Checking that virtual flags don't depend on non-existent flags """ DefectsDB( 'oracle://ATLAS_COOLPROD;schema=ATLAS_COOLOFL_GLOBAL;dbname=CONDBR2' )._virtual_defect_consistency_check()
def connect(self): """ Open connection to defect DB """ self.db = DefectsDB(self.database, read_only=True, create=False, tag=self.tag) self.idbsDefects = [ d for d in self.db.defect_names if d.startswith('ID_BS_') or d == 'LUMI_VDM' ] if self.debug: print self.idbsDefects return
def show_defects(connection_string, tag, get_defects, patterns, args): ddb = DefectsDB(connection_string, tag=tag) all_defects = get_defects(ddb) for pattern in patterns: if len(patterns) != 1: print # Extra newline to separate the patterns print "%s:" % pattern for defect in sorted(fnmatch.filter(all_defects, pattern)): print defect
def connect(self, fileName, forceNew=False, dbName='IDBSDQ', tag='nominal'): """ Open connection to defect DB """ connString = 'sqlite://;schema=%s;dbname=%s' % (fileName, dbName) if forceNew and os.path.exists(fileName): os.remove(fileName) self.db = DefectsDB( connString, read_only=False, create=True, tag=(tag, 'HEAD') ) # Second tag is for virtual defects, which we are not interested in self.officialDb = DefectsDB() return
def test_virtual_defects_deep(): ddb = DefectsDB(TEST_DATABASE, read_only=False) # Create two defects create_defect_type(ddb, 0) create_defect_type(ddb, 1) # Insert an iov into each ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests") ddb.insert("DQD_TEST_DEFECT_1", 150, 200, "Test", "DQDefects.tests") # Make a virtual defect whose result is the combination of the above ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_0", "", "DQD_TEST_DEFECT_0") ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_1", "", "DQD_TEST_DEFECT_1") ddb = DefectsDB(TEST_DATABASE) iovs = ddb.retrieve()
def test_defect_insertion_retrieval_unicode(): ddb = DefectsDB(TEST_DATABASE, read_only=False) TEST_ID = 0 TEST_DEFECT_NAME = "DQD_TEST_DEFECT_%i" % TEST_ID TEST_COMMENT = u"First test defect with character: ±" TEST_USER = u"DQDefécts.tests" TEST_SINCE, TEST_UNTIL = 0, 100 TEST_DEFECT_DESCRIPTION = u"À test defect (%i)" % TEST_ID create_defect_type_unicode(ddb, TEST_ID, TEST_DEFECT_DESCRIPTION) ddb.insert(TEST_DEFECT_NAME, TEST_SINCE, TEST_UNTIL, TEST_COMMENT, TEST_USER) iovs = ddb.retrieve() assert len(iovs) == 1 iov = iovs[0] assert iov.present assert not iov.recoverable assert iov.user == TEST_USER assert iov.comment == TEST_COMMENT assert ddb.all_defect_descriptions[TEST_DEFECT_NAME] == TEST_DEFECT_DESCRIPTION
def test_nonpresent(): ddb = DefectsDB(TEST_DATABASE, read_only=False) create_defect_type(ddb, 0) ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests") ddb.insert("DQD_TEST_DEFECT_0", 0, 100, "Test", "DQDefects.tests", present=False) iovs = ddb.retrieve() assert len(iovs) == 0 iovs = ddb.retrieve(nonpresent=True) assert len(iovs) == 1 assert not iovs[0].present
def test_normalize_defect_names(): ddb = DefectsDB(TEST_DATABASE, read_only=False) # Create two defects create_defect_type(ddb, 0) create_defect_type(ddb, 1) # Make a virtual defect whose result is the combination of the above ddb.new_virtual_defect("DQD_TEST_Virtual_DEFECT", "Comment", "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1") assert ddb.normalize_defect_names('dQd_tEsT_DeFeCt_0')=='DQD_TEST_DEFECT_0' assert ddb.normalize_defect_names(['dQd_tEsT_DeFeCt_0', 'DqD_TeSt_dEfEcT_1'])==['DQD_TEST_DEFECT_0', 'DQD_TEST_DEFECT_1'] assert ddb.normalize_defect_names('dqd_test_virtual_defect')=='DQD_TEST_Virtual_DEFECT' try: ddb.normalize_defect_names('does_not_exist') wasthrown = False except DefectUnknownError: wasthrown = True assert wasthrown, 'normalize_defect_names should throw when the defect does not exist'
def show_tags(connection_string, args): ddb = DefectsDB(connection_string) nspec = sum(bool(x) for x in (args.tags, args.defect_tags, args.logic_tags)) assert nspec == 1, "Only one of --tags, --logic-tags and --defect-tags can be specified." if args.tags: tags = ddb.tags if args.logic_tags: tags = ddb.logics_tags if args.defect_tags: tags = ddb.defects_tags for t in tags: print t
def test_virtual_defect_hiding(): ddb = DefectsDB(TEST_DATABASE, read_only=False) # Create two defects create_defect_type(ddb, 0) create_defect_type(ddb, 1) # Make a virtual defect whose result is the combination of the above ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment", "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1") new_tag = ddb.new_logics_tag() ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT_2", "Comment", "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1") ddb2 = DefectsDB(TEST_DATABASE, tag=('HEAD', new_tag), read_only=True) assert ddb2.virtual_defect_names == set(['DQD_TEST_VIRTUAL_DEFECT']), 'Only one virtual defect should be in this tag'
def test_reject_duplicate_names(): ddb = DefectsDB(TEST_DATABASE, read_only=False) ddb.create_defect('A_TEST_DEFECT', 'A test defect') wasthrown = False try: ddb.create_defect('A_TEST_DEFECT', 'A test defect 2') except DefectExistsError: wasthrown = True assert wasthrown, 'Creation of duplicate defects should throw' wasthrown = False try: ddb.create_defect('A_test_defect', 'A test defect 2') except DefectExistsError: wasthrown = True assert wasthrown, 'Creation of duplicate defects should throw, even with different case'
def test_intersect(): ddb = DefectsDB(TEST_DATABASE, read_only=False) # Create two defects create_defect_type(ddb, 0) create_defect_type(ddb, 1) create_defect_type(ddb, 2) ddb.insert("DQD_TEST_DEFECT_0", 0, 1000, "", "") ddb.insert("DQD_TEST_DEFECT_0", 1000, 2000, "", "") iovs = ddb.retrieve(50, 100, intersect=True) assert len(iovs) == 1 assert (iovs[0].since, iovs[0].until) == (50, 100) iovs = ddb.retrieve(999, 1001, intersect=True) assert len(iovs) == 2 first, second = iovs assert (first.since, first.until) == (999, 1000) assert (second.since, second.until) == (1000, 1001)
def show_defects_with_logic(connection_string, tag, patterns, args): ddb = DefectsDB(connection_string, tag=tag) defects = ddb.virtual_defect_names logics = ddb.virtual_defect_logics all_matching = [d for pat in patterns for d in fnmatch.filter(defects, pat)] if not all_matching: return ldl = longest_defect_length = max(len(d) for d in all_matching) for pattern in patterns: if len(patterns) != 1: print "%s:" % pattern for defect in sorted(fnmatch.filter(defects, pattern)): print "{0:<{width}}: {1}".format( defect, ", ".join(logics[defect].clauses), width=ldl) print
def LArDefectList(inputFlags,origDbTag=None): """ Get the defects to configure for LAr - cache results to avoid lots of DB lookups Arguments: - origDbTag (optional): if set, will override automatic configuration of database tag (only for testing) """ import operator from DQDefects import DefectsDB ddb = DefectsDB('COOLOFL_GLOBAL/' + inputFlags.IOVDb.DatabaseInstance, tag=origDbTag or inputFlags.IOVDb.GlobalTag) lar_defects = reduce(operator.or_, [set(ddb.virtual_defect_logics[z].clauses) for z in \ ('EMBA', 'EMBC', 'EMECA', 'EMECC', 'HECA', 'HECC', 'FCALA', 'FCALC')])-set(['LAR_UNCHECKED','LAR_GENERAL','DISABLED','NONGREEN']) lar_defects = set(defect for defect in lar_defects if ('LAR' in defect and (('HVTRIP' in defect) or ('SEV' in defect) or ('CORRUPT' in defect)))) return lar_defects
def test_query_with_primary_dependencies(): ddb = DefectsDB(TEST_DATABASE, read_only=False) # Create two defects defect_names = [create_defect_type(ddb, i) for i in range(3)] for i, defect in enumerate(defect_names): ddb.insert(defect, i * 100, (i + 1) * 100, "", "") ddb.new_virtual_defect("DQD_TEST_VDEFECT", "", " ".join(defect_names)) iovs = ddb.retrieve(channels=["DQD_TEST_VDEFECT"]) assert iovs.channels == set(["DQD_TEST_VDEFECT"]) assert len(iovs) == len(defect_names) iovs = ddb.retrieve(channels=["DQD_TEST_VDEFECT"], with_primary_dependencies=True) assert iovs.channels == set(["DQD_TEST_VDEFECT"] + defect_names), ("Check failed.") assert len(iovs) == len(defect_names) * 2
def test_defect_empty_retrieval(): ddb = DefectsDB(TEST_DATABASE, read_only=False) iovs = ddb.retrieve() assert not iovs # Create two defects create_defect_type(ddb, 0) create_defect_type(ddb, 1) # Make a virtual defect whose result is the combination of the above ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "Comment", "DQD_TEST_DEFECT_0 DQD_TEST_DEFECT_1") iovs = ddb.retrieve() assert not iovs
def GetLArBadLBFilterTool(origDbTag=None): """ Configure a LAr defect-specific instance of the bad LB filter tool. If called twice with the same options, will return the same instance. Arguments: - origDbTag (optional): if set, will override automatic configuration of database tag (only for testing) """ import operator from AthenaCommon.Logging import logging log = logging.getLogger('BadLBFilterTool/LAr') # if online or MC, we don't want to do any filtering, or even access # the DBs from AthenaMonitoring.DQMonFlags import DQMonFlags from AthenaCommon.GlobalFlags import globalflags if (DQMonFlags.monManEnvironment == 'online' or globalflags.DataSource.get_Value() == 'geant4'): log.info( 'Disabling LAr bad LB filter tool due to inappropriate environment' ) lar_defects = [] else: from DQDefects import DefectsDB dbtag = _resolve_db_tag(origDbTag) dbname = _InstanceFromProjectName() ddb = DefectsDB('COOLOFL_GLOBAL/' + dbname, tag=dbtag) defects = ddb.defect_names defectliststr = [] defectlist = [] lar_defects = reduce(operator.or_, [set(ddb.virtual_defect_logics[z].clauses) for z in \ ('EMBA', 'EMBC', 'EMECA', 'EMECC', 'HECA', 'HECC', 'FCALA', \ 'FCALC')])-set(['LAR_UNCHECKED','LAR_GENERAL','DISABLED','NONGREEN']) lar_defects = set(defect for defect in lar_defects if ('LAR' in defect and (('HVTRIP' in defect) or ( 'SEV' in defect) or ('CORRUPT' in defect)))) return GetBadLBFilterTool('LArBadLBFilterTool', tuple(lar_defects), origDbTag=origDbTag)
def test_virtual_defects_stress(): ddb = DefectsDB(TEST_DATABASE, read_only=False) STRESS_COUNT = 20 for i in range(STRESS_COUNT): create_defect_type(ddb, i) with ddb.storage_buffer: for i in range(STRESS_COUNT): ddb.insert("DQD_TEST_DEFECT_%i" % i, i, i + 1, "Test", "DQDefects.tests") ALL_DEFECTS = " ".join("DQD_TEST_DEFECT_%i" % i for i in range(STRESS_COUNT)) ddb.new_virtual_defect("DQD_TEST_VIRTUAL_DEFECT", "", ALL_DEFECTS) iovs = ddb.retrieve(channels=["DQD_TEST_VIRTUAL_DEFECT"]) assert len(iovs) == STRESS_COUNT - 1 assert (iovs[0].since, iovs[-1].until) == (1, STRESS_COUNT)
def main(): parser = ArgumentParser(description="Dump defect viewer information") parser.add_argument("-t", "--tag", default="HEAD", help="Defect tag") parser.add_argument("-o", "--output", default=".", help="Directory to dump files") args = parser.parse_args() # Instantiate the Defect DB db = DefectsDB(tag=args.tag) descs = db.all_defect_descriptions # Build node objects all_nodes = build_tree(db.virtual_defect_logics) # Write outputs output_dir = "%s/%s" % (args.output, args.tag) render_all_flags(output_dir, all_nodes, descs)