Back to home page

EIC code displayed by LXR

 
 

    


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

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 include files
0015 #include <DDCond/ConditionsContent.h>
0016 #include <DD4hep/InstanceCount.h>
0017 #include <DD4hep/Printout.h>
0018 
0019 using namespace dd4hep::cond;
0020 
0021 /// Default constructor
0022 ConditionsLoadInfo::ConditionsLoadInfo()   {
0023   InstanceCount::increment(this);  
0024 }
0025 
0026 /// Default destructor. 
0027 ConditionsLoadInfo::~ConditionsLoadInfo()  {
0028   InstanceCount::decrement(this);  
0029 }
0030 
0031 /// Initializing constructor
0032 ConditionsContent::ConditionsContent()
0033 {
0034   InstanceCount::increment(this);  
0035 }
0036 
0037 /// Default destructor. 
0038 ConditionsContent::~ConditionsContent()   {
0039   detail::releaseObjects(m_derived);
0040   detail::releaseObjects(m_conditions);
0041   InstanceCount::decrement(this);  
0042 }
0043 
0044 /// Clear the container. Destroys the contained stuff
0045 void ConditionsContent::clear()   {
0046   detail::releaseObjects(m_derived);
0047   detail::releaseObjects(m_conditions);
0048 }
0049 
0050 /// Merge the content of "to_add" into the this content
0051 void ConditionsContent::merge(const ConditionsContent& to_add)    {
0052   auto& cond  = to_add.conditions();
0053   auto& deriv = to_add.derived();
0054   for( const auto& c : cond )   {
0055     auto ret = m_conditions.emplace(c);
0056     if ( ret.second )  {
0057       c.second->addRef();
0058       continue;
0059     }
0060     // Need error handling here ?
0061     ConditionKey key(c.first);
0062     printout(WARNING,"ConditionsContent",
0063              "++ Condition %s already present in content. Not merged",key.toString().c_str());
0064              
0065   }
0066   for( const auto& d : deriv )   {
0067     auto ret = m_derived.emplace(d);
0068     if ( ret.second )  {
0069       d.second->addRef();
0070       continue;
0071     }
0072     // Need error handling here ?
0073     ConditionKey key(d.first);
0074     printout(WARNING,"ConditionsContent",
0075              "++ Dependency %s already present in content. Not merged",key.toString().c_str());
0076   }
0077 }
0078 
0079 /// Remove a new shared condition
0080 bool ConditionsContent::remove(Condition::key_type hash)   {
0081   auto i = m_conditions.find(hash);
0082   if ( i != m_conditions.end() )  {
0083     detail::releasePtr((*i).second);
0084     m_conditions.erase(i);
0085     return true;
0086   }
0087   auto j = m_derived.find(hash);
0088   if ( j != m_derived.end() )  {
0089     detail::releasePtr((*j).second);
0090     m_derived.erase(j);
0091     return true;
0092   }
0093   return false;
0094 }
0095 
0096 std::pair<dd4hep::Condition::key_type, ConditionsLoadInfo*>
0097 ConditionsContent::insertKey(Condition::key_type hash)   {
0098   auto ret = m_conditions.emplace(hash,(ConditionsLoadInfo*)0);
0099   //printout(DEBUG,"ConditionsContent","++ Insert key: %016X",hash);
0100   if ( ret.second )  return { hash, 0 };
0101   return { 0,0 };
0102 }
0103 
0104 /// Add a new conditions key. T must inherit from class ConditionsContent::Info
0105 std::pair<dd4hep::Condition::key_type, ConditionsLoadInfo*>
0106 ConditionsContent::addLocationInfo(Condition::key_type hash, ConditionsLoadInfo* info)   {
0107   if ( info )   {
0108     //printout(DEBUG,"ConditionsContent","++ Add location key: %016X",hash);
0109     auto ret = m_conditions.emplace(hash,info);
0110     if ( ret.second )  {
0111       info->addRef();
0112       return *(ret.first);
0113     }
0114     info->release();
0115   }
0116   return { 0,0 };
0117 }
0118 
0119 /// Add a new shared conditions dependency
0120 std::pair<dd4hep::Condition::key_type, ConditionDependency*>
0121 ConditionsContent::addDependency(ConditionDependency* dep)
0122 {
0123   auto ret = m_derived.emplace(dep->key(),dep);
0124   if ( ret.second )  {
0125     //printout(DEBUG,"ConditionsContent","++ Add dependency key: %016X",dep->key());
0126     dep->addRef();
0127     return *(ret.first);
0128   }
0129   ConditionKey::KeyMaker maker(dep->target.hash);
0130 #if defined(DD4HEP_CONDITIONS_DEBUG)
0131   DetElement             de(dep->detector);
0132   const char* path = de.isValid() ? de.path().c_str() : "(global)";
0133 #else
0134   const char* path = "";
0135 #endif
0136   dep->release();
0137   except("DeConditionsRequests",
0138          "++ Dependency already exists: %s [%08X] [%016llX]",
0139          path, maker.values.item_key, maker.hash);
0140   return std::pair<Condition::key_type, ConditionDependency*>(0,0);
0141 }
0142 
0143 /// Add a new conditions dependency (Built internally from arguments)
0144 std::pair<dd4hep::Condition::key_type, ConditionDependency*>
0145 ConditionsContent::addDependency(DetElement de,
0146                                  Condition::itemkey_type item,
0147                                  std::shared_ptr<ConditionUpdateCall> callback)
0148 {
0149   ConditionDependency* dep = new ConditionDependency(de, item, std::move(callback));
0150   return addDependency(dep);
0151 }
0152