Skip to content
Snippets Groups Projects
Commit bdf1bdee authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2:
Browse files

MetaData - Put the plugin names into the meta data of the database

parent 3dd09442
No related branches found
No related tags found
1 merge request!340MetaData - Put the plugin names into the meta data of the database
Pipeline #7715421 passed
...@@ -23,20 +23,21 @@ class GeoVGeometryPlugin ...@@ -23,20 +23,21 @@ class GeoVGeometryPlugin
public: public:
//! Default constructor. //! Default constructor.
GeoVGeometryPlugin() : m_publisher(nullptr) {} GeoVGeometryPlugin() = default;
//! Parametrized constructor for plugins that publish lists of nodes //! Parametrized constructor for plugins that publish lists of nodes
GeoVGeometryPlugin(std::string name) : m_publisher(std::make_unique<GeoPublisher>()), m_pluginName( name ) { m_publisher->setName(m_pluginName); } GeoVGeometryPlugin(const std::string& name) :
m_pluginName{name} { m_publisher->setName(m_pluginName); }
virtual ~GeoVGeometryPlugin() {} virtual ~GeoVGeometryPlugin() = default;
//! Create the system geometry. //! Create the system geometry.
/// Note: this is a pure virtual method, so you need to implement it in your derived plugin class /// Note: this is a pure virtual method, so you need to implement it in your derived plugin class
virtual void create ( GeoVPhysVol* world, bool publish = false ) = 0; virtual void create ( GeoVPhysVol* world, bool publish = false ) = 0;
//! Returns the plugin's name //! Returns the plugin's name
std::string getName() { return m_pluginName; } std::string getName() const { return m_pluginName; }
//! Returns the Publisher that publishes the lists of the GeoFullPhysVol and AlignableTransform nodes //! Returns the Publisher that publishes the lists of the GeoFullPhysVol and AlignableTransform nodes
GeoPublisher* getPublisher() { return m_publisher.get(); } GeoPublisher* getPublisher() { return m_publisher.get(); }
...@@ -44,7 +45,7 @@ class GeoVGeometryPlugin ...@@ -44,7 +45,7 @@ class GeoVGeometryPlugin
protected: protected:
//! A GeoPublisher instance is used to publish lists of nodes. //! A GeoPublisher instance is used to publish lists of nodes.
std::unique_ptr<GeoPublisher> m_publisher; std::unique_ptr<GeoPublisher> m_publisher{std::make_unique<GeoPublisher>()};
private: private:
......
...@@ -36,9 +36,10 @@ const std::string shared_obj_extension=".so"; ...@@ -36,9 +36,10 @@ const std::string shared_obj_extension=".so";
void publishMetaData( GMDBManager & db, void publishMetaData( GMDBManager & db,
const std::string& repoPath, const std::string& repoPath,
std::vector<std::string> &inputFiles, const std::vector<std::string> &inputFiles,
std::vector<std::string> &inputPlugins, const std::vector<std::string> &inputPlugins,
std::string &outputFile); const std::vector<std::string> &pluginNames,
const std::string &outputFile);
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
...@@ -65,8 +66,7 @@ int main(int argc, char ** argv) { ...@@ -65,8 +66,7 @@ int main(int argc, char ** argv) {
// //
// Parse the command line: // Parse the command line:
// //
std::vector<std::string> inputFiles; std::vector<std::string> inputFiles{}, inputPlugins{};
std::vector<std::string> inputPlugins;
std::string outputFile; std::string outputFile;
std::string gmAtlasDir{"."}; std::string gmAtlasDir{"."};
bool outputFileSet = false; bool outputFileSet = false;
...@@ -142,6 +142,7 @@ int main(int argc, char ** argv) { ...@@ -142,6 +142,7 @@ int main(int argc, char ** argv) {
} }
std::vector<GeoPublisher*> vecPluginsPublishers; // caches the stores from all plugins std::vector<GeoPublisher*> vecPluginsPublishers; // caches the stores from all plugins
std::vector<std::unique_ptr<GeoVGeometryPlugin>> pluginInstances{};
for (const std::string & plugin : inputPlugins) { for (const std::string & plugin : inputPlugins) {
GeoGeometryPluginLoader loader; GeoGeometryPluginLoader loader;
...@@ -151,7 +152,7 @@ int main(int argc, char ** argv) { ...@@ -151,7 +152,7 @@ int main(int argc, char ** argv) {
std::cout.rdbuf(fileBuff); std::cout.rdbuf(fileBuff);
} }
GeoVGeometryPlugin *factory=loader.load(plugin); std::unique_ptr<GeoVGeometryPlugin> factory{loader.load(plugin)};
if (!factory) { if (!factory) {
std::cerr << "gmcat -- Could not load plugin " << plugin << std::endl; std::cerr << "gmcat -- Could not load plugin " << plugin << std::endl;
return 5; return 5;
...@@ -172,6 +173,7 @@ int main(int argc, char ** argv) { ...@@ -172,6 +173,7 @@ int main(int argc, char ** argv) {
std::cout << "\t ... DONE!" << std::endl; std::cout << "\t ... DONE!" << std::endl;
std::cout.rdbuf(fileBuff); std::cout.rdbuf(fileBuff);
} }
pluginInstances.emplace_back(std::move(factory));
} }
// //
...@@ -184,41 +186,35 @@ int main(int argc, char ** argv) { ...@@ -184,41 +186,35 @@ int main(int argc, char ** argv) {
std::cout.rdbuf(fileBuff); std::cout.rdbuf(fileBuff);
} }
GMDBManager* db = new GMDBManager(file); auto db = std::make_unique<GMDBManager>(file);
if (!db->checkIsDBOpen()){ if (!db->checkIsDBOpen()){
std::cerr << "gmcat -- Error opening the input file: " << file << std::endl; std::cerr << "gmcat -- Error opening the input file: " << file << std::endl;
return 6; return 6;
} }
/* set the GeoModel reader */ /* set the GeoModel reader */
GeoModelIO::ReadGeoModel readInGeo = GeoModelIO::ReadGeoModel(db); GeoModelIO::ReadGeoModel readInGeo = GeoModelIO::ReadGeoModel(db.get());
/* build the GeoModel geometry */ /* build the GeoModel geometry */
const GeoVPhysVol* dbPhys = readInGeo.buildGeoModel(); // builds the whole GeoModel tree in memory PVConstLink dbPhys{readInGeo.buildGeoModel()}; // builds the whole GeoModel tree in memory
/* get an handle on a Volume Cursor, to traverse the whole set of Volumes */ /* get an handle on a Volume Cursor, to traverse the whole set of Volumes */
GeoVolumeCursor aV(dbPhys); GeoVolumeCursor aV(dbPhys);
/* loop over the Volumes in the tree */ /* loop over the Volumes in the tree */
while (!aV.atEnd()) { while (!aV.atEnd()) {
if (aV.getName()!="ANON") { if (aV.getName()!="ANON") {
GeoNameTag *nameTag=new GeoNameTag(aV.getName()); world->add(make_intrusive<GeoNameTag>(aV.getName()));
world->add(nameTag);
} }
GeoTransform *transform= new GeoTransform(aV.getTransform()); world->add(make_intrusive<GeoTransform>(aV.getTransform()));
world->add(transform); world->add(const_pointer_cast(aV.getVolume()));
world->add((GeoVPhysVol *) &*aV.getVolume());
aV.next(); aV.next();
} }
delete db;
if(!verbose) { if(!verbose) {
std::cout.rdbuf(coutBuff); std::cout.rdbuf(coutBuff);
std::cout << "\t ... DONE!" << std::endl; std::cout << "\t ... DONE!" << std::endl;
std::cout.rdbuf(fileBuff); std::cout.rdbuf(fileBuff);
} }
} }
// //
// Open a new database: // Open a new database:
...@@ -259,10 +255,17 @@ int main(int argc, char ** argv) { ...@@ -259,10 +255,17 @@ int main(int argc, char ** argv) {
std::cout << "Writing metadata to the output database ..." << std::endl; std::cout << "Writing metadata to the output database ..." << std::endl;
std::cout.rdbuf(fileBuff); std::cout.rdbuf(fileBuff);
} }
try { std::vector<std::string> systemNames{};
publishMetaData(db,gmAtlasDir,inputFiles,inputPlugins,outputFile); for (auto& plugin : pluginInstances) {
if(plugin->getName().size()){
systemNames.push_back(plugin->getName());
} }
catch(std::runtime_error& e) { }
std::sort(systemNames.begin(), systemNames.end());
try {
publishMetaData(db, gmAtlasDir, inputFiles, inputPlugins, systemNames, outputFile);
} catch(const std::runtime_error& e) {
std::cerr << "ERROR: " << e.what() << std::endl; std::cerr << "ERROR: " << e.what() << std::endl;
return 1; return 1;
} }
......
#include "GeoModelDBManager/GMDBManager.h" #include "GeoModelDBManager/GMDBManager.h"
#include <GeoModelHelpers/StringUtils.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
...@@ -10,11 +11,12 @@ ...@@ -10,11 +11,12 @@
#define STR_VALUE(arg) #arg #define STR_VALUE(arg) #arg
#define STR_NAME(name) STR_VALUE(name) #define STR_NAME(name) STR_VALUE(name)
std::string resolveVariable(const std::string& varName) { namespace{
const char* var = std::getenv(varName.c_str()); static const std::string tableName{"AAHEADER"};
if (!var) return std::string{};
return std::string(var);
} }
using tableVariant = std::variant<int,long,float,double,std::string>;
std::string getCommandOutput(const std::string & cmd, bool firstLineOnly=false) std::string getCommandOutput(const std::string & cmd, bool firstLineOnly=false)
{ {
std::string response; std::string response;
...@@ -34,18 +36,19 @@ std::string getCommandOutput(const std::string & cmd, bool firstLineOnly=false) ...@@ -34,18 +36,19 @@ std::string getCommandOutput(const std::string & cmd, bool firstLineOnly=false)
void publishMetaData( GMDBManager & db, void publishMetaData( GMDBManager & db,
const std::string& repoPath, const std::string& repoPath,
std::vector<std::string> &inputFiles, const std::vector<std::string> &inputFiles,
std::vector<std::string> &inputPlugins, const std::vector<std::string> &inputPlugins,
std::string &outputFile) { const std::vector<std::string> &pluginNames,
const std::string &outputFile) {
struct Metadata { struct Metadata {
std::string dateString=getCommandOutput("date -Iminutes"); std::string dateString=getCommandOutput("date -Iminutes");
std::string username{resolveVariable("USER")}; std::string username{GeoStrUtils::resolveEnviromentVariables("${USER}")};
std::string hostname{}; std::string hostname{};
std::string os; std::string os{};
std::string wd; std::string wd{};
std::string gmversion=STR_NAME(GMVERSION); std::string gmversion=STR_NAME(GMVERSION);
std::string outputFile; std::string outputFile{};
std::string geoModelDataBranch="Undefined"; // or overwritten below std::string geoModelDataBranch="Undefined"; // or overwritten below
std::string gmdataIsClean ="Not applicable"; // or overwritten below std::string gmdataIsClean ="Not applicable"; // or overwritten below
std::string gmdataCommitHash ="Undefined"; // or overwritten below std::string gmdataCommitHash ="Undefined"; // or overwritten below
...@@ -64,7 +67,7 @@ void publishMetaData( GMDBManager & db, ...@@ -64,7 +67,7 @@ void publishMetaData( GMDBManager & db,
char wdbuff[1024]; char wdbuff[1024];
metadata.wd=std::string(getcwd(wdbuff,1024)); metadata.wd=std::string(getcwd(wdbuff,1024));
#else #else
metadata.wd= resolveVariable("PWD"); metadata.wd= GeoStrUtils::resolveEnviromentVariables("${PWD}");
#endif #endif
metadata.outputFile=outputFile; metadata.outputFile=outputFile;
...@@ -78,20 +81,18 @@ void publishMetaData( GMDBManager & db, ...@@ -78,20 +81,18 @@ void publishMetaData( GMDBManager & db,
if (gethostname (hn,1024)==0) metadata.hostname=std::string(hn); if (gethostname (hn,1024)==0) metadata.hostname=std::string(hn);
} }
std::string geomodel_xml_dir=resolveVariable("GEOMODEL_XML_DIR"); std::string geomodel_xml_dir=GeoStrUtils::resolveEnviromentVariables("${GEOMODEL_XML_DIR}");
if (!geomodel_xml_dir.empty()) { if (!geomodel_xml_dir.empty()) {
{ {
metadata.geoModelDataBranch=getCommandOutput("git -C "+ geomodel_xml_dir + " rev-parse --abbrev-ref HEAD"); metadata.geoModelDataBranch=getCommandOutput("git -C "+ geomodel_xml_dir + " rev-parse --abbrev-ref HEAD");
std::string shortGitStatus=getCommandOutput("git -C "+ geomodel_xml_dir + " status -s "); std::string shortGitStatus=getCommandOutput("git -C "+ geomodel_xml_dir + " status -s ");
if (shortGitStatus!="") { if (shortGitStatus!="") {
metadata.gmdataIsClean="no"; metadata.gmdataIsClean="no";
} } else {
else {
std::string synchedToOrigin=getCommandOutput("git -C "+ std::string(geomodel_xml_dir) + " diff origin/"+metadata.geoModelDataBranch,true); std::string synchedToOrigin=getCommandOutput("git -C "+ std::string(geomodel_xml_dir) + " diff origin/"+metadata.geoModelDataBranch,true);
if (synchedToOrigin!="") { if (synchedToOrigin.size()) {
metadata.gmdataIsClean="no"; metadata.gmdataIsClean="no";
} }else {
else {
metadata.gmdataIsClean="yes"; metadata.gmdataIsClean="yes";
metadata.gmdataCommitHash=getCommandOutput("git -C " + std::string(geomodel_xml_dir) + " log -1 --format=format:\"%H\""); metadata.gmdataCommitHash=getCommandOutput("git -C " + std::string(geomodel_xml_dir) + " log -1 --format=format:\"%H\"");
metadata.gmdataAssociatedTag=getCommandOutput("git -C " + std::string(geomodel_xml_dir) + " describe --tag " + metadata.gmdataCommitHash+ " 2> /dev/null"); metadata.gmdataAssociatedTag=getCommandOutput("git -C " + std::string(geomodel_xml_dir) + " describe --tag " + metadata.gmdataCommitHash+ " 2> /dev/null");
...@@ -109,17 +110,13 @@ void publishMetaData( GMDBManager & db, ...@@ -109,17 +110,13 @@ void publishMetaData( GMDBManager & db,
} }
else { else {
std::string synchedToOrigin=getCommandOutput("git -C " + repoPath + " diff origin/"+xtraMetadata.branch,true); std::string synchedToOrigin=getCommandOutput("git -C " + repoPath + " diff origin/"+xtraMetadata.branch,true);
if (synchedToOrigin!="") { xtraMetadata.isClean = synchedToOrigin.empty() ? "yes" : "no";
xtraMetadata.isClean="no"; if (synchedToOrigin.empty()){
}
else {
xtraMetadata.isClean="yes";
xtraMetadata.commitHash=getCommandOutput("git -C " + repoPath + " log -1 --format=format:\"%H\""); xtraMetadata.commitHash=getCommandOutput("git -C " + repoPath + " log -1 --format=format:\"%H\"");
xtraMetadata.associatedTag=getCommandOutput("git -C " + repoPath + " describe --tag " + xtraMetadata.commitHash+ " 2> /dev/null"); xtraMetadata.associatedTag=getCommandOutput("git -C " + repoPath + " describe --tag " + xtraMetadata.commitHash+ " 2> /dev/null");
} }
} }
} } else {
else {
std::cerr << std::endl << "WARNING: no information on User repository will be written to metadata. " << std::endl; std::cerr << std::endl << "WARNING: no information on User repository will be written to metadata. " << std::endl;
} }
...@@ -134,34 +131,25 @@ void publishMetaData( GMDBManager & db, ...@@ -134,34 +131,25 @@ void publishMetaData( GMDBManager & db,
"WorkingDirectory", "WorkingDirectory",
"GeoModelVersion", "GeoModelVersion",
"OutputFile", "OutputFile",
"PluginNames",
"PluginLibs",
"DataBaseFiles",
"GeoModelDataIsClean", "GeoModelDataIsClean",
"GeoModelDataCommitHash", "GeoModelDataCommitHash",
"GeoModelDataAssociatedTag" "GeoModelDataAssociatedTag",
tableName + "_DATA_ID"
}; };
std::vector<std::string> gmcatColTypes={"STRING", std::vector<std::string> gmcatColTypes(gmcatColNames.size(), "STRING");
"STRING" , gmcatColTypes[gmcatColTypes.size() - 1] = "INT";
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING",
"STRING"
};
// Strip extraneous \n // Strip extraneous \n
for (std::string * s : { for (std::string * s : {&metadata.geoModelDataBranch, &metadata.dateString,
&metadata.geoModelDataBranch, &metadata.gmdataAssociatedTag, &xtraMetadata.repo, &xtraMetadata.branch}) {
&metadata.dateString,
&metadata.gmdataAssociatedTag}) {
s->erase(std::remove(s->begin(), s->end(), '\n'), s->end()); s->erase(std::remove(s->begin(), s->end(), '\n'), s->end());
} }
std::vector<std::vector<std::variant<int,long,float,double,std::string>>> gmcatData ={{ std::vector<std::vector<tableVariant>> gmcatData ={{
metadata.dateString, metadata.dateString,
metadata.geoModelDataBranch, metadata.geoModelDataBranch,
metadata.username, metadata.username,
...@@ -170,59 +158,32 @@ void publishMetaData( GMDBManager & db, ...@@ -170,59 +158,32 @@ void publishMetaData( GMDBManager & db,
metadata.wd, metadata.wd,
metadata.gmversion, metadata.gmversion,
metadata.outputFile, metadata.outputFile,
GeoStrUtils::chainUp(pluginNames,";"),
GeoStrUtils::chainUp(inputPlugins,";"),
GeoStrUtils::chainUp(inputFiles,";"),
metadata.gmdataIsClean, metadata.gmdataIsClean,
metadata.gmdataCommitHash, metadata.gmdataCommitHash,
metadata.gmdataAssociatedTag metadata.gmdataAssociatedTag,
0
}}; }};
unsigned int pcounter(0);
for (std::string plugin : inputPlugins) {
gmcatColNames.push_back("P"+std::to_string(pcounter++));
gmcatColTypes.push_back("STRING");
gmcatData[0].push_back((plugin));
}
unsigned int fcounter(0);
for (std::string file : inputFiles) {
gmcatColNames.push_back("F"+std::to_string(fcounter++));
gmcatColTypes.push_back("STRING");
gmcatData[0].push_back(file);
}
// Strip extraneous \n
for (std::string * s : {
&xtraMetadata.repo,
&xtraMetadata.branch }) {
s->erase(std::remove(s->begin(), s->end(), '\n'), s->end());
}
if (xtraMetadata.branch!="Undefined") { if (xtraMetadata.branch!="Undefined") {
std::vector<std::string> xtraColNames={ std::vector<std::string> xtraColNames={"UserCodeGitRepository",
"UserCodeGitRepository",
"UserCodeGitBranch", "UserCodeGitBranch",
"UserCodeRepoIsClean", "UserCodeRepoIsClean",
"UserCodeRepoCommitHash", "UserCodeRepoCommitHash",
"UserCodeAssociatedTag"}; "UserCodeAssociatedTag"};
std::vector<std::string> xtraColTypes={"STRING", std::vector<std::string> xtraColTypes(xtraColNames.size(), "STRING");
"STRING", std::vector<std::vector<tableVariant>> xtraData ={{xtraMetadata.repo,
"STRING",
"STRING",
"STRING"};
std::vector<std::vector<std::variant<int,long,float,double,std::string>>> xtraData ={{
xtraMetadata.repo,
xtraMetadata.branch, xtraMetadata.branch,
xtraMetadata.isClean, xtraMetadata.isClean,
xtraMetadata.commitHash, xtraMetadata.commitHash,
xtraMetadata.associatedTag xtraMetadata.associatedTag }};
}}; gmcatColNames.insert(std::end(gmcatColNames), std::begin(xtraColNames), std::end(xtraColNames));
using std::begin, std::end; gmcatColTypes.insert(std::end(gmcatColTypes), std::begin(xtraColTypes), std::end(xtraColTypes));
gmcatColNames.insert(end(gmcatColNames), begin(xtraColNames), end(xtraColNames)); gmcatData[0].insert(std::end(gmcatData[0]), std::begin(xtraData[0]), std::end(xtraData[0]));
gmcatColTypes.insert(end(gmcatColTypes), begin(xtraColTypes), end(xtraColTypes));
gmcatData[0].insert(end(gmcatData[0]), begin(xtraData[0]), end(xtraData[0]));
db.createCustomTable("AAHEADER", gmcatColNames,gmcatColTypes,gmcatData);
}
else {
db.createCustomTable("AAHEADER", gmcatColNames,gmcatColTypes,gmcatData);
} }
db.createCustomTable(tableName, gmcatColNames,gmcatColTypes,gmcatData);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment