1 #include "DD4hep/Path.h" 2 #include "DD4hep/Printout.h" 3 #include "DD4hep/Detector.h" 4 #include "DD4hep/BasicGrammar.h" 20 double thetaY,
double phiY,
21 double thetaZ,
double phiZ) {
22 dd4hep::Position
posX(
sin( thetaX ) *
cos( phiX ),
23 sin( thetaX ) *
sin( phiX ),
25 dd4hep::Position
posY(
sin( thetaY ) *
cos( phiY ),
26 sin( thetaY ) *
sin( phiY ),
28 dd4hep::Position posZ(
sin( thetaZ ) *
cos( phiZ ),
29 sin( thetaZ ) *
sin( phiZ ),
31 dd4hep::Rotation3D
rotation( posX, posY, posZ );
42 rotation = dd4hep::RotationX( angle );
45 rotation = dd4hep::RotationY( angle );
48 rotation = dd4hep::RotationZ( angle );
51 throw std::runtime_error(
"Axis is not valid." );
75 return n.
realName(value<string>(
"ChildName"));
81 string n =
p.attr<
string>(_U(
name));
92 string n =
p.attr<
string>(_U(
name));
97 except(
"MyDDCMS",
"+++ Attempt to access non-existing algorithm option %s[%s]",
name.c_str(),nam.c_str());
98 throw runtime_error(
"DDCMS: Attempt to access non-existing algorithm option.");
105 string val = arg.attr<
string>(_U(
value));
116 string val = xp.text();
117 string nam = xp.nameStr();
118 string typ = xp.typeStr();
119 int num = xp.attr<
int>(
_CMU(nEntries));
120 const BasicGrammar& gr = BasicGrammar::instance<vector<string> >();
123 val = remove_whitespace(val);
124 int res = gr.fromString(&data,val);
126 except(
"MyDDCMS",
"+++ VectorParam<%s>: %s -> %s [Invalid conversion:%d]",
127 typ.c_str(), nam.c_str(), val.c_str(), res);
129 else if ( num != (
int)data.size() ) {
130 except(
"MyDDCMS",
"+++ VectorParam<%s>: %s -> %s [Invalid entry count: %d <> %ld]",
131 typ.c_str(), nam.c_str(), val.c_str(),
num, data.size());
133 printout(
DEBUG,
"MyDDCMS",
"+++ VectorParam<%s>: ret=%d %s -> %s",
134 typ.c_str(), res, nam.c_str(), gr.str(&data).c_str());
139 template <
typename T>
T __cnv(
const string&) {
return 0;}
140 template <>
double __cnv<double>(
const string&
arg) {
return _toDouble(arg); }
141 template <>
float __cnv<float> (
const string&
arg) {
return _toFloat(arg); }
142 template <>
long __cnv<long> (
const string&
arg) {
return _toLong(arg); }
143 template <>
int __cnv<int> (
const string&
arg) {
return _toInt(arg); }
144 template <>
string __cnv<string>(
const string&
arg) {
return arg; }
146 template <
typename T> vector<T> __cnvVect(
const DDAlgoArguments* a,
const char* req_typ, xml_h xp) {
149 string nam = xp.attr<
string>(_U(
name));
150 string typ = xp.attr<
string>(_U(
type));
151 string val = xp.text();
152 int num = xp.attr<
int>(
_CMU(nEntries));
153 if ( typ != req_typ ) {
155 "+++ VectorParam<%s | %s>: %s -> <%s> %s [Incompatible vector-type]",
156 req_typ, typ.c_str(), nam.c_str(), typeName(
typeid(
T)).c_str(),
160 val = remove_whitespace(val);
161 if ( !val.empty() ) val +=
',';
162 for(
size_t idx=0, idq=val.find(
',',
idx);
163 idx != string::npos && idq != string::npos;
164 idx=++idq, idq=val.find(
',',
idx))
167 T d = __cnv<T>(piece);
170 printout(
DEBUG,
"MyDDCMS",
"+++ VectorParam<%s>: %s[%d] -> %s",
171 typ.c_str(), nam.c_str(),
num, val.c_str());
184 template double DDAlgoArguments::value<double>(
const string& nam)
const;
185 template float DDAlgoArguments::value<float>(
const string& nam)
const;
186 template long DDAlgoArguments::value<long>(
const string& nam)
const;
187 template int DDAlgoArguments::value<int>(
const string& nam)
const;
188 template string DDAlgoArguments::value<string>(
const string& nam)
const;
191 template<> vector<string> DDAlgoArguments::value<vector<string> >(
const string& nam)
const 195 template<> vector<double> DDAlgoArguments::value<vector<double> >(
const string& nam)
const 196 {
return __cnvVect<double>(
this,
"numeric",
rawArgument(nam)); }
199 template<> vector<float> DDAlgoArguments::value<vector<float> >(
const string& nam)
const 200 {
return __cnvVect<float>(
this,
"numeric",
rawArgument(nam)); }
203 template<> vector<long> DDAlgoArguments::value<vector<long> >(
const string& nam)
const 204 {
return __cnvVect<long>(
this,
"numeric",
rawArgument(nam)); }
207 template<> vector<int> DDAlgoArguments::value<vector<int> >(
const string& nam)
const 208 {
return __cnvVect<int>(
this,
"numeric",
rawArgument(nam)); }
213 {
return this->value<string>(nam); }
217 {
return this->value<double>(nam); }
221 {
return this->value<int>(nam); }
225 {
return this->value<vector<double> >(nam); }
229 {
return this->value<vector<int> >(nam); }
233 {
return this->value<vector<string> >(nam); }
std::string childName() const
Access value of child'name from the xml element.
Sin< T >::type sin(const T &t)
T value(const std::string &name) const
int integer(const std::string &nam) const
Shortcut to access integer arguments.
dd4hep::Rotation3D makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
xml_h rawArgument(const std::string &name) const
Access raw argument as a string by name.
std::string realName(const std::string &) const
Cos< T >::type cos(const T &t)
Namespace of DDCMS conversion namespace.
char data[epos_bytes_allocation]
std::vector< double > vecDble(const std::string &nam) const
Shortcut to access vector<double> arguments.
double dble(const std::string &nam) const
Shortcut to access double arguments.
cms::DDParsingContext & context
std::vector< std::string > vecStr(const std::string &nam) const
Shortcut to access vector<string> arguments.
bool find(const std::string &name) const
Check the existence of an argument by name.
std::vector< int > vecInt(const std::string &nam) const
Shortcut to access vector<int> arguments.
std::string resolved_scalar_arg(const std::string &name) const
Access namespace resolved argument as a string by name.
std::string parentName() const
Access value of rParent child node.
std::string str(const std::string &nam) const
Shortcut to access string arguments.
T angle(T x1, T y1, T z1, T x2, T y2, T z2)