Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:42

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