File indexing completed on 2025-07-05 08:14:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/ComponentProperties.h>
0016 #include <DD4hep/Factories.h>
0017
0018
0019 #include <iostream>
0020 #include <deque>
0021 #include <list>
0022
0023 using namespace dd4hep;
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #include <sstream>
0034 namespace {
0035 template <typename T> int _test_prop(const std::string& tag, const std::string& data) {
0036 T value;
0037 std::stringstream log;
0038 Property prop(value);
0039 try {
0040 prop.str(data);
0041 log << "| " << std::setw(32) << std::left << tag << " "
0042 << std::setw(6) << std::left << "" << " "
0043 << std::setw(10) << std::left << value << " ";
0044 std::cout << log.str() << std::endl;
0045 }
0046 catch(const std::exception& e) {
0047 std::cout << "Test FAILED: " << tag << " Exception: " << e.what() << std::endl;
0048 return 1;
0049 }
0050 return 0;
0051 }
0052 template <typename T> int _test_cont(const std::string& tag, const std::string& data) {
0053 T value;
0054 std::stringstream log;
0055 Property prop(value);
0056 try {
0057 prop.str(data);
0058 log << "| " << std::setw(32) << std::left << tag << " ";
0059 for(const auto& p : value)
0060 log << std::setw(6) << std::left << "" << " " << std::setw(10) << std::left << p << " ";
0061 std::cout << log.str() << std::endl;
0062 }
0063 catch(const std::exception& e) {
0064 std::cout << "Test FAILED: " << tag << " Exception: " << e.what() << std::endl;
0065 return 1;
0066 }
0067 return 0;
0068 }
0069 template <> int _test_cont<std::vector<bool> >(const std::string& tag, const std::string& data) {
0070 std::vector<bool> value;
0071 std::stringstream log;
0072 Property prop(value);
0073 try {
0074 prop.str(data);
0075 log << "| " << std::setw(32) << std::left << tag << " ";
0076 for(const auto p : value)
0077 log << std::setw(6) << std::left << "" << " " << std::setw(10) << std::left << p << " ";
0078 std::cout << log.str() << std::endl;
0079 }
0080 catch(const std::exception& e) {
0081 std::cout << "Test FAILED: " << tag << " Exception: " << e.what() << std::endl;
0082 return 1;
0083 }
0084 return 0;
0085 }
0086 template <typename T> int _test_map(const std::string& tag, const std::string& data) {
0087 T value;
0088 std::stringstream log;
0089 Property prop(value);
0090 try {
0091 prop.str(data);
0092 log << "| " << std::setw(32) << std::left << tag << " ";
0093 for(const auto& p : value)
0094 log << std::setw(6) << std::left << p.first << " = " << std::setw(10) << std::left << p.second << " ";
0095 std::cout << log.str() << std::endl;
0096 }
0097 catch(const std::exception& e) {
0098 std::cout << "Test FAILED: " << tag << " Exception: " << e.what() << std::endl;
0099 return 1;
0100 }
0101 return 0;
0102 }
0103 void line() {
0104 std::cout << "+-----------------------------------------------------"
0105 << "-----------------------------------------------------" << std::endl;
0106 }
0107 }
0108
0109 static int property_test(Detector& , int , char** ) {
0110 using _ulong = unsigned long;
0111 using XYZPoint = ROOT::Math::XYZPoint;
0112 using XYZVector = ROOT::Math::XYZVector;
0113 using PxPyPzE = ROOT::Math::PxPyPzEVector;
0114 int result = 0;
0115 line();
0116 result += _test_prop<std::string> ("prop_str", "'a'");
0117 result += _test_prop<bool> ("prop_bool", "true");
0118 result += _test_prop<int> ("prop_int", "11");
0119 result += _test_prop<int> ("prop_int_eval", "1*11");
0120 result += _test_prop<long> ("prop_long", "1111");
0121 result += _test_prop<long> ("prop_long_eval", "1*1111");
0122 result += _test_prop<_ulong> ("prop_ulong", "11111");
0123 result += _test_prop<_ulong> ("prop_ulong_eval", "1*11111");
0124 result += _test_prop<float> ("prop_float", "1.11");
0125 result += _test_prop<float> ("prop_float_eval", "1.11*GeV");
0126 result += _test_prop<double> ("prop_double", "1.1111");
0127 result += _test_prop<double> ("prop_double_eval", "1.1111*GeV");
0128 result += _test_prop<XYZPoint> ("prop_XYZPoint", "(1, 2, 3)");
0129 result += _test_prop<XYZPoint> ("prop_XYZPoint_eval", "(1*m, 2*m, 3*m)");
0130 result += _test_prop<XYZVector> ("prop_XYZVector", "(1, 2, 3)");
0131 result += _test_prop<XYZVector> ("prop_XYZVector_eval", "(1*GeV, 2*GeV, 3*GeV)");
0132 result += _test_prop<PxPyPzE> ("prop_PxPyPzEVector", "(1, 2, 3, 4)");
0133 result += _test_prop<PxPyPzE> ("prop_PxPyPzEVector_eval", "(1*GeV, 2*GeV, 3*GeV, 4*GeV)");
0134 line();
0135 result += _test_map <std::map<std::string, std::string> >("map_str_str", "{'a': 'a', 'b': 'bb', 'c': 'ccc'}");
0136 result += _test_map <std::map<std::string, bool> > ("map_str_bool", "{'a': true, 'b': false, 'c': true}");
0137 result += _test_map <std::map<std::string, int> > ("map_str_int", "{'a': 11, 'b': 222, 'c': 3333}");
0138 result += _test_map <std::map<std::string, int> > ("map_str_int_eval", "{'a': 1*11, 'b': 2*111, 'c': 3*1111}");
0139 result += _test_map <std::map<std::string, long> > ("map_str_long", "{'a': 111, 'b': 222, 'c': 3333}");
0140 result += _test_map <std::map<std::string, long> > ("map_str_long_eval", "{'a': 1*111, 'b': 2*111, 'c': 3*1111}");
0141 result += _test_map <std::map<std::string, float> > ("map_str_float", "{'a': 1.11, 'b': 22.22, 'c': 333.33}");
0142 result += _test_map <std::map<std::string, float> > ("map_str_float_eval", "{'a': '1.11*GeV','b':'22.22*MeV', 'c': '333.3*TeV'}");
0143 result += _test_map <std::map<std::string, double> > ("map_str_double", "{'a': 1.11, 'b': 22.22, 'c': 333.33}");
0144 result += _test_map <std::map<std::string, double> > ("map_str_double_eval", "{'a': '1.11*GeV','b':'22.22*MeV', 'c': '333.3*TeV'}");
0145
0146
0147
0148 line();
0149 result += _test_map <std::map<int, std::string> > ("map_int_str", "{ 10: 'a', 200: 'bb', 3000: ' ccc'}");
0150 result += _test_map <std::map<int, bool> > ("map_int_bool", "{ 10: true, 200: false, 3000: true}");
0151 result += _test_map <std::map<int, int> > ("map_int_int", "{ 10: 11, 200: 200, 3000: 3000}");
0152 result += _test_map <std::map<int, int> > ("map_int_int_eval", "{ 10: 1*11, 200: 2*100, 3000: 3*1000}");
0153 result += _test_map <std::map<int, long> > ("map_int_long", "{ 10: 111, 200: 222, 3000: 3333}");
0154 result += _test_map <std::map<int, long> > ("map_int_long_eval", "{ 10: 1*111, 200: 2*111, 3000: 3*1111}");
0155 result += _test_map <std::map<int, float> > ("map_int_float", "{ 10: 1.11, 200: 22.22, 3000: 333.33}");
0156 result += _test_map <std::map<int, float> > ("map_int_float_eval", "{ 10: 1.11*GeV, 200: 22.22*MeV, 3000: 333.3*TeV}");
0157 result += _test_map <std::map<int, double> > ("map_int_double", "{ 10: 1.11, 200: 22.22, 3000: 333.33}");
0158 result += _test_map <std::map<int, double> > ("map_int_double_eval", "{ 10: 1.11*GeV, 200: 22.22*MeV, 3000: 333.3*TeV}");
0159
0160 result += _test_map <std::map<int, double> > ("map_eval_int_double", "{ 1*10: 1.11, 2*100: 22.22, 3*1000: 333.33}");
0161
0162
0163
0164 #if defined(DD4HEP_HAVE_ALL_PARSERS)
0165 line();
0166 result += _test_map <std::map<float, std::string> > ("map_float_str", "{ 10: 'a', 200: 'bb', 3000: 'ccc'}");
0167 result += _test_map <std::map<float, bool> > ("map_float_bool", "{ 10: true, 200: false, 3000: true}");
0168 result += _test_map <std::map<float, int> > ("map_float_int", "{ 10: 11, 200: 200, 3000: 3000}");
0169 result += _test_map <std::map<float, int> > ("map_float_int_eval", "{ 10: 1*11, 200: 2*100, 3000: 3*1000}");
0170 result += _test_map <std::map<float, float> > ("map_float_float", "{ 10: 1.11, 200: 22.22, 3000: 333.33}");
0171 result += _test_map <std::map<float, float> > ("map_float_float_eval", "{ 10: 1.11*GeV, 200: 22.22*MeV, 3000: 333.3*TeV}");
0172 result += _test_map <std::map<float, double> > ("map_float_double", "{ 10: 1.11, 200: 22.22, 3000: 333.33}");
0173 result += _test_map <std::map<float, double> > ("map_float_double_eval", "{ 10: 1.11*GeV, 200: 22.22*MeV, 3000: 333.3*TeV}");
0174 #endif
0175 line();
0176 result += _test_cont<std::set<std::string> > ("set_str", "{'a', 'bb', 'ccc'}");
0177 result += _test_cont<std::set<bool> > ("set_bool", "{true, false, true}");
0178 result += _test_cont<std::set<int> > ("set_int", "{11, 222, 3333}");
0179 result += _test_cont<std::set<int> > ("set_int_eval", "{1*11, 2*111, 3*1111}");
0180 result += _test_cont<std::set<int> > ("set_int", "{11, 222, 3333}");
0181 result += _test_cont<std::set<long> > ("set_long_eval", "{1*11, 2*111, 3*1111}");
0182 result += _test_cont<std::set<long> > ("set_long", "{11, 222, 3333}");
0183 result += _test_cont<std::set<float> > ("set_float", "{1.11, 22.22, 333.33}");
0184 result += _test_cont<std::set<float> > ("set_float_eval", "{1.11*GeV, 22.22*MeV, 333.3*TeV}");
0185 result += _test_cont<std::set<double> > ("set_double", "{1.11, 22.22, 333.33}");
0186 result += _test_cont<std::set<double> > ("set_double_eval", "{1.11*GeV, 22.22*MeV, 333.3*TeV}");
0187 result += _test_cont<std::set<XYZPoint> > ("set_XYZPoint", "{(1, 2, 3), (10,20,30), (100,200,300)}");
0188 result += _test_cont<std::set<XYZPoint> > ("set_XYZPoint_eval", "{(1*m, 2*m, 3*m), (10*m,20*m,30*m), (100*m,200*m,300*m)}");
0189 result += _test_cont<std::set<XYZVector> > ("set_XYZVector", "{(1, 2, 3), (10,20,30), (100,200,300)}");
0190 result += _test_cont<std::set<XYZVector> > ("set_XYZVector_eval", "{(1*m, 2*m, 3*m), (10*m,20*m,30*m), (100*m,200*m,300*m)}");
0191 result += _test_cont<std::set<PxPyPzE> > ("set_PxPyPzEVector", "{(1, 2, 3,4), (10,20,30,40), (100,200,300,400)}");
0192 result += _test_cont<std::set<PxPyPzE> > ("set_PxPyPzEVector_eval", "{(1*m, 2*m, 3*m, 4*m), (10*m,20*m,30*m,40*m), (100*m,200*m,300*m,400*m)}");
0193 line();
0194 result += _test_cont<std::vector<std::string> > ("vector_str", "{'a', 'bb', 'ccc'}");
0195 result += _test_cont<std::vector<bool> > ("vector_bool", "{true, false, true}");
0196 result += _test_cont<std::vector<int> > ("vector_int", "{11, 222, 3333}");
0197 result += _test_cont<std::vector<int> > ("vector_int_eval", "{1*11, 2*111, 3*1111}");
0198 result += _test_cont<std::vector<long> > ("vector_long_eval", "{1*11, 2*111, 3*1111}");
0199 result += _test_cont<std::vector<long> > ("vector_long", "{11, 222, 3333}");
0200 result += _test_cont<std::vector<_ulong> > ("vector_ulong_eval", "{1*11, 2*111, 3*1111}");
0201 result += _test_cont<std::vector<_ulong> > ("vector_ulong", "{11, 222, 3333}");
0202 result += _test_cont<std::vector<float> > ("vector_float", "{1.11, 22.22, 333.33}");
0203 result += _test_cont<std::vector<float> > ("vector_float_eval", "{1.11*GeV, 22.22*MeV, 333.3*TeV}");
0204 result += _test_cont<std::vector<double> > ("vector_double", "{1.11, 22.22, 333.33}");
0205 result += _test_cont<std::vector<double> > ("vector_double_eval", "{1.11*GeV, 22.22*MeV, 333.3*TeV}");
0206 result += _test_cont<std::vector<XYZPoint> > ("vector_XYZPoint", "{(1, 2, 3), (10,20,30), (100,200,300)}");
0207 result += _test_cont<std::vector<XYZPoint> > ("vector_XYZPoint_eval", "{(1*m, 2*m, 3*m), (10*m,20*m,30*m), (100*m,200*m,300*m)}");
0208 result += _test_cont<std::vector<XYZVector> > ("vector_XYZVector", "{(1, 2, 3), (10,20,30), (100,200,300)}");
0209 result += _test_cont<std::vector<XYZVector> > ("vector_XYZVector_eval", "{(1*m, 2*m, 3*m), (10*m,20*m,30*m), (100*m,200*m,300*m)}");
0210 result += _test_cont<std::vector<PxPyPzE> > ("vector_PxPyPzEVector", "{(1, 2, 3,4), (10,20,30,40), (100,200,300,400)}");
0211 result += _test_cont<std::vector<PxPyPzE> > ("vector_PxPyPzEVector_eval","{(1*m, 2*m, 3*m, 4*m), (10*m,20*m,30*m,40*m), (100*m,200*m,300*m,400*m)}");
0212 line();
0213 result += _test_cont<std::list<std::string> > ("list_str", "{'a', 'bb', 'ccc'}");
0214 result += _test_cont<std::list<bool> > ("list_bool", "{true, false, true}");
0215 result += _test_cont<std::list<int> > ("list_int", "{11, 222, 3333}");
0216 result += _test_cont<std::list<int> > ("list_int_eval", "{1*11, 2*111, 3*1111}");
0217 result += _test_cont<std::list<long> > ("list_long_eval", "{1*11, 2*111, 3*1111}");
0218 result += _test_cont<std::list<long> > ("list_long", "{11, 222, 3333}");
0219 result += _test_cont<std::list<_ulong> > ("list_ulong_eval", "{1*11, 2*111, 3*1111}");
0220 result += _test_cont<std::list<_ulong> > ("list_ulong", "{11, 222, 3333}");
0221 result += _test_cont<std::list<float> > ("list_float", "{1.11, 22.22, 333.33}");
0222 result += _test_cont<std::list<float> > ("list_float_eval", "{1.11*GeV, 22.22*MeV, 333.3*TeV}");
0223 result += _test_cont<std::list<double> > ("list_double", "{1.11, 22.22, 333.33}");
0224 result += _test_cont<std::list<double> > ("list_double_eval", "{1.11*GeV, 22.22*MeV, 333.3*TeV}");
0225 result += _test_cont<std::list<XYZPoint> > ("list_XYZPoint", "{(1, 2, 3), (10,20,30), (100,200,300)}");
0226 result += _test_cont<std::list<XYZVector> > ("list_XYZVector", "{(1, 2, 3), (10,20,30), (100,200,300)}");
0227 result += _test_cont<std::list<PxPyPzE> > ("list_PxPyPzEVector", "{(1, 2, 3,4), (10,20,30,40), (100,200,300,400)}");
0228 result += _test_cont<std::list<XYZVector> > ("list_XYZVector_eval", "{(1*m, 2*m, 3*m), (10*m,20*m,30*m), (100*m,200*m,300*m)}");
0229 result += _test_cont<std::list<PxPyPzE> > ("list_PxPyPzEVector", "{(1, 2, 3,4), (10,20,30,40), (100,200,300,400)}");
0230 result += _test_cont<std::list<PxPyPzE> > ("list_PxPyPzEVector_eval", "{(1*m, 2*m, 3*m, 4*m), (10*m,20*m,30*m,40*m), (100*m,200*m,300*m,400*m)}");
0231 line();
0232 #if defined(DD4HEP_HAVE_ALL_PARSERS)
0233 result += _test_cont<std::deque<std::string> > ("deque_str", "{'a', 'bb', 'ccc'}");
0234 result += _test_cont<std::deque<bool> > ("deque_bool", "{true, false, true}");
0235 result += _test_cont<std::deque<int> > ("deque_int", "{11, 222, 3333}");
0236 result += _test_cont<std::deque<int> > ("deque_int_eval", "{1*11, 2*111, 3*1111}");
0237 result += _test_cont<std::deque<float> > ("deque_float", "{1.11, 22.22, 333.33}");
0238 result += _test_cont<std::deque<float> > ("deque_float_eval", "{1.11*GeV, 22.22*MeV, 333.3*TeV}");
0239 result += _test_cont<std::deque<double> > ("deque_double", "{1.11, 22.22, 333.33}");
0240 result += _test_cont<std::deque<double> > ("deque_double_eval", "{1.11*GeV, 22.22*MeV, 333.3*TeV}");
0241 line();
0242 #endif
0243 if ( 0 == result )
0244 std::cout << std::endl << "Test PASSED" << std::endl << std::endl;
0245 else
0246 std::cout << std::endl << "Test FAILED" << std::endl << "===> " << result << " Subtests FAILED" << std::endl;
0247
0248
0249 return 1;
0250 }
0251
0252
0253 DECLARE_APPLY(DD4hep_property_test,property_test)