diff --git a/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp b/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp index 15dcf7c0076f73b14d86cb3d370dfa0dbaf7c643..dc340a9577bc8a8c74c44b230662434d919e0f5e 100644 --- a/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp +++ b/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp @@ -1710,12 +1710,13 @@ bool GMDBManager::createTables() { m_childType_tableName[geoNode] = tableName; tab.push_back(tableName); tab.push_back("id"); + tab.push_back("computedVolume"); tab.push_back("XHalfLength"); tab.push_back("YHalfLength"); tab.push_back("ZHalfLength"); storeTableColumnNames(tab); queryStr = fmt::format( - "create table {0}({1} integer primary key, {2} varchar, {3} real, {4} real, {5} real " + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real " "varchar)", tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]); if (0 == (rc = execQuery(queryStr))) { @@ -1730,12 +1731,13 @@ bool GMDBManager::createTables() { m_childType_tableName[geoNode] = tableName; tab.push_back(tableName); tab.push_back("id"); + tab.push_back("computedVolume"); tab.push_back("RMin"); tab.push_back("RMax"); tab.push_back("ZHalfLength"); storeTableColumnNames(tab); queryStr = fmt::format( - "create table {0}({1} integer primary key, {2} varchar, {3} real, {4} real, {5} real " + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real " "varchar)", tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]); if (0 == (rc = execQuery(queryStr))) { @@ -1750,6 +1752,7 @@ bool GMDBManager::createTables() { m_childType_tableName[geoNode] = tableName; tab.push_back(tableName); tab.push_back("id"); + tab.push_back("computedVolume"); tab.push_back("SPhi"); tab.push_back("DPhi"); tab.push_back("NZPlanes"); @@ -1757,7 +1760,7 @@ bool GMDBManager::createTables() { tab.push_back("dataEnd"); storeTableColumnNames(tab); queryStr = fmt::format( - "create table {0}({1} integer primary key, {2} varchar, {3} real, {4} real, {5} integer, {6} integer, {7} integer " + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} integer, {6} integer, {7} integer " "varchar)", tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7]); if (0 == (rc = execQuery(queryStr))) { diff --git a/GeoModelIO/GeoModelWrite/GeoModelWrite/WriteGeoModel.h b/GeoModelIO/GeoModelWrite/GeoModelWrite/WriteGeoModel.h index 01d26f879e3f8994d181ed70efdea2a3f41f447c..a9539ad94b4d9deb62890aa2a0e7cd41056a4a0f 100644 --- a/GeoModelIO/GeoModelWrite/GeoModelWrite/WriteGeoModel.h +++ b/GeoModelIO/GeoModelWrite/GeoModelWrite/WriteGeoModel.h @@ -217,6 +217,10 @@ class WriteGeoModel : public GeoNodeAction { const std::vector<std::string> values) const; unsigned int addRecord(std::vector<std::vector<std::variant<int, long, float, double, std::string>>> *container, const std::vector<std::variant<int, long, float, double, std::string>> values) const; + + std::pair<unsigned, unsigned> addRecordData( + std::vector<std::vector<std::variant<int, long, float, double, std::string>>> *container, + const std::vector<std::vector<std::variant<int, long, float, double, std::string>>> values) const; unsigned int addMaterial(const std::string &name, const double &density, const std::string &elements); @@ -234,8 +238,8 @@ class WriteGeoModel : public GeoNodeAction { const std::string ¶meters); unsigned int addShape(const std::string &type, const std::vector<std::variant<int, long, float, double, std::string>> ¶meters); - std::vector<unsigned> addShapeData(const std::string type, - const std::vector<std::variant<int, long, float, double, std::string>> &shapeData); + std::pair<unsigned, unsigned> addShapeData(const std::string type, + const std::vector<std::vector<std::variant<int, long, float, double, std::string>>> &shapeData); unsigned int addSerialDenominator(const std::string &baseName); unsigned int addSerialIdentifier(const int &baseId); unsigned int addIdentifierTag(const int &identifier); @@ -301,7 +305,7 @@ class WriteGeoModel : public GeoNodeAction { // from TransFunctionRecorder as well. std::string getShapeParameters(const GeoShape *); std::pair<std::vector<std::variant<int, long, float, double, std::string>>, - std::vector<std::variant<int, long, float, double, std::string>>> + std::vector<std::vector<std::variant<int, long, float, double, std::string>>>> getShapeParametersV(const GeoShape *, const bool data = false); std::string getGeoTypeFromVPhysVol(const GeoVPhysVol *vol); diff --git a/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp b/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp index f7af8b0e8d6a4e398ac808329415dd450219e998..03a0a10ba24bcd9a11a387b8ece86574e9f42eaa 100644 --- a/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp +++ b/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp @@ -699,24 +699,24 @@ unsigned int WriteGeoModel::storeShape(const GeoShape* shape) { // LArCustomShape is deprecated. Write it out as a GeoUnidentifiedShape; if (shapeType == "CustomShape") shapeType = "UnidentifiedShape"; - const std::set<std::string> shapesNewDB{"Box", "Tube"}; + const std::set<std::string> shapesNewDB{"Box", "Tube", "Pcon"}; // get shape parameters if (std::count(shapesNewDB.begin(), shapesNewDB.end(), shapeType)) { std::pair<std::vector<std::variant<int, long, float, double, std::string>>, - std::vector<std::variant<int, long, float, double, std::string>>> + std::vector<std::vector<std::variant<int, long, float, double, std::string>>>> shapePair = getShapeParametersV(shape); std::vector<std::variant<int, long, float, double, std::string>> shapePars = shapePair.first; - std::vector<std::variant<int, long, float, double, std::string>> shapeData = shapePair.second; + std::vector<std::vector<std::variant<int, long, float, double, std::string>>> shapeData = shapePair.second; if (shapeData.size() > 0) { // Store the Function's numbers - std::vector<unsigned> dataRows = addShapeData(shapeType, shapeData); - unsigned dataStart = dataRows[0]; - unsigned dataEnd = dataRows[1]; + std::pair<unsigned, unsigned> dataRows = addShapeData(shapeType, shapeData); + unsigned dataStart = dataRows.first; + unsigned dataEnd = dataRows.second; shapePars.push_back(dataStart); shapePars.push_back(dataEnd); } @@ -731,11 +731,14 @@ unsigned int WriteGeoModel::storeShape(const GeoShape* shape) { } else { + std::cout << "WARNING! The shape '" << shapeType + << "' has not been ported to the new DB schema yet, so the old schema will be used to dump it." + << std::endl; std::string shapePars = getShapeParameters(shape); - // store the shape in the DB and returns the ID - return storeObj(shape, shapeType, shapePars); + // store the shape in the DB and returns the ID + return storeObj(shape, shapeType, shapePars); } - return 1; // we should not be here + return 1; // you should not get here } //______________________________________________________________________ @@ -959,14 +962,20 @@ void WriteGeoModel::handleReferencedVPhysVol(const GeoVPhysVol* vol) { // Get shape parameters std::pair<std::vector<std::variant<int, long, float, double, std::string>>, - std::vector<std::variant<int, long, float, double, std::string>>> + std::vector<std::vector<std::variant<int, long, float, double, std::string>>>> WriteGeoModel::getShapeParametersV(const GeoShape *shape, const bool data) { const std::string shapeType = shape->type(); std::vector<std::variant<int, long, float, double, std::string>> shapePars; - std::vector<std::variant<int, long, float, double, std::string>> shapeData; - std::pair<std::vector<std::variant<int, long, float, double, std::string>>, std::vector<std::variant<int, long, float, double, std::string>>> shapePair; + std::vector<std::vector<std::variant<int, long, float, double, std::string>>> shapeData; + std::pair<std::vector<std::variant<int, long, float, double, std::string>>, std::vector<std::vector<std::variant<int, long, float, double, std::string>>>> shapePair; + std::vector<std::variant<int, long, float, double, std::string>> dataRow; + // init the 'computedVolume' column with a dummy value: '-1' + // the real value will be added later, when the DB will be passed throug + // the tool to compute the volume for the shapes and store them + double computedVolumeDummy = -1; + shapePars.push_back(computedVolumeDummy); if ("Box" == shapeType) { @@ -989,11 +998,14 @@ WriteGeoModel::getShapeParametersV(const GeoShape *shape, const bool data) shapePars.push_back(shapeIn->getDPhi()); // get number of Z planes and loop over them const int nZplanes = shapeIn->getNPlanes(); - shapePars.push_back(nZplanes); + shapePars.push_back(nZplanes); + std::cout << "get Zplanes parameters:" << std::endl; for (int i = 0; i < nZplanes; ++i) { - shapeData.push_back(shapeIn->getZPlane(i)); - shapeData.push_back(shapeIn->getRMinPlane(i)); - shapeData.push_back(shapeIn->getRMaxPlane(i)); + dataRow.push_back(shapeIn->getZPlane(i)); + dataRow.push_back(shapeIn->getRMinPlane(i)); + dataRow.push_back(shapeIn->getRMaxPlane(i)); + shapeData.push_back(dataRow); + dataRow.clear(); } } else @@ -1172,13 +1184,15 @@ std::string WriteGeoModel::getShapeParameters(const GeoShape* shape) { CppHelper::to_string_with_precision(shapeIn->getYHalfLength2())); pars.push_back("ZHalfLength=" + CppHelper::to_string_with_precision(shapeIn->getZHalfLength())); - } else if (shapeType == "Tube") { - const GeoTube* tube = dynamic_cast<const GeoTube*>(shape); - pars.push_back("RMin=" + CppHelper::to_string_with_precision(tube->getRMin())); - pars.push_back("RMax=" + CppHelper::to_string_with_precision(tube->getRMax())); - pars.push_back("ZHalfLength=" + - CppHelper::to_string_with_precision(tube->getZHalfLength())); - } else if (shapeType == "Tubs") { + } + // else if (shapeType == "Tube") { + // const GeoTube* tube = dynamic_cast<const GeoTube*>(shape); + // pars.push_back("RMin=" + CppHelper::to_string_with_precision(tube->getRMin())); + // pars.push_back("RMax=" + CppHelper::to_string_with_precision(tube->getRMax())); + // pars.push_back("ZHalfLength=" + + // CppHelper::to_string_with_precision(tube->getZHalfLength())); + // } + else if (shapeType == "Tubs") { const GeoTubs* shapeIn = dynamic_cast<const GeoTubs*>(shape); pars.push_back("RMin=" + CppHelper::to_string_with_precision(shapeIn->getRMin())); pars.push_back("RMax=" + CppHelper::to_string_with_precision(shapeIn->getRMax())); @@ -1728,12 +1742,33 @@ unsigned int WriteGeoModel::addRecord( return idx; } +std::pair<unsigned, unsigned> WriteGeoModel::addRecordData( + std::vector<std::vector<std::variant<int, long, float, double, std::string>>> *container, + const std::vector<std::vector<std::variant<int, long, float, double, std::string>>> values) const +{ + const unsigned dataStart = container->size() + 1; + // Note: ^ we add +1 because start filling the table + // from a new row with respect to what we currently have + + for (const auto &val : values) + { + container->push_back(val); + } + unsigned dataEnd = + container->size(); // index of pushed element = size after pushing, to + // match ID starting at 1 in the DB + std::pair<unsigned, unsigned> ret{dataStart, dataEnd}; + return ret; +} std::vector<unsigned> WriteGeoModel::addExprData( const std::deque<double>& exprData) { std::vector<std::variant<int, long, float, double, std::string>> *container = &m_exprData; - const unsigned dataStart = container->size(); + const unsigned dataStart = container->size() + 1; + // Note: ^ we add +1 because start filling the table + // from a new row with respect to what we currently have + for (const auto& num : exprData) { // std::cout << "num: " << GeoModelIO::CppHelper::to_string_with_precision(num) << std::endl; // DEBUG MSG container->push_back(num); @@ -1748,25 +1783,17 @@ std::vector<unsigned> WriteGeoModel::addExprData( return dataRows; } -std::vector<unsigned> WriteGeoModel::addShapeData(const std::string type, - const std::vector<std::variant<int, long, float, double, std::string>>& shapeData) +std::pair<unsigned, unsigned> WriteGeoModel::addShapeData(const std::string type, + const std::vector<std::vector<std::variant<int, long, float, double, std::string>>>& shapeData) { std::vector<std::vector<std::variant<int, long, float, double, std::string>>> *container = nullptr; if ("Pcon" == type) { container = &m_shapes_Pcon_Data; } - - const unsigned dataStart = container->size(); - unsigned dataEnd = addRecord(container, shapeData); - // ^ index of pushed element = size after pushing, to - // match ID starting at 1 in the DB - - std::vector<unsigned> dataRows; - dataRows.push_back(dataStart); - dataRows.push_back(dataEnd); - return dataRows; + std::pair<unsigned, unsigned> dataPair = addRecordData(container, shapeData); + return dataPair; }