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