Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Nodes.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
18 """
19 Simple 'decorator for nodes'
20 """
21 from __future__ import print_function
22 
23 # =============================================================================
24 __author__ = "Vanya BELYAEV <Ivan.Belyaev@nikhef.nl>"
25 __version__ = ""
26 # =============================================================================
27 
28 # Workaround for ROOT-10769
29 import warnings
30 
31 with warnings.catch_warnings():
32  warnings.simplefilter("ignore")
33  import cppyy
34 
35 import GaudiPython
36 
37 # namespaces shortcuts
38 Decays = cppyy.gbl.Gaudi.Decays
39 std = cppyy.gbl.std
40 Gaudi = GaudiPython.gbl.Gaudi
41 
42 
43 # =============================================================================
44 
45 def _decorate(nodes, opers):
46  """
47  Decorate the functions
48  """
49 
50 
51  if hasattr(opers, "__call__"):
52 
53  def _call_(self, arg):
54  """
55  Evaluate the functor
56 
57  >>> fun = ... # get the functor
58  >>> arg = ... # get the argument
59  >>> res = fun ( arg )
60  """
61  result = opers.__call__(self, arg)
62  return True if result else False
63 
64  _call_.__doc__ = opers.__call__.__doc__
65 
66 
67  if hasattr(opers, "__or__"):
68 
69  def _or_(self, arg):
70  """
71  LOGICAL or
72 
73  >>> fun1 = ... # get the functor
74  >>> fun2 = ... # get the functor
75  >>> fun = fun1 | fun2
76  """
77  return opers.__or__(self, arg)
78 
79  _or_.__doc__ = opers.__or__.__doc__
80 
81 
82  if hasattr(opers, "__ror__"):
83 
84  def _ror_(self, arg):
85  """
86  LOGICAL or
87 
88  >>> fun1 = ... # get the functor
89  >>> fun2 = ... # get the functor
90  >>> fun = fun1 | fun2
91  """
92  return opers.__ror__(self, arg)
93 
94  _or_.__doc__ = opers.__or__.__doc__
95 
96 
97  if hasattr(opers, "__and__"):
98 
99  def _and_(self, arg):
100  """
101  LOGICAL and
102 
103  >>> fun1 = ... # get the functor
104  >>> fun2 = ... # get the functor
105  >>> fun = fun1 & fun2
106  """
107  return opers.__and__(self, arg)
108 
109  _and_.__doc__ = opers.__and__.__doc__
110 
111 
112  if hasattr(opers, "__rand__"):
113 
114  def _rand_(self, arg):
115  """
116  LOGICAL and
117 
118  >>> fun1 = ... # get the functor
119  >>> fun2 = ... # get the functor
120  >>> fun = fun1 & fun2
121  """
122  return opers.__rand__(self, arg)
123 
124  _rand_.__doc__ = opers.__rand__.__doc__
125 
126 
127  if hasattr(opers, "__invert__"):
128 
129  def _invert_(self, *arg):
130  """
131  LOGICAL negation
132 
133  >>> fun1 = ... # get the functor
134  >>> fun = ~fun2
135  """
136  return opers.__invert__(self, *arg)
137 
138  _invert_.__doc__ = opers.__invert__.__doc__
139 
140 
141  if hasattr(opers, "__rshift__"):
142 
143  def _rshift_(self, arg):
144  """
145  Streamers
146 
147  >>> fun1 = ... # get the functor
148  >>> fun1 = ... # get the functor
149  >>> fun = fun1 >> fun2
150  """
151  return opers.__rshift__(self, arg)
152 
153  _rshift_.__doc__ = opers.__rshift__.__doc__
154 
155 
156  if hasattr(opers, "__rrshift__"):
157 
158  def _rrshift_(self, arg):
159  """
160  Evaluate the functor as streametr shift
161 
162  >>> fun = ... # get the functor
163  >>> arg = ... # get the argument
164  >>> res = arg >> fun
165  """
166  result = opers.__rrshift__(self, arg)
167  return True if result else False
168 
169  _rrshift_.__doc__ = opers.__rrshift__.__doc__
170 
171  for node in nodes:
172  if _call_:
173  node.__call__ = _call_
174  if _or_:
175  node.__or__ = _or_
176  if _ror_:
177  node.__ror__ = _ror_
178  if _and_:
179  node.__and__ = _and_
180  if _rand_:
181  node.__rand__ = _rand_
182  if _rshift_:
183  node.__rshift__ = _rshift_
184  if _rrshift_:
185  node.__rrshift__ = _rrshift_
186  if _invert_:
187  node.__invert__ = _invert_
188 
189  node.__repr__ = lambda s: s.toString()
190  node.__str__ = lambda s: s.toString()
191 
192  return nodes
193 
194 
195 
196 _decorated = _decorate(
197  (
198  Decays.iNode,
199  Decays.Node,
200  #
201  Decays.Nodes.Any,
202  Decays.Nodes.Pid,
203  Decays.Nodes.CC,
204  #
205  Decays.Nodes.Lepton,
206  Decays.Nodes.Nu,
207  Decays.Nodes.Ell,
208  Decays.Nodes.EllPlus,
209  Decays.Nodes.EllMinus,
210  Decays.Nodes.Hadron,
211  Decays.Nodes.Meson,
212  Decays.Nodes.Baryon,
213  Decays.Nodes.Charged,
214  Decays.Nodes.Positive,
215  Decays.Nodes.Negative,
216  Decays.Nodes.Neutral,
217  Decays.Nodes.HasQuark,
218  Decays.Nodes.JSpin,
219  Decays.Nodes.SSpin,
220  Decays.Nodes.LSpin,
221  Decays.Nodes.Nucleus,
222  Decays.Nodes.CTau,
223  Decays.Nodes.ShortLived_,
224  Decays.Nodes.LongLived_,
225  Decays.Nodes.Stable,
226  Decays.Nodes.StableCharged,
227  Decays.Nodes.CTau,
228  Decays.Nodes.Mass,
229  Decays.Nodes.Light,
230  Decays.Nodes.Heavy,
231  Decays.Nodes.Symbol,
232  Decays.Nodes.Invalid,
233  Decays.Nodes._Node,
234  #
235  Decays.Nodes.Or,
236  Decays.Nodes.And,
237  Decays.Nodes.Not,
238  ),
240  opers=Decays.Dict.NodeOps,
241 )
242 
243 
244 
247 #
248 Any = Decays.Nodes.Any() # instance
249 Pid = Decays.Nodes.Pid # type
250 CC = Decays.Nodes.CC # type
251 Lepton = Decays.Nodes.Lepton() # instance
252 Nu = Decays.Nodes.Nu() # instance
253 Ell = Decays.Nodes.Ell() # instance
254 EllPlus = Decays.Nodes.EllPlus() # instance
255 EllMinus = Decays.Nodes.EllMinus() # instance
256 Hadron = Decays.Nodes.Hadron() # instance
257 Meson = Decays.Nodes.Meson() # instance
258 Baryon = Decays.Nodes.Baryon() # instance
259 Charged = Decays.Nodes.Charged() # instance
260 Positive = Decays.Nodes.Positive() # instance
261 Negative = Decays.Nodes.Negative() # instance
262 Neutral = Decays.Nodes.Neutral() # instance
263 HasQuark = Decays.Nodes.HasQuark # type
264 JSpin = Decays.Nodes.JSpin # type
265 SSpin = Decays.Nodes.SSpin # type
266 LSpin = Decays.Nodes.LSpin # type
267 Nucleus = Decays.Nodes.Nucleus() # instance
268 Or = Decays.Nodes.Or # type
269 And = Decays.Nodes.And # type
270 Not = Decays.Nodes.Not # type
271 Invalid = Decays.Nodes.Invalid() # instance
272 _Node = Decays.Nodes._Node # type
273 
274 PosId = Decays.Nodes.PosID() # instance
275 NegId = Decays.Nodes.NegID() # instance
276 
277 Up = HasQuark(Gaudi.ParticleID.up)
278 Down = HasQuark(Gaudi.ParticleID.down)
279 Strange = HasQuark(Gaudi.ParticleID.strange)
280 Charm = HasQuark(Gaudi.ParticleID.charm)
281 Beauty = HasQuark(Gaudi.ParticleID.bottom)
282 Bottom = HasQuark(Gaudi.ParticleID.bottom)
283 Top = HasQuark(Gaudi.ParticleID.top)
284 
285 Xu = HasQuark(Gaudi.ParticleID.up)
286 Xd = HasQuark(Gaudi.ParticleID.down)
287 Xs = HasQuark(Gaudi.ParticleID.strange)
288 Xc = HasQuark(Gaudi.ParticleID.charm)
289 Xb = HasQuark(Gaudi.ParticleID.bottom)
290 Xb = HasQuark(Gaudi.ParticleID.bottom)
291 Xt = HasQuark(Gaudi.ParticleID.top)
292 
293 Scalar = JSpin(1)
294 Spinor = JSpin(2)
295 Vector = JSpin(3)
296 Tensor = JSpin(5)
297 
298 OneHalf = JSpin(2)
299 ThreeHalf = JSpin(4)
300 FiveHalf = JSpin(6)
301 
302 CTau = Decays.Nodes.CTau # type
303 LongLived_ = Decays.Nodes.LongLived_ # type
304 LongLived = Decays.Nodes.LongLived_() # instance
305 ShortLived_ = Decays.Nodes.ShortLived_ # type
306 ShortLived = Decays.Nodes.ShortLived_() # instance
307 Stable = Decays.Nodes.Stable() # instance
308 StableCharged = Decays.Nodes.StableCharged() # instance
309 Mass = Decays.Nodes.Mass # type
310 Light = Decays.Nodes.Light # type
311 Heavy = Decays.Nodes.Heavy # type
312 Symbol = Decays.Nodes.Symbol # type
313 
314 NodeList = Decays.NodeList
315 
316 if "__main__" == __name__:
317  print(" decorated objects: %s " % str(_decorated))
318  print(_decorated)
319  print(dir())
Gaudi::Decays::Node
Definition: iNode.h:74
Gaudi::Decays::NodeList
Definition: Nodes.h:168
GaudiPartProp.Nodes.JSpin
JSpin
Definition: Nodes.py:264
GaudiPartProp.Nodes._decorate
def _decorate(nodes, opers)
Decorate the nodes.
Definition: Nodes.py:45
GaudiPartProp.Nodes.HasQuark
HasQuark
Definition: Nodes.py:263
Gaudi::Decays::iNode
Definition: iNode.h:35