Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /DD4hep/DDCond/src/plugins/ConditionsMappedPool.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 #ifndef DDCOND_CONDITIONSMAPPEDPOOL_H
0014 #define DDCOND_CONDITIONSMAPPEDPOOL_H
0015 
0016 // Framework include files
0017 #include <DD4hep/Printout.h>
0018 #include <DD4hep/detail/ConditionsInterna.h>
0019 
0020 #include <DDCond/ConditionsPool.h>
0021 #include <DDCond/ConditionsSelectors.h>
0022 
0023 // C/C++ include files
0024 #include <map>
0025 #include <unordered_map>
0026 
0027 /// Namespace for the AIDA detector description toolkit
0028 namespace dd4hep {
0029 
0030   /// Namespace for implementation details of the AIDA detector description toolkit
0031   namespace cond {
0032 
0033     /// Class implementing the conditions collection for a given IOV type
0034     /**
0035      *
0036      *  Please note:
0037      *  Users should not directly interact with object instances of this type.
0038      *  Data are not thread protected and interaction may cause serious harm.
0039      *  Only the ConditionsManager implementation should interact with
0040      *  this class or any subclass to ensure data integrity.
0041      *
0042      *  \author  M.Frank
0043      *  \version 1.0
0044      *  \ingroup DD4HEP_CONDITIONS
0045      */
0046     template<typename MAPPING, typename BASE> 
0047     class ConditionsMappedPool : public BASE   {
0048     public:
0049       typedef BASE                               Base;
0050       typedef MAPPING                            Mapping;
0051       typedef ConditionsMappedPool<Mapping,Base> Self;
0052       
0053     protected:
0054       Mapping          m_entries;
0055       
0056       /// Helper function to loop over the conditions container and apply a functor
0057       template <typename R,typename T> std::size_t loop(R& result, T functor) {
0058         size_t len = result.size();
0059         for_each(m_entries.begin(),m_entries.end(),functor);
0060         return result.size() - len;
0061       }
0062     public:
0063       /// Default constructor
0064       ConditionsMappedPool(ConditionsManager mgr);
0065 
0066       /// Default destructor
0067       virtual ~ConditionsMappedPool();
0068 
0069       /// Total entry count
0070       virtual size_t size()  const  final  {
0071         return m_entries.size();
0072       }
0073 
0074       /// Register a new condition to this pool
0075       virtual bool insert(Condition condition)  final    {
0076         Condition::Object* c = condition.access();
0077         bool result = m_entries.emplace(c->hash,c).second;
0078         if ( result ) return true;
0079         auto i = m_entries.find(c->hash);
0080         Condition present = (*i).second;
0081           
0082         printout(ERROR,"MappedPool","ConditionsClash: %s %08llX <> %08llX %s",
0083                  present.name(), present.key(), condition.key(), condition.name());
0084         return false;
0085        }
0086 
0087       /// Register a new condition to this pool. May overload for performance reasons.
0088       virtual void insert(RangeConditions& new_entries)  final   {
0089         Condition::Object* o;
0090         for( Condition c : new_entries )  {
0091           o = c.access();
0092           m_entries.emplace(o->hash,o);
0093         }
0094       }
0095 
0096       /// Full cleanup of all managed conditions.
0097       virtual void clear()  final   {
0098         for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this));
0099         m_entries.clear();
0100       }
0101 
0102       /// Check if a condition exists in the pool
0103       virtual Condition exists(Condition::key_type key)  const  final   {
0104         auto i=find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key));
0105         return i==m_entries.end() ? Condition() : (*i).second;
0106       }
0107 
0108       /// Select the conditions matching the DetElement and the conditions name
0109       virtual size_t select(Condition::key_type key, RangeConditions& result)  final
0110       {  return loop(result, Operators::keyedSelect(key,result));      }
0111 
0112       /// Select the conditons, used also by the DetElement of the condition
0113       virtual size_t select_all(const ConditionsSelect& result)  final
0114       {  return loop(result, Operators::operatorWrapper(result));      }
0115 
0116       /// Select the conditons, used also by the DetElement of the condition
0117       virtual size_t select_all(RangeConditions& result)  final
0118       {  return loop(result, Operators::sequenceSelect(result));       }
0119 
0120       /// Select the conditons, used also by the DetElement of the condition
0121       virtual size_t select_all(ConditionsPool& result)  final
0122       {  return loop(result, Operators::poolSelect(result));           }
0123     };
0124 
0125     /// Class implementing the conditions update pool for a given IOV type
0126     /**
0127      *
0128      *  \author  M.Frank
0129      *  \version 1.0
0130      *  \ingroup DD4HEP_CONDITIONS
0131      */
0132     template<typename MAPPING, typename BASE> class ConditionsMappedUpdatePool 
0133       : public ConditionsMappedPool<MAPPING,BASE>
0134     {
0135     public:
0136       typedef ConditionsMappedPool<MAPPING,BASE>                    Self;
0137     public:
0138       /// Default constructor
0139       ConditionsMappedUpdatePool(ConditionsManager mgr)
0140         : ConditionsMappedPool<MAPPING,BASE>(mgr) { }
0141 
0142       /// Default destructor
0143       virtual ~ConditionsMappedUpdatePool()  { }
0144 
0145       /// Adopt all entries sorted by IOV. Entries will be removed from the pool
0146       virtual size_t popEntries(UpdatePool::UpdateEntries& entries)  final   {
0147         detail::ClearOnReturn<MAPPING> clr(this->Self::m_entries);
0148         return this->Self::loop(entries, [&entries](const std::pair<Condition::key_type,Condition::Object*>& o) {
0149             entries[o.second->iov].emplace_back(o.second);});
0150       }
0151 
0152       /// Select the conditions matching the DetElement and the conditions name
0153       virtual void select_range(Condition::key_type key,
0154                                 const IOV& req, 
0155                                 RangeConditions& result)  final
0156       {
0157         MAPPING& m = this->ConditionsMappedPool<MAPPING,BASE>::m_entries;
0158         if ( !m.empty() )   {
0159           unsigned int req_typ = req.iovType ? req.iovType->type : req.type;
0160           const IOV::Key& req_key = req.key();
0161           result.reserve(m.size());
0162           for(const auto& e : m)  {
0163             Condition::Object* o = e.second;
0164             if ( key == o->hash )  {
0165               const IOV* _iov = o->iov;
0166               unsigned int typ = _iov->iovType ? _iov->iovType->type : _iov->type;
0167               if ( req_typ == typ )   {
0168                 if ( IOV::key_is_contained(_iov->key(),req_key) )
0169                   // IOV test contained in key. Take it!
0170                   result.emplace_back(o);
0171                 else if ( IOV::key_overlaps_lower_end(_iov->key(),req_key) )
0172                   // IOV overlap on test on the lower end of key
0173                   result.emplace_back(o);
0174                 else if ( IOV::key_overlaps_higher_end(_iov->key(),req_key) )
0175                   // IOV overlap of test on the higher end of key
0176                   result.emplace_back(o);
0177               }
0178             }
0179           }
0180         }
0181       }
0182     };
0183   }    /* End namespace cond               */
0184 }      /* End namespace dd4hep                   */
0185 #endif /* DDCOND_CONDITIONSMAPPEDPOOL_H          */
0186 
0187 //==========================================================================
0188 //  AIDA Detector description implementation 
0189 //--------------------------------------------------------------------------
0190 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0191 // All rights reserved.
0192 //
0193 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0194 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0195 //
0196 // Author     : M.Frank
0197 //
0198 //==========================================================================
0199 
0200 // Framework include files
0201 //#include <DDCond/ConditionsMappedPool.h>
0202 #include <DD4hep/InstanceCount.h>
0203 
0204 using dd4hep::Handle;
0205 using namespace dd4hep::cond;
0206 
0207 /// Default constructor
0208 template<typename MAPPING, typename BASE>
0209 ConditionsMappedPool<MAPPING,BASE>::ConditionsMappedPool(ConditionsManager mgr) : BASE(mgr,0)  {
0210   this->BASE::SetName("");
0211   this->BASE::SetTitle("ConditionsMappedPool");
0212   InstanceCount::increment(this);
0213 }
0214 
0215 /// Default destructor
0216 template<typename MAPPING, typename BASE>
0217 ConditionsMappedPool<MAPPING,BASE>::~ConditionsMappedPool()  {
0218   clear();
0219   InstanceCount::decrement(this);
0220 }
0221 
0222 #include <DD4hep/Factories.h>
0223 namespace {
0224   ConditionsManager _mgr(int argc, char** argv)  {
0225     if ( argc > 0 )  {
0226       ConditionsManagerObject* m = (ConditionsManagerObject*)argv[0];
0227       return m;
0228     }
0229     dd4hep::except("ConditionsMappedPool","++ Insufficient arguments: arg[0] = ConditionManager!");
0230     return ConditionsManager(0);
0231   }
0232 #define _CR(fun,x,b,y) void* fun(dd4hep::Detector&, int argc, char** argv) \
0233   {  return new b<x<dd4hep::Condition::key_type,dd4hep::Condition::Object*>,y>(_mgr(argc,argv));  }
0234 
0235   /// Create a conditions pool based on STL maps
0236   _CR(create_map_pool,std::map,ConditionsMappedPool,ConditionsPool)
0237   /// Create a conditions pool based on STL hash-maps (unordered_map)
0238   _CR(create_unordered_map_pool,std::unordered_map,ConditionsMappedPool,ConditionsPool)
0239   /// Create a conditions update pool based on STL maps
0240   _CR(create_map_update_pool,std::map,ConditionsMappedUpdatePool,UpdatePool)
0241   /// Create a conditions update pool based on STL hash-maps (unordered_map)
0242   _CR(create_unordered_map_update_pool,std::unordered_map,ConditionsMappedUpdatePool,UpdatePool)
0243 }
0244 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsMappedPool,            create_map_pool)
0245 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsHashedPool,            create_unordered_map_pool)
0246 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsMappedUpdatePool,      create_map_update_pool)
0247 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsHashedUpdatePool,      create_unordered_map_update_pool)