14#include "arcane/impl/internal/VariableMng.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/IObservable.h"
18#include "arcane/utils/ScopedPtr.h"
19#include "arcane/utils/StringBuilder.h"
20#include "arcane/utils/MD5HashAlgorithm.h"
21#include "arcane/utils/SHA1HashAlgorithm.h"
22#include "arcane/utils/JSONWriter.h"
23#include "arcane/utils/ValueConvert.h"
25#include "arcane/core/IDataWriter.h"
26#include "arcane/core/IXmlDocumentHolder.h"
27#include "arcane/core/DomUtils.h"
28#include "arcane/core/XmlNode.h"
29#include "arcane/core/VariableMetaData.h"
30#include "arcane/core/IData.h"
31#include "arcane/core/IMesh.h"
32#include "arcane/core/Properties.h"
33#include "arcane/core/Timer.h"
34#include "arcane/core/ICheckpointWriter.h"
35#include "arcane/core/IPostProcessorWriter.h"
36#include "arcane/core/internal/IDataInternal.h"
38#include "arcane/core/ISubDomain.h"
39#include "arcane/core/IParallelMng.h"
51VariableIOWriterMng(VariableMng* vm)
52: TraceAccessor(vm->traceMng())
55 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_VARIABLEMNG_HASHV2",
true))
56 m_use_hash_v2 = (v.value() != 0);
65void VariableIOWriterMng::
66writeCheckpoint(ICheckpointWriter* service)
73 Timer::Phase tp(m_variable_mng->m_time_stats, TP_InputOutput);
75 CheckpointSaveFilter save_filter;
77 service->notifyBeginWrite();
78 IDataWriter* data_writer = service->dataWriter();
81 writeVariables(data_writer, &save_filter,
true);
82 service->notifyEndWrite();
88void VariableIOWriterMng::
89writePostProcessing(IPostProcessorWriter* post_processor)
96 Timer::Phase tp(m_variable_mng->m_time_stats, TP_InputOutput);
98 post_processor->notifyBeginWrite();
99 VariableCollection variables(post_processor->variables());
100 IDataWriter* data_writer = post_processor->dataWriter();
103 writeVariables(data_writer, variables,
false);
104 post_processor->notifyEndWrite();
110void VariableIOWriterMng::
111writeVariables(IDataWriter* writer, IVariableFilter* filter,
bool use_hash)
120 for (
const auto& i : m_variable_mng->m_full_name_variable_map) {
121 IVariable* var = i.second;
122 bool apply_var =
true;
124 apply_var = filter->applyFilter(*var);
128 _writeVariables(writer, vars, use_hash);
136void VariableIOWriterMng::
143 for (
const auto& i : m_variable_mng->m_full_name_variable_map) {
163 void _writeAttribute(JSONWriter& json_writer, XmlNode var_node,
const String& name,
Int32 value)
166 var_node.setAttrValue(name, String::fromNumber(v));
167 json_writer.write(name, v);
169 void _writeAttribute(JSONWriter& json_writer, XmlNode var_node,
const String& name,
bool value)
171 var_node.setAttrValue(name, String::fromNumber(value));
172 json_writer.write(name, value);
180void VariableIOWriterMng::
181_generateVariablesMetaData(JSONWriter& json_writer, XmlNode variables_node,
182 const VariableCollection& vars, IHashAlgorithm* hash_algo)
184 StringBuilder var_full_type_b;
186 Ref<IHashAlgorithmContext> hash_context;
188 SHA1HashAlgorithm sha1_hash_algo;
189 hash_context = sha1_hash_algo.createContext();
192 json_writer.writeKey(
"variables");
193 json_writer.beginArray();
195 for (VariableCollection::Enumerator i(vars); ++i;) {
196 JSONWriter::Object o(json_writer);
198 Ref<VariableMetaData> vmd(var->createMetaDataRef());
199 String var_full_type = vmd->fullType();
200 String var_family_name = var->itemFamilyName();
201 String var_mesh_name = var->meshName();
202 XmlNode var_node = XmlElement(variables_node,
"variable");
203 _writeAttribute(json_writer, var_node,
"base-name", var->name());
204 if (!var_family_name.null())
205 _writeAttribute(json_writer, var_node,
"item-family-name", var_family_name);
206 if (var->isPartial())
207 _writeAttribute(json_writer, var_node,
"item-group-name", var->itemGroupName());
208 if (!var_mesh_name.null())
209 _writeAttribute(json_writer, var_node,
"mesh-name", var_mesh_name);
210 _writeAttribute(json_writer, var_node,
"full-type", var_full_type);
211 _writeAttribute(json_writer, var_node,
"data-type", String(
dataTypeName(var->dataType())));
212 _writeAttribute(json_writer, var_node,
"dimension", var->dimension());
213 _writeAttribute(json_writer, var_node,
"multi-tag", var->multiTag());
214 _writeAttribute(json_writer, var_node,
"property", var->property());
217 var->data()->computeHash(hash_algo, hash_values);
218 String hash_str = Convert::toHexaString(hash_values);
219 _writeAttribute(json_writer, var_node,
"hash", hash_str);
220 if (hash_context.get()) {
221 hash_context->reset();
222 DataHashInfo hash_info(hash_context.get());
223 var->data()->_commonInternal()->computeHash(hash_info);
224 HashAlgorithmValue hash_value;
225 hash_context->computeHashValue(hash_value);
226 String hash2_str = Convert::toHexaString(
asBytes(hash_value.bytes()));
227 info(6) <<
"Hash=" << hash2_str <<
" old_hash="
228 << hash_str <<
" name=" << var->name();
229 _writeAttribute(json_writer, var_node,
"hash2", hash2_str);
230 _writeAttribute(json_writer, var_node,
"hash-version", hash_info.version());
235 json_writer.endArray();
244void VariableIOWriterMng::
259 for (Integer i = 0, n = meshes.size(); i < n; ++i) {
260 IMesh* mesh = meshes[i];
285String VariableIOWriterMng::
297 json_writer.write(
"version",
static_cast<Int64
>(1));
306 XmlElement json_node(root_element,
"json", json_writer.getBuffer());
308 String s = doc->save();
309 info(6) <<
"META_DATA=" << s;
316void VariableIOWriterMng::
317_writeVariables(IDataWriter* writer,
const VariableCollection& vars,
bool use_hash)
322 m_variable_mng->m_write_observable->notifyAllObservers();
323 writer->beginWrite(vars);
329 for (VariableCollection::Enumerator i(vars); ++i;) {
332 var->notifyBeginWrite();
335 MD5HashAlgorithm md5_hash_algo;
336 SHA1HashAlgorithm sha1_hash_algo;
337 IHashAlgorithm* hash_algo = &md5_hash_algo;
339 hash_algo = &sha1_hash_algo;
342 String meta_data = _generateMetaData(vars, hash_algo);
343 writer->setMetaData(meta_data);
345 for (VariableCollection::Enumerator i(vars); ++i;) {
350 writer->write(var, var->data());
352 catch (
const Exception& ex) {
353 error() <<
"Exception Arcane while VariableMng::writeVariables()"
354 <<
" var=" << var->fullName()
355 <<
" exception=" << ex;
358 catch (
const std::exception& ex) {
359 error() <<
"Exception while VariableMng::writeVariables()"
360 <<
" var=" << var->fullName()
361 <<
" exception=" << ex.what();
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Interface d'écriture des données d'une variable.
Interface d'un algorithme de hashage.
virtual String name() const =0
Nom du maillage.
virtual IParallelMng * parallelMng()=0
Gestionnaire de parallèlisme.
virtual String factoryName() const =0
Nom de la fabrique utilisée pour créer le maillage.
virtual Properties * properties()=0
Propriétés associées à ce maillage.
Interface du gestionnaire de parallélisme pour un sous-domaine.
virtual IParallelMng * sequentialParallelMng()=0
Retourne un gestionnaire de parallélisme séquentiel.
virtual bool isParallel() const =0
Retourne true si l'exécution est parallèle.
Interface du gestionnaire d'un sous-domaine.
Interface d'une variable.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Chaîne de caractères unicode.
Positionne une classe de message.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
UniqueArray< Byte > ByteUniqueArray
Tableau dynamique à une dimension de caractères.
const char * dataTypeName(eDataType type)
Nom du type de donnée.
detail::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets non modifiables.