File indexing completed on 2025-02-21 09:58:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDCOND_CONDITIONSSLICE_H
0014 #define DDCOND_CONDITIONSSLICE_H
0015
0016
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
0026 #include <memory>
0027
0028
0029 namespace dd4hep {
0030
0031
0032 namespace cond {
0033
0034
0035 class UserPool;
0036 class ConditionsSlice;
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
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
0068
0069
0070
0071
0072
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
0102
0103
0104
0105 ConditionsManager manager;
0106
0107 std::unique_ptr<UserPool> pool;
0108
0109 std::shared_ptr<ConditionsContent> content;
0110
0111
0112 ConditionsManager::Result status;
0113
0114 ContainedPools used_pools;
0115
0116 unsigned long flags = 0;
0117
0118 protected:
0119
0120 ConditionsContent::Conditions m_missingConditions;
0121
0122 ConditionsContent::Dependencies m_missingDerivations;
0123
0124
0125 ConditionsSlice& operator=(const ConditionsSlice& copy) = delete;
0126
0127
0128
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
0136 ConditionsSlice() = delete;
0137
0138 ConditionsSlice(ConditionsManager m);
0139
0140 ConditionsSlice(ConditionsManager m, const std::shared_ptr<ConditionsContent>& c);
0141
0142 ConditionsSlice(const ConditionsSlice& copy);
0143
0144 virtual ~ConditionsSlice();
0145
0146
0147 size_t size() const { return content->conditions().size()+content->derived().size(); }
0148
0149 void refPools() { this->flags |= REF_POOLS; }
0150
0151 void derefPools();
0152
0153 const ConditionsContent::Conditions& conditions() const { return content->conditions();}
0154
0155 const ConditionsContent::Dependencies& derived() const { return content->derived(); }
0156
0157 ConditionsContent::Conditions& missingConditions() { return m_missingConditions; }
0158
0159 ConditionsContent::Dependencies& missingDerivations() { return m_missingDerivations; }
0160
0161 const IOV& iov() const;
0162
0163 void reset();
0164
0165
0166
0167 template <typename T> void manage(const T& conds, ManageFlag flg) {
0168 if ( !conds.empty() ) {
0169 ConditionsPool* p = (flg®ISTER_MANAGER) ? manager.registerIOV(pool->validity()) : 0;
0170 for( const auto& e : conds )
0171 manage(p, select_cond(e), flg);
0172 }
0173 }
0174
0175
0176 virtual bool manage(Condition condition, ManageFlag flg);
0177
0178
0179 std::vector<Condition> get(DetElement detector) const;
0180
0181
0182
0183 virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition) override;
0184
0185 virtual Condition get(DetElement detector, Condition::itemkey_type key) const override;
0186
0187 virtual std::vector<Condition> get(DetElement detector,
0188 Condition::itemkey_type lower,
0189 Condition::itemkey_type upper) const override;
0190
0191 virtual void scan(const Condition::Processor& processor) const override;
0192
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
0200 void fill_content(ConditionsManager mgr, ConditionsContent& content, const IOVType& typ);
0201
0202 }
0203 }
0204 #endif