14#include "arcane/utils/ArrayView.h"
15#include "arcane/utils/ScopedPtr.h"
16#include "arcane/utils/CheckedConvert.h"
18#include "arcane/core/ITimeHistoryCurveWriter2.h"
19#include "arcane/core/BasicService.h"
20#include "arcane/core/FactoryService.h"
21#include "arcane/core/IApplication.h"
22#include "arcane/core/IRessourceMng.h"
23#include "arcane/core/IXmlDocumentHolder.h"
24#include "arcane/core/XmlNode.h"
41class ArcaneCurveWriter
56 std::ofstream m_stream;
75 virtual String name()
const {
return "ArcaneCurveWriter"; }
91 Int64 offset = m_p->m_stream.tellp();
92 m_p->m_stream.write((
const char*)values.
data(), values.
size() *
sizeof(T));
101ArcaneCurveWriter::Impl::
104, m_file_name(
"curves")
106 String full_path = path +
"/" + m_file_name +
".acv";
107 info() <<
"Begin write curves full_path=" << full_path;
108 m_stream.open(full_path.localstr(), std::ios::trunc);
110 warning() <<
"Can not open file '" << full_path <<
"' for writing curves";
111 m_curves_doc = app->ressourceMng()->createXmlDocument();
112 XmlNode doc = m_curves_doc->documentNode();
113 m_root_element = XmlElement(doc,
"curves");
128 if (!m_output_path.empty())
129 m_output_path = path;
131 info() << A_FUNCNAME <<
"Begin write curves path=" << path;
132 m_p =
new Impl(subDomain()->application(),
traceMng(), path);
136 m_p->m_root_element.setAttrValue(
"times-offset", String::fromNumber(time_offset));
137 m_p->m_root_element.setAttrValue(
"times-size", String::fromNumber(infos.
times().
size()));
138 m_p->m_root_element.setAttrValue(
"x",
"iteration");
144void ArcaneCurveWriter::
153 header[3] = (
Byte)122;
157 header[4] = (
Byte)m_version;
162 Int32 v = 0x01020304;
164 for (
Integer i = 0; i < 4; ++i)
165 header[8 + i] = ptr[i];
166 m_p->m_stream.write((
const char*)header, 12);
176 m_p->m_curves_doc->save(bytes);
177 if (m_version == 2) {
179 write_info[0] = _write(bytes.constView());
180 write_info[1] = bytes.largeSize();
184 else if (m_version == 1) {
186 write_info[0] = CheckedConvert::toInt32(_write(bytes.constView()));
187 write_info[1] = bytes.size();
192 ARCANE_FATAL(
"Invalid version {0} (valid values are '1' or '2')", m_version);
194 info(4) <<
"End writing curves";
211 Int32 range_iterations[2];
216 Int32 first_iter = iterations[0];
217 Int32 last_iter = iterations[nb_val - 1];
218 Int32 diff = 1 + last_iter - first_iter;
221 if (diff == nb_val) {
222 range_iterations[0] = first_iter;
223 range_iterations[1] = last_iter;
227 Int64 iteration_offset = _write(iterations);
229 XmlNode node = m_p->m_root_element.createAndAppendElement(
"curve");
233 if (infos.subDomain() != NULL_SUB_DOMAIN_ID) {
234 name =
"SD" + String::fromNumber(infos.subDomain()) +
"_" +
name;
236 if (infos.hasSupport()) {
237 name = infos.support() +
"_" +
name;
241 node.
setAttrValue(
"iterations-offset", String::fromNumber(iteration_offset));
242 node.
setAttrValue(
"iterations-size", String::fromNumber(iterations.
size()));
243 node.
setAttrValue(
"values-offset", String::fromNumber(values_offset));
247 if (infos.hasSupport()) {
250 if (infos.subDomain() != NULL_SUB_DOMAIN_ID) {
251 node.
setAttrValue(
"sub-domain", String::fromNumber(infos.subDomain()));
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCANE_REGISTER_SUB_DOMAIN_FACTORY(aclass, ainterface, aname)
Registers a factory service for the class aclass.
Writing curves in the specific Arcane format.
virtual void setOutputPath(const String &path)
Base directory where curves will be written.
virtual String name() const
Writer name.
virtual String outputPath() const
Base directory where curves will be written.
virtual void endWrite()
Notify the end of writing.
virtual void build()
Build-level construction of the service.
virtual void beginWrite(const TimeHistoryCurveWriterInfo &infos)
Notify the start of writing.
virtual void writeCurve(const TimeHistoryCurveInfo &infos)
Write a curve.
Constant view of an array of type T.
constexpr const_pointer data() const noexcept
Pointer to the allocated memory.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface for a curve writer.
Encapsulation of an automatically destructing pointer.
Structure containing the information to create a service.
Unicode character string.
String clone() const
Clones this string.
Information for writing a curve.
Int32ConstArrayView iterations() const
List of iterations.
const String & name() const
Curve name.
RealConstArrayView values() const
List of curve values.
Integer subSize() const
Number of values per time step.
Information about writing curves.
String path() const
Path to write the data (unless specifically overridden by the service via ITimeHistoryCurveWriter2::s...
RealConstArrayView times() const
List of times.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage info() const
Flow for an information message.
TraceMessage warning() const
Flow for a warning message.
ITraceMng * traceMng() const
Trace manager.
void setAttrValue(const String &name, const String &value)
Sets the attribute name to the value value.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
UniqueArray< Byte > ByteUniqueArray
Dynamic 1D array of characters.
unsigned char Byte
Type of a byte.
std::int32_t Int32
Signed integer type of 32 bits.