2 #include <DD4hep/Path.h>
3 #include <DD4hep/Printout.h>
4 #include <DD4hep/Detector.h>
5 #include <DD4hep/Filter.h>
6 #include <DD4hep/Grammar.h>
25 dd4hep::Rotation3D
rotation(posX, posY, posZ);
39 constexpr
double tol = 1.0e-3;
40 double check = (x.Cross(y)).Dot(z);
41 if (
abs(1. + check) > tol) {
42 except(
"DD4CMS",
"+++ FAILED to construct Rotation is not LEFT-handed!");
45 dd4hep::Rotation3D
rotation(x.x(), y.x(), z.x(), x.y(), y.y(), z.y(), x.z(), y.z(), z.z());
53 rotation =
dd4hep::RotationX(angle);
56 rotation =
dd4hep::RotationY(angle);
59 rotation =
dd4hep::RotationZ(angle);
62 throw std::runtime_error(
"Axis is not valid.");
70 str.erase(0, str.find_first_not_of(chars));
75 str.erase(str.find_last_not_of(chars) + 1);
90 res.append(ts).append(
",");
93 res.erase(res.find_last_of(
','));
114 return n.
realName(value<string>(
"ChildName"));
119 for (xml_coll_t
p(
element, _U(star));
p; ++
p) {
120 string n =
p.attr<
string>(_U(
name));
130 for (xml_coll_t
p(
element, _U(star));
p; ++
p) {
131 string n =
p.attr<
string>(_U(
name));
136 except(
"DD4CMS",
"+++ Attempt to access non-existing algorithm option %s[%s]",
name.c_str(), nam.c_str());
137 throw runtime_error(
"DDCMS: Attempt to access non-existing algorithm option.");
144 string val = arg.attr<
string>(_U(
value));
150 string value(aValue);
151 size_t idx = value.find(
'[');
152 if (idx == string::npos) {
156 while (idx != string::npos) {
158 size_t idp = value.find(
':', idx);
159 size_t idq = value.find(
']', idx);
160 if (idp == string::npos || idp > idq)
161 value.insert(idx, ns.
name());
162 else if (idp != string::npos && idp < idq)
164 idx = value.find(
'[', idx);
170 for (idx = v.find(
'[', 0); idx != string::npos; idx = v.find(
'[', idx + 1)) {
171 idq = v.find(
']', idx + 1);
172 rep = v.substr(idx + 1, idq - idx - 1);
175 rep =
"(" +
r->second->type +
")";
176 v.replace(idx, idq - idx + 1, rep);
189 string val = xp.text();
190 string nam = xp.nameStr();
191 string typ = xp.typeStr();
192 string numValue = xp.attr<
string>(
DD_CMU(nEntries));
193 int num = _toDouble(numValue);
194 const BasicGrammar& gr = BasicGrammar::instance<vector<string> >();
196 val = trimSVecWhitespace(val);
197 val =
'[' + ns.realName(val) +
']';
198 int res = gr.fromString(&data, val);
201 "DD4CMS",
"+++ VectorParam<%s>: %s -> %s [Invalid conversion:%d]", typ.c_str(), nam.c_str(), val.c_str(), res);
202 }
else if (num != (
int)data.size()) {
204 "+++ VectorParam<%s>: %s -> %s [Invalid entry count: %d <> %ld]",
213 "+++ VectorParam<%s>: ret=%d %s -> %s",
217 gr.str(&data).c_str());
221 template <
typename T>
222 T __cnv(
const string&) {
226 double __cnv<double>(
const string&
arg) {
227 return _toDouble(arg);
230 float __cnv<float>(
const string&
arg) {
231 return _toFloat(arg);
234 long __cnv<long>(
const string&
arg) {
238 int __cnv<int>(
const string&
arg) {
242 string __cnv<string>(
const string&
arg) {
246 template <
typename T>
247 vector<T> __cnvVect(
const DDAlgoArguments* a,
const char* req_typ, xml_h xp) {
250 string nam = xp.attr<
string>(_U(
name));
251 string typ = xp.hasAttr(_U(
type)) ? xp.attr<
string>(_U(
type)) :
"numeric";
252 string val = xp.text();
254 int num = _toInt(nValues);
255 if (typ != req_typ) {
257 "+++ VectorParam<%s | %s>: %s -> <%s> %s [Incompatible vector-type]",
265 val = remove_whitespace(val);
269 for (
size_t idx = 0, idq = val.find(
',', idx); idx != string::npos && idq != string::npos;
270 idx = ++idq, idq = val.find(
',', idx)) {
271 piece = ns.realName(val.substr(idx, idq - idx));
272 T d = __cnv<T>(piece);
277 "+++ VectorParam<%s>: %s[%d] -> %s",
290 template <
typename T>
292 return __cnv<T>(resolved_scalar_arg(nam));
295 template double DDAlgoArguments::value<double>(
const string& nam)
const;
296 template float DDAlgoArguments::value<float>(
const string& nam)
const;
297 template long DDAlgoArguments::value<long>(
const string& nam)
const;
298 template int DDAlgoArguments::value<int>(
const string& nam)
const;
299 template string DDAlgoArguments::value<string>(
const string& nam)
const;
303 vector<string> DDAlgoArguments::value<vector<string> >(
const string& nam)
const {
304 return raw_vector(
this, rawArgument(nam));
309 vector<double> DDAlgoArguments::value<vector<double> >(
const string& nam)
const {
310 return __cnvVect<double>(
this,
"numeric", rawArgument(nam));
315 vector<float> DDAlgoArguments::value<vector<float> >(
const string& nam)
const {
316 return __cnvVect<float>(
this,
"numeric", rawArgument(nam));
321 vector<long> DDAlgoArguments::value<vector<long> >(
const string& nam)
const {
322 return __cnvVect<long>(
this,
"numeric", rawArgument(nam));
327 vector<int> DDAlgoArguments::value<vector<int> >(
const string& nam)
const {
328 return __cnvVect<int>(
this,
"numeric", rawArgument(nam));
std::string childName() const
Access value of child'name from the xml element.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >> DD3Vector
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.
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
static void ltrim(std::string &s)
DDParsingContext *const context() const
std::string_view name() const
xml_h rawArgument(const std::string &name) const
Access raw argument as a string by name.
std::string realName(const std::string &) const
DDRotationMatrix 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)
std::string resolveValue(const std::string &value) const
static void rtrim(std::string &s)
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.
dd4hep::Detector & description
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::vector< float > vecFloat(const std::string &nam) const
Shortcut to access vector<float> 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)