A treatment planning code for inverse planning and 3D optimization in hadrontherapy