diff --git a/DDAlign/src/AlignmentsForward.cpp b/DDAlign/src/AlignmentsForward.cpp index 98a0a8646939743ed9665913b4df0dc6a758c66f..a3f0aac3d654c323ace69cf80970239591609dd4 100644 --- a/DDAlign/src/AlignmentsForward.cpp +++ b/DDAlign/src/AlignmentsForward.cpp @@ -59,7 +59,7 @@ int AlignmentsForward::processElement(DetElement de) { } // // Now add the dependency to the alignmant manager - Conditions::DependencyBuilder b(k, updateCall->addRef(), de); + Conditions::DependencyBuilder b(k, updateCall, de); bool result = alignmentMgr.adoptDependency(b.release()); if ( result ) { printout(printLevel,"AlignForward", diff --git a/DDAlign/src/AlignmentsManager.cpp b/DDAlign/src/AlignmentsManager.cpp index 587002b15ff8703bb8246677478f13b4aa3a98cb..4f05dc6fd9d8164b01d3c50ceac6b2476ea8fc45 100644 --- a/DDAlign/src/AlignmentsManager.cpp +++ b/DDAlign/src/AlignmentsManager.cpp @@ -347,12 +347,12 @@ const AlignmentsManager::Dependencies& AlignmentsManager::knownDependencies() c /// Compute all alignment conditions of the internal dependency list AlignmentsManager::Result AlignmentsManager::compute(Slice& slice) const { Object* o = access(); - return o->compute(*slice.pool(), *(o->dependencies)); + return o->compute(*slice.pool, *(o->dependencies)); } /// Compute all alignment conditions of the specified dependency list AlignmentsManager::Result AlignmentsManager::compute(Slice& slice, const Dependencies& deps) const { - return access()->compute(*slice.pool(), deps); + return access()->compute(*slice.pool, deps); } /// Compute all alignment conditions of the internal dependency list diff --git a/DDAlign/src/AlignmentsRegister.cpp b/DDAlign/src/AlignmentsRegister.cpp index 85778dd5e987009ca61334afc011f4cd21ff56bf..a3fc34b4119689e6a861ad2f29ae6cad546eab59 100644 --- a/DDAlign/src/AlignmentsRegister.cpp +++ b/DDAlign/src/AlignmentsRegister.cpp @@ -77,7 +77,7 @@ int AlignmentsRegister::processElement(DetElement de) { } // // Now add the dependency to the alignmant manager - Conditions::DependencyBuilder b(k, updateCall->addRef(), de); + Conditions::DependencyBuilder b(k, updateCall, de); b.add(Conditions::ConditionKey(cond->name)); bool result = alignmentMgr.adoptDependency(b.release()); if ( result ) { diff --git a/DDCond/include/DDCond/ConditionsAccess.h b/DDCond/include/DDCond/ConditionsAccess.h index 0ec47e9fc270b9f2b22e290e1941a9b23cec7633..f845bd079151a20d07b2f9364362780bd436da83 100644 --- a/DDCond/include/DDCond/ConditionsAccess.h +++ b/DDCond/include/DDCond/ConditionsAccess.h @@ -48,9 +48,7 @@ namespace DD4hep { ConditionsAccess(Object* p) : Handle<Object>(p) {} /// Constructor to assing handle of the same type - ConditionsAccess(const ConditionsAccess& c) - : Handle<Object>(c) { - } + ConditionsAccess(const ConditionsAccess& c) : Handle<Object>(c) {} /// Constructor to be used assigning from different type template <typename Q> ConditionsAccess(const Handle<Q>& e) diff --git a/DDCond/include/DDCond/ConditionsDataLoader.h b/DDCond/include/DDCond/ConditionsDataLoader.h index b8c76aa0a68c9421bee9d3d9cecbf60d89101254..e64ab72ea9f66f7a301e8bb96be726b6aeb4a16d 100644 --- a/DDCond/include/DDCond/ConditionsDataLoader.h +++ b/DDCond/include/DDCond/ConditionsDataLoader.h @@ -32,8 +32,9 @@ namespace DD4hep { // Forward declarations class Entry; - class ConditionsSlice; typedef std::list<Entry*> ConditionsStack; + class ConditionsSlice; + class ConditionsDescriptor; /// Interface for a generic conditions loader /** @@ -50,8 +51,8 @@ namespace DD4hep { typedef Condition::iov_type iov_type; typedef Condition::key_type key_type; - typedef std::map<key_type,Condition> LoadedItems; - typedef std::vector<std::pair<key_type,ConditionsSlice::Entry*> > RequiredItems; + typedef std::map<key_type,Condition> LoadedItems; + typedef std::vector<std::pair<key_type,ConditionsDescriptor*> > RequiredItems; protected: /// Reference to main detector description object diff --git a/DDCond/include/DDCond/ConditionsSlice.h b/DDCond/include/DDCond/ConditionsSlice.h index ec7a88536d0d664238803e26003662a0e1ca6aa8..18fc914fd86955dd2b64990f4c7f04aacd6407bc 100644 --- a/DDCond/include/DDCond/ConditionsSlice.h +++ b/DDCond/include/DDCond/ConditionsSlice.h @@ -34,7 +34,61 @@ namespace DD4hep { // Forward declarations class UserPool; class ConditionsSlice; + class ConditionsDescriptor; + /// Base class for data loading information. + /** + * Must be specialized to fit the needs of the concrete ConditionsDataLoader object. + * + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + */ + class ConditionsLoadInfo { + public: + /// Default destructor. + virtual ~ConditionsLoadInfo(); + virtual const std::type_info& type() const = 0; + virtual const void* ptr() const = 0; + template<typename T> T* data() const { return (T*)ptr(); } + }; + + /// Slice entry class. Describes all information to load a condition. + /** + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + */ + class ConditionsDescriptor { + friend class ConditionsSlice; + private: + int refCount = 0; + public: + ConditionKey key; + ConditionDependency* dependency = 0; + ConditionsLoadInfo* loadinfo = 0; + + // These are mine. Do not even dare to call any of these two! + ConditionsDescriptor* addRef() { ++refCount; return this; } + void release() { if ( --refCount <= 0 ) delete this; } + + private: + /// Default constructor + ConditionsDescriptor() = delete; + /// Default destructor. + virtual ~ConditionsDescriptor(); + /// Copy constructor (special!) + ConditionsDescriptor(const ConditionsDescriptor& copy) = delete; + /// Default assignment operator + ConditionsDescriptor& operator=(const ConditionsDescriptor& copy) = delete; + + protected: + /// Initializing constructor + ConditionsDescriptor(const ConditionKey& k, ConditionsLoadInfo* l); + /// Initializing constructor + ConditionsDescriptor(ConditionDependency* d, ConditionsLoadInfo* l); + }; + /// Conditions slice object. Defines which conditions should be loaded by the ConditionsManager. /** * Object contains set of required conditions keys to be loaded to the user pool. @@ -53,29 +107,15 @@ namespace DD4hep { class ConditionsSlice { public: - /// Base class for data loading information. - /** - * Must be specialized to fit the needs of the concrete ConditionsDataLoader object. - * - * \author M.Frank - * \version 1.0 - * \date 31/03/2016 - */ - struct Info { - /// Default destructor. - virtual ~Info(); - virtual const std::type_info& type() const = 0; - virtual const void* ptr() const = 0; - template<typename T> T* data() const { return (T*)ptr(); } - }; - + typedef ConditionsDescriptor Descriptor; + /// Concrete class for data loading information. /** * \author M.Frank * \version 1.0 * \date 31/03/2016 */ - template <typename T> struct LoadInfo : public Info { + template <typename T> struct LoadInfo : public ConditionsLoadInfo { T info; LoadInfo() = default; LoadInfo(const T& i) : info(i) {} @@ -89,36 +129,15 @@ namespace DD4hep { }; template <typename T> static LoadInfo<T> loadInfo(const T& t) { return LoadInfo<T>(t); } - - /// Slice entry class. Describes all information to load a condition. - /** - * \author M.Frank - * \version 1.0 - * \date 31/03/2016 - */ - struct Entry { - friend class ConditionsSlice; - private: - /// Default assignment operator - Entry& operator=(const Entry& copy) = delete; - /// Copy constructor (special!) - Entry(const Entry& copy, Info* l); - protected: - public: - ConditionKey key; - ConditionDependency* dependency = 0; - Condition::mask_type mask = 0; - Info* loadinfo = 0; - /// Default constructor - Entry() = default; - /// Initializing constructor - Entry(const ConditionKey& k, Info* l); - /// Default destructor. - virtual ~Entry(); - /// Clone the entry - virtual Entry* clone(); + struct NoLoadInfo : public ConditionsLoadInfo { + NoLoadInfo() = default; + NoLoadInfo(const NoLoadInfo& i) = default; + virtual ~NoLoadInfo() = default; + NoLoadInfo& operator=(const NoLoadInfo& copy) = default; + virtual const std::type_info& type() const { return typeid(void); } + virtual const void* ptr() const { return 0; } }; - + /// Concrete slice entry class. Includes the load information /** * T must be specialized and must @@ -127,67 +146,56 @@ namespace DD4hep { * \version 1.0 * \date 31/03/2016 */ - template <typename T> class ConditionsLoaderEntry : public Entry, public T + template <typename T> class ConditionsLoaderDescriptor : public Descriptor, public T { friend class ConditionsSlice; /// No default constructor - ConditionsLoaderEntry() = delete; + ConditionsLoaderDescriptor() = delete; /// Default assignment operator - ConditionsLoaderEntry& operator=(const ConditionsLoaderEntry& copy) = delete; + ConditionsLoaderDescriptor& operator=(const ConditionsLoaderDescriptor& copy) = delete; /// Copy constructor - ConditionsLoaderEntry(const ConditionsLoaderEntry& copy) - : Entry(copy, this), T(copy) { } + ConditionsLoaderDescriptor(const ConditionsLoaderDescriptor& copy) = delete; + private: /// Initializing constructor - ConditionsLoaderEntry(const ConditionKey& k, const T& d) - : Entry(k, this), T(d) { } - virtual ~ConditionsLoaderEntry() = default; - virtual Entry* clone() { return new ConditionsLoaderEntry(*this); } + ConditionsLoaderDescriptor(const ConditionKey& k, const T& d) + : Descriptor(k, this), T(d) { } + virtual ~ConditionsLoaderDescriptor() = default; virtual const void* data() const { return (T*)this; } }; - typedef Condition::key_type key_type; - typedef ConditionDependency Dependency; - typedef ConditionsDependencyCollection Dependencies; - typedef std::map<key_type,Entry*> ConditionsProxy; - + typedef Condition::key_type key_type; + typedef ConditionDependency Dependency; + typedef std::map<key_type,Descriptor*> ConditionsProxy; + public: /// Reference to the conditions manager. /** Not used by the object, simple for convenience. - * Then all actora are lumped together. + * Then all actors are lumped together, which are used by the client code. */ ConditionsManager manager; + /// Reference to the user pool managing all conditions of this slice + dd4hep_ptr<UserPool> pool; protected: - /// Reference to the user pool - dd4hep_ptr<UserPool> m_pool; ConditionsProxy m_conditions; ConditionsProxy m_derived; - Dependencies m_dependencies; - IOV m_iov; + /// Default assignment operator ConditionsSlice& operator=(const ConditionsSlice& copy) = delete; /// Add a new conditions entry - bool insert_condition(Entry* entry); + bool insert_condition(Descriptor* entry); public: /// Default constructor - ConditionsSlice() : manager(), m_iov(0) {} + ConditionsSlice() = delete; /// Initializing constructor - ConditionsSlice(ConditionsManager m, const IOV& value) : manager(m), m_iov(value) {} + ConditionsSlice(ConditionsManager m); /// Copy constructor (Special, partial copy only. Hence no assignment!) ConditionsSlice(const ConditionsSlice& copy); /// Default destructor. virtual ~ConditionsSlice(); - /// Required IOV - const IOV& iov() const { return m_iov; } - /// Set a new IOV - void setNewIOV(const IOV& value) { m_iov = value; } - /// Access the user condition pool - dd4hep_ptr<UserPool>& pool() { return m_pool; } - /// Access dependency list - const Dependencies& dependencies() const { return m_dependencies; } /// Access to the real condition entries to be loaded const ConditionsProxy& conditions() const { return m_conditions; } /// Access to the derived condition entries to be computed @@ -199,12 +207,19 @@ namespace DD4hep { /// Clear the conditions access and the user pool. void reset(); /// Add a new conditions dependency collection - void insert(const Dependencies& deps); + void insert(const ConditionsDependencyCollection& deps); /// Add a new shared conditions dependency bool insert(Dependency* dependency); + /// Create slice entry for external usage + template <typename T> static + Descriptor* createDescriptor(const ConditionKey& key, const T& loadinfo) { + Descriptor* e = new ConditionsLoaderDescriptor<T>(key,loadinfo); + return e; + } /// Add a new conditions key. T must inherot from class ConditionsSlice::Info - template <typename T=Info> bool insert(const ConditionKey& key, const T& loadinfo) { - Entry* e = new ConditionsLoaderEntry<T>(key,loadinfo); + template <typename T> + bool insert(const ConditionKey& key, const T& loadinfo) { + Descriptor* e = new ConditionsLoaderDescriptor<T>(key,loadinfo); return insert_condition(e); } }; diff --git a/DDCond/include/DDCond/Type1/Manager_Type1.h b/DDCond/include/DDCond/Type1/Manager_Type1.h index 46b7533ed46dc07876c722ff97c19c19a2966b0e..140cb64f42b9a0fa65030d755ee94c0db3b130a5 100644 --- a/DDCond/include/DDCond/Type1/Manager_Type1.h +++ b/DDCond/include/DDCond/Type1/Manager_Type1.h @@ -117,45 +117,45 @@ namespace DD4hep { /** Returns (false,pointer) if IOV existed and * (true,pointer) if new IOV was registered to the manager. */ - virtual std::pair<bool, const IOVType*> registerIOVType(size_t iov_type, const std::string& iov_name); + virtual std::pair<bool, const IOVType*> registerIOVType(size_t iov_type, const std::string& iov_name) final; /// Access IOV by its type - virtual const IOVTypes& iovTypes () const { return m_iovTypes; } + virtual const IOVTypes& iovTypes () const final { return m_iovTypes; } /// Access IOV by its type - virtual const IOVType* iovType (size_t iov_type) const; + virtual const IOVType* iovType (size_t iov_type) const final; /// Access IOV by its name - virtual const IOVType* iovType (const std::string& iov_name) const; + virtual const IOVType* iovType (const std::string& iov_name) const final; /// Register IOV with type and key - virtual ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key); + virtual ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key) final; /// Access conditions multi IOV pool by iov type - ConditionsIOVPool* iovPool(const IOVType& type) const; + ConditionsIOVPool* iovPool(const IOVType& type) const final; /// Register new condition with the conditions store. Unlocked version, not multi-threaded - virtual bool registerUnlocked(ConditionsPool* pool, Condition cond); + virtual bool registerUnlocked(ConditionsPool* pool, Condition cond) final; /// Clean conditions, which are above the age limit. /** @return Number of conditions cleaned/removed from the IOV pool of the given type */ - int clean(const IOVType* typ, int max_age); + int clean(const IOVType* typ, int max_age) final; /// Full cleanup of all managed conditions. /** @return pair<Number of pools cleared, Number of conditions cleaned up and removed> */ - std::pair<int,int> clear(); + std::pair<int,int> clear() final; /// Push all pending updates to the conditions store. /** Note: * This does not yet make the new conditions availible to the clients */ - virtual void pushUpdates(); + virtual void pushUpdates() final; /// Retrieve a condition set given a Detector Element and the conditions name according to their validity (deprecated) - virtual Condition get(key_type key, const iov_type& req_validity); + virtual Condition get(key_type key, const iov_type& req_validity) final; /// Retrieve a condition given a Detector Element and the conditions name (deprecated) - virtual RangeConditions getRange(key_type key, const iov_type& req_validity); + virtual RangeConditions getRange(key_type key, const iov_type& req_validity) final; /// Prepare all updates for the given keys to the clients with the defined IOV /** @@ -164,7 +164,7 @@ namespace DD4hep { * * @return */ - Result prepare(const IOV& req_iov, ConditionsSlice& slice); + Result prepare(const IOV& req_iov, ConditionsSlice& slice) final; }; } /* End namespace Conditions */ diff --git a/DDCond/src/ConditionsSlice.cpp b/DDCond/src/ConditionsSlice.cpp index 6782f902c06fc0f1e14d88bb8d555d69c93d6020..8e71f67b7b9ffc5fe676bd32bacd2d15f19ce05b 100644 --- a/DDCond/src/ConditionsSlice.cpp +++ b/DDCond/src/ConditionsSlice.cpp @@ -14,107 +14,100 @@ // Framework include files #include "DDCond/ConditionsSlice.h" #include "DDCond/ConditionsIOVPool.h" +#include "DD4hep/InstanceCount.h" #include "DD4hep/Printout.h" using namespace DD4hep::Conditions; /// Default destructor. -ConditionsSlice::Info::~Info() { -} - -/// Copy constructor (special!) -ConditionsSlice::Entry::Entry(const Entry& copy, Info* l) - : key(copy.key), loadinfo(l) -{ - if ( copy.dependency ) dependency = copy.dependency->addRef(); +ConditionsLoadInfo::~ConditionsLoadInfo() { } /// Initializing constructor -ConditionsSlice::Entry::Entry(const ConditionKey& k, Info* l) +ConditionsDescriptor::ConditionsDescriptor(const ConditionKey& k, ConditionsLoadInfo* l) : key(k), loadinfo(l) { + InstanceCount::increment(this); } -/// Clone the entry -ConditionsSlice::Entry* ConditionsSlice::Entry::clone() { - Entry* e = new Entry(*this); - return e; +/// Initializing constructor +ConditionsDescriptor::ConditionsDescriptor(ConditionDependency* dep, ConditionsLoadInfo* l) + : key(dep->target), dependency(dep->addRef()), loadinfo(l) +{ + InstanceCount::increment(this); } /// Default destructor. -ConditionsSlice::Entry::~Entry() { +ConditionsDescriptor::~ConditionsDescriptor() { releasePtr(dependency); + InstanceCount::decrement(this); +} + +/// Initializing constructor +ConditionsSlice::ConditionsSlice(ConditionsManager m) : manager(m) +{ + InstanceCount::increment(this); } /// Copy constructor (Special, partial copy only. Hence no assignment!) ConditionsSlice::ConditionsSlice(const ConditionsSlice& copy) - : manager(copy.manager), m_iov(copy.m_iov.iovType) + : manager(copy.manager) { + InstanceCount::increment(this); for(const auto& c : copy.m_conditions ) { - Entry* e = new Entry(*c.second); + Descriptor* e = c.second->addRef(); m_conditions.insert(std::make_pair(e->key.hash,e)); } for(const auto& c : copy.m_derived ) { - Entry* e = new Entry(*c.second); - if ( m_derived.insert(std::make_pair(e->key.hash,e)).second ) { - if ( e->dependency ) m_dependencies.insert(e->dependency); - } + Descriptor* e = c.second->addRef(); + m_derived.insert(std::make_pair(e->key.hash,e)); } } /// Default destructor. ConditionsSlice::~ConditionsSlice() { - destroyObjects(m_conditions); - destroyObjects(m_derived); - m_dependencies.clear(); + releaseObjects(m_conditions); + releaseObjects(m_derived); + InstanceCount::decrement(this); } /// Clear the container. Destroys the contained stuff void ConditionsSlice::clear() { - destroyObjects(m_conditions); - destroyObjects(m_derived); - m_dependencies.clear(); + releaseObjects(m_conditions); + releaseObjects(m_derived); } /// Clear the conditions access and the user pool. void ConditionsSlice::reset() { - //for(const auto& e : m_conditions ) e.second->condition = 0; - //for(const auto& e : m_derived ) e.second->condition = 0; - if ( pool().get() ) pool()->clear(); - m_iov.reset(); + if ( pool.get() ) pool->clear(); } /// Add a new conditions dependency collection -void ConditionsSlice::insert(const Dependencies& deps) { - for ( const auto& d : deps ) insert(d.second.get()); +void ConditionsSlice::insert(const ConditionsDependencyCollection& deps) { + for ( const auto& d : deps ) this->insert(d.second.get()); } /// Add a new conditions dependency (shared) bool ConditionsSlice::insert(Dependency* dependency) { - Entry* entry = new Entry(); - entry->dependency = dependency->addRef(); - entry->mask |= Condition::DERIVED; - entry->key = entry->dependency->target; - if ( m_derived.insert(std::make_pair(entry->key.hash,entry)).second ) { - if ( entry->dependency ) m_dependencies.insert(entry->dependency); + Descriptor* entry = new Descriptor(dependency,0); + if ( m_derived.insert(std::make_pair(entry->key.hash,entry->addRef())).second ) { return true; } - deletePtr(entry); + delete entry; return false; } /// Add a new entry -bool ConditionsSlice::insert_condition(Entry* entry) { +bool ConditionsSlice::insert_condition(Descriptor* entry) { if ( entry->dependency ) { // ERROR: This call should not be invoked for derivatives! DD4hep::except("ConditionsSlice", "insert_condition: Bad invokation. No dependency allowed here!"); } - - if ( m_conditions.insert(std::make_pair(entry->key.hash,entry)).second ) { + if ( m_conditions.insert(std::make_pair(entry->key.hash,entry->addRef())).second ) { return true; } - deletePtr(entry); + releasePtr(entry); return false; } @@ -149,7 +142,7 @@ namespace { /// Populate the conditions slice from the conditions manager (convenience) ConditionsSlice* DD4hep::Conditions::createSlice(ConditionsManager mgr, const IOVType& typ) { - dd4hep_ptr<ConditionsSlice> slice(new ConditionsSlice(mgr, IOV(&typ))); + dd4hep_ptr<ConditionsSlice> slice(new ConditionsSlice(mgr)); Conditions::ConditionsIOVPool* iovPool = mgr.iovPool(typ); Conditions::ConditionsIOVPool::Elements& pools = iovPool->elements; for_each(begin(pools),end(pools),SliceOper(slice.get())); diff --git a/DDCond/src/Type1/Manager_Type1.cpp b/DDCond/src/Type1/Manager_Type1.cpp index 193ec54345b14fcb0cc2a6219e5dd34f66188751..e7cc94d03dd26c852f83bff10cc91d429310603f 100644 --- a/DDCond/src/Type1/Manager_Type1.cpp +++ b/DDCond/src/Type1/Manager_Type1.cpp @@ -461,10 +461,9 @@ Manager_Type1::getRange(Condition::key_type key, const Condition::iov_type& iov) ConditionsManager::Result Manager_Type1::prepare(const IOV& req_iov, ConditionsSlice& slice) { - dd4hep_ptr<UserPool>& up = slice.pool(); - __get_checked_pool(req_iov, up); + __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 - return up->prepare(req_iov, slice); + return slice.pool->prepare(req_iov, slice); } diff --git a/DDCond/src/plugins/ConditionsLinearPool.cpp b/DDCond/src/plugins/ConditionsLinearPool.cpp index 7e1e0b5bb477ee941d01a65acd653e0709a75c24..9df3a4c902bbe3ef4e16e58d542a099a4d092b9f 100644 --- a/DDCond/src/plugins/ConditionsLinearPool.cpp +++ b/DDCond/src/plugins/ConditionsLinearPool.cpp @@ -63,44 +63,44 @@ namespace DD4hep { virtual ~ConditionsLinearPool(); /// Total entry count - virtual size_t size() const { + virtual size_t size() const final { return m_entries.size(); } /// Full cleanup of all managed conditions. - virtual void clear() { + virtual void clear() final { for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this)); m_entries.clear(); } /// Check if a condition exists in the pool - virtual Condition exists(Condition::key_type key) const { + virtual Condition exists(Condition::key_type key) const final { auto i = find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key)); return i==m_entries.end() ? Condition() : (*i); } /// Register a new condition to this pool - virtual bool insert(Condition condition) + virtual bool insert(Condition condition) final { m_entries.insert(m_entries.end(),condition.access()); return true; } /// Register a new condition to this pool. May overload for performance reasons. - virtual void insert(RangeConditions& rc) + virtual void insert(RangeConditions& rc) final { for_each(rc.begin(), rc.end(), Operators::sequenceSelect(m_entries)); } /// Select the conditions matching the DetElement and the conditions name - virtual size_t select(Condition::key_type key, RangeConditions& result) + virtual size_t select(Condition::key_type key, RangeConditions& result) final { return loop(result, Operators::keyedSelect(key, result)); } /// Select the conditons, used also by the DetElement of the condition - virtual size_t select_all(const ConditionsSelect& result) + virtual size_t select_all(const ConditionsSelect& result) final { return loop(result, Operators::operatorWrapper(result)); } /// Select the conditons, used also by the DetElement of the condition - virtual size_t select_all(RangeConditions& result) + virtual size_t select_all(RangeConditions& result) final { return loop(result, Operators::sequenceSelect(result)); } /// Select the conditons, used also by the DetElement of the condition - virtual size_t select_all(ConditionsPool& result) + virtual size_t select_all(ConditionsPool& result) final { return loop(result, Operators::poolSelect(result)); } }; @@ -126,7 +126,7 @@ namespace DD4hep { virtual ~ConditionsLinearUpdatePool() {} /// Adopt all entries sorted by IOV. Entries will be removed from the pool - virtual size_t popEntries(UpdatePool::UpdateEntries& entries) { + virtual size_t popEntries(UpdatePool::UpdateEntries& entries) final { MAPPING& m = this->ConditionsLinearPool<MAPPING,BASE>::m_entries; size_t len = entries.size(); if ( !m.empty() ) { @@ -142,7 +142,7 @@ namespace DD4hep { /// Select the conditions matching the DetElement and the conditions name virtual void select_range(Condition::key_type key, const Condition::iov_type& req, - RangeConditions& result) + RangeConditions& result) final { MAPPING& m = this->ConditionsLinearPool<MAPPING,BASE>::m_entries; if ( !m.empty() ) { diff --git a/DDCond/src/plugins/ConditionsMappedPool.cpp b/DDCond/src/plugins/ConditionsMappedPool.cpp index 40ffdf6637873903b785c91c36295f6da6bcc873..81108b7496e24e9c1e597eba4fde98d76505c6e8 100644 --- a/DDCond/src/plugins/ConditionsMappedPool.cpp +++ b/DDCond/src/plugins/ConditionsMappedPool.cpp @@ -68,12 +68,12 @@ namespace DD4hep { virtual ~ConditionsMappedPool(); /// Total entry count - virtual size_t size() const { + virtual size_t size() const final { return m_entries.size(); } /// Register a new condition to this pool - virtual bool insert(Condition condition) { + virtual bool insert(Condition condition) final { Condition::Object* c = condition.access(); bool result = m_entries.insert(std::make_pair(c->hash,c)).second; if ( result ) return true; @@ -86,7 +86,7 @@ namespace DD4hep { } /// Register a new condition to this pool. May overload for performance reasons. - virtual void insert(RangeConditions& new_entries) { + virtual void insert(RangeConditions& new_entries) final { Condition::Object* o; for( Condition c : new_entries ) { o = c.access(); @@ -95,31 +95,31 @@ namespace DD4hep { } /// Full cleanup of all managed conditions. - virtual void clear() { + virtual void clear() final { for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this)); m_entries.clear(); } /// Check if a condition exists in the pool - virtual Condition exists(Condition::key_type key) const { + virtual Condition exists(Condition::key_type key) const final { auto i=find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key)); return i==m_entries.end() ? Condition() : (*i).second; } /// Select the conditions matching the DetElement and the conditions name - virtual size_t select(Condition::key_type key, RangeConditions& result) + virtual size_t select(Condition::key_type key, RangeConditions& result) final { return loop(result, Operators::keyedSelect(key,result)); } /// Select the conditons, used also by the DetElement of the condition - virtual size_t select_all(const ConditionsSelect& result) + virtual size_t select_all(const ConditionsSelect& result) final { return loop(result, Operators::operatorWrapper(result)); } /// Select the conditons, used also by the DetElement of the condition - virtual size_t select_all(RangeConditions& result) + virtual size_t select_all(RangeConditions& result) final { return loop(result, Operators::sequenceSelect(result)); } /// Select the conditons, used also by the DetElement of the condition - virtual size_t select_all(ConditionsPool& result) + virtual size_t select_all(ConditionsPool& result) final { return loop(result, Operators::poolSelect(result)); } }; @@ -145,29 +145,16 @@ namespace DD4hep { virtual ~ConditionsMappedUpdatePool() { } /// Adopt all entries sorted by IOV. Entries will be removed from the pool - virtual size_t popEntries(UpdatePool::UpdateEntries& entries) { + virtual size_t popEntries(UpdatePool::UpdateEntries& entries) final { ClearOnReturn<MAPPING> clr(this->Self::m_entries); return this->Self::loop(entries, [&entries](const std::pair<key_type,Condition::Object*>& o) { entries[o.second->iov].push_back(Condition(o.second));}); -#if 0 - MAPPING& m = this->ConditionsMappedPool<MAPPING,BASE>::m_entries; - size_t len = entries.size(); - size_t len = m.size(); - if ( !m.empty() ) { - for(typename MAPPING::iterator i=m.begin(); i!=m.end(); ++i) { - Condition::Object* o = (*i).second; - entries[o->iov].push_back(Condition(o)); - } - m.clear(); - } - return len; -#endif } /// Select the conditions matching the DetElement and the conditions name virtual void select_range(Condition::key_type key, const Condition::iov_type& req, - RangeConditions& result) + RangeConditions& result) final { //return this->Self::loop(entries, [&entries](const std::pair<key_type,Condition::Object*>& o) { // entries[o.second->iov].push_back(Condition(o.second));}); diff --git a/DDCond/src/plugins/ConditionsParser.cpp b/DDCond/src/plugins/ConditionsParser.cpp index 921a6be8af4373213e89c6fb62e67ab2937f3f95..9e139413034d6d7b7344bfd349cad65f682759bb 100644 --- a/DDCond/src/plugins/ConditionsParser.cpp +++ b/DDCond/src/plugins/ConditionsParser.cpp @@ -64,6 +64,7 @@ using Geometry::DetElement; namespace DD4hep { + struct ConversionArg { DetElement detector; ConditionsStack* stack; diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index 2e1c787f0c8ac50b27a6915d33cb4a0c5f03c74d..2be2c2d7e97992248263d186f9ba9814df748bf7 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -257,11 +257,11 @@ static int ddcond_detelement_dump(LCDD& lcdd, int argc, char** argv) { } } actor; dd4hep_ptr<ConditionsSlice> slice(ddcond_prepare(lcdd,"run",1500,argc,argv)); - UserPool* pool = slice->pool().get(); + UserPool* pool = slice->pool.get(); pool->print("User pool"); actor.printer.setPool(pool); int ret = actor.process(lcdd.world(),0,true); - slice->manager.clean(slice->iov().iovType, 20); + slice->manager.clean(pool->validity().iovType, 20); return ret; } DECLARE_APPLY(DD4hep_DetElementConditionsDump,ddcond_detelement_dump) @@ -277,7 +277,7 @@ DECLARE_APPLY(DD4hep_DetElementConditionsDump,ddcond_detelement_dump) */ static void* ddcond_prepare_plugin(LCDD& lcdd, int argc, char** argv) { dd4hep_ptr<ConditionsSlice> slice(ddcond_prepare(lcdd,"",-1,argc,argv)); - UserPool* p = slice->pool().get(); + UserPool* p = slice->pool.get(); return p && p->size() > 0 ? slice.release() : 0; } DECLARE_LCDD_CONSTRUCTOR(DD4hep_ConditionsPrepare,ddcond_prepare_plugin) @@ -318,7 +318,7 @@ static int ddcond_detelement_processor(LCDD& lcdd, int argc, char** argv) { processor = createProcessor<ConditionsProcessor>(lcdd, 2, (char**)args); } dd4hep_ptr<ConditionsSlice> slice(ddcond_prepare(lcdd,"run",1500,argc,argv)); - UserPool* pool = slice->pool().get(); + UserPool* pool = slice->pool.get(); Actor actor(processor); pool->print("User pool"); processor->setPool(pool); @@ -342,7 +342,7 @@ static long ddcond_synchronize_conditions(lcdd_t& lcdd, int argc, char** argv) { string iov_typ = argv[0]; IOV::Key::first_type iov_key = *(IOV::Key::first_type*)argv[1]; dd4hep_ptr<ConditionsSlice> slice(ddcond_prepare(lcdd,iov_typ,iov_key,argc,argv)); - UserPool* pool = slice->pool().get(); + UserPool* pool = slice->pool.get(); pool->print("User pool"); slice->manager.clean(pool->validity().iovType, 20); pool->clear(); diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp index 75b7716ddae4969f8c522c643e3ef7a80aa18470..6ba4e8ca945121ebd67339fc358f6309527be6ea 100644 --- a/DDCond/src/plugins/ConditionsUserPool.cpp +++ b/DDCond/src/plugins/ConditionsUserPool.cpp @@ -125,6 +125,8 @@ namespace DD4hep { #include "DDCond/ConditionsManagerObject.h" #include "DDCond/ConditionsDependencyHandler.h" +#include <mutex> + using namespace std; using namespace DD4hep; using namespace DD4hep::Conditions; @@ -309,19 +311,14 @@ size_t ConditionsMappedUserPool<MAPPING>::compute(const Dependencies& deps, return num_updates; } -typedef ConditionsSlice::Entry SliceEntry; namespace { struct COMP { - typedef pair<Condition::key_type,SliceEntry*> Slice; + typedef pair<Condition::key_type,ConditionsDescriptor*> Slice; typedef pair<Condition::key_type,Condition> Cond; - bool operator()(const Slice& a,const Cond& b) const - { return a.first < b.first; } - bool operator()(const Cond& a,const Slice& b) const - { return a.first < b.first; } + bool operator()(const Slice& a,const Cond& b) const { return a.first < b.first; } + bool operator()(const Cond& a,const Slice& b) const { return a.first < b.first; } }; - //bool _compare(const pair<const Condition::key_type,void*>& a,const pair<const Condition::key_type,void*>& b) - //{ return a.first < b.first; } - pair<Condition::key_type,ConditionDependency*> _to_dep(pair<Condition::key_type,SliceEntry*>& e) + pair<Condition::key_type,ConditionDependency*> _to_dep(pair<Condition::key_type,ConditionsDescriptor*>& e) { return make_pair(e.second->key.hash,e.second->dependency); } } @@ -330,14 +327,18 @@ ConditionsMappedUserPool<MAPPING>::prepare_VSN_1(const IOV& require ConditionsSlice& slice, void* user_param) { - //typedef std::set<pair<Condition::key_type,SliceEntry*> > _Missing; - typedef std::vector<pair<Condition::key_type,SliceEntry*> > _Missing; - //typedef ConditionsDataLoader::RequiredItems _Missing; + typedef std::vector<pair<Condition::key_type,ConditionsDescriptor*> > _Missing; const auto& slice_cond = slice.conditions(); const auto& slice_calc = slice.derived(); IOV pool_iov(required.iovType); Result result; + // This is a critical operation, because we have to ensure the + // IOV pools are ONLY manipulated by the current thread. + // Otherwise the selection and the population are unsafe! + static mutex lock; + lock_guard<mutex> guard(lock); + m_conditions.clear(); pool_iov.reset().invert(); m_iovPool->select(required, Operators::mapConditionsSelect(m_conditions), pool_iov); diff --git a/DDCore/include/DD4hep/AlignedVolumePrinter.h b/DDCore/include/DD4hep/AlignedVolumePrinter.h index 9557a68fe73e656b499bf5028fd2c0aa5647406e..10d08f688b1849a5fa7b43a1b0d4f9b83a4d66c7 100644 --- a/DDCore/include/DD4hep/AlignedVolumePrinter.h +++ b/DDCore/include/DD4hep/AlignedVolumePrinter.h @@ -58,11 +58,11 @@ namespace DD4hep { /// Set prefix for printouts void setPrefix(const std::string& value) { prefix = value; } /// Callback to output alignments information - virtual int operator()(Alignment cond); + virtual int operator()(Alignment cond) override; /// Container callback for object processing - virtual int operator()(Container container); + virtual int operator()(Container container) override; /// Callback to output alignments information of an entire DetElement - virtual int processElement(DetElement de); + virtual int processElement(DetElement de) override; }; } /* End namespace Alignments */ } /* End namespace DD4hep */ diff --git a/DDCore/include/DD4hep/AlignmentsPrinter.h b/DDCore/include/DD4hep/AlignmentsPrinter.h index aced8404d673ea1bfd45faa877771fdbfbab4bcf..f12f920664ff235d5ff481fd2dc58f6d9c57e86e 100644 --- a/DDCore/include/DD4hep/AlignmentsPrinter.h +++ b/DDCore/include/DD4hep/AlignmentsPrinter.h @@ -58,11 +58,11 @@ namespace DD4hep { /// Set prefix for printouts void setPrefix(const std::string& value) { prefix = value; } /// Callback to output alignments information - virtual int operator()(Alignment cond); + virtual int operator()(Alignment cond) override; /// Container callback for object processing - virtual int operator()(Container container); + virtual int operator()(Container container) override; /// Callback to output alignments information of an entire DetElement - virtual int processElement(DetElement de); + virtual int processElement(DetElement de) override; }; /// Default printout of an alignment entry diff --git a/DDCore/include/DD4hep/AlignmentsProcessor.h b/DDCore/include/DD4hep/AlignmentsProcessor.h index 6f811ccfa51dfaa227d516412f5d712fe4178043..526d614083c344f87d32e7a05728f41eda509f8a 100644 --- a/DDCore/include/DD4hep/AlignmentsProcessor.h +++ b/DDCore/include/DD4hep/AlignmentsProcessor.h @@ -62,11 +62,11 @@ namespace DD4hep { /// Set pool void setPool(pool_type* value) { m_pool = value; } /// Callback to output alignments information - virtual int operator()(Alignment cond); + virtual int operator()(Alignment cond) override; /// Container callback for object processing - virtual int operator()(Container container); + virtual int operator()(Container container) override; /// Callback to output alignments information of an entire DetElement - virtual int processElement(DetElement de); + virtual int processElement(DetElement de) override; }; /// Generic Alignment object collector @@ -85,15 +85,15 @@ namespace DD4hep { /// Default destructor virtual ~AlignmentsCollector() = default; /// Callback to output alignments information - virtual int operator()(Alignment cond) { + virtual int operator()(Alignment cond) final { alignments.push_back(cond); return 1; } /// Container callback for object processing - virtual int operator()(Container container) + virtual int operator()(Container container) final { return this->self_type::operator()(container); } /// Callback to output alignments information of an entire DetElement - virtual int processElement(DetElement detector) + virtual int processElement(DetElement detector) final { return this->self_type::processElement(detector); } }; diff --git a/DDCore/include/DD4hep/ConditionDerived.h b/DDCore/include/DD4hep/ConditionDerived.h index 67f3f7ee51e85dd201b17fe865bf8088e721e42c..c6f6c7fd0018644c9f107a20b2d4cdc09ad27fed 100644 --- a/DDCore/include/DD4hep/ConditionDerived.h +++ b/DDCore/include/DD4hep/ConditionDerived.h @@ -128,15 +128,24 @@ namespace DD4hep { /// Reference count int m_refCount; /// Standard destructor - ConditionUpdateCall() : m_refCount(1) { } + ConditionUpdateCall(); + /// No copy constructor + ConditionUpdateCall(const ConditionUpdateCall& copy) = delete; /// Standard destructor virtual ~ConditionUpdateCall(); - + /// No assignment operator + ConditionUpdateCall& operator=(const ConditionUpdateCall& copy) = delete; public: /// Add use count to the object - ConditionUpdateCall* addRef() { ++m_refCount; return this; } + ConditionUpdateCall* addRef() { + ++m_refCount; + return this; + } /// Release object. May not be used any longer - void release() { if ( --m_refCount <= 0 ) delete this; } + void release() { + if ( --m_refCount <= 0 ) + delete this; + } /// Interface to client Callback in order to update the condition virtual Condition operator()(const ConditionKey& target, const Context& ctxt) = 0; }; diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h index f3538de7fe3f91a38354ba85b739cd55425caeae..d213d0f96cfe4d74e95d465006713670f7b4bf88 100644 --- a/DDCore/include/DD4hep/Conditions.h +++ b/DDCore/include/DD4hep/Conditions.h @@ -338,11 +338,13 @@ namespace DD4hep { ConditionsSelectWrapper() = delete; /// Default assignment operator bool operator==(const ConditionsSelectWrapper& compare) = delete; + public: /// Information collector type typedef OBJECT object_t; /// Reference to the infomation collector object_t& object; + public: /// Default constructor ConditionsSelectWrapper(object_t& o) : ConditionsSelect(), object(o) {} diff --git a/DDCore/include/DD4hep/ConditionsPrinter.h b/DDCore/include/DD4hep/ConditionsPrinter.h index 4276d8d533615e7ddf64a1b66ffc10db912eebd5..9360ac44fe9231e7b094c633ea671d067c5c3a0b 100644 --- a/DDCore/include/DD4hep/ConditionsPrinter.h +++ b/DDCore/include/DD4hep/ConditionsPrinter.h @@ -61,12 +61,9 @@ namespace DD4hep { /// Set prefix for printouts void setPrefix(const std::string& value) { prefix = value; } /// Callback to output conditions information - virtual int operator()(Condition cond); + virtual int operator()(Condition cond) override; /// Container callback for object processing - virtual int operator()(Container container); - /// Callback to output conditions information of an entire DetElement - virtual int processElement(DetElement de) - { return this->ConditionsProcessor::processElement(de); } + virtual int operator()(Container container) override; }; } /* End namespace Conditions */ diff --git a/DDCore/include/DD4hep/ConditionsProcessor.h b/DDCore/include/DD4hep/ConditionsProcessor.h index 8c539069554f346f8582bd568b0848c2d9708ab9..25fb2a1d4344c9f933a4806be048c3629556d051 100644 --- a/DDCore/include/DD4hep/ConditionsProcessor.h +++ b/DDCore/include/DD4hep/ConditionsProcessor.h @@ -65,11 +65,11 @@ namespace DD4hep { /// Set pool void setPool(pool_type* value) { m_pool = value; } /// Callback to output conditions information - virtual int operator()(Condition cond); + virtual int operator()(Condition cond) override; /// Container callback for object processing - virtual int operator()(Container container); + virtual int operator()(Container container) override; /// Callback to output conditions information of an entire DetElement - virtual int processElement(DetElement de); + virtual int processElement(DetElement de) override; }; /// Generic Condition object collector @@ -88,15 +88,15 @@ namespace DD4hep { /// Default destructor virtual ~ConditionsCollector() = default; /// Callback to output conditions information - virtual int operator()(Condition cond) { + virtual int operator()(Condition cond) final { conditions.push_back(cond); return 1; } /// Container callback for object processing - virtual int operator()(Container container) + virtual int operator()(Container container) final { return this->self_type::operator()(container); } /// Callback to output conditions information of an entire DetElement - virtual int processElement(DetElement detector) + virtual int processElement(DetElement detector) final { return this->self_type::processElement(detector); } }; } /* End namespace Conditions */ diff --git a/DDCore/include/DD4hep/DetectorProcessor.h b/DDCore/include/DD4hep/DetectorProcessor.h index c2794a827aad37b3fb38035ba6426274e804eefb..791a2916abcafab409ff6fae3899b4ff9435cd55 100644 --- a/DDCore/include/DD4hep/DetectorProcessor.h +++ b/DDCore/include/DD4hep/DetectorProcessor.h @@ -74,10 +74,11 @@ namespace DD4hep { /// Default destructor virtual ~DetElementProcessor() = default; }; + /// Instantiation helper template <typename T> DetElementProcessor<T> detectorProcessor(T* proc) { return DetElementProcessor<T>(proc); } - + /// Generic Condition object collector /** * Please see the documentation of the @@ -98,7 +99,7 @@ namespace DD4hep { /// Default destructor virtual ~DetectorCollector() = default; /// Callback to output detector information of an entire DetElement - virtual int operator()(DetElement de, int level); + virtual int operator()(DetElement de, int level) final; }; } /* End namespace Geometry */ } /* End namespace DD4hep */ diff --git a/DDCore/src/ConditionDerived.cpp b/DDCore/src/ConditionDerived.cpp index 9da81b8686dceb76b3980bed35e17b19bdd00374..643077791a93ee78f0c053b1d1d10940859b0cd7 100644 --- a/DDCore/src/ConditionDerived.cpp +++ b/DDCore/src/ConditionDerived.cpp @@ -22,8 +22,14 @@ using namespace DD4hep; using namespace DD4hep::Conditions; +/// Standard destructor +ConditionUpdateCall::ConditionUpdateCall() : m_refCount(1) { + InstanceCount::increment(this); +} + /// Standard destructor ConditionUpdateCall::~ConditionUpdateCall() { + InstanceCount::decrement(this); } /// Standard destructor diff --git a/DDCore/src/DetectorInterna.cpp b/DDCore/src/DetectorInterna.cpp index 9cdfb3907666f94ff4e06138d262ba30fc8f915c..845f92a0b2f12c80b113ea405216349ea41380e3 100644 --- a/DDCore/src/DetectorInterna.cpp +++ b/DDCore/src/DetectorInterna.cpp @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/DetectorProcessor.cpp b/DDCore/src/DetectorProcessor.cpp index 1bacf0de739a07d77f37ed129e2d64c762905ae3..5c7362a57b213d7d4ef6470b3eb28f80838e70ac 100644 --- a/DDCore/src/DetectorProcessor.cpp +++ b/DDCore/src/DetectorProcessor.cpp @@ -41,7 +41,7 @@ int DetectorProcessor::process(DetElement de, int level, bool recursive) { } /// Callback to output detector information of an single DetElement -int DetectorCollector::operator()(DetElement de, int level) { +int DetectorCollector::operator()(DetElement de, int level) { if ( de.isValid() ) { detectors.push_back(std::make_pair(level,de)); return 1; diff --git a/DDCore/src/InstanceCount.cpp b/DDCore/src/InstanceCount.cpp index 61ace8d068c9211cd870ceb7d8087aa240e2aadb..16796c28c12f467706fcc1e59ae8edac32591d8b 100644 --- a/DDCore/src/InstanceCount.cpp +++ b/DDCore/src/InstanceCount.cpp @@ -134,40 +134,40 @@ void InstanceCount::decrement(const std::type_info& typ) { void InstanceCount::dump(int typ) { bool need_footer = false; if ((typ & STRING) && s_strCounts.get()) { - if (s_strCounts->begin() != s_strCounts->end()) { - StringCounter::const_iterator i; - std::cout << "+-----------------------------------------------------------------------+" << std::endl; - std::cout << "| I n s t a n c e c o u n t e r s b y N A M E |" << std::endl; - std::cout << "+----------+------+---------+-------------------------------------------+" << std::endl; - std::cout << "| Total | Max | Leaking | Type identifier |" << std::endl; - std::cout << "+----------+------+---------+-------------------------------------------+" << std::endl; - for (i = s_strCounts->begin(); i != s_strCounts->end(); ++i) { - std::cout << "|" << std::setw(10) << (*i).second->total() - << "|" << std::setw(6) << (*i).second->maximum() - << "|" << std::setw(9) << (*i).second->value() - << "|" << (*i).first << std::endl; + if ( !s_strCounts->empty() ) { + cout << "+--------------------------------------------------------------------------+" << endl; + cout << "| I n s t a n c e c o u n t e r s b y N A M E |" << endl; + cout << "+----------+---------+---------+-------------------------------------------+" << endl; + cout << "| Total | Max | Leaking | Type identifier |" << endl; + cout << "+----------+---------+---------+-------------------------------------------+" << endl; + for ( const auto& i : *s_strCounts ) { + cout << "|" << setw(10) << i.second->total() + << "|" << setw(9) << i.second->maximum() + << "|" << setw(9) << i.second->value() + << "|" << i.first->substr(0,80) << endl; } need_footer = true; } } if ((typ & TYPEINFO) && s_typCounts.get()) { - if (s_typCounts->begin() != s_typCounts->end()) { - TypeCounter::const_iterator i; - std::cout << "+-----------------------------------------------------------------------+" << std::endl; - std::cout << "| I n s t a n c e c o u n t e r s b y T Y P E I N F O |" << std::endl; - std::cout << "+----------+------+---------+-------------------------------------------+" << std::endl; - std::cout << "| Total | Max | Leaking | Type identifier |" << std::endl; - std::cout << "+----------+------+---------+-------------------------------------------+" << std::endl; - for (i = s_typCounts->begin(); i != s_typCounts->end(); ++i) { - std::cout << "|" << std::setw(10) << (*i).second->total() - << "|" << std::setw(6) << (*i).second->maximum() - << "|" << std::setw(9) << (*i).second->value() - << "|" << typeName(*((*i).first)) << std::endl; + if ( !s_typCounts->empty() ) { + cout << "+--------------------------------------------------------------------------+" << endl; + cout << "| I n s t a n c e c o u n t e r s b y T Y P E I N F O |" << endl; + cout << "+----------+---------+---------+-------------------------------------------+" << endl; + cout << "| Total | Max | Leaking | Type identifier |" << endl; + cout << "+----------+---------+---------+-------------------------------------------+" << endl; + for ( const auto& i : *s_typCounts ) { + string nam = typeName(*(i.first)); + if ( nam.length() > 80 ) nam = nam.substr(0,80)+" ..."; + cout << "|" << setw(10) << i.second->total() + << "|" << setw(9) << i.second->maximum() + << "|" << setw(9) << i.second->value() + << "|" << nam << endl; } need_footer = true; } } if (need_footer) { - std::cout << "+----------+-------+-------------------------------------------+" << std::endl; + cout << "+----------+-------+-------------------------------------------+" << endl; } } diff --git a/DDCore/src/LCDDImp.cpp b/DDCore/src/LCDDImp.cpp index 6b169b4de06ff0692e676af0cea172fb8057c5ab..2679a16037f2bcb015845c9ce0ceb0a07195c410 100644 --- a/DDCore/src/LCDDImp.cpp +++ b/DDCore/src/LCDDImp.cpp @@ -110,9 +110,12 @@ LCDDImp::LCDDImp() : LCDDData(), LCDDLoad(this), m_buildType(BUILD_NONE) } { m_manager = gGeoManager; - //m_manager->AddNavigator(); - //m_manager->SetCurrentNavigator(0); - //cout << "Navigator:" << (void*)m_manager->GetCurrentNavigator() << endl; + TGeoElementTable* table = m_manager->GetElementTable(); + table->TGeoElementTable::~TGeoElementTable(); + new(table) TGeoElementTable(); + // This will initialize the table without filling: + table->AddElement("VACUUM","VACUUM" ,0, 0, 0.0); + table->Print(); } //if ( 0 == gGeoIdentity ) { diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index cae3577d707d1d411bca0d0790acc645d43a25f6..748a43ad174acb9ddbcbcde52bbd3320ea9dc6b6 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -158,9 +158,6 @@ namespace { sd = SensitiveDetector(0); } } - if ( e.path().find("/world/EcalBarrel") == 0 ) { - printout(DEBUG, "VolumeManager",""); - } if ( sd.isValid() ) { if ( !have_encoding ) { printout(ERROR, "VolumeManager","%s: Missing SD encoding. Volume manager won't work!", diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 58b7a48d612b03e0893bee7d80f07388dee78faa..b2b2c03fb7dddb19afe4870e3f45052af7b513bb 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -286,18 +286,18 @@ template <> void Converter<Header>::operator()(xml_h e) const { */ template <> void Converter<Material>::operator()(xml_h e) const { xml_ref_t m(e); - TGeoManager& mgr = lcdd.manager(); - xml_tag_t mname = m.name(); - const char* matname = mname.c_str(); + TGeoManager& mgr = lcdd.manager(); + xml_tag_t mname = m.name(); + const char* matname = mname.c_str(); TGeoElementTable* table = mgr.GetElementTable(); - TGeoMaterial* mat = mgr.GetMaterial(matname); - TGeoMixture* mix = dynamic_cast<TGeoMixture*>(mat); - xml_coll_t fractions(m, _U(fraction)); - xml_coll_t composites(m, _U(composite)); + TGeoMaterial* mat = mgr.GetMaterial(matname); + TGeoMixture* mix = dynamic_cast<TGeoMixture*>(mat); + xml_coll_t fractions(m, _U(fraction)); + xml_coll_t composites(m, _U(composite)); if (0 == mat) { TGeoMaterial* comp_mat; - TGeoElement* comp_elt; + TGeoElement* comp_elt; xml_h radlen = m.child(_U(RL), false); xml_h intlen = m.child(_U(NIL), false); xml_h density = m.child(_U(D), false); @@ -312,6 +312,14 @@ template <> void Converter<Material>::operator()(xml_h e) const { if ( density.ptr() && density.hasAttr(_U(unit)) ) { dens_unit = density.attr<double>(_U(unit))/XML::_toDouble(_Unicode(gram/cm3)); } + if ( radlen.ptr() && radlen.hasAttr(_U(unit)) ) { + double radlen_unit = radlen.attr<double>(_U(unit))/XML::_toDouble(_Unicode(cm)); + radlen_val *= radlen_unit; + } + if ( intlen.ptr() && intlen.hasAttr(_U(unit)) ) { + double intlen_unit = intlen.attr<double>(_U(unit))/XML::_toDouble(_Unicode(cm)); + intlen_val *= intlen_unit; + } if ( dens_unit != 1.0 ) { cout << matname << " Density unit:" << dens_unit; if ( dens_unit != 1.0 ) cout << " " << density.attr<string>(_U(unit)); @@ -329,7 +337,8 @@ template <> void Converter<Material>::operator()(xml_h e) const { cout << "degree " << XML::_toDouble(_Unicode(degree)) << endl; #endif //throw 1; - printout(DEBUG, "Compact", "++ Converting material %s", matname); + printout(DEBUG, "Compact", "++ Converting material %-22s IntLen:%8.3g cm RadLen:%8.3g cm Densitiy:%8.3g g/cm3", + matname, intlen_val, radlen_val, dens_val); mat = mix = new TGeoMixture(matname, composites.size(), dens_val); mat->SetRadLen(radlen_val, intlen_val); size_t ifrac = 0; @@ -421,8 +430,14 @@ template <> void Converter<Atom>::operator()(xml_h e) const { TGeoElement* element = tab->FindElement(eltname.c_str()); if (!element) { xml_ref_t atom(elem.child(_U(atom))); - tab->AddElement(elem.attr<string>(_U(name)).c_str(), elem.attr<string>(_U(formula)).c_str(), elem.attr<int>(_U(Z)), - atom.attr<int>(_U(value))); + string formula = elem.attr<string>(_U(formula)); + double value = atom.attr<double>(_U(value)); + string unit = atom.attr<string>(_U(unit)); + int z = elem.attr<int>(_U(Z)); + double a = value*_multiply<double>(unit,"mol/g"); + printout(DEBUG, "Compact", "++ Converting element %-16s [%-3s] Z:%3d A:%8.4f [g/mol]", + eltname.c_str(), formula.c_str(), z, a); + tab->AddElement(eltname.c_str(), formula.c_str(), z, a); element = tab->FindElement(eltname.c_str()); if (!element) { throw_print("Failed to properly insert the Element:" + eltname + " into the element table!"); diff --git a/DDDB/src/DDDBAlignmentTest.cpp b/DDDB/src/DDDBAlignmentTest.cpp index 408095926237cc2ee2701ad043dabdcd6e1d696b..d92dace534cfbf28462d17b646e6eae559a12d40 100644 --- a/DDDB/src/DDDBAlignmentTest.cpp +++ b/DDDB/src/DDDBAlignmentTest.cpp @@ -92,7 +92,7 @@ namespace { align.alignments()->addKey("Alignment",k.name); // // Now add the dependency to the alignmant manager - DependencyBuilder b(k, updateCall->addRef()); + DependencyBuilder b(k, updateCall); b->detector = de; b.add(ConditionKey(cond->value)); am.adoptDependency(b.release()); @@ -122,7 +122,7 @@ namespace { long collect(ConditionsManager manager, AlignmentsManager& context, const IOV& iov) { dd4hep_ptr<ConditionsSlice> slice(createSlice(manager,*iov.iovType)); manager.prepare(iov, *slice); - int res = collect(lcdd.world(), slice->pool(), context, 0); + int res = collect(lcdd.world(), slice->pool, context, 0); return res; } /// Compute dependent alignment conditions @@ -137,7 +137,7 @@ namespace { TTimeStamp acc_stop; acc_stat.Fill(acc_stop.AsDouble()-acc_start.AsDouble()); TTimeStamp comp_start; - AlignmentsManager::Result ares = align.compute(*(slice->pool())); + AlignmentsManager::Result ares = align.compute(*slice->pool); TTimeStamp comp_stop; comp_stat.Fill(comp_stop.AsDouble()-comp_start.AsDouble()); printout(INFO,"DDDBAlign", @@ -158,12 +158,11 @@ namespace { for(Deps::const_iterator i=deps.begin(); i!=deps.end(); ++i) { const ConditionDependency* d = (*i).second.get(); if ( d->detector.hasAlignments() ) { - UserPool& p = *(slice->pool().get()); Alignments::DetAlign det(d->detector); const ConditionKey& k = d->target; Alignments::Container c = det.alignments(); { - Alignments::Alignment a = c.get(k.hash,p); + Alignments::Alignment a = c.get(k.hash,*slice->pool); const Alignments::Delta& D = a.data().delta; printout(m_level,"Alignment","++ [%16llX] (%11s-%8s-%5s) Cond:%p '%s'", k.hash, D.hasTranslation() ? "Translation" : "", @@ -175,7 +174,7 @@ namespace { ++m_accessCount; } { - Alignments::Alignment a = c.get("Alignment",p); + Alignments::Alignment a = c.get("Alignment",*slice->pool); const Alignments::Delta& D = a.data().delta; printout(m_level,"Alignment","++ [%16llX] (%11s-%8s-%5s) Cond:%p 'Alignment'", k.hash, D.hasTranslation() ? "Translation" : "", @@ -225,35 +224,35 @@ namespace { ::exit(EINVAL); } } - AlignmentSelector selec(lcdd, level); - AlignmentsManager align(AlignmentsManager::from(lcdd)); - ConditionsManager conds(ConditionsManager::from(lcdd)); - TStatistic cr_stat("Initialize"), re_acc_stat("Reaccess"); - const IOVType* iovType = conds.iovType("epoch"); int ret; { - TTimeStamp start; - IOV iov(iovType, time); - ret = selec.collect(conds,align,iov); - TTimeStamp stop; - cr_stat.Fill(stop.AsDouble()-start.AsDouble()); - } - if ( ret == 1 ) { - for(int i=0; i<turns; ++i) { { - long ti = time + (i+1)*3600; - IOV iov(iovType, ti); - dd4hep_ptr<ConditionsSlice> slice; - ret = selec.computeDependencies(slice,conds,align,iov); - slice->reset(); - dd4hep_ptr<ConditionsSlice> slice2; - TTimeStamp start; - slice2.adopt(createSlice(conds,*iov.iovType)); - //slice2->insert(align.knownDependencies()); - conds.prepare(iov, *slice2); - TTimeStamp stop; - re_acc_stat.Fill(stop.AsDouble()-start.AsDouble()); + AlignmentSelector selec(lcdd, level); + AlignmentsManager align(AlignmentsManager::from(lcdd)); + ConditionsManager conds(ConditionsManager::from(lcdd)); + TStatistic cr_stat("Initialize"), re_acc_stat("Reaccess"); + const IOVType* iovType = conds.iovType("epoch"); + { + TTimeStamp start; + IOV iov(iovType, time); + ret = selec.collect(conds,align,iov); + TTimeStamp stop; + cr_stat.Fill(stop.AsDouble()-start.AsDouble()); + } + if ( ret == 1 ) { + for(int i=0; i<turns; ++i) { { + IOV iov(iovType, time + (i+1)*3600); + dd4hep_ptr<ConditionsSlice> slice1, slice2; + ret = selec.computeDependencies(slice1,conds,align,iov); + slice2.adopt(createSlice(conds,*iov.iovType)); + TTimeStamp start; + ConditionsManager::Result cres = conds.prepare(iov, *slice2); + TTimeStamp stop; + re_acc_stat.Fill(stop.AsDouble()-start.AsDouble()); + printout(INFO,"DDDBAlign", + "++ REACCESS: %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) for IOV:%-12s", + cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing, iov.str().c_str()); + } } - DD4hep::InstanceCount::dump(); } printout(INFO,"Statistics","+======= Summary: # of Runs: %3d ==========================================",turns); printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld", @@ -268,6 +267,7 @@ namespace { re_acc_stat.GetName(), re_acc_stat.GetMean(), re_acc_stat.GetMeanErr(), re_acc_stat.GetRMS(), re_acc_stat.GetN()); printout(INFO,"Statistics","+========================================================================="); } + InstanceCount::dump(); return ret; } } /* End anonymous namespace */ diff --git a/DDDB/src/DDDBAlignmentTestEx.cpp b/DDDB/src/DDDBAlignmentTestEx.cpp new file mode 100644 index 0000000000000000000000000000000000000000..872346777a546c344a5830028041ca504dff1aca --- /dev/null +++ b/DDDB/src/DDDBAlignmentTestEx.cpp @@ -0,0 +1,261 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +// +// DDDB is a detector description convention developed by the LHCb experiment. +// For further information concerning the DTD, please see: +// http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf +// +//========================================================================== + + +// Framework includes +#include "DD4hep/LCDD.h" +#include "DD4hep/Path.h" +#include "DD4hep/DetAlign.h" +#include "DD4hep/Printout.h" +#include "DD4hep/Factories.h" +#include "DD4hep/InstanceCount.h" +#include "DD4hep/objects/AlignmentsInterna.h" +#include "DDCond/ConditionsSlice.h" +#include "DD4hep/ConditionsPrinter.h" +#include "DDAlign/AlignmentsManager.h" + +#include "DDDB/DDDBConversion.h" +#include "DDDB/DDDBAlignmentUpdateCall.h" + +#include "TStatistic.h" +#include "TTimeStamp.h" + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Conditions; +using Alignments::AlignmentsManager; + +/// Anonymous namespace for plugins +namespace { + + /// DDDB Conditions analyser to select alignments. + /** + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + * \ingroup DD4HEP_DDDB + */ + class AlignmentSelector { + public: + ConditionUpdateCall* updateCall; + LCDD& lcdd; + string m_name; + PrintLevel m_level = INFO; + long m_installCount = 0; + long m_accessCount = 0; + TStatistic acc_stat, comp_stat; + + struct UCall : public Alignments::AlignmentUpdateCall { + AlignmentsManager manager; + UCall(AlignmentsManager m) : manager(m) {} + virtual ~UCall() = default; + Condition operator()(const ConditionKey& key, const UpdateContext& context) + { + Condition cond = context.condition(0); + AbstractMap& src = cond.get<AbstractMap>(); + OpaqueDataBlock& par = src.firstParam().second; + DetElement det = context.dependency.detector; + printout(DEBUG,"AlignmentUpdate","++ Building dependent condition: %s Detector [%d]: %s ", + key.name.c_str(), det.level(), det.path().c_str()); + if ( par.typeInfo() == typeid(Data::Delta) ) { + const Data::Delta& delta = src.first<Data::Delta>(); + return AlignmentUpdateCall::handle(key, context, delta); + } + // Somehow the condition is not of type Data::Delta. This is an ERROR. + // Here only print and return an empty alignment condition. + // Otherwise the return is not accepted! + // TODO: To be decided how to handle this error + Alignments::AlignmentCondition target(key.name); + Data& data = target.data(); + data.detector = det; + printout(INFO,"AlignmentUpdate","++ Failed to access alignment-Delta from %s", + cond->value.c_str()); + ConditionsPrinter("AlignmentUpdate")(cond); + return target; + } + }; + + /// Initializing constructor + AlignmentSelector(LCDD& l, PrintLevel p, AlignmentsManager m) + : lcdd(l), m_name("DDDBAlignments"), m_level(p), acc_stat("Access"), comp_stat("Compute") { + // The alignment update call can be re-used over and over. It has not state. + updateCall = new UCall(m); + } + /// Default destructor + virtual ~AlignmentSelector() { + printout(INFO,m_name,"++ Installed alignment calls: %ld", m_installCount); + printout(INFO,m_name,"++ Number of accessed alignments: %ld", m_accessCount); + releasePtr(updateCall); + } + /// Recursive alignment collector + long collect(DetElement de, dd4hep_ptr<UserPool>& user_pool, ConditionsSlice& slice, int level) + { + char fmt[64]; + try { + DDDB::Catalog* cat = de.extension<DDDB::Catalog>(); + if ( !cat->condition.empty() ) { + ConditionKey key(cat->condition); + Condition cond = user_pool->get(key.hash); + if ( cond.isValid() ) { + ConditionKey k(cat->condition+"/Tranformations"); + // + // The alignment access through the DetElement object is optional! + // It is slow and deprecated. The access using the UserPool directly + // is highly favored. + // + Alignments::DetAlign align(de); + align.alignments()->addKey(k.name); + align.alignments()->addKey("Alignment",k.name); + // + // Now add the dependency to the alignmant manager + DependencyBuilder b(k, updateCall); + b->detector = de; + b.add(ConditionKey(cond->value)); + slice.insert(b.release()); + ++m_installCount; + } + else { + ::sprintf(fmt,"%03d %%-%ds %%-20s -> %%s",level+1,2*level+3); + printout(m_level,m_name,fmt,"","Alignment: ", + !cond.isValid() ? (cat->condition+" !!!UNRESOLVED!!!").c_str() : cat->condition.c_str()); + } + } + } + catch(const exception& e) { + ::sprintf(fmt,"%03d %%-%ds %%s: %%-20s Exception: %%s",level+1,2*level+3); + printout(ERROR,m_name, fmt, "", de.path().c_str(), "[NO CATALOG availible]", e.what()); + } + catch(...) { + ::sprintf(fmt,"%03d %%-%ds %%s: %%-20s",level+1,2*level+3); + printout(ERROR,m_name, fmt, "", de.path().c_str(), "[NO CATALOG availible]"); + } + const DetElement::Children& c = de.children(); + for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) + collect((*i).second, user_pool, slice, level+1); + return 1; + } + /// Initial collector call + long collect(ConditionsManager manager, const IOV& iov) { + dd4hep_ptr<ConditionsSlice> slice(createSlice(manager,*iov.iovType)); + manager.prepare(iov, *slice); + int res = collect(lcdd.world(), slice->pool, *slice, 0); + return res; + } + /// Compute dependent alignment conditions + int computeDependencies(dd4hep_ptr<ConditionsSlice>& slice, + ConditionsManager conds, + AlignmentsManager align, + const IOV& iov) + { + slice.adopt(createSlice(conds,*iov.iovType)); + TTimeStamp acc_start; + ConditionsManager::Result cres = conds.prepare(iov, *slice); + TTimeStamp acc_stop; + acc_stat.Fill(acc_stop.AsDouble()-acc_start.AsDouble()); + TTimeStamp comp_start; + AlignmentsManager::Result ares = align.compute(*slice->pool); + TTimeStamp comp_stop; + comp_stat.Fill(comp_stop.AsDouble()-comp_start.AsDouble()); + printout(INFO,"DDDBAlign", + "++ AlignmentManager: %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) (A:%ld,M:%ld) for IOV:%-12s", + cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing, + ares.computed, ares.missing, iov.str().c_str()); + return 1; + } + }; +} + +//========================================================================== +namespace { + + /// Plugin function: Load dependent alignment conditions according to time stamps. + long dddb_derived_alignments(LCDD& lcdd, int argc, char** argv) { + int turns = 1; + PrintLevel level = INFO; + long time = makeTime(2016,4,1,12); + + for(int i=0; i<argc; ++i) { + if ( ::strcmp(argv[i],"-time")==0 ) { + time = makeTime(argv[++i],"%d-%m-%Y %H:%M:%S"); + printout(level,"DDDB","Setting event time in %s to %s [%ld]", + Path(__FILE__).filename().c_str(), argv[i-1], time); + } + else if ( ::strcmp(argv[i],"-print")==0 ) { + level = DD4hep::printLevel(argv[++i]); + printout(level,"DDDB","Setting print level in %s to %s [%d]", + Path(__FILE__).filename().c_str(), argv[i-1], level); + } + else if ( ::strcmp(argv[i],"-turns")==0 ) { + turns = ::atol(argv[++i]); + } + else if ( ::strcmp(argv[i],"--help")==0 ) { + printout(level,"Plugin-Help","Usage: DDDB_DerivedAlignmentsTest --opt [--opt] "); + printout(level,"Plugin-Help"," -time <string> Set event time Format: \"%%d-%%m-%%Y %%H:%%M:%%S\""); + printout(level,"Plugin-Help"," -print <value> Printlevel for output "); + printout(level,"Plugin-Help"," -help Print this help message "); + ::exit(EINVAL); + } + } + AlignmentsManager align(AlignmentsManager::from(lcdd)); + ConditionsManager conds(ConditionsManager::from(lcdd)); + AlignmentSelector selec(lcdd, level, align); + TStatistic cr_stat("Initialize"), re_acc_stat("Reaccess"); + const IOVType* iovType = conds.iovType("epoch"); + int ret; + { + TTimeStamp start; + IOV iov(iovType, time); + ret = selec.collect(conds,iov); + TTimeStamp stop; + cr_stat.Fill(stop.AsDouble()-start.AsDouble()); + } + if ( ret == 1 ) { + for(int i=0; i<turns; ++i) { { + long ti = time + (i+1)*3600; + IOV iov(iovType, ti); + dd4hep_ptr<ConditionsSlice> slice; + ret = selec.computeDependencies(slice,conds,align,iov); + slice->reset(); + dd4hep_ptr<ConditionsSlice> slice2; + TTimeStamp start; + slice2.adopt(createSlice(conds,*iov.iovType)); + conds.prepare(iov, *slice2); + TTimeStamp stop; + re_acc_stat.Fill(stop.AsDouble()-start.AsDouble()); + } + DD4hep::InstanceCount::dump(); + } + printout(INFO,"Statistics","+======= Summary: # of Runs: %3d ==========================================",turns); + printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld", + cr_stat.GetName(), cr_stat.GetMean(), cr_stat.GetMeanErr(), cr_stat.GetRMS(), cr_stat.GetN()); + printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld", + selec.acc_stat.GetName(), selec.acc_stat.GetMean(), selec.acc_stat.GetMeanErr(), + selec.acc_stat.GetRMS(), selec.acc_stat.GetN()); + printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld", + selec.comp_stat.GetName(), selec.comp_stat.GetMean(), selec.comp_stat.GetMeanErr(), + selec.comp_stat.GetRMS(), selec.comp_stat.GetN()); + printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld", + re_acc_stat.GetName(), re_acc_stat.GetMean(), re_acc_stat.GetMeanErr(), re_acc_stat.GetRMS(), re_acc_stat.GetN()); + printout(INFO,"Statistics","+========================================================================="); + } + return ret; + } +} /* End anonymous namespace */ +DECLARE_APPLY(DDDB_DerivedAlignmentsTestEx,dddb_derived_alignments) +//========================================================================== diff --git a/DDDB/src/DDDBConditionsLoader.cpp b/DDDB/src/DDDBConditionsLoader.cpp index 1fc0d0e14b24fa50a412dd339d0db3d3bfc5f296..8169074d76d8fa104d381ca055e97f4ba6b29d1d 100644 --- a/DDDB/src/DDDBConditionsLoader.cpp +++ b/DDDB/src/DDDBConditionsLoader.cpp @@ -41,6 +41,7 @@ using Conditions::Condition; using Conditions::RangeConditions; using Conditions::ConditionsSlice; using Conditions::ConditionsListener; +using Conditions::ConditionsDescriptor; using Conditions::ConditionsManagerObject; using DDDB::DDDBConditionsLoader; @@ -248,6 +249,7 @@ size_t DDDBConditionsLoader::load_range(key_type key, return 0; } +/// Access single conditions from the persistent medium size_t DDDBConditionsLoader::load_single(key_type key, const iov_type& req_iov, RangeConditions& conditions) { @@ -269,7 +271,6 @@ size_t DDDBConditionsLoader::load_single(key_type key, return 0; } - /// Optimized update using conditions slice data size_t DDDBConditionsLoader::load_many(const iov_type& req_iov, RequiredItems& work, @@ -290,7 +291,7 @@ size_t DDDBConditionsLoader::load_many(const iov_type& req_iov, // Since one file contains many conditions, we have // to create a unique set for(const auto& i : work ) { - ConditionsSlice::Entry* e = i.second; + ConditionsDescriptor* e = i.second; if ( e->dependency ) { printout(INFO,"DDDBLoader","++ CANNOT update derived: %-40s [%16llX]", e->dependency->target.name.c_str(), e->dependency->target.hash); diff --git a/DDDB/src/DDDBDerivedCondTest.cpp b/DDDB/src/DDDBDerivedCondTest.cpp index 47dfaebeeeb7908deec46cda62a6afde65ed1c18..a4a16bb029d0a73dee8fa192add0d19bfb393128 100644 --- a/DDDB/src/DDDBDerivedCondTest.cpp +++ b/DDDB/src/DDDBDerivedCondTest.cpp @@ -351,8 +351,8 @@ namespace { m_manager.prepare(iov, *slice); printout(m_level,"Conditions", "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s", - long(slice->pool()->size()), iov.str().c_str()); - slice->pool()->clear(); + long(slice->pool->size()), iov.str().c_str()); + slice->pool->clear(); return 1; } }; diff --git a/cmake/DD4hepBuild.cmake b/cmake/DD4hepBuild.cmake index c113f2c49ef4e44c78e19efd8489447317927f03..f3342d1412454629c8f3734942b710da19c52616 100644 --- a/cmake/DD4hepBuild.cmake +++ b/cmake/DD4hepBuild.cmake @@ -71,11 +71,22 @@ macro(dd4hep_set_compiler_flags) add_definitions(-DDD4HEP_USE_STDCXX=11) endif() + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshadow -Wformat-security -Wno-long-long -Wdeprecated") - IF(("${CMAKE_CXX_COMPILER_ID}" EQUAL "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" EQUAL "Clang")) + CHECK_CXX_COMPILER_FLAG("-fdiagnostics-color=always" FLAG_COLOR) + if (FLAG_COLOR) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") + endif() + + IF( "${CMAKE_CXX_COMPILER_ID}" EQUAL "Clang" ) SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") ENDIF() + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined -pthread") + endif() + IF("${CMAKE_CXX_COMPILER_ID}" EQUAL "AppleClang") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error") ENDIF() diff --git a/examples/AlignDet/src/AlignmentExampleObjects.cpp b/examples/AlignDet/src/AlignmentExampleObjects.cpp index aeefe16207825541561813dd6dc2c071efa14bba..5b49640ac174519ba435d8cb141ac81c12fb128b 100644 --- a/examples/AlignDet/src/AlignmentExampleObjects.cpp +++ b/examples/AlignDet/src/AlignmentExampleObjects.cpp @@ -19,6 +19,7 @@ #include "DDAlign/DDAlignForwardCall.h" #include "DDAlign/AlignmentsRegister.h" #include "DDAlign/AlignmentsForward.h" +#include "DDCond/ConditionsSlice.h" using namespace std; using namespace DD4hep; @@ -37,13 +38,12 @@ void DD4hep::AlignmentExamples::registerAlignmentCallbacks(LCDD& lcdd, ConditionsSlice& slice, AlignmentsManager alignMgr) { - dd4hep_ptr<UserPool>& pool = slice.pool(); // Let's register the callbacks to compute dependent conditions/alignments // 1) Create dependencies for all deltas found in the conditions - Alignments::AlignmentsRegister reg(alignMgr,new Alignments::DDAlignUpdateCall(),pool.get()); + Alignments::AlignmentsRegister reg(alignMgr,new Alignments::DDAlignUpdateCall(),slice.pool.get()); Scanner().scan(reg,lcdd.world()); // 2) Create child dependencies if higher level alignments exist - Alignments::AlignmentsForward fwd(alignMgr,new Alignments::DDAlignForwardCall(),pool.get()); + Alignments::AlignmentsForward fwd(alignMgr,new Alignments::DDAlignForwardCall(),slice.pool.get()); Scanner().scan(fwd,lcdd.world()); } @@ -53,13 +53,13 @@ int AlignmentDataAccess::processElement(DetElement de) { Alignments::Container container = a.alignments(); // Let's go for the deltas.... for(const auto& k : container.keys() ) { - Alignment align = container.get(k.first,*pool); + Alignment align = container.get(k.first,pool); const Delta& delta = align.data().delta; if ( delta.hasTranslation() || delta.hasPivot() || delta.hasRotation() ) {} } // Keep it simple. To know how to access stuff, // simply look in DDDCore/src/AlignmentsPrinter.cpp... - Alignments::printElementPlacement(printLevel,"Example",de,pool); + Alignments::printElementPlacement(printLevel,"Example",de,&pool); return 1; } diff --git a/examples/AlignDet/src/AlignmentExampleObjects.h b/examples/AlignDet/src/AlignmentExampleObjects.h index bf4fa17b46f20f8b807343495907130ff77e53e7..18299ecf658827bcacceca1a6332c0dad3ad1b17 100644 --- a/examples/AlignDet/src/AlignmentExampleObjects.h +++ b/examples/AlignDet/src/AlignmentExampleObjects.h @@ -93,11 +93,11 @@ namespace DD4hep { * \date 01/04/2016 */ struct AlignmentDataAccess : public Alignments::AlignmentsProcessor { - UserPool* pool; + UserPool& pool; /// Print level PrintLevel printLevel; /// Constructor - AlignmentDataAccess(UserPool* p) : AlignmentsProcessor(0), pool(p), + AlignmentDataAccess(UserPool& p) : AlignmentsProcessor(0), pool(p), printLevel(DEBUG) { } /// Callback to process a single detector element diff --git a/examples/AlignDet/src/AlignmentExample_populate.cpp b/examples/AlignDet/src/AlignmentExample_populate.cpp index 770a6bd5c4b45e1fbf65ef5b1ca0c686db51014c..49df9efbf51647b956b7d45cc704fa314e2dedaa 100644 --- a/examples/AlignDet/src/AlignmentExample_populate.cpp +++ b/examples/AlignDet/src/AlignmentExample_populate.cpp @@ -92,7 +92,6 @@ static int alignment_example (Geometry::LCDD& lcdd, int argc, char** argv) { /******************** Now as usual: create the slice ********************/ dd4hep_ptr<ConditionsSlice> slice(Conditions::createSlice(condMgr,*iov_typ)); - dd4hep_ptr<UserPool>& pool = slice->pool(); /******************** Register alignments *******************************/ // Note: We have to load one set of conditions in order to auto-populate @@ -116,7 +115,7 @@ static int alignment_example (Geometry::LCDD& lcdd, int argc, char** argv) { res.computed, res.missing, iov_typ->str().c_str()); } // What else ? let's access/print the current selection - Alignments::AlignedVolumePrinter printer(pool.get(),"Example"); + Alignments::AlignedVolumePrinter printer(slice->pool.get(),"Example"); Scanner().scan(printer,lcdd.world()); // All done. diff --git a/examples/AlignDet/src/AlignmentExample_read_xml.cpp b/examples/AlignDet/src/AlignmentExample_read_xml.cpp index a4e2684fe772c4c0131701703875198c2cd1499c..607a2b407a66ad5f3f501041ba04a1d9a451a2e5 100644 --- a/examples/AlignDet/src/AlignmentExample_read_xml.cpp +++ b/examples/AlignDet/src/AlignmentExample_read_xml.cpp @@ -85,10 +85,10 @@ static int alignment_example (Geometry::LCDD& lcdd, int argc, char** argv) { AlignmentsManager::Result ares = alignMgr.compute(*slice); // What else ? let's access the data - Scanner().scan2(AlignmentDataAccess(slice->pool().get()),lcdd.world()); + Scanner().scan2(AlignmentDataAccess(*slice->pool),lcdd.world()); // What else ? let's print the current selection - Alignments::AlignedVolumePrinter printer(slice->pool().get(),"Example"); + Alignments::AlignedVolumePrinter printer(slice->pool.get(),"Example"); Scanner().scan(printer,lcdd.world()); printout(INFO,"Example", diff --git a/examples/Conditions/src/ConditionExampleObjects.cpp b/examples/Conditions/src/ConditionExampleObjects.cpp index 26a7228d6406d2ad178bf3450c57b1c46977f782..5e4cce670d8be49a7718a885155ec26e354a5f2a 100644 --- a/examples/Conditions/src/ConditionExampleObjects.cpp +++ b/examples/Conditions/src/ConditionExampleObjects.cpp @@ -19,6 +19,9 @@ using namespace std; using namespace DD4hep; using namespace DD4hep::ConditionExamples; using Conditions::DependencyBuilder; +using Conditions::ConditionsLoadInfo; +using Conditions::ConditionsSlice; + /// Install the consitions and the alignment manager void DD4hep::ConditionExamples::installManagers(LCDD& lcdd) { @@ -71,7 +74,7 @@ Condition ConditionUpdate3::operator()(const ConditionKey& key, const Context& c return target; } - +/// Initializing constructor ConditionsDependencyCreator::ConditionsDependencyCreator(ConditionsSlice& s,PrintLevel p) : slice(s), printLevel(p) { @@ -80,6 +83,13 @@ ConditionsDependencyCreator::ConditionsDependencyCreator(ConditionsSlice& s,Prin call3 = new ConditionUpdate3(printLevel); } +/// Destructor +ConditionsDependencyCreator::~ConditionsDependencyCreator() { + releasePtr(call1); + releasePtr(call2); + releasePtr(call3); +} + /// Callback to process a single detector element int ConditionsDependencyCreator::operator()(DetElement de, int) { DetConditions dc(de); @@ -87,9 +97,9 @@ int ConditionsDependencyCreator::operator()(DetElement de, int) { ConditionKey target1(key.name+"/derived_1"); ConditionKey target2(key.name+"/derived_2"); ConditionKey target3(key.name+"/derived_3"); - DependencyBuilder build_1(target1, call1->addRef()); - DependencyBuilder build_2(target2, call2->addRef()); - DependencyBuilder build_3(target3, call3->addRef()); + DependencyBuilder build_1(target1, call1); + DependencyBuilder build_2(target2, call2); + DependencyBuilder build_3(target3, call3); // Compute the derived stuff build_1.add(key); @@ -130,10 +140,11 @@ int ConditionsDataAccess::processElement(DetElement de) { ConditionKey key_derived2 (path+"#derived_data/derived_2"); ConditionKey key_derived3 (path+"#derived_data/derived_3"); Conditions::Container container = dc.conditions(); - int result = 0; + int result = 0, count = 0; // Let's go for the deltas.... for(const auto& k : container.keys() ) { - Condition cond = container.get(k.first,*pool); + Condition cond = container.get(k.first,*m_pool); + ++count; if ( k.first == key_temperature.hash ) { result += int(cond.get<double>()); } @@ -158,16 +169,23 @@ int ConditionsDataAccess::processElement(DetElement de) { else if ( k.first == key_derived3.hash ) { result += int(cond.get<vector<int> >().size()); } + if ( !IOV::key_is_contained(iov.key(),cond.iov().key()) ) { + printout(printLevel,"CondAccess","++ IOV mismatch:%s <> %s", + iov.str().c_str(), cond.iov().str().c_str()); + } } - return result; + for (const auto& c : de.children() ) + count += processElement(c.second); + return count; } -template<typename T> Condition make_condition(DetElement de, const string& name, T val) { +template<typename T> Condition ConditionsCreator::make_condition(DetElement de, const string& name, T val) { Condition cond(de.path()+"#"+name, name); T& value = cond.bind<T>(); value = val; cond->hash = ConditionKey::hashCode(cond->name); cond->setFlag(Condition::ACTIVE); + if ( slice ) slice->insert(ConditionKey(cond->name,cond->hash),ConditionsSlice::NoLoadInfo()); return cond; } diff --git a/examples/Conditions/src/ConditionExampleObjects.h b/examples/Conditions/src/ConditionExampleObjects.h index 8f29551bbbdd5a103dbd9de756b14b0308ae1da3..9be4764860e209002adf8c84f4a6964d11c8f289 100644 --- a/examples/Conditions/src/ConditionExampleObjects.h +++ b/examples/Conditions/src/ConditionExampleObjects.h @@ -120,17 +120,19 @@ namespace DD4hep { ConditionsManager manager; /// Reference to the conditiosn user pool ConditionsPool* pool; + ConditionsSlice* slice; /// Counter unsigned int conditionCount; /// Print level PrintLevel printLevel; /// Constructor ConditionsCreator(ConditionsManager& m,ConditionsPool* p,PrintLevel l) - : manager(m), pool(p), conditionCount(0), printLevel(l) { } + : manager(m), pool(p), slice(0), conditionCount(0), printLevel(l) { } /// Destructor virtual ~ConditionsCreator(); /// Callback to process a single detector element virtual int operator()(DetElement de, int level); + template<typename T> Condition make_condition(DetElement de, const std::string& name, T val); }; /// Example how to populate the detector description with derived conditions @@ -150,6 +152,8 @@ namespace DD4hep { ConditionUpdateCall *call1, *call2, *call3; /// Constructor ConditionsDependencyCreator(ConditionsSlice& s,PrintLevel p); + /// Destructor + virtual ~ConditionsDependencyCreator(); /// Callback to process a single detector element virtual int operator()(DetElement de, int level); }; @@ -176,12 +180,13 @@ namespace DD4hep { * \date 01/04/2016 */ struct ConditionsDataAccess : public Conditions::ConditionsProcessor { - UserPool* pool; + /// IOV to be checked + const IOV& iov; /// Print level - PrintLevel printLevel; + PrintLevel printLevel; /// Constructor - ConditionsDataAccess(UserPool* p) : - ConditionsProcessor(0), pool(p), printLevel(DEBUG) { } + ConditionsDataAccess(const IOV& i, UserPool* p) : + ConditionsProcessor(p), iov(i), printLevel(DEBUG) { } /// Callback to process a single detector element int processElement(DetElement de); }; diff --git a/examples/Conditions/src/ConditionExample_MT.cpp b/examples/Conditions/src/ConditionExample_MT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d7fae31e757e4fce8b43eb7affbe6aa91981eb0a --- /dev/null +++ b/examples/Conditions/src/ConditionExample_MT.cpp @@ -0,0 +1,243 @@ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +/* + Plugin invocation: + ================== + This plugin behaves like a main program. + Invoke the plugin with something like this: + + geoPluginRun -volmgr -destroy -plugin DD4hep_ConditionExample_MT \ + -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml + + Populate the conditions store by hand for a set of IOVs. + Then compute the corresponding alignment entries.... + +*/ +// Framework include files +#include "ConditionExampleObjects.h" +#include "DDCond/ConditionsManagerObject.h" +#include "DD4hep/Factories.h" +#include "TStatistic.h" +#include "TTimeStamp.h" +#include "TRandom3.h" + +#include <mutex> +#include <thread> +#include <unistd.h> + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::ConditionExamples; + +namespace { + mutex printout_lock; + class EventQueue { + vector<std::pair<long,long> > events; + mutex guard; + public: + EventQueue() = default; + ~EventQueue() = default; + void push(const std::pair<long,long>& e) { + lock_guard<mutex> lock(guard); + events.push_back(e); + } + long get() { + if ( !events.empty() ) { + lock_guard<mutex> lock(guard); + if ( !events.empty() ) { + pair<long,long>& last = events.back(); + if ( --last.second > 0 ) + return last.first; + long iov = last.first; + events.pop_back(); + return iov; + } + } + return -1; + } + }; + class Statistics { + public: + TStatistic create, prepare, access; + Statistics() : create("Creation"), prepare("Prepare"), access("Access") { } + void print() const { + printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld", + create.GetName(), create.GetMean(), create.GetMeanErr(), + create.GetRMS(), create.GetN()); + printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld", + prepare.GetName(), prepare.GetMean(), prepare.GetMeanErr(), + prepare.GetRMS(), prepare.GetN()); + printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld", + access.GetName(), access.GetMean(), access.GetMeanErr(), + access.GetRMS(), access.GetN()); + printout(INFO,"Statistics","+========================================================================="); + } + }; + class Executor { + public: + ConditionsManager manager; + EventQueue& events; + ConditionsSlice* slice; + const IOVType* iovTyp; + Statistics& stats; + int identifier; + Executor(ConditionsManager m, const IOVType* typ, int id, EventQueue& q, Statistics& s) + : manager(m), events(q), slice(0), iovTyp(typ), stats(s), identifier(id) + { + } + virtual ~Executor() { + delete slice; + } + int accessConditions(const IOV& iov) { + TTimeStamp start; + ConditionsDataAccess access(iov, slice->pool.get()); + int count = access.processElement(manager->lcdd().world()); + TTimeStamp stop; + stats.access.Fill(stop.AsDouble()-start.AsDouble()); + return count; + } + void run() { + int num_reuse = 0; + int num_access = 0; + for(long iov_val=events.get(), last_iov=-1; iov_val>0; iov_val=events.get()) { + IOV iov(iovTyp, iov_val); + if ( iov_val != last_iov ) { + TTimeStamp start; + IOV pool_iov(slice->pool.get() ? slice->pool->validity() : iov); + ConditionsManager::Result res = manager.prepare(iov,*slice); + TTimeStamp stop; + stats.prepare.Fill(stop.AsDouble()-start.AsDouble()); + last_iov = iov_val; + // Now compute the tranformation matrices + { + lock_guard<mutex> lock(printout_lock); + printout(INFO,"Re-use","Thread:%3d Conditions reused: %d times. " + "Number of accesses:%d IOV:%s", + identifier, num_reuse, num_access, pool_iov.str().c_str()); + printout(INFO,"Prepare","Thread:%3d Total %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld) of type %s [%8.3f sec]", + identifier, res.total(), res.selected, res.loaded, res.computed, res.missing, + iov.str().c_str(), stop.AsDouble()-start.AsDouble()); + } + num_access = accessConditions(iov); + num_reuse = 0; + continue; + } + ++num_reuse; + ::usleep(10000); + num_access += accessConditions(iov); + } + } + }; +} + +/// Plugin function: Condition program example +/** + * Factory: DD4hep_ConditionExample_stress + * + * \author M.Frank + * \version 1.0 + * \date 01/12/2016 + */ +static int condition_example (Geometry::LCDD& lcdd, int argc, char** argv) { + string input; + int num_iov = 10, num_threads = 1; + bool arg_error = false; + for(int i=0; i<argc && argv[i]; ++i) { + if ( 0 == ::strncmp("-input",argv[i],4) ) + input = argv[++i]; + else if ( 0 == ::strncmp("-iovs",argv[i],4) ) + num_iov = ::atol(argv[++i]); + else if ( 0 == ::strncmp("-threads",argv[i],4) ) + num_threads = ::atol(argv[++i]); + else + arg_error = true; + } + if ( arg_error || input.empty() ) { + /// Help printout describing the basic command line interface + cout << + "Usage: -plugin <name> -arg [-arg] \n" + " name: factory name DD4hep_ConditionExample_MT \n" + " -input <string> Geometry file \n" + " -iovs <number> Number of parallel IOV slots for processing. \n" + " -runs <number> Number of collision loads to be performed. \n" + " -threads <number> Number of execution threads. \n" + "\tArguments given: " << arguments(argc,argv) << endl << flush; + ::exit(EINVAL); + } + + // First we load the geometry + lcdd.fromXML(input); + installManagers(lcdd); + + /******************** Initialize the conditions manager *****************/ + ConditionsManager condMgr = ConditionsManager::from(lcdd); + condMgr["PoolType"] = "DD4hep_ConditionsLinearPool"; + condMgr["UserPoolType"] = "DD4hep_ConditionsMapUserPool"; + condMgr["UpdatePoolType"] = "DD4hep_ConditionsLinearUpdatePool"; + condMgr.initialize(); + + const IOVType* iov_typ = condMgr.registerIOVType(0,"run").second; + if ( 0 == iov_typ ) { + except("ConditionsPrepare","++ Unknown IOV type supplied."); + } + + /******************** Now as usual: create the slice ********************/ + dd4hep_ptr<ConditionsSlice> slice(Conditions::createSlice(condMgr,*iov_typ)); + ConditionsKeys(DEBUG).process(lcdd.world(),0,true); + ConditionsDependencyCreator(*slice,DEBUG).process(lcdd.world(),0,true); + + Statistics stats; + /******************** Populate the conditions store *********************/ + // Have e.g. 10 run-slices [1,10], [11,20] .... [91,100] + for(int i=0; i<num_iov; ++i) { + TTimeStamp start; + IOV iov(iov_typ, IOV::Key(1+i*10,(i+1)*10)); + ConditionsPool* pool = condMgr.registerIOV(*iov.iovType, iov.key()); + ConditionsCreator creator(condMgr, pool, DEBUG); // Use a generic creator + creator.slice = slice.get(); + creator.process(lcdd.world(),0,true); // Create conditions with all deltas + TTimeStamp stop; + stats.create.Fill(stop.AsDouble()-start.AsDouble()); + printout(INFO,"Example", "Setup %ld conditions for IOV:%s [%8.3f sec]", + creator.conditionCount, iov.str().c_str(), + stop.AsDouble()-start.AsDouble()); + } + + // ++++++++++++++++++++++++ Now compute the conditions for each of these IOVs + EventQueue events; + for(int i=0; i<num_iov; ++i) { + for(int j=0; j<2; ++j) { + events.push(make_pair((i*10)+j,30)); + } + } + vector<thread*> threads; + for(int i=0; i<num_threads; ++i) { + Executor* exec = new Executor(condMgr, iov_typ, i, events, stats); + exec->slice = new ConditionsSlice(*slice); + thread* t = new thread( [exec]{ exec->run(); delete exec; }); + threads.push_back(t); + } + for(thread* t : threads) { + t->join(); + delete t; + } + printout(INFO,"Statistics", + "+======= Summary: # of IOV: %3d # of Threads: %3d ========================", + num_iov, num_threads); + stats.print(); + // All done. + return 1; +} + +// first argument is the type from the xml file +DECLARE_APPLY(DD4hep_ConditionExample_MT,condition_example) diff --git a/examples/Conditions/src/ConditionExample_populate.cpp b/examples/Conditions/src/ConditionExample_populate.cpp index 492c448823de7198f658b215110f15ef6602ae09..0c45ff082818236cc1d3db838d435fa41180843b 100644 --- a/examples/Conditions/src/ConditionExample_populate.cpp +++ b/examples/Conditions/src/ConditionExample_populate.cpp @@ -99,7 +99,7 @@ static int condition_example (Geometry::LCDD& lcdd, int argc, char** argv) { // Attach the proper set of conditions to the user pool ConditionsManager::Result r = condMgr.prepare(req_iov,*slice); if ( 0 == i ) { // First one we print... - ConditionsPrinter printer(slice->pool().get(),"Example"); + ConditionsPrinter printer(slice->pool.get(),"Example"); Scanner().scan(printer,lcdd.world()); } // Now compute the tranformation matrices diff --git a/examples/Conditions/src/ConditionExample_stress.cpp b/examples/Conditions/src/ConditionExample_stress.cpp index 4769068cae0603067d955629dda20c3675543c6c..8c260301c16c524f5da972872cbe3ee62d6a8baf 100644 --- a/examples/Conditions/src/ConditionExample_stress.cpp +++ b/examples/Conditions/src/ConditionExample_stress.cpp @@ -74,7 +74,7 @@ static int condition_example (Geometry::LCDD& lcdd, int argc, char** argv) { /******************** Initialize the conditions manager *****************/ ConditionsManager condMgr = ConditionsManager::from(lcdd); - condMgr["PoolType"] = "DD4hep_ConditionsMappedPool"; + condMgr["PoolType"] = "DD4hep_ConditionsLinearPool"; condMgr["UserPoolType"] = "DD4hep_ConditionsMapUserPool"; condMgr["UpdatePoolType"] = "DD4hep_ConditionsLinearUpdatePool"; condMgr.initialize();