diff --git a/DDCond/include/DDCond/ConditionsContent.h b/DDCond/include/DDCond/ConditionsContent.h index 2238fd0f5d94c8b40bbb5232106d059e6429845e..28e8c5c74be6a811088b76017ff9320e64dac1c2 100644 --- a/DDCond/include/DDCond/ConditionsContent.h +++ b/DDCond/include/DDCond/ConditionsContent.h @@ -18,6 +18,10 @@ #include "DD4hep/Conditions.h" #include "DD4hep/ConditionDerived.h" +// C/C++ include files +#include <memory> +#include <unordered_map> + /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -34,18 +38,25 @@ namespace dd4hep { */ class ConditionsLoadInfo { public: - /// Default constructor - ConditionsLoadInfo() = default; - /// Copy constructor - ConditionsLoadInfo(const ConditionsLoadInfo& copy) = default; + int refCount = 0; + protected: /// Default destructor. virtual ~ConditionsLoadInfo(); + public: + /// Default constructor + ConditionsLoadInfo(); + /// Move constructor + ConditionsLoadInfo(ConditionsLoadInfo&& copy) = delete; + /// Copy constructor + ConditionsLoadInfo(const ConditionsLoadInfo& copy) = delete; /// Assignment operator - ConditionsLoadInfo& operator=(const ConditionsLoadInfo& copy) = default; - + ConditionsLoadInfo& operator=(const ConditionsLoadInfo& copy) = delete; + ConditionsLoadInfo* addRef() { ++refCount; return this; } + void release() { --refCount; if ( refCount <= 0 ) delete this; } virtual const std::type_info& type() const = 0; virtual const void* ptr() const = 0; virtual ConditionsLoadInfo* clone() const = 0; + virtual std::string toString() const = 0; template<typename T> T* data() const { return (T*)ptr(); } }; @@ -73,19 +84,23 @@ namespace dd4hep { T info; LoadInfo(const T& i) : info(i) {} LoadInfo() = default; - LoadInfo(const LoadInfo& c) = default; + LoadInfo(const LoadInfo& c) = delete; virtual ~LoadInfo() = default; - LoadInfo& operator=(const LoadInfo& copy) = default; + LoadInfo& operator=(const LoadInfo& copy) = delete; virtual const std::type_info& type() const override { return typeid(T); } virtual const void* ptr() const override { return &info; } virtual ConditionsLoadInfo* clone() const override { return new LoadInfo<T>(info); } + virtual std::string toString() const override; }; - + + // Looks like tree-maps are a bit slower. typedef std::map<Condition::key_type,ConditionDependency* > Dependencies; typedef std::map<Condition::key_type,ConditionsLoadInfo* > Conditions; + //typedef std::unordered_map<Condition::key_type,ConditionDependency* > Dependencies; + //typedef std::unordered_map<Condition::key_type,ConditionsLoadInfo* > Conditions; protected: /// Container of conditions required by this content @@ -105,36 +120,48 @@ namespace dd4hep { /// Default destructor. virtual ~ConditionsContent(); /// Access to the real condition entries to be loaded + Conditions& conditions() { return m_conditions; } + /// Access to the real condition entries to be loaded (CONST) const Conditions& conditions() const { return m_conditions; } /// Access to the derived condition entries to be computed + Dependencies& derived() { return m_derived; } + /// Access to the derived condition entries to be computed (CONST) const Dependencies& derived() const { return m_derived; } /// Clear the conditions content definitions void clear(); + /// Merge the content of "to_add" into the this content + void merge(const ConditionsContent& to_add); /// Remove a condition from the content bool remove(Condition::key_type condition); /// Add a new conditions key representing a real (not derived) condition - bool insertKey(Condition::key_type hash) { - return m_conditions.insert(std::make_pair(hash,(ConditionsLoadInfo*)0)).second; - } + std::pair<Condition::key_type, ConditionsLoadInfo*> + insertKey(Condition::key_type hash); /// Add a new conditions key. T must inherit from class ConditionsContent::Info - bool insertKey(Condition::key_type hash, std::unique_ptr<ConditionsLoadInfo>& info) { - bool ret = m_conditions.insert(std::make_pair(hash,info.get())).second; - if ( ret ) info.release(); - else info.reset(); - return ret; - } + std::pair<Condition::key_type, ConditionsLoadInfo*> + addLocationInfo(Condition::key_type hash, ConditionsLoadInfo* info); /// Add a new conditions key. T must inherit from class ConditionsContent::Info - template <typename T> bool insertKey(Condition::key_type hash, const T& info) { - std::unique_ptr<ConditionsLoadInfo> ptr(new LoadInfo<T>(info)); - return insertKey(hash, ptr); + template <typename T> std::pair<Condition::key_type, ConditionsLoadInfo*> + addLocation(Condition::key_type hash, const T& info) { + return addLocationInfo(hash, new LoadInfo<T>(info)); } - /// Add a new shared conditions dependency - bool insertDependency(ConditionDependency* dep) { - bool ret = m_derived.insert(std::make_pair(dep->key(),dep)).second; - if ( ret ) dep->addRef(); - return ret; + /// Add a new shared conditions dependency. + template <typename T> std::pair<Condition::key_type, ConditionsLoadInfo*> + addLocation(DetElement de, Condition::itemkey_type item, const T& info) { + return addLocationInfo(ConditionKey(de, item).hash, new LoadInfo<T>(info)); } + /// Add a new shared conditions dependency + std::pair<Condition::key_type, ConditionDependency*> + addDependency(ConditionDependency* dep); + /// Add a new conditions dependency (Built internally from arguments) + std::pair<Condition::key_type, ConditionDependency*> + addDependency(DetElement de, Condition::itemkey_type item, ConditionUpdateCall* callback); }; + + template <> inline + std::string ConditionsContent::LoadInfo<std::string>::toString() const { + return this->info; + } + } /* End namespace cond */ } /* End namespace dd4hep */ #endif /* DD4HEP_DDCOND_CONDITIONSCONTENT_H */ diff --git a/DDCond/include/DDCond/ConditionsDataLoader.h b/DDCond/include/DDCond/ConditionsDataLoader.h index 8787fb4beb8fbe1abecc225b3dd9b2f1db9750b3..bdd12e267cda373cd5c12dc85941b1a83da5aaf5 100644 --- a/DDCond/include/DDCond/ConditionsDataLoader.h +++ b/DDCond/include/DDCond/ConditionsDataLoader.h @@ -55,7 +55,7 @@ namespace dd4hep { protected: /// Reference to main detector description object - Detector& m_detDesc; + Detector& m_detector; /// Reference to conditions manager used to queue update requests ConditionsManager m_mgr; /// Property: input data source definitions @@ -72,6 +72,14 @@ namespace dd4hep { ConditionsDataLoader(Detector& description, ConditionsManager mgr, const std::string nam); /// Default destructor virtual ~ConditionsDataLoader(); + /// Optional initialization for sub-classes + virtual void initialize() {} + /// Access conditions manager + ConditionsManager manager() const { return m_mgr; } + /// Access to properties + Property& operator[](const std::string& property_name); + /// Access to properties (CONST) + const Property& operator[](const std::string& property_name) const; /// Add data source definition to loader void addSource(const std::string& source); /// Add data source definition to loader for data corresponding to a given IOV diff --git a/DDCond/include/DDCond/ConditionsDependencyHandler.h b/DDCond/include/DDCond/ConditionsDependencyHandler.h index c452225a5a16a9e1e52598b0f3f3bf34d159fe11..589c994be6eeccf2a2db074a709b2ca19fa5dce1 100644 --- a/DDCond/include/DDCond/ConditionsDependencyHandler.h +++ b/DDCond/include/DDCond/ConditionsDependencyHandler.h @@ -32,6 +32,17 @@ namespace dd4hep { /// Callback handler to update condition dependencies. /** + * Fully stack based condition resolution. Any user request + * for dependent conditions are fully handled by + * - either the connected conditions pool (if present there) or + * - by the currently worked on items. + * + * The ConditionsDependencyHandler implements the + * ConditionResolver interface, which is offered to the clients as + * an embedded parameter during the conversion mechanism. + * Clients must direct any subsequent conditions access to the + * ConditionResolver interface in order to allow for upgrades of + * this implementation which might not be polymorph. * * \author M.Frank * \version 1.0 @@ -42,18 +53,35 @@ namespace dd4hep { enum State { INVALID, CREATED, RESOLVED }; /// Helper structure to define the current update item struct Work { - IOV iov; + public: + IOV _iov; + /// Auxiliary information to resolve condition callbacks ConditionUpdateContext context; + /// Condition IOV + IOV* iov = 0; + /// The final result: the condition object Condition::Object* condition = 0; - State state = INVALID; + /// Flag to detect non resolvable circular dependencies + int callstack = 0; + /// Current conversion state of the item + State state = INVALID; + public: + /// Inhibit default constructor Work() = delete; + /// Initializing constructor Work(ConditionResolver* r, const ConditionDependency* d, ConditionUpdateUserContext* u, const IOV& i) - : iov(i), context(r,d,&iov,u) {} + : _iov(i), context(r,d,&_iov,u) {} + /// Copy constructor Work(const Work&) = default; + /// Assignment operator Work& operator=(const Work&) = default; + /// Helper to determine the IOV intersection taking into account dependencies + void do_intersection(const IOV* iov); + /// Helper function for the second level dependency resolution + Condition resolve(Work*& current); }; typedef std::map<Condition::key_type, const ConditionDependency*> Dependencies; typedef std::map<Condition::key_type, Work*> WorkConditions; @@ -65,24 +93,25 @@ namespace dd4hep { UserPool& m_pool; /// Dependency container to be resolved. const Dependencies& m_dependencies; - /// IOV target pool for this handler - ConditionsPool* m_iovPool; /// User defined optional processing parameter ConditionUpdateUserContext* m_userParam; + /// Local cacheL pool's IOV type + const IOVType* m_iovType = 0; /// The objects created during processing - WorkConditions m_created, m_todo; + WorkConditions m_todo; /// Handler's state State m_state = CREATED; - /// Current blocking work item - Work* m_block; - + /// Current block work item + Work* m_block = 0; + /// Current item of the block + Work* m_currentWork = 0; public: /// Number of callbacks to the handler for monitoring mutable size_t num_callback; protected: /// Internal call to trigger update callback - Condition::Object* do_callback(Work* dep); + void do_callback(Work* dep); public: /// Initializing constructor @@ -122,6 +151,8 @@ namespace dd4hep { virtual std::vector<Condition> get(DetElement de) override; /// Interface to access conditions by hash value of the DetElement (only valid at resolve!) virtual std::vector<Condition> get(Condition::detkey_type key) override; + /// Interface to access conditions by hash value of the item (only valid at resolve!) + virtual std::vector<Condition> getByItem(Condition::itemkey_type key) override; }; } /* End namespace cond */ diff --git a/DDCond/include/DDCond/ConditionsManager.h b/DDCond/include/DDCond/ConditionsManager.h index 2e3e2176e73c51102171cebe54fb1becf2875fac..35d2ac3f80496431a77c57e9159137ca0deedaba 100644 --- a/DDCond/include/DDCond/ConditionsManager.h +++ b/DDCond/include/DDCond/ConditionsManager.h @@ -48,7 +48,6 @@ namespace dd4hep { /// Standard object type typedef ConditionsManagerObject Object; - typedef ConditionsDataLoader Loader; typedef std::vector<IOVType> IOVTypes; /// Result of a prepare call to the conditions manager @@ -85,9 +84,12 @@ namespace dd4hep { */ template <typename T> static ConditionsManager from(T& host); - /// Initializing constructor + /// Initializing constructor - used only by examples ConditionsManager(Detector& description); + /// Initializing constructor to create a manager from the factory name + ConditionsManager(Detector& description, const std::string& factory); + /// Default constructor ConditionsManager() = default; @@ -119,7 +121,7 @@ namespace dd4hep { PropertyManager& properties() const; /// Access the conditions loader - Loader* loader() const; + ConditionsDataLoader& loader() const; /// Access the used/registered IOV types const std::vector<const IOVType*> iovTypesUsed() const; @@ -150,6 +152,9 @@ namespace dd4hep { /// Register new condition with the conditions store. Unlocked version, not multi-threaded bool registerUnlocked(ConditionsPool& pool, Condition cond) const; + + /// Register a whole block of conditions with identical IOV. + size_t blockRegister(ConditionsPool& pool, const std::vector<Condition>& cond) const; /// Push all pending updates to the conditions store. /** Note: @@ -181,6 +186,14 @@ namespace dd4hep { Result prepare(const IOV& required_validity, ConditionsSlice& slice, ConditionUpdateUserContext* ctxt=0) const; + /// Load all updates to the clients with the defined IOV (1rst step of prepare) + Result load(const IOV& required_validity, + ConditionsSlice& slice, + ConditionUpdateUserContext* ctxt=0) const; + /// Compute all derived conditions with the defined IOV (2nd step of prepare) + Result compute(const IOV& required_validity, + ConditionsSlice& slice, + ConditionUpdateUserContext* ctxt=0) const; }; /// Add results diff --git a/DDCond/include/DDCond/ConditionsManagerObject.h b/DDCond/include/DDCond/ConditionsManagerObject.h index ed2960dd836c67e8314bcae28014d8fdfe7d08ce..c9bd8a4770e337b384e794c6f1056bed02eb7fb4 100644 --- a/DDCond/include/DDCond/ConditionsManagerObject.h +++ b/DDCond/include/DDCond/ConditionsManagerObject.h @@ -53,7 +53,6 @@ namespace dd4hep { public PropertyConfigurable { public: - typedef std::vector<IOVType> IOVTypes; typedef Condition::key_type key_type; typedef std::pair<ConditionsListener*,void*> Listener; typedef std::set<Listener> Listeners; @@ -62,7 +61,7 @@ namespace dd4hep { protected: /// Reference to main detector description object - Detector& m_detDesc; + Detector& m_detDesc; /// Conditions listeners on registration of new conditions Listeners m_onRegister; /// Conditions listeners on de-registration of new conditions @@ -123,7 +122,7 @@ namespace dd4hep { virtual void initialize() = 0; /// Access IOV by its type - virtual const IOVTypes& iovTypes () const = 0; + virtual const std::vector<IOVType>& iovTypes () const = 0; /// Access IOV by its type virtual const IOVType* iovType (size_t iov_type) const = 0; @@ -158,12 +157,25 @@ namespace dd4hep { /// Register new condition with the conditions store. Unlocked version, not multi-threaded virtual bool registerUnlocked(ConditionsPool& pool, Condition cond) = 0; + /// Register a whole block of conditions with identical IOV. + virtual size_t blockRegister(ConditionsPool& pool, const std::vector<Condition>& cond) const = 0; + /// Create empty user pool object virtual std::unique_ptr<UserPool> createUserPool(const IOVType* iovT) const = 0; /// Prepare all updates to the clients with the defined IOV virtual Result prepare(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx=0) = 0; + /// Load all updates to the clients with the defined IOV (1rst step of prepare) + virtual Result load(const IOV& required_validity, + ConditionsSlice& slice, + ConditionUpdateUserContext* ctxt=0) = 0; + + /// Compute all derived conditions with the defined IOV (2nd step of prepare) + virtual Result compute(const IOV& required_validity, + ConditionsSlice& slice, + ConditionUpdateUserContext* ctxt=0) = 0; + /// Adopt cleanup handler. If a handler is registered, it is invoked at every "prepare" step /** Note: * This may be convenient under certain circumstances, however at the expense of diff --git a/DDCond/include/DDCond/ConditionsPool.h b/DDCond/include/DDCond/ConditionsPool.h index e42e0dd2472e0cf630112230a2d6d031119d0d1d..9807256a8ae9d9454c76b3662253b3eb66c6e88b 100644 --- a/DDCond/include/DDCond/ConditionsPool.h +++ b/DDCond/include/DDCond/ConditionsPool.h @@ -157,6 +157,10 @@ namespace dd4hep { /// ConditionsMap overload: Add a condition directly to the slice virtual bool insert(Condition condition) = 0; + template <typename C> struct get_second { + const typename C::mapped_type& operator()( const typename C::value_type& v) const + { return v.second; } + }; public: /// Default constructor @@ -185,6 +189,25 @@ namespace dd4hep { virtual bool remove(Condition::key_type hash_key) = 0; /// Remove condition by key from pool. virtual bool remove(const ConditionKey& key) = 0; + /// Do single insertion of condition including registration to the manager + /** Note: block insertions are preferred!!! */ + virtual bool registerOne(const IOV& iov, Condition cond) = 0; + /// Do block insertions of conditions with identical IOV + virtual size_t registerMany(const IOV& iov, const std::vector<Condition>& values) = 0; + /// Insert multiple conditions. Note: the conditions must already have a hash key + template <typename CONT> size_t registerUnmapped(const IOV& iov, CONT& c) { + std::vector<Condition> conditions; + conditions.reserve(c.size()); + std::copy(std::begin(c), std::end(c), std::back_inserter(conditions)); + return this->registerMany(iov, conditions); + } + /// Insert multiple conditions. Note: the conditions must already have a hash key + template <typename CONT> size_t registerMapping(const IOV& iov, CONT& c) { + std::vector<Condition> conditions; + conditions.reserve(c.size()); + std::transform(std::begin(c), std::end(c), std::back_inserter(conditions), get_second<CONT>()); + return this->registerMany(iov, conditions); + } /// ConditionsMap overload: Add a condition directly to the slice virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition) = 0; @@ -215,6 +238,15 @@ namespace dd4hep { ConditionsSlice& slice, ConditionUpdateUserContext* user_param = 0) = 0; + /// Load all updates to the clients with the defined IOV (1rst step of prepare) + virtual ConditionsManager::Result load(const IOV& required_validity, + ConditionsSlice& slice, + ConditionUpdateUserContext* ctxt=0) = 0; + /// Compute all derived conditions with the defined IOV (2nd step of prepare) + virtual ConditionsManager::Result compute(const IOV& required_validity, + ConditionsSlice& slice, + ConditionUpdateUserContext* ctxt=0) = 0; + /// Evaluate and register all derived conditions from the dependency list virtual size_t compute(const Dependencies& dependencies, ConditionUpdateUserContext* user_param, diff --git a/DDCond/include/DDCond/Type1/Manager_Type1.h b/DDCond/include/DDCond/Type1/Manager_Type1.h index d2289712dd4a72a89146dd63094e6a935ee6a198..fd8b5ee5e2d3bb98eef6720ab5ba075218d84486 100644 --- a/DDCond/include/DDCond/Type1/Manager_Type1.h +++ b/DDCond/include/DDCond/Type1/Manager_Type1.h @@ -64,7 +64,7 @@ namespace dd4hep { std::string m_loaderType; /// Collection of IOV types managed - IOVTypes m_iovTypes; + std::vector<IOVType> m_iovTypes; /** Specialized interface only used by this implementation */ /// Lock to protect the update/delayed conditions pool @@ -122,7 +122,7 @@ namespace dd4hep { virtual std::pair<bool, const IOVType*> registerIOVType(size_t iov_index, const std::string& iov_name) final; /// Access IOV by its type - virtual const IOVTypes& iovTypes () const final { return m_iovTypes; } + virtual const std::vector<IOVType>& iovTypes () const final { return m_iovTypes; } /// Access IOV by its type virtual const IOVType* iovType (size_t iov_index) const final; @@ -139,6 +139,9 @@ namespace dd4hep { /// Register new condition with the conditions store. Unlocked version, not multi-threaded virtual bool registerUnlocked(ConditionsPool& pool, Condition cond) final; + /// Register a whole block of conditions with identical IOV. + virtual size_t blockRegister(ConditionsPool& pool, const std::vector<Condition>& cond) const final; + /// Adopt cleanup handler. If a handler is registered, it is invoked at every "prepare" step virtual void adoptCleanup(ConditionsCleanup* cleaner) final; @@ -176,7 +179,17 @@ namespace dd4hep { * * @return */ - Result prepare(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctxt) final; + virtual Result prepare(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctxt) final; + + /// Load all updates to the clients with the defined IOV (1rst step of prepare) + virtual Result load(const IOV& required_validity, + ConditionsSlice& slice, + ConditionUpdateUserContext* ctxt=0) final; + /// Compute all derived conditions with the defined IOV (2nd step of prepare) + virtual Result compute(const IOV& required_validity, + ConditionsSlice& slice, + ConditionUpdateUserContext* ctxt=0) final; + }; } /* End namespace cond */ diff --git a/DDCond/src/ConditionsContent.cpp b/DDCond/src/ConditionsContent.cpp index 03e8ec84ef01f3655ab4475ecf273df437e2919a..8467224c680973e85d6b336febc404aec6963079 100644 --- a/DDCond/src/ConditionsContent.cpp +++ b/DDCond/src/ConditionsContent.cpp @@ -14,11 +14,20 @@ // Framework include files #include "DDCond/ConditionsContent.h" #include "DD4hep/InstanceCount.h" +#include "DD4hep/Printout.h" +using namespace std; +using namespace dd4hep; using namespace dd4hep::cond; +/// Default constructor +ConditionsLoadInfo::ConditionsLoadInfo() { + InstanceCount::increment(this); +} + /// Default destructor. ConditionsLoadInfo::~ConditionsLoadInfo() { + InstanceCount::decrement(this); } /// Initializing constructor @@ -30,21 +39,50 @@ ConditionsContent::ConditionsContent() /// Default destructor. ConditionsContent::~ConditionsContent() { detail::releaseObjects(m_derived); - detail::destroyObjects(m_conditions); + detail::releaseObjects(m_conditions); InstanceCount::decrement(this); } /// Clear the container. Destroys the contained stuff void ConditionsContent::clear() { detail::releaseObjects(m_derived); - detail::destroyObjects(m_conditions); + detail::releaseObjects(m_conditions); +} + +/// Merge the content of "to_add" into the this content +void ConditionsContent::merge(const ConditionsContent& to_add) { + auto& cond = to_add.conditions(); + auto& deriv = to_add.derived(); + for( const auto& c : cond ) { + auto ret = m_conditions.insert(c); + if ( ret.second ) { + c.second->addRef(); + continue; + } + // Need error handling here ? + ConditionKey key(c.first); + printout(WARNING,"ConditionsContent", + "++ Condition %s already present in content. Not merged",key.toString().c_str()); + + } + for( const auto& d : deriv ) { + auto ret = m_derived.insert(d); + if ( ret.second ) { + d.second->addRef(); + continue; + } + // Need error handling here ? + ConditionKey key(d.first); + printout(WARNING,"ConditionsContent", + "++ Dependency %s already present in content. Not merged",key.toString().c_str()); + } } /// Remove a new shared condition bool ConditionsContent::remove(Condition::key_type hash) { auto i = m_conditions.find(hash); if ( i != m_conditions.end() ) { - detail::deleteObject((*i).second); + detail::releasePtr((*i).second); m_conditions.erase(i); return true; } @@ -56,3 +94,53 @@ bool ConditionsContent::remove(Condition::key_type hash) { } return false; } + +pair<Condition::key_type, ConditionsLoadInfo*> +ConditionsContent::insertKey(Condition::key_type hash) { + auto ret = m_conditions.insert(make_pair(hash,(ConditionsLoadInfo*)0)); + if ( ret.second ) return pair<Condition::key_type, ConditionsLoadInfo*>(hash,0); + return pair<Condition::key_type, ConditionsLoadInfo*>(0,0); +} + +/// Add a new conditions key. T must inherit from class ConditionsContent::Info +pair<Condition::key_type, ConditionsLoadInfo*> +ConditionsContent::addLocationInfo(Condition::key_type hash, ConditionsLoadInfo* info) { + if ( info ) { + auto ret = m_conditions.insert(make_pair(hash,info)); + if ( ret.second ) { + info->addRef(); + return *(ret.first); + } + info->release(); + } + return pair<Condition::key_type, ConditionsLoadInfo*>(0,0); +} + +/// Add a new shared conditions dependency +pair<Condition::key_type, ConditionDependency*> +ConditionsContent::addDependency(ConditionDependency* dep) +{ + auto ret = m_derived.insert(make_pair(dep->key(),dep)); + if ( ret.second ) { + dep->addRef(); + return *(ret.first); + } + ConditionKey::KeyMaker km(dep->target.hash); + DetElement de(dep->detector); + dep->release(); + except("DeConditionsRequests", + "++ Dependency already exists: %s [%08X] [%016llX]", + de.path().c_str(), km.values.item_key, km.hash); + return pair<Condition::key_type, ConditionDependency*>(0,0); +} + +/// Add a new conditions dependency (Built internally from arguments) +std::pair<Condition::key_type, ConditionDependency*> +ConditionsContent::addDependency(DetElement de, + Condition::itemkey_type item, + ConditionUpdateCall* callback) +{ + ConditionDependency* dep = new ConditionDependency(de, item, callback); + return addDependency(dep); +} + diff --git a/DDCond/src/ConditionsDataLoader.cpp b/DDCond/src/ConditionsDataLoader.cpp index b7380c0b4c8c49cf0688c52308cbb3f4fd85224e..b4c379d434348c141a554f52a88524eb3ed91e04 100644 --- a/DDCond/src/ConditionsDataLoader.cpp +++ b/DDCond/src/ConditionsDataLoader.cpp @@ -24,7 +24,7 @@ DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsDataLoader); /// Default constructor ConditionsDataLoader::ConditionsDataLoader(Detector& description, ConditionsManager mgr, const string nam) - : NamedObject(nam,"ConditionsDataLoader"), m_detDesc(description), m_mgr(mgr) + : NamedObject(nam,"ConditionsDataLoader"), m_detector(description), m_mgr(mgr) { if ( m_mgr.isValid() ) return; except("ConditionsDataLoader","+++ Cannot create loader without a valid conditions manager handle!"); @@ -34,6 +34,16 @@ ConditionsDataLoader::ConditionsDataLoader(Detector& description, ConditionsMana ConditionsDataLoader::~ConditionsDataLoader() { } +/// Access to properties +dd4hep::Property& ConditionsDataLoader::operator[](const std::string& property_name) { + return properties().property(property_name); +} + +/// Access to properties (CONST) +const dd4hep::Property& ConditionsDataLoader::operator[](const std::string& property_name) const { + return properties().property(property_name); +} + /// Add data source definition to loader void ConditionsDataLoader::addSource(const string& source, const IOV& iov) { m_sources.push_back(make_pair(source,iov)); diff --git a/DDCond/src/ConditionsDependencyHandler.cpp b/DDCond/src/ConditionsDependencyHandler.cpp index 3c2ee828a74df87340587aac1447b056f67515bc..8a464d6c7a3907f6a9d44871fa74e0f14c7ad7aa 100644 --- a/DDCond/src/ConditionsDependencyHandler.cpp +++ b/DDCond/src/ConditionsDependencyHandler.cpp @@ -14,6 +14,7 @@ // Framework include files #include "DDCond/ConditionsDependencyHandler.h" #include "DDCond/ConditionsManagerObject.h" +#include "DD4hep/ConditionsProcessor.h" #include "DD4hep/Printout.h" using namespace dd4hep; @@ -30,7 +31,28 @@ namespace { return text; #endif } +} + +void ConditionsDependencyHandler::Work::do_intersection(const IOV* iov_ptr) { + if ( iov_ptr ) { + if ( !this->iov ) { + this->_iov = *iov_ptr; + this->iov = &this->_iov; + } + else { + this->_iov.iov_intersection(*iov_ptr); + } + } +} +Condition ConditionsDependencyHandler::Work::resolve(Work*& current) { + Work* previous = current; + current = this; + state = RESOLVED; + context.dependency->callback->resolve(condition, context); + previous->do_intersection(iov); + current = previous; + return condition; } /// Default constructor @@ -42,22 +64,19 @@ ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManager mgr, m_userParam(user_param), num_callback(0) { const IOV& iov = m_pool.validity(); - //IOV full_iov(iov.iovType,IOV::Key(IOV::MIN_KEY,IOV::MAX_KEY)); - IOV full_iov(iov.iovType,IOV::Key(0,detail::makeTime(2099,12,31))); - m_iovPool = m_manager->registerIOV(*iov.iovType, iov.keyData); unsigned char* p = new unsigned char[dependencies.size()*sizeof(Work)]; Dependencies::const_iterator idep = dependencies.begin(); m_block = (Work*)p; for(size_t i=0; i<dependencies.size(); ++i, ++idep, p+=sizeof(Work)) { - Work* w = new(p) Work(this,(*idep).second,user_param,full_iov); + Work* w = new(p) Work(this,(*idep).second,user_param,iov); m_todo.insert(std::make_pair((*idep).first,w)); } + m_iovType = iov.iovType; } /// Default destructor ConditionsDependencyHandler::~ConditionsDependencyHandler() { m_todo.clear(); - m_created.clear(); if ( m_block ) delete [] m_block; m_block = 0; } @@ -82,28 +101,47 @@ void ConditionsDependencyHandler::compute() { /// 2nd pass: Handler callback for the second turn to resolve missing dependencies void ConditionsDependencyHandler::resolve() { + PrintLevel prt_lvl = INFO; size_t num_resolved = 0; - std::map<IOV::Key,ConditionsPool*> pools; + std::vector<Condition> tmp; + std::map<IOV::Key,std::vector<Condition> > work_pools; + Work* w; + m_state = RESOLVED; - for( auto& c : m_created ) { - Work* w = c.second; + for( const auto& c : m_todo ) { + w = c.second; + // Fill an empty map of condition vectors for the block inserts + auto ret = work_pools.insert(make_pair(w->iov->keyData,tmp)); + if ( ret.second ) { + // There is sort of the hope that most conditions go into 1 pool... + ret.first->second.reserve(m_todo.size()); + } if ( w->state == RESOLVED ) continue; w->state = RESOLVED; + m_currentWork = w; w->context.dependency->callback->resolve(w->condition, w->context); ++num_resolved; } // Optimize pool interactions: Cache pool in map assuming there are only few pools created - for( auto& c : m_created ) { - Work* w = c.second; - ConditionsPool* p = 0; - auto res = pools.insert(make_pair(w->iov.keyData,p)); - if ( res.second ) { - p = m_manager->registerIOV(*w->iov.iovType, w->iov.keyData); - (*res.first).second = p; + for( const auto& c : m_todo ) { + w = c.second; + auto& section = work_pools[w->iov->keyData]; + section.push_back(w->condition); + printout(prt_lvl,"DependencyHandler","++ Register %s %s %s [%s]", + w->context.dependency->target.toString().c_str(), + w->context.dependency->detector.path().c_str(), + w->condition->iov->str().c_str(), + typeName(typeid(*w->condition)).c_str()); + } + // Now block register all conditions to the manager AND to the user pool + for( const auto& section : work_pools ) { + IOV iov(m_iovType, section.first); + size_t result = m_pool.registerMany(iov, section.second); + if ( result != section.second.size() ) { + // } - p = (*res.first).second; - w->condition->iov = p->iov; - m_manager->registerUnlocked(*p, w->condition); + printout(prt_lvl,"DependencyHandler","++ Inserted %ld conditions to pool-iov: %s", + section.second.size(), iov.str().c_str()); } } @@ -112,12 +150,37 @@ std::vector<Condition> ConditionsDependencyHandler::get(DetElement de) { return this->get(de.key()); } +/// Interface to access conditions by hash value of the item (only valid at resolve!) +std::vector<Condition> ConditionsDependencyHandler::getByItem(Condition::itemkey_type key) { + if ( m_state == RESOLVED ) { + struct item_selector { + std::vector<Condition> conditions; + Condition::itemkey_type key; + item_selector(Condition::itemkey_type k) : key(k) {} + virtual int operator()(Condition cond) { + ConditionKey::KeyMaker km(cond->hash); + if ( km.values.item_key == key ) conditions.push_back(cond); + return 1; + } + }; + item_selector proc(key); + m_pool.scan(conditionsProcessor(proc)); + for (auto c : proc.conditions ) m_currentWork->do_intersection(c->iov); + return proc.conditions; + } + except("ConditionsDependencyHandler", + "Conditions bulk accesses are only possible during conditions resolution!"); + return std::vector<Condition>(); +} + /// Interface to access conditions by hash value of the DetElement (only valid at resolve!) std::vector<Condition> ConditionsDependencyHandler::get(Condition::detkey_type det_key) { if ( m_state == RESOLVED ) { - ConditionKey::KeyMaker lower(det_key, 0); - ConditionKey::KeyMaker upper(det_key, ~0x0); - return m_pool.get(lower.hash, upper.hash); + ConditionKey::KeyMaker lower(det_key, Condition::FIRST_ITEM_KEY); + ConditionKey::KeyMaker upper(det_key, Condition::LAST_ITEM_KEY); + std::vector<Condition> conditions = m_pool.get(lower.hash, upper.hash); + for (auto c : conditions ) m_currentWork->do_intersection(c->iov); + return conditions; } except("ConditionsDependencyHandler", "Conditions bulk accesses are only possible during conditions resolution!"); @@ -126,26 +189,27 @@ std::vector<Condition> ConditionsDependencyHandler::get(Condition::detkey_type d /// ConditionResolver implementation: Interface to access conditions Condition ConditionsDependencyHandler::get(Condition::key_type key, bool throw_if_not) { - /// Check if the required condition is one of the newly created ones: - auto e = m_created.find(key); - if ( e != m_created.end() ) { - Work* w = (*e).second; - if ( w->state == CREATED ) { - w->state = RESOLVED; - w->context.dependency->callback->resolve(w->condition, w->context); - return w->condition; - } - } /// If we are not already resolving here, we follow the normal procedure Condition c = m_pool.get(key); if ( c.isValid() ) { + m_currentWork->do_intersection(c->iov); return c; } auto i = m_todo.find(key); if ( i != m_todo.end() ) { - c = do_callback((*i).second); - if ( c.isValid() ) { - return c; + Work* w = i->second; + if ( w->state == RESOLVED ) { + return w->condition; + } + else if ( w->state == CREATED ) { + return w->resolve(m_currentWork); + } + else if ( w->state == INVALID ) { + do_callback(w); + if ( w->condition && w->state == RESOLVED ) // cross-dependencies... + return w->condition; + else if ( w->condition ) + return w->resolve(m_currentWork); } } if ( throw_if_not ) { @@ -154,26 +218,41 @@ Condition ConditionsDependencyHandler::get(Condition::key_type key, bool throw_i return Condition(); } - /// Internal call to trigger update callback -Condition::Object* -ConditionsDependencyHandler::do_callback(Work* work) { - const ConditionDependency* dep = work->context.dependency; +void ConditionsDependencyHandler::do_callback(Work* work) { + const ConditionDependency* dep = work->context.dependency; try { + Work* previous = m_currentWork; + m_currentWork = work; + if ( work->callstack > 0 ) { + // if we end up here it means a previous construction call never finished + // because the bugger tried to access another condition, which in turn + // during the construction tries to access this one. + // ---> Classic dead-lock + except("DependencyHandler", + "++ Handler caught in infinite recursion loop. DE:%s Key:%s", + work->context.dependency->target.toString().c_str(), + work->context.dependency->detector.path().c_str()); + } + ++work->callstack; work->condition = (*dep->callback)(dep->target, work->context).ptr(); + --work->callstack; + m_currentWork = previous; if ( work->condition ) { - work->condition->iov = &work->iov; + if ( !work->iov ) { + work->_iov = IOV(m_iovType,IOV::Key(IOV::MIN_KEY, IOV::MAX_KEY)); + work->iov = &work->_iov; + } + if ( previous ) { + previous->do_intersection(work->iov); + } + work->condition->iov = work->iov; work->condition->hash = dep->target.hash; work->condition->setFlag(Condition::DERIVED); work->state = CREATED; - //TEST cond->iov = m_pool.validityPtr(); - // Must IMMEDIATELY insert to handle inter-dependencies. ++num_callback; - m_created[dep->target.hash] = work; - //TEST m_manager->registerUnlocked(*m_iovPool, work.condition); - m_pool.insert(work->condition); } - return work->condition; + return; } catch(const std::exception& e) { printout(ERROR,"ConditionDependency", @@ -190,5 +269,4 @@ ConditionsDependencyHandler::do_callback(Work* work) { except("ConditionDependency", "++ Exception while creating dependent Condition %s.", dependency_name(dep).c_str()); - return 0; } diff --git a/DDCond/src/ConditionsManager.cpp b/DDCond/src/ConditionsManager.cpp index 6c9dba94870c26d934922a1e4473e7078ab3f8ed..8ca9ca5a76dad5fbc27a6d178ef28970f86e3f40 100644 --- a/DDCond/src/ConditionsManager.cpp +++ b/DDCond/src/ConditionsManager.cpp @@ -17,6 +17,7 @@ #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/detail/Handle.inl" +#include "DD4hep/PluginCreators.h" #include "DD4hep/ConditionsListener.h" #include "DDCond/ConditionsManager.h" @@ -95,7 +96,7 @@ void ConditionsManagerObject::onRemove(Condition condition) { /// Access the used/registered IOV types const vector<const IOVType*> ConditionsManagerObject::iovTypesUsed() const { vector<const IOVType*> result; - const IOVTypes& types = iovTypes(); + const auto& types = this->iovTypes(); for ( const auto& i : types ) { if ( int(i.type) != IOVType::UNKNOWN_IOV ) result.push_back(&i); } @@ -146,6 +147,16 @@ ConditionsPool* ConditionsManagerObject::registerIOV(const string& data) { return registerIOV(*iov.iovType, iov.keyData); } +/// Initializing constructor to create a named manager +ConditionsManager::ConditionsManager(Detector& description, const std::string& factory) { + ConditionsManagerObject* obj = createPlugin<ConditionsManagerObject>(factory,description); + if ( !obj ) { + except("ConditionsManagerInstaller","Failed to create manager object of type %s", + factory.c_str()); + } + assign(obj, "ConditionsManager",factory); +} + /// Default constructor ConditionsManager::ConditionsManager(Detector& description) { assign(ConditionsManager::from(description).ptr(), "ConditionsManager",""); @@ -156,24 +167,24 @@ ConditionsManager& ConditionsManager::initialize() { return *this; } -/// Access to the property manager -PropertyManager& ConditionsManager::properties() const { - return access()->properties(); -} - /// Access the detector description Detector& ConditionsManager::detectorDescription() const { return access()->detectorDescription(); } +/// Access to the property manager +PropertyManager& ConditionsManager::properties() const { + return access()->properties(); +} + /// Access to properties Property& ConditionsManager::operator[](const std::string& property_name) const { return access()->properties().property(property_name); } /// Access the conditions loader -ConditionsManager::Loader* ConditionsManager::loader() const { - return access()->loader(); +ConditionsDataLoader& ConditionsManager::loader() const { + return *(access()->loader()); } /// Register new IOV type if it does not (yet) exist. @@ -196,9 +207,9 @@ ConditionsIOVPool* ConditionsManager::iovPool(const IOVType& iov_type) const { const vector<const IOVType*> ConditionsManager::iovTypesUsed() const { Object* obj = access(); vector<const IOVType*> result; - const IOVTypes& types = obj->iovTypes(); - for(IOVTypes::const_iterator i=types.begin(); i!=types.end(); ++i) - if ( int((*i).type) != IOVType::UNKNOWN_IOV ) result.push_back(&(*i)); + const auto& types = obj->iovTypes(); + for(const auto& i : types ) + if ( int(i.type) != IOVType::UNKNOWN_IOV ) result.push_back(&i); return result; } @@ -230,6 +241,11 @@ ConditionsPool* ConditionsManager::registerIOV(const IOVType& typ, IOV::Key key) void ConditionsManager::fromString(const string& iov_str, IOV& iov) const { access()->fromString(iov_str, iov); } + +/// Register a whole block of conditions with identical IOV. +size_t ConditionsManager::blockRegister(ConditionsPool& pool, const std::vector<Condition>& cond) const { + return access()->blockRegister(pool, cond); +} /// Register new condition with the conditions store. Unlocked version, not multi-threaded bool ConditionsManager::registerUnlocked(ConditionsPool& pool, Condition cond) const { @@ -270,3 +286,15 @@ ConditionsManager::Result ConditionsManager::prepare(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx) const { return access()->prepare(req_iov, slice, ctx); } + +/// Load all updates to the clients with the defined IOV (1rst step of prepare) +ConditionsManager::Result +ConditionsManager::load(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx) const { + return access()->load(req_iov, slice, ctx); +} + +/// Compute all derived conditions with the defined IOV (2nd step of prepare) +ConditionsManager::Result +ConditionsManager::compute(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx) const { + return access()->compute(req_iov, slice, ctx); +} diff --git a/DDCond/src/ConditionsSlice.cpp b/DDCond/src/ConditionsSlice.cpp index 5c4f73a0000ff9d6bfc61206bb90d3d7e39b9cd0..4dc18ff4d8f9f02424e15840347b0d219e6e3995 100644 --- a/DDCond/src/ConditionsSlice.cpp +++ b/DDCond/src/ConditionsSlice.cpp @@ -168,7 +168,7 @@ namespace { bool operator()(Condition::Object* c) const { if ( 0 == (c->flags&Condition::DERIVED) ) { #if !defined(DD4HEP_MINIMAL_CONDITIONS) - content.insertKey(c->hash,c->address); + content.addLocation(c->hash,c->address); #endif return true; } diff --git a/DDCond/src/Type1/Manager_Type1.cpp b/DDCond/src/Type1/Manager_Type1.cpp index 4d4f331aa4b95545a4c75f3871bdc35d8810af0e..db17e6f83fcfd04be955c10d2a85b98e791f635d 100644 --- a/DDCond/src/Type1/Manager_Type1.cpp +++ b/DDCond/src/Type1/Manager_Type1.cpp @@ -144,7 +144,7 @@ Manager_Type1::Manager_Type1(Detector& description_instance) declareProperty("PoolType", m_poolType = ""); declareProperty("UpdatePoolType", m_updateType = "DD4hep_ConditionsLinearUpdatePool"); declareProperty("UserPoolType", m_userType = "DD4hep_ConditionsMapUserPool"); - declareProperty("LoaderType", m_loaderType = "multi"); + declareProperty("LoaderType", m_loaderType = "DD4hep_Conditions_multi_Loader"); m_iovTypes.resize(m_maxIOVTypes,IOVType()); m_rawPool.resize(m_maxIOVTypes,0); } @@ -157,7 +157,7 @@ Manager_Type1::~Manager_Type1() { void Manager_Type1::initialize() { if ( !m_updatePool.get() ) { - string typ = "DD4hep_Conditions_"+m_loaderType+"_Loader"; + string typ = m_loaderType; const void* argv_loader[] = {"ConditionsDataLoader", this, 0}; const void* argv_pool[] = {this, 0, 0}; m_loader.reset(createPlugin<ConditionsDataLoader>(typ,m_detDesc,2,argv_loader)); @@ -250,7 +250,9 @@ bool Manager_Type1::registerUnlocked(ConditionsPool& pool, Condition cond) { printout(INFO,"ConditionsMgr","Register condition %016lX %s [%s] IOV:%s", cond->hash, cond.name(), cond->address.c_str(), pool.iov->str().c_str()); #endif - __callListeners(m_onRegister, &ConditionsListener::onRegisterCondition, cond); + if ( !m_onRegister.empty() ) { + __callListeners(m_onRegister, &ConditionsListener::onRegisterCondition, cond); + } return true; } else if ( !cond.isValid() ) @@ -259,6 +261,27 @@ bool Manager_Type1::registerUnlocked(ConditionsPool& pool, Condition cond) { return false; } +/// Register a whole block of conditions with identical IOV. +size_t Manager_Type1::blockRegister(ConditionsPool& pool, const vector<Condition>& cond) const { + size_t result = 0; + for(auto c : cond) { + if ( c.isValid() ) { + c->iov = pool.iov; + c->setFlag(Condition::ACTIVE); + pool.insert(c); + if ( !m_onRegister.empty() ) { + __callListeners(m_onRegister, &ConditionsListener::onRegisterCondition, c); + } + ++result; + continue; + } + except("ConditionsMgr", + "+++ Invalid condition objects may not be registered. [%s]", + Errors::invalidArg().c_str()); + } + return result; +} + /// Set a single conditions value to be managed. /// Requires external lock on update pool! Condition Manager_Type1::__queue_update(cond::Entry* e) { @@ -490,6 +513,28 @@ Manager_Type1::prepare(const IOV& req_iov, ConditionsSlice& slice, ConditionUpda return res; } +/// Load all updates to the clients with the defined IOV (1rst step of prepare) +ConditionsManager::Result +Manager_Type1::load(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx) { + __get_checked_pool(req_iov, slice.pool); + /// First push any pending updates and register them to pending pools... + pushUpdates(); + /// Now update/fill the user pool + Result res = slice.pool->load(req_iov, slice, ctx); + return res; +} + +/// Compute all derived conditions with the defined IOV (2nd step of prepare) +ConditionsManager::Result +Manager_Type1::compute(const IOV& req_iov, ConditionsSlice& slice, ConditionUpdateUserContext* ctx) { + Result res = slice.pool->compute(req_iov, slice, ctx); + /// Invoke auto cleanup if registered + if ( m_cleaner.get() ) { + this->clean(*m_cleaner); + } + return res; +} + /// Create empty user pool object std::unique_ptr<UserPool> Manager_Type1::createUserPool(const IOVType* iovT) const { if ( iovT ) { diff --git a/DDCond/src/plugins/ConditionsMultiLoader.cpp b/DDCond/src/plugins/ConditionsMultiLoader.cpp index d8a2bbd48f775f4fa7dbd77a17a690557866855d..c4ae170b8ea342d1740010d9b30ca3a7337c263d 100644 --- a/DDCond/src/plugins/ConditionsMultiLoader.cpp +++ b/DDCond/src/plugins/ConditionsMultiLoader.cpp @@ -132,7 +132,7 @@ ConditionsMultiLoader::load_source(const std::string& nam, string typ = "DD4hep_Conditions_"+ident+"_Loader"; string fac = ident+"_ConditionsDataLoader"; const void* argv[] = {fac.c_str(), m_mgr.ptr(), 0}; - loader = createPlugin<ConditionsDataLoader>(typ,m_detDesc,2,argv); + loader = createPlugin<ConditionsDataLoader>(typ,m_detector,2,argv); if ( !loader ) { except("ConditionsMultiLoader", "Failed to create conditions loader of type: "+typ+" to read:"+nam); diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp index 826e8a7f05c77ea14cb037a3f8e7c1c8bedcb18e..73acaccb29532669d4babf107c5ac567fa12ca9a 100644 --- a/DDCond/src/plugins/ConditionsUserPool.cpp +++ b/DDCond/src/plugins/ConditionsUserPool.cpp @@ -82,6 +82,10 @@ namespace dd4hep { virtual bool remove(Condition::key_type hash_key) override; /// Remove condition by key from pool. virtual bool remove(const ConditionKey& key) override; + /// Do single insertion of condition including registration to the manager + virtual bool registerOne(const IOV& iov, Condition cond) override; + /// Do block insertions of conditions with identical IOV including registration to the manager + virtual size_t registerMany(const IOV& iov, const std::vector<Condition>& values); /// Register a new condition to this pool virtual bool insert(Condition cond) override; @@ -121,7 +125,8 @@ namespace dd4hep { /// Prepare user pool for usage (load, fill etc.) according to required IOV virtual ConditionsManager::Result load (const IOV& required, - ConditionsSlice& slice); + ConditionsSlice& slice, + ConditionUpdateUserContext* user_param); /// Prepare user pool for usage (load, fill etc.) according to required IOV virtual ConditionsManager::Result compute(const IOV& required, ConditionsSlice& slice, @@ -302,6 +307,43 @@ Condition ConditionsMappedUserPool<MAPPING>::get(const ConditionKey& key) const return i_findCondition(key.hash); } +/// Do block insertions of conditions with identical IOV including registration to the manager +template<typename MAPPING> bool +ConditionsMappedUserPool<MAPPING>::registerOne(const IOV& iov, + Condition cond) { + if ( iov.iovType ) { + ConditionsPool* pool = m_manager.registerIOV(*iov.iovType,iov.keyData); + if ( pool ) { + return m_manager.registerUnlocked(*pool, cond); + } + except("UserPool","++ Failed to register IOV: %s",iov.str().c_str()); + } + except("UserPool","++ Cannot register conditions with invalid IOV."); + return 0; +} + +/// Do block insertions of conditions with identical IOV including registration to the manager +template<typename MAPPING> size_t +ConditionsMappedUserPool<MAPPING>::registerMany(const IOV& iov, + const vector<Condition>& conds) { + if ( iov.iovType ) { + ConditionsPool* pool = m_manager.registerIOV(*iov.iovType,iov.keyData); + if ( pool ) { + size_t result = m_manager.blockRegister(*pool, conds); + if ( result == conds.size() ) { + for(auto c : conds) i_insert(c.ptr()); + return result; + } + except("UserPool","++ Conditions registration was incomplete: " + "registerd only %ld out of %ld conditions.", + result, conds.size()); + } + except("UserPool","++ Failed to register IOV: %s",iov.str().c_str()); + } + except("UserPool","++ Cannot register conditions with invalid IOV."); + return 0; +} + /// Register a new condition to this pool template<typename MAPPING> bool ConditionsMappedUserPool<MAPPING>::insert(Condition cond) { @@ -342,9 +384,13 @@ ConditionsMappedUserPool<MAPPING>::get(DetElement detector, template<typename MAPPING> std::vector<Condition> ConditionsMappedUserPool<MAPPING>::get(Condition::key_type lower, Condition::key_type upper) const { vector<Condition> result; - typename MAPPING::const_iterator first = m_conditions.lower_bound(lower); - for(; first != m_conditions.end() && (*first).first <= upper; ++first ) - result.push_back((*first).second); + if ( !m_conditions.empty() ) { + typename MAPPING::const_iterator first = m_conditions.lower_bound(lower); + for(; first != m_conditions.end(); ++first ) { + result.push_back((*first).second); + if ( (*first).first > upper ) break; + } + } return result; } @@ -529,6 +575,9 @@ ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required, num_load_miss, loaded.size()); if ( do_output_miss ) { copy(begin(load_missing), load_last, inserter(slice_miss_cond, slice_miss_cond.begin())); + for ( const auto& m : slice_miss_cond ) { + printout (ERROR, "TEST", "Unloaded: %s",m.second->toString().c_str()); + } } for_each(loaded.begin(),loaded.end(),Inserter<MAPPING>(m_conditions,&m_iov)); result.loaded = slice_cond.size()-num_load_miss; @@ -542,6 +591,9 @@ ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required, } else if ( do_output_miss ) { copy(begin(cond_missing), last_cond, inserter(slice_miss_cond, slice_miss_cond.begin())); + for ( const auto& m : slice_miss_cond ) { + printout (ERROR, "TEST", "Unloaded: %s",m.second->toString().c_str()); + } } } // @@ -580,8 +632,9 @@ ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required, } template<typename MAPPING> ConditionsManager::Result -ConditionsMappedUserPool<MAPPING>::load(const IOV& required, - ConditionsSlice& slice) +ConditionsMappedUserPool<MAPPING>::load(const IOV& required, + ConditionsSlice& slice, + ConditionUpdateUserContext* /* user_param */) { typedef vector<pair<Condition::key_type,ConditionsLoadInfo*> > CondMissing; const auto& slice_cond = slice.content->conditions(); diff --git a/DDCond/src/plugins/ConditionsXmlLoader.cpp b/DDCond/src/plugins/ConditionsXmlLoader.cpp index 3fe0c8c7d4f3b86d838ea79a48b0c75fc6cc47c5..58392103f087de36f39505a3b87b244e67b83c1f 100644 --- a/DDCond/src/plugins/ConditionsXmlLoader.cpp +++ b/DDCond/src/plugins/ConditionsXmlLoader.cpp @@ -113,8 +113,8 @@ size_t ConditionsXmlLoader::load_source(const std::string& nam, xml::Handle_t handle = doc.root(); ConditionsStack stack; char* argv[] = { (char*)handle.ptr(), (char*)&stack, 0}; - void* result = dd4hep::createPlugin(fac, m_detDesc, 2, argv, 0); - if ( result == &m_detDesc ) { // All OK. + void* result = dd4hep::createPlugin(fac, m_detector, 2, argv, 0); + if ( result == &m_detector ) { // All OK. for (ConditionsStack::iterator c=stack.begin(); c!=stack.end(); ++c) { Entry* e = (*c); Condition condition;/// = queueUpdate(e); diff --git a/DDCore/include/DD4hep/AlignmentsCalculator.h b/DDCore/include/DD4hep/AlignmentsCalculator.h index 3c7b4f7e26b1b96cf794c6914ee5a0d1c872e3a7..5fbe44e819cbe0eefa2872a092a8e8bd49880f27 100644 --- a/DDCore/include/DD4hep/AlignmentsCalculator.h +++ b/DDCore/include/DD4hep/AlignmentsCalculator.h @@ -100,11 +100,14 @@ namespace dd4hep { cond::ConditionUpdateContext& context; /// Collection container OrderedDeltas& deltas; + /// Resulting IOV + IOV* iov = 0; public: /// Default constructor Scanner() = delete; /// Initializing constructor Scanner(cond::ConditionUpdateContext& m, OrderedDeltas& d) : context(m), deltas(d) {} + Scanner(cond::ConditionUpdateContext& m, OrderedDeltas& d, IOV* i) : context(m), deltas(d), iov(i) {} /// Default move constructor is disabled Scanner(cond::ConditionUpdateContext& m, OrderedDeltas&& p) = delete; /// R-value copy from a temporary diff --git a/DDCore/include/DD4hep/ComponentProperties.h b/DDCore/include/DD4hep/ComponentProperties.h index 2bb40d9e659b1ffc9220dba3efa1995a83c6989e..8b8cbf184d6be0910be235b8c57ad1d64e5716a4 100644 --- a/DDCore/include/DD4hep/ComponentProperties.h +++ b/DDCore/include/DD4hep/ComponentProperties.h @@ -253,6 +253,8 @@ namespace dd4hep { virtual ~PropertyInterface() = default; /// Access to the properties of the object virtual PropertyManager& properties() = 0; + /// Access to the properties of the object + virtual const PropertyManager& properties() const = 0; /// Check property for existence virtual bool hasProperty(const std::string& name) const = 0; /// Access single property @@ -280,6 +282,10 @@ namespace dd4hep { virtual PropertyManager& properties() override { return m_properties; } + /// Access to the properties of the object + virtual const PropertyManager& properties() const override { + return m_properties; + } /// Check property for existence virtual bool hasProperty(const std::string& name) const override; /// Access single property diff --git a/DDCore/include/DD4hep/ConditionDerived.h b/DDCore/include/DD4hep/ConditionDerived.h index 781754dbf159f704ce5135bd6b2bb94115a21a49..9f74e21acce290fc45af85f93bf10b80f43d4954 100644 --- a/DDCore/include/DD4hep/ConditionDerived.h +++ b/DDCore/include/DD4hep/ConditionDerived.h @@ -79,6 +79,8 @@ namespace dd4hep { virtual std::vector<Condition> get(DetElement de) = 0; /// Interface to access conditions by hash value of the DetElement (only valid at resolve!) virtual std::vector<Condition> get(Condition::detkey_type key) = 0; + /// Interface to access conditions by hash value of the item (only valid at resolve!) + virtual std::vector<Condition> getByItem(Condition::itemkey_type key) = 0; }; /// ConditionUpdateContext class used by the derived conditions calculation mechanism @@ -141,13 +143,20 @@ namespace dd4hep { return conditions(det.key()); } - /// Access to all conditions of a detector element. + /// Access to all conditions of a detector element key. /** Careful: This limits the validity! * ONLY VALID AT RESOLVE ! * Otherwise the resulting IOV shall be wrong ! */ std::vector<Condition> conditions(Condition::detkey_type det_key) const; + /// Access conditions by the condition item key + /** Careful: This limits the validity! + * ONLY VALID AT RESOLVE ! + * Otherwise the resulting IOV shall be wrong ! + */ + std::vector<Condition> getByItem(Condition::itemkey_type key) const; + /// Access to condition object by dependency key /** Careful: This limits the validity! * ONLY VALID AT RESOLVE ! diff --git a/DDCore/include/DD4hep/DetElement.h b/DDCore/include/DD4hep/DetElement.h index 6f48c68e0a0dd963828ac4b7cbc1301fd64ca1b8..5090ebe74f243bef26956da69f821fce479e5edf 100644 --- a/DDCore/include/DD4hep/DetElement.h +++ b/DDCore/include/DD4hep/DetElement.h @@ -240,6 +240,9 @@ namespace dd4hep { /// Copy/clone the object virtual ExtensionEntry* clone(void* det) const override { return new DetElementExtension<Q,T>((T*)this->copy(det)); } + /// Hash value + virtual unsigned long long int hash64() const override + { return detail::typeHash64<Q>(); } }; /// Internal call to extend the detector element with an arbitrary structure accessible by the type @@ -306,7 +309,7 @@ namespace dd4hep { DetElement clone(const std::string& new_name, int new_id) const; /// Add an extension object to the detector element - void* addExtension(unsigned long long int key,ExtensionEntry* entry) const; + void* addExtension(ExtensionEntry* entry) const; /// Access an existing extension object from the detector element void* extension(unsigned long long int key, bool alert) const; @@ -314,8 +317,7 @@ namespace dd4hep { /// Extend the detector element with an arbitrary structure accessible by the type template <typename IFACE, typename CONCRETE> IFACE* addExtension(CONCRETE* c) const { CallbackSequence::checkTypes(typeid(IFACE), typeid(CONCRETE), dynamic_cast<IFACE*>(c)); - return (IFACE*) this->addExtension(detail::typeHash64<IFACE>(), - new DetElementExtension<IFACE,CONCRETE>(c)); + return (IFACE*) this->addExtension(new DetElementExtension<IFACE,CONCRETE>(c)); } /// Access extension element by the type template <typename IFACE> IFACE* extension() const { diff --git a/DDCore/include/DD4hep/ExtensionEntry.h b/DDCore/include/DD4hep/ExtensionEntry.h index e251a3cb927bbf95f3717a8bc0eaf2d21ed68673..da6275ba1f6a9f84fce0060ccfe5a768a864b15b 100644 --- a/DDCore/include/DD4hep/ExtensionEntry.h +++ b/DDCore/include/DD4hep/ExtensionEntry.h @@ -55,6 +55,8 @@ namespace dd4hep { virtual void destruct() const = 0; /// Virtual entry clone function virtual ExtensionEntry* clone(void* arg) const = 0; + /// Hash value + virtual unsigned long long int hash64() const = 0; }; namespace detail { @@ -97,6 +99,9 @@ namespace dd4hep { /// Virtual entry clone function virtual ExtensionEntry* clone(void*) const override { invalidCall("clone"); return 0; } + /// Hash value + virtual unsigned long long int hash64() const override + { return detail::typeHash64<Q>(); } }; /// Implementation class for the object extension mechanism. @@ -139,6 +144,9 @@ namespace dd4hep { /// Virtual entry clone function virtual ExtensionEntry* clone(void* arg) const override { return new DeleteExtension((T*)this->copy(arg)); } + /// Hash value + virtual unsigned long long int hash64() const override + { return detail::typeHash64<Q>(); } }; /// Implementation class for the object extension mechanism. @@ -181,6 +189,9 @@ namespace dd4hep { /// Virtual entry clone function virtual ExtensionEntry* clone(void* arg) const override { return new CopyDeleteExtension((T*)this->copy(arg)); } + /// Hash value + virtual unsigned long long int hash64() const override + { return detail::typeHash64<Q>(); } }; } // End namespace detail } // End namespace dd4hep diff --git a/DDCore/include/DD4hep/Handle.h b/DDCore/include/DD4hep/Handle.h index d1c9d71fce9c5044429794e05c1a1e1a95d09ac3..7b232c5dc5e85f715036601e42c5cf2c4d57956f 100644 --- a/DDCore/include/DD4hep/Handle.h +++ b/DDCore/include/DD4hep/Handle.h @@ -171,6 +171,8 @@ namespace dd4hep { const char* name() const; /// Assign a new named object. Note: object references must be managed by the user void assign(Object* n, const std::string& nam, const std::string& title); + /// Destroy the underlying object (be careful here: things are not reference counted)! + void destroy(); /// Helper routine called when unrelated types are assigned. static void bad_assignment(const std::type_info& from, const std::type_info& to); }; diff --git a/DDCore/include/DD4hep/IOV.h b/DDCore/include/DD4hep/IOV.h index 7490a1d975c3fa2ed64117e800a777b7a340e4a2..8a39f2e3ea72b73ec8fce2915e0a3377d319170a 100644 --- a/DDCore/include/DD4hep/IOV.h +++ b/DDCore/include/DD4hep/IOV.h @@ -115,7 +115,6 @@ namespace dd4hep { bool is_discrete() const { return keyData.first == keyData.second; } /// Get the local key of the IOV Key key() const { return keyData; } - /// Set discrete IOV value void set(const Key& value); /// Set discrete IOV value @@ -140,6 +139,12 @@ namespace dd4hep { * is fully conained by the caller. */ bool contains(const IOV& iov) const; + /// Conditions key representing eternity + static IOV forever(const IOVType* typ) + { return IOV(typ, Key(MIN_KEY, MAX_KEY)); } + /// Conditions key representing eternity + static Key key_forever() + { return Key(MIN_KEY, MAX_KEY); } /// Check if 2 IOV objects are of the same type static bool same_type(const IOV& iov, const IOV& test) { unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type; diff --git a/DDCore/include/DD4hep/detail/Handle.inl b/DDCore/include/DD4hep/detail/Handle.inl index 6591f7b50125519e9d6b4d6e872be7857f784529..13beb937043cca62f9254238a1f6e915e9eec1c1 100644 --- a/DDCore/include/DD4hep/detail/Handle.inl +++ b/DDCore/include/DD4hep/detail/Handle.inl @@ -45,6 +45,13 @@ namespace dd4hep { invalidHandleError(typeid(T)); return 0; // We have thrown an exception before - does not harm! } + /// Destroy the underlying object (be careful here: things are not reference counted)! + template <typename T> void Handle<T>::destroy() { + if ( this->m_element ) { + delete this->m_element; + this->m_element = 0; + } + } } /* End namespace dd4hep */ diff --git a/DDCore/src/AlignmentsCalculator.cpp b/DDCore/src/AlignmentsCalculator.cpp index b7d4a8d6e344cae4a34e12809235d4784ea47d4c..da95008791d8d6c227142b7c7d4774992c58a0b9 100644 --- a/DDCore/src/AlignmentsCalculator.cpp +++ b/DDCore/src/AlignmentsCalculator.cpp @@ -111,6 +111,7 @@ int AlignmentsCalculator::Scanner::operator()(DetElement de, int) const { if ( c.isValid() ) { const Delta& d = c.get<Delta>(); deltas.insert(std::make_pair(de,&d)); + if ( iov ) iov->iov_intersection(c->iov->key()); } return 1; } diff --git a/DDCore/src/ConditionDerived.cpp b/DDCore/src/ConditionDerived.cpp index 5ad40b3d850ca3d279014a2d7354317afb15013c..88d20de753a3bee34a2be1f9a3f85e293d7050d1 100644 --- a/DDCore/src/ConditionDerived.cpp +++ b/DDCore/src/ConditionDerived.cpp @@ -25,6 +25,22 @@ using namespace dd4hep::cond; ConditionUpdateUserContext::~ConditionUpdateUserContext() { } +/// Access to all conditions of a detector element. Careful: This limits the validity! +std::vector<Condition> ConditionUpdateContext::conditions(Condition::detkey_type det_key) const { + std::vector<Condition> v = resolver->get(det_key); + /// Update result IOV according by and'ing the new iov structure + for(Condition c : v) iov->iov_intersection(c.iov()); + return v; +} + +/// Access conditions by the condition item key +std::vector<Condition> ConditionUpdateContext::getByItem(Condition::itemkey_type item_key) const { + std::vector<Condition> v = resolver->getByItem(item_key); + /// Update result IOV according by and'ing the new iov structure + for(Condition c : v) iov->iov_intersection(c.iov()); + return v; +} + /// Access to condition object by dependency key Condition ConditionUpdateContext::condition(const ConditionKey& key_value) const { Condition c = resolver->get(key_value); @@ -43,16 +59,6 @@ Condition ConditionUpdateContext::condition(const ConditionKey& key_value) cons return Condition(); } -/// Access to all conditions of a detector element. Careful: This limits the validity! -std::vector<Condition> ConditionUpdateContext::conditions(Condition::detkey_type det_key) const { - std::vector<Condition> v = resolver->get(det_key); - for(Condition c : v) { - /// Update result IOV according by and'ing the new iov structure - iov->iov_intersection(c.iov()); - } - return v; -} - /// Access to condition object by dependency key Condition ConditionUpdateContext::condition(Condition::key_type key_value) const { Condition c = resolver->get(key_value); diff --git a/DDCore/src/Conditions.cpp b/DDCore/src/Conditions.cpp index 27f41d821d94f5c007479888a244f747682ff6bd..bc47f1ddc367c2ab0399870c9aed0cb3aadee78e 100644 --- a/DDCore/src/Conditions.cpp +++ b/DDCore/src/Conditions.cpp @@ -274,9 +274,11 @@ string ConditionKey::toString() const { char text[64]; ::snprintf(text,sizeof(text),"%08X-%08X",key.values.det_key, key.values.item_key); #if !defined(DD4HEP_MINIMAL_CONDITIONS) - stringstream str; - str << "(" << name << ") " << text; - return str.str(); + if ( !name.empty() ) { + stringstream str; + str << "(" << name << ") " << text; + return str.str(); + } #endif return text; } diff --git a/DDCore/src/DetElement.cpp b/DDCore/src/DetElement.cpp index 64e48156177041993d08e75e222730a950b05a45..1e4e21ac6e4aa47b140872bb500051807a9fbacc 100644 --- a/DDCore/src/DetElement.cpp +++ b/DDCore/src/DetElement.cpp @@ -64,8 +64,8 @@ DetElement::DetElement(DetElement det_parent, const string& det_name, int det_id } /// Add an extension object to the detector element -void* DetElement::addExtension(unsigned long long int k,ExtensionEntry* e) const { - return access()->addExtension(k,e); +void* DetElement::addExtension(ExtensionEntry* e) const { + return access()->addExtension(e->hash64(), e); } /// Access an existing extension object from the detector element diff --git a/DDCore/src/DetectorData.cpp b/DDCore/src/DetectorData.cpp index cfba9150fefccdfbd4cc6419de23c9f30e349730..0f9958579b74aead169248f5ac2226a037f5efcc 100644 --- a/DDCore/src/DetectorData.cpp +++ b/DDCore/src/DetectorData.cpp @@ -215,7 +215,14 @@ void DetectorData::destroyData(bool destroy_mgr) { destroyHandles(m_display); destroyHandles(m_fields); destroyHandles(m_define); - +#if 0 + for(const auto& d : m_define) { + auto c = d; + std::cout << "Delete " << d.first << std::endl; + //if ( d.first == "world_side" ) continue; + delete d.second.ptr(); + } +#endif destroyHandle(m_volManager); m_properties.clear(); m_trackers.clear(); diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt index bbaa48eb425676fb59cd821424d48af21ebc9194..d1bdbf1a69b23167e4e19821ea384c2b749ad8a4 100644 --- a/examples/ClientTests/CMakeLists.txt +++ b/examples/ClientTests/CMakeLists.txt @@ -172,7 +172,7 @@ dd4hep_add_test_reg( ClientTests_Save_ROOT_MiniTel_LONGTEST # # Test basic shapes by comparing mesh vertices with reference file foreach (test Box Cone ConeSegment Tube ElTube - CutTube Hyperboloid Paraboloid + CutTube Hyperboloid Paraboloid EightPointSolid Polycone PseudoTrap PseudoTrap2 Sphere Torus Trap Trd1 Trd2 TruncatedTube ExtrudedPolygon) dd4hep_add_test_reg( ClientTests_Check_Shape_${test} diff --git a/examples/ClientTests/compact/CheckShape.xml b/examples/ClientTests/compact/CheckShape.xml index f1cd7de9ca943657458cf7d8ee3eeb762a547a71..1ddbc30828a3ea98a22f79f46776f9c2b868d99b 100644 --- a/examples/ClientTests/compact/CheckShape.xml +++ b/examples/ClientTests/compact/CheckShape.xml @@ -43,7 +43,7 @@ <constant name="world_x" value="world_side"/> <constant name="world_y" value="world_side"/> <constant name="world_z" value="world_side"/> - <constant name="CheckShape_create" value="1"/> + <constant name="CheckShape_create" value="0"/> </define> <display> diff --git a/examples/ClientTests/compact/Check_Shape_EightPointSolid.xml b/examples/ClientTests/compact/Check_Shape_EightPointSolid.xml new file mode 100644 index 0000000000000000000000000000000000000000..389ebe44cae49b161859f99465530ed61986c111 --- /dev/null +++ b/examples/ClientTests/compact/Check_Shape_EightPointSolid.xml @@ -0,0 +1,25 @@ +<lccdd> + <includes> + <gdmlFile ref="CheckShape.xml"/> + </includes> + + <detectors> + <detector id="1" name="Shape_EightPointSolid" type="DD4hep_TestShape_Creator"> + <check vis="Shape1_vis"> + <shape type="EightPointSolid" dz="30*cm"> + <vertex x="-30*cm" y="-25*cm"/> + <vertex x="-25*cm" y=" 25*cm"/> + <vertex x=" 5*cm" y=" 25*cm"/> + <vertex x=" 25*cm" y="-25*cm"/> + <vertex x="-28*cm" y="-23*cm"/> + <vertex x="-23*cm" y=" 27*cm"/> + <vertex x="-23*cm" y=" 27*cm"/> + <vertex x=" 13*cm" y="-27*cm"/> + </shape> + <position x="0" y="0" z="0"/> + <rotation x="0" y="0" z="0"/> + </check> + <test type="DD4hep_Mesh_Verifier" ref="${DD4hepExamplesINSTALL}/examples/ClientTests/ref/Ref_EightPointSolid.txt" create="CheckShape_create"/> + </detector> + </detectors> +</lccdd> diff --git a/examples/ClientTests/ref/Ref_EightPointSolid.txt b/examples/ClientTests/ref/Ref_EightPointSolid.txt new file mode 100644 index 0000000000000000000000000000000000000000..5fff71d183e3daa334d2bdc390a64b960f0112c8 --- /dev/null +++ b/examples/ClientTests/ref/Ref_EightPointSolid.txt @@ -0,0 +1,11 @@ +ShapeCheck[0] TGeoArb8 8 Mesh-points: +TGeoArb8 EightPointSolid N(mesh)=8 N(vert)=8 N(seg)=12 N(pols)=6 +TGeoArb8 0 Local ( -30.00, -25.00, -30.00) Global ( -30.00, -25.00, -30.00) +TGeoArb8 1 Local ( -25.00, 25.00, -30.00) Global ( -25.00, 25.00, -30.00) +TGeoArb8 2 Local ( 5.00, 25.00, -30.00) Global ( 5.00, 25.00, -30.00) +TGeoArb8 3 Local ( 25.00, -25.00, -30.00) Global ( 25.00, -25.00, -30.00) +TGeoArb8 4 Local ( -28.00, -23.00, 30.00) Global ( -28.00, -23.00, 30.00) +TGeoArb8 5 Local ( -23.00, 27.00, 30.00) Global ( -23.00, 27.00, 30.00) +TGeoArb8 6 Local ( -23.00, 27.00, 30.00) Global ( -23.00, 27.00, 30.00) +TGeoArb8 7 Local ( 13.00, -27.00, 30.00) Global ( 13.00, -27.00, 30.00) +TGeoArb8 Bounding box: dx= 27.50 dy= 27.00 dz= 30.00 Origin: x= -2.50 y= 0.00 z= 0.00 diff --git a/examples/Conditions/data/manager.xml b/examples/Conditions/data/manager.xml index d0ec45f60b08eb8c2e2810d08f326f761d3291a4..214bdc2084d1a4f494fd134b95ca1d9793d9ce19 100644 --- a/examples/Conditions/data/manager.xml +++ b/examples/Conditions/data/manager.xml @@ -5,7 +5,7 @@ <conditions> <manager> <property name="PoolType" value="DD4hep_ConditionsLinearPool"/> - <property name="LoaderType" value="xml"/> + <property name="LoaderType" value="DD4hep_Conditions_xml_Loader"/> <property name="UserPoolType" value="DD4hep_ConditionsMapUserPool"/> <property name="UpdatePoolType" value="DD4hep_ConditionsLinearUpdatePool"/> </manager> diff --git a/examples/Conditions/src/ConditionExampleObjects.cpp b/examples/Conditions/src/ConditionExampleObjects.cpp index 3b8cec94c5b671ff6b5a2ee5f5d988af2da569eb..28375b0b5e926fb432a676f384cfc83ed779afcb 100644 --- a/examples/Conditions/src/ConditionExampleObjects.cpp +++ b/examples/Conditions/src/ConditionExampleObjects.cpp @@ -149,9 +149,9 @@ int ConditionsDependencyCreator::operator()(DetElement de, int) const { build_3.add(target1); build_3.add(target2); - content.insertDependency(build_1.release()); - content.insertDependency(build_2.release()); - content.insertDependency(build_3.release()); + content.addDependency(build_1.release()); + content.addDependency(build_2.release()); + content.addDependency(build_3.release()); printout(printLevel,"Example","++ Added derived conditions dependencies for %s",de.path().c_str()); return 1; } diff --git a/examples/Conditions/src/ConditionExample_manual.cpp b/examples/Conditions/src/ConditionExample_manual.cpp index 7666223e6a6825d17386b7235aa01c983881fbc6..92c3dc531815ba0af22afd424733ac46995ef5db 100644 --- a/examples/Conditions/src/ConditionExample_manual.cpp +++ b/examples/Conditions/src/ConditionExample_manual.cpp @@ -83,11 +83,11 @@ static int condition_example (Detector& description, int argc, char** argv) { manager["PoolType"] = "DD4hep_ConditionsLinearPool"; manager["UserPoolType"] = "DD4hep_ConditionsMapUserPool"; manager["UpdatePoolType"] = "DD4hep_ConditionsLinearUpdatePool"; - manager["LoaderType"] = "root"; + manager["LoaderType"] = "DD4hep_Conditions_root_Loader"; manager.initialize(); printout(ALWAYS,"Example","Load conditions data from file:%s",conditions.c_str()); - manager.loader()->addSource(conditions); + manager.loader().addSource(conditions); /// Create the container with the desired conditions content and an empty conditions slice shared_ptr<ConditionsContent> content(new ConditionsContent()); diff --git a/examples/Conditions/src/ConditionsTest.cpp b/examples/Conditions/src/ConditionsTest.cpp index 3ec2b174f33ce4c4787d7ffb8b4dd4c8e31bd07d..fdd8d6cff6e31fc7004728013cc8908a6055ea18 100644 --- a/examples/Conditions/src/ConditionsTest.cpp +++ b/examples/Conditions/src/ConditionsTest.cpp @@ -179,7 +179,7 @@ TestEnv::TestEnv(Detector& _description, const string& detector_name) : description(_description), detector(), manager() { manager = ConditionsManager::from(description); - manager["LoaderType"] = "multi"; + manager["LoaderType"] = "DD4hep_Conditions_multi_Loader"; manager["PoolType"] = "DD4hep_ConditionsLinearPool"; manager["UpdatePoolType"] = "DD4hep_ConditionsLinearUpdatePool"; manager["UserPoolType"] = "DD4hep_ConditionsLinearUserPool"; @@ -188,7 +188,7 @@ TestEnv::TestEnv(Detector& _description, const string& detector_name) if ( detector.isValid() ) { pair<bool, const IOVType*> e = manager.registerIOVType(0, "epoch"); pair<bool, const IOVType*> r = manager.registerIOVType(1, "run"); - loader = manager.loader(); + loader = &manager.loader(); if ( e.first && r.first ) { epoch = e.second; run = r.second; diff --git a/examples/DDDB/src/plugins/DDDB2Objects.cpp b/examples/DDDB/src/plugins/DDDB2Objects.cpp index f331aa8f37368a1110e8e0a2d5fb134abe98707e..d21bef5d666071564087e99317e162c69088ce72 100644 --- a/examples/DDDB/src/plugins/DDDB2Objects.cpp +++ b/examples/DDDB/src/plugins/DDDB2Objects.cpp @@ -1034,7 +1034,7 @@ namespace dd4hep { if ( !context->manager.isValid() ) { ConditionsManager manager = ConditionsManager::from(description); manager["PoolType"] = "DD4hep_ConditionsLinearPool"; - manager["LoaderType"] = "dddb"; + manager["LoaderType"] = "DD4hep_Conditions_dddb_Loader"; manager["UserPoolType"] = "DD4hep_ConditionsMapUserPool"; manager["UpdatePoolType"] = "DD4hep_ConditionsLinearUpdatePool"; manager.initialize(); diff --git a/examples/DDDB/src/plugins/DDDBConditionsLoader.cpp b/examples/DDDB/src/plugins/DDDBConditionsLoader.cpp index dbed5c8d952a068eaa4fb024d3ac0251d0ae722c..8c9ea5cbed9189543fdca42d919e01eaeef90c08 100644 --- a/examples/DDDB/src/plugins/DDDBConditionsLoader.cpp +++ b/examples/DDDB/src/plugins/DDDBConditionsLoader.cpp @@ -200,12 +200,12 @@ void DDDBConditionsLoader::loadDocument(xml::UriContextReader& rdr, const string& obj_id) { const void* argv_conddb[] = {&rdr, sys_id.c_str(), obj_id.c_str(), 0}; - long result = load_dddb_conditions_from_uri(m_detDesc, 3, (char**)argv_conddb); + long result = load_dddb_conditions_from_uri(m_detector, 3, (char**)argv_conddb); if ( 0 == result ) { except("DDDB","++ Failed to load conditions from URI:%s",sys_id.c_str()); } const void* argv_dddb[] = {"conditions_only", 0}; - result = dddb_conditions_2_dd4hep(m_detDesc, 1, (char**)argv_dddb); + result = dddb_conditions_2_dd4hep(m_detector, 1, (char**)argv_dddb); if ( 0 == result ) { except("DDDBLoader","++ Failed to process conditions from URI:%s",sys_id.c_str()); } diff --git a/examples/DDDB/src/plugins/DDDBDerivedCondTest.cpp b/examples/DDDB/src/plugins/DDDBDerivedCondTest.cpp index cc005c16a38190c21a65552ba6dfbbb63e5ca991..d9f6b3f043fe0edce8d45541e4a49e4f994c8150 100644 --- a/examples/DDDB/src/plugins/DDDBDerivedCondTest.cpp +++ b/examples/DDDB/src/plugins/DDDBDerivedCondTest.cpp @@ -296,9 +296,9 @@ namespace { build_3.add(target2); printout(m_context.level,m_name,"Build [%ld] cond.deps: %s [%s # %s] -> %016llX", rc.size(), cat->condition.c_str(), de.path().c_str(), cond.name(), cond->hash); - content->insertDependency(build_1.release()); - content->insertDependency(build_2.release()); - content->insertDependency(build_3.release()); + content->addDependency(build_1.release()); + content->addDependency(build_2.release()); + content->addDependency(build_3.release()); } else { // These conditions cannot be handled.... printout(INFO,m_name,"Ignore condition: %s [%s # %s] -> Hash: %016llX Key: %016llX Type: %s", diff --git a/examples/DDDB/src/plugins/DeVeloServiceTest.cpp b/examples/DDDB/src/plugins/DeVeloServiceTest.cpp index d27442c360665b7b100ea9a970bb000d4ee0b3aa..2e233fc07fea2dff32e5a26d5708d6a1fec0ad9a 100644 --- a/examples/DDDB/src/plugins/DeVeloServiceTest.cpp +++ b/examples/DDDB/src/plugins/DeVeloServiceTest.cpp @@ -136,7 +136,7 @@ namespace { { auto first = cont->conditions().lower_bound(lower.hash); for(; first != cont->conditions().end() && (*first).first <= upper.hash; ++first) { - std::unique_ptr<dd4hep::cond::ConditionsLoadInfo> ptr((*first).second->clone()); + dd4hep::cond::ConditionsLoadInfo* ptr = (*first).second->addRef(); m_service->addContent(content, (*first).first, *ptr->data<string>()); } } diff --git a/examples/DDDB/src/plugins/DeVeloTest.cpp b/examples/DDDB/src/plugins/DeVeloTest.cpp index b57108643d18dd1b59aaa369e64886655986eb85..4cc985c0dd141500fb87c133e83a40c35b3acc3d 100644 --- a/examples/DDDB/src/plugins/DeVeloTest.cpp +++ b/examples/DDDB/src/plugins/DeVeloTest.cpp @@ -119,7 +119,7 @@ namespace { new DeAlignmentCall(m_de)); auto* dep = align_builder.release(); dep->target.hash = Keys::alignmentsComputedKey; - m_content->insertDependency(dep); + m_content->addDependency(dep); std::unique_ptr<DeVeloStaticConditionCall> static_update(new DeVeloStaticConditionCall()); for(const auto& e : elts) { @@ -133,25 +133,23 @@ namespace { m_context->detectors.insert(make_pair(det_key,make_pair(de,cat))); { auto first = cont->conditions().lower_bound(lower.hash); - for(; first != cont->conditions().end() && (*first).first <= upper.hash; ++first) { - std::unique_ptr<dd4hep::cond::ConditionsLoadInfo> ptr((*first).second->clone()); - m_content->insertKey((*first).first, ptr); - } + for(; first != cont->conditions().end() && (*first).first <= upper.hash; ++first) + m_content->addLocationInfo((*first).first, (*first).second->addRef()); } { auto first = cont->derived().lower_bound(lower.hash); for(; first != cont->derived().end() && (*first).first <= upper.hash; ++first) - m_content->insertDependency((*first).second); + m_content->addDependency((*first).second); } dd4hep::cond::DependencyBuilder static_builder(de, Keys::staticKey, static_update->addRef()); - m_content->insertDependency(static_builder.release()); + m_content->addDependency(static_builder.release()); dd4hep::cond::ConditionUpdateCall* call = (e.first == m_de) ? new DeVeloConditionCall(de, cat, m_context.get()) : new DeVeloIOVConditionCall(de, cat, m_context.get()); dd4hep::cond::DependencyBuilder iov_builder(de, Keys::deKey, call); - m_content->insertDependency(iov_builder.release()); + m_content->addDependency(iov_builder.release()); } static_update.release()->release(); m_manager.clear(); diff --git a/examples/DDDB/src/plugins/DetService.cpp b/examples/DDDB/src/plugins/DetService.cpp index 0eed20715b7c15c3a846aa007935a4a585ad08dd..2781be532ff9b207d095ea3883ada236eec447d3 100644 --- a/examples/DDDB/src/plugins/DetService.cpp +++ b/examples/DDDB/src/plugins/DetService.cpp @@ -94,7 +94,7 @@ bool DetService::_addContent(Content& content, if ( content ) { for(auto& c : m_openContents) { if ( content == c.second ) { - if ( c.second->insertKey(key, address) ) { + if ( c.second->addLocation(key, address).first ) { return true; } } @@ -149,7 +149,7 @@ void DetService::addContent(Content& content, Dependency* dep) { if ( content && dep ) { for(auto& c : m_openContents) { - if ( content == c.second && c.second->insertDependency(dep) ) { + if ( content == c.second && c.second->addDependency(dep->addRef()).first ) { return; } except("DetService","Attempt to insert dependency with duplicate key.");