File indexing completed on 2025-01-30 09:16:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Detector.h>
0016 #include <DD4hep/Errors.h>
0017 #include <DD4hep/Printout.h>
0018 #include <DD4hep/InstanceCount.h>
0019 #include <DD4hep/detail/Handle.inl>
0020 #include <DD4hep/PluginCreators.h>
0021
0022 #include <DD4hep/ConditionsListener.h>
0023 #include <DDCond/ConditionsManager.h>
0024 #include <DDCond/ConditionsManagerObject.h>
0025
0026 using namespace dd4hep::cond;
0027
0028 DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsManagerObject);
0029
0030
0031 namespace dd4hep {
0032
0033
0034 namespace cond {
0035
0036
0037 template <> ConditionsManager ConditionsManager::from<Detector>(Detector& host) {
0038 Object* obj = host.extension<Object>();
0039 if ( obj ) return ConditionsManager(obj);
0040 except("ConditionsManager","+++ Failed to access installed manager from Detector.");
0041 return ConditionsManager();
0042 }
0043 }
0044 }
0045
0046
0047 ConditionsManagerObject::ConditionsManagerObject(Detector& ref_description)
0048 : NamedObject(), m_detDesc(ref_description)
0049 {
0050 InstanceCount::increment(this);
0051 declareProperty("LoadConditions", m_doLoad);
0052 declareProperty("OutputUnloadedConditions", m_doOutputUnloaded);
0053 }
0054
0055
0056 ConditionsManagerObject::~ConditionsManagerObject() {
0057 m_onRegister.clear();
0058 m_onRemove.clear();
0059 InstanceCount::decrement(this);
0060 }
0061
0062 void ConditionsManagerObject::registerCallee(Listeners& listeners, const Listener& callee, bool add) {
0063 if ( add ) {
0064 listeners.insert(callee);
0065 return;
0066 }
0067 Listeners::iterator i=listeners.find(callee);
0068 if ( i != listeners.end() ) listeners.erase(i);
0069 }
0070
0071
0072 void ConditionsManagerObject::callOnRegister(const Listener& callee, bool add) {
0073 registerCallee(m_onRegister, callee, add);
0074 }
0075
0076
0077 void ConditionsManagerObject::callOnRemove(const Listener& callee, bool add) {
0078 registerCallee(m_onRemove, callee, add);
0079 }
0080
0081
0082 void ConditionsManagerObject::onRegister(Condition condition) {
0083 for(const auto& listener : m_onRegister )
0084 listener.first->onRegisterCondition(condition, listener.second);
0085 }
0086
0087
0088 void ConditionsManagerObject::onRemove(Condition condition) {
0089 for(const auto& listener : m_onRemove )
0090 listener.first->onRegisterCondition(condition, listener.second);
0091 }
0092
0093
0094 const std::vector<const dd4hep::IOVType*> ConditionsManagerObject::iovTypesUsed() const {
0095 std::vector<const IOVType*> result;
0096 const auto& types = this->iovTypes();
0097 for ( const auto& i : types ) {
0098 if ( i.type != IOVType::UNKNOWN_IOV ) result.emplace_back(&i);
0099 }
0100 return result;
0101 }
0102
0103
0104 void ConditionsManagerObject::fromString(const std::string& data, IOV& iov) {
0105 size_t id1 = data.find(',');
0106 size_t id2 = data.find('#');
0107 if ( id2 == std::string::npos ) {
0108 except("ConditionsManager","+++ Unknown IOV string representation: %s",data.c_str());
0109 }
0110 std::string iov_name = data.substr(id2+1);
0111 IOV::Key key;
0112 int nents = 0;
0113
0114 long k1 = 0, k2 = 0;
0115 if ( id1 != std::string::npos ) {
0116 nents = ::sscanf(data.c_str(),"%ld,%ld#",&k1,&k2) == 2 ? 2 : 0;
0117 key.second = k2;
0118 key.first = k1;
0119 }
0120 else {
0121 nents = ::sscanf(data.c_str(),"%ld#",&k1) == 1 ? 1 : 0;
0122 key.second = key.first = k1;
0123 }
0124 if ( nents == 0 ) {
0125 except("ConditionsManager",
0126 "+++ Failed to read keys from IOV string representation: %s",data.c_str());
0127 }
0128
0129
0130 const IOVType* typ = iovType(iov_name);
0131 if ( !typ ) {
0132
0133
0134 except("ConditionsManager","+++ Unknown IOV type requested from data: %s. [%s]",
0135 data.c_str(),Errors::invalidArg().c_str());
0136 }
0137 iov.type = typ->type;
0138 iov.iovType = typ;
0139 iov.set(key);
0140 }
0141
0142
0143 ConditionsPool* ConditionsManagerObject::registerIOV(const std::string& data) {
0144 IOV iov(0);
0145
0146 fromString(data, iov);
0147
0148
0149 return registerIOV(*iov.iovType, iov.keyData);
0150 }
0151
0152
0153 ConditionsManager::ConditionsManager(Detector& description, const std::string& factory) {
0154 ConditionsManagerObject* obj = createPlugin<ConditionsManagerObject>(factory,description);
0155 if ( !obj ) {
0156 except("ConditionsManagerInstaller","Failed to create manager object of type %s",
0157 factory.c_str());
0158 }
0159 assign(obj, "ConditionsManager",factory);
0160 }
0161
0162
0163 ConditionsManager::ConditionsManager(Detector& description) {
0164 assign(ConditionsManager::from(description).ptr(), "ConditionsManager","");
0165 }
0166
0167 ConditionsManager& ConditionsManager::initialize() {
0168 access()->initialize();
0169 return *this;
0170 }
0171
0172
0173 dd4hep::Detector& ConditionsManager::detectorDescription() const {
0174 return access()->detectorDescription();
0175 }
0176
0177
0178 dd4hep::PropertyManager& ConditionsManager::properties() const {
0179 return access()->properties();
0180 }
0181
0182
0183 dd4hep::Property& ConditionsManager::operator[](const std::string& property_name) const {
0184 return access()->properties().property(property_name);
0185 }
0186
0187
0188 ConditionsDataLoader& ConditionsManager::loader() const {
0189 return *(access()->loader());
0190 }
0191
0192
0193 std::pair<bool, const dd4hep::IOVType*>
0194 ConditionsManager::registerIOVType(size_t iov_type, const std::string& iov_name) const {
0195 return access()->registerIOVType(iov_type, iov_name);
0196 }
0197
0198
0199 const dd4hep::IOVType* ConditionsManager::iovType (const std::string& iov_name) const {
0200 return access()->iovType(iov_name);
0201 }
0202
0203
0204 ConditionsIOVPool* ConditionsManager::iovPool(const IOVType& iov_type) const {
0205 return access()->iovPool(iov_type);
0206 }
0207
0208
0209 const std::vector<const dd4hep::IOVType*> ConditionsManager::iovTypesUsed() const {
0210 Object* obj = access();
0211 std::vector<const IOVType*> result;
0212 const auto& types = obj->iovTypes();
0213 result.reserve(types.size());
0214 for(const auto& i : types )
0215 if ( i.type != IOVType::UNKNOWN_IOV ) result.emplace_back(&i);
0216 return result;
0217 }
0218
0219
0220 ConditionsPool* ConditionsManager::registerIOV(const std::string& iov_rep) const {
0221 IOV iov(0);
0222 Object* o = access();
0223 o->fromString(iov_rep, iov);
0224 if ( iov.iovType )
0225 return o->registerIOV(*iov.iovType, iov.key());
0226 except("ConditionsManager","Invalid IOV type registration requested by IOV:%s",iov_rep.c_str());
0227 return 0;
0228 }
0229
0230
0231 ConditionsPool* ConditionsManager::registerIOV(const IOV& iov) const {
0232 if ( iov.iovType )
0233 return access()->registerIOV(*iov.iovType, iov.key());
0234 except("ConditionsManager","+++ Attempt to register invalid IOV [FAILED]");
0235 return 0;
0236 }
0237
0238
0239 ConditionsPool* ConditionsManager::registerIOV(const IOVType& typ, IOV::Key key) const {
0240 return access()->registerIOV(typ, key);
0241 }
0242
0243
0244 void ConditionsManager::fromString(const std::string& iov_str, IOV& iov) const {
0245 access()->fromString(iov_str, iov);
0246 }
0247
0248
0249 std::size_t ConditionsManager::blockRegister(ConditionsPool& pool, const std::vector<Condition>& cond) const {
0250 return access()->blockRegister(pool, cond);
0251 }
0252
0253
0254 bool ConditionsManager::registerUnlocked(ConditionsPool& pool, Condition cond) const {
0255 return access()->registerUnlocked(pool, cond);
0256 }
0257
0258
0259 void ConditionsManager::pushUpdates() const {
0260 }
0261
0262
0263 void ConditionsManager::adoptCleanup(ConditionsCleanup* cleaner) const {
0264 access()->adoptCleanup(cleaner);
0265 }
0266
0267
0268 void ConditionsManager::clean(const IOVType* typ, int max_age) const {
0269 access()->clean(typ, max_age);
0270 }
0271
0272
0273 void ConditionsManager::clean(const ConditionsCleanup& cleaner) const {
0274 access()->clean(cleaner);
0275 }
0276
0277
0278 void ConditionsManager::clear() const {
0279 access()->clear();
0280 }
0281
0282
0283 std::unique_ptr<UserPool> ConditionsManager::createUserPool(const IOVType* iovT) const {
0284 return access()->createUserPool(iovT);
0285 }
0286
0287
0288 ConditionsManager::Result
0289 ConditionsManager::prepare(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx) const {
0290 return access()->prepare(req_iov, slice, ctx);
0291 }
0292
0293
0294 ConditionsManager::Result
0295 ConditionsManager::load(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx) const {
0296 return access()->load(req_iov, slice, ctx);
0297 }
0298
0299
0300 ConditionsManager::Result
0301 ConditionsManager::compute(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx) const {
0302 return access()->compute(req_iov, slice, ctx);
0303 }