43 static long addVariantParameters(Detector& description,
int argc,
char** argv) {
46 printout(ERROR,
"ParametersPlugin",
"+++ Invalid arguments");
50 printout(INFO,
"ParametersPlugin",
"+++ Applying %d parameters", argc);
53 static std::regex expr{
"^(\\w+)(?:: ?(.*?)?)? ?= ?(.*)"};
55 std::string detector = argv[0];
57 for(
int i=1;i<argc;i++) {
58 std::string kv = argv[i];
60 if(!std::regex_match(kv, m, expr)) {
61 throw std::runtime_error(
"Unable to parse key-value pair to assign");
64 throw std::runtime_error(
"Unable to parse key-value pair to assign");
67 std::string
key = m.str(1);
68 std::string type = m.str(2);
72 std::string value = m.str(3);
74 printout(INFO,
"ParametersPlugin",
"+++ %s -> %s: %s = %s", detector.c_str(),
key.c_str(), type.c_str(), value.c_str());
76 DetElement elt = description.detector(detector);
78 printout(ERROR,
"ParametersPlugin",
"+++ Did not find element with name '%s'", detector.c_str());
83 if(extension ==
nullptr) {
88 if (type ==
"str" || type ==
"string") {
89 extension->variantParameters[
key] = value;
91 else if (type ==
"double") {
94 else if (type ==
"int") {
97 else if (type ==
"bool") {
98 if (value ==
"true") {
99 extension->variantParameters[
key] =
true;
101 else if (value ==
"false") {
102 extension->variantParameters[
key] =
false;
105 throw std::runtime_error{
"Invalid boolean value: " + value};
109 throw std::runtime_error{
"Unknown type '"+type+
"'"};
119 DECLARE_APPLY(DD4hep_ParametersPlugin, dd4hep::rec::addVariantParameters)