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_CONDITIONSSLICE_H
0014 #define DDCOND_CONDITIONSSLICE_H
0015 
0016 // Framework include files
0017 #include "DD4hep/Conditions.h"
0018 #include "DD4hep/ConditionsMap.h"
0019 #include "DD4hep/ConditionDerived.h"
0020 
0021 #include "DDCond/ConditionsPool.h"
0022 #include "DDCond/ConditionsContent.h"
0023 #include "DDCond/ConditionsManager.h"
0024 
0025 // C/C++ include files
0026 #include <memory>
0027 
0028 /// Namespace for the AIDA detector description toolkit
0029 namespace dd4hep {
0030 
0031   /// Namespace for implementation details of the AIDA detector description toolkit
0032   namespace cond {
0033 
0034     // Forward declarations
0035     class UserPool;
0036     class ConditionsSlice;
0037     
0038     /// Conditions slice object. Defines which conditions should be loaded by the ConditionsManager.
0039     /**
0040      *  Object contains set of required conditions keys to be loaded to the user pool.
0041      *  It alkso contains the load information for the required conditions (conditions addresses).
0042      *  The address objects depend on the actual loader mechanism and must be specified the user.
0043      *  The information is then chained through the calls and made availible to the loader object.
0044      *
0045      *  On return it contains the individual condition load information.
0046      *
0047      *  Referenced by: ConditonsUserPool, ConditionsManager
0048      *
0049      *  \author  M.Frank
0050      *  \version 1.0
0051      *  \ingroup DD4HEP_CONDITIONS
0052      */
0053     class ConditionsSlice : public ConditionsMap  {
0054     public:
0055       typedef Condition::key_type                           key_type;
0056       typedef std::vector<std::shared_ptr<ConditionsPool> > ContainedPools;
0057 
0058       enum ManageFlag {
0059         REGISTER_MANAGER= 1<<0,
0060         REGISTER_POOL   = 1<<1,
0061         REGISTER_FULL   = REGISTER_MANAGER|REGISTER_POOL
0062       };
0063       enum LoadFlags  {
0064         REF_POOLS       = 1<<1
0065       };
0066       
0067       /// Helper to simplify the registration of new condtitions from arbitrary containers.
0068       /**
0069        *
0070        *  \author  M.Frank
0071        *  \version 1.0
0072        *  \ingroup DD4HEP_CONDITIONS
0073        */
0074       class Inserter  {
0075         ConditionsSlice& slice;
0076         ConditionsPool*  iov_pool = 0;
0077 
0078       public:
0079         Inserter(ConditionsSlice& s) : slice(s) {
0080           const IOV& iov = s.pool->validity();
0081           iov_pool = s.manager.registerIOV(*iov.iovType,iov.key());
0082         }
0083         template <typename T> Inserter(ConditionsSlice& s, const T& data) : slice(s) {
0084           const IOV& iov = slice.pool->validity();
0085           iov_pool = slice.manager.registerIOV(*iov.iovType,iov.key());
0086           std::for_each(std::begin(data), std::end(data), *this);
0087         }
0088         void operator()(Condition c) const  {
0089           slice.manager.registerUnlocked(*iov_pool,c);
0090           slice.pool->insert(c);
0091         }
0092         void operator()(const std::pair<Condition::key_type,Condition>& e) const  {
0093           (*this)(e.second);
0094         }
0095         template <typename T> void process(const T& data)  const   {
0096           std::for_each(std::begin(data), std::end(data), *this);
0097         }
0098       };
0099 
0100     public:
0101       /// Reference to the conditions manager.
0102       /** Not used by the object, simple for convenience.
0103        *  Then all actors are lumped together, which are used by the client code.
0104        */
0105       ConditionsManager         manager;
0106       /// Reference to the user pool managing all conditions of this slice
0107       std::unique_ptr<UserPool> pool;
0108       /// Container of conditions required by this slice
0109       std::shared_ptr<ConditionsContent> content;
0110 
0111       /// Store the result of the prepare step
0112       ConditionsManager::Result status;
0113       /// If requested refence the used pools with a shared pointer to inhibit cleanup
0114       ContainedPools            used_pools;
0115       /// Flag to steer conditions management
0116       unsigned long             flags = 0;
0117       
0118     protected:
0119       /// If flag conditonsManager["OutputUnloadedConditions"]=true: will contain conditions not loaded
0120       ConditionsContent::Conditions   m_missingConditions;
0121       /// If flag conditonsManager["OutputUnloadedConditions"]=true: will contain conditions not computed
0122       ConditionsContent::Dependencies m_missingDerivations;
0123       
0124       /// Default assignment operator
0125       ConditionsSlice& operator=(const ConditionsSlice& copy) = delete;
0126 
0127       /// Local optimization: Insert a set of conditions to the slice AND register them to the conditions manager.
0128       /** Note: The conditions already require a valid hash key                           */
0129       virtual bool manage(ConditionsPool* pool, Condition condition, ManageFlag flg);
0130 
0131       static Condition select_cond(Condition c)  {  return c; }
0132       template <typename T>
0133       static Condition select_cond(const std::pair<T,Condition>& c)  {  return c.second; }
0134     public:
0135       /// Default constructor
0136       ConditionsSlice() = delete;
0137       /// Initializing constructor
0138       ConditionsSlice(ConditionsManager m);
0139       /// Initializing constructor
0140       ConditionsSlice(ConditionsManager m, const std::shared_ptr<ConditionsContent>& c);
0141       /// Copy constructor (Special, partial copy only. Hence no assignment!)
0142       ConditionsSlice(const ConditionsSlice& copy);
0143       /// Default destructor. 
0144       virtual ~ConditionsSlice();
0145 
0146       /// Total size of all conditions contained in the slice
0147       size_t size() const   { return content->conditions().size()+content->derived().size(); }
0148       /// Set flag to reference the used pools during prepare
0149       void refPools()       { this->flags |= REF_POOLS;                                      }
0150       /// Set flag to not reference the used pools during prepare (and drop possibly pending)
0151       void derefPools();
0152       /// Access the map of conditions from the desired content
0153       const ConditionsContent::Conditions& conditions() const { return content->conditions();}
0154       /// Access the map of computational conditions from the desired content
0155       const ConditionsContent::Dependencies& derived() const  { return content->derived();   }
0156       /// Access the map of missing conditions (only valid after preparation)
0157       ConditionsContent::Conditions& missingConditions()      { return m_missingConditions;  }
0158       /// Access the map of missing computational conditions (only valid after preparation)
0159       ConditionsContent::Dependencies& missingDerivations()   { return m_missingDerivations; }
0160       /// Access the combined IOV of the slice from the pool
0161       const IOV& iov()  const;
0162       /// Clear the conditions content and the user pool.
0163       void reset();
0164 
0165       /// Insert a set of conditions to the slice AND register them to the conditions manager.
0166       /** Note: The conditions already require a valid hash key                           */
0167       template <typename T> void manage(const T& conds, ManageFlag flg)  {
0168         if ( !conds.empty() )  {
0169           ConditionsPool* p = (flg&REGISTER_MANAGER) ? manager.registerIOV(pool->validity()) : 0;
0170           for( const auto& e : conds )
0171             manage(p, select_cond(e), flg);
0172         }
0173       }
0174       /// Insert a set of conditions to the slice AND register them to the conditions manager.
0175       /** Note: The conditions already require a valid hash key                           */
0176       virtual bool manage(Condition condition, ManageFlag flg);
0177 
0178       /// Access all conditions from a given detector element
0179       std::vector<Condition> get(DetElement detector)  const;
0180       
0181       /** ConditionsMap interface implementation:                                         */
0182       /// ConditionsMap overload: Add a condition directly to the slice
0183       virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition)  override;
0184       /// ConditionsMap overload: Access a condition
0185       virtual Condition get(DetElement detector, Condition::itemkey_type key)  const override;
0186       /// No ConditionsMap overload: Access all conditions within a key range in the interval [lower,upper]
0187       virtual std::vector<Condition> get(DetElement detector,
0188                                          Condition::itemkey_type lower,
0189                                          Condition::itemkey_type upper)  const  override;
0190       /// ConditionsMap overload: Interface to scan data content of the conditions mapping
0191       virtual void scan(const Condition::Processor& processor) const  override;
0192       /// ConditionsMap overload: Interface to partially scan data content of the conditions mapping
0193       virtual void scan(DetElement       detector,
0194                         Condition::itemkey_type     lower,
0195                         Condition::itemkey_type     upper,
0196                         const Condition::Processor& processor) const  override;
0197     };
0198 
0199     /// Populate the conditions slice from the conditions manager (convenience)
0200     void fill_content(ConditionsManager mgr, ConditionsContent& content, const IOVType& typ);
0201 
0202   }        /* End namespace cond               */
0203 }          /* End namespace dd4hep                   */
0204 #endif // DDCOND_CONDITIONSSLICE_H