File indexing completed on 2025-01-30 09:16:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/ConditionAny.h>
0017 #include <DD4hep/detail/ConditionsInterna.h>
0018
0019
0020 #include <iomanip>
0021
0022 using namespace dd4hep;
0023
0024 namespace {
0025 inline const BasicGrammar* any_grammar() {
0026 static const BasicGrammar* s_any_grammar = &BasicGrammar::instance<std::any>();
0027 return s_any_grammar;
0028 }
0029 }
0030
0031
0032 ConditionAny::ConditionAny(key_type hash_key) : Handle<Object>()
0033 {
0034 if ( hash_key != 0 && hash_key != ~0x0ULL ) {
0035 Object* o = new Object();
0036 this->assign(o, "", "");
0037 o->data.bind<std::any>();
0038 o->hash = hash_key;
0039 return;
0040 }
0041 except("ConditionAny","+++ Cannot create a any-condition with an invalid key: %016llX",hash_key);
0042 }
0043
0044
0045 ConditionAny::ConditionAny(const std::string& nam, const std::string& typ) : Handle<Object>()
0046 {
0047 Object* o = new Object();
0048 this->assign(o, nam, typ);
0049 o->data.bind<std::any>();
0050 o->hash = 0;
0051 }
0052
0053 void ConditionAny::use_data(detail::ConditionObject* obj) {
0054 if ( obj ) {
0055 if ( !obj->data.grammar ) {
0056 except("ConditionAny",
0057 "+++ Cannot assign unbound conditions data to handle. [Invalid operation]");
0058 }
0059 if ( obj->data.grammar != any_grammar() ) {
0060 except("ConditionAny",
0061 "+++ Cannot assign data of type " +
0062 obj->data.grammar->type_name() +
0063 " to handle holding std::any. [Invalid operation]");
0064 }
0065 }
0066 this->m_element = obj;
0067 }
0068
0069
0070 const dd4hep::IOVType& ConditionAny::iovType() const {
0071 return *(this->access()->iovType());
0072 }
0073
0074
0075 const dd4hep::IOV& ConditionAny::iov() const {
0076 return *(this->access()->iovData());
0077 }
0078
0079
0080 ConditionAny::key_type ConditionAny::key() const {
0081 return this->access()->hash;
0082 }
0083
0084
0085 ConditionAny::detkey_type ConditionAny::detector_key() const {
0086 return ConditionKey::KeyMaker(this->access()->hash).values.det_key;
0087 }
0088
0089
0090 ConditionAny::itemkey_type ConditionAny::item_key() const {
0091 return ConditionKey::KeyMaker(access()->hash).values.item_key;
0092 }
0093
0094
0095 ConditionAny::mask_type ConditionAny::flags() const {
0096 return access()->flags;
0097 }
0098
0099
0100 void ConditionAny::setFlag(mask_type option) {
0101 access()->setFlag(option);
0102 }
0103
0104
0105 void ConditionAny::unFlag(mask_type option) {
0106 access()->unFlag(option);
0107 }
0108
0109
0110 bool ConditionAny::testFlag(mask_type option) const {
0111 return access()->testFlag(option);
0112 }
0113
0114
0115 std::any& ConditionAny::get() {
0116 OpaqueData& o = this->access()->data;
0117 if ( o.grammar && (o.grammar == any_grammar()) ) {
0118 return *(std::any*)o.ptr();
0119 }
0120 throw std::bad_cast();
0121 }
0122
0123
0124 const std::any& ConditionAny::get() const {
0125 const OpaqueData& o = this->access()->data;
0126 if ( o.grammar && (o.grammar == any_grammar()) ) {
0127 return *(std::any*)o.ptr();
0128 }
0129 throw std::bad_cast();
0130 }
0131
0132
0133 bool ConditionAny::has_value() const {
0134 return this->get().has_value();
0135 }
0136
0137
0138 const std::type_info& ConditionAny::any_type() const {
0139 const Object* o = this->ptr();
0140 if ( o && o->data.grammar && (o->data.grammar == any_grammar()) ) {
0141 const std::any* a = (const std::any*)o->data.ptr();
0142 return a->type();
0143 }
0144 return typeid(void);
0145 }
0146
0147
0148 const std::string ConditionAny::any_type_name() const {
0149 const Object* o = this->ptr();
0150 if ( o && o->data.grammar && (o->data.grammar == any_grammar()) ) {
0151 const std::any* a = (const std::any*)o->data.ptr();
0152 return typeName(a->type());
0153 }
0154 return typeName(typeid(void));
0155 }