Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-13 07:52:40

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 includes
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/ConditionAny.h>
0017 #include <DD4hep/detail/ConditionsInterna.h>
0018 
0019 // C/C++ include files
0020 #include <any>
0021 #include <string>
0022 
0023 using namespace dd4hep;
0024 
0025 namespace {
0026   inline const BasicGrammar* any_grammar()   {
0027     static const BasicGrammar* s_any_grammar = &BasicGrammar::instance<std::any>();
0028     return s_any_grammar;
0029   }
0030 }
0031 
0032 /// Initializing constructor for a pure, undecorated conditions object
0033 ConditionAny::ConditionAny(key_type hash_key) : Handle<Object>()
0034 {
0035   if ( hash_key != 0 && hash_key != ~0x0ULL )  {
0036     Object* o = new Object();
0037     this->assign(o, "", "");
0038     o->data.bind<std::any>();
0039     o->hash = hash_key;
0040     return;
0041   }
0042   except("ConditionAny","+++ Cannot create a any-condition with an invalid key: %016llX",hash_key);
0043 }
0044 
0045 /// Initializing constructor for a pure, undecorated conditions object
0046 ConditionAny::ConditionAny(const std::string& nam, const std::string& typ) : Handle<Object>()
0047 {
0048   Object* o = new Object();
0049   this->assign(o, nam, typ);
0050   o->data.bind<std::any>();
0051   o->hash = 0;
0052 }
0053 
0054 void ConditionAny::use_data(detail::ConditionObject* obj)   {
0055   if ( obj )   {
0056     if ( !obj->data.grammar )   {
0057       except("ConditionAny",
0058          "+++ Cannot assign unbound conditions data to handle. [Invalid operation]");
0059     }
0060     if ( obj->data.grammar != any_grammar() )   {
0061       except("ConditionAny",
0062          "+++ Cannot assign data of type " +
0063          obj->data.grammar->type_name() +
0064          " to handle holding std::any. [Invalid operation]");
0065     }
0066   }
0067   this->m_element = obj;
0068 }
0069 
0070 /// Access the IOV type
0071 const dd4hep::IOVType& ConditionAny::iovType() const   {
0072   return *(this->access()->iovType());
0073 }
0074 
0075 /// Access the IOV block
0076 const dd4hep::IOV& ConditionAny::iov() const   {
0077   return *(this->access()->iovData());
0078 }
0079 
0080 /// Hash identifier
0081 ConditionAny::key_type ConditionAny::key()  const    {
0082   return this->access()->hash;
0083 }
0084 
0085 /// DetElement part of the identifier
0086 ConditionAny::detkey_type ConditionAny::detector_key()  const   {
0087   return ConditionKey::KeyMaker(this->access()->hash).values.det_key;
0088 }
0089 
0090 /// Item part of the identifier
0091 ConditionAny::itemkey_type ConditionAny::item_key()  const   {
0092   return ConditionKey::KeyMaker(access()->hash).values.item_key;
0093 }
0094 
0095 /// Flag operations: Get flags
0096 ConditionAny::mask_type ConditionAny::flags()  const    {
0097   return access()->flags;
0098 }
0099 
0100 /// Flag operations: Set a conditons flag
0101 void ConditionAny::setFlag(mask_type option)   {
0102   access()->setFlag(option);
0103 }
0104 
0105 /// Flag operations: UN-Set a conditons flag
0106 void ConditionAny::unFlag(mask_type option)   {
0107   access()->unFlag(option);
0108 }
0109 
0110 /// Flag operations: Test for a given a conditons flag
0111 bool ConditionAny::testFlag(mask_type option) const {
0112   return access()->testFlag(option);
0113 }
0114 
0115 /// Generic getter. Specify the exact type, not a polymorph type
0116 std::any& ConditionAny::get() {
0117   OpaqueData& o = this->access()->data;
0118   if ( o.grammar && (o.grammar == any_grammar()) )   {
0119     return *(std::any*)o.ptr();
0120   }
0121   throw std::bad_cast();
0122 }
0123 
0124 /// Generic getter (const version). Specify the exact type, not a polymorph type
0125 const std::any& ConditionAny::get() const {
0126   const OpaqueData& o = this->access()->data;
0127   if ( o.grammar && (o.grammar == any_grammar()) )   {
0128     return *(std::any*)o.ptr();
0129   }
0130   throw std::bad_cast();
0131 }
0132   
0133 /// Checks whether the object contains a value
0134 bool ConditionAny::has_value()   const   {
0135   return this->get().has_value();
0136 }
0137 
0138 /// Access to the type information
0139 const std::type_info& ConditionAny::any_type() const   {
0140   const Object* o = this->ptr();
0141   if ( o && o->data.grammar && (o->data.grammar == any_grammar()) )   {
0142     const std::any* a = (const std::any*)o->data.ptr();
0143     return a->type();
0144   }
0145   return typeid(void);
0146 }
0147 
0148 /// Access to the type information as string
0149 const std::string ConditionAny::any_type_name() const   {
0150   const Object* o = this->ptr();
0151   if ( o && o->data.grammar && (o->data.grammar == any_grammar()) )   {
0152     const std::any* a = (const std::any*)o->data.ptr();
0153     return typeName(a->type());
0154   }
0155   return typeName(typeid(void));
0156 }