Arcane  4.2.3.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ParamFile.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ParamFile.cc (C) 2000-2026 */
9/* */
10/* Lecteur des fichiers de paramètres. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/launcher/internal/ParamFile.h"
15
16#include "arcane/launcher/ArcaneLauncher.h"
17
18#include "arcane/utils/PlatformUtils.h"
19#include "arcane/utils/FatalErrorException.h"
20#include "arcane/utils/CommandLineArguments.h"
21#include "arcane/utils/JSONReader.h"
22#include "arccore/common/ArcaNetReader.h"
23
24#include <iostream>
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
36{
37 public:
38
39 ArgsFill(CommandLineArguments& args)
40 : m_args(args)
41 {}
42
43 public:
44
45 void readFilePart(JSONValue file_part);
46 void readArcanePart(JSONValue arcane_part);
47 String name() const { return m_name; }
48
49 private:
50
52 StringBuilder m_name;
53};
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58void ParamFile::ArgsFill::
59readFilePart(const JSONValue file_part)
60{
61 const JSONValue dataset = file_part.child("name");
62 if (!dataset.isNull()) {
63 m_name += " -> \"";
64 m_name += dataset.valueAsStringView();
65 m_name += "\"";
66 }
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72void ParamFile::ArgsFill::
73readArcanePart(const JSONValue arcane_part)
74{
75 const JSONValue dataset = arcane_part.child("dataset");
76 if (!dataset.isNull()) {
77 m_args.addParameterLine(String::format("CaseDatasetFileName={0}", dataset.value()));
78 //std::cout << "Dataset : " << dataset.value() << std::endl;
79 }
80
81 const JSONValue arcane_params = arcane_part.child("options");
82
83 if (!arcane_params.isNull()) {
84 const JSONKeyValueList params = arcane_params.keyValueChildren();
85
86 for (auto elem : params) {
87 m_args.addParameterLine(String::format("{0}={1}", elem.name(), elem.value().valueAsStringView()));
88 // std::cout << "Elem : " << elem.name() << " -- val : " << elem.value().valueAsStringView() << std::endl;
89 }
90 }
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99void ParamFile::
100editParams(const String& param_file_name, const String& variation)
101{
102 CommandLineArguments args = ArcaneLauncher::applicationInfo().commandLineArguments();
103
104 JSONDocument json_doc;
105 {
106 UniqueArray<Byte> bytes;
107
108 if (platform::readAllFile(param_file_name, false, bytes)) {
109 ARCANE_FATAL("Param file not available");
110 }
111
112 json_doc.parse(bytes, param_file_name, (JSONDocument::ParseCommentsFlag | JSONDocument::ParseNumbersAsStringsFlag));
113 }
114
115 ArcaNetReader reader(json_doc.root());
116 reader.init(variation, "arcane");
117 reader.read();
118
119 ArgsFill args_fill(args);
120
121 ArrayView<JSONValue> json_values = reader.jsonValues();
122 for (JSONValue elem : json_values) {
123 args_fill.readFilePart(reader.extractFilePart(elem));
124 args_fill.readArcanePart(reader.extractProgPart(elem));
125 }
126
127 std::cout << "ArcaNet path: " << args_fill.name() << std::endl;
128
129 if (reader.computePath()) {
130 std::cout << "ArcaNet full path: " << reader.path() << std::endl;
131 std::cout << "ArcaNet config part readed: " << reader.configPartName() << std::endl;
132 }
133
134 // StringList names;
135 // StringList values;
136 // args.fillParameters(names, values);
137 // for (Integer i = 0, n = names.count(); i < n; ++i) {
138 // std::cout << "Final Elem : " << names[i] << " -- val : " << values[i] << std::endl;
139 // }
140
142}
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
146
147} // End namespace Arcane
148
149/*---------------------------------------------------------------------------*/
150/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
void setCommandLineArguments(const CommandLineArguments &args)
Positionne les arguments de la ligne de commande.
const CommandLineArguments & commandLineArguments() const
Arguments de la ligne de commande.
static ApplicationInfo & applicationInfo()
Informations sur l'application.
@ ParseNumbersAsStringsFlag
Analyse tous les nombres (entiers/réels) comme des chaînes de caractères.
@ ParseCommentsFlag
Autorise les commentaires sur une ligne (//) et multi-lignes (/‍**/).
StringView valueAsStringView() const
Valeur sous forme de StringView. La chaîne est vide si 'null()' est vrai.
bool isNull() const
Vrai si la valeur est de type 'null'.
JSONValue child(StringView name) const
Valeur fille de nom name. Retourne une valeur nulle si non trouvé.
Constructeur de chaîne de caractère unicode.
Chaîne de caractères unicode.
bool readAllFile(StringView filename, bool is_binary, ByteArray &out_bytes)
Lit le contenu d'un fichier et le conserve dans out_bytes.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --