24 #include <TInterpreter.h>
25 #include <TGeoElement.h>
26 #include <TGeoManager.h>
41 static long plain_root_dump(
Detector& description,
int argc,
char** argv) {
45 size_t num_volume_patches = 0;
46 size_t num_placement_patches = 0;
49 PrintLevel printLevel = DEBUG;
50 TGeoManip(
DetectorData* dsc,
int mx,
bool imp, PrintLevel p)
51 : detector(dsc), max_level(mx), import(imp), printLevel(p)
55 printout(INFO,
"PlainROOTDump",
"+++ Scanned a total of %9ld NODES",num_nodes);
57 printout(INFO,
"PlainROOTDump",
"+++ Scanned a total of %9ld VOLUMES",num_volume_patches);
58 printout(INFO,
"PlainROOTDump",
"+++ Scanned a total of %9ld PLACEMENTS",num_placement_patches);
61 void operator()(
int lvl, TGeoNode* n) {
64 TGeoVolume*
v = n->GetVolume();
65 bool v_ext =
false, a_ext =
false, p_ext =
false;
67 if ( !
v->GetUserExtension() ) {
68 if (
v->IsA() == TGeoVolume::Class() ) {
73 v->SetUserExtension(
new Assembly::Object());
79 if ( !n->GetUserExtension() ) {
81 ++num_placement_patches;
89 if ( lvl <= max_level ) {
90 if ( !
import || (
import && npatch > 0) ) {
91 ::snprintf(fmt,
sizeof(fmt),
"%-5d %%-%ds %%s NDau:%%d Ext:%%p Vol:%%s Mother:%%s Ext:%%p Mat:%%s",lvl,lvl);
92 TGeoVolume* mother = n->GetMotherVolume();
93 printout(printLevel,
"PlainROOTDump",fmt,
"",
94 n->GetName(), n->GetNdaughters(), n->GetUserExtension(),
95 v->GetName(), mother ? mother->GetName() :
"-----",
96 v->GetUserExtension(),
v->GetMedium()->GetName());
99 ::snprintf(fmt,
sizeof(fmt),
"%-5d %%-%ds --> Adding VOLUME extension object",lvl,lvl);
100 printout(printLevel,
"PlainROOTDump",fmt,
"");
103 ::snprintf(fmt,
sizeof(fmt),
"%-5d %%-%ds --> Adding VOLUME ASSEMBLY extension object",lvl,lvl);
104 printout(printLevel,
"PlainROOTDump",fmt,
"");
107 ::snprintf(fmt,
sizeof(fmt),
"%-5d %%-%ds --> Adding PLACEMENT extension object",lvl,lvl);
108 printout(printLevel,
"PlainROOTDump",fmt,
"");
115 for (Int_t idau = 0, ndau = n->GetNdaughters(); idau < ndau; ++idau) {
116 TGeoNode* daughter = n->GetDaughter(idau);
117 this->operator()(lvl+1, daughter);
123 PrintLevel prt = DEBUG;
124 bool do_import =
false;
125 string input, in_obj =
"Geometry", air, vacuum;
126 for(
int i = 0; i < argc && argv[i]; ++i) {
127 if ( 0 == ::strncmp(
"-input",argv[i],5) && (i+1)<argc )
129 else if ( 0 == ::strncmp(
"-object",argv[i],5) && (i+1)<argc )
131 else if ( 0 == ::strncmp(
"-air",argv[i],5) && (i+1)<argc )
133 else if ( 0 == ::strncmp(
"-vacuum",argv[i],5) && (i+1)<argc )
135 else if ( 0 == ::strncmp(
"-level",argv[i],5) && (i+1)<argc )
136 level = ::atol(argv[++i]);
137 else if ( 0 == ::strncmp(
"-print",argv[i],5) && (i+1)<argc )
138 prt = decodePrintLevel(argv[++i]);
139 else if ( 0 == ::strncmp(
"-import",argv[i],5) )
144 if ( input.empty() || in_obj.empty() ) {
147 "Usage: -plugin <name> -arg [-arg] \n"
148 " name: factory name DD4hep_PlainROOT \n"
149 " -input <string> Input file name. \n"
150 " -object <string> Name of geometry object in file. Default: \"Geometry\"\n"
151 "\tArguments given: " << arguments(argc,argv) << endl << flush;
154 printout(INFO,
"ImportROOT",
"+++ Read geometry from GDML file file:%s",input.c_str());
155 DetectorData::unpatchRootStreamer(TGeoVolume::Class());
156 DetectorData::unpatchRootStreamer(TGeoNode::Class());
157 TFile* f = TFile::Open(input.c_str());
158 if ( f && !f->IsZombie() ) {
160 TGeoManager* mgr = (TGeoManager*)f->Get(in_obj.c_str());
162 TGeoManip manip(
det, level, do_import, prt);
163 DetectorData::patchRootStreamer(TGeoVolume::Class());
164 DetectorData::patchRootStreamer(TGeoNode::Class());
165 det->m_manager = mgr;
166 manip(0, mgr->GetTopNode());
167 det->m_worldVol = mgr->GetTopNode()->GetVolume();
168 if ( !air.empty() ) {
171 if ( !vacuum.empty() ) {
176 detail::deleteObject(f);
180 detail::deleteObject(f);
182 DetectorData::patchRootStreamer(TGeoVolume::Class());
183 DetectorData::patchRootStreamer(TGeoNode::Class());
184 except(
"ImportROOT",
"+++ No input file name given.");