コード例 #1
0
def test_2nd_order_lookup():
    'Seen in the wild to generate an out-of-scope error'
    r = (cms_aod_dataset().Select(
        lambda e: {
            "m": e.Muons("muons"),
            "p": e.Vertex("offlinePrimaryVertices")[0].position()
        }).Select(
            lambda i: i.m.Where(lambda m: m.isPFMuon(
            ) and m.isPFIsolationValid() and isNonnull(m.globalTrack(
            )) and abs((m.globalTrack()).dxy(i.p)) < 0.5 and abs(
                (m.globalTrack()).dz(i.p)) < 1.).Select(lambda m: m.p()),
        ).value())

    lines = get_lines_of_code(r)
    print_lines(lines)

    # Make sure the vertex line isn't used after it goes out of scope
    vertex_decl_line = find_line_with('edm::Handle<reco::VertexCollection>',
                                      lines)

    vertex_variable_name = lines[vertex_decl_line].split(' ')[-1].strip(';')

    closing_scope = find_next_closing_bracket(lines[vertex_decl_line:])
    vertex_used_too_late = find_line_with(vertex_variable_name,
                                          lines[vertex_decl_line +
                                                closing_scope:],
                                          throw_if_not_found=False)
    if vertex_used_too_late != -1:
        print('Here is where it is used and down')
        print_lines(lines[closing_scope + vertex_decl_line +
                          vertex_used_too_late:])
    assert vertex_used_too_late == -1
コード例 #2
0
def test_Select_member_variable():
    r = cms_aod_dataset() \
        .SelectMany(lambda e: e.Muons("muons")) \
        .Select(lambda m: m.pfIsolationR04().sumChargedHadronPt) \
        .value()
    lines = get_lines_of_code(r)
    _ = find_line_with(".sumChargedHadronPt", lines)
    assert find_line_with(".sumChargedHadronPt()",
                          lines,
                          throw_if_not_found=False) == -1
コード例 #3
0
def test_complex_dict():
    'Seen to fail in the wild, so a test case to track'
    r = cms_aod_dataset() \
        .Select(lambda e: {"muons": e.Muons("muons"), "primvtx": e.Vertex("offlinePrimaryVertices")}) \
        .Select(lambda i: i.muons
                .Where(lambda m: isNonnull(m.globalTrack()))
                .Select(lambda m: m.globalTrack().dx(i.primvtx[0].position()))
                ) \
        .value()
    lines = get_lines_of_code(r)
    print_lines(lines)

    find_line_with("globalTrack()->dx", lines)
    find_line_with("at(0).position()", lines)
コード例 #4
0
def test_metadata_collection_bad_experiment():
    'This is integration testing - making sure the dict to root conversion works'
    with pytest.raises(ValueError) as e:
        (cms_aod_dataset().MetaData({
            'metadata_type':
            'add_atlas_event_collection_info',
            'name':
            'ForkInfo',
            'include_files': ['xAODEventInfo/EventInfo.h'],
            'container_type':
            'xAOD::EventInfo',
            'contains_collection':
            False,
        }).Select(lambda e: e.ForkInfo("EventInfo").runNumber()).Select(
            lambda e: {
                'run_number': e
            }).value())

    assert "backend; only" in str(e.value)
コード例 #5
0
def test_metadata_collection():
    'This is integration testing - making sure the dict to root conversion works'
    r = (cms_aod_dataset().MetaData({
        'metadata_type':
        'add_cms_event_collection_info',
        'name':
        'ForkVertex',
        'include_files': ['DataFormats/VertexReco/interface/Vertex.h'],
        'container_type':
        'reco::VertexCollection',
        'contains_collection':
        True,
        'element_type':
        'reco::Vertex',
        'element_pointer':
        False,
    }).Select(lambda e: e.ForkVertex("EventInfo").Count()).Select(
        lambda e: {
            'run_number': e
        }).value())
    vs = r.QueryVisitor._gc._class_vars
    assert 1 == len(vs)
    assert "int" == str(vs[0].cpp_type())
コード例 #6
0
def test_isnonnull_call():
    r = cms_aod_dataset().Select(lambda e: isNonnull(e)).value()
    vs = r.QueryVisitor._gc._class_vars
    assert 1 == len(vs)
    assert "bool" == str(vs[0].cpp_type())