diff --git a/DDCond/include/DDCond/ConditionsDependencyHandler.h b/DDCond/include/DDCond/ConditionsDependencyHandler.h index b1a0136f6ec459fc0429f4d281837882ce73ba4e..0fafb94278c4bc13b2129ba38d344ad9f5761687 100644 --- a/DDCond/include/DDCond/ConditionsDependencyHandler.h +++ b/DDCond/include/DDCond/ConditionsDependencyHandler.h @@ -133,18 +133,18 @@ namespace dd4hep { /// Access to the detector description instance virtual Detector& detectorDescription() const override; /// Access to the conditions manager - virtual Ref_t manager() const override { return m_manager; } + virtual Ref_t manager() const override { return m_manager; } /// Access to pool IOV - virtual const IOV& requiredValidity() const override { return m_pool.validity(); } + virtual const IOV& requiredValidity() const override { return m_pool.validity(); } /// Accessor for the current conditons mapping - virtual ConditionsMap& conditionsMap() const override { return m_pool; } + virtual ConditionsMap& conditionsMap() const override { return m_pool; } /// ConditionResolver implementation: Interface to access conditions. - virtual Condition get(const ConditionKey& key) override { return get(key.hash); } + virtual Condition get(const ConditionKey& key) override { return get(key.hash, true); } /// Interface to access conditions by conditions key virtual Condition get(const ConditionKey& key, bool throw_if_not) override - { return get(key.hash, throw_if_not); } + { return get(key.hash, throw_if_not); } /// ConditionResolver implementation: Interface to access conditions - virtual Condition get(Condition::key_type key) override { return get(key, true); } + virtual Condition get(Condition::key_type key) override { return get(key, true); } /// Interface to access conditions by hash value virtual Condition get(Condition::key_type key, bool throw_if_not) override; /// Interface to access conditions by hash value of the DetElement (only valid at resolve!) diff --git a/DDCond/src/ConditionsDependencyHandler.cpp b/DDCond/src/ConditionsDependencyHandler.cpp index d0f5fd672ef500272a7a6426551353cb5f440ea4..8f332da2d57b05e81b45c598859d46db15c3aba7 100644 --- a/DDCond/src/ConditionsDependencyHandler.cpp +++ b/DDCond/src/ConditionsDependencyHandler.cpp @@ -50,6 +50,9 @@ Condition ConditionsDependencyHandler::Work::resolve(Work*& current) { Work* previous = current; current = this; state = RESOLVED; + if ( !condition ) { + printout(ERROR,"ConditionsDependency","ERROR: Cannot resolve not existing conditions."); + } context.dependency->callback->resolve(condition, context); previous->do_intersection(iov); current = previous; @@ -57,8 +60,8 @@ Condition ConditionsDependencyHandler::Work::resolve(Work*& current) { } /// Default constructor -ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManager mgr, - UserPool& pool, +ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManager mgr, + UserPool& pool, const Dependencies& dependencies, ConditionUpdateUserContext* user_param) : m_manager(mgr.access()), m_pool(pool), m_dependencies(dependencies), @@ -93,10 +96,12 @@ void ConditionsDependencyHandler::compute() { for( const auto& i : m_todo ) { if ( !i.second->condition ) { do_callback(i.second); - continue; + if ( !i.second->condition ) { + except("ConditionsDependencyHandler", + "Derived condition was not created after calling the creation callback!"); + } } // printout(INFO,"UserPool","Already calcluated: %s",d->name()); - continue; } } diff --git a/examples/Conditions/CMakeLists.txt b/examples/Conditions/CMakeLists.txt index 1d42e62759a940d1efa7b14279f9d7d7f204ce04..30f09ea16fe0ff23109075daa1520ae169cd580f 100644 --- a/examples/Conditions/CMakeLists.txt +++ b/examples/Conditions/CMakeLists.txt @@ -71,7 +71,7 @@ dd4hep_add_test_reg( Conditions_Telescope_populate COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_Conditions.sh" EXEC_ARGS geoPluginRun -destroy -plugin DD4hep_ConditionExample_populate -input file:${CMAKE_INSTALL_PREFIX}/examples/AlignDet/compact/Telescope.xml -iovs 5 - REGEX_PASS "Accessed a total of 900 conditions \\(S: 500,L: 0,C: 400,M:0\\)" + REGEX_PASS "Accessed a total of 1000 conditions \\(S: 500,L: 0,C: 500,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -80,7 +80,7 @@ dd4hep_add_test_reg( Conditions_Telescope_stress COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_Conditions.sh" EXEC_ARGS geoPluginRun -destroy -plugin DD4hep_ConditionExample_stress -input file:${CMAKE_INSTALL_PREFIX}/examples/AlignDet/compact/Telescope.xml -iovs 10 -runs 20 - REGEX_PASS "\\+ Accessed a total of 3600 conditions \\(S: 2880,L: 0,C: 720,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 4000 conditions \\(S: 3100,L: 0,C: 900,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -89,7 +89,7 @@ dd4hep_add_test_reg( Conditions_Telescope_stress2 COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_Conditions.sh" EXEC_ARGS geoPluginRun -destroy -plugin DD4hep_ConditionExample_stress2 -input file:${CMAKE_INSTALL_PREFIX}/examples/AlignDet/compact/Telescope.xml -iovs 10 - REGEX_PASS "\\+ Accessed a total of 1800 conditions \\(S: 1000,L: 0,C: 800,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 2000 conditions \\(S: 1000,L: 0,C: 1000,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -98,7 +98,7 @@ dd4hep_add_test_reg( Conditions_Telescope_MT_LONGTEST COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_Conditions.sh" EXEC_ARGS geoPluginRun -destroy -plugin DD4hep_ConditionExample_MT -input file:${CMAKE_INSTALL_PREFIX}/examples/AlignDet/compact/Telescope.xml -iovs 30 -runs 10 -threads 1 - REGEX_PASS "\\+ Accessed a total of 322200 conditions \\(S:298200,L: 0,C: 24000,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 358000 conditions \\(S:328000,L: 0,C: 30000,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -108,7 +108,7 @@ dd4hep_add_test_reg( Conditions_Telescope_root_save EXEC_ARGS geoPluginRun -print WARNING -destroy -plugin DD4hep_ConditionExample_save -input file:${CMAKE_INSTALL_PREFIX}/examples/AlignDet/compact/Telescope.xml -iovs 30 -conditions TelescopeConditions.root - REGEX_PASS "\\+ Successfully saved 14400 condition to file." + REGEX_PASS "\\+ Successfully saved 16200 condition to file." REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -119,7 +119,7 @@ dd4hep_add_test_reg( Conditions_Telescope_root_load_iov -input file:${CMAKE_INSTALL_PREFIX}/examples/AlignDet/compact/Telescope.xml -conditions TelescopeConditions.root -iovs 30 -restore iovpool DEPENDS Conditions_Telescope_root_save - REGEX_PASS "\\+ Accessed a total of 5400 conditions \\(S: 4800,L: 0,C: 600,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 6000 conditions \\(S: 5400,L: 0,C: 600,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -130,7 +130,7 @@ dd4hep_add_test_reg( Conditions_Telescope_root_load_usr -input file:${CMAKE_INSTALL_PREFIX}/examples/AlignDet/compact/Telescope.xml -conditions TelescopeConditions.root -iovs 30 -restore userpool DEPENDS Conditions_Telescope_root_save - REGEX_PASS "\\+ Accessed a total of 5400 conditions \\(S: 4800,L: 0,C: 600,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 6000 conditions \\(S: 5400,L: 0,C: 600,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -141,7 +141,7 @@ dd4hep_add_test_reg( Conditions_Telescope_root_load_pool -input file:${CMAKE_INSTALL_PREFIX}/examples/AlignDet/compact/Telescope.xml -conditions TelescopeConditions.root -iovs 30 -restore condpool DEPENDS Conditions_Telescope_root_save - REGEX_PASS "\\+ Accessed a total of 5400 conditions \\(S: 4800,L: 0,C: 600,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 6000 conditions \\(S: 5400,L: 0,C: 600,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -150,7 +150,7 @@ dd4hep_add_test_reg( Conditions_CLICSiD_stress_LONGTEST COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_Conditions.sh" EXEC_ARGS geoPluginRun -destroy -plugin DD4hep_ConditionExample_stress -input file:${DD4hep_ROOT}/DDDetectors/compact/SiD.xml -iovs 10 -runs 100 - REGEX_PASS "\\+ Accessed a total of 31596300 conditions \\(S:30192020,L: 0,C:1404280,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 35107000 conditions \\(S:33351650,L: 0,C:1755350,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -159,7 +159,7 @@ dd4hep_add_test_reg( Conditions_CLICSiD_stress2_LONGTEST COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_Conditions.sh" EXEC_ARGS geoPluginRun -destroy -plugin DD4hep_ConditionExample_stress2 -input file:${DD4hep_ROOT}/DDDetectors/compact/SiD.xml -iovs 20 - REGEX_PASS "\\+ Accessed a total of 6319260 conditions \\(S:3510700,L: 0,C:2808560,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 7021400 conditions \\(S:3510700,L: 0,C:3510700,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -168,7 +168,7 @@ dd4hep_add_test_reg( Conditions_CLICSiD_MT_LONGTEST COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_Conditions.sh" EXEC_ARGS geoPluginRun -destroy -plugin DD4hep_ConditionExample_MT -input file:${DD4hep_ROOT}/DDDetectors/compact/SiD.xml -iovs 3 -runs 2 -threads 1 - REGEX_PASS "\\+ Accessed a total of 10742742 conditions \\(S:9900174,L: 0,C:842568,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 11936380 conditions \\(S:10883170,L: 0,C:1053210,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -178,7 +178,7 @@ dd4hep_add_test_reg( Conditions_CLICSiD_root_save_LONGTEST EXEC_ARGS geoPluginRun -print WARNING -destroy -plugin DD4hep_ConditionExample_save -input file:${DD4hep_ROOT}/DDDetectors/compact/SiD.xml -iovs 3 -conditions CLICSiDConditions.root - REGEX_PASS "\\+ Successfully saved 2527704 condition to file." + REGEX_PASS "\\+ Successfully saved 2843667 condition to file." REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -189,7 +189,7 @@ dd4hep_add_test_reg( Conditions_CLICSiD_root_load_iov_LONGTEST -input file:${DD4hep_ROOT}/DDDetectors/compact/SiD.xml -iovs 3 -restore iovpool -conditions CLICSiDConditions.root DEPENDS Conditions_CLICSiD_root_save_LONGTEST - REGEX_PASS "\\+ Accessed a total of 947889 conditions \\(S:842568,L: 0,C:105321,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 1053210 conditions \\(S:947889,L: 0,C:105321,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -200,7 +200,7 @@ dd4hep_add_test_reg( Conditions_CLICSiD_root_load_usr_LONGTEST -input file:${DD4hep_ROOT}/DDDetectors/compact/SiD.xml -iovs 3 -restore userpool -conditions CLICSiDConditions.root DEPENDS Conditions_CLICSiD_root_save_LONGTEST - REGEX_PASS "\\+ Accessed a total of 947889 conditions \\(S:842568,L: 0,C:105321,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 1053210 conditions \\(S:947889,L: 0,C:105321,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) # @@ -211,6 +211,6 @@ dd4hep_add_test_reg( Conditions_CLICSiD_root_load_cond_LONGTEST -input file:${DD4hep_ROOT}/DDDetectors/compact/SiD.xml -iovs 3 -restore condpool -conditions CLICSiDConditions.root DEPENDS Conditions_CLICSiD_root_save_LONGTEST - REGEX_PASS "\\+ Accessed a total of 947889 conditions \\(S:842568,L: 0,C:105321,M:0\\)" + REGEX_PASS "\\+ Accessed a total of 1053210 conditions \\(S:947889,L: 0,C:105321,M:0\\)" REGEX_FAIL " ERROR ;EXCEPTION;Exception" ) diff --git a/examples/Conditions/src/ConditionExampleObjects.cpp b/examples/Conditions/src/ConditionExampleObjects.cpp index a2789a5ecb04c4dcb02775c734cb8102d33bd3ff..38659d65e0eb1e69634833d5ef0a7f5559b6eb69 100644 --- a/examples/Conditions/src/ConditionExampleObjects.cpp +++ b/examples/Conditions/src/ConditionExampleObjects.cpp @@ -130,6 +130,42 @@ void ConditionUpdate3::resolve(Condition target, ConditionUpdateContext& context data.insert(data.end(), c2.begin(), c2.end()); } +/// Interface to client Callback in order to update the condition +Condition ConditionUpdate4::operator()(const ConditionKey& key, ConditionUpdateContext&) { +#ifdef DD4HEP_CONDITIONS_DEBUG + printout(printLevel,"ConditionUpdate3","++ Building dependent condition: %016llX [%s]",key.hash, key.name.c_str()); + Condition target(key.name,"derived"); +#else + printout(printLevel,"ConditionUpdate3","++ Building dependent condition: %016llX",key.hash); + Condition target(key.hash); +#endif + target.bind<vector<int> >(); + return target; +} + +/// Interface to client Callback in order to update the condition +void ConditionUpdate4::resolve(Condition target, ConditionUpdateContext& context) { + vector<int>& data = target.get<vector<int> >(); + Condition cond3 = context.condition(context.key(0)); + Condition cond2 = context.condition(context.key(1)); + Condition cond0 = context.condition(context.key(2)); + Condition cond1 = context.condition(context.key(3)); + + // Ensure the data are really accessible + if ( typeid(*cond0.ptr()) == typeid(detail::ConditionObject) ) { } + if ( typeid(*cond1.ptr()) == typeid(detail::ConditionObject) ) { } + if ( typeid(*cond2.ptr()) == typeid(detail::ConditionObject) ) { } + if ( typeid(*cond3.ptr()) == typeid(detail::ConditionObject) ) { } + + data.push_back(cond0.get<int>()); + data.push_back(cond0.get<int>()*2); + vector<int>& c1 = cond1.get<vector<int> >(); + data.insert(data.end(), c1.begin(), c1.end()); + + vector<int>& c2 = cond2.get<vector<int> >(); + data.insert(data.end(), c2.begin(), c2.end()); +} + /// Initializing constructor ConditionsDependencyCreator::ConditionsDependencyCreator(ConditionsContent& c, PrintLevel p, bool persist) : OutputLevel(p), content(c), persist_conditions(persist) @@ -138,6 +174,7 @@ ConditionsDependencyCreator::ConditionsDependencyCreator(ConditionsContent& c, P call1 = std::shared_ptr<ConditionUpdateCall>(new ConditionUpdate1(printLevel)); call2 = std::shared_ptr<ConditionUpdateCall>(new ConditionUpdate2(printLevel)); call3 = std::shared_ptr<ConditionUpdateCall>(new ConditionUpdate3(printLevel)); + call4 = std::shared_ptr<ConditionUpdateCall>(new ConditionUpdate4(printLevel)); } /// Destructor @@ -151,10 +188,12 @@ int ConditionsDependencyCreator::operator()(DetElement de, int) const { ConditionKey target1(de,"derived_data/derived_1"); ConditionKey target2(de,"derived_data/derived_2"); ConditionKey target3(de,"derived_data/derived_3"); + ConditionKey target4(de,"derived_data/derived_4"); DependencyBuilder sbuild_1(de, starget1.item_key(), scall1); DependencyBuilder build_1(de, target1.item_key(), call1); DependencyBuilder build_2(de, target2.item_key(), call2); DependencyBuilder build_3(de, target3.item_key(), call3); + DependencyBuilder build_4(de, target4.item_key(), call4); // Compute the derived stuff sbuild_1.add(key); @@ -166,12 +205,20 @@ int ConditionsDependencyCreator::operator()(DetElement de, int) const { build_3.add(key); build_3.add(target1); build_3.add(target2); + + /// Make here some random dependencies + build_4.add(target3); + build_4.add(target2); + build_4.add(key); + build_4.add(target1); + if ( !persist_conditions ) { content.addDependency(sbuild_1.release()); } content.addDependency(build_1.release()); content.addDependency(build_2.release()); content.addDependency(build_3.release()); + content.addDependency(build_4.release()); printout(printLevel,"Example","++ Added derived conditions dependencies for %s",de.path().c_str()); return 1; } @@ -194,10 +241,19 @@ int ConditionsDataAccess::accessConditions(DetElement de, const std::vector<Cond ConditionKey key_derived1 (de,"derived_data/derived_1"); ConditionKey key_derived2 (de,"derived_data/derived_2"); ConditionKey key_derived3 (de,"derived_data/derived_3"); + ConditionKey key_derived4 (de,"derived_data/derived_4"); int result = 0, count = 0; // Let's go for the deltas.... for( auto cond : conditions ) { + const auto& info = typeid(*cond.ptr()); + if ( info != typeid(detail::ConditionObject) ) { + printout(ERROR,"accessConditions","Condition with bad base class!"); + } + if ( 0 == dynamic_cast<detail::ConditionObject*>(cond.ptr()) ) { + printout(ERROR,"accessConditions","Condition with bad base class!"); + } + if ( cond.item_key() == key_temperature.item_key() ) { result += int(cond.get<double>()); } @@ -222,6 +278,9 @@ int ConditionsDataAccess::accessConditions(DetElement de, const std::vector<Cond else if ( cond.item_key() == key_derived3.item_key() ) { result += int(cond.get<vector<int> >().size()); } + else if ( cond.item_key() == key_derived4.item_key() ) { + result += int(cond.get<vector<int> >().size()); + } else if ( cond.item_key() == key_noctor_1.item_key() ) { const NonDefaultCtorCond& c = cond.get<NonDefaultCtorCond>(); result += c.a + c.b + c.b + c.d; diff --git a/examples/Conditions/src/ConditionExampleObjects.h b/examples/Conditions/src/ConditionExampleObjects.h index 8126fcd261d40990f21a605a73f4b6c153dcd352..f4f70d2ff15ef24c292a7bb85c49aea2ff1492c1 100644 --- a/examples/Conditions/src/ConditionExampleObjects.h +++ b/examples/Conditions/src/ConditionExampleObjects.h @@ -168,6 +168,26 @@ namespace dd4hep { virtual void resolve(Condition condition, ConditionUpdateContext& context) override final; }; + /// Specialized conditions update callback + /** + * Used by clients to update a condition. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionUpdate4 : public ConditionUpdateCall, public OutputLevel { + public: + /// Initializing constructor + ConditionUpdate4(PrintLevel p) : OutputLevel(p) { } + /// Default destructor + virtual ~ConditionUpdate4() = default; + /// Interface to client Callback in order to update the condition + virtual Condition operator()(const ConditionKey& key, ConditionUpdateContext& context) override final; + /// Interface to client Callback in order to update the condition + virtual void resolve(Condition condition, ConditionUpdateContext& context) override final; + }; + /// This is important, otherwise the register and forward calls won't find them! /** * \author M.Frank @@ -196,7 +216,7 @@ namespace dd4hep { /// Content object to be filled ConditionsContent& content; /// Three different update call types - std::shared_ptr<ConditionUpdateCall> scall1, call1, call2, call3; + std::shared_ptr<ConditionUpdateCall> scall1, call1, call2, call3, call4; /// Flag for special setup for ROOT persistency bool persist_conditions; /// Constructor