File indexing completed on 2025-01-18 09:13:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
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
0023 ConditionsSlice::ConditionsSlice(ConditionsManager mgr) : manager(mgr)
0024 {
0025 InstanceCount::increment(this);
0026 }
0027
0028
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
0037 ConditionsSlice::ConditionsSlice(const ConditionsSlice& copy)
0038 : manager(copy.manager), content(copy.content)
0039 {
0040 InstanceCount::increment(this);
0041 }
0042
0043
0044 ConditionsSlice::~ConditionsSlice() {
0045 reset();
0046 InstanceCount::decrement(this);
0047 }
0048
0049
0050 void ConditionsSlice::derefPools() {
0051 used_pools.clear();
0052 this->flags &= ~REF_POOLS;
0053 }
0054
0055
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
0064 void ConditionsSlice::reset() {
0065 derefPools();
0066 if ( pool.get() ) pool->clear();
0067 }
0068
0069
0070 bool ConditionsSlice::manage(ConditionsPool* p, Condition condition, ManageFlag flg) {
0071 if ( condition.isValid() ) {
0072 bool ret = false;
0073 if ( flg®ISTER_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®ISTER_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
0102 bool ConditionsSlice::manage(Condition condition, ManageFlag flg) {
0103 ConditionsPool* p = (flg®ISTER_MANAGER) ? manager.registerIOV(pool->validity()) : 0;
0104 return manage(p, condition, flg);
0105 }
0106
0107
0108 std::vector<dd4hep::Condition> ConditionsSlice::get(DetElement detector) const {
0109 return pool->get(detector,FIRST_ITEM,LAST_ITEM);
0110 }
0111
0112
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
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
0142 dd4hep::Condition ConditionsSlice::get(DetElement detector, Condition::itemkey_type key) const {
0143 return pool->get(detector, key);
0144 }
0145
0146
0147 void ConditionsSlice::scan(const Condition::Processor& processor) const {
0148 pool->scan(processor);
0149 }
0150
0151
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
0177 virtual size_t size() const { return content.conditions().size(); }
0178 };
0179 }
0180
0181
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 }