Skip to content
Snippets Groups Projects

Declare data dependencies in ThOr functors

Merged Alex Pearce requested to merge apearce-moore-51 into master
Files
5
@@ -12,9 +12,11 @@
from __future__ import print_function
from __future__ import division
from past.utils import old_div
import pickle
from Functors import PT, ISMUON, MINIPCUT
from Functors import math as fmath
from GaudiKernel.SystemOfUnits import *
from PyConf.Algorithms import Gaudi__Examples__IntDataProducer
def not_empty(f):
@@ -79,3 +81,25 @@ def test_disabled_logical_operators():
pass
else:
raise Exception("Use of logical `not` did not raise an exception.")
def test_serialisation():
"""A BoundFunctor must be seriasable by the pickle module."""
functor = MINIPCUT(IPCut=1.0, Vertices='Test/Path')
# Use the same protocol as in `gaudirun.py -o options.pkl`
loaded = pickle.loads(pickle.dumps(functor, protocol=-1))
assert functor.code() == loaded.code()
assert functor.code_repr() == loaded.code_repr()
assert functor.headers() == loaded.headers()
assert functor.name() == loaded.name()
assert repr(functor) == repr(loaded)
assert str(functor) == str(loaded)
# Should also work with DataHandle inputs
pvs = Gaudi__Examples__IntDataProducer().OutputLocation
functor = MINIPCUT(IPCut=1.0, Vertices=pvs)
loaded = pickle.loads(pickle.dumps(functor, protocol=-1))
# It is expected that the data dependencies are lost during serialisation;
# see BoundFunctor.__getstate__
assert len(functor.data_dependencies()) > len(loaded.data_dependencies())
assert len(loaded.data_dependencies()) == 0
Loading