41 def addAlgorithm(self, algClassOrObj, name = None, addFilterTools = [], addToSubSequence=True, *args, **kwargs):
42 '''
43 Instantiate/add a monitoring algorithm
44
45 Arguments:
46 algClassOrObj -- the Configurable class object of the algorithm to create, or an instance
47 of the algorithm Configurable. The former is recommended. In the former case,
48 the name argument is required.
49 name -- the name of the algorithm to create. Required when passing a Configurable class object
50 as algClassOrObj. No effect if a Configurable instance is passed.
51 addToSubSequence -- if the algorithm should be added to a subsequence in the component accumulator,
52 or just to the top level sequence.
53 *args, **kwargs -- additional arguments will be forwarded to the Configurable constructor if
54 a Configurable class object is passed. No effect if a Configurable instance
55 is passed.
56
57 Returns:
58 algObj -- an algorithm Configurable object
59 '''
60 from inspect import isclass
61 if isclass(algClassOrObj):
62 if name is None:
63 raise TypeError('addAlgorithm with a class argument requires a name for the algorithm')
64 algObj = algClassOrObj(name, *args, **kwargs)
65 else:
66 algObj = algClassOrObj
67
68
69 algObj.Environment = self.flags.DQ.Environment
70 algObj.DataType = self.flags.DQ.DataType.value
71 if self.flags.DQ.useTrigger:
72 algObj.TrigDecisionTool = self.resobj.getPublicTool("TrigDecisionTool")
73
74 if self.flags.DQ.enableLumiAccess:
75 algObj.EnableLumi = True
76 from LumiBlockComps.LuminosityCondAlgConfig import LuminosityCondAlgCfg
77 self.resobj.merge (LuminosityCondAlgCfg (self.flags))
78 if not self.flags.Input.isMC:
79 from LumiBlockComps.LBDurationCondAlgConfig import LBDurationCondAlgCfg
80 from LumiBlockComps.TrigLiveFractionCondAlgConfig import TrigLiveFractionCondAlgCfg
81 self.resobj.merge (LBDurationCondAlgCfg (self.flags))
82 self.resobj.merge (TrigLiveFractionCondAlgCfg (self.flags))
83 else:
84 algObj.EnableLumi = False
85
86
87 for obj in addFilterTools:
88
89 if isinstance(obj, ComponentAccumulator):
90 filter = self.resobj.popToolsAndMerge(obj)
91 elif hasattr(obj, 'getGaudiType') and obj.getGaudiType() == 'AlgTool':
92 filter = obj
93 else:
94 raise ValueError(f'Object {obj} passed to addFilterTools is not a ComponentAccumulator or an AlgTool')
95 algObj.FilterTools += [filter]
96
97 if addToSubSequence:
98 if self.resobj.getSequence(self.monSeq.name) is None:
99 self.resobj.addSequence(self.monSeq)
100 self.resobj.addEventAlgo(algObj, sequenceName=self.monSeq.name)
101 else:
102 self.resobj.addEventAlgo(algObj)
103 return algObj
104