Back to home page

EIC code displayed by LXR

 
 

    


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

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