-
Notifications
You must be signed in to change notification settings - Fork 4
/
hdds-root_h.cpp
771 lines (708 loc) · 22.6 KB
/
hdds-root_h.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
/*
* hdds-root_h : this is a copy of hdds-root modified to generate a header file
* for the DRootGeom class
*
* Original Verions: B. Zihlmann Sun Feb 15 12:48:59 EST 2009
* Based on hdds-root by Edward Bras, November 1 2003.
* Based on hdds-geant by Richard Jones, May 19 2001.
*
* Notes:
* ------
* 1. Output is sent to standard out through the ordinary c++ i/o library.
* 2. As a by-product of using the DOM parser to access the xml source,
* hdds-geant verifies the source against the schema before translating it.
* Therefore it may also be used as a validator of the xml specification
* (see the -v option).
*/
#define APP_NAME "hdds-root"
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLStringTokenizer.hpp>
#include <xercesc/sax/SAXParseException.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/sax/ErrorHandler.hpp>
using namespace xercesc;
#include "XString.hpp"
#include "XParsers.hpp"
#include "hddsCommon.hpp"
#include <assert.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
#include <vector>
#include <list>
#define X(str) XString(str).unicode_str()
#define S(str) str.c_str()
int first_volume_placement = 0;
void usage()
{
std::cerr
<< "Usage: " << APP_NAME << " [-v] {HDDS file}"
<< std::endl << "Options:" << std::endl
<< " -v validate only" << std::endl;
}
class RootMacroWriter : public CodeWriter
{
public:
RootMacroWriter() {};
void createHeader();
void createTrailer();
int createMaterial(DOMElement* el); // generate code for materials
int createSolid(DOMElement* el,
Refsys& ref); // generate code for solids
int createRotation(Refsys& ref); // generate code for rotations
int createVolume(DOMElement* el,
Refsys& ref); // generate code for placement
int createDivision(XString& divStr,
Refsys& ref); // generate code for divisions
void createUtilityFunctions(DOMElement* el,
const XString& ident); // generate utility functions
};
int main(int argC, char* argV[])
{
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
XString message(toCatch.getMessage());
std::cerr
<< APP_NAME << " - error during initialization!"
<< std::endl << S(message) << std::endl;
return 1;
}
if (argC < 2)
{
usage();
return 1;
}
else if ((argC == 2) && (strcmp(argV[1], "-?") == 0))
{
usage();
return 2;
}
XString xmlFile;
bool rootMacroOutput = true;
int argInd;
for (argInd = 1; argInd < argC; argInd++)
{
if (argV[argInd][0] != '-')
break;
if (strcmp(argV[argInd], "-v") == 0)
rootMacroOutput = false;
else
std::cerr
<< "Unknown option \'" << argV[argInd]
<< "\', ignoring it\n" << std::endl;
}
if (argInd != argC - 1)
{
usage();
return 1;
}
xmlFile = argV[argInd];
#if defined OLD_STYLE_XERCES_PARSER
DOMDocument* document = parseInputDocument(xmlFile,false);
#else
DOMDocument* document = buildDOMDocument(xmlFile,false);
#endif
if (document == 0)
{
std::cerr
<< APP_NAME << " - error parsing HDDS document, "
<< "cannot continue" << std::endl;
return 1;
}
// DOMNode* docEl; commented out to avoid compiler warnings 4/26/2015 DL
try {
/* docEl =*/ document->getDocumentElement();
}
catch (DOMException& e) {
std::cerr << "Woops " << e.msg << std::endl;
return 1;
}
DOMElement* rootEl = document->getElementById(X("everything"));
if (rootEl == 0)
{
std::cerr
<< APP_NAME << " - error scanning HDDS document, " << std::endl
<< " no element named \"everything\" found" << std::endl;
return 1;
}
if (rootMacroOutput)
{
RootMacroWriter fout;
fout.translate(rootEl);
}
XMLPlatformUtils::Terminate();
return 0;
}
struct goo // utility class for RootMacroWriter::createMaterial()
{
double weight;
Substance* sub;
};
int RootMacroWriter::createMaterial(DOMElement* el)
{
int imate = CodeWriter::createMaterial(el);
double a = fSubst.getAtomicWeight();
double z = fSubst.getAtomicNumber();
double dens = fSubst.getDensity();
double radl = fSubst.getRadLength();
// double absl = fSubst.getAbsLength();
double coll = fSubst.getColLength();
// double dedx = fSubst.getMIdEdx();
XString matS = fSubst.getName();
if (fSubst.fBrewList.size() == 0)
{
std::cout
<< "TGeoMaterial *mat" << imate
<< "= new TGeoMaterial(\"" << S(matS)
<< "\"," << a << "," << z << "," << dens << ");"
<< std::endl
<< "mat" << imate << "->SetUniqueID(" << imate << ");"
<< std::endl;
if (dens > 0 && radl > 0)
{
std::cout
<< "mat" << imate
<< "->SetRadLen(" << radl << "," << coll << ");"
<< std::endl;
}
}
else
{
std::stringstream sout;
struct goo gunk;
gunk.weight = 1;
gunk.sub = &fSubst;
std::list<struct goo> gooStack;
gooStack.push_back(gunk);
int nelem = 0;
while (gooStack.size() > 0)
{
gunk = gooStack.front();
gooStack.pop_front();
if (gunk.sub->fBrewList.size() == 0)
{
sout << "mat" << imate
<< "->DefineElement(" << nelem++ << ","
<< gunk.sub->getAtomicWeight() << ","
<< gunk.sub->getAtomicNumber() << ","
<< gunk.weight << ");" << std::endl;
}
else
{
std::list<Substance::Brew>::iterator iter;
for (iter = gunk.sub->fBrewList.begin();
iter != gunk.sub->fBrewList.end();
++iter)
{
struct goo slime;
slime.weight = gunk.weight * iter->wfact;
slime.sub = iter->sub;
gooStack.push_back(slime);
}
}
}
std::cout
<< "TGeoMixture *mat" << imate
<< "= new TGeoMixture(\"" << S(matS)
<< "\"," << nelem << "," << dens << ");"
<< std::endl
<< "mat" << imate << "->SetUniqueID(" << imate << ");"
<< std::endl
<< sout.str();
}
return imate;
}
int RootMacroWriter::createSolid(DOMElement* el, Refsys& ref)
{
int ivolu = CodeWriter::createSolid(el,ref);
int imate = fSubst.fUniqueID;
// int iregion = ref.fRegionID;
int ifield = 0; // default values for tracking properties
double fieldm = 0; // are overridden by values specified in region tag
double tmaxfd = 0;
double stemax = -1;
double deemax = -1;
XString epsil = "0.001";
double stmin = -1;
if (ref.fRegion)
{
DOMNodeList* noBfieldL = ref.fRegion->getElementsByTagName(X("noBfield"));
DOMNodeList* uniBfieldL = ref.fRegion->getElementsByTagName(X("uniformBfield"));
DOMNodeList* mapBfieldL = ref.fRegion->getElementsByTagName(X("mappedBfield"));
DOMNodeList* swimL = ref.fRegion->getElementsByTagName(X("swim"));
if (noBfieldL->getLength() > 0)
{
ifield = 0;
fieldm = 0;
}
else if (uniBfieldL->getLength() > 0)
{
DOMElement* uniBfieldEl = (DOMElement*)uniBfieldL->item(0);
XString bvecS(uniBfieldEl->getAttribute(X("Bx_By_Bz")));
std::stringstream str(S(bvecS));
double B[3];
str >> B[0] >> B[1] >> B[2];
fieldm = sqrt(B[0]*B[0] + B[1]*B[1] + B[2]*B[2]);
ifield = 2;
tmaxfd = 1;
}
else if (mapBfieldL->getLength() > 0)
{
DOMElement* mapBfieldEl = (DOMElement*)mapBfieldL->item(0);
XString bmaxS(mapBfieldEl->getAttribute(X("maxBfield")));
fieldm = atof(S(bmaxS));
ifield = 2;
tmaxfd = 1;
if (swimL->getLength() > 0)
{
DOMElement* swimEl = (DOMElement*)swimL->item(0);
XString methodS(swimEl->getAttribute(X("method")));
ifield = (methodS == "RungeKutta")? 1 : 2;
}
}
}
static int itmedCount = 0;
int itmed = ++itmedCount;
XString nameS(el->getAttribute(X("name")));
XString matS(el->getAttribute(X("material")));
XString sensiS(el->getAttribute(X("sensitive")));
std::cout
<< "TGeoMedium *med" << itmed
<< " = new TGeoMedium(\"" << S(nameS)
<< " " << S(matS) << "\"," << itmed << "," << imate << ","
<< (sensiS == "true" ? 1 : 0) << ","
<< ifield << "," << fieldm << "," << tmaxfd << ","
<< stemax << "," << deemax << "," << epsil << "," << stmin << ");"
<< std::endl;
Units unit;
unit.getConversions(el);
double par[99];
int npar = 0;
XString shapeS(el->getTagName());
if (shapeS == "box")
{
shapeS = "BOX ";
double xl, yl, zl;
XString xyzS(el->getAttribute(X("X_Y_Z")));
std::stringstream listr(xyzS);
listr >> xl >> yl >> zl;
npar = 3;
par[0] = xl/2 /unit.cm;
par[1] = yl/2 /unit.cm;
par[2] = zl/2 /unit.cm;
std::cout
<< "TGeoVolume *" << S(nameS)
<< "= gGeoManager->MakeBox(\"" << S(nameS) << "\",med"
<< itmed << "," << par[0] << "," << par[1] << ","
<< par[2] << ");" << std::endl;
}
else if (shapeS == "eltu")
{
shapeS = "ELTU";
double rx, ry, zl;
// double phi0, dphi;
XString rxyzS(el->getAttribute(X("Rxy_Z")));
std::stringstream listr(rxyzS);
listr >> rx >> ry >> zl;
npar = 3;
par[0] = rx /unit.cm;
par[1] = ry /unit.cm;
par[2] = zl/2 /unit.cm;
std::cout
<< "TGeoVolume *" << S(nameS) << "= gGeoManager->MakeEltu(\""
<< S(nameS) << "\",med" << itmed << ","
<< par[0] << "," << par[1] << "," << par[2] << ");"
<< std::endl;
}
else if (shapeS == "tubs")
{
shapeS = "TUBS";
double ri, ro, zl, phi0, dphi;
XString riozS(el->getAttribute(X("Rio_Z")));
std::stringstream listr(riozS);
listr >> ri >> ro >> zl;
XString profS(el->getAttribute(X("profile")));
listr.clear(), listr.str(profS);
listr >> phi0 >> dphi;
npar = 5;
par[0] = ri /unit.cm;
par[1] = ro /unit.cm;
par[2] = zl/2 /unit.cm;
par[3] = phi0 /unit.deg;
par[4] = (phi0 + dphi) /unit.deg;
if (dphi == 360*unit.deg)
{
shapeS = "TUBE";
npar = 3;
std::cout
<< "TGeoVolume *" << S(nameS) << "= gGeoManager->MakeTube(\""
<< S(nameS) << "\",med" << itmed << ","
<< par[0] << "," << par[1] << "," << par[2] << ");"
<< std::endl;
}
else
{
std::cout
<< "TGeoVolume *" << S(nameS) << "= gGeoManager->MakeTubs(\""
<< S(nameS) << "\",med" << itmed << "," << par[0] << ","
<< par[1] << "," << par[2] << "," << par[3] << "," << par[4]
<< ");" << std::endl;
}
}
else if (shapeS == "trd")
{
shapeS = "TRAP";
double xm, ym, xp, yp, zl;
XString xyzS(el->getAttribute(X("Xmp_Ymp_Z")));
std::stringstream listr(xyzS);
listr >> xm >> xp >> ym >> yp >> zl;
double alph_xz, alph_yz;
XString incS(el->getAttribute(X("inclination")));
listr.clear(), listr.str(incS);
listr >> alph_xz >> alph_yz;
npar = 11;
double x = tan(alph_xz/unit.rad);
double y = tan(alph_yz/unit.rad);
double r = sqrt(x*x + y*y);
par[0] = zl/2 /unit.cm;
par[1] = atan2(r,1)*unit.rad /unit.deg;
par[2] = atan2(y,x)*unit.rad /unit.deg;
par[3] = ym/2 /unit.cm;
par[4] = xm/2 /unit.cm;
par[5] = xm/2 /unit.cm;
par[6] = 0;
par[7] = yp/2 /unit.cm;
par[8] = xp/2 /unit.cm;
par[9] = xp/2 /unit.cm;
par[10] = 0;
std::cout
<< "TGeoVolume *" << S(nameS) << "= gGeoManager->MakeTrap(\""
<< S(nameS) << "\",med" << itmed << "," << par[0] << ","
<< par[1] << "," << par[2] << "," << par[3] << "," << par[4]
<< "," << par[5] << "," << par[6] << "," << par[7] << ","
<< par[8] << "," << par[9] << "," << par[10] << ");"
<< std::endl;
}
else if (shapeS == "pcon")
{
shapeS = "PCON";
double phi0, dphi;
XString profS(el->getAttribute(X("profile")));
std::stringstream listr(profS);
listr >> phi0 >> dphi;
DOMNodeList* planeList = el->getElementsByTagName(X("polyplane"));
npar = 3;
par[0] = phi0 /unit.deg;
par[1] = dphi /unit.deg;
par[2] = planeList->getLength();
for (unsigned int p = 0; p < planeList->getLength(); p++)
{
double ri, ro, zl;
DOMNode* node = planeList->item(p);
DOMElement* elem = (DOMElement*) node;
XString riozS(elem->getAttribute(X("Rio_Z")));
std::stringstream listr1(riozS);
listr1 >> ri >> ro >> zl;
par[npar++] = zl /unit.cm;
par[npar++] = ri /unit.cm;
par[npar++] = ro /unit.cm;
}
std::cout
<< "TGeoVolume *" << S(nameS) << "= gGeoManager->MakePcon(\""
<< S(nameS) << "\",med" << itmed << "," << par[0] << ","
<< par[1] << "," << par[2] << ");" << std::endl;
for (int mycounter=0; mycounter < par[2]; mycounter++)
{
std::cout
<< " ((TGeoPcon*)" << S(nameS)
<< "->GetShape())->DefineSection(" << mycounter
<< "," << par[3+3*mycounter] << "," << par[4+3*mycounter]
<< "," << par[5+3*mycounter] << ");" << std::endl;
}
}
else if (shapeS == "pgon")
{
shapeS = "PGON";
int segments;
XString segS(el->getAttribute(X("segments")));
segments = atoi(S(segS));
double phi0, dphi;
XString profS(el->getAttribute(X("profile")));
std::stringstream listr(profS);
listr >> phi0 >> dphi;
DOMNodeList* planeList = el->getElementsByTagName(X("polyplane"));
npar = 4;
par[0] = phi0 /unit.deg;
par[1] = dphi /unit.deg;
par[2] = segments;
par[3] = planeList->getLength();
for (unsigned int p = 0; p < planeList->getLength(); p++)
{
double ri, ro, zl;
DOMNode* node = planeList->item(p);
DOMElement* elem = (DOMElement*) node;
XString riozS(elem->getAttribute(X("Rio_Z")));
std::stringstream listr1(riozS);
listr1 >> ri >> ro >> zl;
par[npar++] = zl /unit.cm;
par[npar++] = ri /unit.cm;
par[npar++] = ro /unit.cm;
}
std::cout
<< "TGeoVolume *" << S(nameS) << "= gGeoManager->MakePgon(\""
<< S(nameS) << "\",med" << itmed << "," << par[0] << ","
<< par[1] << "," << par[2] << "," << par[3] << ");" << std::endl;
for (int mycounter=0; mycounter < par[3]; mycounter++)
{
std::cout
<< " ((TGeoPgon*)" << S(nameS)
<< "->GetShape())->DefineSection(" << mycounter
<< "," << par[4+3*mycounter] << "," << par[5+3*mycounter]
<< "," << par[6+3*mycounter] << ");" << std::endl;
}
}
else if (shapeS == "cons")
{
shapeS = "CONS";
double rim, rip, rom, rop, zl;
XString riozS(el->getAttribute(X("Rio1_Rio2_Z")));
std::stringstream listr(riozS);
listr >> rim >> rom >> rip >> rop >> zl;
double phi0, dphi;
XString profS(el->getAttribute(X("profile")));
listr.clear(), listr.str(profS);
listr >> phi0 >> dphi;
npar = 7;
par[0] = zl/2 /unit.cm;
par[1] = rim /unit.cm;
par[2] = rom /unit.cm;
par[3] = rip /unit.cm;
par[4] = rop /unit.cm;
par[5] = phi0 /unit.deg;
par[6] = (phi0 + dphi) /unit.deg;
if (dphi == 360*unit.deg)
{
shapeS = "CONE";
npar = 5;
std::cout
<< "TGeoVolume *" << S(nameS) << "= gGeoManager->MakeCone(\""
<< S(nameS) << "\",med" << itmed << ","
<< par[0] << "," << par[1] << "," << par[2]
<< par[3] << "," << par[4] << ");" << std::endl;
}
else
{
std::cout
<< "TGeoVolume *" << S(nameS)
<< "= gGeoManager->MakeCons(\"" << S(nameS)
<< "\",med" << itmed << "," << par[0] << "," << par[1]
<< "," << par[2] << "," << par[3] << "," << par[4] << ","
<< par[5] << "," << par[6] << ");" << std::endl;
}
}
else if (shapeS == "sphere")
{
shapeS = "SPHE";
double ri, ro;
XString rioS(el->getAttribute(X("Rio")));
std::stringstream listr(rioS);
listr >> ri >> ro;
double theta0, theta1;
XString polarS(el->getAttribute(X("polar_bounds")));
listr.clear(), listr.str(polarS);
listr >> theta0 >> theta1;
double phi0, dphi;
XString profS(el->getAttribute(X("profile")));
listr.clear(), listr.str(profS);
listr >> phi0 >> dphi;
npar = 6;
par[0] = ri /unit.cm;
par[1] = ro /unit.cm;
par[2] = theta0 /unit.deg;
par[3] = theta1 /unit.deg;
par[4] = phi0 /unit.deg;
par[5] = (phi0 + dphi) /unit.deg;
std::cout
<< "TGeoVolume *" << S(nameS)
<< "= gGeoManager->MakeSphere(\"" << S(nameS)
<< "\",med" << itmed << "," << par[0] << "," << par[1]
<< "," << par[2] << "," << par[3] << "," << par[4] << ","
<< par[5] << ");" << std::endl;
}
else
{
std::cerr
<< APP_NAME << " error: volume " << S(nameS)
<< " should be one of the valid shapes, not " << S(shapeS)
<< std::endl;
exit(1);
}
if (nameS.size() > 4)
{
std::cerr
<< APP_NAME << " error: volume name " << S(nameS)
<< " should be no more than 4 characters long." << std::endl;
exit(1);
}
return ivolu;
}
int RootMacroWriter::createRotation(Refsys& ref)
{
int irot = CodeWriter::createRotation(ref);
if (irot > 0)
{
double theta[3], phi[3];
for (int i = 0; i < 3; i++)
{
double r = sqrt(ref.fRmatrix[0][i] * ref.fRmatrix[0][i]
+ ref.fRmatrix[1][i] * ref.fRmatrix[1][i]);
theta[i] = atan2(r, ref.fRmatrix[2][i]) * 180/M_PI;
phi[i] = atan2(ref.fRmatrix[1][i], ref.fRmatrix[0][i]) * 180/M_PI;
}
std::cout
<< "TGeoRotation *rot" << irot
<<" = new TGeoRotation(\"rot" << irot << "\","
<< theta[0] << "," << phi[0] << "," << theta[1] << ","
<< phi[1] << "," << theta[2] << "," << phi[2] << ");"
<< std::endl;
}
return irot;
}
int RootMacroWriter::createDivision(XString& divStr, Refsys& ref)
{
int ndiv = CodeWriter::createDivision(divStr,ref);
int iaxis;
if (ref.fPartition.axis == "x")
{
iaxis = 1;
}
else if (ref.fPartition.axis == "y")
{
iaxis = 2;
}
else if (ref.fPartition.axis == "z")
{
iaxis = 3;
}
else if (ref.fPartition.axis == "rho")
{
iaxis = 1;
}
else if (ref.fPartition.axis == "phi")
{
iaxis = 2;
}
else
{
XString motherS(ref.fMother->getAttribute(X("name")));
std::cerr
<< APP_NAME << " error: volume " << S(motherS)
<< " is divided along unsupported axis "
<< "\"" << ref.fPartition.axis << "\""
<< std::endl;
exit(1);
}
XString motherS(ref.fMother->getAttribute(X("name")));
std::cout
<< "TGeoVolume *" << divStr << "= "
<< S(motherS) << "->Divide(\"" << divStr << "\","
<< iaxis << "," << ref.fPartition.ncopy << ","
<< ref.fPartition.start << "," << ref.fPartition.step << ");"
<< std::endl;
return ndiv;
}
int RootMacroWriter::createVolume(DOMElement* el, Refsys& ref)
{
int icopy = CodeWriter::createVolume(el,ref);
if (fPending)
{
XString nameS(el->getAttribute(X("name")));
XString motherS(fRef.fMother->getAttribute(X("name")));
int irot = fRef.fRotation;
if (first_volume_placement == 0)
{
std::cout
<< "gGeoManager->SetTopVolume(" << S(motherS) << ");"
<< std::endl;
first_volume_placement = 1;
}
if (irot == 0)
{
if ( (fRef.fOrigin[0] == 0) &&
(fRef.fOrigin[1] == 0) &&
(fRef.fOrigin[2] == 0))
{
std::cout
<< S(motherS) << "->AddNode("
<< S(nameS) << "," << icopy << ",gGeoIdentity);"
<< std::endl;
}
else
{
std::cout
<< S(motherS) <<"->AddNode(" << S(nameS) << ","
<< icopy << ",new TGeoTranslation("
<< fRef.fOrigin[0] << ","
<< fRef.fOrigin[1] << ","
<< fRef.fOrigin[2] << "));" << std::endl;
}
}
else
{
std::cout
<< S(motherS) <<"->AddNode(" << S(nameS)<< ","
<< icopy << ",new TGeoCombiTrans("
<< fRef.fOrigin[0] << ","
<< fRef.fOrigin[1] << ","
<< fRef.fOrigin[2] << "," << "rot" << irot
<<"));" << std::endl;
}
fPending = false;
}
return icopy;
}
void RootMacroWriter::createHeader()
{
CodeWriter::createHeader();
std::cout
<< "TGeoManager * hddsroot()" << std::endl
<< "{" << std::endl
<< "//" << std::endl
<< "// This file has been generated automatically via the " << std::endl
<< "// utility hdds-root_h directly from main_HDDS.xml " << std::endl
<< "// (see ROOT class TGeoManager for an example of use) " << std::endl
<< "//" << std::endl
<< " " << std::endl
<< "//-----------List of Materials and Mixtures--------------" << std::endl
<< " " << std::endl;
}
void RootMacroWriter::createTrailer()
{
CodeWriter::createTrailer();
std::cout
<< "gGeoManager->CloseGeometry();" << std::endl
<< "gGeoManager->SetTopVolume(SITE);" << std::endl
<< "return gGeoManager;" << std::endl
<< "}" << std::endl;
}
void RootMacroWriter::createUtilityFunctions(DOMElement* el, const XString& ident)
{
// Simply declare here. Implmentation is output from hdds-root.cpp
std::cout
<< std::endl
<< "const char* md5geom(void){ return \""<< last_md5_checksum <<"\";}" << std::endl;
}