14#include "arcane/std/internal/BasicReader.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/StringBuilder.h"
18#include "arcane/utils/IDataCompressor.h"
19#include "arcane/utils/JSONReader.h"
20#include "arcane/utils/Ref.h"
22#include "arcane/core/IApplication.h"
23#include "arcane/core/IXmlDocumentHolder.h"
24#include "arcane/core/IIOMng.h"
25#include "arcane/core/IData.h"
26#include "arcane/core/ArcaneException.h"
27#include "arcane/core/ISerializedData.h"
28#include "arcane/core/XmlNodeList.h"
40BasicGenericReader(IApplication* app,
Int32 version, Ref<KeyValueTextReader> text_reader)
41: TraceAccessor(app->traceMng())
43, m_text_reader(text_reader)
51void BasicGenericReader::
52initialize(
const String& path,
Int32 rank)
61 info(4) <<
"BasicGenericReader::initialize known_version=" << m_version;
63 ScopedPtrT<IXmlDocumentHolder> xdoc;
66 if (!m_text_reader.get())
69 if (m_text_reader->dataCompressor().get())
70 dc_name = m_text_reader->dataCompressor()->name();
71 info(4) <<
"BasicGenericReader::initialize data_compressor=" << dc_name;
76 String main_filename = BasicReaderWriterCommon::_getBasicVariableFile(m_version, m_path, rank);
77 Int64 meta_data_size = 0;
78 String key_name =
"Global:OwnMetadata";
79 m_text_reader->getExtents(key_name,
Int64ArrayView(1, &meta_data_size));
80 UniqueArray<std::byte> bytes(meta_data_size);
81 m_text_reader->read(key_name, bytes);
82 info(4) <<
"Reading own metadata rank=" << rank <<
" from database";
83 xdoc = IXmlDocumentHolder::loadFromBuffer(bytes,
"OwnMetadata", traceMng());
86 StringBuilder filename = BasicReaderWriterCommon::_getOwnMetatadaFile(m_path, m_rank);
87 info(4) <<
"Reading own metadata rank=" << rank <<
" file=" << filename;
88 IApplication* app = m_application;
89 xdoc = app->ioMng()->parseXmlFile(filename);
91 XmlNode root = xdoc->documentNode().documentElement();
92 XmlNodeList variables_elem = root.children(
"variable-data");
93 String deflater_name = root.attrValue(
"deflater-service");
94 String hash_algorithm_name = root.attrValue(
"hash-algorithm-service");
95 String version_id = root.attrValue(
"version",
false);
96 info(4) <<
"Infos from metadata deflater-service=" << deflater_name
97 <<
" hash-algorithm-service=" << hash_algorithm_name
98 <<
" version=" << version_id;
99 if (version_id.null() || version_id ==
"1")
103 else if (version_id ==
"2")
107 else if (version_id ==
"3")
113 ARCANE_FATAL(
"Unsupported version '{0}' (max=3)", version_id);
115 Ref<IDataCompressor> deflater;
116 if (!deflater_name.null())
117 deflater = BasicReaderWriterCommon::_createDeflater(m_application, deflater_name);
119 Ref<IHashAlgorithm> hash_algorithm;
120 if (!hash_algorithm_name.null())
121 hash_algorithm = BasicReaderWriterCommon::_createHashAlgorithm(m_application, hash_algorithm_name);
125 String json_variables_elem = root.child(
"variables-data-json").value();
126 if (do_json && !json_variables_elem.empty()) {
127 JSONDocument json_doc;
128 json_doc.parse(json_variables_elem.bytes(),
"Internal variables data");
129 JSONValue json_root = json_doc.root();
130 JSONValue json_vars = json_root.expectedChild(
"Variables");
131 for (JSONKeyValue kv : json_vars.keyValueChildren()) {
132 String var_full_name = kv.name();
133 m_variables_data_info.add(var_full_name, kv.value());
137 for (
const XmlNode& n : variables_elem) {
138 String var_full_name = n.attrValue(
"full-name");
139 m_variables_data_info.add(var_full_name, n);
143 if (!m_text_reader.get()) {
144 String main_filename = BasicReaderWriterCommon::_getBasicVariableFile(m_version, m_path, rank);
145 m_text_reader =
makeRef(
new KeyValueTextReader(traceMng(), main_filename, m_version));
152 m_text_reader->setDataCompressor(deflater);
153 if (hash_algorithm.get())
154 m_text_reader->setHashAlgorithm(hash_algorithm);
160Ref<VariableDataInfo> BasicGenericReader::
161_getVarInfo(
const String& full_name)
163 Ref<VariableDataInfo> vdi = m_variables_data_info.find(full_name);
166 "Can not find own metadata infos for data var={0} rank={1}", full_name, m_rank);
173void BasicGenericReader::
174readData(
const String& var_full_name, IData* data)
176 KeyValueTextReader* reader = m_text_reader.get();
177 String vname = var_full_name;
178 Ref<VariableDataInfo> vdi = _getVarInfo(vname);
180 reader->setFileOffset(vdi->fileOffset());
182 eDataType data_type = vdi->baseDataType();
183 Int64 memory_size = vdi->memorySize();
184 Integer dimension_array_size = vdi->dimensionArraySize();
185 Int64 nb_element = vdi->nbElement();
186 Integer nb_dimension = vdi->nbDimension();
187 Int64 nb_base_element = vdi->nbBaseElement();
188 bool is_multi_size = vdi->isMultiSize();
189 UniqueArray<Int64> extents(dimension_array_size);
190 reader->getExtents(var_full_name, extents.view());
191 ArrayShape shape = vdi->shape();
194 nb_base_element, is_multi_size, extents, shape));
196 Int64 storage_size = sd->memorySize();
197 info(4) <<
" READ DATA storage_size=" << storage_size <<
" DATA=" << data;
199 data->allocateBufferForSerializedData(sd.get());
201 if (storage_size != 0)
204 data->assignSerializedData(sd.get());
210void BasicGenericReader::
211readItemGroup(
const String& group_full_name, Int64Array& written_unique_ids,
212 Int64Array& wanted_unique_ids)
214 if (m_version >= 3) {
216 String written_uid_name = String(
"GroupWrittenUid:") + group_full_name;
217 Int64 nb_written_uid = 0;
218 m_text_reader->getExtents(written_uid_name,
Int64ArrayView(1, &nb_written_uid));
219 written_unique_ids.resize(nb_written_uid);
220 m_text_reader->read(written_uid_name,
asWritableBytes(written_unique_ids.span()));
223 String wanted_uid_name = String(
"GroupWantedUid:") + group_full_name;
224 Int64 nb_wanted_uid = 0;
225 m_text_reader->getExtents(wanted_uid_name,
Int64ArrayView(1, &nb_wanted_uid));
226 wanted_unique_ids.resize(nb_wanted_uid);
227 m_text_reader->read(wanted_uid_name,
asWritableBytes(wanted_unique_ids.span()));
232 info(5) <<
"READ GROUP " << group_full_name;
233 String filename = BasicReaderWriterCommon::_getBasicGroupFile(m_path, group_full_name, m_rank);
234 std::ifstream reader(filename.localstr(), std::ios::in | std::ios::binary);
239 info(5) <<
"NB_WRITTEN_UNIQUE_ID = " << nb_unique_id;
240 written_unique_ids.resize(nb_unique_id);
247 info(5) <<
"NB_WANTED_UNIQUE_ID = " << nb_unique_id;
248 wanted_unique_ids.resize(nb_unique_id);
256String BasicGenericReader::
257comparisonHashValue(
const String& var_full_name)
const
259 Ref<VariableDataInfo> vdi = m_variables_data_info.find(var_full_name);
261 return vdi->comparisonHashValue();
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Ref< ISerializedData > arcaneCreateSerializedDataRef(eDataType data_type, Int64 memory_size, Integer nb_dim, Int64 nb_element, Int64 nb_base_element, bool is_multi_size, Int64ConstArrayView dimensions)
Créé des données sérialisées.
ArrayView< Int64 > Int64ArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
eDataType
Type d'une donnée.
Int32 Integer
Type représentant un entier.
void binaryRead(std::istream &istr, const Span< std::byte > &bytes)
Lit en binaire le contenu de bytes depuis le flot istr.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
detail::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets modifiables.