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 );
40 double thetaY,
double phiY,
41 double thetaZ,
double phiZ ) {
48 double check = ( x.Cross( y )).Dot( z );
49 if(
abs( 1. + check ) > tol ) {
50 except(
"DD4CMS",
"+++ FAILED to construct Rotation is not LEFT-handed!");
53 dd4hep::Rotation3D
rotation( x.x(), y.x(), z.x(),
65 rotation = dd4hep::RotationX( angle );
68 rotation = dd4hep::RotationY( angle );
71 rotation = dd4hep::RotationZ( angle );
74 throw std::runtime_error(
"Axis is not valid." );
98 return n.
realName(value<string>(
"ChildName"));
104 string n =
p.attr<
string>(_U(
name));
115 string n =
p.attr<
string>(_U(
name));
120 except(
"DD4CMS",
"+++ Attempt to access non-existing algorithm option %s[%s]",
name.c_str(),nam.c_str());
121 throw runtime_error(
"DDCMS: Attempt to access non-existing algorithm option.");
128 string val = arg.attr<
string>(_U(
value));
139 string val = xp.text();
140 string nam = xp.nameStr();
141 string typ = xp.typeStr();
142 int num = xp.attr<
int>(
DD_CMU(nEntries));
143 const BasicGrammar& gr = BasicGrammar::instance<vector<string> >();
146 val = remove_whitespace(val);
147 int res = gr.fromString(&data,val);
149 except(
"DD4CMS",
"+++ VectorParam<%s>: %s -> %s [Invalid conversion:%d]",
150 typ.c_str(), nam.c_str(), val.c_str(), res);
152 else if ( num != (
int)data.size() ) {
153 except(
"DD4CMS",
"+++ VectorParam<%s>: %s -> %s [Invalid entry count: %d <> %ld]",
154 typ.c_str(), nam.c_str(), val.c_str(),
num, data.size());
156 printout(
DEBUG,
"DD4CMS",
"+++ VectorParam<%s>: ret=%d %s -> %s",
157 typ.c_str(), res, nam.c_str(), gr.str(&data).c_str());
162 template <
typename T>
T __cnv(
const string&) {
return 0;}
163 template <>
double __cnv<double>(
const string&
arg) {
return _toDouble(arg); }
164 template <>
float __cnv<float> (
const string&
arg) {
return _toFloat(arg); }
165 template <>
long __cnv<long> (
const string&
arg) {
return _toLong(arg); }
166 template <>
int __cnv<int> (
const string&
arg) {
return _toInt(arg); }
167 template <>
string __cnv<string>(
const string&
arg) {
return arg; }
169 template <
typename T> vector<T> __cnvVect(
const DDAlgoArguments* a,
const char* req_typ, xml_h xp) {
172 string nam = xp.attr<
string>(_U(
name));
173 string typ = xp.attr<
string>(_U(
type));
174 string val = xp.text();
175 int num = xp.attr<
int>(
DD_CMU(nEntries));
176 if ( typ != req_typ ) {
178 "+++ VectorParam<%s | %s>: %s -> <%s> %s [Incompatible vector-type]",
179 req_typ, typ.c_str(), nam.c_str(), typeName(
typeid(
T)).c_str(),
183 val = remove_whitespace(val);
184 if ( !val.empty() ) val +=
',';
185 for(
size_t idx=0, idq=val.find(
',',
idx);
186 idx != string::npos && idq != string::npos;
187 idx=++idq, idq=val.find(
',',
idx))
190 T d = __cnv<T>(piece);
193 printout(
DEBUG,
"DD4CMS",
"+++ VectorParam<%s>: %s[%d] -> %s",
194 typ.c_str(), nam.c_str(),
num, val.c_str());
207 template double DDAlgoArguments::value<double>(
const string& nam)
const;
208 template float DDAlgoArguments::value<float>(
const string& nam)
const;
209 template long DDAlgoArguments::value<long>(
const string& nam)
const;
210 template int DDAlgoArguments::value<int>(
const string& nam)
const;
211 template string DDAlgoArguments::value<string>(
const string& nam)
const;
214 template<> vector<string> DDAlgoArguments::value<vector<string> >(
const string& nam)
const 218 template<> vector<double> DDAlgoArguments::value<vector<double> >(
const string& nam)
const 219 {
return __cnvVect<double>(
this,
"numeric",
rawArgument(nam)); }
222 template<> vector<float> DDAlgoArguments::value<vector<float> >(
const string& nam)
const 223 {
return __cnvVect<float>(
this,
"numeric",
rawArgument(nam)); }
226 template<> vector<long> DDAlgoArguments::value<vector<long> >(
const string& nam)
const 227 {
return __cnvVect<long>(
this,
"numeric",
rawArgument(nam)); }
230 template<> vector<int> DDAlgoArguments::value<vector<int> >(
const string& nam)
const 231 {
return __cnvVect<int>(
this,
"numeric",
rawArgument(nam)); }
236 {
return this->value<string>(nam); }
240 {
return this->value<double>(nam); }
244 {
return this->value<int>(nam); }
248 {
return this->value<vector<double> >(nam); }
252 {
return this->value<vector<int> >(nam); }
256 {
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
dd4hep::Rotation3D makeRotReflect(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
Namespace of DDCMS conversion namespace.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >> DD3Vector
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)