Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
updater.hxx
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21#ifndef __ANTARES_LIBS_STUDY_SCENARIO_BUILDER_UPDATER_HXX__
22#define __ANTARES_LIBS_STUDY_SCENARIO_BUILDER_UPDATER_HXX__
23
24#include <yuni/yuni.h>
25
26#include "antares/study/study.h"
27
28#include "sets.h"
29
30#define SEP IO::Separator
31
32namespace Antares
33{
34namespace // anonymous
35{
36class ScenarioBuilderUpdater
37{
38public:
39 ScenarioBuilderUpdater(Data::Study& study):
40 pStudy(study)
41 {
42 using namespace Yuni;
43 // We can store the INI files in disk because it may not fit in memory
44
45 if (study.scenarioRules)
46 {
47 study.scenarioRules->inUpdaterMode = true;
48 logs.debug() << "[scenario-builder] updater mode ON";
49
50 logs.debug()
51 << "[scenario-builder] writing data to a temporary file before structure changes";
52 pTempFile << memory.cacheFolder() << SEP << "antares-scenbld-save-"
53 << memory.processID() << '-' << (size_t)(this) << "-scenariobuilder.tmp";
54 // Dump the memory
55 study.scenarioRules->saveToINIFile(pTempFile);
56 study.scenarioRules->clear();
57 }
58 }
59
60 ~ScenarioBuilderUpdater()
61 {
62 using namespace Yuni;
63
64 if (not pTempFile.empty())
65 {
66 if (pStudy.scenarioRules)
67 {
68 logs.debug() << "[scenario-builder] reloading data from a temporary file";
69 pStudy.scenarioRules->loadFromINIFile(pTempFile);
70
71 pStudy.scenarioRules->inUpdaterMode = false;
72 logs.debug() << "[scenario-builder] updater mode OFF";
73 }
74 // Removing the temporary file
75 IO::File::Delete(pTempFile);
76 }
77 }
78
79private:
80 Data::Study& pStudy;
81 Yuni::String pTempFile;
82
83}; // class ScenarioBuilderUpdater
84
85} // anonymous namespace
86
87} // namespace Antares
88
89#endif // __ANTARES_LIBS_STUDY_SCENARIO_BUILDER_UPDATER_HXX__
Definition study.h:61
std::unique_ptr< ScenarioBuilder::Sets > scenarioRules
Rules for building scenarios (can be null)
Definition study.h:560