forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FacilityHelper.h
50 lines (45 loc) · 1.76 KB
/
FacilityHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
/*********************************************************************************
* PLEASE READ THIS!!!!!!!
*
* This file MAY NOT be modified to use anything from a package other than
*Kernel.
*********************************************************************************/
#pragma once
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
#include <Poco/Path.h>
namespace FacilityHelper {
/**
* Simple RAII struct to switch the facilities files to the when constructed
* and switch back to the previous settings on destruction
*/
struct ScopedFacilities {
/**
* Switch facilities file & default facility
* @param filename It is assumed it is in the instrument directory
* @param defFacility
*/
ScopedFacilities(const std::string &filename, const std::string &defFacility) {
auto &config = Mantid::Kernel::ConfigService::Instance();
defFacilityOnStart = config.getFacility().name();
Poco::Path testFile = Poco::Path(config.getInstrumentDirectory()).resolve(filename);
// Load the test facilities file
config.updateFacilities(testFile.toString());
config.setFacility(defFacility);
}
~ScopedFacilities() {
auto &config = Mantid::Kernel::ConfigService::Instance();
// Restore the main facilities file
config.updateFacilities(); // no file loads the default
config.setFacility(defFacilityOnStart);
}
private:
std::string defFacilityOnStart;
};
} // namespace FacilityHelper