Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:32:50

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_TYPE1_MANAGER_TYPE1_H
0014 #define DDCOND_TYPE1_MANAGER_TYPE1_H
0015 
0016 // Framework include files%
0017 #include "DD4hep/Mutex.h"
0018 #include "DD4hep/ObjectExtensions.h"
0019 #include "DDCond/ConditionsManagerObject.h"
0020 
0021 // C/C++ include files
0022 #include <memory>
0023 
0024 /// Namespace for the AIDA detector description toolkit
0025 namespace dd4hep {
0026 
0027   /// Namespace for implementation details of the AIDA detector description toolkit
0028   namespace cond {
0029 
0030     class Entry;
0031     class ConditionsPool;
0032     class ConditionsSlice;
0033     class ConditionsIOVPool;
0034     class ConditionsDataLoader;
0035 
0036     /// The data class behind a conditions manager handle
0037     /**
0038      *  For convenience, the class definition is here.
0039      *  See ConditionsManager.cpp for the implementation.
0040      *
0041      *  \author  M.Frank
0042      *  \version 1.0
0043      *  \ingroup DD4HEP_CONDITIONS
0044      */
0045     class Manager_Type1 : public ConditionsManagerObject, 
0046                           public ObjectExtensions
0047     {
0048     public:
0049       typedef std::vector<ConditionsIOVPool*> TypedConditionPool;
0050 
0051     protected:
0052 
0053       /** Generic interface of any concrete instance  */
0054       
0055       /// Property: maximal number of IOV types to be handled
0056       int                     m_maxIOVTypes;
0057       /// Property: ConditionsPool constructor type (default: empty. MUST BE SET!)
0058       std::string             m_poolType;
0059       /// Property: UpdatePool constructor type (default: DD4hep_ConditionsLinearUpdatePool)
0060       std::string             m_updateType;
0061       /// Property: UserPool constructor type (default: DD4hep_ConditionsLinearUserPool)
0062       std::string             m_userType;
0063       /// Property: Conditions loader type (default: "multi" -> DD4hep_Conditions_multi_Loader)
0064       std::string             m_loaderType;
0065 
0066       /// Collection of IOV types managed
0067       std::vector<IOVType>    m_iovTypes;
0068 
0069       /** Specialized interface only used by this implementation  */
0070       /// Lock to protect the update/delayed conditions pool
0071       dd4hep_mutex_t          m_updateLock;
0072       /// Lock to protect the pool of all known conditions
0073       dd4hep_mutex_t          m_poolLock;
0074       /// Reference to update conditions pool
0075       std::unique_ptr<UpdatePool>  m_updatePool;
0076       /// Reference to the default conditions cleanup object (if registered)
0077       std::unique_ptr<ConditionsCleanup> m_cleaner;
0078       
0079     public:
0080       /// Managed pool of typed conditions indexed by IOV-type and IOV key
0081       TypedConditionPool      m_rawPool;
0082       /// Public access: if locked, DetElements stay intact and are not altered
0083       int                     m_locked;
0084 
0085     protected:
0086       /// Retrieve  a condition set given a Detector Element and the conditions name according to their validity
0087       bool select(key_type key, const IOV& req_validity, RangeConditions& conditions);
0088 
0089       /// Retrieve  a condition set given a Detector Element and the conditions name according to their validity
0090       bool select_range(key_type key, const IOV& req_validity, RangeConditions& conditions);
0091 
0092       /// Register a set of new managed condition for an IOV range. Called by __load_immediate
0093       // void __register_immediate(RangeConditions& c);
0094 
0095 
0096       /// Helper to check iov and user pool and create user pool if not present
0097       void __get_checked_pool(const IOV& required_validity, std::unique_ptr<UserPool>& user_pool);
0098       
0099       /** Generic interface of any concrete instance  */
0100       
0101       /// Set a single conditions value to be managed.
0102       /// Requires EXTERNALLY held lock on update pool!
0103       Condition __queue_update(cond::Entry* data);
0104 
0105     public:
0106       /// Standard constructor
0107       Manager_Type1(Detector& description);
0108 
0109       /// Default destructor
0110       virtual ~Manager_Type1();
0111 
0112       /// Access to managed pool of typed conditions indexed by IOV-type and IOV key
0113       //const TypedConditionPool& conditionsPool() const  {  return m_rawPool; }
0114       
0115       /// Initialize object and define factories
0116       void initialize();
0117 
0118       /// Register new IOV type if it does not (yet) exist.
0119       /** Returns (false,pointer) if IOV existed and
0120        *  (true,pointer) if new IOV was registered to the manager.
0121        */
0122       virtual std::pair<bool, const IOVType*> registerIOVType(size_t iov_index, const std::string& iov_name) final;
0123       
0124       /// Access IOV by its type
0125       virtual const std::vector<IOVType>& iovTypes () const final { return  m_iovTypes;  }
0126 
0127       /// Access IOV by its type
0128       virtual const IOVType* iovType (size_t iov_index) const final;
0129 
0130       /// Access IOV by its name
0131       virtual const IOVType* iovType (const std::string& iov_name) const final;
0132 
0133       /// Register IOV with type and key
0134       virtual ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key)  final;
0135 
0136       /// Access conditions multi IOV pool by iov type
0137       virtual ConditionsIOVPool* iovPool(const IOVType& type)  const  final;
0138 
0139       /// Register new condition with the conditions store. Unlocked version, not multi-threaded
0140       virtual bool registerUnlocked(ConditionsPool& pool, Condition cond)  final;
0141 
0142       /// Register a whole block of conditions with identical IOV.
0143       virtual size_t blockRegister(ConditionsPool& pool, const std::vector<Condition>& cond) const final;
0144 
0145       /// Adopt cleanup handler. If a handler is registered, it is invoked at every "prepare" step
0146       virtual void adoptCleanup(ConditionsCleanup* cleaner)  final;
0147       
0148       /// Clean conditions, which are above the age limit.
0149       /** @return Number of conditions cleaned/removed from the IOV pool of the given type   */
0150       virtual int clean(const IOVType* typ, int max_age)  final;
0151 
0152       /// Invoke cache cleanup with user defined policy
0153       /** @return pair<Number of pools cleared, Number of conditions cleaned up and removed> */
0154       virtual std::pair<int,int> clean(const ConditionsCleanup& cleaner)  final;
0155 
0156       /// Full cleanup of all managed conditions.
0157       /** @return pair<Number of pools cleared, Number of conditions cleaned up and removed> */
0158       virtual std::pair<int,int> clear()  final;
0159 
0160       /// Push all pending updates to the conditions store. 
0161       /** Note:
0162        *  This does not yet make the new conditions availible to the clients
0163        */
0164       virtual void pushUpdates()  final;
0165 #if 0 
0166       /// Retrieve a condition set given a Detector Element and the conditions name according to their validity  (deprecated)
0167       virtual Condition get(key_type key, const IOV& req_validity)  final;
0168 
0169       /// Retrieve a condition given a Detector Element and the conditions name (deprecated)
0170       virtual RangeConditions getRange(key_type key, const IOV& req_validity)  final;
0171 #endif
0172       /// Create empty user pool object
0173       virtual std::unique_ptr<UserPool> createUserPool(const IOVType* iovT)  const;
0174 
0175       /// Prepare all updates for the given keys to the clients with the defined IOV
0176       /**
0177        *   @arg      req_validity [IOV]            Required interval of validity of the selected conditions
0178        *   @arg      slice        []               Conditions slice with load/computation recipes.
0179        *
0180        *   @return   
0181        */
0182       virtual Result prepare(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctxt)  final;
0183 
0184       /// Load all updates to the clients with the defined IOV (1rst step of prepare)
0185       virtual Result load(const IOV&                  required_validity,
0186                           ConditionsSlice&            slice,
0187                           ConditionUpdateUserContext* ctxt=0) final;
0188       /// Compute all derived conditions with the defined IOV (2nd step of prepare)
0189       virtual Result compute(const IOV&                  required_validity,
0190                              ConditionsSlice&            slice,
0191                              ConditionUpdateUserContext* ctxt=0) final;
0192 
0193 
0194     };
0195   }        /* End namespace cond               */
0196 }          /* End namespace dd4hep                   */
0197 #endif // DDCOND_TYPE1_MANAGER_TYPE1_H