Thermodynamics of the micromaser