Exemplo n.º 1
0
def test_tree_Inputs_propagated():

    sel00 = AutomaticData(Location='Phys/Sel00/Particles')
    sel01 = AutomaticData(Location='Phys/Sel01/Particles')
    alg0 = MockConfGenerator(Inputs=[])
    sel0 = Selection('Sel001',
                     Algorithm=alg0,
                     RequiredSelections=[sel00, sel01])
    assert len(alg0.Inputs) == 0
    assert len(sel0.algorithm().Inputs) == 2
    assert sel0.algorithm().Inputs.count('Phys/Sel00/Particles') == 1
    assert sel0.algorithm().Inputs.count('Phys/Sel01/Particles') == 1
def test_sequencer_sequence():
    _sel00 = AutomaticData(Location='Phys/Sel00')
    _sel01 = AutomaticData(Location='Phys/Sel01')
    _sel02 = AutomaticData(Location='Phys/Sel02')
    _sel03 = AutomaticData(Location='Phys/Sel03')

    sel01 = Selection('000110',
                      Algorithm=MockConfGenerator(),
                      RequiredSelections=[_sel00, _sel01])
    sel02 = Selection('000111',
                      Algorithm=MockConfGenerator(),
                      RequiredSelections=[_sel02, _sel03])
    sel03 = Selection('000112',
                      Algorithm=MockConfGenerator(),
                      RequiredSelections=[sel01, sel02])

    presel0 = MockConfGenerator()
    presel1 = MockConfGenerator()
    postsel0 = MockConfGenerator()
    postsel1 = MockConfGenerator()

    presels = [presel0, presel1]
    postsels = [postsel0, postsel1]
    seq = SelectionSequence('Seq0002',
                            TopSelection=sel03,
                            EventPreSelector=presels,
                            PostSelectionAlgs=postsels,
                            sequencerType=DummySequencer)

    seqAlgos = seq.sequence().Members

    ref_algos = [
        presel0, presel1,
        _sel00.algorithm(),
        _sel01.algorithm(),
        _sel02.algorithm(),
        _sel03.algorithm(),
        sel02.algorithm(),
        sel01.algorithm(),
        sel03.algorithm(), postsel0, postsel1
    ]

    assert len(seqAlgos) == 11

    assert presels == ref_algos[:len(presels)]

    assert postsels == ref_algos[len(ref_algos) - len(postsels):]

    for sel in [sel01, sel02, sel03]:
        assert sel.algorithm() in ref_algos[len(presels):len(ref_algos) -
                                            len(postsels)]
Exemplo n.º 3
0
def test_clone_selection_with_existing_selection_name_raises():

    sel02 = AutomaticData(Location='Phys/Sel02')
    sel03 = AutomaticData(Location='Phys/Sel03')
    alg0 = MockConfGenerator()
    sel0 = Selection('Sel004',
                     Algorithm=alg0,
                     RequiredSelections=[sel02, sel03])

    raises(NameError,
           sel0.clone,
           name='Sel004',
           Algorithm=alg0,
           RequiredSelections=[sel02, sel03])
    assert sel0.algorithm().Inputs == ['Phys/Sel02', 'Phys/Sel03']
Exemplo n.º 4
0
def test_selection_with_existing_selection_name_raises():

    sel02 = AutomaticData(Location='Phys/Sel02/Particles')
    sel03 = AutomaticData(Location='Phys/Sel03/Particles')
    alg0 = MockConfGenerator()

    sel0 = Selection('Sel003',
                     Algorithm=alg0,
                     RequiredSelections=[sel02, sel03])
    raises(NameError,
           Selection,
           'Sel003',
           Algorithm=alg0,
           RequiredSelections=[sel02, sel03])

    assert sel0.algorithm().Inputs == [
        'Phys/Sel02/Particles', 'Phys/Sel03/Particles'
    ]
def test_clone_sequence():
    _sel00 = AutomaticData(Location='Phys/Sel00')
    _sel01 = AutomaticData(Location='Phys/Sel01')
    _sel02 = AutomaticData(Location='Phys/Sel02')
    _sel03 = AutomaticData(Location='Phys/Sel03')

    sel01 = Selection('00120',
                      Algorithm=MockConfGenerator(),
                      RequiredSelections=[_sel00, _sel01])
    sel02 = Selection('00121',
                      Algorithm=MockConfGenerator(),
                      RequiredSelections=[_sel02, _sel03])
    sel03 = Selection('00122',
                      Algorithm=MockConfGenerator(),
                      RequiredSelections=[sel01, sel02])

    presel0 = MockConfGenerator()
    presel1 = MockConfGenerator()
    postsel0 = MockConfGenerator()
    postsel1 = MockConfGenerator()

    presels = [presel0, presel1]
    postsels = [postsel0, postsel1]

    seq = SelectionSequence('Seq03',
                            TopSelection=sel03,
                            EventPreSelector=presels,
                            PostSelectionAlgs=postsels,
                            sequencerType=DummySequencer)

    clone = seq.clone(name='clone')

    seqAlgos = clone.sequence().Members

    ref_algos = [
        presel0, presel1,
        _sel00.algorithm(),
        _sel01.algorithm(),
        _sel02.algorithm(),
        _sel03.algorithm(),
        sel02.algorithm(),
        sel01.algorithm(),
        sel03.algorithm(), postsel0, postsel1
    ]

    assert len(seqAlgos) == len(ref_algos)
    assert presels == seqAlgos[:len(presels)]
    assert postsels == seqAlgos[len(ref_algos) - len(postsels):]
    # sel03 must come just before the post selection algos.
    assert sel03.algorithm() == ref_algos[len(ref_algos) - (len(presels) + 1)]
    # order of sel01 and sel02 doesn't matter.
    for sel in [sel01, sel02]:
        assert sel.algorithm() in ref_algos[len(presels):len(ref_algos) -
                                            len(postsels)]

    seqAlgos = seq.algorithms()

    assert len(seqAlgos) == len(ref_algos)
    assert presels == seqAlgos[:len(presels)]
    assert postsels == seqAlgos[len(ref_algos) - len(postsels):]

    for sel in [sel01, sel02, sel03]:
        assert sel.algorithm() in ref_algos[len(presels):len(ref_algos) -
                                            len(postsels)]
Exemplo n.º 6
0
def test_multi_sequencer_sequences():
    _sel00 = AutomaticData(Location='Phys/Sel00')
    _sel01 = AutomaticData(Location='Phys/Sel01')
    _sel02 = AutomaticData(Location='Phys/Sel02')
    _sel03 = AutomaticData(Location='Phys/Sel03')

    sel00_01 = Selection('0000110',
                         Algorithm=MockConfGenerator(),
                         RequiredSelections=[_sel00, _sel01])
    sel02_03 = Selection('0000111',
                         Algorithm=MockConfGenerator(),
                         RequiredSelections=[_sel02, _sel03])
    selA = Selection('000112A',
                     Algorithm=MockConfGenerator(),
                     RequiredSelections=[sel00_01, sel02_03])

    _sel04 = AutomaticData(Location='Phys/Sel04')
    _sel05 = AutomaticData(Location='Phys/Sel05')
    _sel06 = AutomaticData(Location='Phys/Sel06')
    _sel07 = AutomaticData(Location='Phys/Sel07')
    sel04_05 = Selection('0000112',
                         Algorithm=MockConfGenerator(),
                         RequiredSelections=[_sel04, _sel05])
    sel06_07 = Selection('0000113',
                         Algorithm=MockConfGenerator(),
                         RequiredSelections=[_sel06, _sel07])
    selB = Selection('000112B',
                     Algorithm=MockConfGenerator(),
                     RequiredSelections=[sel04_05, sel06_07])

    presel0 = MockConfGenerator()
    presel1 = MockConfGenerator()
    presel2 = MockConfGenerator()
    presel3 = MockConfGenerator()

    postsel0 = MockConfGenerator()
    postsel1 = MockConfGenerator()
    postsel2 = MockConfGenerator()
    postsel3 = MockConfGenerator()

    preselsA = [presel0, presel1]
    postselsA = [postsel0, postsel1]
    preselsB = [presel2, presel3]
    postselsB = [postsel2, postsel3]

    seqA = SelectionSequence('Seq0002A',
                             TopSelection=selA,
                             EventPreSelector=preselsA,
                             PostSelectionAlgs=postselsA)
    seqB = SelectionSequence('Seq0002B',
                             TopSelection=selB,
                             EventPreSelector=preselsB,
                             PostSelectionAlgs=postselsB)

    multiSeq = MultiSelectionSequence('MultiSeqAB',
                                      Sequences=[seqA, seqB],
                                      sequencerType=DummySequencer)

    assert multiSeq.outputLocations() == [
        selA.outputLocation(), selB.outputLocation()
    ]

    print 'algos in seqA', len(seqA.algorithms())
    print 'algos in seqB', len(seqB.algorithms())

    seqAlgos = multiSeq.sequence().Members
    seqAlgosA = seqAlgos[0].Members
    seqAlgosB = seqAlgos[1].Members
    assert len(seqAlgos) == len(multiSeq._sequences)
    assert len(multiSeq.algorithms()) == len(seqAlgosA) + len(seqAlgosB)

    ref_algosA = [
        presel0, presel1,
        _sel00.algorithm(),
        _sel01.algorithm(),
        _sel02.algorithm(),
        _sel03.algorithm(),
        sel02_03.algorithm(),
        sel00_01.algorithm(),
        selA.algorithm(), postsel0, postsel1
    ]

    ref_algosB = [
        presel2, presel3,
        _sel04.algorithm(),
        _sel05.algorithm(),
        _sel06.algorithm(),
        _sel07.algorithm(),
        sel06_07.algorithm(),
        sel04_05.algorithm(),
        selB.algorithm(), postsel2, postsel3
    ]

    assert len(seqAlgos) == 2

    assert preselsA == seqAlgosA[:len(preselsA)]
    assert preselsB == seqAlgosB[:len(preselsB)]
    # selA must be just before postsels
    assert selA.algorithm() == ref_algosA[len(ref_algosA) -
                                          (len(postselsA) + 1)]
    assert postselsA == seqAlgosA[len(ref_algosA) - len(postselsA):]
    assert postselsB == seqAlgosB[len(ref_algosB) - len(postselsB):]
    # selB must be just before postsels
    assert selB.algorithm() == ref_algosB[len(ref_algosB) -
                                          (len(postselsB) + 1)]

    # order doesn't matter
    for sel in [sel04_05, sel06_07]:
        assert sel.algorithm() in ref_algosB[len(preselsB):len(ref_algosB) -
                                             len(postselsB)]
    for sel in [sel00_01, sel02_03]:
        assert sel.algorithm() in ref_algosA[len(preselsA):len(ref_algosA) -
                                             len(postselsA)]