Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DD4hep] Add check for existing constant to prevent unneeded warning message #35594

Merged
merged 1 commit into from Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion DetectorDescription/DDCMS/src/DDNamespace.cc
Expand Up @@ -3,6 +3,7 @@
#include "DataFormats/Math/interface/Rounding.h"
#include "DD4hep/Path.h"
#include "DD4hep/Printout.h"
#include "Evaluator/Evaluator.h"
#include "XML/XML.h"

#include <TClass.h>
Expand Down Expand Up @@ -136,6 +137,10 @@ void DDNamespace::addConstant(const string& name, const string& val, const strin
addConstantNS(prepend(name), val, type);
}

namespace dd4hep {
dd4hep::tools::Evaluator& evaluator();
}

void DDNamespace::addConstantNS(const string& name, const string& val, const string& type) const {
const string& v = val;
const string& n = name;
Expand All @@ -145,7 +150,14 @@ void DDNamespace::addConstantNS(const string& name, const string& val, const str
n.c_str(),
v.c_str(),
type.c_str());
dd4hep::_toDictionary(n, v, type);
const dd4hep::tools::Evaluator& eval(dd4hep::evaluator());
bool constExists = eval.findVariable(n);
dd4hep::printout(
m_context->debug_constants ? dd4hep::ALWAYS : dd4hep::DEBUG, "DD4CMS", "findVariable result = %d", constExists);
if (constExists == false) {
// Only add it to the dictionary if it is not yet defined
dd4hep::_toDictionary(n, v, type);
}
dd4hep::Constant c(n, v, type);

m_context->description.addConstant(c);
Expand Down