7 This module defines various components to be used in AnalysisBase releases.
8 These components (classes, submodules...) can be used in place of some Athena components
9 they are replacing, so athena-style configuration can be used unchanged in AnalysisBase
11 This module is thus designed ONLY for AnalysisBase and to run EventLoop jobs.
13 IMPORTANT : this module is only designed so the jet configuration works. There's no guarantee it won't mess up
14 when used with other part of Athena configuration.
16 Internally, the athena-style configurations of algorithms are translated to AnaReentrantAlgorithmConfig or
17 AnaAlgorithmConfig. The configuration of AsgTools are translated to call to AnaAlgorithmConfig.addPrivateTool()
18 or AnaAlgorithmConfig.setPropertyFromString()
20 This module allows to write python config for EventLoop exactly as one would do for Athena :
22 alg1 = CompFactory.MyAlg("algname",
23 InputContainer = "SomeJets".
25 AprivateTool = CompFactory.SomeTool("tool", AToolparam =0.21), )
26 alg2 = CompFactory.AnOtherAlg( ... )
30 job.addManyAlgs([alg1, alg2]) # specific call allowed by this module
32 driver = ROOT.EL.DirectDriver()
33 driver.submit( job, "out")
38 from types
import ModuleType
45 logging.setLoggerClass( logging.Logger )
51 """Helper function producing a string property value"""
53 stringValue =
str( value )
54 if isinstance( value, bool ):
55 stringValue =
str(
int( value ) )
60 """A simplistic array of Configured (see below) to replace the ToolHandleArray of Athena """
82 actualName = anaAlg.createPrivateToolInArray(conf.fullname(), conf.type)
83 conf._name = actualName.split(
'.')[-1]
84 conf.assignAllProperties(anaAlg)
88 """A replacement for Athena auto-generated Configured python class.
89 Configured has the same interface as its Athena counterpart and can describe both Tools and Algorithms
91 This is a base class. The system replacing CompFactory will generate a derived class for each c++ Tool/Algorithm
92 to hold the configuration of such tool/alg (see generateConfigured())
99 _allowed = [
'_properties',
'_name',
'_parent',
'_anaAlg']
104 for k,v
in props.items():
111 raise AttributeError(
"Configuration of Tool {} / {} . can't set attribute : {}".
format(self.type, self.
_name, k) )
119 if isinstance(v, Configured):
121 raise RuntimeError(
"Configuring {} / {} : Tool for property {} already exists".
format(self.type, self.
_name, k) )
125 elif isinstance(v, (list, tuple) ):
126 if isinstance(v[0], Configured):
141 if self.
_parent is None:
return k
145 if self.
_parent is None :
return [self]
150 return '.'.
join([p._name
for p
in parents])
153 return [ (k, getattr(self,k))
for k
in self.
_properties]
156 return self.type+
'/'+self.
_name
159 if issubclass(self._cppclass, ROOT.EL.AnaReentrantAlgorithm):
160 alg=ROOT.EL.AnaReentrantAlgorithmConfig()
162 alg=ROOT.EL.AnaAlgorithmConfig()
175 if isinstance(v , Configured):
177 alg.createPrivateTool(v.fullname(), v.type)
178 v.assignAllProperties(alg)
179 elif isinstance(v, ConfArray ):
181 v.assignAllProperties(alg)
193 if issubclass(cppclass, cppyy.gbl.asg.IAsgTool):
194 dummy = cppclass(
'dummy')
196 dummy = cppclass(
'dummy', 0)
199 allowedProp = Configured._allowed + [k
for k,v
in dummy.getPropertyMgr().getProperties() ]
201 klass=
type(classname+
'Conf', (Configured,), dict(_allowed=allowedProp,
202 type=prefix+classname,_cppclass=cppclass) )
207 """A namespace able to automatically generate Configured when quering attributes :
208 Used to replace CompFactory so that expressions like :
209 tool = CompFactory.Trk.SomeTrkTool("tname", Prop=2.345)
210 tool = CompFactory.getComp("Trk::SomeTrkTool")("tname", Prop=2.345)
212 In the above 2 examples both CompFactory and Trk are ConfNameSpace
215 self.
prefix=name+
"::" if name !=
"" else ""
221 """generates a new Configured class for the C++ class ROOT.classname .
222 This implies there must be a dictionnary for classname.
226 c = self.__dict__.
get(classname,
None)
231 c=getattr(ROOT, self.
prefix+classname,
None)
234 print(
"JetAnalysisCommon ERROR : ",classname,
" is not a known C++ tool, alg, or namespace ")
237 if hasattr(c,
'getPropertyMgr'):
244 setattr(self, classname, conf)
257 CompFactory.addNameSpaces(
'Analysis',
'Trk',
'Jet',
'Sim',)
261 ComponentFactory.CompFactory = CompFactory
263 ComponentFactory.isComponentAccumulatorCfg =
lambda :
True
271 CFElements.parOR = parOR
277 """Provdide similar interface than AthenaConfiguration.ComponentAccumulator and also very simplistic
278 merging of list of algorithms
285 return iter(self.
algs)
291 setattr(self, alg._name, alg)
293 def merge(self, ca, sequenceName=""):
294 myTNs =
set( alg.typeAndName()
for alg
in self.
algs)
296 tn = alg.typeAndName()
299 setattr(self, alg._name, alg)
311 """a little configuration function added from the python module JetAnalysisCommon.py to easily schedule
312 # a list of Configured algs as defined by this module."""
314 job.algsAdd( alg.asAnaAlg() )
316 ROOT.EL.Job.addManyAlgs = addManyAlgs
323 JetAnalysisCommon = sys.modules[__name__]
326 sys.modules[
'AthenaConfiguration.ComponentFactory'] = JetAnalysisCommon.ComponentFactory
327 sys.modules[
'AthenaConfiguration.ComponentAccumulator'] = JetAnalysisCommon.ComponentAccumulator
328 sys.modules[
'AthenaCommon.CFElements'] = JetAnalysisCommon.CFElements
332 """Allows to ignore JetRecTools in case this package is not checked out on top of AnalysisBase"""
333 sys.modules[
'JetRecTools'] =
ModuleType(
'JetRecTools')
334 sys.modules[
'JetRecTools.JetRecToolsConfig'] =
ModuleType(
'JetRecToolsConfig')
341 import JetRecConfig.JetRecConfig
as JetRecConfig
350 JetRecConfig.JetRecCfg_original = JetRecConfig.JetRecCfg
352 """Builds the algs with JetRecConfig.JetRecCfg and then make sure
353 they are in proper order.
354 Re-ordering is done manually, according to various input alg type.
356 res = JetRecConfig.JetRecCfg_original(flags, jetdef , returnFinalJetDef)
358 acc , _ = res
if returnFinalJetDef
else (res,
None)
363 if not hasattr(ROOT,
'EventDensityAthAlg'):
365 evtDensityAlgs = [ (i,alg)
for (i,alg)
in enumerate(algs)
if alg._cppclass == ROOT.EventDensityAthAlg ]
366 pjAlgs = [ (i,alg)
for (i,alg)
in enumerate(algs)
if alg._cppclass == ROOT.PseudoJetAlgorithm ]
368 for i,edalg
in evtDensityAlgs:
369 edInput = edalg.EventDensityTool.InputContainer
370 for j,pjalg
in pjAlgs:
372 if edInput == pjalg.OutputContainer:
373 pairsToswap.append( (i,j) )
374 for (i,j)
in pairsToswap:
375 algs[i], algs[j] = algs[j], algs[i]
383 JetRecConfig.JetRecCfg = JetRecCfg_reorder