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"
39class ArcaneCurveWriter
54 std::ofstream m_stream;
73 virtual String name()
const {
return "ArcaneCurveWriter"; }
89 Int64 offset = m_p->m_stream.tellp();
90 m_p->m_stream.write((
const char*)values.
data(), values.
size() *
sizeof(T));
99ArcaneCurveWriter::Impl::
102, m_file_name(
"curves")
104 String full_path = path +
"/" + m_file_name +
".acv";
105 info() <<
"Begin write curves full_path=" << full_path;
106 m_stream.open(full_path.localstr(), std::ios::trunc);
108 warning() <<
"Can not open file '" << full_path <<
"' for writing curves";
109 m_curves_doc = app->ressourceMng()->createXmlDocument();
110 XmlNode doc = m_curves_doc->documentNode();
111 m_root_element = XmlElement(doc,
"curves");
126 if (!m_output_path.empty())
127 m_output_path = path;
129 info() << A_FUNCNAME <<
"Begin write curves path=" << path;
130 m_p =
new Impl(subDomain()->application(),
traceMng(), path);
134 m_p->m_root_element.setAttrValue(
"times-offset", String::fromNumber(time_offset));
135 m_p->m_root_element.setAttrValue(
"times-size", String::fromNumber(infos.
times().
size()));
136 m_p->m_root_element.setAttrValue(
"x",
"iteration");
142void ArcaneCurveWriter::
151 header[3] = (
Byte)122;
155 header[4] = (
Byte)m_version;
160 Int32 v = 0x01020304;
162 for (
Integer i = 0; i < 4; ++i)
163 header[8 + i] = ptr[i];
164 m_p->m_stream.write((
const char*)header, 12);
174 m_p->m_curves_doc->save(bytes);
175 if (m_version == 2) {
177 write_info[0] = _write(bytes.constView());
178 write_info[1] = bytes.largeSize();
182 else if (m_version == 1) {
184 write_info[0] = CheckedConvert::toInt32(_write(bytes.constView()));
185 write_info[1] = bytes.size();
190 ARCANE_FATAL(
"Invalid version {0} (valid values are '1' or '2')", m_version);
192 info(4) <<
"End writing curves";
209 Int32 range_iterations[2];
214 Int32 first_iter = iterations[0];
215 Int32 last_iter = iterations[nb_val - 1];
216 Int32 diff = 1 + last_iter - first_iter;
219 if (diff == nb_val) {
220 range_iterations[0] = first_iter;
221 range_iterations[1] = last_iter;
225 Int64 iteration_offset = _write(iterations);
227 XmlNode node = m_p->m_root_element.createAndAppendElement(
"curve");
231 if (infos.subDomain() != NULL_SUB_DOMAIN_ID) {
232 name =
"SD" + String::fromNumber(infos.subDomain()) +
"_" +
name;
234 if (infos.hasSupport()) {
235 name = infos.support() +
"_" +
name;
239 node.
setAttrValue(
"iterations-offset", String::fromNumber(iteration_offset));
240 node.
setAttrValue(
"iterations-size", String::fromNumber(iterations.
size()));
241 node.
setAttrValue(
"values-offset", String::fromNumber(values_offset));
245 if (infos.hasSupport()) {
248 if (infos.subDomain() != NULL_SUB_DOMAIN_ID) {
249 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.