CMS 3D CMS Logo

DDTypes.cc
Go to the documentation of this file.
3 
4 #include <iostream>
5 #include <utility>
6 
7 using namespace geant_units;
8 using namespace geant_units::operators;
9 
10 
12 
13 std::ostream & operator<<(std::ostream & os, const DDNumericArguments & t)
14 {
15  DDNumericArguments::const_iterator it(t.begin()), ed(t.end());
16  for(; it != ed; ++it) {
17  os << it->first << '=' << it->second << std::endl;
18  }
19  return os;
20 }
21 
22 std::ostream & operator<<(std::ostream & os, const DDStringArguments & t)
23 {
24  DDStringArguments::const_iterator it(t.begin()), ed(t.end());
25  for(; it != ed; ++it) {
26  os << it->first << '=' << it->second << std::endl;
27  }
28  return os;
29 }
30 
31 std::ostream & operator<<(std::ostream & os, const DDVectorArguments & t)
32 {
33  DDVectorArguments::const_iterator it(t.begin()), ed(t.end());
34  for(; it != ed; ++it) {
35  os << it->first << ": ";
36  std::vector<double>::const_iterator vit(it->second.begin()), ved(it->second.end());
37  for(;vit!=ved;++vit) {
38  os << *vit << ' ';
39  }
40  os << std::endl;
41  }
42  return os;
43 }
44 
45 std::ostream & operator<<(std::ostream & os, const DDMapArguments & t)
46 {
47  DDMapArguments::const_iterator it(t.begin()), ed(t.end());
48  for(; it != ed; ++it) {
49  os << it->first << ": ";
50  std::map<std::string,double>::const_iterator mit(it->second.begin()), med(it->second.end());
51  for(;mit!=med;++mit) {
52  os << mit->first << '=' << mit->second << ' ';
53  }
54  os << std::endl;
55  }
56  return os;
57 }
58 
59 std::ostream & operator<<(std::ostream & os, const DDStringVectorArguments & t)
60 {
61  DDStringVectorArguments::const_iterator it(t.begin()), ed(t.end());
62  for(; it != ed; ++it) {
63  os << it->first << ": ";
64  std::vector<std::string>::const_iterator vit(it->second.begin()), ved(it->second.end());
65  for(; vit!=ved; ++vit) {
66  os << *vit << ' ';
67  }
68  os << std::endl;
69  }
70  return os;
71 }
72 
73 
74 // Formats an angle in radians as a 0-padded string in degrees; e.g. "-001.293900" for -1.2939 degrees.
75 std::string formatAsDegrees(double radianVal)
76 {
77  const unsigned short numlen = 12;
78  char degstr[numlen];
79  int retval = snprintf(degstr, numlen, "%0*f", numlen - 1, convertRadToDeg( radianVal ));
80  if (retval == numlen - 1)
81  return degstr;
82  else return "0000.000000";
83 }
84 
85 // Formats an angle in radians as a 0-padded string in degrees expressed as integer between 0 and 360; e.g. "090" for -270.001 degrees.
87 
88  const unsigned short numlen = 4;
89  char degstr[numlen];
90  int degVal = std::lround(convertRadToDeg( radianVal ));
91  if (degVal < 0) degVal += 360;
92  else if (degVal >= 360) degVal -= 360;
93  int retval = snprintf(degstr, numlen, "%0*d", numlen-1, degVal);
94 
95  if (retval == numlen - 1) return degstr;
96  else return "000";
97 }
std::string formatAsDegrees(double radianVal)
Definition: DDTypes.cc:75
constexpr NumType convertRadToDeg(NumType radians)
Definition: GeantUnits.h:98
std::ostream & operator<<(std::ostream &os, const DDNumericArguments &t)
Definition: DDTypes.cc:13
a std::map<std::string,YourType> that offers a const operator[key]; if key is not stored in the std::...
Definition: DDReadMapType.h:13
std::string formatAsDegreesInInteger(double radianVal)
Definition: DDTypes.cc:86