The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
Service.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
21"""
22Useful 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
32import GaudiPartProp.decorators # noqa: F401
33
34# =============================================================================
36
37cpp = GaudiPython.Bindings.gbl
39Helper = GaudiPython.Bindings.Helper
42Gaudi = GaudiPython.gbl.Gaudi
43
44
45# =============================================================================
46
47class iParticlePropertySvc(iService):
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)
61 isvc
62 )
63
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:
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:
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
228iParticlePropertySvc.ParticleIDs = Gaudi.Interfaces.IParticlePropertySvc.ParticleIDs
229iParticlePropertySvc.Decay = Gaudi.Interfaces.IParticlePropertySvc.Decay
230iParticlePropertySvc.Decays = Gaudi.Interfaces.IParticlePropertySvc.Decays
231iParticlePropertySvc.Item = Gaudi.Interfaces.IParticlePropertySvc.Item
232iParticlePropertySvc.Items = Gaudi.Interfaces.IParticlePropertySvc.Items
233
234
235# =============================================================================
236
237def _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
249AppMgr.gaudiPartProp = _ppSvc_
250AppMgr.gaudiPartProp = _ppSvc_
The abstract interface to Particle Property Service.
validate(self, obj)
validate the node/decay/tree
Definition Service.py:181
__len__(self)
get the size (number of known particle proeprties)
Definition Service.py:220
svc(self)
get the C++ service itself
Definition Service.py:157
service(self)
get the C++ service itself
Definition Service.py:170
size(self)
get the size (number of known particle proeprties)
Definition Service.py:211
__iter__(self)
make iteration over all known particle properties
Definition Service.py:192
cc(self, decay)
CC-conjugation.
Definition Service.py:144
find(self, what)
Find the Particle Property by particle name or particle ID.
Definition Service.py:69
all(self, asList=False)
get all
Definition Service.py:124
dump(self)
dump the particle property table
Definition Service.py:137
get(self, cut, asList=False)
get the Particle Properties by particle name or particle ID
Definition Service.py:83
_ppSvc_(self, name="Gaudi::ParticlePropertySvc")
accessor to the service
Definition Service.py:237