Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:16:56

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 <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 /// Initializing constructor for a pure, undecorated conditions object
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 /// Initializing constructor for a pure, undecorated conditions object
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 /// Access the IOV type
0070 const dd4hep::IOVType& ConditionAny::iovType() const   {
0071   return *(this->access()->iovType());
0072 }
0073 
0074 /// Access the IOV block
0075 const dd4hep::IOV& ConditionAny::iov() const   {
0076   return *(this->access()->iovData());
0077 }
0078 
0079 /// Hash identifier
0080 ConditionAny::key_type ConditionAny::key()  const    {
0081   return this->access()->hash;
0082 }
0083 
0084 /// DetElement part of the identifier
0085 ConditionAny::detkey_type ConditionAny::detector_key()  const   {
0086   return ConditionKey::KeyMaker(this->access()->hash).values.det_key;
0087 }
0088 
0089 /// Item part of the identifier
0090 ConditionAny::itemkey_type ConditionAny::item_key()  const   {
0091   return ConditionKey::KeyMaker(access()->hash).values.item_key;
0092 }
0093 
0094 /// Flag operations: Get flags
0095 ConditionAny::mask_type ConditionAny::flags()  const    {
0096   return access()->flags;
0097 }
0098 
0099 /// Flag operations: Set a conditons flag
0100 void ConditionAny::setFlag(mask_type option)   {
0101   access()->setFlag(option);
0102 }
0103 
0104 /// Flag operations: UN-Set a conditons flag
0105 void ConditionAny::unFlag(mask_type option)   {
0106   access()->unFlag(option);
0107 }
0108 
0109 /// Flag operations: Test for a given a conditons flag
0110 bool ConditionAny::testFlag(mask_type option) const {
0111   return access()->testFlag(option);
0112 }
0113 
0114 /// Generic getter. Specify the exact type, not a polymorph type
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 /// Generic getter (const version). Specify the exact type, not a polymorph type
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 /// Checks whether the object contains a value
0133 bool ConditionAny::has_value()   const   {
0134   return this->get().has_value();
0135 }
0136 
0137 /// Access to the type information
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 /// Access to the type information as string
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 }