28 #include <TGeoMatrix.h>
29 #include <TGeoBoolNode.h>
30 #include <TGeoCompositeShape.h>
35 std::string prefix =
"\t";
45 std::set<const TGeoNode*> nodes;
46 std::set<const TGeoVolume*> volumes;
47 std::set<const TGeoShape*> solids;
48 std::set<const TGeoMatrix*> matrices;
49 std::set<const TGeoMedium*> materials;
50 std::set<const TGeoElement*> elements;
51 std::string
function {
"run_geometry"};
52 bool dump_vis =
false;
53 bool dump_mat =
false;
57 std::ostream& handleHeader (std::ostream& log);
58 std::ostream& handleTrailer (std::ostream& log);
59 std::ostream& handleSolid (std::ostream& log,
const TGeoShape* sh);
60 std::ostream& handleMatrix (std::ostream& log, TGeoMatrix* mat);
61 std::ostream& handleElement (std::ostream& log, TGeoElement* elt);
62 std::ostream& handleMaterial (std::ostream& log, TGeoMedium* mat);
63 std::ostream& handlePlacement(std::ostream& log, TGeoNode* parent, TGeoNode* node);
65 typedef void* pvoid_t;
67 std::ostream& newline(std::ostream& log) {
68 return log << std::endl << prefix;
71 std::ostream& Actor::handleHeader (std::ostream& log) {
72 log <<
"#include \"TClass.h\"" << std::endl
73 <<
"#include \"TGeoNode.h\"" << std::endl
74 <<
"#include \"TGeoExtension.h\"" << std::endl
75 <<
"#include \"TGeoShapeAssembly.h\"" << std::endl
76 <<
"#include \"TGeoMedium.h\"" << std::endl
77 <<
"#include \"TGeoVolume.h\"" << std::endl
78 <<
"#include \"TGeoShape.h\"" << std::endl
79 <<
"#include \"TGeoPhysicalNode.h\"" << std::endl
80 <<
"#include \"TGeoCone.h\"" << std::endl
81 <<
"#include \"TGeoParaboloid.h\"" << std::endl
82 <<
"#include \"TGeoPgon.h\"" << std::endl
83 <<
"#include \"TGeoPcon.h\"" << std::endl
84 <<
"#include \"TGeoSphere.h\"" << std::endl
85 <<
"#include \"TGeoArb8.h\"" << std::endl
86 <<
"#include \"TGeoTrd1.h\"" << std::endl
87 <<
"#include \"TGeoTrd2.h\"" << std::endl
88 <<
"#include \"TGeoTube.h\"" << std::endl
89 <<
"#include \"TGeoEltu.h\"" << std::endl
90 <<
"#include \"TGeoXtru.h\"" << std::endl
91 <<
"#include \"TGeoHype.h\"" << std::endl
92 <<
"#include \"TGeoTorus.h\"" << std::endl
93 <<
"#include \"TGeoHalfSpace.h\"" << std::endl
94 <<
"#include \"TGeoCompositeShape.h\"" << std::endl
95 <<
"#include \"TGeoShapeAssembly.h\"" << std::endl
96 <<
"#include \"TGeoMatrix.h\"" << std::endl
97 <<
"#include \"TGeoBoolNode.h\"" << std::endl
98 <<
"#include \"TGeoCompositeShape.h\"" << std::endl
99 <<
"#include \"TGeoManager.h\"" << std::endl
100 <<
"#include <vector>" << std::endl
101 <<
"#include <map>" << std::endl
102 <<
"#include <set>" << std::endl << std::endl << std::endl;
103 log <<
"TGeoVolume* generate_geometry() {" << newline;
107 std::ostream& Actor::handleTrailer (std::ostream& log) {
108 log << std::endl <<
"}" << std::endl << std::endl;
109 log <<
"void " <<
function <<
"() {" << newline
110 <<
"if ( !gGeoManager ) gGeoManager = new TGeoManager();" << newline
111 <<
"TGeoVolume* vol_top = generate_geometry();" << newline
112 <<
"gGeoManager->SetTopVolume(vol_top);" << newline
113 <<
"vol_top->Draw(\"ogl\");" << newline
114 << std::endl <<
"}" << std::endl;
118 std::ostream& Actor::handlePlacement(std::ostream& log, TGeoNode* parent, TGeoNode* node) {
119 if ( node && nodes.find(node) == nodes.end() ) {
120 TGeoVolume* vol = node->GetVolume();
121 TGeoMatrix* mat = node->GetMatrix();
123 handleMatrix(log, mat);
125 if ( vol && volumes.find(vol) == volumes.end() ) {
127 if ( vol->IsA() == TGeoVolumeAssembly::Class() ) {
128 log <<
"TGeoVolume* vol_" << pvoid_t(vol)
129 <<
" = new TGeoVolumeAssembly(\"" << vol->GetName() <<
"\");" << newline;
132 TGeoMedium* med = vol->GetMedium();
133 TGeoShape* sh = vol->GetShape();
134 handleSolid(log, sh);
135 handleMaterial(log, med);
136 log <<
"TGeoVolume* vol_" << pvoid_t(vol) <<
" = new TGeoVolume(\"" << vol->GetName() <<
"\", "
137 <<
"shape_" << pvoid_t(sh) <<
", material_" << pvoid_t(med) <<
");" << newline;
139 log <<
"vol_" << pvoid_t(vol) <<
"->SetLineColor(Color_t(" << int(vol->GetLineColor()) <<
"));" << newline;
140 log <<
"vol_" << pvoid_t(vol) <<
"->SetLineStyle(" << vol->GetLineStyle() <<
");" << newline;
141 log <<
"vol_" << pvoid_t(vol) <<
"->SetLineWidth(" << vol->GetLineWidth() <<
");" << newline;
142 log <<
"vol_" << pvoid_t(vol) <<
"->SetFillColor(Color_t(" << int(vol->GetFillColor()) <<
"));" << newline;
143 log <<
"vol_" << pvoid_t(vol) <<
"->SetFillStyle(" << vol->GetFillStyle() <<
");" << newline;
148 for (Int_t idau = 0, ndau = node->GetNdaughters(); idau < ndau; ++idau) {
149 TGeoNode* daughter = node->GetDaughter(idau);
150 handlePlacement(log, node, daughter);
154 Int_t ndau = parent->GetNdaughters();
155 TGeoVolume* pvol = parent->GetVolume();
156 log <<
"vol_" << pvoid_t(pvol)
157 <<
"->AddNode(vol_" << pvoid_t(vol) <<
", " << ndau <<
", matrix_" << pvoid_t(mat)
159 log <<
"TGeoNode* node_" << pvoid_t(node) <<
" = vol_" << pvoid_t(pvol)
160 <<
"->GetNode(" << ndau <<
");" << newline;
163 log <<
"return vol_" << pvoid_t(vol) <<
";" << std::endl;
169 std::ostream& Actor::handleElement (std::ostream& log, TGeoElement* elt) {
170 if ( elt && elements.find(elt) == elements.end() ) {
171 elements.insert(elt);
172 log <<
"TGeoElement* elt_" << pvoid_t(elt) <<
" = new TGeoElement(\""
173 << elt->GetName() <<
"\", \"" << elt->GetTitle() <<
"\", ";
174 if ( elt->GetNisotopes() > 0 ) {
175 log << elt->GetNisotopes() <<
");" << newline;
176 for(Int_t i=0; i<elt->GetNisotopes(); ++i) {
177 TGeoIsotope* iso = elt->GetIsotope(i);
178 log <<
"elt_" << pvoid_t(elt) <<
"->AddIsotope("
179 <<
"new TGeoIsotope(\"" << elt->GetName() <<
"_" << iso->GetN()
180 <<
"\", " << iso->GetZ() <<
", " << iso->GetN() <<
", " << iso->GetA() <<
"));"
185 log << elt->Z() <<
", " << elt->N() <<
", " << elt->A() <<
");" << newline;
191 std::ostream& Actor::handleMaterial(std::ostream& log, TGeoMedium* medium) {
192 if ( medium && materials.find(medium) == materials.end() ) {
193 materials.insert(medium);
195 log <<
"TGeoMedium* material_" << pvoid_t(medium) <<
" = gGeoManager->GetMedium(\"IRON\");"
199 TGeoMaterial* mat = medium->GetMaterial();
200 if ( mat->IsMixture() ) {
201 TGeoMixture*
mix = (TGeoMixture*) mat;
202 int nElements =
mix->GetNelements();
203 double W_total = 0.0;
204 for (
int i = 0; i < nElements; ++i) {
205 handleElement(log,
mix->GetElement(i));
206 W_total += (
mix->GetWmixt())[i];
208 log <<
"TGeoMixture* mat_" << pvoid_t(mat) <<
" = new TGeoMixture(\""
209 <<
mix->GetName() <<
"\", " << nElements <<
", " <<
mix->GetDensity() <<
");"
211 for (
int i = 0; i < nElements; ++i) {
212 TGeoElement* e =
mix->GetElement(i);
213 log <<
"mat_" << pvoid_t(mat) <<
"->AddElement(elt_" << pvoid_t(e)
214 <<
", " << ((
mix->GetWmixt())[i]/W_total) <<
");"
218 mix->ComputeDerivedQuantities();
221 double z = mat->GetZ(), a = mat->GetA();
222 if ( z < 1.0000001 ) z = 1.0;
223 if ( a < 0.5000001 ) a = 1.0;
224 log <<
"TGeoMaterial* mat_" << pvoid_t(mat) <<
" = new TGeoMaterial(\""
225 << mat->GetName() <<
"\", " << a <<
", " << z
226 <<
", " << mat->GetDensity()
227 <<
", " << mat->GetRadLen()
228 <<
", " << mat->GetIntLen() <<
");"
231 log <<
"mat_" << pvoid_t(mat) <<
"->SetState(TGeoMaterial::EGeoMaterialState("
232 << mat->GetState() <<
"));" << newline
233 <<
"mat_" << pvoid_t(mat) <<
"->SetPressure(" << mat->GetPressure() <<
");" << newline
234 <<
"mat_" << pvoid_t(mat) <<
"->SetTemperature(" << mat->GetTemperature() <<
");" << newline
235 <<
"mat_" << pvoid_t(mat) <<
"->SetTransparency(" << int(mat->GetTransparency()) <<
");" << newline;
236 log <<
"TGeoMedium* material_" << pvoid_t(medium) <<
" = new TGeoMedium(\""
237 << medium->GetName() <<
"\", " << medium->GetId()
238 <<
", mat_" << pvoid_t(mat) <<
");" << newline;
243 std::ostream& Actor::handleMatrix(std::ostream& log, TGeoMatrix* mat) {
244 if ( mat && matrices.find(mat) == matrices.end() ) {
245 const Double_t* rot = mat->GetRotationMatrix();
246 const Double_t* tra = mat->GetTranslation();
247 const Double_t* sca = mat->GetScale();
248 log <<
"TGeoHMatrix* matrix_" << pvoid_t(mat) <<
" = new TGeoHMatrix(\"" << mat->GetName() <<
"\");"
249 << newline <<
"{" << newline;
250 if ( mat->IsTranslation() ) {
251 log <<
"\t Double_t trans[] = {";
252 for(
size_t i=0; tra && i<3; ++i) {
254 log << ((i<2) ?
", " :
"};");
256 log << newline <<
"\t matrix_" << pvoid_t(mat) <<
"->SetTranslation(trans);" << newline;
258 if ( mat->IsRotation() ) {
259 log <<
"\t Double_t rot[] = {";
260 for(
size_t i=0; rot && i<9; ++i) {
262 log << ((i<8) ?
", " :
"};");
264 log << newline <<
"\t matrix_" << pvoid_t(mat) <<
"->SetRotation(rot);" << newline;
266 if ( mat->IsScale() ) {
267 log <<
"\t Double_t scale[] = {";
268 for(
size_t i=0; sca && i<3; ++i) {
270 log << ((i<2) ?
", " :
"};");
272 log << newline <<
"\t matrix_" << pvoid_t(mat) <<
"->SetScale(scale);" << newline;
274 log <<
"}" << newline;
280 std::ostream& Actor::handleSolid(std::ostream& log,
const TGeoShape* shape) {
281 if ( !shape || solids.find(shape) != solids.end() ) {
284 solids.insert(shape);
286 TClass* cl = shape->IsA();
287 void* pvoid = (
void*)shape;
288 if ( cl == TGeoBBox::Class() ) {
289 TGeoBBox* sh = (TGeoBBox*) shape;
290 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
291 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
292 <<
", " << sh->GetDX()
293 <<
", " << sh->GetDY()
294 <<
", " << sh->GetDZ() <<
");" << newline;
296 else if (cl == TGeoHalfSpace::Class()) {
297 TGeoHalfSpace* sh = (TGeoHalfSpace*)(
const_cast<TGeoShape*
>(shape));
298 log << cl->GetName() <<
"* shape_" << (
void*)shape <<
" = 0;" << newline
300 <<
"\t Double_t* point_ << " << pvoid <<
" = {"
301 << sh->GetPoint()[0] <<
", " << sh->GetPoint()[1] <<
", " << sh->GetPoint()[2] <<
"}; " << newline
302 <<
"\t Double_t* norm_ << " << pvoid <<
" = {"
303 << sh->GetNorm()[0] <<
", " << sh->GetNorm()[1] <<
", " << sh->GetNorm()[2] <<
"}; " << newline
304 <<
"shape_" << pvoid <<
" = "
305 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
"\" "
306 <<
", point_" << pvoid <<
", norm_" << pvoid <<
");" << newline
309 else if (cl == TGeoTube::Class()) {
310 const TGeoTube* sh = (
const TGeoTube*) shape;
311 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
312 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
313 <<
", " << sh->GetRmin()
314 <<
", " << sh->GetRmax()
315 <<
", " << sh->GetDz()
318 else if (cl == TGeoTubeSeg::Class()) {
319 const TGeoTubeSeg* sh = (
const TGeoTubeSeg*) shape;
320 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
321 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
322 <<
", " << sh->GetRmin()
323 <<
", " << sh->GetRmax()
324 <<
", " << sh->GetDz()
325 <<
", " << sh->GetPhi1()
326 <<
", " << sh->GetPhi2()
329 else if (cl == TGeoCtub::Class()) {
330 const TGeoCtub* sh = (
const TGeoCtub*) shape;
331 const Double_t* hi = sh->GetNhigh();
332 const Double_t* lo = sh->GetNlow();
333 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
334 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
335 <<
", " << sh->GetRmin()
336 <<
", " << sh->GetRmax()
337 <<
", " << sh->GetDz()
338 <<
", " << sh->GetPhi1()
339 <<
", " << sh->GetPhi2()
348 else if (cl == TGeoEltu::Class()) {
349 const TGeoEltu* sh = (
const TGeoEltu*) shape;
350 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
351 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
352 <<
", " << sh->GetA()
353 <<
", " << sh->GetB()
354 <<
", " << sh->GetDz()
357 else if (cl == TGeoTrd1::Class()) {
358 const TGeoTrd1* sh = (
const TGeoTrd1*) shape;
359 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
360 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
361 <<
", " << sh->GetDx1()
362 <<
", " << sh->GetDx2()
363 <<
", " << sh->GetDy()
364 <<
", " << sh->GetDz()
367 else if (cl == TGeoTrd2::Class()) {
368 const TGeoTrd2* sh = (
const TGeoTrd2*) shape;
369 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
370 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
371 <<
", " << sh->GetDx1()
372 <<
", " << sh->GetDx2()
373 <<
", " << sh->GetDy1()
374 <<
", " << sh->GetDy2()
375 <<
", " << sh->GetDz()
378 else if (cl == TGeoTrap::Class()) {
379 const TGeoTrap* sh = (
const TGeoTrap*) shape;
380 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
381 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
382 <<
", " << sh->GetDz() <<
", " << sh->GetTheta() <<
", " << sh->GetPhi()
383 <<
", " << sh->GetH1() <<
", " << sh->GetBl1() <<
", " << sh->GetTl1() <<
", " << sh->GetAlpha1()
384 <<
", " << sh->GetH2() <<
", " << sh->GetBl2() <<
", " << sh->GetTl2() <<
", " << sh->GetAlpha2()
387 else if (cl == TGeoHype::Class()) {
388 const TGeoHype* sh = (
const TGeoHype*) shape;
389 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
390 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
391 <<
", " << sh->GetRmin() <<
", " << sh->GetRmax() <<
", " << sh->GetDz()
392 <<
", " << sh->GetStIn() <<
", " << sh->GetStOut()
395 else if (cl == TGeoPgon::Class()) {
396 const TGeoPgon* sh = (
const TGeoPgon*) shape;
397 std::vector<double> params;
398 params.emplace_back(sh->GetPhi1());
399 params.emplace_back(sh->GetDphi());
400 params.emplace_back(
double(sh->GetNedges()));
401 params.emplace_back(
double(sh->GetNz()));
402 for(
int i=0, n=sh->GetNz(); i<n; ++i) {
403 params.emplace_back(sh->GetZ(i));
404 params.emplace_back(sh->GetRmin(i));
405 params.emplace_back(sh->GetRmax(i));
407 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
408 <<
"new " << cl->GetName() <<
"(" << ¶ms[0] <<
");" << newline;
409 log <<
"shape_" << pvoid <<
"->SetName(\"" << sh->GetName() <<
"\");" << newline;
411 else if (cl == TGeoPcon::Class()) {
412 const TGeoPcon* sh = (
const TGeoPcon*) shape;
413 std::vector<double> params;
414 params.emplace_back(sh->GetPhi1());
415 params.emplace_back(sh->GetDphi());
416 params.emplace_back(
double(sh->GetNz()));
417 for(
int i=0, n=sh->GetNz(); i<n; ++i) {
418 params.emplace_back(sh->GetZ(i));
419 params.emplace_back(sh->GetRmin(i));
420 params.emplace_back(sh->GetRmax(i));
422 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
423 <<
"new " << cl->GetName() <<
"(" << ¶ms[0] <<
");" << newline;
424 log <<
"shape_" << pvoid <<
"->SetName(\"" << sh->GetName() <<
"\");" << newline;
426 else if (cl == TGeoCone::Class()) {
427 const TGeoCone* sh = (
const TGeoCone*) shape;
428 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
429 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
430 <<
", " << sh->GetRmin1() <<
", " << sh->GetRmin2() <<
", "
431 <<
", " << sh->GetRmax1() <<
", " << sh->GetRmax2()
432 <<
", " << sh->GetDz()
435 else if (cl == TGeoConeSeg::Class()) {
437 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
438 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
439 <<
", " << sh->GetRmin1() <<
", " << sh->GetRmin2() <<
", "
440 <<
", " << sh->GetRmax1() <<
", " << sh->GetRmax2()
441 <<
", " << sh->GetDz()
442 <<
", " << sh->GetPhi1() <<
", " << sh->GetPhi2()
445 else if (cl == TGeoParaboloid::Class()) {
446 const TGeoParaboloid* sh = (
const TGeoParaboloid*) shape;
447 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
448 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
449 <<
", " << sh->GetRlo() <<
", " << sh->GetRhi() <<
", " << sh->GetDz() <<
");" << newline;
451 else if (cl == TGeoSphere::Class()) {
452 const TGeoSphere* sh = (
const TGeoSphere*) shape;
453 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
454 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
455 <<
", " << sh->GetRmin() <<
", " << sh->GetRmax()
456 <<
", " << sh->GetPhi1() <<
", " << sh->GetPhi2()
457 <<
", " << sh->GetTheta1() <<
", " << sh->GetTheta2()
460 else if (cl == TGeoTorus::Class()) {
461 const TGeoTorus* sh = (
const TGeoTorus*) shape;
462 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
463 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
464 <<
", " << sh->GetRmin() <<
", " << sh->GetRmax() <<
", " << sh->GetR()
465 <<
", " << sh->GetPhi1() <<
", " << sh->GetDphi()
468 else if (cl == TGeoArb8::Class()) {
469 TGeoArb8* sh = (TGeoArb8*) shape;
470 const Double_t*
v = sh->GetVertices();
471 log << cl->GetName() <<
"* shape_" << pvoid <<
" = 0;" << newline
473 <<
"\tstd::vector<double> vertices_" << pvoid <<
";" << newline;
474 for(
int i=0; i<8; ++i) {
475 log <<
"\tvertices_" << pvoid <<
".emplace_back(" << *
v <<
");" << newline; ++
v;
476 log <<
"\tvertices_" << pvoid <<
".emplace_back(" << *
v <<
");" << newline; ++
v;
478 log <<
"\tshape_" << pvoid <<
" = new " << cl->GetName()
479 <<
"(\"" << sh->GetName() <<
'"'
480 <<
", " << sh->GetDz() <<
", &vertices_" << pvoid <<
"[0]);" << newline
483 else if (cl == TGeoXtru::Class()) {
485 const TGeoXtru* sh = (
const TGeoXtru*) shape;
486 std::vector<double> pars = sol.dimensions();
487 log << cl->GetName() <<
"* shape_" << pvoid <<
" = 0;" << newline
489 <<
"\tstd::vector<double> param_" << pvoid <<
";" << newline;
491 log <<
"\tparam_" << pvoid <<
".emplace_back(" << p <<
");" << newline;
492 log <<
"\tshape_" << pvoid <<
" = new " << cl->GetName()
493 <<
"( ¶m_" << pvoid <<
"[0]);" << newline;
494 log <<
"shape_" << pvoid <<
"->SetName(\"" << sh->GetName() <<
"\");" << newline;
496 else if (shape->IsA() == TGeoCompositeShape::Class()) {
497 const TGeoCompositeShape* sh = (
const TGeoCompositeShape*) shape;
498 const TGeoBoolNode*
boolean = sh->GetBoolNode();
499 const TGeoShape* left =
boolean->GetLeftShape();
500 const TGeoShape* right =
boolean->GetRightShape();
501 TGeoBoolNode::EGeoBoolType oper =
boolean->GetBooleanOperator();
502 handleSolid(log, left);
503 handleSolid(log, right);
504 handleMatrix(log, boolean->GetRightMatrix());
505 log <<
"TGeoCompositeShape* shape_" << pvoid_t(sh) <<
" = 0;" << newline;
506 log <<
"{" << newline;
507 if (oper == TGeoBoolNode::kGeoSubtraction)
508 log <<
"\t TGeoSubtraction* boolean = new TGeoSubtraction";
509 else if (oper == TGeoBoolNode::kGeoUnion)
510 log <<
"\t TGeoUnion* boolean = new TGeoUnion";
511 else if (oper == TGeoBoolNode::kGeoIntersection)
512 log <<
"\t TGeoIntersection* boolean = new TGeoIntersection";
513 log <<
"(shape_" << pvoid_t(left) <<
", shape_" << pvoid_t(right) <<
", 0, ";
514 log <<
"matrix_" << pvoid_t(boolean->GetRightMatrix()) <<
");" << newline;
515 log <<
"\t shape_" << pvoid_t(sh)
516 <<
" = new TGeoCompositeShape(\"" << sh->GetName() <<
"\", boolean);" << newline;
517 log <<
"}" << newline;
519 else if (shape->IsA() == TGeoShapeAssembly::Class()) {
524 except(
"CxxRootGenerator",
"++ Unknown shape transformation request: %s", shape->IsA()->GetName());
531 static long generate_cxx(
Detector& description,
int argc,
char** argv) {
535 for(
int i=0; i<argc; ++i) {
536 char c = ::tolower(argv[i][0]);
537 if ( c ==
'-' ) { c = ::tolower(argv[i][1]); }
538 if ( c ==
'-' ) { c = ::tolower(argv[i][1]); }
539 if ( c ==
'o' && i+1<argc )
541 else if ( c ==
'f' && i+1<argc )
542 actor.function = argv[++i];
544 actor.dump_vis =
true;
546 actor.dump_mat =
true;
549 "Usage: -plugin DD4hep_CxxRootGenerator -arg [-arg] \n"
550 " -output <string> Set output file for generated code. Default: stdout \n"
551 " -visualization Also dump visualization attributes of volumes \n"
552 " -materials Also dump proper materials. Default to IRON \n"
553 " -help Show thi help message \n"
554 "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
558 std::unique_ptr<std::ofstream> out;
559 std::ostream* os = &std::cout;
560 if ( !output.empty() ) {
562 out.reset(
new std::ofstream(path.c_str()));
563 if ( !out->good() ) {
565 except(
"CxxRootGenerator",
566 "++ Failed to open output files: %s [%s]",
567 path.c_str(), ::strerror(errno));
570 actor.function = path.filename();
571 if ( actor.function.rfind(
'.') != std::string::npos )
572 actor.function = actor.function.substr(0, actor.function.rfind(
'.'));
573 printout(INFO,
"CxxRootGenerator",
574 "++ Dump generated code to output files: %s [function: %s()]",
575 path.c_str(), actor.function.c_str());
577 else if ( actor.function.empty() ) {
578 actor.function =
"run_geometry";
582 actor.handleHeader(*os);
583 actor.handlePlacement(*os, 0, pv.
ptr());
584 actor.handleTrailer(*os);