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