11 #include <TGeoManager.h>
12 #include <TGeoVolume.h>
13 #include <TGeoMaterial.h>
14 #include <TGeoMedium.h>
17 #include <TGeoMatrix.h>
24 extern const char*
md5geom(
void);
50 int main(
int narg,
char *argv[])
62 cout<<
"Created TGeoManager :"<<gGeoManager<<endl;
65 TGeoManager *DRGeom = NULL;
72 cerr<<
"Can't get TGeoManager object!"<<endl;
78 cerr<<
"Can't get node object from TGeoManager!"<<endl;
82 TGeoVolume *vol = cnode->GetVolume();
84 cerr<<
"Can't get volume object from TGeoNode!"<<endl;
88 TGeoMaterial *mat = vol->GetMedium()->GetMaterial();
90 cerr<<
"Can't get material object from TGeoVolume!"<<endl;
101 cout<<
"Ignore above ROOT errors they are \"normal\" ;)" << endl;
104 double density=mat->GetDensity();
105 double RadLen=mat->GetRadLen();
106 double A=mat->GetA();
107 double Z=mat->GetZ();
110 cout<<
" Location: (X, Y, Z) = ("<<
X_LAB<<
", "<<
Y_LAB<<
", "<<
Z_LAB<<
")"<<endl;
111 cout<<
"==============================================="<<endl;
112 cout<<
" Volume: "<<vol->GetName()<<endl;
113 cout<<
" material: "<<mat->GetName()<<endl;
114 cout<<
" density: "<<density<<
" g/cm^3"<<endl;
115 cout<<
"rad. length: "<<RadLen<<
" cm"<<endl;
116 cout<<
" A: "<<A<<endl;
117 cout<<
" Z: "<<Z<<endl;
121 gGeoManager->GetCurrentNavigator()->SetCurrentPoint(pos);
122 cout<<
" ancestory: ";
124 for(
int i=0; i<1000; i++){
125 TGeoNode *node = gGeoManager->GetCurrentNavigator()->GetMother(i);
127 if(i>0) cout <<
" -> ";
128 cout << node->GetVolume()->GetName();
139 cerr <<
"Unable to find material map in CCDB corresponding to this point" << endl;
147 if( fabs(rmin) < 1.0E-6) rmin = 0.0;
149 cout <<
"Material map info from CCDB for run " <<
RUN_NUMBER << endl;
150 cout<<
"==============================================="<<endl;
151 cout <<
" namepath: " << map->
GetNamepath() << endl;
152 cout <<
"R range (cm): " << rmin <<
" - " << map->
GetRmax() << endl;
153 cout <<
"Z range (cm): " << map->
GetZmin() <<
" - " << map->
GetZmax() << endl;
154 cout <<
" density: " << node->
Density <<
" g/cm^3"<< endl;
155 cout <<
" rad. length: " << node->
RadLen <<
" cm"<< endl;
156 cout <<
" A: " << node->
A << endl;
157 cout <<
" Z: " << node->
Z << endl;
173 cout<<
"=============================================================="<<endl;
174 cout<<
"Enabling dynamic geometry rendering"<<endl;
175 cout<<
"- - - - - - - - - - - - - - - - - - -"<<endl;
182 string fname =
"./tmp_hddsroot.so";
183 string md5_shared =
"";
185 void *handle = dlopen(fname.c_str(), RTLD_NOW | RTLD_GLOBAL);
187 const char* (*md5geom_ext)(void);
188 *(
void **) (&md5geom_ext) = dlsym(handle,
"md5geom_ext");
189 char *err = dlerror();
191 md5_shared = (*md5geom_ext)();
198 if(md5_shared.length()>0){
199 cout<<
"found existing shared object"<<endl;
200 cout<<
" shared object checksum: "<<md5_shared<<endl;
201 cout<<
" xml checksum: "<<md5_xml<<endl;
202 if(md5_shared != md5_xml){
203 cout<<
"Checksums don't match. Shared object will be regenerated."<<endl;
212 cout <<
"Attaching shared object ..." << endl;
213 handle = dlopen(fname.c_str(), RTLD_NOW | RTLD_GLOBAL);
215 cerr<<
"Unable to open \""<<fname<<
"\"!"<<endl;
216 cerr<<dlerror()<<endl;
232 cout<<
"Please make sure root-config is in your PATH and that"<<endl;
233 cout<<
"the following environment variables are set:" <<endl;
234 cout<<
" HDDS_HOME "<< endl;
235 cout<<
" BMS_OSNAME "<< endl;
238 ofstream ofs(
"tmp_hddsroot.cc");
239 ofs <<
"#include <TSystem.h>"<<endl;
240 ofs <<
"#include <TGeoManager.h>"<<endl;
241 ofs <<
"#include <TGeoVolume.h>"<<endl;
242 ofs <<
"#include <TGeoMaterial.h>"<<endl;
243 ofs <<
"#include <TGeoMedium.h>"<<endl;
244 ofs <<
"#include <TGeoPcon.h>"<<endl;
245 ofs <<
"#include <TGeoPgon.h>"<<endl;
246 ofs <<
"#include <TGeoMatrix.h>"<<endl;
247 ofs <<
"extern \"C\" {"<<endl;
248 ofs <<
"TGeoManager* hddsroot(void);"<<endl;
253 cout <<
"Generating C++ from XML source ...." << endl;
254 string cmd =
"$HDDS_HOME/$BMS_OSNAME/bin/hdds-root_h " +
HDDS_XML +
" >> tmp_hddsroot.cc";
256 int err = system(cmd.c_str());
257 if(err!=0){ cerr <<
"Error running \""<< cmd <<
"\"" << endl; exit(-1); }
260 ofs.open(
"tmp_hddsroot.cc", ios_base::app);
261 ofs <<
"const char* md5geom_ext(void){return md5geom();}"<<endl;
267 cout <<
"Compiling C++ into shared object ..." << endl;
268 cmd =
"c++ -shared -fPIC -o tmp_hddsroot.so `root-config --cflags --libs` -lGeom tmp_hddsroot.cc";
270 err = system(cmd.c_str());
271 if(err!=0){ cerr <<
"Error running \""<< cmd <<
"\"" << endl; exit(-1); }
274 unlink(
"./tmp_hddsroot.cc");
292 cout <<
"Locating geometry ... " << endl;
293 TGeoManager* (*my_hddsroot)(void);
294 *(
void **) (&my_hddsroot) = dlsym(
dlgeom_handle,
"hddsroot");
295 char *err = dlerror();
303 cout <<
"Loading geometry ... " << endl;
304 TGeoManager *geo = (*my_hddsroot)();
307 cout <<
"Geometry loaded successfully" << endl;
308 cout<<
"=============================================================="<<endl;
328 const char* (*md5geom_ext)(void);
329 *(
void **) (&md5geom_ext) = dlsym(
dlgeom_handle,
"md5geom_ext");
330 char *err = dlerror();
337 return (*md5geom_ext)();
347 static string md5_xml=
"";
348 string fname =
"tmp_hddsroot.md5";
349 string cmd =
"$HDDS_HOME/$BMS_OSNAME/bin/hdds-md5 " +
HDDS_XML +
" > " + fname;
350 int err = system(cmd.c_str());
351 if(err!=0){ cerr <<
"Error running \""<< cmd <<
"\"" << endl; exit(-1); }
352 ifstream ifs(fname.c_str());
355 while(ifs.good())ifs >> str;
356 if(str.length()>=32)md5_xml = str.substr(str.length()-32);
359 unlink(fname.c_str());
361 return md5_xml.c_str();
392 bool print_xml_md5_checksum =
false;
394 for(
int i=1; i<narg; i++){
398 string next = (i+1)<narg ? (
const char*)argv[i+1]:
"";
399 if(arg==
"-h" || arg==
"--help")
Usage();
401 if(arg==
"-checksum" || arg==
"--checksum")print_xml_md5_checksum =
true;
402 if(arg.find(
"-xml")==0){
404 if(arg.find(
"=")!=string::npos){
405 HDDS_XML = arg.substr(arg.find(
"=")+1);
408 if( arg==
"-r" && next.length()>0 ){
413 vals.push_back(atof(argv[i]));
419 if(print_xml_md5_checksum){
421 cout <<
"HDDS Geometry MD5 Checksum: " << checksum << endl;
426 if(vals.size() != 3)
Usage();
438 cout<<
"Usage:"<<endl;
439 cout<<
" hd_geom_query [options] X Y Z"<<endl;
441 cout<<
"Print the material properties for the specified point in lab"<<endl;
442 cout<<
" coordinates. Units of X,Y, and Z are cm."<<endl;
444 cout<<
"By default, this uses the geometry in $HDDS/src/hddsroot.h"<<endl;
445 cout<<
"that was used to link this executable. The -xml switch may be used"<<endl;
446 cout<<
"to dynamically compile and link code generated from the XML at run"<<endl;
447 cout<<
"time. If an equals sign \"=\" follows the -xml switch then the"<<endl;
448 cout<<
"main_HDDS.xml file is taken from the remainder of that argument."<<endl;
450 cout<<
"If the -xml switch is specified, then a file named \"tmp_hddsroot.so\""<<endl;
451 cout<<
"is searched for in the current directory. If found, it is opened and"<<endl;
452 cout<<
"the geometry checksum is read from it and compared to that of the XML"<<endl;
453 cout<<
"specified (which may be the default of $HDDS_HOME/main_HDDS.xml)."<<endl;
454 cout<<
"If the two match, then that shared object is used, bypassing the"<<endl;
455 cout<<
"(expensive) compilation phase. If the file is not present, is unreadable,"<<endl;
456 cout<<
"or the checksums don't match, then the shared object is automatically"<<endl;
457 cout<<
"(re)generated."<<endl;
459 cout<<
"Information from the CCDB hosted material map will also be printed."<<endl;
460 cout<<
"This map is used by the track reconstruction software. It is derived"<<endl;
461 cout<<
"from the same ROOT geometry classes used for the above. Keep in mind"<<endl;
462 cout<<
"though that the CCDB material maps are maintained by a human regenerating"<<endl;
463 cout<<
"the maps and committing them to CCDB. i.e. they are not updated automatically."<<endl;
464 cout<<
"One can specify the run number used to index the CCDB via the -r run"<<endl;
465 cout<<
"command line option. The location of the CCDB and variation are set by"<<endl;
466 cout<<
"the standard environment variables."<<endl;
469 cout<<
" options:"<<endl;
470 cout<<
" -h or --help Print this usage statement"<<endl;
471 cout<<
" -xml[=main_HDDS.xml] Dynamically generate geometry"<<endl;
472 cout<<
" -checksum Print the MD5 checksum of the "<<endl;
473 cout<<
" geometry and exit"<<endl;
474 cout<<
" -r run Set run number used for CCDB query"<<endl;
476 cout<<
"If the -xml option is given and no file is specified,"<<endl;
477 cout<<
"then a value of: "<<
HDDS_XML<<endl;
478 cout<<
"is used."<<endl;
const char * md5geom_runtime(void)
double GetZmin(void) const
void MakeSharedObjectFromXML(void)
const char * md5geom(void)
const char * GetMD5Geom(void)
void ParseCommandLineArguments(int &narg, char *argv[])
DGeometry * GetDGeometry(unsigned int run_number)
TGeoManager * hddsroot_runtime(void)
double GetZmax(void) const
const char * md5geom_xml(void)
static unsigned int RUN_NUMBER
double GetRmin(void) const
static void * dlgeom_handle
const MaterialNode * FindNode(const DVector3 &pos) const
double GetRmax(void) const
string GetNamepath(void) const
void Usage(JApplication &app)
int main(int argc, char *argv[])
const DMaterialMap * FindDMaterialMap(DVector3 &pos) const
void init_runtime_xml(void)