ATLAS Offline Software
test_CA.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 import AthenaCommon.SystemOfUnits as Units
4 from AthenaConfiguration.AllConfigFlags import initConfigFlags
5 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6 from AthenaConfiguration.ComponentFactory import CompFactory
7 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
8 from AthenaPython.tests.PyTestsLib import MyAlg, MySvc, MyTool
9 
10 import unittest
11 
12 class 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 
45  def test_merge_fail(self):
46  cfg1 = ComponentAccumulator()
47  cfg2 = ComponentAccumulator()
48  cfg1.addEventAlgo( MyAlg(px=1) )
49  cfg2.addEventAlgo( MyAlg(px=2) )
50  with self.assertRaises(ValueError):
51  cfg1.merge(cfg2)
52 
53 
54 if __name__ == "__main__":
55  unittest.main()
python.tests.test_CA.Test.test_merge
def test_merge(self)
Definition: test_CA.py:38
SystemOfUnits
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.tests.test_CA.Test.test_basic
def test_basic(self)
Definition: test_CA.py:13
python.tests.test_CA.Test.test_merge_fail
def test_merge_fail(self)
Definition: test_CA.py:45
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:259
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.tests.test_CA.Test
Definition: test_CA.py:12