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"
39BasicGenericWriter(IApplication* app,
Int32 version,
40 Ref<KeyValueTextWriter> text_writer)
41: TraceAccessor(app->traceMng())
44, m_text_writer(text_writer)
51void BasicGenericWriter::
52initialize(
const String& path, Int32 rank)
63void BasicGenericWriter::
65 const String& comparison_hash,
bool is_save_values)
68 auto var_data_info = m_variables_data_info.add(var_full_name, sdata);
70 var_data_info->setFileOffset(writer->fileOffset());
71 var_data_info->setComparisonHashValue(comparison_hash);
72 info(4) <<
" SDATA name=" << var_full_name <<
" nb_element=" << sdata->
nbElement()
86 writer->setExtents(var_full_name, extents);
90 if (nb_base_element != 0 && ptr) {
99void BasicGenericWriter::
103 if (m_version >= 3) {
106 String written_uid_name =
String(
"GroupWrittenUid:") + group_full_name;
107 Int64 nb_written_uid = written_unique_ids.
size();
109 m_text_writer->write(written_uid_name,
asBytes(written_unique_ids));
112 String wanted_uid_name =
String(
"GroupWantedUid:") + group_full_name;
113 Int64 nb_wanted_uid = wanted_unique_ids.
size();
115 m_text_writer->write(wanted_uid_name,
asBytes(wanted_unique_ids));
120 String filename = BasicReaderWriterCommon::_getBasicGroupFile(m_path, group_full_name, m_rank);
121 ofstream writer(filename.localstr(), std::ios::out | std::ios::binary);
141void BasicGenericWriter::
144 IApplication* app = m_application;
145 ScopedPtrT<IXmlDocumentHolder> xdoc(app->ressourceMng()->createXmlDocument());
146 XmlNode doc = xdoc->documentNode();
147 XmlElement root(doc,
"variables-data");
148 const IDataCompressor* dc = m_text_writer->dataCompressor().get();
150 root.setAttrValue(
"deflater-service", dc->name());
151 root.setAttrValue(
"min-compress-size", String::fromNumber(dc->minCompressSize()));
153 root.setAttrValue(
"version", String::fromNumber(m_version));
156 JSONWriter::Object main_object(jsw);
157 JSONWriter::Object json_vars(jsw,
"Variables");
158 for (
const auto& i : m_variables_data_info) {
159 Ref<VariableDataInfo> vdi = i.second;
160 XmlNode e = root.createAndAppendElement(
"variable-data");
161 e.setAttrValue(
"full-name", vdi->fullName());
165 if (m_version >= 3) {
167 XmlElement json_var(root,
"variables-data-json", jsw.getBuffer());
170 UniqueArray<Byte> bytes;
172 Int64 length = bytes.length();
173 String key_name =
"Global:OwnMetadata";
175 m_text_writer->write(key_name,
asBytes(bytes.span()));
178 String filename = BasicReaderWriterCommon::_getOwnMetatadaFile(m_path, m_rank);
179 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.