CMS 3D CMS Logo

round_string.h
Go to the documentation of this file.
1 #ifndef ROUND_STRING_H
2 #define ROUND_STRING_H
3 
4 #include <iomanip>
5 #include <sstream>
6 #include <string>
7 #include <sstream>
8 #include <cmath>
9 
10 struct round_string {
11  template<class T>
12  std::string operator()(const std::pair<T,T> x) const {
13  int val_digit(0), err_digit(0);
14 
15  if(x.first != 0) {
16  while( fabs(x.first) / pow(10, val_digit) < 1 ) val_digit--;
17  while( fabs(x.first) / pow(10, val_digit) > 10 )val_digit++;
18  }
19  if(x.second != 0 ) {
20  while( x.second / pow(10,err_digit) < 0.95 ) err_digit--;
21  while( x.second / pow(10,err_digit) > 9.50 ) err_digit++;
22  }
23 
24  if(val_digit<err_digit) val_digit=err_digit;
25  const bool scinot = (val_digit<-1 || err_digit>0);
26 
27  std::stringstream s;
28  s << std::fixed << std::setprecision( scinot? val_digit-err_digit : -err_digit)
29  << ( scinot? x.first/pow(10,val_digit) : x.first )
30  << "("
31  << unsigned(x.second / pow(10,err_digit) + 0.5) << ")";
32  if(scinot) s<< "e" << (val_digit>0 ? "+" : "") << val_digit;
33 
34  return s.str();
35  }
36 };
37 
38 #endif
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
round_string::operator()
std::string operator()(const std::pair< T, T > x) const
Definition: round_string.h:12
DDAxes::x
alignCSCRings.s
s
Definition: alignCSCRings.py:92
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
round_string
Definition: round_string.h:10
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30