00001
00002
00004
00005 #ifndef EVENTPRIMITIVESTOSTRINGCONVERTER_H_
00006 #define EVENTPRIMITIVESTOSTRINGCONVERTER_H_
00007
00008 #include "EventPrimitives/EventPrimitives.h"
00009 #ifndef XAOD_STANDALONE
00010 # include "CLHEP/Matrix/GenMatrix.h"
00011 #endif // not XAOD_STANDALONE
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <string>
00015
00016 namespace Amg {
00017
00033 inline double roundWithPrecision( double val, int precision ) {
00034 if( val < 0 && fabs(val)*std::pow(10,precision) < 1. ) return -val;
00035 return val;
00036 }
00037
00038
00039 inline std::string toString( const MatrixX& matrix, int precision = 4, std::string offset="" ){
00040 std::ostringstream sout;
00041
00042 sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
00043 if( matrix.cols() == 1 ){
00044 sout << "(";
00045 for( int i=0;i<matrix.rows();++i ){
00046 double val = roundWithPrecision(matrix(i,0),precision);
00047 sout << val;
00048 if( i != matrix.rows() - 1 ) sout << ", ";
00049 }
00050 sout << ")";
00051 }else{
00052 for( int i=0;i<matrix.rows();++i ){
00053 for( int j=0;j<matrix.cols();++j ){
00054 if( j == 0 ) sout << "(";
00055 double val = roundWithPrecision(matrix(i,j),precision);
00056 sout << val;
00057 if( j == matrix.cols() - 1 ) sout << ")";
00058 else sout << ", ";
00059 }
00060 if( i != matrix.rows() - 1 )
00061 {
00062 sout << std::endl;
00063 sout << offset;
00064 }
00065 }
00066 }
00067 return sout.str();
00068 }
00069
00070 #ifndef XAOD_STANDALONE
00071 inline std::string toString( const CLHEP::HepGenMatrix& matrix, int precision = 4, std::string offset="" ){
00072 std::ostringstream sout;
00073
00074 sout << std::setiosflags(std::ios::fixed) << std::setprecision(precision);
00075 for( int i=0;i<matrix.num_row();++i ){
00076 for( int j=0;j<matrix.num_col();++j ){
00077 if( j == 0 ) sout << "(";
00078 double val = roundWithPrecision(matrix(i+1,j+1),precision);
00079 sout << val;
00080 if( j == matrix.num_col() - 1 ) sout << ")";
00081 else sout << ", ";
00082 }
00083 if( i != matrix.num_row() - 1 )
00084 {
00085 sout << std::endl;
00086 sout << offset;
00087 }
00088 }
00089 return sout.str();
00090 }
00091 #endif // not XAOD_STANDALONE
00092 }
00093
00094 #endif