Back to home page

EIC code displayed by LXR

 
 

    


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

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_CONDITIONSDEPENDENCYHANDLER_H
0014 #define DDCOND_CONDITIONSDEPENDENCYHANDLER_H
0015 
0016 // Framework include files
0017 #include "DD4hep/DetElement.h"
0018 #include "DD4hep/ConditionDerived.h"
0019 #include "DDCond/ConditionsPool.h"
0020 #include "DDCond/ConditionsManager.h"
0021 
0022 /// Namespace for the AIDA detector description toolkit
0023 namespace dd4hep {
0024 
0025   /// Namespace for implementation details of the AIDA detector description toolkit
0026   namespace cond {
0027 
0028     // Forward declarations
0029     class UserPool;
0030     class ConditionsPool;
0031     class ConditionsManagerObject;
0032     
0033     /// Callback handler to update condition dependencies.
0034     /** 
0035      *  Fully stack based condition resolution. Any user request
0036      *  for dependent conditions are fully handled by 
0037      *  - either the connected conditions pool (if present there) or
0038      *  - by the currently worked on items.
0039      *
0040      *  The ConditionsDependencyHandler implements the 
0041      *  ConditionResolver interface, which is offered to the clients as
0042      *  an embedded parameter during the conversion mechanism.
0043      *  Clients must direct any subsequent conditions access to the
0044      *  ConditionResolver interface in order to allow for upgrades of
0045      *  this implementation which might not be polymorph.
0046      *
0047      *  \author  M.Frank
0048      *  \version 1.0
0049      */
0050     class ConditionsDependencyHandler : public ConditionResolver {
0051     public:
0052       /// Obect state definitions
0053       enum State  {  INVALID, CREATED, RESOLVED };
0054       /// Helper structure to define the current update item
0055       struct Work  {
0056       public:
0057         IOV                        _iov;
0058         /// Auxiliary information to resolve condition callbacks
0059         ConditionUpdateContext     context;
0060         /// Condition IOV
0061         IOV*                       iov       = 0;
0062         /// The final result: the condition object
0063         Condition::Object*         condition = 0;
0064         /// Flag to detect non resolvable circular dependencies
0065         int                        callstack = 0;
0066         /// Current conversion state of the item
0067         State                      state     = INVALID;
0068       public:
0069         /// Inhibit default constructor
0070         Work() = delete;
0071         /// Initializing constructor
0072         Work(ConditionResolver* r,
0073              const ConditionDependency* d,
0074              ConditionUpdateUserContext* u,
0075              const IOV& i)
0076           : _iov(i), context(r,d,&_iov,u) {}
0077         /// Copy constructor
0078         Work(const Work&) = default;
0079         /// Assignment operator
0080         Work& operator=(const Work&) = default;
0081         /// Helper to determine the IOV intersection taking into account dependencies
0082         void do_intersection(const IOV* iov);
0083         /// Helper function for the second level dependency resolution
0084         Condition resolve(Work*& current);
0085       };
0086       typedef std::map<Condition::key_type, const ConditionDependency*>  Dependencies;
0087       typedef std::map<Condition::key_type, Work*> WorkConditions;
0088 
0089     protected:
0090       /// Reference to conditions manager 
0091       ConditionsManagerObject*    m_manager;
0092       /// Reference to the user pool object
0093       UserPool&                   m_pool;
0094       /// Dependency container to be resolved.
0095       const Dependencies&         m_dependencies;
0096       /// User defined optional processing parameter
0097       ConditionUpdateUserContext* m_userParam;
0098       /// Local cacheL pool's IOV type
0099       const IOVType*              m_iovType = 0;
0100       /// The objects created during processing
0101       WorkConditions              m_todo;
0102       /// Handler's state
0103       State                       m_state = CREATED;
0104       /// Current block work item
0105       Work*                       m_block = 0;
0106       /// Current item of the block
0107       Work*                       m_currentWork = 0;
0108     public:
0109       /// Number of callbacks to the handler for monitoring
0110       mutable size_t              num_callback;
0111 
0112     protected:
0113       /// Internal call to trigger update callback
0114       void do_callback(Work* dep);
0115 
0116     public:
0117       /// Initializing constructor
0118       ConditionsDependencyHandler(ConditionsManager mgr,
0119                                   UserPool& pool, 
0120                                   const Dependencies& dependencies,
0121                                   ConditionUpdateUserContext* user_param);
0122       /// Default destructor
0123       ~ConditionsDependencyHandler();
0124 
0125       /// Access the conditions created during processing
0126       //const CreatedConditions& created()  const                  { return m_created;         }
0127       /// 1rst pass: Compute/create the missing conditions
0128       void compute();
0129       /// 2nd pass:  Handler callback for the second turn to resolve missing dependencies
0130       void resolve();
0131 
0132       /** ConditionResolver interface implementation         */
0133       /// Access to the detector description instance
0134       virtual Detector& detectorDescription() const  override;
0135       /// Access to the conditions manager
0136       virtual Ref_t manager() const  override                 { return m_manager;           }
0137       /// Access to pool IOV
0138       virtual const IOV& requiredValidity()  const  override  { return m_pool.validity();   }
0139       /// Accessor for the current conditons mapping
0140       virtual ConditionsMap& conditionsMap() const override   { return m_pool;              }
0141       /// ConditionResolver implementation: Interface to access conditions.
0142       virtual Condition get(const ConditionKey& key) override
0143       {  return get(key.hash, nullptr, true);                                               }
0144       /// Interface to access conditions by conditions key
0145       virtual Condition get(const ConditionKey& key, bool throw_if_not)  override
0146       {  return get(key.hash, nullptr, throw_if_not);                                       }
0147       /// ConditionResolver implementation: Interface to access conditions
0148       virtual Condition get(Condition::key_type key) override
0149       {  return get(key, nullptr, true);                                                    }
0150       /// Interface to access conditions by hash value
0151       virtual Condition get(Condition::key_type key, bool throw_if_not)  override;
0152       /// Interface to access conditions by hash value
0153       virtual Condition get(Condition::key_type key,
0154                             const ConditionDependency* dependency,
0155                             bool throw_if_not)  override;
0156       /// Interface to access conditions by hash value of the DetElement (only valid at resolve!)
0157       virtual std::vector<Condition> get(DetElement de)    override;
0158       /// Interface to access conditions by hash value of the DetElement (only valid at resolve!)
0159       virtual std::vector<Condition> get(Condition::detkey_type key)   override;
0160       /// Interface to access conditions by hash value of the item (only valid at resolve!)
0161       virtual std::vector<Condition> getByItem(Condition::itemkey_type key)   override;
0162       /// Interface to handle multi-condition inserts by callbacks: One single insert
0163       virtual bool registerOne(const IOV& iov, Condition cond)   override;
0164       /// Handle multi-condition inserts by callbacks: block insertions of conditions with identical IOV
0165       virtual size_t registerMany(const IOV& iov, const std::vector<Condition>& values)   override;
0166     };
0167 
0168   }        /* End namespace cond                */
0169 }          /* End namespace dd4hep                    */
0170 
0171 #endif // DDCOND_CONDITIONSDEPENDENCYHANDLER_H