ATLAS Offline Software
Loading...
Searching...
No Matches
python.JetAnalysisCommon.Configured Class Reference
Collaboration diagram for python.JetAnalysisCommon.Configured:

Public Member Functions

 __init__ (self, name, **props)
 __setattr__ (self, k, v)
 getName (self)
 setparent (self, parent)
 prefixed (self, k)
 ancestors (self)
 fullname (self)
 properties (self)
 typeAndName (self)
 asAnaAlg (self)
 toToolInAnaAlg (self, anaAlg, handlename)
 assignAllProperties (self, anaAlg)
 setPropToAnaAlg (self, k, v)
 getType (self)

Public Attributes

 type

Protected Member Functions

 _setattrImpl (self, k, v)

Protected Attributes

 _name = name
 _cppclass

Static Protected Attributes

 _properties = set()
dict _propTypes = {}
 _parent = None
 _anaAlg = None
list _allowed = ['_properties', '_name', '_parent', '_anaAlg']

Detailed Description

A replacement for Athena auto-generated Configured python class.
Configured has the same interface as its Athena counterpart and can describe both Tools and Algorithms

This is a base class. The system replacing CompFactory will generate a derived class for each c++ Tool/Algorithm
to hold the configuration of such tool/alg  (see generateConfigured())

Definition at line 88 of file JetAnalysisCommon.py.

Constructor & Destructor Documentation

◆ __init__()

python.JetAnalysisCommon.Configured.__init__ ( self,
name,
** props )

Definition at line 104 of file JetAnalysisCommon.py.

104 def __init__(self, name, **props):
105
106 self._name = name
107 self._properties = set()
108 for k,v in props.items():
109 setattr(self,k,v)
110
STL class.

Member Function Documentation

◆ __setattr__()

python.JetAnalysisCommon.Configured.__setattr__ ( self,
k,
v )

Definition at line 111 of file JetAnalysisCommon.py.

111 def __setattr__(self, k, v):
112 if k in self._allowed:
113 self._setattrImpl(k,v)
114 else:
115 raise AttributeError("Configuration of Tool {} / {} . can't set attribute : {}".format(self.type, self._name, k) )
116

◆ _setattrImpl()

python.JetAnalysisCommon.Configured._setattrImpl ( self,
k,
v )
protected

Definition at line 117 of file JetAnalysisCommon.py.

117 def _setattrImpl(self, k, v) :
118 super().__setattr__(k,v)
119 if k[0] == '_' :
120 # this is not a Property
121 return
122
123 if isinstance(v, Configured):
124 if k in self._properties:
125 raise RuntimeError( "Configuring {} / {} : Tool for property {} already exists".format(self.type, self._name, k) )
126 # it's a tool:
127 v.setparent(self)
128 v._name = k
129 elif isinstance(v, (list, tuple) ):
130 if isinstance(v[0], Configured):
131 v = ConfArray(k,v, self)
132 super().__setattr__(k,v)
133 self._properties.add(k)
134 if self._anaAlg:
135 self.setPropToAnaAlg( k , v)
136
137
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55

◆ ancestors()

python.JetAnalysisCommon.Configured.ancestors ( self)

Definition at line 148 of file JetAnalysisCommon.py.

148 def ancestors(self):
149 if self._parent is None : return [self]
150 return self._parent.ancestors()+[self]
151

◆ asAnaAlg()

python.JetAnalysisCommon.Configured.asAnaAlg ( self)
Returns this configured alg as an instance of Ana(Reentrant)AlgorithmConfig       

Definition at line 163 of file JetAnalysisCommon.py.

163 def asAnaAlg(self):
164 """Returns this configured alg as an instance of Ana(Reentrant)AlgorithmConfig
165 """
166 if issubclass(self._cppclass, ROOT.EL.AnaReentrantAlgorithm):
167 alg=ROOT.EL.AnaReentrantAlgorithmConfig()
168 else:
169 alg=ROOT.EL.AnaAlgorithmConfig()
170
171 alg.setTypeAndName( self.typeAndName() )
172 self.assignAllProperties(alg)
173 return alg
174
175

◆ assignAllProperties()

python.JetAnalysisCommon.Configured.assignAllProperties ( self,
anaAlg )
 Transfer all the configuration in self to anaAlg
where anaAlg is an AnaAlgorithmConfig.

Definition at line 189 of file JetAnalysisCommon.py.

189 def assignAllProperties(self, anaAlg):
190 """ Transfer all the configuration in self to anaAlg
191 where anaAlg is an AnaAlgorithmConfig."""
192 self._anaAlg = anaAlg
193 for (k,v) in self.properties():
194 self.setPropToAnaAlg(k,v)
195

◆ fullname()

python.JetAnalysisCommon.Configured.fullname ( self)

Definition at line 152 of file JetAnalysisCommon.py.

152 def fullname(self):
153 parents = self.ancestors()[1:]
154 return '.'.join([p._name for p in parents])
155

◆ getName()

python.JetAnalysisCommon.Configured.getName ( self)

Definition at line 138 of file JetAnalysisCommon.py.

138 def getName(self):
139 return self._name
140

◆ getType()

python.JetAnalysisCommon.Configured.getType ( self)

Definition at line 214 of file JetAnalysisCommon.py.

214 def getType(self):
215 return self.type
216

◆ prefixed()

python.JetAnalysisCommon.Configured.prefixed ( self,
k )

Definition at line 144 of file JetAnalysisCommon.py.

144 def prefixed(self, k):
145 if self._parent is None: return k
146 return self.fullname()+'.'+k
147

◆ properties()

python.JetAnalysisCommon.Configured.properties ( self)

Definition at line 156 of file JetAnalysisCommon.py.

156 def properties(self):
157 return [ (k, getattr(self,k)) for k in self._properties]
158

◆ setparent()

python.JetAnalysisCommon.Configured.setparent ( self,
parent )

Definition at line 141 of file JetAnalysisCommon.py.

141 def setparent(self, parent):
142 self._parent = parent
143

◆ setPropToAnaAlg()

python.JetAnalysisCommon.Configured.setPropToAnaAlg ( self,
k,
v )

Definition at line 196 of file JetAnalysisCommon.py.

196 def setPropToAnaAlg(self, k, v):
197 alg=self._anaAlg
198 if isinstance(v , Configured):
199 # it must be a Tool :
200 try:
201 alg.addPrivateTool(v.fullname(), v.type)
202 except RuntimeError:
203 # this means the tool is already declared, nothing to do.
204 pass #
205 v.assignAllProperties(alg)
206 elif isinstance(v, ConfArray ):
207 # it is a Tool array
208 v.assignAllProperties(alg)
209 else:
210 # any other type :
211 cpptype = self._propTypes[k]
212 alg.setProperty[cpptype](self.prefixed(k) , v)
213

◆ toToolInAnaAlg()

python.JetAnalysisCommon.Configured.toToolInAnaAlg ( self,
anaAlg,
handlename )
If self represents a configured AlgTool,
this call will configure the AnaAlgorithmConfig 'anaAlg' so
its ToolHandle property 'handlename' is configured with self

Definition at line 176 of file JetAnalysisCommon.py.

176 def toToolInAnaAlg(self, anaAlg, handlename):
177 """If self represents a configured AlgTool,
178 this call will configure the AnaAlgorithmConfig 'anaAlg' so
179 its ToolHandle property 'handlename' is configured with self
180 """
181 if handlename in anaAlg._props:
182 return
183 props = {handlename:self, }
184 klass=type('TmpConf', (Configured,), dict(_allowed=self._allowed+[handlename], _propTypes={},
185 type=anaAlg.getType(),_cppclass='none') )
186 c=klass(anaAlg.name(), **props)
187 c.assignAllProperties(anaAlg)
188

◆ typeAndName()

python.JetAnalysisCommon.Configured.typeAndName ( self)

Definition at line 159 of file JetAnalysisCommon.py.

159 def typeAndName(self):
160 return self.type+'/'+self._name
161
162

Member Data Documentation

◆ _allowed

list python.JetAnalysisCommon.Configured._allowed = ['_properties', '_name', '_parent', '_anaAlg']
staticprotected

Definition at line 102 of file JetAnalysisCommon.py.

◆ _anaAlg

python.JetAnalysisCommon.Configured._anaAlg = None
staticprotected

Definition at line 99 of file JetAnalysisCommon.py.

◆ _cppclass

python.JetAnalysisCommon.Configured._cppclass
protected

Definition at line 166 of file JetAnalysisCommon.py.

◆ _name

python.JetAnalysisCommon.Configured._name = name
protected

Definition at line 106 of file JetAnalysisCommon.py.

◆ _parent

python.JetAnalysisCommon.Configured._parent = None
staticprotected

Definition at line 98 of file JetAnalysisCommon.py.

◆ _properties

python.JetAnalysisCommon.Configured._properties = set()
staticprotected

Definition at line 96 of file JetAnalysisCommon.py.

◆ _propTypes

dict python.JetAnalysisCommon.Configured._propTypes = {}
staticprotected

Definition at line 97 of file JetAnalysisCommon.py.

◆ type

python.JetAnalysisCommon.Configured.type

Definition at line 115 of file JetAnalysisCommon.py.


The documentation for this class was generated from the following file: