The Gaudi Framework  v38r1p1 (ae26267b)
Service.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
21 """
22 Useful decorator for Gaudi::(I)ParticlePropertySvc
23 """
24 # =============================================================================
25 __author__ = "Vanya BELYAEV Ivan.Belyaev@nikhef.nl"
26 __version__ = ""
27 # =============================================================================
28 __all__ = ("iParticlePropertySvc",)
29 # The following is misunderstood by flake8 - the import is needed as it
30 # has necessary side effects
31 import GaudiPartProp.decorators # noqa: F401
32 
33 # =============================================================================
35 
36 cpp = GaudiPython.Bindings.gbl
38 Helper = GaudiPython.Bindings.Helper
41 Gaudi = GaudiPython.gbl.Gaudi
42 
43 
44 # =============================================================================
45 
47  """
48  Class iParticlePropertySvc: 'python'-twin for C++ class
49 
50  Gaudi::Interfaces::IParticlePropertySvc
51 
52  """
53 
54  def __init__(self, name, isvc):
55  """
56  Constructor from the name and the service
57  """
58  iService.__init__(self, name, isvc)
59  self.__dict__["_ipps"] = InterfaceCast(Gaudi.Interfaces.IParticlePropertySvc)(
60  isvc
61  )
62 
63  def retrieveInterface(self):
64  iService.retrieveInterface(self)
65  iParticlePropertySvc.__init__(self, self._name, self._isvc)
66 
67 
68  def find(self, what):
69  """
70  Find the Particle Property by particle name or particle ID
71 
72  >>> svc = ... # get the service
73  >>> pp1 = svc.find ( 'pi0' ) # find by name
74  >>> pp2 = svc.find ( Gaudi.ParticleID( 511 ) ) # find by Particle ID
75 
76  """
77  if not self._ipps:
78  self.retrieveInterface()
79  return self._ipps.find(what) # return
80 
81 
82  def get(self, cut, asList=False):
83  """
84  Simple 'get' method for Gaudi::Interfaces::IParticlePropertySvc
85  service to extract the properties which satisfy some criteria
86 
87  >>> svc = ... # get service (Gaudi::Interfaces::IParticlePropertySvc) or vector
88  >>> leptons = svc.get ( lambda s : s.pid().isLepton() ) # get all leptons
89  >>> longlived = svc.get ( lambda s : s.ctau() > 0.001 ) # get longlived
90 
91  """
92  if not self._ipps:
93  self.retrieveInterface()
94  return self._ipps.get(cut, asList) # return
95 
96 
97  def begin(self):
98  """
99  Get the begin-iterator for the sequence of particle proeprties
100 
101  >>> svc = ... # get the service
102  >>> begin = svc.begin()
103 
104  """
105  if not self._ipps:
106  self.retrieveInterface()
107  return self._ipps.begin() # return
108 
109 
110  def end(self):
111  """
112  Get the end-iterator for the sequence of particle proeprties
113 
114  >>> svc = ... # get the service
115  >>> end = svc.end()
116 
117  """
118  if not self._ipps:
119  self.retrieveInterface()
120  return self._ipps.end() # return
121 
122 
123  def all(self, asList=False):
124  """
125  Get all particle properties form the service
126 
127  >>> svc = ... # get the service
128  >>> all = svc.all () # get all properties
129 
130  """
131  if not self._ipps:
132  self.retrieveInterface()
133  return self._ipps.all(asList) # return
134 
135 
136  def dump(self):
137  """
138  Dump the particle property table
139  """
140  self.Dump = True
141 
142 
143  def cc(self, decay):
144  """
145  Get CC-conjugationfor decay -descriptor
146 
147  >>> svc = ... # get the service
148  >>> cc = svc.cc ( 'B0 -> K- pi+' ) # get CC-conjugation
149 
150  """
151  if not self._ipps:
152  self.retrieveInterface()
153  return self._ipps.cc(decay) # return
154 
155 
156  def svc(self):
157  """
158  Get C++ service
159 
160  >>> svc = ... #
161  >>> svccpp = svc.svc ()
162 
163  """
164  if not self._ipps:
165  self.retrieveInterface()
166  return self._ipps # return
167 
168 
169  def service(self):
170  """
171  Get C++ service
172 
173  >>> svc = ... #
174  >>> svccpp = svc.service ()
175 
176  """
177  return self.svc()
178 
179 
180  def validate(self, obj):
181  """
182  Validate the node/decay/tree
183 
184  >>> svc = ... # get the service
185  >>> node = ... # get the node
186  >>> sc = svc.validate ( node )
187  """
188  return obj.validate(self.svc())
189 
190 
191  def __iter__(self):
192  """
193  Make an iteration over all known particle properties:
194 
195  >>> svc = ... # get the service
196  >>> for pp i svc : # make an iteration
197  ... print pp
198 
199  """
200  if not self._ipps:
201  self.retrieveInterface()
202  _list = self._ipps.all(False)
203  _size = len(_list)
204  _i = 0
205  while _i < _size:
206  yield _list[_i]
207  _i += 1
208 
209 
210  def size(self):
211  """
212  Get the length(size) of known particle properties
213  """
214  if not self._ipps:
215  self.retrieveInterface()
216  return self._ipps.size()
217 
218 
219  def __len__(self):
220  """
221  Get the length(size) of known particle properties
222  """
223  return self.size()
224 
225 
226 # useful types
227 iParticlePropertySvc.ParticleIDs = Gaudi.Interfaces.IParticlePropertySvc.ParticleIDs
228 iParticlePropertySvc.Decay = Gaudi.Interfaces.IParticlePropertySvc.Decay
229 iParticlePropertySvc.Decays = Gaudi.Interfaces.IParticlePropertySvc.Decays
230 iParticlePropertySvc.Item = Gaudi.Interfaces.IParticlePropertySvc.Item
231 iParticlePropertySvc.Items = Gaudi.Interfaces.IParticlePropertySvc.Items
232 
233 
234 # =============================================================================
235 
236 def _ppSvc_(self, name="Gaudi::ParticlePropertySvc"):
237  """
238  Get particle property service form application manager
239 
240  >>> gaudi = ...
241  >>> pps = gaudi.gaudiPartProp()
242 
243  """
244  svc = Helper.service(self._svcloc, name)
245  return iParticlePropertySvc(name, svc)
246 
247 
248 AppMgr.gaudiPartProp = _ppSvc_
249 AppMgr.gaudiPartProp = _ppSvc_
GaudiPartProp.Service.iParticlePropertySvc.Dump
Dump
Definition: Service.py:140
GaudiPartProp.Service.iParticlePropertySvc.cc
def cc(self, decay)
CC-conjugation.
Definition: Service.py:143
GaudiPartProp.Service.iParticlePropertySvc.__len__
def __len__(self)
get the size (number of known particle proeprties)
Definition: Service.py:219
Gaudi::Interfaces::IParticlePropertySvc
Definition: IParticlePropertySvc.h:29
GaudiPartProp.Service.iParticlePropertySvc.get
def get(self, cut, asList=False)
get the Particle Properties by particle name or particle ID
Definition: Service.py:82
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:887
GaudiPartProp.Service.InterfaceCast
InterfaceCast
Definition: Service.py:39
GaudiPartProp.Service.iParticlePropertySvc.all
def all(self, asList=False)
get all
Definition: Service.py:123
GaudiPython.Bindings
Definition: Bindings.py:1
GaudiPartProp.Service.iParticlePropertySvc.svc
def svc(self)
get the C++ service itself
Definition: Service.py:156
GaudiPartProp.Service.iParticlePropertySvc.find
def find(self, what)
Find the Particle Property by particle name or particle ID.
Definition: Service.py:68
GaudiPartProp.Service.iParticlePropertySvc.validate
def validate(self, obj)
validate the node/decay/tree
Definition: Service.py:180
GaudiPartProp.Service.iParticlePropertySvc
Definition: Service.py:46
GaudiPartProp.decorators
Definition: decorators.py:1
GaudiPartProp.Service.iParticlePropertySvc.size
def size(self)
get the size (number of known particle proeprties)
Definition: Service.py:210
GaudiPartProp.Service.iParticlePropertySvc.end
def end(self)
end-iterator
Definition: Service.py:110
GaudiPython.Bindings.iService
Definition: Bindings.py:385
GaudiPartProp.Service.iParticlePropertySvc.begin
def begin(self)
begin-iterator
Definition: Service.py:97
GaudiPartProp.Service.iParticlePropertySvc.retrieveInterface
def retrieveInterface(self)
Definition: Service.py:63
GaudiPartProp.Service.iParticlePropertySvc.service
def service(self)
get the C++ service itself
Definition: Service.py:169
GaudiPython.Bindings.InterfaceCast
Definition: Bindings.py:140
GaudiPartProp.Service._ppSvc_
def _ppSvc_(self, name="Gaudi::ParticlePropertySvc")
accessor to the service
Definition: Service.py:236
GaudiPartProp.Service.iParticlePropertySvc.__iter__
def __iter__(self)
make iteration over all known particle properties
Definition: Service.py:191
GaudiPartProp.Service.iService
iService
Definition: Service.py:37
GaudiPartProp.Service.iParticlePropertySvc.__init__
def __init__(self, name, isvc)
Definition: Service.py:54
GaudiPartProp.Service.iParticlePropertySvc.dump
def dump(self)
dump the particle property table
Definition: Service.py:136