183 def persistent_id(self, obj):
184 if hasattr(obj, '_ROOT_Proxy__obj'):
185 obj = obj._ROOT_Proxy__obj()
186 if isinstance(obj, ROOT.TObject):
187 """
188 Write the object, and return the resulting NAME;CYCLE.
189 We used to do this::
190
191 o.Write()
192 k = self.__file.GetKey(o.GetName())
193 pid = "{0};{1:d}".format(k.GetName(), k.GetCycle())
194
195 It turns out, though, that destroying the python objects
196 referencing the TKeys is quite expensive (O(logN) where N is the
197 total number of pyroot objects?). Although we want to allow for
198 the case of saving multiple objects with the same name, the most
199 common case is that the name has not already been written to the
200 file. So we optimize for that case, doing the key lookup before we
201 write the object, not after. (Note further: GetKey() is very slow
202 if the key does not actually exist, as it does a linear search of
203 the key list. We use FindObject instead for the initial
204 lookup, which is a hashed lookup, but it is not guaranteed to
205 find the highest cycle. So if we do find an existing key, we
206 need to look up again using GetKey.
207 """
208 nm = obj.GetName()
209 key = self.__keys.FindObject(nm)
210 obj.Write()
211 if key:
212 key = self.__file.GetKey(nm)
213 pid = '{0};{1:d}'.format(nm, key.GetCycle())
214 else:
215 pid = nm + ';1'
216 return pid
217
218