Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:29

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 
0014 // Framework include files
0015 #include <DDCond/ConditionsSlice.h>
0016 #include <DDCond/ConditionsIOVPool.h>
0017 #include <DD4hep/InstanceCount.h>
0018 #include <DD4hep/Printout.h>
0019 
0020 using namespace dd4hep::cond;
0021 
0022 /// Initializing constructor
0023 ConditionsSlice::ConditionsSlice(ConditionsManager mgr) : manager(mgr)
0024 {
0025   InstanceCount::increment(this);  
0026 }
0027 
0028 /// Initializing constructor
0029 ConditionsSlice::ConditionsSlice(ConditionsManager mgr,
0030                                  const std::shared_ptr<ConditionsContent>& cont)
0031   : manager(mgr), content(cont)
0032 {
0033   InstanceCount::increment(this);  
0034 }
0035 
0036 /// Copy constructor (Special, partial copy only. Hence no assignment!)
0037 ConditionsSlice::ConditionsSlice(const ConditionsSlice& copy)
0038   : manager(copy.manager), content(copy.content)
0039 {
0040   InstanceCount::increment(this);  
0041 }
0042 
0043 /// Default destructor. 
0044 ConditionsSlice::~ConditionsSlice()   {
0045   reset();
0046   InstanceCount::decrement(this);  
0047 }
0048 
0049 /// Set flag to not reference the used pools during prepare (and drop possibly pending)
0050 void ConditionsSlice::derefPools()     {
0051   used_pools.clear(); // Drop all refs possibly pending
0052   this->flags &= ~REF_POOLS;
0053 }
0054 
0055 /// Access the combined IOV of the slice from the pool
0056 const dd4hep::IOV& ConditionsSlice::iov()  const    {
0057   if ( pool.get() ) return pool->validity();
0058   except("ConditionsSlice",
0059          "pool-iov: Failed to access validity of non-existing pool.");
0060   return pool->validity();
0061 }
0062 
0063 /// Clear the conditions access and the user pool.
0064 void ConditionsSlice::reset()   {
0065   derefPools();
0066   if ( pool.get() ) pool->clear();
0067 }
0068 
0069 /// Local optimization: Insert a set of conditions to the slice AND register them to the conditions manager.
0070 bool ConditionsSlice::manage(ConditionsPool* p, Condition condition, ManageFlag flg)   {
0071   if ( condition.isValid() )  {
0072     bool ret = false;
0073     if ( flg&REGISTER_MANAGER )  {
0074       if ( !p )   {
0075         except("ConditionsSlice",
0076                "manage_condition: Cannot access conditions pool according to IOV:%s.",
0077                pool->validity().str().c_str());
0078       }
0079       ret = manager.registerUnlocked(*p,condition);
0080       if ( !ret )  {
0081         except("ConditionsSlice",
0082                "manage_condition: Failed to register condition %016llx according to IOV:%s.",
0083                condition->hash, pool->validity().str().c_str());
0084       }
0085     }
0086     if ( flg&REGISTER_POOL )  {
0087       ret = pool->insert(condition);
0088       if ( !ret )  {
0089         except("ConditionsSlice",
0090                "manage_condition: Failed to register condition %016llx to user pool with IOV:%s.",
0091                condition->hash, pool->validity().str().c_str());
0092       }
0093     }
0094     return ret;
0095   }
0096   except("ConditionsSlice",
0097          "manage_condition: Cannot manage invalid condition!");
0098   return false;
0099 }
0100 
0101 /// Insert a set of conditions to the slice AND register them to the conditions manager.
0102 bool ConditionsSlice::manage(Condition condition, ManageFlag flg)    {
0103   ConditionsPool* p = (flg&REGISTER_MANAGER) ? manager.registerIOV(pool->validity()) : 0;
0104   return manage(p, condition, flg);
0105 }
0106 
0107 /// Access all conditions from a given detector element
0108 std::vector<dd4hep::Condition> ConditionsSlice::get(DetElement detector)  const  {
0109   return pool->get(detector,FIRST_ITEM,LAST_ITEM);
0110 }
0111 
0112 /// No ConditionsMap overload: Access all conditions within a key range in the interval [lower,upper]
0113 std::vector<dd4hep::Condition> ConditionsSlice::get(DetElement detector,
0114                                                     Condition::itemkey_type lower,
0115                                                     Condition::itemkey_type upper)  const  {
0116   return pool->get(detector, lower, upper);
0117 }
0118 
0119 /// ConditionsMap overload: Add a condition directly to the slice
0120 bool ConditionsSlice::insert(DetElement detector, Condition::itemkey_type key, Condition condition)   {
0121   if ( condition.isValid() )  {
0122     ConditionsPool* p = manager.registerIOV(pool->validity());
0123     if ( !p )   {
0124       except("ConditionsSlice",
0125              "manage_condition: Cannot access conditions pool according to IOV:%s.",
0126              pool->validity().str().c_str());
0127     }
0128     bool ret = manager.registerUnlocked(*p,condition);
0129     if ( !ret )  {
0130       except("ConditionsSlice",
0131              "manage_condition: Failed to register condition %016llx according to IOV:%s.",
0132              condition->hash, pool->validity().str().c_str());
0133     }
0134     return pool->insert(detector, key, condition);
0135   }
0136   except("ConditionsSlice",
0137          "insert_condition: Cannot insert invalid condition to the user pool!");
0138   return false;
0139 }
0140 
0141 /// ConditionsMap overload: Access a condition
0142 dd4hep::Condition ConditionsSlice::get(DetElement detector, Condition::itemkey_type key)  const   {
0143   return pool->get(detector, key);
0144 }
0145 
0146 /// ConditionsMap overload: Interface to scan data content of the conditions mapping
0147 void ConditionsSlice::scan(const Condition::Processor& processor) const   {
0148   pool->scan(processor);
0149 }
0150 
0151 /// ConditionsMap overload: Interface to partially scan data content of the conditions mapping
0152 void ConditionsSlice::scan(DetElement         detector,
0153                            Condition::itemkey_type       lower,
0154                            Condition::itemkey_type       upper,
0155                            const Condition::Processor&   processor) const  {
0156   pool->scan(detector, lower, upper, processor);
0157 }
0158 
0159 namespace  {
0160   
0161   struct SliceOper  : public dd4hep::ConditionsSelect  {
0162     ConditionsContent& content;
0163     SliceOper(ConditionsContent& c) : content(c) {}
0164     void operator()(const ConditionsIOVPool::Elements::value_type& v)    {
0165       v.second->select_all(*this);
0166     }
0167     bool operator()(dd4hep::Condition::Object* c)  const  {
0168       if ( 0 == (c->flags&dd4hep::Condition::DERIVED) )   {
0169 #if !defined(DD4HEP_MINIMAL_CONDITIONS)
0170         content.addLocation(c->hash,c->address);
0171 #endif
0172         return true;
0173       }
0174       return true;
0175     }
0176     /// Return number of conditions selected
0177     virtual size_t size()  const { return content.conditions().size(); }
0178   };
0179 }
0180 
0181 /// Populate the conditions slice from the conditions manager (convenience)
0182 void dd4hep::cond::fill_content(ConditionsManager mgr,
0183                                 ConditionsContent& content,
0184                                 const IOVType& typ)
0185 {
0186   ConditionsIOVPool* iovPool = mgr.iovPool(typ);
0187   ConditionsIOVPool::Elements& pools = iovPool->elements;
0188   for_each(begin(pools),end(pools),SliceOper(content));
0189 }