Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 08:19:36

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/Detector.h>
0017 #include <DD4hep/InstanceCount.h>
0018 #include <DD4hep/ConditionDerived.h>
0019 
0020 // C/C++ include files
0021 
0022 using namespace dd4hep;
0023 using namespace dd4hep::cond;
0024 
0025 /// Default destructor
0026 ConditionUpdateUserContext::~ConditionUpdateUserContext()   {
0027 }
0028 
0029 /// Access to the top level detector element
0030 DetElement ConditionUpdateContext::world()  const   {
0031   return resolver->detectorDescription().world();
0032 }
0033 
0034 /// Access to all conditions of a detector element. Careful: This limits the validity!
0035 std::vector<Condition> ConditionUpdateContext::conditions(Condition::detkey_type det_key)  const   {
0036   std::vector<Condition> v = resolver->get(det_key);
0037   /// Update result IOV according by and'ing the new iov structure
0038   for(Condition c : v) iov->iov_intersection(c.iov());
0039   return v;
0040 }
0041 
0042 /// Access conditions by the condition item key
0043 std::vector<Condition> ConditionUpdateContext::getByItem(Condition::itemkey_type item_key)   const    {
0044   std::vector<Condition> v = resolver->getByItem(item_key);
0045   /// Update result IOV according by and'ing the new iov structure
0046   for(Condition c : v) iov->iov_intersection(c.iov());
0047   return v;
0048 }
0049 
0050 /// Access to condition object by dependency key
0051 Condition ConditionUpdateContext::condition(const ConditionKey& key_value)  const  {
0052   Condition c = this->resolver->get(key_value, this->dependency, true);
0053   if ( c.isValid() )  {
0054     /// Update result IOV according by and'ing the new iov structure
0055     iov->iov_intersection(c.iov());
0056     return c;
0057   }
0058 #if defined(DD4HEP_CONDITIONS_HAVE_NAME)
0059   except("ConditionUpdateCall:","Failed to access non-existing condition:"+key_value.name);
0060 #else
0061   ConditionKey::KeyMaker key(key_value.hash);
0062   except("ConditionUpdateCall:","Failed to access non-existing condition with key [%08X %08X]:",
0063          key.values.det_key, key.values.item_key);
0064 #endif
0065   return Condition();
0066 }
0067    
0068 /// Access to condition object by dependency key
0069 Condition ConditionUpdateContext::condition(Condition::key_type key_value)  const   {
0070   Condition c = resolver->get(key_value);
0071   if ( c.isValid() )  {
0072     /// Update result IOV according by and'ing the new iov structure
0073     iov->iov_intersection(c.iov());
0074     return c;
0075   }
0076   throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing condition.");
0077 }
0078 
0079 /// Access to condition object by dependency key
0080 Condition ConditionUpdateContext::condition(Condition::key_type key_value,
0081                                             bool throw_if_not)  const   {
0082   Condition c = resolver->get(key_value, throw_if_not);
0083   if ( c.isValid() )  {
0084     /// Update result IOV according by and'ing the new iov structure
0085     iov->iov_intersection(c.iov());
0086     return c;
0087   }
0088   else if ( throw_if_not )  {
0089     throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing condition.");
0090   }
0091   return Condition();
0092 }
0093 
0094 /// Interface to handle multi-condition inserts by callbacks: One single insert
0095 bool ConditionUpdateContext::registerOne(const IOV& iov_val, Condition cond)   {
0096   return resolver->registerOne(iov_val, cond);
0097 }
0098 
0099 /// Handle multi-condition inserts by callbacks: block insertions of conditions with identical IOV
0100 size_t ConditionUpdateContext::registerMany(const IOV& iov_val, const std::vector<Condition>& values)  {
0101   return resolver->registerMany(iov_val, values);
0102 }
0103 
0104 /// Standard destructor
0105 ConditionUpdateCall::ConditionUpdateCall()  {
0106   InstanceCount::increment(this);
0107 }
0108 
0109 /// Standard destructor
0110 ConditionUpdateCall::~ConditionUpdateCall()  {
0111   InstanceCount::decrement(this);
0112 }
0113 
0114 /// Standard destructor
0115 ConditionResolver::~ConditionResolver()  {
0116 }
0117 
0118 /// Throw exception on conditions access failure
0119 void ConditionUpdateContext::accessFailure(const ConditionKey& key_value)  const   {
0120 #if defined(DD4HEP_CONDITIONS_HAVE_NAME)
0121   except("ConditionUpdateCall",
0122          "%s [%016llX]: FAILED to access non-existing item:%s [%016llX]",
0123          dependency->target.name.c_str(), dependency->target.hash,
0124          key_value.name.c_str(), key_value.hash);
0125 #else
0126   ConditionKey::KeyMaker key(key_value.hash);
0127   ConditionKey::KeyMaker dep(dependency->target.hash);
0128   except("ConditionUpdateCall",
0129          "Derived condition [%08X %08X]: FAILED to access non-existing item:%s [%08X %08X]",
0130          dep.values.det_key, dep.values.item_key, key.values.det_key, key.values.item_key);
0131 #endif
0132 }
0133 
0134 /// Initializing constructor
0135 ConditionDependency::ConditionDependency(DetElement              de,
0136                                          Condition::itemkey_type item_key,
0137                                          std::shared_ptr<ConditionUpdateCall> call)
0138   : m_refCount(0), detector(de), target(de, item_key), callback(std::move(call))
0139 {
0140   InstanceCount::increment(this);
0141 }
0142 
0143 /// Initializing constructor
0144 ConditionDependency::ConditionDependency(DetElement de,
0145                                          const std::string&   item, 
0146                                          std::shared_ptr<ConditionUpdateCall> call)
0147   : 
0148   detector(de), target(de, item), callback(std::move(call))
0149 {
0150   InstanceCount::increment(this);
0151 }
0152 
0153 /// Default constructor
0154 ConditionDependency::ConditionDependency()
0155 {
0156   InstanceCount::increment(this);
0157 }
0158 
0159 /// Default destructor
0160 ConditionDependency::~ConditionDependency()
0161 {
0162   InstanceCount::decrement(this);
0163 }
0164 
0165 /// Initializing constructor
0166 DependencyBuilder::DependencyBuilder(DetElement           de,
0167                                      unsigned int         item_key,
0168                                      std::shared_ptr<ConditionUpdateCall> call)
0169   : m_dependency(new ConditionDependency(de,item_key,std::move(call)))
0170 {
0171 }
0172 
0173 /// Initializing constructor
0174 DependencyBuilder::DependencyBuilder(DetElement           de,
0175                                      const std::string&   item,
0176                                      std::shared_ptr<ConditionUpdateCall> call)
0177   : m_dependency(new ConditionDependency(de,item,std::move(call)))
0178 {
0179 }
0180 
0181 /// Default destructor
0182 DependencyBuilder::~DependencyBuilder()   {
0183 }
0184 
0185 /// Add a new dependency
0186 void DependencyBuilder::add(const ConditionKey& source)   {
0187   if ( m_dependency )   {
0188     m_dependency->dependencies.emplace_back(source);
0189     return;
0190   }
0191   except("Dependency","++ Invalid object. No further source may be added!");
0192 }
0193 
0194 /// Release the created dependency and take ownership.
0195 ConditionDependency* DependencyBuilder::release()   {
0196   if ( m_dependency )   {
0197     return m_dependency.release();
0198   }
0199   except("Dependency","++ Invalid object. Cannot access built objects!");
0200   return m_dependency.release(); // Not necessary, but need to satisfy compiler
0201 }
0202