  Let $P(b)\subset R^d$ be a semi-rational parametric polytope, where
$b=(b_j)\in R^N$ is a real multi-parameter. We study intermediate sums of
polynomial functions $h(x)$ on $P(b)$, $$
  S^L (P(b),h)=\sum_{y}\int_{P(b)\cap (y+L)} h(x) \mathrm dx, $$ where we
integrate over the intersections of $P(b)$ with the subspaces parallel to a
fixed rational subspace $L$ through all lattice points, and sum the integrals.
The purely discrete sum is of course a particular case ($L=0$), so $S^0(P(b),
1)$ counts the integer points in the parametric polytopes.
  The chambers are the open conical subsets of $R^N$ such that the shape of
$P(b)$ does not change when $b$ runs over a chamber. We first prove that on
every chamber of $R^N$, $S^L (P(b),h)$ is given by a quasi-polynomial function
of $b\in R^N$. A key point of our paper is an analysis of the interplay between
two notions of degree on quasi-polynomials: the usual polynomial degree and a
filtration, called the local degree.
  Then, for a fixed $k\leq d$, we consider a particular linear combination of
such intermediate weighted sums, which was introduced by Barvinok in order to
compute efficiently the $k+1$ highest coefficients of the Ehrhart
quasi-polynomial which gives the number of points of a dilated rational
polytope. Thus, for each chamber, we obtain a quasi-polynomial function of $b$,
which we call Barvinok's patched quasi-polynomial (at codimension level $k$).
  Finally, for each chamber, we introduce a new quasi-polynomial function of
$b$, the cone-by-cone patched quasi-polynomial (at codimension level $k$),
defined in a refined way by linear combinations of intermediate generating
functions for the cones at vertices of $P(b)$.
  We prove that both patched quasi-polynomials agree with the discrete weighted
sum $b\mapsto S^0(P(b),h)$ in the terms corresponding to the $k+1$ highest
polynomial degrees.
