14#include "arcane/std/internal/BasicWriter.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/IDataCompressor.h"
18#include "arcane/utils/JSONWriter.h"
19#include "arcane/utils/Ref.h"
21#include "arcane/core/IXmlDocumentHolder.h"
22#include "arcane/core/IParallelMng.h"
23#include "arcane/core/IIOMng.h"
24#include "arcane/core/IApplication.h"
25#include "arcane/core/ISerializedData.h"
26#include "arcane/core/IRessourceMng.h"
27#include "arcane/core/ItemGroup.h"
41BasicGenericWriter(IApplication* app,
Int32 version,
42 Ref<KeyValueTextWriter> text_writer)
43: TraceAccessor(app->traceMng())
46, m_text_writer(text_writer)
53void BasicGenericWriter::
54initialize(
const String& path, Int32 rank)
65void BasicGenericWriter::
67 const String& comparison_hash,
bool is_save_values)
70 auto var_data_info = m_variables_data_info.add(var_full_name, sdata);
72 var_data_info->setFileOffset(writer->fileOffset());
73 var_data_info->setComparisonHashValue(comparison_hash);
74 info(4) <<
" SDATA name=" << var_full_name <<
" nb_element=" << sdata->
nbElement()
88 writer->setExtents(var_full_name, extents);
92 if (nb_base_element != 0 && ptr) {
101void BasicGenericWriter::
105 if (m_version >= 3) {
108 String written_uid_name =
String(
"GroupWrittenUid:") + group_full_name;
109 Int64 nb_written_uid = written_unique_ids.
size();
111 m_text_writer->write(written_uid_name,
asBytes(written_unique_ids));
114 String wanted_uid_name =
String(
"GroupWantedUid:") + group_full_name;
115 Int64 nb_wanted_uid = wanted_unique_ids.
size();
117 m_text_writer->write(wanted_uid_name,
asBytes(wanted_unique_ids));
122 String filename = BasicReaderWriterCommon::_getBasicGroupFile(m_path, group_full_name, m_rank);
123 ofstream writer(filename.localstr(), std::ios::out | std::ios::binary);
143void BasicGenericWriter::
146 IApplication* app = m_application;
147 ScopedPtrT<IXmlDocumentHolder> xdoc(app->ressourceMng()->createXmlDocument());
148 XmlNode doc = xdoc->documentNode();
149 XmlElement root(doc,
"variables-data");
150 const IDataCompressor* dc = m_text_writer->dataCompressor().get();
152 root.setAttrValue(
"deflater-service", dc->name());
153 root.setAttrValue(
"min-compress-size", String::fromNumber(dc->minCompressSize()));
155 root.setAttrValue(
"version", String::fromNumber(m_version));
158 JSONWriter::Object main_object(jsw);
159 JSONWriter::Object json_vars(jsw,
"Variables");
160 for (
const auto& i : m_variables_data_info) {
161 Ref<VariableDataInfo> vdi = i.second;
162 XmlNode e = root.createAndAppendElement(
"variable-data");
163 e.setAttrValue(
"full-name", vdi->fullName());
167 if (m_version >= 3) {
169 XmlElement json_var(root,
"variables-data-json", jsw.getBuffer());
172 UniqueArray<Byte> bytes;
174 Int64 length = bytes.length();
175 String key_name =
"Global:OwnMetadata";
177 m_text_writer->write(key_name,
asBytes(bytes.span()));
180 String filename = BasicReaderWriterCommon::_getOwnMetatadaFile(m_path, m_rank);
181 app->ioMng()->writeXmlFile(xdoc.get(), filename);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface of a serialized data.
virtual eDataType baseDataType() const =0
Data type.
virtual Integer nbDimension() const =0
Dimension. 0 for a scalar, 1 for a 1D array, ...
virtual Int64 memorySize() const =0
Indicates the number of bytes that must be allocated to store or read the data.
virtual Int64 nbBaseElement() const =0
Number of base elements.
virtual Int64ConstArrayView extents() const =0
Array containing the number of elements for each dimension.
virtual Int64 nbElement() const =0
Number of elements.
virtual Span< const Byte > constBytes() const =0
Serialized values.
virtual bool isMultiSize() const =0
Indicates if it is a multi-size array. (only relevant if nbDimension()>1).
View of an array of elements of type T.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Unicode character string.
TraceMessage info() const
Flow for an information message.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
void binaryWrite(std::ostream &ostr, const Span< const std::byte > &bytes)
Writes the content of bytes to the stream ostr in binary format.
std::int32_t Int32
Signed integer type of 32 bits.