ATLAS Offline Software
Loading...
Searching...
No Matches
test_CA.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3import AthenaCommon.SystemOfUnits as Units
4from AthenaConfiguration.AllConfigFlags import initConfigFlags
5from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6from AthenaConfiguration.ComponentFactory import CompFactory
7from AthenaConfiguration.MainServicesConfig import MainServicesCfg
8from AthenaPython.tests.PyTestsLib import MyAlg, MySvc, MyTool
9
10import unittest
11
12class Test( unittest.TestCase ):
13 def test_basic(self):
14 flags = initConfigFlags()
15 flags.lock()
16
17 cfg = MainServicesCfg(flags)
18 cfg.addSequence(CompFactory.AthSequencer("MySeq"))
19
20 cfg.addEventAlgo( MyAlg("MyAlg1", eta = 2.5, pt = 42.),
21 sequenceName = "MySeq" )
22
23 cfg.addEventAlgo( MyAlg("MyAlg2", eta = 5.1, pt = 20.*Units.GeV, filterPassed = False),
24 sequenceName = "MySeq" )
25
26 # alg3 should never be executed due to filterPassed of alg2
27 cfg.addEventAlgo( MyAlg("MyAlg3", eta = 4.9, pt = 15.*Units.GeV,
28 mytool = MyTool("MyTool", counter = 50, parent="MyAlg3")),
29 sequenceName = "MySeq" )
30
31 cfg.addService( MySvc(), create=True )
32
33 with open('test_CA.pkl','wb') as f:
34 cfg.store(f)
35 sc = cfg.run(2)
36 self.assertFalse(sc.isFailure())
37
38 def test_merge(self):
39 cfg1 = ComponentAccumulator()
40 cfg2 = ComponentAccumulator()
41 cfg1.addEventAlgo( MyAlg(name='Alg1', px=1) )
42 cfg2.addEventAlgo( MyAlg(name='Alg2', px=2) )
43 cfg1.merge(cfg2)
44 cfg1.wasMerged()
45
46 def test_merge_fail(self):
47 cfg1 = ComponentAccumulator()
48 cfg2 = ComponentAccumulator()
49 cfg1.addEventAlgo( MyAlg(px=1) )
50 cfg2.addEventAlgo( MyAlg(px=2) )
51 with self.assertRaises(ValueError):
52 cfg1.merge(cfg2)
53
54
55if __name__ == "__main__":
56 unittest.main()