Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:05

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_CONDITIONSPOOL_H
0014 #define DDCOND_CONDITIONSPOOL_H
0015 
0016 // Framework include files
0017 #include "DD4hep/NamedObject.h"
0018 #include "DD4hep/ConditionsMap.h"
0019 #include "DDCond/ConditionsManager.h"
0020 
0021 // C/C++ include files
0022 
0023 /// Namespace for the AIDA detector description toolkit
0024 namespace dd4hep {
0025 
0026   /// Namespace for implementation details of the AIDA detector description toolkit
0027   namespace cond {
0028 
0029     // Forward declarations
0030     class ConditionsSlice;
0031     class ConditionsIOVPool;
0032     class ConditionDependency;
0033     
0034     /// Class implementing the conditions collection for a given IOV type
0035     /**
0036      *  Implementation is mostly virtual, to allow to switch between
0037      *  different implementations, which allow for different lookup
0038      *  and store optimizations and/or various caches.
0039      *  The interface only represents the basic functionality required.
0040      *
0041      *  Please note:
0042      *  Users should not directly interact with object instances of this type.
0043      *  Data are not thread protected and interaction may cause serious harm.
0044      *  Only the ConditionsManager implementation should interact with
0045      *  this class or any subclass to ensure data integrity.
0046      *
0047      *  For convenience, the class definition is here.
0048      *  See ConditionsManager.cpp for the implementation.
0049      *
0050      *  \author  M.Frank
0051      *  \version 1.0
0052      *  \ingroup DD4HEP_CONDITIONS
0053      */
0054     class ConditionsPool : public NamedObject {
0055     protected:
0056       /// Handle to conditions manager object
0057       ConditionsManager m_manager;
0058       
0059     public:
0060       enum { AGE_NONE    = 0, 
0061              AGE_ANY     = 9999999,
0062              AGE_EXPIRED = 12345678
0063       };
0064       /// The IOV of the conditions hosted
0065       IOV* iov;
0066       /// Aging value
0067       int  age_value;
0068 
0069     public:
0070       /// Listener invocation when a condition is registered to the cache
0071       void onRegister(Condition condition);
0072       /// Listener invocation when a condition is deregistered from the cache
0073       void onRemove(Condition condition);
0074 
0075     public:
0076       /// Default constructor
0077       ConditionsPool(ConditionsManager mgr, IOV* iov);
0078       /// Default destructor. Note: pool must be cleared by the subclass!
0079       virtual ~ConditionsPool();
0080       /// Print pool basics
0081       void print()   const;
0082       /// Print pool basics
0083       void print(const std::string& opt)   const;
0084       /// Total entry count
0085       virtual size_t size()  const = 0;
0086       /// Full cleanup of all managed conditions.
0087       virtual void clear() = 0;
0088       /// Register a new condition to this pool
0089       virtual bool insert(Condition cond) = 0;
0090       /// Register a new condition to this pool. May overload for performance reasons.
0091       virtual void insert(RangeConditions& cond) = 0;
0092       /// Check if a condition exists in the pool
0093       virtual Condition exists(Condition::key_type key)  const = 0;
0094       /// Select the conditions matching the DetElement and the conditions name
0095       virtual size_t select(Condition::key_type key, RangeConditions& result) = 0;
0096       /// Select all conditions contained
0097       virtual size_t select_all(RangeConditions& result) = 0;
0098       /// Select the conditons, passing a predicate
0099       virtual size_t select_all(const ConditionsSelect& predicate) = 0;
0100       /// Select all conditions contained
0101       virtual size_t select_all(ConditionsPool& selection_pool) = 0;
0102     };
0103 
0104     /// Interface for conditions pool optimized to host conditions updates.
0105     /** 
0106      *  \author  M.Frank
0107      *  \version 1.0
0108      */
0109     class UpdatePool : public ConditionsPool  {
0110 
0111     public:
0112       typedef std::vector<Condition> ConditionEntries;
0113       /// Update container specification
0114       typedef std::map<const IOV*, ConditionEntries> UpdateEntries;
0115 
0116     public:
0117       /// Default constructor
0118       UpdatePool(ConditionsManager mgr, IOV* iov);
0119       /// Default destructor.
0120       virtual ~UpdatePool();
0121       /// Adopt all entries sorted by IOV. Entries will be removed from the pool
0122       virtual size_t popEntries(UpdateEntries& entries) = 0;
0123       /// Select the conditions matching the key
0124       virtual void select_range(Condition::key_type key, 
0125                                 const IOV& req_validity,
0126                                 RangeConditions& result) = 0;
0127     };
0128 
0129     /// Interface for conditions pool optimized to host conditions updates.
0130     /** 
0131      *  \author  M.Frank
0132      *  \version 1.0
0133      */
0134     class UserPool : public ConditionsMap {
0135     public:
0136       /// Forward definition of the key type
0137       typedef std::map<Condition::key_type,const ConditionDependency*> Dependencies;
0138 
0139     protected:
0140       /// The pool's interval of validity
0141       IOV                 m_iov;
0142       /// Handle to conditions manager object
0143       ConditionsManager   m_manager;
0144 
0145     public:
0146       /// Printout flags for debugging
0147       enum {
0148         PRINT_NONE   = 0,
0149         PRINT_INSERT = 1<<0,
0150         PRINT_CLEAR  = 1<<1,
0151     PRINT_LOAD   = 1<<2,
0152         PRINT_COMPUTE= 1<<3,
0153     PRINT_LAST
0154       };
0155       /// Processing flags (printout etc.)
0156       unsigned int flags = 0;
0157 
0158       /// ConditionsMap overload: Add a condition directly to the slice
0159       virtual bool insert(Condition condition) = 0;
0160 
0161     public:
0162       /// Default constructor
0163       UserPool(ConditionsManager mgr);
0164       /// Default destructor.
0165       virtual ~UserPool();
0166       /// Access the interval of validity for this user pool
0167       const IOV& validity() const    {  return m_iov;  }
0168       /// Access the interval of validity for this user pool
0169       const IOV* validityPtr() const {  return &m_iov; }
0170       /// Print pool content
0171       virtual void print(const std::string& opt) const = 0;
0172       /// Total entry count
0173       virtual size_t size()  const = 0;
0174       /// Full cleanup of all managed conditions.
0175       virtual void clear() = 0;
0176       /// Check a condition for existence
0177       virtual bool exists(Condition::key_type key)  const = 0;
0178       /// Check a condition for existence
0179       virtual bool exists(const ConditionKey& key)  const = 0;
0180       /// Check if a condition exists in the pool and return it to the caller
0181       virtual Condition get(Condition::key_type key)  const = 0;
0182       /// Check if a condition exists in the pool and return it to the caller
0183       virtual Condition get(const ConditionKey& key)  const = 0;
0184       /// Remove condition by key from pool.
0185       virtual bool remove(Condition::key_type hash_key) = 0;
0186       /// Remove condition by key from pool.
0187       virtual bool remove(const ConditionKey& key) = 0;
0188       /// Do single insertion of condition including registration to the manager
0189       /** Note: block insertions are preferred!!!  */
0190       virtual bool registerOne(const IOV& iov, Condition cond)  = 0;
0191       /// Do block insertions of conditions with identical IOV
0192       virtual size_t registerMany(const IOV& iov, const std::vector<Condition>& values) = 0;
0193       /// Insert multiple conditions. Note: the conditions must already have a hash key
0194       template <typename CONT> size_t registerUnmapped(const IOV& iov, CONT& c)   {
0195         std::vector<Condition> conditions;
0196         conditions.reserve(c.size());
0197         std::copy(std::begin(c), std::end(c), std::back_inserter(conditions));
0198         return this->registerMany(iov, conditions);
0199       }
0200       /// Insert multiple conditions. Note: the conditions must already have a hash key
0201       template <typename CONT> size_t registerMapping(const IOV& iov, CONT& c)     {
0202         std::vector<Condition> conditions;
0203         conditions.reserve(c.size());
0204         std::transform(std::begin(c), std::end(c), std::back_inserter(conditions), detail::get_2nd<CONT>());
0205         return this->registerMany(iov, conditions);
0206       }
0207       /// ConditionsMap overload: Add a condition directly to the slice
0208       virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition) = 0;
0209 
0210       /// ConditionsMap overload: Access a single condition
0211       virtual Condition get(DetElement detector, Condition::itemkey_type key)  const = 0;
0212       /// No ConditionsMap overload: Access all conditions within a key range in the interval [lower,upper]
0213       virtual std::vector<Condition> get(Condition::key_type lower,
0214                                          Condition::key_type upper)  const = 0;
0215       /// No ConditionsMap overload: Access all conditions within a key range in the interval [lower,upper]
0216       virtual std::vector<Condition> get(DetElement detector,
0217                                          Condition::itemkey_type lower,
0218                                          Condition::itemkey_type upper)  const = 0;
0219 
0220       /// ConditionsMap overload: Interface to scan data content of the conditions mapping
0221       virtual void scan(const Condition::Processor& processor) const = 0;
0222       /// No ConditionsMap overload: Interface to scan data content of the conditions mapping
0223       virtual void scan(Condition::key_type lower,
0224                         Condition::key_type upper,
0225                         const Condition::Processor& processor) const = 0;
0226       /// No ConditionsMap overload: Interface to scan data content of the conditions mapping
0227       virtual void scan(DetElement detector,
0228                         Condition::itemkey_type lower,
0229                         Condition::itemkey_type upper,
0230                         const Condition::Processor& processor) const = 0;
0231 
0232       /// Prepare user pool for usage (load, fill etc.) according to required IOV
0233       virtual ConditionsManager::Result prepare(const IOV&                  required, 
0234                                                 ConditionsSlice&            slice,
0235                                                 ConditionUpdateUserContext* user_param = 0) = 0;
0236 
0237       /// Load all updates to the clients with the defined IOV (1rst step of prepare)
0238       virtual ConditionsManager::Result load(const IOV&                  required_validity,
0239                                              ConditionsSlice&            slice,
0240                                              ConditionUpdateUserContext* ctxt=0)  = 0;
0241       /// Compute all derived conditions with the defined IOV (2nd step of prepare)
0242       virtual ConditionsManager::Result compute(const IOV&                  required_validity,
0243                                                 ConditionsSlice&            slice,
0244                                                 ConditionUpdateUserContext* ctxt=0)  = 0;
0245       
0246       /// Evaluate and register all derived conditions from the dependency list
0247       virtual size_t compute(const Dependencies& dependencies,
0248                              ConditionUpdateUserContext* user_param,
0249                              bool force) = 0;
0250     };
0251   }        /* End namespace cond                     */
0252 }          /* End namespace dd4hep                   */
0253 #endif // DDCOND_CONDITIONSPOOL_H