Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
SimpleTableWriterHelper.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* SimpleTableWriterHelper.h (C) 2000-2023 */
9/* */
10/* Class allowing writing a SimpleTableInternal to a file. */
11/* Simplifies the use of the writer by managing multiprocessing and the */
12/* names of files/directories. */
13/*---------------------------------------------------------------------------*/
14#ifndef ARCANE_STD_SIMPLETABLEWRITERHELPER_H
15#define ARCANE_STD_SIMPLETABLEWRITERHELPER_H
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19#include "arcane/core/ISimpleTableInternalMng.h"
20#include "arcane/core/ISimpleTableReaderWriter.h"
21#include "arcane/core/ISimpleTableWriterHelper.h"
22
23#include "arcane/core/Directory.h"
24#include "arcane/utils/FatalErrorException.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35class SimpleTableWriterHelper
37{
38 public:
39
40 SimpleTableWriterHelper(const Ref<ISimpleTableReaderWriter>& simple_table_reader_writer)
41 : m_simple_table_internal(simple_table_reader_writer->internal())
42 , m_simple_table_reader_writer(simple_table_reader_writer)
43 , m_name_output_directory("")
44 , m_name_table_without_computation("")
45 , m_root()
46 , m_name_table_computed(false)
47 , m_name_output_directory_computed(false)
48 , m_name_table_one_file_by_ranks_permited(false)
49 , m_name_output_directory_one_file_by_ranks_permited(false)
50 {
51 if (simple_table_reader_writer.isNull())
52 ARCANE_FATAL("The reference passed as a parameter is Null.");
53 }
54
55 SimpleTableWriterHelper()
56 : m_simple_table_internal()
57 , m_simple_table_reader_writer()
58 , m_name_output_directory("")
59 , m_name_table_without_computation("")
60 , m_root()
61 , m_name_table_computed(false)
62 , m_name_output_directory_computed(false)
63 , m_name_table_one_file_by_ranks_permited(false)
64 , m_name_output_directory_one_file_by_ranks_permited(false)
65 {
66 }
67
68 virtual ~SimpleTableWriterHelper() = default;
69
70 public:
71
72 bool init(const Directory& root_directory, const String& table_name, const String& directory_name) override;
73
74 void print(Integer rank) override;
75 bool writeFile(Integer rank) override;
76 bool writeFile(const Directory& root_directory, Integer rank) override;
77
78 Integer precision() override;
79 void setPrecision(Integer precision) override;
80
81 bool isFixed() override;
82 void setFixed(bool fixed) override;
83
84 bool isForcedToUseScientificNotation() override;
85 void setForcedToUseScientificNotation(bool use_scientific) override;
86
87 String outputDirectory() override;
89 void setOutputDirectory(const String& directory) override;
90
91 String tableName() override;
93 void setTableName(const String& name) override;
94
95 String fileName() override;
96
97 Directory outputPath() override;
98 Directory rootPath() override;
99
100 String fileType() override;
101
102 bool isOneFileByRanksPermited() override;
103
105
107 void setReaderWriter(const Ref<ISimpleTableReaderWriter>& simple_table_reader_writer) override;
108
109 protected:
110
111 void _computeTableName();
112 void _computeOutputDirectory();
113 String _computeName(String name, bool& one_file_by_ranks_permited);
114
115 protected:
116
117 Ref<SimpleTableInternal> m_simple_table_internal;
118 Ref<ISimpleTableReaderWriter> m_simple_table_reader_writer;
119
120 String m_name_output_directory;
121 String m_name_output_directory_without_computation;
122 String m_name_table_without_computation;
123
124 Directory m_root;
125
126 bool m_name_table_computed;
127 bool m_name_output_directory_computed;
128
129 // Booleans indicating whether the file name or the directory name
130 // contains the "@proc_id@" symbol which allows file writing by
131 // multiple processes.
132 bool m_name_table_one_file_by_ranks_permited;
133 bool m_name_output_directory_one_file_by_ranks_permited;
134};
135
136/*---------------------------------------------------------------------------*/
137/*---------------------------------------------------------------------------*/
138
139} // End namespace Arcane
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144#endif
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Class managing a directory.
Definition Directory.h:36
Class interface for writing a file using ISimpleTableReaderWriter. Provides methods for managing para...
bool isNull() const
Indicates if the counter references a non-null instance.
Reference to an instance.
bool init(const Directory &root_directory, const String &table_name, const String &directory_name) override
Method to initialize the object. Specifically, the table name and the directory name that will contai...
String fileType() override
Method to know the file type that will be used.
void setPrecision(Integer precision) override
Method to modify the print precision.
String outputDirectory() override
Method to retrieve the directory name where the tables will be placed.
void setTableName(const String &name) override
Method to set the table name.
void setFixed(bool fixed) override
Method to set or unset the 'std::fixed' flag.
void print(Integer rank) override
Method to display the table.
void setForcedToUseScientificNotation(bool use_scientific) override
Method to set or unset the 'std::scientific' flag.
Ref< SimpleTableInternal > internal() override
Method to retrieve a reference to the SimpleTableInternal object used.
bool isForcedToUseScientificNotation() override
Method to check if the 'std::scientific' flag is active for writing values.
String fileName() override
Method to retrieve the file name.
String outputDirectoryWithoutComputation() override
Method to retrieve the directory name as it was previously provided.
Ref< ISimpleTableReaderWriter > readerWriter() override
Method to retrieve a reference to the ISimpleTableReaderWriter object used.
void setOutputDirectory(const String &directory) override
Method to set the directory where the tables should be saved.
bool writeFile(Integer rank) override
String tableName() override
Method to retrieve the table name.
String tableNameWithoutComputation() override
Method to retrieve the table name as it was previously provided.
void setReaderWriter(const Ref< ISimpleTableReaderWriter > &simple_table_reader_writer) override
Method to set a reference to an ISimpleTableReaderWriter.
Integer precision() override
Method to retrieve the precision currently used for writing values.
Directory rootPath() override
Method to retrieve the path where the implementation saves these tables.
bool isFixed() override
Method to check if the 'std::fixed' flag is active for writing values.
Directory outputPath() override
Method to retrieve the path where the tables will be saved.
String _computeName(String name, bool &one_file_by_ranks_permited)
Method allowing replacement of name symbols by their value.
bool isOneFileByRanksPermited() override
Method to check if the parameters currently held by the implementation allow it to write a file per p...
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.