Refs #3175: add the tooling to order trees

Backporting some code from 2.4 to 2.3