PandA-2024.02
translator.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
43 #ifndef TRANSLATOR_HPP
44 #define TRANSLATOR_HPP
45 
47 #include <ios>
48 #include <list>
49 #include <string>
50 #include <vector>
51 
53 #include "custom_map.hpp"
54 #include "custom_set.hpp"
55 #include "refcount.hpp"
56 #include <boost/preprocessor/facilities/empty.hpp>
57 #include <boost/preprocessor/seq/for_each.hpp>
58 
64 enum class Parameters_FileFormat;
67 
68 #define TEXT_FORMAT (text)(number)(exponential)
69 
70 #define TF_ENUM(r, data, elem) BOOST_PP_CAT(TF_, elem),
71 
72 #define COMPARISON_OPERATOR (abs_le)
73 
74 #define CO_ENUM(r, data, elem) BOOST_PP_CAT(CO_, elem),
75 
76 #define TOTAL_FORMAT (average)(overall)(none)
77 
78 #define TOF_ENUM(r, data, elem) BOOST_PP_CAT(TOF_, elem),
79 
84 {
85  private:
88 
91 
94  {
95  public:
97  using TextFormat = enum { BOOST_PP_SEQ_FOR_EACH(TF_ENUM, BOOST_PP_EMPTY, TEXT_FORMAT) };
98 
101 
103  using TotalFormat = enum { BOOST_PP_SEQ_FOR_EACH(TOF_ENUM, BOOST_PP_EMPTY, TOTAL_FORMAT) };
104 
105  private:
108 
111 
114 
115  public:
117  std::string column_name;
118 
120  std::vector<std::string> columns_prefix;
121 
123  std::string source_name;
124 
126  std::string column_alignment;
127 
130 
132  std::streamsize precision;
133 
136 
139 
142 
147 
152  static TextFormat get_TF(const std::string& string);
153 
158  static ComparisonOperator get_CO(const std::string& string);
159 
164  static TotalFormat GetTotalFormat(const std::string& string);
165 
173  static bool Compare(const long double A, const ComparisonOperator comparator, const long double B);
174  };
175 
181 
187  std::string get_exponential_notation(const std::string& input) const;
188 
193  static void replace_underscore(std::string& ioString);
194 
201  void read_column_formats(const XMLDomParserRef parser, std::list<LatexColumnFormat>& latex_column_formats,
202  size_t& max_column_width) const;
203 
204  public:
209  explicit Translator(const ParameterConstRef Param);
210 
217  void
218  write_to_csv(const std::map<std::string, CustomOrderedSet<std::string>>& tags,
219  const CustomUnorderedMap<
220  std::string,
222  const std::string& file_name) const;
223 
229  void write_to_csv(const std::map<std::string, CustomMap<std::string, std::string>>& results,
230  const std::string& file_name) const;
231 
238  void
239  write_to_pa(const std::map<std::string, CustomOrderedSet<std::string>>& tags,
240  const CustomUnorderedMap<
241  std::string,
243  const std::string& file_name) const;
244 
250  void write_to_latex(std::map<std::string, CustomMap<std::string, std::string>>& results,
251  const Parameters_FileFormat input_format, const std::string& file_name) const;
252 
261  void merge_pa(
262  const std::map<std::string, CustomOrderedSet<std::string>>& tags,
263  const CustomUnorderedMap<std::string, CustomOrderedSet<std::string>>& keys,
264  const CustomUnorderedMap<
266  input_data,
267  const CustomUnorderedMap<
269  merge_data,
270  CustomUnorderedMap<std::string,
272  output_data) const;
273 
280  static void AggregateAndClean(std::map<std::string, std::map<std::string, long double>>& data,
282 };
283 
285 #endif
static CustomUnorderedMap< std::string, TotalFormat > string_to_TOF
Map string->enum for total format.
Definition: translator.hpp:113
std::vector< std::string > columns_prefix
The prefix of the columns.
Definition: translator.hpp:120
static CustomUnorderedMap< std::string, TextFormat > string_to_TF
Map string->enum for text format.
Definition: translator.hpp:107
REF_FORWARD_DECL(XMLDomParser)
TVMValue param[3]
static TextFormat get_TF(const std::string &string)
Given a string return the corresponding enum.
CONSTREF_FORWARD_DECL(Parameter)
void merge_pa(const std::map< std::string, CustomOrderedSet< std::string >> &tags, const CustomUnorderedMap< std::string, CustomOrderedSet< std::string >> &keys, const CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &input_data, const CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &merge_data, CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &output_data) const
Merget profiling analysis.
Definition: translator.cpp:826
static void replace_underscore(std::string &ioString)
Replace &#39;_&#39; with &#39; &#39;.
Definition: translator.cpp:943
int input[SIZE]
Definition: hash.h:1
std::string column_alignment
The alignment of the column.
Definition: translator.hpp:126
int debug_level
the debug level
Definition: translator.hpp:90
void write_to_latex(std::map< std::string, CustomMap< std::string, std::string >> &results, const Parameters_FileFormat input_format, const std::string &file_name) const
Write data in latex table format.
Definition: translator.cpp:259
CustomOrderedMap< T, U > CustomMap
Definition: custom_map.hpp:167
#define COMPARISON_OPERATOR
Definition: translator.hpp:72
#define CO_ENUM(r, data, elem)
Definition: translator.hpp:74
enum { BOOST_PP_SEQ_FOR_EACH(TOF_ENUM, BOOST_PP_EMPTY, TOTAL_FORMAT) } TotalFormat
Total format.
Definition: translator.hpp:103
static TotalFormat GetTotalFormat(const std::string &string)
Given a string return the corresponding enum.
void read_column_formats(const XMLDomParserRef parser, std::list< LatexColumnFormat > &latex_column_formats, size_t &max_column_width) const
Read latex column format from xml.
Definition: translator.cpp:981
redefinition of map to manage ordered/unordered structures
std::string source_name
The xml name of this column.
Definition: translator.hpp:123
#define TEXT_FORMAT
Definition: translator.hpp:68
#define A
Definition: generate.c:13
void get_normalization(CustomUnorderedMap< std::string, long double > &normalization) const
Read normalization file.
Definition: translator.cpp:885
CustomUnorderedSet< std::string > compared_columns
The columns with which this has to be compared.
Definition: translator.hpp:135
std::string get_exponential_notation(const std::string &input) const
Return a number in latex exponential notation.
Definition: translator.cpp:948
std::streamsize precision
The precision of the number.
Definition: translator.hpp:132
static CustomUnorderedMap< std::string, ComparisonOperator > string_to_CO
Map string->enum for comparison operator.
Definition: translator.hpp:110
const ParameterConstRef Param
the set of parameters
Definition: translator.hpp:87
TotalFormat total_format
The format of the total of this column.
Definition: translator.hpp:141
enum { BOOST_PP_SEQ_FOR_EACH(CO_ENUM, BOOST_PP_EMPTY, COMPARISON_OPERATOR) } ComparisonOperator
Comparison operator.
Definition: translator.hpp:100
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
std::string column_name
The name of the column.
Definition: translator.hpp:117
LatexColumnFormat()
Constructor.
Definition: translator.cpp:97
static bool Compare(const long double A, const ComparisonOperator comparator, const long double B)
Return A operator B.
Definition: translator.cpp:154
redefinition of set to manage ordered/unordered structures
enum { BOOST_PP_SEQ_FOR_EACH(TF_ENUM, BOOST_PP_EMPTY, TEXT_FORMAT) } TextFormat
Text format.
Definition: translator.hpp:97
TextFormat text_format
The text format of the column.
Definition: translator.hpp:129
XML DOM parser.
void write_to_csv(const std::map< std::string, CustomOrderedSet< std::string >> &tags, const CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &results, const std::string &file_name) const
Write rtl data in csv format.
#define TOF_ENUM(r, data, elem)
Definition: translator.hpp:78
Class describing the characteristic of a column of latex table.
Definition: translator.hpp:93
Translator(const ParameterConstRef Param)
Constructor.
Definition: translator.cpp:171
static void AggregateAndClean(std::map< std::string, std::map< std::string, long double >> &data, CustomOrderedSet< std::string > &column_names, const ParameterConstRef param)
Collapse columns of data considering super classes and remove selected rows.
Template definition of refcount.
Class to translate data from a format to another one.
Definition: translator.hpp:83
coord_t input_data[TEST_COUNT][2]
Definition: cordic_test.cpp:44
void write_to_pa(const std::map< std::string, CustomOrderedSet< std::string >> &tags, const CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &results, const std::string &file_name) const
Write profiling analysis to pa.
Definition: translator.cpp:214
#define TF_ENUM(r, data, elem)
Definition: translator.hpp:70
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
Parameters_FileFormat
File formats.
Definition: Parameter.hpp:261
absl::node_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapStable
Definition: custom_map.hpp:152
ComparisonOperator comparison_operator
The operator of the comparison.
Definition: translator.hpp:138
#define B
Definition: generate.c:14
#define TOTAL_FORMAT
Definition: translator.hpp:76
static ComparisonOperator get_CO(const std::string &string)
Given a string return the corresponding enum.

Generated on Mon Feb 12 2024 13:02:51 for PandA-2024.02 by doxygen 1.8.13