Fix error writing trees to file
Make sure that correct gDirectory is set before writing trees to file, in multi-threaded applications gDirectory needs special attention. Added test code for debugging the issue and script to generate simple DQM configuration.