Normalization of a Hamiltonian system near an invariant cycle or torus