7 #include <GeoModelKernel/GeoPhysVol.h>
9 #include <GeoModelXml/Gmx2Geo.h>
10 #include <GeoModelXml/GmxInterface.h>
11 #include <GeoModelRead/ReadGeoModel.h>
20 const std::string &
name,
32 return StatusCode::SUCCESS;
35 const GeoVPhysVol*
GeoModelXmlTool::createTopVolume(GeoPhysVol* world, GmxInterface& gmxInterface,
const std::string& vNode,
const std::string& tableName,
const std::string& containingDetector,
const std::string& envelopeName,
const GeoModelIO::ReadGeoModel* sqlreader)
const
39 if(!sqlreader)
createVolume(world, gmxInterface, vNode, tableName);
42 unsigned int nChildren = world->getNChildVols();
44 const GeoVPhysVol * envVol =
nullptr;
45 const GeoVPhysVol * topVol =
nullptr;
47 bool foundEnvelope =
false;
48 bool foundContainingDetector =
false;
54 if(containingDetector!=
"") detectorName = containingDetector;
56 for (
int iChild = nChildren - 1; iChild>=0; --iChild) {
57 if (world->getNameOfChildVol(iChild) == detectorName) {
60 envVol = &*world->getChildVol(iChild);
61 foundContainingDetector =
true;
62 if(envelopeName==
"") {topVol = envVol;
break;}
63 unsigned int nGrandchildren = envVol->getNChildVols();
64 for (
int iGchild = nGrandchildren - 1; iGchild>=0; --iGchild) {
65 if (envVol->getNameOfChildVol(iGchild) == envelopeName) {
66 topVol = &*(envVol->getChildVol(iGchild));
73 if(containingDetector!=
"" && !foundContainingDetector)
ATH_MSG_ERROR(
"Couldn't find the containing detector "<<containingDetector<<
" in the world hierarchy!");
74 else if(envelopeName!=
"" && !foundEnvelope)
ATH_MSG_ERROR(
"Couldn't find the envelope volume "<<envelopeName<<
" in the world hierarchy!");
82 const std::string& versionTag = versionKey.
tag();
83 const std::string& versionNode = versionKey.
node();
98 if (!recordSet || recordSet->size() == 0) {
100 throw std::runtime_error(
"Unable to obtain recordSet");
103 std::string clobString = record->
getString(
"XMLCLOB");
109 std::string gmxInput;
115 gmxInput =
getBlob(vNode,tableName);
116 if (gmxInput.empty()) {
117 std::string errMessage(
"GeoModelXmlTool::createTopVolume: Empty response received from the database.");
118 throw std::runtime_error(errMessage);
124 if (gmxInput.empty()) {
125 std::string errMessage(
"GeoModelXmlTool::createTopVolume: Unable to find file " +
m_gmxFilename +
126 " with PathResolver; check filename and DATAPATH environment variable");
127 throw std::runtime_error(errMessage);
133 std::string replacementName =
"GeoModelXml/";
135 std::string startdelim =
"SYSTEM \"";
136 std::string enddelim =
"\" [";
137 unsigned startpos = gmxInput.find(startdelim) + startdelim.length();
138 unsigned endpos = gmxInput.find(enddelim);
139 std::string searchName = gmxInput.substr(startpos,(endpos - startpos));
140 if(searchName==
"geomodel.dtd") replacementName+=
"geomodel_v0.dtd";
141 else replacementName+=searchName;
142 ATH_MSG_DEBUG(
"Searching for "<<searchName<<
" and replacing it with "<<replacementName);
143 size_t chars = searchName.length();
144 size_t index = gmxInput.find(searchName);
146 if (
index != std::string::npos) {
149 gmxInput.replace(
index,chars, dtdFile);
151 throw std::runtime_error(
"GeoModelXmlTool::createTopVolume: Did not find valid .dtd in the gmx input string.");
161 std::ifstream in(gmxInput);
171 Gmx2Geo gmx2Geo(gmxInput, world, gmxInterface,
flags);