Hierarchical structure of thermodynamics