Antares Simulator
Power System Simulator
correlation-updater.hxx
1 /*
2 ** Copyright 2007-2025, 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_CORRELATION_UPDATER_HXX__
22 #define __ANTARES_LIBS_STUDY_CORRELATION_UPDATER_HXX__
23 
24 #include <yuni/yuni.h>
25 
26 #define SEP IO::Separator
27 
28 namespace Antares
29 {
30 namespace // anonymous
31 {
32 class CorrelationUpdater final
33 {
34 public:
35  CorrelationUpdater(Data::Study& study):
36  pStudy(study)
37  {
38  using namespace Yuni;
39  // We can store the INI files in disk because it may not fit in memory
40  pTempFile << memory.cacheFolder() << SEP << "antares-corr-save-" << memory.processID()
41  << '-' << (void*)(this) << '-';
42 
43  pS.clear() << pTempFile << "load.tmp";
44  study.preproLoadCorrelation.saveToFile(study, pS);
45  pS.clear() << pTempFile << "solar.tmp";
46  study.preproSolarCorrelation.saveToFile(study, pS);
47  pS.clear() << pTempFile << "wind.tmp";
48  study.preproWindCorrelation.saveToFile(study, pS);
49  pS.clear() << pTempFile << "hydro.tmp";
50  study.preproHydroCorrelation.saveToFile(study, pS);
51  }
52 
53  ~CorrelationUpdater()
54  {
55  using namespace Yuni;
56  pS.clear() << pTempFile << "load.tmp";
57  pStudy.preproLoadCorrelation.loadFromFile(pStudy, pS, false);
58  IO::File::Delete(pS);
59 
60  pS.clear() << pTempFile << "solar.tmp";
61  pStudy.preproSolarCorrelation.loadFromFile(pStudy, pS, false);
62  IO::File::Delete(pS);
63 
64  pS.clear() << pTempFile << "wind.tmp";
65  pStudy.preproWindCorrelation.loadFromFile(pStudy, pS, false);
66  IO::File::Delete(pS);
67 
68  pS.clear() << pTempFile << "hydro.tmp";
69  pStudy.preproHydroCorrelation.loadFromFile(pStudy, pS, false);
70  IO::File::Delete(pS);
71  }
72 
73 private:
74  Data::Study& pStudy;
75  Yuni::Clob pTempFile;
76  Yuni::Clob pS;
77 
78 }; // class CorrelationUpdater
79 
80 } // anonymous namespace
81 
82 } // namespace Antares
83 
84 #endif // __ANTARES_LIBS_STUDY_CORRELATION_UPDATER_HXX__
const Yuni::String & cacheFolder() const
\nane Cache Folder
Definition: memory.cpp:137
uint64_t processID() const
Get the process ID of the application.
Definition: memory.hxx:26