Skip to content

Commit

Permalink
Fix bug in DDDB conditions loading. Add Gaudi-like conditions service…
Browse files Browse the repository at this point in the history
… to DDDB
  • Loading branch information
MarkusFrankATcernch committed Apr 5, 2018
1 parent 00065e6 commit 6f1ec6e
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 40 deletions.
16 changes: 10 additions & 6 deletions DDCond/include/DDCond/ConditionsCleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define DDCOND_CONDITIONSCLEANUP_H

// Framework include files
#include "DDCond/ConditionsManager.h"
#include "DDCond/ConditionsPool.h"

/// Namespace for the AIDA detector description toolkit
namespace dd4hep {
Expand All @@ -39,8 +39,10 @@ namespace dd4hep {
virtual ~ConditionsCleanup() = default;
/// Assignment operator
ConditionsCleanup& operator=(const ConditionsCleanup& c) = default;
/// Cleanup operation
virtual void operator()(ConditionsManager mgr) const = 0;
/// Request cleanup operation of IOV POOL
virtual bool operator()(const ConditionsIOVPool& iov_pool) const;
/// Request cleanup operation of regular conditiions pool
virtual bool operator()(const ConditionsPool& pool) const;
};

/// Base class to handle conditions cleanups
Expand All @@ -60,10 +62,12 @@ namespace dd4hep {
virtual ~ConditionsFullCleanup() = default;
/// Assignment operator
ConditionsFullCleanup& operator=(const ConditionsFullCleanup& c) = default;
/// Cleanup operation
virtual void operator()(ConditionsManager mgr) const override;
/// Request cleanup operation of IOV POOL
virtual bool operator()(const ConditionsIOVPool& iov_pool) const override;
/// Request cleanup operation of regular conditiions pool
virtual bool operator()(const ConditionsPool& pool) const override;
};
} /* End namespace cond */
} /* End namespace cond */
} /* End namespace dd4hep */

#endif /* DDCOND_CONDITIONSCLEANUP_H */
4 changes: 4 additions & 0 deletions DDCond/include/DDCond/ConditionsIOVPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ namespace dd4hep {
/// Remove all key based pools with an age beyon the minimum age.
/** @return Number of conditions cleaned up and removed. */
int clean(int max_age);

/// Invoke cache cleanup with user defined policy
/** @return pair<Number of pools cleared, Number of conditions cleaned up and removed> */
int clean(const ConditionsCleanup& cleaner);
};

} /* End namespace cond */
Expand Down
4 changes: 4 additions & 0 deletions DDCond/include/DDCond/ConditionsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace dd4hep {
class UserPool;
class ConditionsPool;
class ConditionsSlice;
class ConditionsCleanup;
class ConditionsIOVPool;
class ConditionsDataLoader;
class ConditionsManagerObject;
Expand Down Expand Up @@ -156,6 +157,9 @@ namespace dd4hep {
*/
void pushUpdates() const;

/// Invoke cache cleanup with user defined policy
void clean(const ConditionsCleanup& cleaner) const;

/// Clean conditions, which are above the age limit.
void clean(const IOVType* typ, int max_age) const;

Expand Down
3 changes: 3 additions & 0 deletions DDCond/include/DDCond/ConditionsManagerObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ namespace dd4hep {
/** @return Number of conditions cleaned/removed from the IOV pool of the given type */
virtual int clean(const IOVType* typ, int max_age) = 0;

/// Invoke cache cleanup with user defined policy
virtual std::pair<int,int> clean(const ConditionsCleanup& cleaner) = 0;

/// Full cleanup of all managed conditions.
/** @return pair<Number of pools cleared, Number of conditions cleaned up and removed> */
virtual std::pair<int,int> clear() = 0;
Expand Down
4 changes: 4 additions & 0 deletions DDCond/include/DDCond/Type1/Manager_Type1.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ namespace dd4hep {
/** @return Number of conditions cleaned/removed from the IOV pool of the given type */
int clean(const IOVType* typ, int max_age) final;

/// Invoke cache cleanup with user defined policy
/** @return pair<Number of pools cleared, Number of conditions cleaned up and removed> */
std::pair<int,int> clean(const ConditionsCleanup& cleaner) 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() final;
Expand Down
27 changes: 23 additions & 4 deletions DDCond/src/ConditionsCleanup.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//==========================================================================
// AIDA Detector description implementation
// AIDA Detector description implementation
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
Expand All @@ -16,7 +16,26 @@

using namespace dd4hep::cond;

/// Cleanup operation
void ConditionsFullCleanup::operator()(ConditionsManager mgr) const {
mgr.clear();
/// Request cleanup operation of IOV POOL
bool ConditionsCleanup::operator()(const ConditionsIOVPool & /* iov_pool */) const
{
return false;
}

/// Request cleanup operation of regular conditiions pool
bool ConditionsCleanup::operator()(const ConditionsPool & /* iov_pool */) const
{
return true;
}

/// Request cleanup operation of IOV POOL
bool ConditionsFullCleanup::operator()(const ConditionsIOVPool & /* iov_pool */) const
{
return true;
}

/// Request cleanup operation of regular conditiions pool
bool ConditionsFullCleanup::operator()(const ConditionsPool & /* iov_pool */) const
{
return true;
}
21 changes: 20 additions & 1 deletion DDCond/src/ConditionsIOVPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#include "DD4hep/Printout.h"
#include "DD4hep/InstanceCount.h"
#include "DDCond/ConditionsIOVPool.h"
#include "DD4hep/detail/ConditionsInterna.h"
#include "DDCond/ConditionsCleanup.h"
#include "DDCond/ConditionsDataLoader.h"

#include "DD4hep/detail/ConditionsInterna.h"

using namespace dd4hep;
using namespace dd4hep::cond;

Expand Down Expand Up @@ -66,6 +68,23 @@ size_t ConditionsIOVPool::selectRange(Condition::key_type key, const IOV& req_va
return result.size() - len;
}

/// Invoke cache cleanup with user defined policy
int ConditionsIOVPool::clean(const ConditionsCleanup& cleaner) {
Elements rest;
int count = 0;
for( const auto& e : elements ) {
const ConditionsPool* p = e.second.get();
if ( cleaner (*p) ) {
count += e.second->size();
e.second->print("Remove");
continue;
}
rest.insert(e);
}
elements = std::move(rest);
return count;
}

/// Remove all key based pools with an age beyon the minimum age
int ConditionsIOVPool::clean(int max_age) {
Elements rest;
Expand Down
5 changes: 5 additions & 0 deletions DDCond/src/ConditionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ void ConditionsManager::clean(const IOVType* typ, int max_age) const {
access()->clean(typ, max_age);
}

/// Invoke cache cleanup with user defined policy
void ConditionsManager::clean(const ConditionsCleanup& cleaner) const {
access()->clean(cleaner);
}

/// Full cleanup of all managed conditions.
void ConditionsManager::clear() const {
access()->clear();
Expand Down
14 changes: 14 additions & 0 deletions DDCond/src/Type1/Manager_Type1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "DDCond/ConditionsPool.h"
#include "DDCond/ConditionsEntry.h"
#include "DDCond/ConditionsCleanup.h"
#include "DDCond/ConditionsManager.h"
#include "DDCond/ConditionsIOVPool.h"
#include "DDCond/ConditionsDataLoader.h"
Expand Down Expand Up @@ -311,6 +312,19 @@ int Manager_Type1::clean(const IOVType* typ, int max_age) {
return count;
}

/// Invoke cache cleanup with user defined policy
pair<int,int> Manager_Type1::clean(const ConditionsCleanup& cleaner) {
pair<int,int> count(0,0);
for( TypedConditionPool::iterator i=m_rawPool.begin(); i != m_rawPool.end(); ++i) {
ConditionsIOVPool* p = *i;
if ( p && cleaner(*p) ) {
++count.first;
count.second += p->clean(cleaner);
}
}
return count;
}

/// Full cleanup of all managed conditions.
pair<int,int> Manager_Type1::clear() {
pair<int,int> count(0,0);
Expand Down
2 changes: 0 additions & 2 deletions DDCore/src/AlignmentsCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ Result AlignmentsCalculator::compute(const std::map<DetElement, Delta>& deltas,
ConditionsMap& alignments) const
{
Result result;
Calculator obj;
Calculator::Context context(alignments);
// This is a tricky one. We absolutely need the detector elements ordered
// by their depth aka. the distance to /world.
Expand All @@ -235,7 +234,6 @@ Result AlignmentsCalculator::compute(const std::map<DetElement, const Delta*>& d
ConditionsMap& alignments) const
{
Result result;
Calculator obj;
Calculator::Context context(alignments);
// This is a tricky one. We absolutely need the detector elements ordered
// by their depth aka. the distance to /world.
Expand Down
12 changes: 6 additions & 6 deletions DDDB/include/Detector/IDetService.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ namespace gaudi {
typedef dd4hep::cond::ConditionsManager ConditionsManager;
/// Other useful type definitions and type short-cuts
typedef dd4hep::cond::ConditionUpdateUserContext Context;
typedef dd4hep::cond::ConditionDependency Dependency;
typedef dd4hep::cond::ConditionsCleanup Cleanup;
typedef dd4hep::DetElement DetElement;
typedef dd4hep::Condition Condition;
typedef dd4hep::IOV::Key_first_type EventStamp;
typedef dd4hep::IOVType IOVType;
typedef dd4hep::cond::ConditionDependency Dependency;
typedef dd4hep::cond::ConditionsCleanup Cleanup;
typedef dd4hep::DetElement DetElement;
typedef dd4hep::Condition Condition;
typedef dd4hep::IOV::Key_first_type EventStamp;
typedef dd4hep::IOVType IOVType;
typedef std::shared_ptr<dd4hep::cond::ConditionsContent> Content;
typedef std::shared_ptr<dd4hep::cond::ConditionsSlice> Slice;

Expand Down
42 changes: 27 additions & 15 deletions DDDB/src/plugins/DDDBDerivedCondTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ namespace {
}
virtual ~ConditionUpdate1() { }
/// Interface to client Callback in order to update the condition
virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& ctxt) override final {
virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& ) override final {
printout(context.level,"ConditionUpdate1","++ Building dependent condition: %s",key.name.c_str());
Condition target(key.name,"Alignment");
target.bind<AlignmentData>();
return target;
}
/// Interface to client Callback in order to update the condition
void resolve(Condition target, ConditionUpdateContext& ctxt) override final {
try {
AlignmentData& data = target.bind<AlignmentData>();
AlignmentData& data = target.get<AlignmentData>();
Condition cond0 = ctxt.condition(ctxt.key(0));
const Delta& delta = cond0.get<Delta>();
data.delta = delta;
Expand All @@ -94,9 +99,8 @@ namespace {
catch(const exception& exc) {
++context.numFail1;
printout(ERROR,"ConditionUpdate2","++ Failed to build condition %s: %s",
key.name.c_str(), exc.what());
ctxt.key(0).name.c_str(), exc.what());
}
return target;
}
};
/// Specialized conditions update callback for alignments
Expand All @@ -115,11 +119,16 @@ namespace {
}
virtual ~ConditionUpdate2() { }
/// Interface to client Callback in order to update the condition
virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& ctxt) override final {
virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext&) override final {
printout(context.level,"ConditionUpdate2","++ Building dependent condition: %s",key.name.c_str());
Condition target(key.name,"Alignment");
target.bind<AlignmentData>();
return target;
}
/// Interface to client Callback in order to update the condition
void resolve(Condition target, ConditionUpdateContext& ctxt) override final {
try {
AlignmentData& data = target.bind<AlignmentData>();
AlignmentData& data = target.get<AlignmentData>();
Condition cond0 = ctxt.condition(ctxt.key(0));
const Delta& delta0 = cond0.get<Delta>();
const AlignmentData& data1 = ctxt.get<AlignmentData>(ctxt.key(1));
Expand All @@ -131,9 +140,8 @@ namespace {
catch(const exception& exc) {
++context.numFail2;
printout(ERROR,"ConditionUpdate2","++ Failed to build condition %s: %s",
key.name.c_str(), exc.what());
ctxt.key(0).name.c_str(), exc.what());
}
return target;
}
};
/// Specialized conditions update callback for alignments
Expand All @@ -152,15 +160,20 @@ namespace {
}
virtual ~ConditionUpdate3() { }
/// Interface to client Callback in order to update the condition
virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& ctxt) override final {
virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext&) override final {
printout(context.level,"ConditionUpdate3","++ Building dependent condition: %s",key.name.c_str());
Condition target(key.name,"Alignment");
target.bind<AlignmentData>();
return target;
}
/// Interface to client Callback in order to update the condition
void resolve(Condition target, ConditionUpdateContext& ctxt) override final {
try {
AlignmentData& data = target.bind<AlignmentData>();
Condition cond0 = ctxt.condition(ctxt.key(0));
AlignmentData& data = target.get<AlignmentData>();
Condition cond0 = ctxt.condition(ctxt.key(0));
const Delta& delta0 = cond0.get<Delta>();
const AlignmentData& data1 = ctxt.get<AlignmentData>(1);
const AlignmentData& data2 = ctxt.get<AlignmentData>(2);
const AlignmentData& data1 = ctxt.get<AlignmentData>(ctxt.key(1));
const AlignmentData& data2 = ctxt.get<AlignmentData>(ctxt.key(2));
data.delta = delta0;
data.delta = data1.delta;
data.delta = data2.delta;
Expand All @@ -170,9 +183,8 @@ namespace {
catch(const exception& exc) {
++context.numFail3;
printout(ERROR,"ConditionUpdate3","++ Failed to build condition %s: %s",
key.name.c_str(), exc.what());
ctxt.key(0).name.c_str(), exc.what());
}
return target;
}
};

Expand Down
3 changes: 2 additions & 1 deletion DDDB/src/plugins/DeVeloServiceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ namespace {
/// __________________________________________________________________________________
long dump() {
shared_ptr<dd4hep::cond::ConditionsSlice> slice;
IDetService::ConditionsManager manager = m_service->manager();
const IDetService::IOVType* iov_typ = m_service->iovType("epoch");

printout(INFO,"ConditionsManager","+++ Starting conditions dump loop");
Expand Down Expand Up @@ -202,10 +201,12 @@ namespace {
}
}
m_service->cleanup(dd4hep::cond::ConditionsFullCleanup());
printout(dd4hep::ALWAYS,"ServiceTest","Test finished....");
return 1;
}
};

dd4hep::setPrintFormat("%-18s %5s %s");
for(int i=0; i<argc; ++i) {
if ( ::strcmp(argv[i],"-print")==0 ) {
s_PrintLevel = dd4hep::printLevel(argv[++i]);
Expand Down
5 changes: 4 additions & 1 deletion DDDB/src/plugins/DeVeloTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "DDCond/ConditionsSlice.h"
#include "DDCond/ConditionsIOVPool.h"
#include "DDCond/ConditionsCleanup.h"
#include "DDCond/ConditionsManager.h"

#include "DDDB/DDDBHelper.h"
Expand Down Expand Up @@ -200,11 +201,13 @@ namespace {
cout << "Exception(This is GOOD!): " << e.what() << endl;
}
}
m_manager.clear();
m_manager.clean(dd4hep::cond::ConditionsFullCleanup());
printout(dd4hep::ALWAYS,"ServiceTest","Test finished....");
return 1;
}
};

dd4hep::setPrintFormat("%-18s %5s %s");
for(int i=0; i<argc; ++i) {
if ( ::strcmp(argv[i],"-print")==0 ) {
s_PrintLevel = dd4hep::printLevel(argv[++i]);
Expand Down
2 changes: 1 addition & 1 deletion DDDB/src/plugins/DetService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,5 @@ DetService::Slice DetService::project(const string& content,

/// Invoke slice cleanup
void DetService::cleanup(const Cleanup &cleaner) {
cleaner(m_manager);
m_manager.clean(cleaner);
}
3 changes: 1 addition & 2 deletions DDDB/src/plugins/DetService.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ namespace gaudi {
const std::string &address) override;

/// Add a condition functor for a derived condition to the content
virtual void addContent(Content &content,
Dependency *call);
virtual void addContent(Content &content, Dependency *call) override;

/// Close content creation context
virtual void closeContent(Content &content) override;
Expand Down
Loading

0 comments on commit 6f1ec6e

Please sign in to comment.