ATLAS Offline Software
Loading...
Searching...
No Matches
EventPrimitivesToStringConverter.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6// EventPrimitivesToStringConverter.h, (c) ATLAS Detector software
8
9#ifndef EVENTPRIMITIVESTOSTRINGCONVERTER_H_
10#define EVENTPRIMITIVESTOSTRINGCONVERTER_H_
11
13#include <iomanip>
14#include <iostream>
15#include <string>
16#include <string_view>
17#include <cmath>
18
19namespace Amg {
20
35
36inline double roundWithPrecision(double val, int precision) {
37 if (val < 0 && std::abs(val) * std::pow(10, precision) < 1.)
38 return -val;
39 return val;
40}
41
42inline std::string toString(const MatrixX& matrix, int precision = 4,
43 std::string_view offset = "") {
44 std::ostringstream sout;
45
46 sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
47 if (matrix.cols() == 1) {
48 sout << "(";
49 for (int i = 0; i < matrix.rows(); ++i) {
50 double val = roundWithPrecision(matrix(i, 0), precision);
51 sout << val;
52 if (i != matrix.rows() - 1)
53 sout << ", ";
54 }
55 sout << ")";
56 } else {
57 for (int i = 0; i < matrix.rows(); ++i) {
58 for (int j = 0; j < matrix.cols(); ++j) {
59 if (j == 0)
60 sout << "(";
61 double val = roundWithPrecision(matrix(i, j), precision);
62 sout << val;
63 if (j == matrix.cols() - 1)
64 sout << ")";
65 else
66 sout << ", ";
67 }
68 if (i != matrix.rows() - 1) { // make the end line and the offset in the next line
69 sout << std::endl;
70 sout << offset;
71 }
72 }
73 }
74 return sout.str();
75}
76
77} // namespace Amg
78
79#endif /* EVENTPRIMITIVESTOSTRINGCONVERTER_H_ */
Definition of ATLAS Math & Geometry primitives (Amg).
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
double roundWithPrecision(double val, int precision)
EventPrimitvesToStringConverter.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.