1 #include "DD4hep/DetFactoryHelper.h" 2 #include "DD4hep/DetectorHelper.h" 3 #include "DD4hep/DD4hepUnits.h" 4 #include "DD4hep/GeoHandler.h" 5 #include "DD4hep/Printout.h" 6 #include "DD4hep/Plugins.h" 7 #include "DD4hep/detail/SegmentationsInterna.h" 8 #include "DD4hep/detail/DetectorInterna.h" 9 #include "DD4hep/detail/ObjectsInterna.h" 11 #include "XML/Utilities.h" 18 #include "TGeoManager.h" 19 #include "TGeoMaterial.h" 36 UInt_t unique_mat_id = 0xAFFEFEED;
39 class include_constants;
44 class ConstantsSection;
52 class MaterialSection;
56 class RotationSection;
65 class LogicalPartSection;
69 class DDLExtrudedPolygon;
85 class DDLIntersectionSolid;
86 class DDLSubtractionSolid;
97 template <>
void Converter<debug>::operator()(xml_h element)
const;
98 template <>
void Converter<print_xml_doc>::operator()(xml_h element)
const;
99 template <>
void Converter<disabled_algo>::operator()(xml_h element)
const;
102 template <>
void Converter<ConstantsSection>::operator()(xml_h element)
const;
103 template <>
void Converter<DDLConstant>::operator()(xml_h element)
const;
104 template <>
void Converter<DDRegistry>::operator()(xml_h element)
const;
107 template <>
void Converter<vissection>::operator()(xml_h element)
const;
109 template <>
void Converter<vis>::operator()(xml_h element)
const;
112 template <>
void Converter<MaterialSection>::operator()(xml_h element)
const;
113 template <>
void Converter<DDLElementaryMaterial>::operator()(xml_h element)
const;
114 template <>
void Converter<DDLCompositeMaterial>::operator()(xml_h element)
const;
117 template <>
void Converter<RotationSection>::operator()(xml_h element)
const;
119 template <>
void Converter<DDLRotation>::operator()(xml_h element)
const;
121 template <>
void Converter<DDLRotationSequence>::operator()(xml_h element)
const;
123 template <>
void Converter<DDLRotationByAxis>::operator()(xml_h element)
const;
124 template <>
void Converter<DDLTransform3D>::operator()(xml_h element)
const;
127 template <>
void Converter<LogicalPartSection>::operator()(xml_h element)
const;
128 template <>
void Converter<DDLLogicalPart>::operator()(xml_h element)
const;
130 template <>
void Converter<PosPartSection>::operator()(xml_h element)
const;
132 template <>
void Converter<DDLPosPart>::operator()(xml_h element)
const;
135 template <>
void Converter<SolidSection>::operator()(xml_h element)
const;
137 template <>
void Converter<DDLUnionSolid>::operator()(xml_h element)
const;
139 template <>
void Converter<DDLSubtractionSolid>::operator()(xml_h element)
const;
141 template <>
void Converter<DDLIntersectionSolid>::operator()(xml_h element)
const;
143 template <>
void Converter<DDLPseudoTrap>::operator()(xml_h element)
const;
145 template <>
void Converter<DDLExtrudedPolygon>::operator()(xml_h element)
const;
147 template <>
void Converter<DDLShapeless>::operator()(xml_h element)
const;
149 template <>
void Converter<DDLTrapezoid>::operator()(xml_h element)
const;
151 template <>
void Converter<DDLPolycone>::operator()(xml_h element)
const;
153 template <>
void Converter<DDLPolyhedra>::operator()(xml_h element)
const;
155 template <>
void Converter<DDLEllipticalTube>::operator()(xml_h element)
const;
157 template <>
void Converter<DDLTorus>::operator()(xml_h element)
const;
159 template <>
void Converter<DDLTubs>::operator()(xml_h element)
const;
161 template <>
void Converter<DDLCutTubs>::operator()(xml_h element)
const;
163 template <>
void Converter<DDLTruncTubs>::operator()(xml_h element)
const;
165 template <>
void Converter<DDLSphere>::operator()(xml_h element)
const;
167 template <>
void Converter<DDLTrd1>::operator()(xml_h element)
const;
169 template <>
void Converter<DDLCone>::operator()(xml_h element)
const;
171 template <>
void Converter<DDLBox>::operator()(xml_h element)
const;
173 template <>
void Converter<DDLAlgorithm>::operator()(xml_h element)
const;
175 template <>
void Converter<DDLVector>::operator()(xml_h element)
const;
178 template <>
void Converter<include_load>::operator()(xml_h element)
const;
180 template <>
void Converter<include_unload>::operator()(xml_h element)
const;
182 template <>
void Converter<include_constants>::operator()(xml_h element)
const;
186 template <>
void Converter<ConstantsSection>::operator()(xml_h element)
const {
193 template <>
void Converter<vissection>::operator()(xml_h element)
const {
195 xml_coll_t(element,
_CMU(
vis)).for_each(Converter<vis>(
description,_ns.context,optional));
199 template <>
void Converter<MaterialSection>::operator()(xml_h element)
const {
201 xml_coll_t(element,
_CMU(ElementaryMaterial)).for_each(Converter<DDLElementaryMaterial>(
description,_ns.context,optional));
202 xml_coll_t(element,
_CMU(CompositeMaterial)).for_each(Converter<DDLCompositeMaterial>(
description,_ns.context,optional));
205 template <>
void Converter<RotationSection>::operator()(xml_h element)
const {
207 xml_coll_t(element,
_CMU(Rotation)).for_each(Converter<DDLRotation>(
description,_ns.context,optional));
208 xml_coll_t(element,
_CMU(RotationSequence)).for_each(Converter<DDLRotationSequence>(
description,_ns.context,optional));
209 xml_coll_t(element,
_CMU(RotationByAxis)).for_each(Converter<DDLRotationByAxis>(
description,_ns.context,optional));
212 template <>
void Converter<PosPartSection>::operator()(xml_h element)
const {
214 xml_coll_t(element,
_CMU(PosPart)).for_each(Converter<DDLPosPart>(
description,_ns.context,optional));
218 template <>
void Converter<LogicalPartSection>::operator()(xml_h element)
const {
220 xml_coll_t(element,
_CMU(LogicalPart)).for_each(Converter<DDLLogicalPart>(
description,_ns.context,optional));
223 template <>
void Converter<disabled_algo>::operator()(xml_h element)
const {
229 template <>
void Converter<SolidSection>::operator()(xml_h element)
const {
231 for(xml_coll_t solid(element, _U(star)); solid; ++solid) {
232 string tag = solid.tag();
234 switch(
hash( solid.tag()))
239 case hash(
"Polycone"):
240 Converter<DDLPolycone>(
description,_ns.context,optional)(solid);
242 case hash(
"Polyhedra"):
243 Converter<DDLPolyhedra>(
description,_ns.context,optional)(solid);
248 case hash(
"CutTubs"):
249 Converter<DDLCutTubs>(
description,_ns.context,optional)(solid);
251 case hash(
"TruncTubs"):
252 Converter<DDLTruncTubs>(
description,_ns.context,optional)(solid);
258 Converter<DDLTrd1>(
description,_ns.context,optional)(solid);
266 case hash(
"EllipticalTube"):
272 case hash(
"PseudoTrap"):
275 case hash(
"ExtrudedPolygon"):
276 Converter<DDLExtrudedPolygon>(
description,_ns.context,optional)(solid);
278 case hash(
"Trapezoid"):
281 case hash(
"UnionSolid"):
282 Converter<DDLUnionSolid>(
description,_ns.context,optional)(solid);
284 case hash(
"SubtractionSolid"):
285 Converter<DDLSubtractionSolid>(
description,_ns.context,optional)(solid);
287 case hash(
"IntersectionSolid"):
288 Converter<DDLIntersectionSolid>(
description,_ns.context,optional)(solid);
290 case hash(
"ShapelessSolid"):
291 Converter<DDLShapeless>(
description,_ns.context,optional)(solid);
294 throw std::runtime_error(
"Request to process unknown shape '" + xml_dim_t(solid).nameStr() +
"' [" + tag +
"]");
301 template <>
void Converter<DDLConstant>::operator()(xml_h element)
const {
303 DDRegistry*
res = _option<DDRegistry>();
304 xml_dim_t constant = element;
305 xml_dim_t par = constant.parent();
306 bool eval = par.hasAttr(_U(eval)) ? par.attr<
bool>(_U(eval)) :
false;
307 string val = constant.valueStr();
308 string nam = constant.nameStr();
309 string real = _ns.prepend(nam);
310 string typ = eval ?
"number" :
"string";
311 size_t idx = val.find(
'[');
313 if ( constant.hasAttr(_U(
type)) )
314 typ = constant.typeStr();
316 if ( idx == string::npos || typ ==
"string" ) {
318 _ns.addConstant(nam, val, typ);
319 res->allConst[real] =
val;
320 res->originalConst[real] =
val;
323 printout(
INFO,
"MyDDCMS",
"++ Unresolved constant: %s = %s [%s]. Try to resolve later. [%s]",
324 real.c_str(), val.c_str(), typ.c_str(), e.what());
329 while ( idx != string::npos ) {
331 size_t idp = val.find(
':',idx);
332 size_t idq = val.find(
']',idx);
333 if ( idp == string::npos || idp > idq )
334 val.insert(idx,_ns.name());
335 else if ( idp != string::npos && idp < idq )
337 idx = val.find(
'[',idx);
339 printout(_ns.context->debug_constants ? ALWAYS :
DEBUG,
340 "Constant",
"Unresolved: %s -> %s",real.c_str(),val.c_str());
341 res->allConst[real] =
val;
342 res->originalConst[real] =
val;
343 res->unresolvedConst[real] =
val;
354 template <>
void Converter<vis>::operator()(xml_h e)
const {
356 VisAttr attr(e.attr<
string>(_U(
name)));
357 float red = e.hasAttr(_U(
r)) ? e.attr<
float>(_U(
r)) : 1.0
f;
358 float green = e.hasAttr(_U(
g)) ? e.attr<
float>(_U(
g)) : 1.0
f;
359 float blue = e.hasAttr(_U(
b)) ? e.attr<
float>(_U(
b)) : 1.0
f;
361 printout(_ns.context->debug_visattr ? ALWAYS : DEBUG,
"Compact",
362 "++ Converting VisAttr structure: %-16s. R=%.3f G=%.3f B=%.3f",
364 attr.setColor(red, green, blue);
365 if (e.hasAttr(_U(
alpha)))
366 attr.setAlpha(e.attr<
float>(_U(
alpha)));
367 if (e.hasAttr(_U(visible)))
368 attr.setVisible(e.attr<
bool>(_U(visible)));
371 if (ls ==
"unbroken")
372 attr.setLineStyle(VisAttr::SOLID);
373 else if (ls ==
"broken")
374 attr.setLineStyle(VisAttr::DASHED);
377 attr.setLineStyle(VisAttr::SOLID);
379 if (e.hasAttr(_U(drawingStyle))) {
380 string ds = e.attr<
string>(_U(drawingStyle));
381 if (ds ==
"wireframe")
382 attr.setDrawingStyle(VisAttr::WIREFRAME);
383 else if (ds ==
"solid")
384 attr.setDrawingStyle(VisAttr::SOLID);
387 attr.setDrawingStyle(VisAttr::SOLID);
389 if (e.hasAttr(_U(showDaughters)))
390 attr.setShowDaughters(e.attr<
bool>(_U(showDaughters)));
392 attr.setShowDaughters(
true);
397 template <>
void Converter<DDLElementaryMaterial>::operator()(xml_h element)
const {
399 xml_dim_t xmat(element);
400 string nam = _ns.prepend(xmat.nameStr());
402 TGeoMaterial* mat = mgr.GetMaterial(nam.c_str());
403 if (
nullptr == mat ) {
404 const char* matname = nam.c_str();
405 double density = xmat.density();
407 double atomicNumber = xmat.attr<
double>(
_CMU(atomicNumber));
408 TGeoElementTable* tab = mgr.GetElementTable();
409 TGeoMixture*
mix =
new TGeoMixture(nam.c_str(), 1, density);
410 TGeoElement* elt = tab->FindElement(xmat.nameStr().c_str());
412 printout(_ns.context->debug_materials ? ALWAYS : DEBUG,
"MyDDCMS",
413 "+++ Converting material %-48s Density: %.3f.",
414 (
'"'+nam+
'"').c_str(), density);
418 "+++ Converter<ElementaryMaterial> No element present with name:%s [FAKE IT]",
420 int n =
int(atomicNumber/2e0);
422 elt =
new TGeoElement(xmat.nameStr().c_str(),
"CMS element",
n,atomicNumber);
425 if ( elt->Z() == 0 ) {
426 int n =
int(atomicNumber/2e0);
428 elt =
new TGeoElement((xmat.nameStr()+
"-CMS").c_str(),
"CMS element",
n,atomicNumber);
430 mix->AddElement(elt, 1.0);
433 TGeoMedium* medium = mgr.GetMedium(matname);
434 if (
nullptr == medium) {
436 medium =
new TGeoMedium(matname, unique_mat_id, mix);
437 medium->SetTitle(
"material");
438 medium->SetUniqueID(unique_mat_id);
444 template <>
void Converter<DDLCompositeMaterial>::operator()(xml_h element)
const {
446 xml_dim_t xmat(element);
447 string nam = _ns.prepend(xmat.nameStr());
449 TGeoMaterial* mat = mgr.GetMaterial(nam.c_str());
450 if (
nullptr == mat ) {
451 const char* matname = nam.c_str();
452 double density = xmat.density();
453 xml_coll_t composites(xmat,
_CMU(MaterialFraction));
454 TGeoMixture* mix =
new TGeoMixture(nam.c_str(), composites.size(), density);
456 printout(_ns.context->debug_materials ? ALWAYS : DEBUG,
"MyDDCMS",
457 "++ Converting material %-48s Density: %.3f.",
458 (
'"'+nam+
'"').c_str(), density);
460 for (composites.reset(); composites; ++composites) {
461 xml_dim_t xfrac(composites);
462 xml_dim_t xfrac_mat(xfrac.child(
_CMU(rMaterial)));
464 string fracname = _ns.realName(xfrac_mat.nameStr());
466 TGeoMaterial* frac_mat = mgr.GetMaterial(fracname.c_str());
468 mix->AddElement(frac_mat, fraction);
471 printout(
WARNING,
"MyDDCMS",
"+++ Composite material \"%s\" not present!",
476 TGeoMedium* medium = mgr.GetMedium(matname);
477 if (
nullptr == medium) {
479 medium =
new TGeoMedium(matname, unique_mat_id, mix);
480 medium->SetTitle(
"material");
481 medium->SetUniqueID(unique_mat_id);
487 template <>
void Converter<DDLRotation>::operator()(xml_h element)
const {
490 xml_dim_t xrot(element);
491 string nam = xrot.nameStr();
492 double thetaX = xrot.hasAttr(
_CMU(thetaX)) ? _ns.attr<
double>(xrot,
_CMU(thetaX)) : 0e0;
493 double phiX = xrot.hasAttr(
_CMU(phiX)) ? _ns.attr<
double>(xrot,
_CMU(phiX)) : 0e0;
494 double thetaY = xrot.hasAttr(
_CMU(thetaY)) ? _ns.attr<
double>(xrot,
_CMU(thetaY)) : 0e0;
495 double phiY = xrot.hasAttr(
_CMU(phiY)) ? _ns.attr<
double>(xrot,
_CMU(phiY)) : 0e0;
496 double thetaZ = xrot.hasAttr(
_CMU(thetaZ)) ? _ns.attr<
double>(xrot,
_CMU(thetaZ)) : 0e0;
497 double phiZ = xrot.hasAttr(
_CMU(phiZ)) ? _ns.attr<
double>(xrot,
_CMU(phiZ)) : 0e0;
500 "MyDDCMS",
"+++ Adding rotation: %-32s: (theta/phi)[rad] X: %6.3f %6.3f Y: %6.3f %6.3f Z: %6.3f %6.3f",
502 _ns.addRotation(nam, rot);
506 template <>
void Converter<DDLRotationSequence>::operator()(xml_h element)
const {
509 xml_dim_t xrot(element);
510 string nam = xrot.nameStr();
512 xml_coll_t rotations(xrot,
_CMU(RotationByAxis));
513 for( rotations.reset(); rotations; ++rotations ) {
514 string axis = _ns.attr<
string>(rotations,
_CMU(axis));
515 double angle = _ns.attr<
double>(rotations,_U(angle));
518 "MyDDCMS",
"+ Adding rotation to: %-29s: (axis/angle)[rad] Axis: %s Angle: %6.3f",
519 nam.c_str(), axis.c_str(),
angle);
524 rot.GetComponents(xx,xy,xz,yx,yy,yz,zx,zy,zz);
526 "MyDDCMS",
"+++ Adding rotation sequence: %-23s: %6.3f %6.3f %6.3f, %6.3f %6.3f %6.3f, %6.3f %6.3f %6.3f",
527 _ns.prepend(nam).c_str(),
xx,
xy,
xz, yx,
yy,
yz, zx, zy,
zz);
528 _ns.addRotation(nam, rot);
532 template <>
void Converter<DDLRotationByAxis>::operator()(xml_h element)
const {
535 xml_dim_t xrot(element);
536 xml_dim_t par(xrot.parent());
537 if( xrot.hasAttr(_U(
name))) {
538 string nam = xrot.nameStr();
539 string axis = _ns.attr<
string>(xrot,
_CMU(axis));
540 double angle = _ns.attr<
double>(xrot,_U(angle));
544 "MyDDCMS",
"+++ Adding rotation: %-32s: (axis/angle)[rad] Axis: %s Angle: %6.3f",
545 _ns.prepend(nam).c_str(), axis.c_str(),
angle);
546 _ns.addRotation(nam, rot);
551 template <>
void Converter<DDLLogicalPart>::operator()(xml_h element)
const {
553 xml_dim_t
e(element);
554 string sol = e.child(
_CMU(rSolid)).attr<
string>(_U(
name));
555 string mat = e.child(
_CMU(rMaterial)).attr<
string>(_U(
name));
556 _ns.addVolume(
Volume(e.nameStr(), _ns.solid(sol), _ns.material(mat)));
560 template <>
void Converter<DDLTransform3D>::operator()(xml_h element)
const {
562 Transform3D* tr = _option<Transform3D>();
563 xml_dim_t
e(element);
564 xml_dim_t translation = e.child(
_CMU(Translation),
false);
566 xml_dim_t refRotation = e.child(
_CMU(rRotation),
false);
570 if ( translation.ptr() ) {
571 double x = _ns.attr<
double>(translation,_U(x));
572 double y = _ns.attr<
double>(translation,_U(y));
573 double z = _ns.attr<
double>(translation,_U(z));
574 pos = Position(x,y,z);
576 if ( rotation.ptr() ) {
577 double x = _ns.attr<
double>(
rotation,_U(x));
578 double y = _ns.attr<
double>(
rotation,_U(y));
579 double z = _ns.attr<
double>(
rotation,_U(z));
580 rot = RotationZYX(z,y,x);
582 else if ( refRotation.ptr() ) {
583 rot = _ns.rotation(refRotation.nameStr());
585 *tr = Transform3D(rot,pos);
589 template <>
void Converter<DDLPosPart>::operator()(xml_h element)
const {
591 xml_dim_t
e(element);
592 int copy = e.attr<
int>(
_CMU(copyNumber));
593 string parent_nam = _ns.attr<
string>(e.child(
_CMU(rParent)),_U(
name));
594 string child_nam = _ns.attr<
string>(e.child(
_CMU(rChild)),_U(
name));
598 printout(_ns.context->debug_placements ? ALWAYS : DEBUG,
"MyDDCMS",
599 "+++ %s Parent: %-24s [%s] Child: %-32s [%s] copy:%d",
601 parent_nam.c_str(), parent.isValid() ?
"VALID" :
"INVALID",
602 child_nam.c_str(), child.isValid() ?
"VALID" :
"INVALID",
605 if ( child.isValid() ) {
607 Converter<DDLTransform3D>(
description,param,&trafo)(element);
608 pv = parent.placeVolume(child,copy,trafo);
610 if ( !pv.isValid() ) {
611 printout(
ERROR,
"MyDDCMS",
"+++ Placement FAILED! Parent:%s Child:%s Valid:%s",
612 parent.name(), child_nam.c_str(), yes_no(child.isValid()));
616 template <
typename TYPE>
619 xml_dim_t
e(element);
620 string nam = e.nameStr();
625 if ( e.hasChild(
_CMU(rSolid)) ) {
626 for(xml_coll_t
c(element,
_CMU(rSolid)); cnt<2 &&
c; ++
c, ++cnt)
627 solids[cnt] = _ns.
solid(c.attr<
string>(_U(
name)));
630 if ( (solids[0] = _ns.
solid(e.attr<
string>(
_CMU(firstSolid)))).isValid() ) ++cnt;
631 if ( (solids[1] = _ns.
solid(e.attr<
string>(
_CMU(secondSolid)))).isValid() ) ++cnt;
634 except(
"MyDDCMS",
"+++ Failed to create boolean solid %s. Found only %d parts.",nam.c_str(), cnt);
637 "+++ BooleanSolid: %s Left: %-32s Right: %-32s",
638 nam.c_str(), solids[0]->GetName(), solids[1]->GetName());
640 if ( solids[0].isValid() && solids[1].isValid() ) {
642 Converter<DDLTransform3D>(*context->
description,context,&trafo)(element);
643 boolean = TYPE(solids[0],solids[1],trafo);
645 if ( !
boolean.isValid() )
646 except(
"MyDDCMS",
"+++ FAILED to construct subtraction solid: %s",nam.c_str());
651 template <>
void Converter<DDLUnionSolid>::operator()(xml_h element)
const {
652 convert_boolean<UnionSolid>(_param<cms::DDParsingContext>(),element);
656 template <>
void Converter<DDLSubtractionSolid>::operator()(xml_h element)
const {
657 convert_boolean<SubtractionSolid>(_param<cms::DDParsingContext>(),element);
661 template <>
void Converter<DDLIntersectionSolid>::operator()(xml_h element)
const {
662 convert_boolean<IntersectionSolid>(_param<cms::DDParsingContext>(),element);
666 template <>
void Converter<DDLPolycone>::operator()(xml_h element)
const {
668 xml_dim_t
e(element);
669 string nam = e.nameStr();
670 double startPhi = _ns.
attr<
double>(
e,
_CMU(startPhi));
672 vector<double>
z, rmin, rmax,
r;
674 for(xml_coll_t rzpoint(element,
_CMU(RZPoint)); rzpoint; ++rzpoint) {
675 z.emplace_back(_ns.
attr<
double>(rzpoint,_U(z)));
676 r.emplace_back(_ns.
attr<
double>(rzpoint,_U(r)));
679 for(xml_coll_t zplane(element,
_CMU(ZSection)); zplane; ++zplane) {
682 z.emplace_back(_ns.
attr<
double>(zplane,_U(z)));
685 "+ Polycone: startPhi=%10.3f [rad] deltaPhi=%10.3f [rad] %4ld z-planes",
686 startPhi, deltaPhi, z.size());
687 _ns.
addSolid(nam, Polycone(startPhi,deltaPhi,rmin,rmax,z));
691 "+ Polycone: startPhi=%10.3f [rad] deltaPhi=%10.3f [rad] %4ld z-planes and %4ld radii",
692 startPhi, deltaPhi, z.size(), r.size());
693 _ns.
addSolid(nam, Polycone(startPhi,deltaPhi,r,z));
698 template <>
void Converter<DDLExtrudedPolygon>::operator()(xml_h element)
const {
700 xml_dim_t
e(element);
701 string nam = e.nameStr();
702 vector<double> pt_x, pt_y, sec_x, sec_y, sec_z, sec_scale;
704 for(xml_coll_t sec(element,
_CMU(ZXYSection)); sec; ++sec) {
705 sec_z.emplace_back(_ns.
attr<
double>(sec,_U(
z)));
706 sec_x.emplace_back(_ns.
attr<
double>(sec,_U(
x)));
707 sec_y.emplace_back(_ns.
attr<
double>(sec,_U(
y)));
708 sec_scale.emplace_back(_ns.
attr<
double>(sec,
_CMU(
scale),1.0));
710 for(xml_coll_t
pt(element,
_CMU(XYPoint));
pt; ++
pt) {
711 pt_x.emplace_back(_ns.
attr<
double>(
pt,_U(
x)));
712 pt_y.emplace_back(_ns.
attr<
double>(
pt,_U(
y)));
715 "+ ExtrudedPolygon: %4ld points %4ld zxy sections",
716 pt_x.size(), sec_z.size());
721 template <>
void Converter<DDLPolyhedra>::operator()(xml_h element)
const {
723 xml_dim_t
e(element);
724 string nam = e.nameStr();
725 double numSide = _ns.
attr<
int>(
e,
_CMU(numSide));
726 double startPhi = _ns.
attr<
double>(
e,
_CMU(startPhi));
728 vector<double>
z, rmin, rmax;
730 for(xml_coll_t zplane(element,
_CMU(RZPoint)); zplane; ++zplane) {
731 rmin.emplace_back(0.0);
732 rmax.emplace_back(_ns.
attr<
double>(zplane,_U(
r)));
733 z.emplace_back(_ns.
attr<
double>(zplane,_U(z)));
735 for(xml_coll_t zplane(element,
_CMU(ZSection)); zplane; ++zplane) {
738 z.emplace_back(_ns.
attr<
double>(zplane,_U(z)));
741 "+ Polyhedra:startPhi=%8.3f [rad] deltaPhi=%8.3f [rad] %4d sides %4ld z-planes",
742 startPhi, deltaPhi, numSide, z.size());
747 template <>
void Converter<DDLSphere>::operator()(xml_h element)
const {
749 xml_dim_t
e(element);
750 string nam = e.nameStr();
753 double startPhi = _ns.
attr<
double>(
e,
_CMU(startPhi));
755 double startTheta = _ns.
attr<
double>(
e,
_CMU(startTheta));
756 double deltaTheta = _ns.
attr<
double>(
e,
_CMU(deltaTheta));
758 "+ Sphere: r_inner=%8.3f [cm] r_outer=%8.3f [cm]" 759 " startPhi=%8.3f [rad] deltaPhi=%8.3f startTheta=%8.3f delteTheta=%8.3f [rad]",
760 rinner, router, startPhi, deltaPhi, startTheta, deltaTheta);
761 _ns.
addSolid(nam, Sphere(rinner, router, startTheta, deltaTheta, startPhi, deltaPhi));
765 template <>
void Converter<DDLTorus>::operator()(xml_h element)
const {
767 xml_dim_t
e(element);
768 string nam = e.nameStr();
769 double r = _ns.
attr<
double>(
e,
_CMU(torusRadius));
772 double startPhi = _ns.
attr<
double>(
e,
_CMU(startPhi));
775 "+ Torus: r=%10.3f [cm] r_inner=%10.3f [cm] r_outer=%10.3f [cm]" 776 " startPhi=%10.3f [rad] deltaPhi=%10.3f [rad]",
777 r, rinner, router, startPhi, deltaPhi);
778 _ns.
addSolid(nam, Torus(r, rinner, router, startPhi, deltaPhi));
782 template <>
void Converter<DDLPseudoTrap>::operator()(xml_h element)
const {
784 xml_dim_t
e(element);
785 string nam = e.nameStr();
786 double dx1 = _ns.
attr<
double>(
e,
_CMU(dx1));
787 double dy1 = _ns.
attr<
double>(
e,
_CMU(dy1));
788 double dx2 = _ns.
attr<
double>(
e,
_CMU(dx2));
789 double dy2 = _ns.
attr<
double>(
e,
_CMU(dy2));
790 double dz = _ns.
attr<
double>(
e,_U(dz));
792 bool atMinusZ = _ns.
attr<
bool> (
e,
_CMU(atMinusZ));
794 "+ Pseudotrap: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2=%.3f dy2=%.3f radius:%.3f atMinusZ:%s",
795 dz, dx1, dy1, dx2, dy2, r, yes_no(atMinusZ));
796 _ns.
addSolid(nam, PseudoTrap(dx1, dx2, dy1, dy2, dz, r, atMinusZ));
800 template <>
void Converter<DDLTrapezoid>::operator()(xml_h element)
const {
802 xml_dim_t
e(element);
803 string nam = e.nameStr();
804 double dz = _ns.
attr<
double>(
e,_U(dz));
805 double alp1 = _ns.
attr<
double>(
e,
_CMU(alp1));
806 double bl1 = _ns.
attr<
double>(
e,
_CMU(bl1));
807 double tl1 = _ns.
attr<
double>(
e,
_CMU(tl1));
808 double h1 = _ns.
attr<
double>(
e,
_CMU(h1));
809 double alp2 = _ns.
attr<
double>(
e,
_CMU(alp2));
810 double bl2 = _ns.
attr<
double>(
e,
_CMU(bl2));
811 double tl2 = _ns.
attr<
double>(
e,
_CMU(tl2));
812 double h2 = _ns.
attr<
double>(
e,
_CMU(h2));
813 double phi = _ns.
attr<
double>(
e,_U(phi),0.0);
814 double theta = _ns.
attr<
double>(
e,_U(theta),0.0);
817 "+ Trapezoid: dz=%10.3f [cm] alp1:%.3f bl1=%.3f tl1=%.3f alp2=%.3f bl2=%.3f tl2=%.3f h2=%.3f phi=%.3f theta=%.3f",
818 dz, alp1, bl1, tl1, h1, alp2, bl2, tl2, h2, phi, theta);
819 _ns.
addSolid( nam, Trap( dz, theta, phi, h1, bl1, tl1, alp1, h2, bl2, tl2, alp2 ));
823 template <>
void Converter<DDLTrd1>::operator()(xml_h element)
const {
825 xml_dim_t
e( element );
826 string nam = e.nameStr();
827 double dx1 = _ns.
attr<
double>(
e,
_CMU( dx1 ));
828 double dy1 = _ns.
attr<
double>(
e,
_CMU( dy1 ));
829 double dx2 = _ns.
attr<
double>(
e,
_CMU( dx2 ), 0.0 );
830 double dy2 = _ns.
attr<
double>(
e,
_CMU( dy2 ), dy1 );
833 "+ Trd1: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2:%.3f dy2:%.3f",
834 dz, dx1, dy1, dx2, dy2);
839 template <>
void Converter<DDLTubs>::operator()(xml_h element)
const {
841 xml_dim_t
e(element);
842 string nam = e.nameStr();
846 double startPhi = _ns.
attr<
double>(
e,
_CMU(startPhi),0.0);
849 "+ Tubs: dz=%8.3f [cm] rmin=%8.3f [cm] rmax=%8.3f [cm]" 850 " startPhi=%8.3f [rad] deltaPhi=%8.3f [rad]", dz, rmin, rmax, startPhi, deltaPhi);
851 _ns.
addSolid(nam, Tube(rmin,rmax,dz,startPhi,deltaPhi));
855 template <>
void Converter<DDLCutTubs>::operator()(xml_h element)
const {
857 xml_dim_t
e(element);
858 string nam = e.nameStr();
862 double startPhi = _ns.
attr<
double>(
e,
_CMU(startPhi));
864 double lx = _ns.
attr<
double>(
e,
_CMU(lx));
865 double ly = _ns.
attr<
double>(
e,
_CMU(ly));
866 double lz = _ns.
attr<
double>(
e,
_CMU(lz));
867 double tx = _ns.
attr<
double>(
e,
_CMU(tx));
868 double ty = _ns.
attr<
double>(
e,
_CMU(ty));
869 double tz = _ns.
attr<
double>(
e,
_CMU(tz));
871 "+ CutTube: dz=%8.3f [cm] rmin=%8.3f [cm] rmax=%8.3f [cm]" 872 " startPhi=%8.3f [rad] deltaPhi=%8.3f [rad]...",
873 dz, rmin, rmax, startPhi, deltaPhi);
874 _ns.
addSolid(nam, CutTube(rmin,rmax,dz,startPhi,deltaPhi,lx,ly,lz,tx,ty,tz));
878 template <>
void Converter<DDLTruncTubs>::operator()(xml_h element)
const {
880 xml_dim_t
e(element);
881 string nam = e.nameStr();
882 double zhalf = _ns.
attr<
double>(
e,
_CMU(zHalf));
885 double startPhi = _ns.
attr<
double>(
e,
_CMU(startPhi));
887 double cutAtStart = _ns.
attr<
double>(
e,
_CMU(cutAtStart));
888 double cutAtDelta = _ns.
attr<
double>(
e,
_CMU(cutAtDelta));
889 bool cutInside = _ns.
attr<
bool>(
e,
_CMU(cutInside));
891 "+ TruncTube:zHalf=%8.3f [cm] rmin=%8.3f [cm] rmax=%8.3f [cm]" 892 " startPhi=%8.3f [rad] deltaPhi=%8.3f [rad] atStart=%8.3f [cm] atDelta=%8.3f [cm] inside:%s",
893 zhalf, rmin, rmax, startPhi, deltaPhi, cutAtStart, cutAtDelta, yes_no(cutInside));
894 _ns.
addSolid(nam, TruncatedTube(zhalf,rmin,rmax,startPhi,deltaPhi,cutAtStart,cutAtDelta,cutInside));
898 template <>
void Converter<DDLEllipticalTube>::operator()(xml_h element)
const {
900 xml_dim_t
e(element);
901 string nam = e.nameStr();
906 "+ EllipticalTube xSemiAxis=%8.3f [cm] ySemiAxis=%8.3f [cm] zHeight=%8.3f [cm]",dx,dy,dz);
907 _ns.
addSolid(nam, EllipticalTube(dx,dy,dz));
911 template <>
void Converter<DDLCone>::operator()(xml_h element)
const {
913 xml_dim_t
e(element);
914 string nam = e.nameStr();
916 double rmin1 = _ns.
attr<
double>(
e,
_CMU(rMin1));
917 double rmin2 = _ns.
attr<
double>(
e,
_CMU(rMin2));
918 double rmax1 = _ns.
attr<
double>(
e,
_CMU(rMax1));
919 double rmax2 = _ns.
attr<
double>(
e,
_CMU(rMax2));
920 double startPhi = _ns.
attr<
double>(
e,
_CMU(startPhi));
924 "+ Cone: dz=%8.3f [cm]" 925 " rmin1=%8.3f [cm] rmax1=%8.3f [cm]" 926 " rmin2=%8.3f [cm] rmax2=%8.3f [cm]" 927 " startPhi=%8.3f [rad] deltaPhi=%8.3f [rad]",
928 dz, rmin1, rmax1, rmin2, rmax2, startPhi, deltaPhi);
929 _ns.
addSolid(nam, ConeSegment(dz,rmin1,rmax1,rmin2,rmax2,startPhi,phi2));
933 template <>
void Converter<DDLShapeless>::operator()(xml_h element)
const {
935 xml_dim_t
e(element);
936 string nam = e.nameStr();
938 "+ Shapeless: THIS ONE CAN ONLY BE USED AT THE VOLUME LEVEL -> Assembly%s", nam.c_str());
943 template <>
void Converter<DDLBox>::operator()(xml_h element)
const {
945 xml_dim_t
e(element);
946 string nam = e.nameStr();
951 "+ Box: dx=%10.3f [cm] dy=%10.3f [cm] dz=%10.3f [cm]", dx, dy, dz);
956 template <>
void Converter<include_load>::operator()(xml_h element)
const {
957 string fname = element.attr<
string>(_U(ref));
960 doc = xml::DocumentHandler().load( fp.fullPath());
961 printout(_param<cms::DDParsingContext>()->debug_includes ? ALWAYS : DEBUG,
962 "MyDDCMS",
"+++ Processing the CMS detector description %s", fname.c_str());
963 _option<DDRegistry>()->
includes.emplace_back( doc );
967 template <>
void Converter<include_unload>::operator()(xml_h element)
const {
968 string fname = xml::DocumentHandler::system_path(element);
969 xml::DocumentHolder(xml_elt_t(element).document()).assign(
nullptr);
970 printout(_param<cms::DDParsingContext>()->debug_includes ? ALWAYS : DEBUG,
971 "MyDDCMS",
"+++ Finished processing %s",fname.c_str());
975 template <>
void Converter<include_constants>::operator()(xml_h element)
const {
976 xml_coll_t(element,
_CMU(ConstantsSection)).for_each(Converter<ConstantsSection>(description,param,optional));
980 template <>
void Converter<DDLAlgorithm>::operator()(xml_h element)
const {
982 xml_dim_t
e(element);
983 string name = e.nameStr();
985 printout(
INFO,
"MyDDCMS",
"+++ Skip disabled algorithms: %s",name.c_str());
992 while(( idx = type.find(
NAMESPACE_SEP )) != string::npos ) type[
idx] =
'_';
997 "MyDDCMS",
"+++ Start executing algorithm %s....",type.c_str());
1002 "MyDDCMS",
"+++ Executed algorithm: %08lX = %s", ret, name.c_str());
1007 DetElement det(PluginService::Create<NamedObject*>(type, &description, _ns.
context, &element, &sd));
1008 if (det.isValid()) {
1010 if ( sd.isValid() ) {
1011 det->flag |= DetElement::Object::HAVE_SENSITIVE_DETECTOR;
1013 if ( seg.isValid() ) {
1014 seg->sensitive =
sd;
1015 seg->detector = det;
1018 if (!det.isValid()) {
1021 except(
"MyDDCMS",
"Failed to execute subdetector creation plugin. " + dbg.missingFactory(type));
1023 description.addDetector(det);
1025 printout(
ERROR,
"MyDDCMS",
"++ FAILED NOT ADDING SUBDETECTOR %08lX = %s",ret, name.c_str());
1030 printout(
ERROR,
"MyDDCMS",
"++ FAILED to convert subdetector: %s: %s", name.c_str(), exc.what());
1034 printout(
ERROR,
"MyDDCMS",
"++ FAILED to convert subdetector: %s: %s", name.c_str(),
"UNKNONW Exception");
1039 template <
class InputIt,
class ForwardIt,
class BinOp>
1041 ForwardIt s_first, ForwardIt s_last,
1044 while( first != last ) {
1045 const auto pos = std::find_first_of( first, last, s_first, s_last );
1046 binary_op( first, pos );
1047 if( pos == last )
break;
1058 cbegin( delims ), cend( delims ),
1061 output.emplace_back(stod(
string(
first,
second )));
1073 cbegin( delims ), cend( delims ),
1084 template <>
void Converter<DDLVector>::operator()( xml_h element )
const {
1088 xml_dim_t
e( element );
1089 string name = e.nameStr();
1090 string type = _ns.
attr<
string>(
e,_U(type));
1091 string nEntries = _ns.
attr<
string>(
e,
_CMU(nEntries));
1092 string val = e.text();
1093 val.erase( remove_if( val.begin(), val.end(), [](
unsigned char x){
return isspace(
x);}), val.end());
1096 "MyDDCMS",
"+++ Vector<%s>: %s[%s]: %s", type.c_str(), name.c_str(),
1097 nEntries.c_str(), val.c_str());
1100 registry->insert( {
name, results } );
1102 for(
auto it : results )
1107 template <>
void Converter<debug>::operator()(xml_h dbg)
const {
1121 template <>
void Converter<DDRegistry>::operator()(xml_h )
const {
1123 DDRegistry* res = _option<DDRegistry>();
1128 "MyDDCMS",
"+++ RESOLVING %ld unknown constants.....",res->unresolvedConst.size());
1129 while ( !res->unresolvedConst.empty() ) {
1130 for(
auto i=res->unresolvedConst.begin();
i!=res->unresolvedConst.end(); ++
i ) {
1131 const string& n = (*i).first;
1133 string&
v = (*i).second;
1135 for(idx=v.find(
'[',0); idx != string::npos; idx = v.find(
'[',idx+1) ) {
1136 idq = v.find(
']',idx+1);
1137 rep = v.substr(idx+1,idq-idx-1);
1138 auto r = res->allConst.find(rep);
1139 if (
r != res->allConst.end() ) {
1140 rep =
"("+(*r).second+
")";
1141 v.replace(idx,idq-idx+1,rep);
1144 if ( v.find(
']') == string::npos ) {
1145 if ( v.find(
"-+") != string::npos || v.find(
"+-") != string::npos ) {
1146 while ( (idx=v.find(
"-+")) != string::npos )
1147 v.replace(idx,2,
"-");
1148 while ( (idx=v.find(
"+-")) != string::npos )
1149 v.replace(idx,2,
"-");
1152 "MyDDCMS",
"+++ [%06ld] ---------- %-40s = %s",
1153 res->unresolvedConst.size()-1,n.c_str(),res->originalConst[
n].c_str());
1154 _ns.addConstantNS(n, v,
"number");
1155 res->unresolvedConst.erase(
i);
1159 if ( ++count > 1000 )
break;
1161 if ( !res->unresolvedConst.empty() ) {
1162 for(
const auto& e : res->unresolvedConst )
1163 printout(
ERROR,
"MyDDCMS",
"+++ Unresolved constant: %-40s = %s.",e.first.c_str(), e.second.c_str());
1164 except(
"MyDDCMS",
"++ FAILED to resolve %ld constant entries:",res->unresolvedConst.size());
1166 res->unresolvedConst.clear();
1167 res->originalConst.clear();
1168 res->allConst.clear();
1171 template <>
void Converter<print_xml_doc>::operator()(xml_h element)
const {
1172 string fname = xml::DocumentHandler::system_path(element);
1173 printout(_param<cms::DDParsingContext>()->debug_includes ? ALWAYS : DEBUG,
1174 "MyDDCMS",
"+++ Processing data from: %s",fname.c_str());
1181 xml_elt_t dddef(element);
1182 string fname = xml::DocumentHandler::system_path(element);
1183 bool open_geometry = dddef.hasChild(
_CMU(open_geometry));
1184 bool close_geometry = dddef.hasChild(
_CMU(close_geometry));
1186 xml_coll_t(dddef, _U(
debug)).for_each(Converter<debug>(det,&context));
1191 printout(
INFO,
"MyDDCMS",
"+++ Processing the CMS detector description %s",fname.c_str());
1194 Converter<print_xml_doc> print_doc(det,&context);
1197 print_doc((doc=dddef.document()).
root());
1198 xml_coll_t(dddef,
_CMU(DisabledAlgo)).for_each(Converter<disabled_algo>(det,&context,&res));
1199 xml_coll_t(dddef,
_CMU(ConstantsSection)).for_each(Converter<ConstantsSection>(det,&context,&res));
1200 xml_coll_t(dddef,
_CMU(VisSection)).for_each(Converter<vissection>(det,&context));
1201 xml_coll_t(dddef,
_CMU(RotationSection)).for_each(Converter<RotationSection>(det,&context));
1202 xml_coll_t(dddef,
_CMU(MaterialSection)).for_each(Converter<MaterialSection>(det,&context));
1204 xml_coll_t(dddef,
_CMU(IncludeSection)).for_each(
_CMU(Include), Converter<include_load>(det,&context,&res));
1206 for(xml::Document
d : res.includes ) {
1207 print_doc((doc=d).
root());
1208 Converter<include_constants>(det,&context,&res)((doc=d).root());
1211 Converter<DDRegistry>(det,&context,&res)(dddef);
1213 for(xml::Document d : res.includes ) {
1214 print_doc((doc=d).
root());
1215 xml_coll_t(d.root(),
_CMU(MaterialSection)).for_each(Converter<MaterialSection>(det,&context));
1217 if ( open_geometry ) {
1218 context.geo_inited =
true;
1222 for(xml::Document d : res.includes ) {
1223 print_doc((doc=d).
root());
1224 xml_coll_t(d.root(),
_CMU(RotationSection)).for_each(Converter<RotationSection>(det,&context));
1226 for(xml::Document d : res.includes ) {
1227 print_doc((doc=d).
root());
1228 xml_coll_t(d.root(),
_CMU(SolidSection)).for_each(Converter<SolidSection>(det,&context));
1230 for(xml::Document d : res.includes ) {
1231 print_doc((doc=d).
root());
1232 xml_coll_t(d.root(),
_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det,&context));
1234 for(xml::Document d : res.includes ) {
1235 print_doc((doc=d).
root());
1236 xml_coll_t(d.root(),
_CMU(
Algorithm)).for_each(Converter<DDLAlgorithm>(det,&context));
1238 for(xml::Document d : res.includes ) {
1239 print_doc((doc=d).
root());
1240 xml_coll_t(d.root(),
_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det,&context));
1244 for(xml::Document d : res.includes ) Converter<include_unload>(det,&context,&res)(d.root());
1246 print_doc((doc=dddef.document()).
root());
1248 xml_coll_t(dddef,
_CMU(SolidSection)).for_each(Converter<SolidSection>(det,&context));
1249 xml_coll_t(dddef,
_CMU(LogicalPartSection)).for_each(Converter<LogicalPartSection>(det,&context));
1250 xml_coll_t(dddef,
_CMU(
Algorithm)).for_each(Converter<DDLAlgorithm>(det,&context));
1251 xml_coll_t(dddef,
_CMU(PosPartSection)).for_each(Converter<PosPartSection>(det,&context));
1254 printout(
ERROR,
"MyDDCMS",
"Exception while processing xml source:%s",doc.uri().c_str());
1255 printout(
ERROR,
"MyDDCMS",
"----> %s", e.what());
1260 if ( close_geometry ) {
1263 printout(
INFO,
"DDDefinition",
"+++ Finished processing %s",fname.c_str());
DDLPosPart handles PosPart elements.
DDLSphere processes all Sphere elements.
std::map< std::string, std::string > allConst
ROOT::Math::Plane3D::Vector Vector
DDLVector handles Rotation and ReflectionRotation elements.
dd4hep::Detector * description
Geom::Theta< T > theta() const
DDLEllipticalTube processes all EllipticalTube elements.
dd4hep::Volume addVolume(dd4hep::Volume vol) const
Add rotation matrix to current namespace.
dd4hep::Solid solid(const std::string &name) const
DDLAlgorithm processes Algorithm elements.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
dd4hep::Rotation3D makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
U second(std::pair< T, U > const &p)
DDLBox processes Box elements.
DDLElementaryMaterial processes ElementaryMaterial elements.
vector< string > splitString(const string &str, const string &delims=",")
std::string realName(const std::string &) const
T attr(xml_elt_t element, const xml_tag_t &name) const
DDLCone processes all Cone elements.
vector< double > splitNumeric(const string &str, const string &delims=",")
constexpr unsigned int hash(const char *str, int h=0)
static void convert_boolean(cms::DDParsingContext *context, xml_h element)
std::set< std::string > disabledAlgs
Namespace of DDCMS conversion namespace.
DDLTubs processes Tubs elements.
std::map< std::string, std::string > originalConst
dd4hep::Solid addSolid(const std::string &name, dd4hep::Solid solid) const
DDLLogicalPart processes LogicalPart elements.
DDParsingContext * context
DDLRotationByAxis handles RotationByAxis elements.
DDLCompositeMaterial processes all CompositeMaterial elements.
std::map< std::string, std::string > unresolvedConst
std::vector< xml::Document > includes
static long load_dddefinition(Detector &det, xml_h element)
Converter for <DDDefinition> tags.
DDLRotationSequence handles a set of Rotations.
void for_each_token(InputIt first, InputIt last, ForwardIt s_first, ForwardIt s_last, BinOp binary_op)
T angle(T x1, T y1, T z1, T x2, T y2, T z2)