ATLAS Offline Software
Loading...
Searching...
No Matches
python.difftuple_text Namespace Reference

Classes

class  Reader
class  Tree
class  String
class  Hist
class  Dumpreader

Functions

 atlasProduction (ver)
 compile_list (ignore_list)
 get_ver ()
 ignore_p (match, ignore_list)
 ignore_br_p (br)
 ignore_key_p (key)
 read_val (val)
 dictkey_diff (d1, d2, msg, filter=None)
 apply_renames (d1, d2, renames)
 diff_string (k, s1, s2)
 compare (o1, o2, thresh=1e-6, ithresh=None, eltcmp=None)
 mc_eta_thresh (x)
 eg_pid_compare (o1, o2)
 compare_detElementId (o1, o2)
 compare_pixid (o1, o2)
 compare_abs (o1, o2)
 diff_branch (k, kb, v1, v2)
 diff_tree (k, t1, t2)
 diff_hist (k, h1, h2)
 diff_files (d1, d2)

Variables

bool ignore_event_differences = False
dict renames
dict rename_keys
list _ignore_branches
list _ignore_keys
list inttypes = [types.IntType, types.LongType]
list branch_thresh
 p
 d1 = Dumpreader (p.stdout)
 d2 = Dumpreader (open (sys.argv[2]))

Function Documentation

◆ apply_renames()

apply_renames ( d1,
d2,
renames )

Definition at line 1286 of file difftuple_text.py.

1286def apply_renames (d1, d2, renames):
1287 for (knew, kold) in renames.items():
1288 if (d2.has_key (kold) and not d2.has_key (knew) and
1289 not d1.has_key (kold) and d1.has_key (knew)):
1290 d2[knew] = d2[kold]
1291 del d2[kold]
1292 return
1293
1294

◆ atlasProduction()

atlasProduction ( ver)

Definition at line 34 of file difftuple_text.py.

34def atlasProduction(ver):
35 return (ver and
36 (ver.find('17.2')>=0 or
37 ver.find('17.3')>=0) and
38 #ver.find('AtlasProduction')>=0 and
39 ver.find('AtlasPhysics')==-1 and
40 ver.find('usatlas+u/snyder')==-1)
41
42
43# List of branches to ignore for various versions.
44# Format is a list of tuples: (V, V, V, [BRANCHES...])
45# We consider the strings V in turn and see if they're contained
46# in CMTPATH. If the first V is `-', then we ignore the branches
47# if there are any matches. Otherwise, we ignore the branches
48# unless there are any matches.
49# If V is callable, then instead of looking for at match in CMTPATH,
50# we call it with CMTPATH as an argument.
51# The list of branches can include glob patterns.

◆ compare()

compare ( o1,
o2,
thresh = 1e-6,
ithresh = None,
eltcmp = None )

Definition at line 1303 of file difftuple_text.py.

1303def compare (o1, o2, thresh = 1e-6, ithresh = None, eltcmp = None):
1304 if eltcmp and not isinstance(o1, list):
1305 return eltcmp (o1, o2)
1306 # Allow comparing int/long int.
1307 if type(o1) in inttypes and type(o2) in inttypes:
1308 if o1 < 0: o1 = o1 + (1<<32)
1309 if o2 < 0: o2 = o2 + (1<<32)
1310 return o1 == o2
1311 # Promote int to float if needed.
1312 if type(o1) in inttypes and isinstance(o2, float):
1313 o1 = float(o1)
1314 elif type(o2) in inttypes and isinstance(o1, float):
1315 o2 = float(o2)
1316
1317 if type(o1) is not type(o2):
1318 return False
1319 if isinstance(o1, list):
1320 if len(o1) != len(o2):
1321 return False
1322
1323 # Inline this to speed up this common case.
1324 if len(o1) > 0 and isinstance(o1[0], float) and not ithresh and not callable(thresh) and not eltcmp:
1325 xabs = abs
1326 for i in range(len(o1)):
1327 x1 = o1[i]
1328 x2 = o2[i]
1329 ax1 = xabs(x1)
1330 ax2 = xabs(x2)
1331 num = x1-x2
1332 den = ax1 + ax2
1333 if den == 0: continue
1334 x = xabs(num / den)
1335 if x > thresh:
1336 print ('fnmismatch', x1, x2, x, thresh)
1337 return False
1338 return True
1339
1340 for i in range(len(o1)):
1341 if not compare (o1[i], o2[i],
1342 thresh=thresh,
1343 ithresh=ithresh,
1344 eltcmp=eltcmp):
1345 return False
1346 return True
1347 if type(o1).__name__ in ['map<string,int>',
1348 'map<string,float>',
1349 'map<string,string>']:
1350 return ROOT.D3PDTest.MapDumper.equal (o1, o2)
1351 if isinstance(o1, float):
1352 if callable(ithresh):
1353 ret = ithresh(o1, o2)
1354 if ret is True or ret is False: return ret
1355 elif ithresh and abs(o1) < ithresh and abs(o2) < ithresh:
1356 return True
1357 num = o1-o2
1358 den = abs(o1)+abs(o2)
1359 if den == 0: return True
1360 x = abs(num / den)
1361 if callable(thresh): thresh = thresh(den)
1362 if x > thresh:
1363 print ('fmismatch', o1, o2, x, thresh)
1364 return False
1365 return True
1366 return o1 == o2
1367
1368

◆ compare_abs()

compare_abs ( o1,
o2 )

Definition at line 1396 of file difftuple_text.py.

1396def compare_abs (o1, o2):
1397 return compare (abs(o1), abs(o2))
1398
1399

◆ compare_detElementId()

compare_detElementId ( o1,
o2 )

Definition at line 1383 of file difftuple_text.py.

1383def compare_detElementId (o1, o2):
1384 if o1 == o2: return True
1385 if o1 == (o2 << 32): return True
1386 return False
1387
1388

◆ compare_pixid()

compare_pixid ( o1,
o2 )

Definition at line 1389 of file difftuple_text.py.

1389def compare_pixid (o1, o2):
1390 if o1 == o2: return True
1391 o2a = ((o2&0x7fffffff)-1)<<28
1392 if o1 == o2a : return True
1393 return False
1394
1395

◆ compile_list()

compile_list ( ignore_list)

Definition at line 1015 of file difftuple_text.py.

1015def compile_list (ignore_list):
1016 for vlist in ignore_list:
1017 l = vlist[-1]
1018 for i in range(len(l)):
1019 l[i] = re.compile (fnmatch.translate (l[i]))
1020 return
1021
1022

◆ dictkey_diff()

dictkey_diff ( d1,
d2,
msg,
filter = None )

Definition at line 1275 of file difftuple_text.py.

1275def dictkey_diff (d1, d2, msg, filter = None):
1276 keys = [k for k in d1.keys() if k not in d2]
1277 if filter: keys = [k for k in keys if not filter(k)]
1278 if keys:
1279 keys.sort()
1280 print (msg)
1281 for k in keys:
1282 print (' ', k)
1283 return
1284
1285

◆ diff_branch()

diff_branch ( k,
kb,
v1,
v2 )

Definition at line 1532 of file difftuple_text.py.

1532def diff_branch (k, kb, v1, v2):
1533 head = '%s branch %s:' % (k, kb)
1534 ev1 = v1.keys()
1535 ev2 = v2.keys()
1536 ev1.sort()
1537 ev2.sort()
1538 if ev1 != ev2:
1539 if ignore_event_differences:
1540 ev1 = list(set(ev1).intersection(set(ev2)))
1541 ev1.sort()
1542 else:
1543 print (head, 'Different set of events; new file: ',
1544 ev1, 'reference file', ev2)
1545 return
1546
1547 ithresh = None
1548 eltcmp = None
1549
1550 thresh = 1e-6
1551 for (pat, th) in branch_thresh:
1552 if pat.match (kb):
1553 if isinstance(th, tuple):
1554 thresh = th[0]
1555 ithresh = th[1]
1556 else:
1557 thresh = th
1558 break
1559
1560 # GSF reco run in d3pd job, so we have dbg/opt diffs.
1561 if kb.startswith ('el_gsf_'): thresh = 1e-4
1562 if kb == 'el_gsf_deltaeta2': thresh = 3e-3
1563 if kb == 'el_gsf_deltaphi2': thresh = 2e-1
1564 if kb == 'el_gsf_deltaphiRescaled': thresh = 2e-2
1565 if kb == 'el_gsf_deltaeta1': thresh = 3e-3
1566 if kb == 'el_gsf_trackz0pv': thresh = 1e-1
1567 if kb == 'el_gsf_covqoverp': thresh = 5e-2
1568 if kb == 'el_gsf_L2_dr': thresh = 3e-2
1569 if kb == 'el_gsf_EF_dr': thresh = 7e-2
1570 if kb == 'el_gsf_covd0theta': thresh = 3e-4
1571 if kb == 'el_gsf_electronweight': thresh = 2e-2
1572 if kb == 'el_gsf_electronbgweight': thresh = 3e-1
1573 if kb == 'el_gsf_adaboost': thresh = 7e-2
1574 if kb == 'el_gsf_neuralnet': thresh = 2e-1
1575 if kb == 'el_gsf_isolationlikelihoodhqelectrons': thresh = 4e-2
1576 if kb == 'el_gsf_jet_dr': thresh = 2e-2
1577 if kb == 'el_gsf_Et': thresh = 3e-3
1578 if kb == 'el_gsf_E': thresh = 4e-3
1579 if kb == 'sc_yCells': thresh = 2e-6
1580 if kb.startswith ('el_gsf_p'): thresh = 3e-3
1581 if kb.startswith ('el_gsf_refittedTrack_cov'): thresh = 3e-1
1582 if kb.startswith ('el_gsf_trackcov'): thresh = 5e-1
1583 if kb.startswith ('el_gsf_tracksig'): thresh = 4e-2
1584 if kb.startswith ('el_gsf_trackd0'): thresh = 6e-2
1585 if kb.startswith ('el_gsf_trackz0'): thresh = 3e-2
1586 if kb.startswith ('el_gsf_trackfitchi2'): thresh = 7e-3
1587 if kb.startswith ('el_gsf_trackqoverp'): thresh = 2e-2
1588 if kb.startswith ('el_gsf_trackpt'): thresh = 2e-2
1589 if kb.startswith ('el_gsf_refittedTrack_d0'): thresh = 3e-3
1590 if kb.startswith ('el_gsf_refittedTrack_LMqoverp'): thresh = 3e-3
1591 if kb.startswith ('el_gsf_refittedTrack_qoverp'): thresh = 2e-2
1592 if kb.startswith ('el_gsf_refittedTrack_covphitheta'): thresh = 5e-1
1593 if kb.startswith ('el_gsf_mvaptcone'): ithresh = 1e-10
1594 if kb == 'el_gsf_m':
1595 thresh = 2e-2
1596 ithresh = 0.01
1597
1598 if kb.find('jet_')>=0 and kb.endswith ('_m'): ithresh = 0.1
1599 if kb.find('jetcone_')>=0 and kb.endswith ('_m'): ithresh = 1e-3
1600 if kb.find('muonTruth_')>=0 and kb.endswith ('_m'): ithresh = 0.5
1601 if kb == 'mc_m':
1602 ithresh = 0.1
1603 thresh = 2e-5
1604 if kb.endswith ('_effTopoInvMass'): thresh = 1e-2
1605 if kb.endswith ('_topoInvMass'): thresh = 1e-2
1606 if (kb.endswith ('_topoMeanDeltaR') or
1607 kb.endswith ('_effTopoMeanDeltaR')):
1608 ithresh = 1e-6
1609 if kb.find ('_rawcl_etas') >= 0: thresh = 2e-4
1610 if kb.endswith ('_convIP'): thresh = 4e-4
1611 if kb.endswith ('_convIPRev'): thresh = 6e-5
1612 if kb.endswith ('_emscale_E'): thresh = 9e-5
1613 if kb.endswith ('_emscale_eta'): thresh = 9e-5
1614 if kb.endswith ('_emscale_m'): ithresh = 0.1
1615 if kb.endswith ('_constscale_E'): thresh = 9e-5
1616 if kb.endswith ('_constscale_eta'): thresh = 9e-5
1617 if kb == 'mc_eta': thresh = mc_eta_thresh
1618 if kb.endswith ('_seg_locX'): ithresh = 2e-12
1619 if kb.endswith ('_seg_locY'): ithresh = 2e-12
1620 if kb == 'MET_Goodness_DeltaEt_JetAlgs_Jet': ithresh = 3e-11
1621 if kb == 'MET_Goodness_EEM_Jet': thresh = 2e-5
1622 if kb == 'MET_Goodness_HECf_Jet': thresh = 3e-6
1623 if kb.find ('_blayerPrediction') >= 0: thresh = 1e-2
1624 if kb.endswith ('_hecf'): thresh = 4e-6
1625 if kb.endswith ('_SpaceTime_t'): thresh = 4e-6
1626 if kb.endswith ('_SpaceTime_weight'): thresh = 2e-5
1627 if kb.endswith ('_SpaceTime_tError'): thresh = 8e-6
1628 if kb.endswith ('_calcVars_ChPiEMEOverCaloEME'): thresh = 1e-5
1629 if kb.endswith ('_vx_m'): ithresh = 1e-2
1630 if kb.endswith ('MET_Goodness_DeltaEt_JetAlgs_Jet'): ithresh = 1e-10
1631
1632 # Diffs btn 32/64-bit
1633 if kb == 'mc_perigee_theta': thresh = 1
1634 if kb == 'mc_perigee_d0': thresh = 1
1635 if kb == 'mc_perigee_phi': thresh = 1 #(ev 2,9)
1636 if kb == 'mc_perigee_z0': thresh = 1
1637 if kb == 'tau_likelihood': thresh = 1e-5
1638 if kb == 'tau_SafeLikelihood': thresh = 1e-5
1639 if kb == 'el_gsf_softeweight': thresh = 1e-1
1640 if kb == 'el_gsf_softebgweight': thresh = 2e-2
1641
1642 if kb.endswith ('_mvaptcone20'): ithresh = 1e-10
1643 if kb.endswith ('_mvaptcone30'): ithresh = 1e-10
1644 if kb.endswith ('_mvaptcone40'): ithresh = 1e-10
1645
1646 # more 32/64 dbg/opt diffs
1647 if kb == 'tau_SafeLikelihood': thresh = 0.4
1648 if kb == 'tau_likelihood': thresh = 0.4
1649 if kb == 'tau_BDTJetScore': thresh = 1.0
1650 if kb == 'tau_calcVars_corrFTrk': thresh = 0.02
1651 if kb == 'tau_calcVars_corrCentFrac': thresh = 0.4
1652 if kb == 'tau_JetBDTSigLoose': thresh = 1.0
1653 if kb == 'tau_JetBDTSigMedium': thresh = 1.0
1654 if kb == 'tau_JetBDTSigTight': thresh = 1.0
1655 if kb == 'tau_tauLlhMedium': thresh = 1.0
1656 if kb == 'tau_pi0_cl1_pt': thresh = 1e-5
1657
1658 if kb.endswith ('_neighbourSig'): thresh = 1e-4
1659 if kb.endswith ('_curvatureSig'): thresh = 1e-4
1660
1661 if kb == 'pixClus_detElementId': eltcmp = compare_detElementId
1662 if kb == 'pixClus_id': eltcmp = compare_pixid
1663 if kb == 'trig_EF_emcl_pt': eltcmp = compare_abs
1664
1665 for e in ev1:
1666 head = '%s branch %s event %d:' % (k, kb, e)
1667 b1 = v1[e]
1668 b2 = v2[e]
1669
1670 # Promote int to float if needed.
1671 if type(b1) in inttypes and isinstance(b2, float):
1672 b1 = float(b1)
1673 elif type(b2) in inttypes and isinstance(b1, float):
1674 b2 = float(b2)
1675
1676 if type(b1) is not type(b2):
1677 print (head, 'Type differs; new file: ', type(b1).__name__,
1678 'reference file:', type(b2).__name__)
1679 elif not compare (b1, b2, thresh = thresh, ithresh = ithresh,
1680 eltcmp = eltcmp):
1681 print (head, 'Branch mismatch')
1682 print (' new file:', b1)
1683 print (' ref file:', b2)
1684
1685 return
1686
STL class.
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)

◆ diff_files()

diff_files ( d1,
d2 )

Definition at line 1713 of file difftuple_text.py.

1713def diff_files (d1, d2):
1714 apply_renames (d1.keys, d2.keys, rename_keys)
1715 dictkey_diff (d1.keys, d2.keys, 'Keys only in new file:',
1716 ignore_key_p)
1717 dictkey_diff (d2.keys, d1.keys, 'Keys only in reference file:',
1718 ignore_key_p)
1719 for k in d1.keys.keys():
1720 if k in d2.keys and not ignore_key_p (k):
1721 v1 = d1.keys[k]
1722 v2 = d2.keys[k]
1723 if type(v1) is not type(v2):
1724 print ('Key', k, 'has type', type(v1).__name__,
1725 'in new file, but type', type(v2).__name__,
1726 'in reference file')
1727 elif type(v1) is String:
1728 diff_string (k, v1, v2)
1729 elif type(v1) is Tree:
1730 diff_tree (k, v1, v2)
1731 elif type(v1) is Hist:
1732 diff_hist (k, v1, v2)
1733 else:
1734 print ('Unknown type for diff:', type(v1).__name__)
1735 return
1736
1737

◆ diff_hist()

diff_hist ( k,
h1,
h2 )

Definition at line 1701 of file difftuple_text.py.

1701def diff_hist (k, h1, h2):
1702 if not compare (h1.bins, h2.bins):
1703 print ('Hist', k, 'has bins', h1.bins)
1704 print ('in new file but bins', h2.bins)
1705 print ('in reference file')
1706 if not compare (h1.errs, h2.errs):
1707 print ('Hist', k, 'has errs', h1.errs)
1708 print ('in new file but errs', h2.errs)
1709 print ('in reference file')
1710 return
1711
1712

◆ diff_string()

diff_string ( k,
s1,
s2 )

Definition at line 1295 of file difftuple_text.py.

1295def diff_string (k, s1, s2):
1296 if s1.val != s2.val:
1297 print ('String', k, 'has value', s1.val,
1298 'in new file but value', s2.val, 'in reference file')
1299 return
1300
1301

◆ diff_tree()

diff_tree ( k,
t1,
t2 )

Definition at line 1687 of file difftuple_text.py.

1687def diff_tree (k, t1, t2):
1688 if t1.dummy and t2.dummy: return
1689 apply_renames (t1.branches, t2.branches, renames)
1690 dictkey_diff (t1.branches, t2.branches, '%s: Branches only in new file:'%k,
1691 ignore_br_p)
1692 dictkey_diff (t2.branches, t1.branches, '%s: Branches only in reference file:'%k,
1693 ignore_br_p)
1694 for kb in t1.branches:
1695 if t2.branches.has_key (kb):
1696 if not ignore_br_p(kb):
1697 diff_branch (k, kb, t1.branches[kb], t2.branches[kb])
1698 return
1699
1700

◆ eg_pid_compare()

eg_pid_compare ( o1,
o2 )

Definition at line 1378 of file difftuple_text.py.

1378def eg_pid_compare (o1, o2):
1379 if o1 == 0xffffffff and o2 == 0: return True
1380 return None
1381
1382

◆ get_ver()

get_ver ( )

Definition at line 1027 of file difftuple_text.py.

1027def get_ver():
1028 ver = os.environ.get ('CMTPATH')
1029 if ver:
1030 ver = string.split (ver, ':')
1031 ver = [s for s in ver if s.find('AtlasSetup') < 0]
1032 ver.append (os.environ.get ('CMTCONFIG'))
1033 ver = string.join (ver, ':')
1034 else:
1035 ver = 'localbuild'
1036 return ver
1037
1038

◆ ignore_br_p()

ignore_br_p ( br)

Definition at line 1061 of file difftuple_text.py.

1061def ignore_br_p (br):
1062 return ignore_p (br, _ignore_branches)
1063
1064

◆ ignore_key_p()

ignore_key_p ( key)

Definition at line 1065 of file difftuple_text.py.

1065def ignore_key_p (key):
1066 return ignore_p (key, _ignore_keys)
1067
1068

◆ ignore_p()

ignore_p ( match,
ignore_list )

Definition at line 1039 of file difftuple_text.py.

1039def ignore_p (match, ignore_list):
1040 ver = get_ver()
1041
1042 for vlist in ignore_list:
1043 vv = vlist[:-1]
1044 ignore = True
1045 if vv and vv[0] == '-':
1046 ignore = False
1047 vv = vv[1:]
1048 for v in vv:
1049 if (callable(v) and v(ver) or
1050 not callable(v) and ver and ver.find (v) >= 0):
1051 ignore = not ignore
1052 break
1053 if not ignore: continue
1054 for b in vlist[-1]:
1055 if b.match (match):
1056 return True
1057 return False
1058
1059
1060# Should a branch be ignored?

◆ mc_eta_thresh()

mc_eta_thresh ( x)

Definition at line 1369 of file difftuple_text.py.

1369def mc_eta_thresh (x):
1370 if x > 36: return 1e-2
1371 if x > 34: return 2e-3
1372 if x > 32: return 2e-4
1373 if x > 30: return 1e-4
1374 if x > 28: return 1e-5
1375 return 1e-6
1376
1377

◆ read_val()

read_val ( val)

Definition at line 1069 of file difftuple_text.py.

1069def read_val (val):
1070 if not val: return val
1071
1072 if val.find ('+') >= 0:
1073 psplit = split_list1 (val, '+')
1074 if len(psplit) > 1:
1075 #psplit = split_list1 (val, '+')
1076 #if len(psplit) > 1:
1077 good = True
1078 for i in range(len(psplit)):
1079 psplit[i] = read_val (psplit[i])
1080 if not isinstance(psplit[i], list):
1081 good = False
1082 break
1083 if good:
1084 return reduce (operator.__add__, psplit)
1085
1086 if val[-1] == 'L':
1087 try:
1088 return int(val)
1089 except TypeError:
1090 pass
1091
1092 if val[0] in '0123456789-':
1093 if val.find ('.') < 0:
1094 try:
1095 return int(val)
1096 except TypeError:
1097 pass
1098 except ValueError:
1099 pass
1100
1101 try:
1102 return float (val)
1103 except TypeError:
1104 pass
1105 except ValueError:
1106 pass
1107
1108 try:
1109 (count, elt) = val.split ('*', 1)
1110 count = int (count)
1111 if elt.startswith('[') and elt.endswith(']'):
1112 return count * [read_val(elt[1:-1])]
1113 except ValueError:
1114 pass
1115
1116 if val[0] == '[':
1117 return [read_val(s) for s in split_list(val)]
1118 return val
1119
1120

Variable Documentation

◆ _ignore_branches

list python.difftuple_text._ignore_branches
protected

Definition at line 52 of file difftuple_text.py.

◆ _ignore_keys

list python.difftuple_text._ignore_keys
protected

Definition at line 934 of file difftuple_text.py.

◆ branch_thresh

list python.difftuple_text.branch_thresh

Definition at line 1400 of file difftuple_text.py.

◆ d1

python.difftuple_text.d1 = Dumpreader (p.stdout)

Definition at line 1751 of file difftuple_text.py.

◆ d2

python.difftuple_text.d2 = Dumpreader (open (sys.argv[2]))

Definition at line 1753 of file difftuple_text.py.

◆ ignore_event_differences

bool ignore_event_differences = False

Definition at line 20 of file difftuple_text.py.

◆ inttypes

list python.difftuple_text.inttypes = [types.IntType, types.LongType]

Definition at line 1302 of file difftuple_text.py.

◆ p

python.difftuple_text.p
Initial value:
= subprocess.Popen ('python -m D3PDMakerTest.dumptuple_any %s' %
sys.argv[1],
shell = True,
stdout = subprocess.PIPE)

Definition at line 1747 of file difftuple_text.py.

◆ rename_keys

dict python.difftuple_text.rename_keys
Initial value:
= {
# Hack for ordering difference when scell tuple is on.
'caloMeta/EventInfoD3PDObject_000005' : 'caloMeta/EventInfoD3PDObject_000004',
'physicsMeta/EventInfoD3PDObject_000003' : 'physicsMeta/EventInfoD3PDObject_000002',
'physicsTrigDecMeta/EventInfoD3PDObject_000004' : 'physicsTrigDecMeta/EventInfoD3PDObject_000003',
}

Definition at line 27 of file difftuple_text.py.

◆ renames

dict python.difftuple_text.renames
Initial value:
= {
}

Definition at line 24 of file difftuple_text.py.