30 #include <TGeoMatrix.h>
31 #include <TGeoBoolNode.h>
32 #include <TGeoCompositeShape.h>
37 std::string prefix =
"\t";
47 std::set<const TGeoNode*> nodes;
48 std::set<const TGeoVolume*> volumes;
49 std::set<const TGeoShape*> solids;
50 std::set<const TGeoMatrix*> matrices;
51 std::set<const TGeoMedium*> materials;
52 std::set<const TGeoElement*> elements;
53 std::string
function {
"run_geometry"};
54 bool dump_vis =
false;
55 bool dump_mat =
false;
59 std::ostream& handleHeader (std::ostream& log);
60 std::ostream& handleTrailer (std::ostream& log);
61 std::ostream& handleSolid (std::ostream& log,
const TGeoShape* sh);
62 std::ostream& handleMatrix (std::ostream& log, TGeoMatrix* mat);
63 std::ostream& handleElement (std::ostream& log, TGeoElement* elt);
64 std::ostream& handleMaterial (std::ostream& log, TGeoMedium* mat);
65 std::ostream& handlePlacement(std::ostream& log, TGeoNode* parent, TGeoNode* node);
67 typedef void* pvoid_t;
69 std::ostream& newline(std::ostream& log) {
70 return log << std::endl << prefix;
73 std::ostream& Actor::handleHeader (std::ostream& log) {
74 log <<
"#include \"TClass.h\"" << std::endl
75 <<
"#include \"TGeoNode.h\"" << std::endl
76 <<
"#include \"TGeoExtension.h\"" << std::endl
77 <<
"#include \"TGeoShapeAssembly.h\"" << std::endl
78 <<
"#include \"TGeoMedium.h\"" << std::endl
79 <<
"#include \"TGeoVolume.h\"" << std::endl
80 <<
"#include \"TGeoShape.h\"" << std::endl
81 <<
"#include \"TGeoPhysicalNode.h\"" << std::endl
82 <<
"#include \"TGeoCone.h\"" << std::endl
83 <<
"#include \"TGeoParaboloid.h\"" << std::endl
84 <<
"#include \"TGeoPgon.h\"" << std::endl
85 <<
"#include \"TGeoPcon.h\"" << std::endl
86 <<
"#include \"TGeoSphere.h\"" << std::endl
87 <<
"#include \"TGeoArb8.h\"" << std::endl
88 <<
"#include \"TGeoTrd1.h\"" << std::endl
89 <<
"#include \"TGeoTrd2.h\"" << std::endl
90 <<
"#include \"TGeoTube.h\"" << std::endl
91 <<
"#include \"TGeoEltu.h\"" << std::endl
92 <<
"#include \"TGeoXtru.h\"" << std::endl
93 <<
"#include \"TGeoHype.h\"" << std::endl
94 <<
"#include \"TGeoTorus.h\"" << std::endl
95 <<
"#include \"TGeoHalfSpace.h\"" << std::endl
96 <<
"#include \"TGeoCompositeShape.h\"" << std::endl
97 <<
"#include \"TGeoShapeAssembly.h\"" << std::endl
98 <<
"#include \"TGeoMatrix.h\"" << std::endl
99 <<
"#include \"TGeoBoolNode.h\"" << std::endl
100 <<
"#include \"TGeoCompositeShape.h\"" << std::endl
101 <<
"#include \"TGeoManager.h\"" << std::endl
102 <<
"#include <vector>" << std::endl
103 <<
"#include <map>" << std::endl
104 <<
"#include <set>" << std::endl << std::endl << std::endl;
105 log <<
"TGeoVolume* generate_geometry() {" << newline;
109 std::ostream& Actor::handleTrailer (std::ostream& log) {
110 log << std::endl <<
"}" << std::endl << std::endl;
111 log <<
"void " <<
function <<
"() {" << newline
112 <<
"if ( !gGeoManager ) gGeoManager = new TGeoManager();" << newline
113 <<
"TGeoVolume* vol_top = generate_geometry();" << newline
114 <<
"gGeoManager->SetTopVolume(vol_top);" << newline
115 <<
"vol_top->Draw(\"ogl\");" << newline
116 << std::endl <<
"}" << std::endl;
120 std::ostream& Actor::handlePlacement(std::ostream& log, TGeoNode* parent, TGeoNode* node) {
121 if ( node && nodes.find(node) == nodes.end() ) {
122 TGeoVolume* vol = node->GetVolume();
123 TGeoMatrix* mat = node->GetMatrix();
125 handleMatrix(log, mat);
127 if ( vol && volumes.find(vol) == volumes.end() ) {
129 if ( vol->IsA() == TGeoVolumeAssembly::Class() ) {
130 log <<
"TGeoVolume* vol_" << pvoid_t(vol)
131 <<
" = new TGeoVolumeAssembly(\"" << vol->GetName() <<
"\");" << newline;
134 TGeoMedium* med = vol->GetMedium();
135 TGeoShape* sh = vol->GetShape();
136 handleSolid(log, sh);
137 handleMaterial(log, med);
138 log <<
"TGeoVolume* vol_" << pvoid_t(vol) <<
" = new TGeoVolume(\"" << vol->GetName() <<
"\", "
139 <<
"shape_" << pvoid_t(sh) <<
", material_" << pvoid_t(med) <<
");" << newline;
141 log <<
"vol_" << pvoid_t(vol) <<
"->SetLineColor(Color_t(" << int(vol->GetLineColor()) <<
"));" << newline;
142 log <<
"vol_" << pvoid_t(vol) <<
"->SetLineStyle(" << vol->GetLineStyle() <<
");" << newline;
143 log <<
"vol_" << pvoid_t(vol) <<
"->SetLineWidth(" << vol->GetLineWidth() <<
");" << newline;
144 log <<
"vol_" << pvoid_t(vol) <<
"->SetFillColor(Color_t(" << int(vol->GetFillColor()) <<
"));" << newline;
145 log <<
"vol_" << pvoid_t(vol) <<
"->SetFillStyle(" << vol->GetFillStyle() <<
");" << newline;
150 for (Int_t idau = 0, ndau = node->GetNdaughters(); idau < ndau; ++idau) {
151 TGeoNode* daughter = node->GetDaughter(idau);
152 handlePlacement(log, node, daughter);
156 Int_t ndau = parent->GetNdaughters();
157 TGeoVolume* pvol = parent->GetVolume();
158 log <<
"vol_" << pvoid_t(pvol)
159 <<
"->AddNode(vol_" << pvoid_t(vol) <<
", " << ndau <<
", matrix_" << pvoid_t(mat)
161 log <<
"TGeoNode* node_" << pvoid_t(node) <<
" = vol_" << pvoid_t(pvol)
162 <<
"->GetNode(" << ndau <<
");" << newline;
165 log <<
"return vol_" << pvoid_t(vol) <<
";" << std::endl;
171 std::ostream& Actor::handleElement (std::ostream& log, TGeoElement* elt) {
172 if ( elt && elements.find(elt) == elements.end() ) {
173 elements.insert(elt);
174 log <<
"TGeoElement* elt_" << pvoid_t(elt) <<
" = new TGeoElement(\""
175 << elt->GetName() <<
"\", \"" << elt->GetTitle() <<
"\", ";
176 if ( elt->GetNisotopes() > 0 ) {
177 log << elt->GetNisotopes() <<
");" << newline;
178 for(Int_t i=0; i<elt->GetNisotopes(); ++i) {
179 TGeoIsotope* iso = elt->GetIsotope(i);
180 log <<
"elt_" << pvoid_t(elt) <<
"->AddIsotope("
181 <<
"new TGeoIsotope(\"" << elt->GetName() <<
"_" << iso->GetN()
182 <<
"\", " << iso->GetZ() <<
", " << iso->GetN() <<
", " << iso->GetA() <<
"));"
187 log << elt->Z() <<
", " << elt->N() <<
", " << elt->A() <<
");" << newline;
193 std::ostream& Actor::handleMaterial(std::ostream& log, TGeoMedium* medium) {
194 if ( medium && materials.find(medium) == materials.end() ) {
195 materials.insert(medium);
197 log <<
"TGeoMedium* material_" << pvoid_t(medium) <<
" = gGeoManager->GetMedium(\"IRON\");"
201 TGeoMaterial* mat = medium->GetMaterial();
202 if ( mat->IsMixture() ) {
203 TGeoMixture*
mix = (TGeoMixture*) mat;
204 int nElements =
mix->GetNelements();
205 double W_total = 0.0;
206 for (
int i = 0; i < nElements; ++i) {
207 handleElement(log,
mix->GetElement(i));
208 W_total += (
mix->GetWmixt())[i];
210 log <<
"TGeoMixture* mat_" << pvoid_t(mat) <<
" = new TGeoMixture(\""
211 <<
mix->GetName() <<
"\", " << nElements <<
", " <<
mix->GetDensity() <<
");"
213 for (
int i = 0; i < nElements; ++i) {
214 TGeoElement* e =
mix->GetElement(i);
215 log <<
"mat_" << pvoid_t(mat) <<
"->AddElement(elt_" << pvoid_t(e)
216 <<
", " << ((
mix->GetWmixt())[i]/W_total) <<
");"
220 mix->ComputeDerivedQuantities();
223 double z = mat->GetZ(), a = mat->GetA();
224 if ( z < 1.0000001 ) z = 1.0;
225 if ( a < 0.5000001 ) a = 1.0;
226 log <<
"TGeoMaterial* mat_" << pvoid_t(mat) <<
" = new TGeoMaterial(\""
227 << mat->GetName() <<
"\", " << a <<
", " << z
228 <<
", " << mat->GetDensity()
229 <<
", " << mat->GetRadLen()
230 <<
", " << mat->GetIntLen() <<
");"
233 log <<
"mat_" << pvoid_t(mat) <<
"->SetState(TGeoMaterial::EGeoMaterialState("
234 << mat->GetState() <<
"));" << newline
235 <<
"mat_" << pvoid_t(mat) <<
"->SetPressure(" << mat->GetPressure() <<
");" << newline
236 <<
"mat_" << pvoid_t(mat) <<
"->SetTemperature(" << mat->GetTemperature() <<
");" << newline
237 <<
"mat_" << pvoid_t(mat) <<
"->SetTransparency(" << int(mat->GetTransparency()) <<
");" << newline;
238 log <<
"TGeoMedium* material_" << pvoid_t(medium) <<
" = new TGeoMedium(\""
239 << medium->GetName() <<
"\", " << medium->GetId()
240 <<
", mat_" << pvoid_t(mat) <<
");" << newline;
245 std::ostream& Actor::handleMatrix(std::ostream& log, TGeoMatrix* mat) {
246 if ( mat && matrices.find(mat) == matrices.end() ) {
247 const Double_t* rot = mat->GetRotationMatrix();
248 const Double_t* tra = mat->GetTranslation();
249 const Double_t* sca = mat->GetScale();
250 log <<
"TGeoHMatrix* matrix_" << pvoid_t(mat) <<
" = new TGeoHMatrix(\"" << mat->GetName() <<
"\");"
251 << newline <<
"{" << newline;
252 if ( mat->IsTranslation() ) {
253 log <<
"\t Double_t trans[] = {";
254 for(
size_t i=0; tra && i<3; ++i) {
256 log << ((i<2) ?
", " :
"};");
258 log << newline <<
"\t matrix_" << pvoid_t(mat) <<
"->SetTranslation(trans);" << newline;
260 if ( mat->IsRotation() ) {
261 log <<
"\t Double_t rot[] = {";
262 for(
size_t i=0; rot && i<9; ++i) {
264 log << ((i<8) ?
", " :
"};");
266 log << newline <<
"\t matrix_" << pvoid_t(mat) <<
"->SetRotation(rot);" << newline;
268 if ( mat->IsScale() ) {
269 log <<
"\t Double_t scale[] = {";
270 for(
size_t i=0; sca && i<3; ++i) {
272 log << ((i<2) ?
", " :
"};");
274 log << newline <<
"\t matrix_" << pvoid_t(mat) <<
"->SetScale(scale);" << newline;
276 log <<
"}" << newline;
282 std::ostream& Actor::handleSolid(std::ostream& log,
const TGeoShape* shape) {
283 if ( !shape || solids.find(shape) != solids.end() ) {
286 solids.insert(shape);
288 TClass* cl = shape->IsA();
289 void* pvoid = (
void*)shape;
290 if ( cl == TGeoBBox::Class() ) {
291 TGeoBBox* sh = (TGeoBBox*) shape;
292 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
293 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
294 <<
", " << sh->GetDX()
295 <<
", " << sh->GetDY()
296 <<
", " << sh->GetDZ() <<
");" << newline;
298 else if (cl == TGeoHalfSpace::Class()) {
299 TGeoHalfSpace* sh = (TGeoHalfSpace*)(
const_cast<TGeoShape*
>(shape));
300 log << cl->GetName() <<
"* shape_" << (
void*)shape <<
" = 0;" << newline
302 <<
"\t Double_t* point_ << " << pvoid <<
" = {"
303 << sh->GetPoint()[0] <<
", " << sh->GetPoint()[1] <<
", " << sh->GetPoint()[2] <<
"}; " << newline
304 <<
"\t Double_t* norm_ << " << pvoid <<
" = {"
305 << sh->GetNorm()[0] <<
", " << sh->GetNorm()[1] <<
", " << sh->GetNorm()[2] <<
"}; " << newline
306 <<
"shape_" << pvoid <<
" = "
307 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
"\" "
308 <<
", point_" << pvoid <<
", norm_" << pvoid <<
");" << newline
311 else if (cl == TGeoTube::Class()) {
312 const TGeoTube* sh = (
const TGeoTube*) shape;
313 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
314 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
315 <<
", " << sh->GetRmin()
316 <<
", " << sh->GetRmax()
317 <<
", " << sh->GetDz()
320 else if (cl == TGeoTubeSeg::Class()) {
321 const TGeoTubeSeg* sh = (
const TGeoTubeSeg*) shape;
322 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
323 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
324 <<
", " << sh->GetRmin()
325 <<
", " << sh->GetRmax()
326 <<
", " << sh->GetDz()
327 <<
", " << sh->GetPhi1()
328 <<
", " << sh->GetPhi2()
331 else if (cl == TGeoCtub::Class()) {
332 const TGeoCtub* sh = (
const TGeoCtub*) shape;
333 const Double_t* hi = sh->GetNhigh();
334 const Double_t* lo = sh->GetNlow();
335 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
336 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
337 <<
", " << sh->GetRmin()
338 <<
", " << sh->GetRmax()
339 <<
", " << sh->GetDz()
340 <<
", " << sh->GetPhi1()
341 <<
", " << sh->GetPhi2()
350 else if (cl == TGeoEltu::Class()) {
351 const TGeoEltu* sh = (
const TGeoEltu*) shape;
352 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
353 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
354 <<
", " << sh->GetA()
355 <<
", " << sh->GetB()
356 <<
", " << sh->GetDz()
359 else if (cl == TGeoTrd1::Class()) {
360 const TGeoTrd1* sh = (
const TGeoTrd1*) shape;
361 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
362 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
363 <<
", " << sh->GetDx1()
364 <<
", " << sh->GetDx2()
365 <<
", " << sh->GetDy()
366 <<
", " << sh->GetDz()
369 else if (cl == TGeoTrd2::Class()) {
370 const TGeoTrd2* sh = (
const TGeoTrd2*) shape;
371 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
372 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
373 <<
", " << sh->GetDx1()
374 <<
", " << sh->GetDx2()
375 <<
", " << sh->GetDy1()
376 <<
", " << sh->GetDy2()
377 <<
", " << sh->GetDz()
380 else if (cl == TGeoTrap::Class()) {
381 const TGeoTrap* sh = (
const TGeoTrap*) shape;
382 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
383 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
384 <<
", " << sh->GetDz() <<
", " << sh->GetTheta() <<
", " << sh->GetPhi()
385 <<
", " << sh->GetH1() <<
", " << sh->GetBl1() <<
", " << sh->GetTl1() <<
", " << sh->GetAlpha1()
386 <<
", " << sh->GetH2() <<
", " << sh->GetBl2() <<
", " << sh->GetTl2() <<
", " << sh->GetAlpha2()
389 else if (cl == TGeoHype::Class()) {
390 const TGeoHype* sh = (
const TGeoHype*) shape;
391 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
392 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
393 <<
", " << sh->GetRmin() <<
", " << sh->GetRmax() <<
", " << sh->GetDz()
394 <<
", " << sh->GetStIn() <<
", " << sh->GetStOut()
397 else if (cl == TGeoPgon::Class()) {
398 const TGeoPgon* sh = (
const TGeoPgon*) shape;
399 std::vector<double> params;
400 params.emplace_back(sh->GetPhi1());
401 params.emplace_back(sh->GetDphi());
402 params.emplace_back(
double(sh->GetNedges()));
403 params.emplace_back(
double(sh->GetNz()));
404 for(
int i=0, n=sh->GetNz(); i<n; ++i) {
405 params.emplace_back(sh->GetZ(i));
406 params.emplace_back(sh->GetRmin(i));
407 params.emplace_back(sh->GetRmax(i));
409 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
410 <<
"new " << cl->GetName() <<
"(" << ¶ms[0] <<
");" << newline;
411 log <<
"shape_" << pvoid <<
"->SetName(\"" << sh->GetName() <<
"\");" << newline;
413 else if (cl == TGeoPcon::Class()) {
414 const TGeoPcon* sh = (
const TGeoPcon*) shape;
415 std::vector<double> params;
416 params.emplace_back(sh->GetPhi1());
417 params.emplace_back(sh->GetDphi());
418 params.emplace_back(
double(sh->GetNz()));
419 for(
int i=0, n=sh->GetNz(); i<n; ++i) {
420 params.emplace_back(sh->GetZ(i));
421 params.emplace_back(sh->GetRmin(i));
422 params.emplace_back(sh->GetRmax(i));
424 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
425 <<
"new " << cl->GetName() <<
"(" << ¶ms[0] <<
");" << newline;
426 log <<
"shape_" << pvoid <<
"->SetName(\"" << sh->GetName() <<
"\");" << newline;
428 else if (cl == TGeoCone::Class()) {
429 const TGeoCone* sh = (
const TGeoCone*) shape;
430 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
431 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
432 <<
", " << sh->GetRmin1() <<
", " << sh->GetRmin2() <<
", "
433 <<
", " << sh->GetRmax1() <<
", " << sh->GetRmax2()
434 <<
", " << sh->GetDz()
437 else if (cl == TGeoConeSeg::Class()) {
439 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
440 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
441 <<
", " << sh->GetRmin1() <<
", " << sh->GetRmin2() <<
", "
442 <<
", " << sh->GetRmax1() <<
", " << sh->GetRmax2()
443 <<
", " << sh->GetDz()
444 <<
", " << sh->GetPhi1() <<
", " << sh->GetPhi2()
447 else if (cl == TGeoParaboloid::Class()) {
448 const TGeoParaboloid* sh = (
const TGeoParaboloid*) shape;
449 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
450 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
451 <<
", " << sh->GetRlo() <<
", " << sh->GetRhi() <<
", " << sh->GetDz() <<
");" << newline;
453 else if (cl == TGeoSphere::Class()) {
454 const TGeoSphere* sh = (
const TGeoSphere*) shape;
455 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
456 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
457 <<
", " << sh->GetRmin() <<
", " << sh->GetRmax()
458 <<
", " << sh->GetPhi1() <<
", " << sh->GetPhi2()
459 <<
", " << sh->GetTheta1() <<
", " << sh->GetTheta2()
462 else if (cl == TGeoTorus::Class()) {
463 const TGeoTorus* sh = (
const TGeoTorus*) shape;
464 log << cl->GetName() <<
"* shape_" << pvoid <<
" = "
465 <<
"new " << cl->GetName() <<
"(\"" << sh->GetName() <<
'"'
466 <<
", " << sh->GetRmin() <<
", " << sh->GetRmax() <<
", " << sh->GetR()
467 <<
", " << sh->GetPhi1() <<
", " << sh->GetDphi()
470 else if (cl == TGeoArb8::Class()) {
471 TGeoArb8* sh = (TGeoArb8*) shape;
472 const Double_t*
v = sh->GetVertices();
473 log << cl->GetName() <<
"* shape_" << pvoid <<
" = 0;" << newline
475 <<
"\tstd::vector<double> vertices_" << pvoid <<
";" << newline;
476 for(
int i=0; i<8; ++i) {
477 log <<
"\tvertices_" << pvoid <<
".emplace_back(" << *
v <<
");" << newline; ++
v;
478 log <<
"\tvertices_" << pvoid <<
".emplace_back(" << *
v <<
");" << newline; ++
v;
480 log <<
"\tshape_" << pvoid <<
" = new " << cl->GetName()
481 <<
"(\"" << sh->GetName() <<
'"'
482 <<
", " << sh->GetDz() <<
", &vertices_" << pvoid <<
"[0]);" << newline
485 else if (cl == TGeoXtru::Class()) {
487 const TGeoXtru* sh = (
const TGeoXtru*) shape;
488 std::vector<double> pars = sol.dimensions();
489 log << cl->GetName() <<
"* shape_" << pvoid <<
" = 0;" << newline
491 <<
"\tstd::vector<double> param_" << pvoid <<
";" << newline;
493 log <<
"\tparam_" << pvoid <<
".emplace_back(" << p <<
");" << newline;
494 log <<
"\tshape_" << pvoid <<
" = new " << cl->GetName()
495 <<
"( ¶m_" << pvoid <<
"[0]);" << newline;
496 log <<
"shape_" << pvoid <<
"->SetName(\"" << sh->GetName() <<
"\");" << newline;
498 else if (shape->IsA() == TGeoCompositeShape::Class()) {
499 const TGeoCompositeShape* sh = (
const TGeoCompositeShape*) shape;
500 const TGeoBoolNode*
boolean = sh->GetBoolNode();
501 const TGeoShape* left =
boolean->GetLeftShape();
502 const TGeoShape* right =
boolean->GetRightShape();
503 TGeoBoolNode::EGeoBoolType oper =
boolean->GetBooleanOperator();
504 handleSolid(log, left);
505 handleSolid(log, right);
506 handleMatrix(log, boolean->GetRightMatrix());
507 log <<
"TGeoCompositeShape* shape_" << pvoid_t(sh) <<
" = 0;" << newline;
508 log <<
"{" << newline;
509 if (oper == TGeoBoolNode::kGeoSubtraction)
510 log <<
"\t TGeoSubtraction* boolean = new TGeoSubtraction";
511 else if (oper == TGeoBoolNode::kGeoUnion)
512 log <<
"\t TGeoUnion* boolean = new TGeoUnion";
513 else if (oper == TGeoBoolNode::kGeoIntersection)
514 log <<
"\t TGeoIntersection* boolean = new TGeoIntersection";
515 log <<
"(shape_" << pvoid_t(left) <<
", shape_" << pvoid_t(right) <<
", 0, ";
516 log <<
"matrix_" << pvoid_t(boolean->GetRightMatrix()) <<
");" << newline;
517 log <<
"\t shape_" << pvoid_t(sh)
518 <<
" = new TGeoCompositeShape(\"" << sh->GetName() <<
"\", boolean);" << newline;
519 log <<
"}" << newline;
521 else if (shape->IsA() == TGeoShapeAssembly::Class()) {
526 except(
"CxxRootGenerator",
"++ Unknown shape transformation request: %s", shape->IsA()->GetName());
533 static long generate_cxx(
Detector& description,
int argc,
char** argv) {
537 for(
int i=0; i<argc; ++i) {
538 char c = ::tolower(argv[i][0]);
539 if ( c ==
'-' ) { c = ::tolower(argv[i][1]); }
540 if ( c ==
'-' ) { c = ::tolower(argv[i][1]); }
541 if ( c ==
'o' && i+1<argc )
543 else if ( c ==
'f' && i+1<argc )
544 actor.function = argv[++i];
546 actor.dump_vis =
true;
548 actor.dump_mat =
true;
551 "Usage: -plugin DD4hep_CxxRootGenerator -arg [-arg] \n"
552 " -output <string> Set output file for generated code. Default: stdout \n"
553 " -visualization Also dump visualization attributes of volumes \n"
554 " -materials Also dump proper materials. Default to IRON \n"
555 " -help Show thi help message \n"
556 "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
560 std::unique_ptr<std::ofstream> out;
561 std::ostream* os = &std::cout;
562 if ( !output.empty() ) {
564 out.reset(
new std::ofstream(path.c_str()));
565 if ( !out->good() ) {
567 except(
"CxxRootGenerator",
568 "++ Failed to open output files: %s [%s]",
569 path.c_str(), ::strerror(errno));
572 actor.function = path.filename();
573 if ( actor.function.rfind(
'.') != std::string::npos )
574 actor.function = actor.function.substr(0, actor.function.rfind(
'.'));
575 printout(INFO,
"CxxRootGenerator",
576 "++ Dump generated code to output files: %s [function: %s()]",
577 path.c_str(), actor.function.c_str());
579 else if ( actor.function.empty() ) {
580 actor.function =
"run_geometry";
584 actor.handleHeader(*os);
585 actor.handlePlacement(*os, 0, pv.
ptr());
586 actor.handleTrailer(*os);