File indexing completed on 2025-01-30 09:17:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 namespace {
0028
0029
0030 class base_0 {
0031 public:
0032 int data_0 {0};
0033 base_0() = default;
0034 base_0(base_0&& copy) = default;
0035 base_0(const base_0& copy) = default;
0036 virtual ~base_0() = default;
0037 base_0& operator=(base_0&& copy) = default;
0038 base_0& operator=(const base_0& copy) = default;
0039 };
0040
0041 template <typename T> class base_1 {
0042 public:
0043 T data_1;
0044 base_1() = default;
0045 base_1(base_1&& copy) = default;
0046 base_1(const base_1& copy) = default;
0047 virtual ~base_1() = default;
0048 base_1& operator=(base_1&& copy) = default;
0049 base_1& operator=(const base_1& copy) = default;
0050 };
0051 template <typename T> class base_2: virtual public base_0 {
0052 public:
0053 T data_2;
0054 base_2() = default;
0055 base_2(base_2&& copy) = default;
0056 base_2(const base_2& copy) = default;
0057 virtual ~base_2() = default;
0058 base_2& operator=(base_2&& copy) = default;
0059 base_2& operator=(const base_2& copy) = default;
0060 };
0061
0062 class payload : public base_1<int>, public base_2<double> {
0063 public:
0064 payload() = default;
0065 payload(payload&& copy) = default;
0066 payload(const payload& copy) = default;
0067 virtual ~payload() = default;
0068 payload& operator=(payload&& copy) = default;
0069 payload& operator=(const payload& copy) = default;
0070 };
0071 }
0072
0073
0074 #include "ConditionExampleObjects.h"
0075 #include "DD4hep/GrammarUnparsed.h"
0076 #include "DD4hep/Factories.h"
0077
0078 using namespace std;
0079 using namespace dd4hep;
0080 using namespace dd4hep::ConditionExamples;
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 static int condition_example (Detector& , int , char** ) {
0091 #define DATA_0 12345
0092 #define DATA_1 54321
0093 #define DATA_2 2.2222e2
0094
0095 Condition cond("Cond","payload");
0096 payload& p = cond.bind<payload>();
0097
0098 BasicGrammar::instance<payload>().setCast( &Cast::instance<payload>() );
0099 BasicGrammar::instance<base_0>().setCast( &Cast::instance<base_0>() );
0100 BasicGrammar::instance<base_1<int> >().setCast( &Cast::instance<base_1<int> >() );
0101 BasicGrammar::instance<base_2<double> >().setCast( &Cast::instance<base_2<double> >() );
0102
0103 p.data_0 = DATA_0;
0104 p.data_1 = DATA_1;
0105 p.data_2 = DATA_2;
0106 {
0107 payload* pl = &p;
0108 base_0* b0 = pl;
0109 base_1<int>* b1 = pl;
0110 base_2<double>* b2 = pl;
0111 cout << "Payload: " << (void*)pl
0112 << " b0: " << (void*)b0
0113 << " b1: " << (void*)b1
0114 << " b2: " << (void*)b2
0115 << endl;
0116 }
0117 const auto& pl = cond.as<payload>();
0118 cout << "Payload: " << pl.data_1 << " " << pl.data_2 << endl;
0119 if ( pl.data_0 != DATA_0 || pl.data_1 != DATA_1 || pl.data_2 != DATA_2 ) cout << "Test FAILED" << endl;
0120
0121 const auto& b0 = cond.as<base_0>();
0122 cout << "Payload(base_0): " << (void*)&b0 << " data: " << b0.data_0 << endl;
0123 if ( b0.data_0 != DATA_0 ) cout << "Test FAILED" << endl;
0124
0125 const auto& b1 = cond.as<base_1<int> >();
0126 cout << "Payload(base_1): " << (void*)&b1 << " data: " << b1.data_1 << endl;
0127 if ( b1.data_1 != DATA_1 ) cout << "Test FAILED" << endl;
0128
0129 const auto& b2 = cond.as<base_2<double> >();
0130 cout << "Payload(base_2): " << (void*)&b2 << " data: " << b2.data_2 << endl;
0131 if ( b2.data_2 != DATA_2 ) cout << "Test FAILED" << endl;
0132
0133 delete cond.ptr();
0134 cout << "Test PASSED" << endl;
0135
0136
0137 return 1;
0138 }
0139
0140
0141 DECLARE_APPLY(DD4hep_Conditions_dynamic,condition_example)