From 0214f55a33147514e1f8d489ce49a3c1cea3eaea Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Sat, 26 Nov 2016 00:10:27 +0100 Subject: [PATCH] Updates to conditions and alignments. --- DDAlign/include/DDAlign/AlignmentOperators.h | 7 +- DDAlign/include/DDAlign/AlignmentsForward.h | 56 +++++ DDAlign/include/DDAlign/AlignmentsRegister.h | 56 +++++ DDAlign/src/AlignmentsForward.cpp | 67 ++++++ DDAlign/src/AlignmentsManager.cpp | 2 + DDAlign/src/AlignmentsRegister.cpp | 87 ++++++++ DDAlign/src/plugins/AlignmentForward.cpp | 119 ----------- DDAlign/src/plugins/AlignmentPlugins.cpp | 74 ++++++- DDAlign/src/plugins/AlignmentRegister.cpp | 154 -------------- DDCond/CMakeLists.txt | 2 +- DDCond/include/DDCond/AlignmentsLoaderImp.h | 2 +- DDCond/include/DDCond/ConditionsAccess.h | 3 +- DDCond/include/DDCond/ConditionsDataLoader.h | 4 +- .../DDCond/ConditionsDependencyHandler.h | 32 ++- DDCond/include/DDCond/ConditionsIOVPool.h | 1 - DDCond/include/DDCond/ConditionsLoaderImp.h | 2 - DDCond/include/DDCond/ConditionsManager.h | 32 +-- .../include/DDCond/ConditionsManagerObject.h | 167 +++++++++++++++ DDCond/include/DDCond/ConditionsOperators.h | 13 +- DDCond/include/DDCond/ConditionsPool.h | 39 ++-- DDCond/include/DDCond/ConditionsRepository.h | 4 - DDCond/include/DDCond/ConditionsTest.h | 6 +- .../Manager_Type1.h} | 133 ++++-------- DDCond/src/AlignmentsLoaderImp.cpp | 8 +- DDCond/src/ConditionsAccess.cpp | 3 +- DDCond/src/ConditionsDataLoader.cpp | 14 +- DDCond/src/ConditionsDependencyHandler.cpp | 11 +- DDCond/src/ConditionsLoaderImp.cpp | 3 +- DDCond/src/ConditionsManager.cpp | 157 ++++++++++++-- DDCond/src/ConditionsOperators.cpp | 40 ++-- DDCond/src/ConditionsPool.cpp | 6 +- DDCond/src/ConditionsRepository.cpp | 2 +- DDCond/src/ConditionsTest.cpp | 35 +-- DDCond/src/ConditionsTest.h | 72 ------- DDCond/src/ConditionsTextRepository.cpp | 2 +- .../Manager_Type1.cpp} | 201 ++++-------------- DDCond/src/plugins/ConditionsExample.cpp | 2 +- DDCond/src/plugins/ConditionsLinearPool.cpp | 7 +- DDCond/src/plugins/ConditionsMappedPool.cpp | 11 +- DDCond/src/plugins/ConditionsMultiLoader.cpp | 7 +- DDCond/src/plugins/ConditionsParser.cpp | 3 +- DDCond/src/plugins/ConditionsPlugins.cpp | 80 ++++--- .../plugins/ConditionsRepositoryParser.cpp | 9 +- DDCond/src/plugins/ConditionsUserPool.cpp | 48 +++-- DDCond/src/plugins/ConditionsXmlLoader.cpp | 4 +- DDCore/include/DD4hep/AlignedVolumePrinter.h | 2 + DDCore/include/DD4hep/AlignmentsPrinter.h | 2 + DDCore/include/DD4hep/Conditions.h | 1 - .../include/DD4hep}/ConditionsListener.h | 1 - DDCore/include/DD4hep/DetectorProcessor.h | 102 +++++++++ DDCore/include/DD4hep/IOV.h | 5 +- DDCore/include/DD4hep/NamedObject.h | 11 +- .../DD4hep/objects/ConditionsInterna.h | 4 + DDCore/src/AlignedVolumePrinter.cpp | 6 + DDCore/src/AlignmentsPrinter.cpp | 6 + DDCore/src/ConditionsInterna.cpp | 1 + {DDCond => DDCore}/src/ConditionsListener.cpp | 3 +- DDCore/src/DetectorProcessor.cpp | 51 +++++ DDCore/src/Fields.cpp | 3 +- DDCore/src/IOV.cpp | 7 + DDCore/src/NamedObject.cpp | 22 -- DDDB/include/DDDB/DDDBConditionsLoader.h | 2 +- DDDB/src/DDDBConditionsLoader.cpp | 2 +- DDDB/src/DDDBDerivedCondTest.cpp | 2 +- examples/AlignDet/CMakeLists.txt | 3 +- examples/AlignDet/src/AlignmentExample.cpp | 135 ++++++++++++ examples/DDG4/CMakeLists.txt | 2 +- 67 files changed, 1297 insertions(+), 863 deletions(-) create mode 100644 DDAlign/include/DDAlign/AlignmentsForward.h create mode 100644 DDAlign/include/DDAlign/AlignmentsRegister.h create mode 100644 DDAlign/src/AlignmentsForward.cpp create mode 100644 DDAlign/src/AlignmentsRegister.cpp delete mode 100644 DDAlign/src/plugins/AlignmentForward.cpp delete mode 100644 DDAlign/src/plugins/AlignmentRegister.cpp create mode 100644 DDCond/include/DDCond/ConditionsManagerObject.h rename DDCond/include/DDCond/{ConditionsInterna.h => Type1/Manager_Type1.h} (60%) delete mode 100644 DDCond/src/ConditionsTest.h rename DDCond/src/{ConditionsInterna.cpp => Type1/Manager_Type1.cpp} (70%) rename {DDCond/include/DDCond => DDCore/include/DD4hep}/ConditionsListener.h (99%) create mode 100644 DDCore/include/DD4hep/DetectorProcessor.h rename {DDCond => DDCore}/src/ConditionsListener.cpp (94%) create mode 100644 DDCore/src/DetectorProcessor.cpp create mode 100644 examples/AlignDet/src/AlignmentExample.cpp diff --git a/DDAlign/include/DDAlign/AlignmentOperators.h b/DDAlign/include/DDAlign/AlignmentOperators.h index e03665355..ea4b9f817 100644 --- a/DDAlign/include/DDAlign/AlignmentOperators.h +++ b/DDAlign/include/DDAlign/AlignmentOperators.h @@ -93,7 +93,6 @@ namespace DD4hep { template <> void AlignmentActor<DDAlign_standard_operations::node_delete>::operator()(Nodes::value_type& n) const; template <> void AlignmentActor<DDAlign_standard_operations::node_reset>::operator() (Nodes::value_type& n) const; template <> void AlignmentActor<DDAlign_standard_operations::node_align>::operator() (Nodes::value_type& n) const; - - } /* End namespace Geometry */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_ALIGNMENT_ALIGNMENTOPERATORS_H */ + } /* End namespace Alignments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_ALIGNMENT_ALIGNMENTOPERATORS_H */ diff --git a/DDAlign/include/DDAlign/AlignmentsForward.h b/DDAlign/include/DDAlign/AlignmentsForward.h new file mode 100644 index 000000000..fdee57db0 --- /dev/null +++ b/DDAlign/include/DDAlign/AlignmentsForward.h @@ -0,0 +1,56 @@ +//========================================================================== +// 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 +// +//========================================================================== +#ifndef DD4HEP_DDALIGN_ALIGNMENTFORWARD_H +#define DD4HEP_DDALIGN_ALIGNMENTFORWARD_H + +// Framework includes +#include "DD4hep/Alignments.h" +#include "DD4hep/Conditions.h" +#include "DD4hep/Detector.h" +#include "DDAlign/AlignmentsManager.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Alignments { + + // Forward declarations + class AlignmentUpdateCall; + + /// Create lignment dependencies from conditions + /** + * Conditions analyser to select alignments.and create the + * corresponding alignment condition dependencies. + * + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + * \ingroup DD4HEP_DDALIGN + */ + class AlignmentsForward : public DetElement::Processor { + public: + AlignmentsManager alignmentMgr; + AlignmentUpdateCall* updateCall; + Conditions::UserPool* user_pool; + + /// Initializing constructor + AlignmentsForward(AlignmentsManager m, AlignmentUpdateCall* c, UserPool* p); + /// Default destructor + virtual ~AlignmentsForward(); + /// Callback to output conditions information + virtual int processElement(DetElement de); + }; + } /* End namespace Alignments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_DDALIGN_ALIGNMENTFORWARD_H */ diff --git a/DDAlign/include/DDAlign/AlignmentsRegister.h b/DDAlign/include/DDAlign/AlignmentsRegister.h new file mode 100644 index 000000000..82bd54d55 --- /dev/null +++ b/DDAlign/include/DDAlign/AlignmentsRegister.h @@ -0,0 +1,56 @@ +//========================================================================== +// 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 +// +//========================================================================== +#ifndef DD4HEP_DDALIGN_ALIGNMENTREGISTER_H +#define DD4HEP_DDALIGN_ALIGNMENTREGISTER_H + +// Framework includes +#include "DD4hep/Alignments.h" +#include "DD4hep/Conditions.h" +#include "DD4hep/Detector.h" +#include "DDAlign/AlignmentsManager.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Alignments { + + // Forward declarations + class AlignmentUpdateCall; + + /// Create lignment dependencies from conditions + /** + * Conditions analyser to select alignments.and create the + * corresponding alignment condition dependencies. + * + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + * \ingroup DD4HEP_DDALIGN + */ + class AlignmentsRegister : public DetElement::Processor { + public: + AlignmentsManager alignmentMgr; + AlignmentUpdateCall* updateCall; + Conditions::UserPool* user_pool; + + /// Initializing constructor + AlignmentsRegister(AlignmentsManager m, AlignmentUpdateCall* c, UserPool* p); + /// Default destructor + virtual ~AlignmentsRegister(); + /// Callback to output conditions information + virtual int processElement(DetElement de); + }; + } /* End namespace Alignments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_DDALIGN_ALIGNMENTREGISTER_H */ diff --git a/DDAlign/src/AlignmentsForward.cpp b/DDAlign/src/AlignmentsForward.cpp new file mode 100644 index 000000000..9f6fb7c51 --- /dev/null +++ b/DDAlign/src/AlignmentsForward.cpp @@ -0,0 +1,67 @@ +//========================================================================== +// 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 +// +//========================================================================== + +// Framework includes +#include "DD4hep/Printout.h" +#include "DD4hep/DetAlign.h" +#include "DD4hep/DetConditions.h" +#include "DD4hep/objects/AlignmentsInterna.h" + +#include "DDAlign/AlignmentsForward.h" +#include "DDAlign/AlignmentUpdateCall.h" + +using namespace DD4hep; +using namespace DD4hep::Alignments; + +/// Initializing constructor +AlignmentsForward::AlignmentsForward(AlignmentsManager m, AlignmentUpdateCall* c, UserPool* p) + : alignmentMgr(m), updateCall(c), user_pool(p) +{ +} + +/// Default destructor +AlignmentsForward::~AlignmentsForward() { + releasePtr(updateCall); +} + +/// Callback to output conditions information +int AlignmentsForward::processElement(DetElement de) { + if ( de.isValid() ) { + DetElement parent = de.parent(); + if ( parent.isValid() && parent.hasAlignments() && !de.hasAlignments() ) { + DetAlign align(de); + Conditions::ConditionKey k(de.path()+"#alignment/Tranformations"); + // + // The alignment access through the DetElement object is optional! + // It is slow and deprecated. The access using the UserPool directly + // is highly favored. + // + align.alignments()->addKey(k.name); + align.alignments()->addKey("Alignment",k.name); + // + // Now add the dependency to the alignmant manager + Conditions::DependencyBuilder b(k, updateCall->addRef(), de); + bool result = alignmentMgr.adoptDependency(b.release()); + if ( result ) { + printout(INFO,"AlignForward", + "++ Added Alignment child dependency Cond:%s Key:%08X", + k.name.c_str(), k.hash); + return 1; + } + printout(ERROR,"AlignForward", + "++ FAILED to add Alignment dependency Cond:%s Key:%08X", + k.name.c_str(), k.hash); + } + } + return 1; +} diff --git a/DDAlign/src/AlignmentsManager.cpp b/DDAlign/src/AlignmentsManager.cpp index 49d6b33e3..672ffb816 100644 --- a/DDAlign/src/AlignmentsManager.cpp +++ b/DDAlign/src/AlignmentsManager.cpp @@ -17,7 +17,9 @@ #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/MatrixHelpers.h" +#include "DD4hep/ConditionDerived.h" #include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsDependencyCollection.h" #include "DDAlign/AlignmentsManager.h" using namespace DD4hep; diff --git a/DDAlign/src/AlignmentsRegister.cpp b/DDAlign/src/AlignmentsRegister.cpp new file mode 100644 index 000000000..b1a892e22 --- /dev/null +++ b/DDAlign/src/AlignmentsRegister.cpp @@ -0,0 +1,87 @@ +//========================================================================== +// 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 +// +//========================================================================== + +// Framework includes +#include "DD4hep/Printout.h" +#include "DD4hep/DetAlign.h" +#include "DD4hep/DetConditions.h" +#include "DD4hep/objects/AlignmentsInterna.h" + +#include "DDAlign/AlignmentsRegister.h" +#include "DDAlign/AlignmentUpdateCall.h" + +using namespace DD4hep; +using namespace DD4hep::Alignments; + +// ====================================================================================== + +/// Initializing constructor +AlignmentsRegister::AlignmentsRegister(AlignmentsManager m, AlignmentUpdateCall* c, UserPool* p) + : alignmentMgr(m), updateCall(c), user_pool(p) +{ +} + +/// Default destructor +AlignmentsRegister::~AlignmentsRegister() { + releasePtr(updateCall); +} + +/// Callback to output conditions information +int AlignmentsRegister::processElement(DetElement de) { + using Conditions::Condition; + if ( de.isValid() ) { + if ( de.hasConditions() ) { + DetAlign align(de); + Conditions::DetConditions conditions(de); + Conditions::Container cont = conditions.conditions(); + printout(DEBUG,"AlignRegister", + "++ Processing DE %s hasConditions:%s [%d entries]", + de.path().c_str(), yes_no(de.hasConditions()), int(cont.numKeys())); + for ( const auto& c : cont.keys() ) { + Condition cond = cont.get(c.first, *user_pool); + printout(DEBUG,"AlignRegister", + "++ Processing DE %s Cond:%s Key:%08X flags:%d", + de.path().c_str(), cond.name(), cond.key(), cond->flags); + if ( (cond->flags&Condition::ALIGNMENT) ) { + Conditions::ConditionKey k(cond->name+"/Tranformations"); + // + // The alignment access through the DetElement object is optional! + // It is slow and deprecated. The access using the UserPool directly + // is highly favored. + // + align.alignments()->addKey(k.name); + align.alignments()->addKey("Alignment",k.name); + // + // Now add the dependency to the alignmant manager + Conditions::DependencyBuilder b(k, updateCall->addRef(), de); + b.add(Conditions::ConditionKey(cond->name)); + bool result = alignmentMgr.adoptDependency(b.release()); + if ( result ) { + printout(INFO,"AlignRegister", + "++ Added Alignment dependency Cond:%s Key:%08X flags:%d", + k.name.c_str(), k.hash, cond->flags); + continue; + } + printout(ERROR,"AlignRegister", + "++ FAILED to add Alignment dependency Cond:%s Key:%08X flags:%d", + k.name.c_str(), k.hash, cond->flags); + } + } + return 1; + } + printout(DEBUG,"AlignRegister","++ Processing DE %s hasConditions:%s", + de.path().c_str(), yes_no(de.hasConditions())); + } + return 1; +} + diff --git a/DDAlign/src/plugins/AlignmentForward.cpp b/DDAlign/src/plugins/AlignmentForward.cpp deleted file mode 100644 index a684f21f6..000000000 --- a/DDAlign/src/plugins/AlignmentForward.cpp +++ /dev/null @@ -1,119 +0,0 @@ -//========================================================================== -// 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 -// -//========================================================================== - -// Framework includes -#include "DD4hep/Plugins.h" -#include "DD4hep/Printout.h" -#include "DD4hep/DetAlign.h" -#include "DD4hep/DetFactoryHelper.h" -#include "DD4hep/objects/AlignmentsInterna.h" - -#include "DDAlign/AlignmentsManager.h" -#include "DDAlign/AlignmentUpdateCall.h" - -using namespace DD4hep; -using namespace DD4hep::Alignments; - -// ====================================================================================== - -/// Anonymous namespace for plugins -namespace { - - /// Create lignment dependencies from conditions - /** - * Conditions analyser to select alignments.and create the - * corresponding alignment condition dependencies. - * - * \author M.Frank - * \version 1.0 - * \date 31/03/2016 - * \ingroup DD4HEP_DDALIGN - */ - class AlignmentForward : public DetElement::Processor { - public: - LCDD& lcdd; - AlignmentsManager alignmentMgr; - AlignmentUpdateCall* updateCall; - Conditions::UserPool* user_pool; - - /// Initializing constructor - AlignmentForward(LCDD& l, AlignmentUpdateCall* c, UserPool* p) - : lcdd(l), updateCall(c), user_pool(p) - { - alignmentMgr = AlignmentsManager::from(lcdd); - } - /// Default destructor - virtual ~AlignmentForward() { - releasePtr(updateCall); - } - /// Callback to output conditions information - virtual int processElement(DetElement de) { - if ( de.isValid() ) { - DetElement parent = de.parent(); - if ( parent.isValid() && parent.hasAlignments() && !de.hasAlignments() ) { - DetAlign align(de); - Conditions::ConditionKey k(de.path()+"#alignment/Tranformations"); - // - // The alignment access through the DetElement object is optional! - // It is slow and deprecated. The access using the UserPool directly - // is highly favored. - // - align.alignments()->addKey(k.name); - align.alignments()->addKey("Alignment",k.name); - // - // Now add the dependency to the alignmant manager - Conditions::DependencyBuilder b(k, updateCall->addRef(), de); - bool result = alignmentMgr.adoptDependency(b.release()); - if ( result ) { - printout(INFO,"AlignForward", - "++ Added Alignment child dependency Cond:%s Key:%08X", - k.name.c_str(), k.hash); - return 1; - } - printout(ERROR,"AlignForward", - "++ FAILED to add Alignment dependency Cond:%s Key:%08X", - k.name.c_str(), k.hash); - } - } - return 1; - } - }; -} - -#include "DD4hep/PluginTester.h" -#include "DDCond/ConditionsPool.h" -/// Convert alignments conditions to alignment objects -static void* ddalign_AlignmentForward(Geometry::LCDD& lcdd, int argc, char** argv) { - std::vector<char*> args_prepare, args_call; - - for(int i=0; i<argc && argv[i]; ++i) { - if ( ::strcmp(argv[i],"-call") == 0 ) { - while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-call-end") ) - args_call.push_back(argv[i]); - } - } - - PluginTester* test = lcdd.extension<PluginTester>(); - Conditions::UserPool* pool = test->extension<Conditions::UserPool>("ConditionsTestUserPool"); - AlignmentUpdateCall* call = (AlignmentUpdateCall*) - PluginService::Create<void*>((const char*)args_call[0],&lcdd, - int(args_call.size())-1, - (char**)&args_call[1]); - if ( 0 == call ) { - except("AlignForward","++ Failed to create update call!"); - } - AlignmentForward* obj = new AlignmentForward(lcdd, call, pool); - return obj; -} -DECLARE_LCDD_CONSTRUCTOR(DDAlign_AlignmentForward,ddalign_AlignmentForward) - diff --git a/DDAlign/src/plugins/AlignmentPlugins.cpp b/DDAlign/src/plugins/AlignmentPlugins.cpp index d0f284398..f2c18e302 100644 --- a/DDAlign/src/plugins/AlignmentPlugins.cpp +++ b/DDAlign/src/plugins/AlignmentPlugins.cpp @@ -109,9 +109,9 @@ static void* create_DDAlignForwardCall(Geometry::LCDD& /* lcdd */, int /* argc * } DECLARE_LCDD_CONSTRUCTOR(DDAlign_ForwardCall, create_DDAlignForwardCall) +// ====================================================================================== #include "DD4hep/PluginTester.h" #include "DDCond/ConditionsPool.h" -// ====================================================================================== static long compute_alignments(Geometry::LCDD& lcdd, int /* argc */, char** /* argv */) { AlignmentsManager mgr = AlignmentsManager::from(lcdd); PluginTester* tst = lcdd.extension<PluginTester>(); @@ -121,3 +121,75 @@ static long compute_alignments(Geometry::LCDD& lcdd, int /* argc */, char** /* a return 1; } DECLARE_APPLY(DDAlign_ComputeAlignments, compute_alignments) + +// ====================================================================================== +#include "DDAlign/AlignmentsRegister.h" +//#include "DD4hep/PluginTester.h" +//#include "DDCond/ConditionsPool.h" +/// Convert alignments conditions to alignment objects +static void* ddalign_AlignmentsRegister(Geometry::LCDD& lcdd, int argc, char** argv) { + std::vector<char*> args_prepare, args_call; + + for(int i=0; i<argc && argv[i]; ++i) { + if ( ::strcmp(argv[i],"-prepare") == 0 ) { + while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-prepare-end") ) + args_prepare.push_back(argv[i]); + } + if ( ::strcmp(argv[i],"-call") == 0 ) { + while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-call-end") ) + args_call.push_back(argv[i]); + } + } + + PluginTester* test = lcdd.extension<PluginTester>(); + Conditions::UserPool* pool = (Conditions::UserPool*) + PluginService::Create<void*>((const char*)args_prepare[0],&lcdd, + int(args_prepare.size())-1, + (char**)&args_prepare[1]); + if ( 0 == pool ) { + except("AlignRegister","++ Failed to prepare conditions user-pool!"); + } + test->addExtension<Conditions::UserPool>(pool,"ConditionsTestUserPool"); + AlignmentUpdateCall* call = (AlignmentUpdateCall*) + PluginService::Create<void*>((const char*)args_call[0],&lcdd, + int(args_call.size())-1, + (char**)&args_call[1]); + if ( 0 == call ) { + except("AlignRegister","++ Failed to create update call!"); + } + AlignmentsManager mgr = AlignmentsManager::from(lcdd); + AlignmentsRegister* obj = new AlignmentsRegister(mgr, call, pool); + return obj; +} +DECLARE_LCDD_CONSTRUCTOR(DDAlign_AlignmentsRegister,ddalign_AlignmentsRegister) + +// ====================================================================================== +#include "DDAlign/AlignmentsForward.h" +//#include "DD4hep/PluginTester.h" +//#include "DDCond/ConditionsPool.h" +/// Convert alignments conditions to alignment objects +static void* ddalign_AlignmentsForward(Geometry::LCDD& lcdd, int argc, char** argv) { + std::vector<char*> args_prepare, args_call; + + for(int i=0; i<argc && argv[i]; ++i) { + if ( ::strcmp(argv[i],"-call") == 0 ) { + while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-call-end") ) + args_call.push_back(argv[i]); + } + } + + PluginTester* test = lcdd.extension<PluginTester>(); + Conditions::UserPool* pool = test->extension<Conditions::UserPool>("ConditionsTestUserPool"); + AlignmentUpdateCall* call = (AlignmentUpdateCall*) + PluginService::Create<void*>((const char*)args_call[0],&lcdd, + int(args_call.size())-1, + (char**)&args_call[1]); + if ( 0 == call ) { + except("AlignForward","++ Failed to create update call!"); + } + AlignmentsManager mgr = AlignmentsManager::from(lcdd); + AlignmentsForward* obj = new AlignmentsForward(mgr, call, pool); + return obj; +} +DECLARE_LCDD_CONSTRUCTOR(DDAlign_AlignmentsForward,ddalign_AlignmentsForward) + diff --git a/DDAlign/src/plugins/AlignmentRegister.cpp b/DDAlign/src/plugins/AlignmentRegister.cpp deleted file mode 100644 index 995b64cc5..000000000 --- a/DDAlign/src/plugins/AlignmentRegister.cpp +++ /dev/null @@ -1,154 +0,0 @@ -//========================================================================== -// 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 -// -//========================================================================== - -// Framework includes -#include "DD4hep/Plugins.h" -#include "DD4hep/Printout.h" -#include "DD4hep/DetFactoryHelper.h" - -#include "DD4hep/DetAlign.h" -#include "DD4hep/DetConditions.h" -#include "DD4hep/AlignmentsProcessor.h" -#include "DD4hep/objects/AlignmentsInterna.h" - -#include "DDAlign/AlignmentsManager.h" -#include "DDAlign/AlignmentUpdateCall.h" - -using namespace DD4hep; -using namespace DD4hep::Alignments; -using Conditions::Condition; -using Conditions::ConditionKey; -using Conditions::ConditionsManager; -using Conditions::DetConditions; -using Conditions::DependencyBuilder; - -// ====================================================================================== - -/// Anonymous namespace for plugins -namespace { - - /// Create lignment dependencies from conditions - /** - * Conditions analyser to select alignments.and create the - * corresponding alignment condition dependencies. - * - * \author M.Frank - * \version 1.0 - * \date 31/03/2016 - * \ingroup DD4HEP_DDALIGN - */ - class AlignmentRegister : public DetElement::Processor { - public: - LCDD& lcdd; - Alignments::AlignmentsManager alignmentMgr; - AlignmentUpdateCall* updateCall; - Conditions::UserPool* user_pool; - - /// Initializing constructor - AlignmentRegister(LCDD& l, AlignmentUpdateCall* c, UserPool* p) - : lcdd(l), updateCall(c), user_pool(p) - { - alignmentMgr = AlignmentsManager::from(lcdd); - } - /// Default destructor - virtual ~AlignmentRegister() { - releasePtr(updateCall); - } - /// Callback to output conditions information - virtual int processElement(DetElement de) { - if ( de.isValid() ) { - if ( de.hasConditions() ) { - DetAlign align(de); - DetConditions conditions(de); - Conditions::Container cont = conditions.conditions(); - printout(DEBUG,"AlignRegister", - "++ Processing DE %s hasConditions:%s [%d entries]", - de.path().c_str(), yes_no(de.hasConditions()), int(cont.numKeys())); - for ( const auto& c : cont.keys() ) { - Condition cond = cont.get(c.first, *user_pool); - printout(DEBUG,"AlignRegister", - "++ Processing DE %s Cond:%s Key:%08X flags:%d", - de.path().c_str(), cond.name(), cond.key(), cond->flags); - if ( (cond->flags&Condition::ALIGNMENT) ) { - ConditionKey k(cond->name+"/Tranformations"); - // - // The alignment access through the DetElement object is optional! - // It is slow and deprecated. The access using the UserPool directly - // is highly favored. - // - align.alignments()->addKey(k.name); - align.alignments()->addKey("Alignment",k.name); - // - // Now add the dependency to the alignmant manager - DependencyBuilder b(k, updateCall->addRef(), de); - b.add(ConditionKey(cond->name)); - bool result = alignmentMgr.adoptDependency(b.release()); - if ( result ) { - printout(INFO,"AlignRegister", - "++ Added Alignment dependency Cond:%s Key:%08X flags:%d", - k.name.c_str(), k.hash, cond->flags); - continue; - } - printout(ERROR,"AlignRegister", - "++ FAILED to add Alignment dependency Cond:%s Key:%08X flags:%d", - k.name.c_str(), k.hash, cond->flags); - } - } - return 1; - } - printout(DEBUG,"AlignRegister","++ Processing DE %s hasConditions:%s", - de.path().c_str(), yes_no(de.hasConditions())); - } - return 1; - } - }; -} - -#include "DD4hep/PluginTester.h" -#include "DDCond/ConditionsPool.h" -/// Convert alignments conditions to alignment objects -static void* ddalign_AlignmentRegister(Geometry::LCDD& lcdd, int argc, char** argv) { - std::vector<char*> args_prepare, args_call; - - for(int i=0; i<argc && argv[i]; ++i) { - if ( ::strcmp(argv[i],"-prepare") == 0 ) { - while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-prepare-end") ) - args_prepare.push_back(argv[i]); - } - if ( ::strcmp(argv[i],"-call") == 0 ) { - while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-call-end") ) - args_call.push_back(argv[i]); - } - } - - PluginTester* test = lcdd.extension<PluginTester>(); - Conditions::UserPool* pool = (Conditions::UserPool*) - PluginService::Create<void*>((const char*)args_prepare[0],&lcdd, - int(args_prepare.size())-1, - (char**)&args_prepare[1]); - if ( 0 == pool ) { - except("AlignRegister","++ Failed to prepare conditions user-pool!"); - } - test->addExtension<Conditions::UserPool>(pool,"ConditionsTestUserPool"); - AlignmentUpdateCall* call = (AlignmentUpdateCall*) - PluginService::Create<void*>((const char*)args_call[0],&lcdd, - int(args_call.size())-1, - (char**)&args_call[1]); - if ( 0 == call ) { - except("AlignRegister","++ Failed to create update call!"); - } - AlignmentRegister* obj = new AlignmentRegister(lcdd, call, pool); - return obj; -} -DECLARE_LCDD_CONSTRUCTOR(DDAlign_AlignmentRegister,ddalign_AlignmentRegister) - diff --git a/DDCond/CMakeLists.txt b/DDCond/CMakeLists.txt index 1c3a71ff1..258972d05 100644 --- a/DDCond/CMakeLists.txt +++ b/DDCond/CMakeLists.txt @@ -17,4 +17,4 @@ dd4hep_package( DDCond dd4hep_add_package_library(DDCond SOURCES src/*.cpp ) #---DDCond components ----------------------------------------------------------- -dd4hep_add_plugin(DDCondPlugins SOURCES src/plugins/*.cpp ) +dd4hep_add_plugin(DDCondPlugins SOURCES src/plugins/*.cpp src/Type1/*.cpp ) diff --git a/DDCond/include/DDCond/AlignmentsLoaderImp.h b/DDCond/include/DDCond/AlignmentsLoaderImp.h index b4e4d6a9b..9560cc0d5 100644 --- a/DDCond/include/DDCond/AlignmentsLoaderImp.h +++ b/DDCond/include/DDCond/AlignmentsLoaderImp.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -16,6 +15,7 @@ // Framework include files #include "DD4hep/objects/AlignmentsInterna.h" +#include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsPool.h" /// Namespace for the AIDA detector description toolkit diff --git a/DDCond/include/DDCond/ConditionsAccess.h b/DDCond/include/DDCond/ConditionsAccess.h index c467dc1ac..0ec47e9fc 100644 --- a/DDCond/include/DDCond/ConditionsAccess.h +++ b/DDCond/include/DDCond/ConditionsAccess.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -28,6 +27,8 @@ namespace DD4hep { /// Manager class for condition handles /** + * Facade of the generic ConditionsManagerObject implementation + * * \author M.Frank * \version 1.0 * \ingroup DD4HEP_CONDITIONS diff --git a/DDCond/include/DDCond/ConditionsDataLoader.h b/DDCond/include/DDCond/ConditionsDataLoader.h index 1bb7e72c1..fc1f29081 100644 --- a/DDCond/include/DDCond/ConditionsDataLoader.h +++ b/DDCond/include/DDCond/ConditionsDataLoader.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -33,6 +32,7 @@ namespace DD4hep { // Forward declarations class Entry; class ConditionsDataLoader; + class ConditionsManagerObject; typedef std::list<Entry*> ConditionsStack; /// Interface for a generic conditions loader @@ -60,7 +60,7 @@ namespace DD4hep { protected: /// Queue update to manager. - Condition queueUpdate(Entry* data); + //Condition queueUpdate(Entry* data); /// Push update to manager. void pushUpdates(); diff --git a/DDCond/include/DDCond/ConditionsDependencyHandler.h b/DDCond/include/DDCond/ConditionsDependencyHandler.h index c8ac20b3c..65e30e29b 100644 --- a/DDCond/include/DDCond/ConditionsDependencyHandler.h +++ b/DDCond/include/DDCond/ConditionsDependencyHandler.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -16,9 +15,9 @@ // Framework include files #include "DD4hep/Detector.h" -#include "DD4hep/Conditions.h" -#include "DDCond/ConditionsInterna.h" -#include "DDCond/ConditionsManager.h" +#include "DD4hep/ConditionDerived.h" +#include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsDependencyCollection.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -28,7 +27,9 @@ namespace DD4hep { // Forward declarations class UserPool; - + class ConditionsManagerObject; + class ConditionsDependencyCollection; + /// Callback handler to update condition dependencies. /** * @@ -37,11 +38,11 @@ namespace DD4hep { */ class ConditionsDependencyHandler : public ConditionResolver { public: - typedef ConditionsManager::Dependencies Dependencies; + typedef ConditionsDependencyCollection Dependencies; protected: /// Reference to conditions manager - ConditionsManager::Object* m_manager; + ConditionsManagerObject* m_manager; /// Reference to the user pool object UserPool& m_pool; /// Dependency container to be resolved. @@ -54,23 +55,20 @@ namespace DD4hep { public: /// Initializing constructor - ConditionsDependencyHandler(ConditionsManager::Object* mgr, + ConditionsDependencyHandler(ConditionsManagerObject* mgr, UserPool& pool, const Dependencies& dependencies, void* user_param); /// Default destructor ~ConditionsDependencyHandler(); - /// ConditionResolver implementation: Access to the conditions manager - virtual Ref_t manager() const - { return m_manager; } /// ConditionResolver implementation: Access to the detector description instance - virtual LCDD& lcdd() const - { return m_manager->lcdd(); } - virtual const IOV& requiredValidity() const - { return m_pool.validity(); } + LCDD& lcdd() const; + /// ConditionResolver implementation: Access to the conditions manager + virtual Ref_t manager() const { return m_manager; } + /// Access to pool IOV + virtual const IOV& requiredValidity() const { return m_pool.validity(); } /// ConditionResolver implementation: Interface to access conditions. - virtual Condition get(const ConditionKey& key) const - { return get(key.hash); } + virtual Condition get(const ConditionKey& key) const { return get(key.hash); } /// ConditionResolver implementation: Interface to access conditions virtual Condition get(unsigned int key) const; /// Handler callback to process multiple derived conditions diff --git a/DDCond/include/DDCond/ConditionsIOVPool.h b/DDCond/include/DDCond/ConditionsIOVPool.h index d27fdbc09..7ea835735 100644 --- a/DDCond/include/DDCond/ConditionsIOVPool.h +++ b/DDCond/include/DDCond/ConditionsIOVPool.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCond/include/DDCond/ConditionsLoaderImp.h b/DDCond/include/DDCond/ConditionsLoaderImp.h index b3464d9cc..624c23cf6 100644 --- a/DDCond/include/DDCond/ConditionsLoaderImp.h +++ b/DDCond/include/DDCond/ConditionsLoaderImp.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -16,7 +15,6 @@ // Framework include files #include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsManager.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { diff --git a/DDCond/include/DDCond/ConditionsManager.h b/DDCond/include/DDCond/ConditionsManager.h index 87c613fa2..c1f6fe0de 100644 --- a/DDCond/include/DDCond/ConditionsManager.h +++ b/DDCond/include/DDCond/ConditionsManager.h @@ -46,7 +46,7 @@ namespace DD4hep { public: /// Standard object type - typedef ConditionsManagerObject Object; + typedef ConditionsManagerObject Object; typedef ConditionsDataLoader Loader; typedef std::vector<IOVType> IOVTypes; typedef std::map<IOVType*,Container> TypeConditions; @@ -98,7 +98,7 @@ namespace DD4hep { PropertyManager& properties() const; /// Access the conditions loader - Handle<Loader> loader() const; + Loader* loader() const; /// Access the used/registered IOV types const std::vector<const IOVType*> iovTypesUsed() const; @@ -110,25 +110,34 @@ namespace DD4hep { ConditionsIOVPool* iovPool(const IOVType& type) const; /// Create IOV from string - void fromString(const std::string& iov_str, IOV& iov); + void fromString(const std::string& iov_str, IOV& iov) const; /// Register new IOV type if it does not (yet) exist. /** Returns (false,pointer) if IOV existed and * (true,pointer) if new IOV was registered to the manager. */ - std::pair<bool, const IOVType*> registerIOVType(size_t iov_type, const std::string& iov_name); + std::pair<bool, const IOVType*> registerIOVType(size_t iov_type, const std::string& iov_name) const; /// Register IOV with type and key - ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key); + ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key) const; + + /// Register IOV with type and key + ConditionsPool* registerIOV(const std::string& iov_rep) const; /// Register new condition with the conditions store. Unlocked version, not multi-threaded - bool registerUnlocked(ConditionsPool* pool, Condition cond); + bool registerUnlocked(ConditionsPool* pool, Condition cond) const; + + /// Push all pending updates to the conditions store. + /** Note: + * This does not yet make the new conditions availible to the clients + */ + void pushUpdates() const; /// Clean conditions, which are above the age limit. - void clean(const IOVType* typ, int max_age); + void clean(const IOVType* typ, int max_age) const; /// Full cleanup of all managed conditions. - void clear(); + void clear() const; /// Prepare all updates for the given keys to the clients with the defined IOV long prepare(const IOV& required_validity, @@ -151,7 +160,6 @@ namespace DD4hep { const Dependencies& dependencies, bool verify_dependencies=true); }; - - } /* End namespace Conditions */ -} /* End namespace DD4hep */ -#endif /* DDCOND_CONDITIONSMANAGER_H */ + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DDCOND_CONDITIONSMANAGER_H */ diff --git a/DDCond/include/DDCond/ConditionsManagerObject.h b/DDCond/include/DDCond/ConditionsManagerObject.h new file mode 100644 index 000000000..30a5ad86d --- /dev/null +++ b/DDCond/include/DDCond/ConditionsManagerObject.h @@ -0,0 +1,167 @@ +//========================================================================== +// 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 +// +//========================================================================== +#ifndef DDCOND_CONDITIONS_CONDITIONSMANAGEROBJECT_H +#define DDCOND_CONDITIONS_CONDITIONSMANAGEROBJECT_H + +// Framework include files +#include "DD4hep/Memory.h" +#include "DD4hep/Conditions.h" +#include "DD4hep/NamedObject.h" +#include "DD4hep/ComponentProperties.h" + +#include "DDCond/ConditionsPool.h" + +// C/C++ include files +#include <vector> +#include <set> + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + // Forward declarations + class IOVType; + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Conditions { + + // Forward declarations + class ConditionsPool; + class ConditionsListener; + class ConditionDependency; + class ConditionsDataLoader; + class ConditionsIOVPool; + class ConditionsDependencyCollection; + + /// Basic conditions manager implementation + /** + * This class implements the basic functionality of the conditions manager. + * To allow for specialization, the important functions are kept virtual. + * For performance reasons these are mostly functions, which either + * are called elatively rarely or are bulk functions. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionsManagerObject : public NamedObject, + public PropertyConfigurable + { + public: + typedef std::vector<IOVType> IOVTypes; + typedef Condition::key_type key_type; + typedef Condition::iov_type iov_type; + typedef std::pair<ConditionsListener*,void*> Listener; + typedef std::set<Listener> Listeners; + typedef std::set<ConditionKey> ConditionKeys; + typedef ConditionDependency Dependency; + typedef ConditionsDependencyCollection Dependencies; + typedef dd4hep_ptr<ConditionsDataLoader> Loader; + + protected: + /// Reference to main detector description object + LCDD& m_lcdd; + /// Conditions listeners on registration of new conditions + Listeners m_onRegister; + /// Conditions listeners on de-registration of new conditions + Listeners m_onRemove; + /// Reference to the data loader userd by this instance + Loader m_loader; + /// Register callback listener object + void registerCallee(Listeners& listeners, const Listener& callee, bool add); + + public: + /// Default constructor + ConditionsManagerObject(LCDD& lcdd); + /// Default destructor + virtual ~ConditionsManagerObject(); + /// Access to the detector description instance + LCDD& lcdd() const { return m_lcdd; } + /// Access to the data loader + ConditionsDataLoader* loader() const { return m_loader.get(); } + /// Listener invocation when a condition is registered to the cache + void onRegister(Condition condition); + /// Listener invocation when a condition is deregistered from the cache + void onRemove(Condition condition); + /// (Un)Registration of conditions listeners with callback when a new condition is registered + void callOnRegister(const Listener& callee, bool add); + /// (Un)Registration of conditions listeners with callback when a condition is unregistered + void callOnRemove(const Listener& callee, bool add); + /// Access the used/registered IOV types + const std::vector<const IOVType*> iovTypesUsed() const; + /// Create IOV from string + void fromString(const std::string& iov_str, IOV& iov); + /// Register IOV using new string data + ConditionsPool* registerIOV(const std::string& data); + + /** Overloadable interface */ + /// Initialize the object after having set the properties + virtual void initialize() = 0; + /// Access IOV by its type + virtual const IOVTypes& iovTypes () const = 0; + /// Access IOV by its type + virtual const IOVType* iovType (size_t iov_type) const = 0; + /// Access IOV by its name + virtual const IOVType* iovType (const std::string& iov_name) const = 0; + /// Register new IOV type if it does not (yet) exist. + /** 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) = 0; + /// Register IOV with type and key (much more performant...) + virtual ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key) = 0; + + /// Access conditions multi IOV pool by iov type + virtual ConditionsIOVPool* iovPool(const IOVType& type) const = 0; + /// Retrieve a condition set given a Detector Element and the conditions name according to their validity + virtual Condition get(key_type key, const iov_type& req_validity) = 0; + /// Retrieve a condition given a Detector Element and the conditions name + virtual RangeConditions getRange(key_type key, const iov_type& req_validity) = 0; + /// Push all pending updates to the conditions store. + /** Note: + * This does not yet make the new conditions availible to the clients + */ + virtual void pushUpdates() = 0; + /// Register new condition with the conditions store. Unlocked version, not multi-threaded + virtual bool registerUnlocked(ConditionsPool* pool, Condition cond) = 0; + + /// Prepare all updates for the given keys to the clients with the defined IOV + virtual long prepare(const IOV& required_validity, + const ConditionKeys& keys, + dd4hep_ptr<UserPool>& user_pool) = 0; + + /// Prepare all updates for the given keys to the clients with the defined IOV + virtual long prepare(const IOV& required_validity, + const ConditionKeys& keys, + dd4hep_ptr<UserPool>& user_pool, + const Dependencies& dependencies, + bool verify_dependencies=true) = 0; + + /// Prepare all updates to the clients with the defined IOV + virtual long prepare(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool) = 0; + + /// Prepare all updates to the clients with the defined IOV + virtual long prepare(const IOV& required_validity, + dd4hep_ptr<UserPool>& user_pool, + const Dependencies& dependencies, + bool verify_dependencies=true) = 0; + /// Clean conditions, which are above the age limit. + /** @return Number of conditions cleaned/removed from the IOV pool of the given type */ + virtual int clean(const IOVType* typ, int max_age) = 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; + }; + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif /* DDCOND_CONDITIONS_CONDITIONSMANAGEROBJECT_H */ diff --git a/DDCond/include/DDCond/ConditionsOperators.h b/DDCond/include/DDCond/ConditionsOperators.h index bc00fa482..b96acb096 100644 --- a/DDCond/include/DDCond/ConditionsOperators.h +++ b/DDCond/include/DDCond/ConditionsOperators.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -15,7 +14,6 @@ #define DD4HEP_CONDITIONS_CONDITIONSOPERATORS_H // Framework include files -#include "DD4hep/Conditions.h" #include "DDCond/ConditionsManager.h" // C/C++ include files @@ -23,14 +21,12 @@ /// Namespace for the AIDA detector description toolkit namespace DD4hep { - /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { - class LCDD; - } - /// Namespace for the geometry part of the AIDA detector description toolkit namespace Conditions { + // Forward declarations + class ConditionsManagerObject; + /// Helper class for common stuff used frequently class Operators { public: @@ -43,9 +39,6 @@ namespace DD4hep { /// Select all condition from the conditions manager registered at the LCDD object static size_t collectAllConditions(ConditionsManager mgr, std::map<int,Condition>& conditions); }; - - - } /* End namespace Conditions */ } /* End namespace DD4hep */ diff --git a/DDCond/include/DDCond/ConditionsPool.h b/DDCond/include/DDCond/ConditionsPool.h index dda58a31a..90f6537da 100644 --- a/DDCond/include/DDCond/ConditionsPool.h +++ b/DDCond/include/DDCond/ConditionsPool.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -16,9 +15,11 @@ // Framework include files #include "DD4hep/Detector.h" -#include "DD4hep/Conditions.h" #include "DDCond/ConditionsManager.h" +// C/C++ include files +#include <set> + /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -26,8 +27,10 @@ namespace DD4hep { namespace Conditions { // Forward declarations + class ConditionsIOVPool; class ConditionsPoolInsert; - class ConditionsManagerObject; + class ConditionDependency; + class ConditionsDependencyCollection; /// Class implementing the conditions collection for a given IOV type /** @@ -36,6 +39,12 @@ namespace DD4hep { * and store optimizations and/or various caches. * The interface only represents the basic functionality required. * + * Please note: + * Users should not directly interact with object instances of this type. + * Data are not thread protected and interaction may cause serious harm. + * Only the ConditionsManager implementation should interact with + * this class or any subclass to ensure data integrity. + * * For convenience, the class definition is here. * See ConditionsManager.cpp for the implementation. * @@ -66,16 +75,11 @@ namespace DD4hep { protected: friend class ConditionsPoolInsert; friend class ConditionsPoolRemove; - friend class ConditionsManagerObject; /// Listener invocation when a condition is registered to the cache void onRegister(Condition condition); /// Listener invocation when a condition is deregistered from the cache void onRemove(Condition condition); - /// Register a new condition to this pool - virtual void insert(Condition cond) = 0; - /// Register a new condition to this pool. May overload for performance reasons. - virtual void insert(RangeConditions& cond) = 0; public: /// Default constructor @@ -86,6 +90,10 @@ namespace DD4hep { void print(const std::string& opt) const; /// Full cleanup of all managed conditions. virtual void clear() = 0; + /// Register a new condition to this pool + virtual void insert(Condition cond) = 0; + /// Register a new condition to this pool. May overload for performance reasons. + virtual void insert(RangeConditions& cond) = 0; /// Check if a condition exists in the pool virtual Condition exists(Condition::key_type key) const = 0; /// Select the conditions matching the DetElement and the conditions name @@ -133,19 +141,18 @@ namespace DD4hep { class UserPool { public: /// Forward definition of the key type - typedef Condition::key_type key_type; - /// Forward definition of the condition keys container - typedef ConditionsManager::ConditionKeys ConditionKeys; - /// Forward definition of the dependency container - typedef ConditionsManager::Dependencies Dependencies; + typedef Condition::key_type key_type; + typedef std::set<ConditionKey> ConditionKeys; + typedef ConditionDependency Dependency; + typedef ConditionsDependencyCollection Dependencies; protected: /// The pool's interval of validity - IOV m_iov; + IOV m_iov; /// Handle to conditions manager object - ConditionsManager m_manager; + ConditionsManager m_manager; /// IOV Pool as data source - ConditionsIOVPool* m_iovPool; + ConditionsIOVPool* m_iovPool; public: /// Default constructor diff --git a/DDCond/include/DDCond/ConditionsRepository.h b/DDCond/include/DDCond/ConditionsRepository.h index 9d34732c4..579766117 100644 --- a/DDCond/include/DDCond/ConditionsRepository.h +++ b/DDCond/include/DDCond/ConditionsRepository.h @@ -1,4 +1,3 @@ -// $Id: ConditionsRepository.h 2336 2016-09-07 17:27:40Z markus.frank@cern.ch $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -29,9 +28,6 @@ namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit namespace Conditions { - /// Forward declarations - - /// Base class to be implemented by objects to listen on condition callbacks /** * diff --git a/DDCond/include/DDCond/ConditionsTest.h b/DDCond/include/DDCond/ConditionsTest.h index a2153ad71..44636fe5b 100644 --- a/DDCond/include/DDCond/ConditionsTest.h +++ b/DDCond/include/DDCond/ConditionsTest.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -20,12 +19,10 @@ #include "DD4hep/Conditions.h" #include "DD4hep/DetConditions.h" #include "DD4hep/DetFactoryHelper.h" -#include "DD4hep/objects/ConditionsInterna.h" #include "DDCond/ConditionsAccess.h" -#include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsInterna.h" +#include "DDCond/ConditionsManager.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -53,7 +50,6 @@ namespace DD4hep { DetElement daughter(const std::string& sub_path) const; void add_xml_data_source(const std::string& file, const std::string& iov); - void dump_conditions_pools(); static void dump_detector_element(DetElement elt); static void dump_conditions_tree(DetElement elt); }; diff --git a/DDCond/include/DDCond/ConditionsInterna.h b/DDCond/include/DDCond/Type1/Manager_Type1.h similarity index 60% rename from DDCond/include/DDCond/ConditionsInterna.h rename to DDCond/include/DDCond/Type1/Manager_Type1.h index 01374abff..2368d1a0b 100644 --- a/DDCond/include/DDCond/ConditionsInterna.h +++ b/DDCond/include/DDCond/Type1/Manager_Type1.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -11,20 +10,21 @@ // Author : M.Frank // //========================================================================== -#ifndef DDCOND_CONDITIONSINTERNA_H -#define DDCOND_CONDITIONSINTERNA_H +#ifndef DDCOND_CONDITIONSMANAGEROBJECT_TYPE1_H +#define DDCOND_CONDITIONSMANAGEROBJECT_TYPE1_H // Framework include files% #include "DD4hep/Mutex.h" #include "DD4hep/Memory.h" #include "DD4hep/Callback.h" -#include "DD4hep/Conditions.h" #include "DD4hep/ConditionDerived.h" #include "DD4hep/ObjectExtensions.h" +#include "DD4hep/objects/ConditionsInterna.h" #include "DDCond/ConditionsPool.h" #include "DDCond/ConditionsIOVPool.h" #include "DDCond/ConditionsDataLoader.h" +#include "DDCond/ConditionsManagerObject.h" // C/C++ include files #include <set> @@ -39,19 +39,8 @@ namespace DD4hep { class Entry; class ConditionsPool; class ConditionsIOVPool; - class ConditionsListener; class ConditionsDataLoader; - /// Conditions internal namespace declaration - /** Internally defined datastructures are not presented to the - * user directly, but are used by dedicated views. - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - //namespace Interna { - /// The data class behind a conditions manager handle /** * For convenience, the class definition is here. @@ -61,25 +50,13 @@ namespace DD4hep { * \version 1.0 * \ingroup DD4HEP_CONDITIONS */ - class ConditionsManagerObject : public NamedObject, - public PropertyConfigurable, - public ObjectExtensions + class ConditionsManagerObject_Type1 : public ConditionsManagerObject, + public ObjectExtensions { - friend class DD4hep::Conditions::ConditionsPool; - friend class DD4hep::Conditions::ConditionsDataLoader; - - public: - typedef dd4hep_ptr<ConditionsDataLoader> Loader; - typedef std::vector<IOVType> IOVTypes; - typedef std::vector<ConditionsIOVPool*> TypedConditionPool; - typedef std::pair<ConditionsListener*,void*> Listener; - typedef std::set<Listener> Listeners; - typedef ConditionsManager::Dependencies Dependencies; - typedef ConditionsManager::ConditionKeys ConditionKeys; - typedef Condition::key_type key_type; - typedef Condition::iov_type iov_type; + protected: - public: + /** Generic interface of any concrete instance */ + /// Property: maximal number of IOV types to be handled int m_maxIOVTypes; /// Property: ConditionsPool constructor type (default: empty. MUST BE SET!) @@ -91,27 +68,26 @@ namespace DD4hep { /// Property: Conditions loader type (default: "multi" -> DD4hep_Conditions_multi_Loader) std::string m_loaderType; - /// Reference to main detector description object - LCDD& m_lcdd; /// Collection of IOV types managed IOVTypes m_iovTypes; + + /** Specialized interface only used by this implementation */ + + public: + typedef std::vector<ConditionsIOVPool*> TypedConditionPool; /// Managed pool of typed conditions indexed by IOV-type and IOV key TypedConditionPool m_rawPool; - /// Conditions listeners on registration of new conditions - Listeners m_onRegister; - /// Conditions listeners on de-registration of new conditions - Listeners m_onRemove; + + protected: /// Lock to protect the update/delayed conditions pool dd4hep_mutex_t m_updateLock; /// Lock to protect the pool of all known conditions dd4hep_mutex_t m_poolLock; - /// Reference to data loader - Loader m_loader; /// Reference to update conditions pool dd4hep_ptr<UpdatePool> m_updatePool; /// Public access: if locked, DetElements stay intact and are not altered - int locked; + int m_locked; protected: /// Retrieve a condition set given a Detector Element and the conditions name according to their validity @@ -123,70 +99,57 @@ namespace DD4hep { /// Register a set of new managed condition for an IOV range. Called by __load_immediate // void __register_immediate(RangeConditions& c); - void registerCallee(Listeners& listeners, const Listener& callee, bool add); - - /// Listener invocation when a condition is registered to the cache - void onRegister(Condition condition); - - /// Listener invocation when a condition is deregistered from the cache - void onRemove(Condition condition); /// Helper to check iov and user pool and create user pool if not present void __get_checked_pool(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool); - public: + /** Generic interface of any concrete instance */ + /// Set a single conditions value to be managed. /// Requires EXTERNALLY held lock on update pool! Condition __queue_update(Conditions::Entry* data); + protected: + /// Register a new managed condition. (Unused) + //void registerCondition(Condition c); + + public: /// Standard constructor - ConditionsManagerObject(LCDD& lcdd); + ConditionsManagerObject_Type1(LCDD& lcdd); /// Default destructor - virtual ~ConditionsManagerObject(); - - /// Access to the detector description instance - LCDD& lcdd() const { return m_lcdd; } + virtual ~ConditionsManagerObject_Type1(); /// Access to managed pool of typed conditions indexed by IOV-type and IOV key - const TypedConditionPool& conditionsPool() const { return m_rawPool; } + //const TypedConditionPool& conditionsPool() const { return m_rawPool; } - ConditionsDataLoader* loader() const { return m_loader.get(); } - + /// Initialize object and define factories void initialize(); - /// (Un)Registration of conditions listeners with callback when a new condition is registered - void callOnRegister(const Listener& callee, bool add); - /// (Un)Registration of conditions listeners with callback when a condition is unregistered - void callOnRemove(const Listener& callee, bool add); - /// Register new IOV type if it does not (yet) exist. /** Returns (false,pointer) if IOV existed and * (true,pointer) if new IOV was registered to the manager. */ - 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); /// Access IOV by its type - const IOVTypes& iovTypes () const { return m_iovTypes; } + virtual const IOVTypes& iovTypes () const { return m_iovTypes; } /// Access IOV by its type - const IOVType* iovType (size_t iov_type) const; + virtual const IOVType* iovType (size_t iov_type) const; /// Access IOV by its name - const IOVType* iovType (const std::string& iov_name) const; - - /// Create IOV from string - void fromString(const std::string& iov_str, IOV& iov); - - /// Register IOV using new string data - ConditionsPool* registerIOV(const std::string& data); + virtual const IOVType* iovType (const std::string& iov_name) const; /// Register IOV with type and key - ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key); + virtual ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key); + + /// Access conditions multi IOV pool by iov type + ConditionsIOVPool* iovPool(const IOVType& type) const; /// Register new condition with the conditions store. Unlocked version, not multi-threaded - bool registerUnlocked(ConditionsPool* pool, Condition cond); + virtual bool registerUnlocked(ConditionsPool* pool, Condition cond); /// Prepare all updates for the given keys to the clients with the defined IOV long prepare(const IOV& required_validity, @@ -210,7 +173,7 @@ namespace DD4hep { bool verify_dependencies=true); /// Clean conditions, which are above the age limit. - /** @return Number of conditions cleaned up and removed */ + /** @return Number of conditions cleaned/removed from the IOV pool of the given type */ int clean(const IOVType* typ, int max_age); /// Full cleanup of all managed conditions. @@ -221,22 +184,14 @@ namespace DD4hep { /** Note: * This does not yet make the new conditions availible to the clients */ - void pushUpdates(); + virtual void pushUpdates(); - /// Register a new managed condition. - /** The condition is created externally by the user. - * Lengthy and tedious procedure. - */ - void registerCondition(Condition c); - /// Retrieve a condition set given a Detector Element and the conditions name according to their validity - Condition get(key_type key, const iov_type& req_validity); + virtual Condition get(key_type key, const iov_type& req_validity); /// Retrieve a condition given a Detector Element and the conditions name - RangeConditions getRange(key_type key, const iov_type& req_validity); + virtual RangeConditions getRange(key_type key, const iov_type& req_validity); }; - // } /* End namespace Interna */ - } /* End namespace Conditions */ -} /* End namespace DD4hep */ - -#endif /* DDCOND_CONDITIONSINTERNA_H */ + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DDCOND_CONDITIONSMANAGEROBJECT_TYPE1_H */ diff --git a/DDCond/src/AlignmentsLoaderImp.cpp b/DDCond/src/AlignmentsLoaderImp.cpp index 9346f54c2..2f1e2d2e0 100644 --- a/DDCond/src/AlignmentsLoaderImp.cpp +++ b/DDCond/src/AlignmentsLoaderImp.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -13,9 +12,9 @@ //========================================================================== // Framework include files -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsInterna.h" #include "DDCond/AlignmentsLoaderImp.h" +#include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsManagerObject.h" using namespace DD4hep::Conditions; using DD4hep::Alignments::Alignment; @@ -25,6 +24,7 @@ using DD4hep::Alignments::AlignmentCondition; AlignmentsLoaderImp::AlignmentsLoaderImp(ConditionsManager mgr) : m_manager(mgr), m_refCount(1) { + m_manager.access(); // Check object validity.... } /// Default destructor @@ -45,7 +45,7 @@ void AlignmentsLoaderImp::release() { /// Access the conditions loading mechanism Alignment AlignmentsLoaderImp::get(key_type key, const Condition::iov_type& iov) { - AlignmentCondition cond = m_manager.ptr()->get(key, iov); + AlignmentCondition cond = m_manager->get(key, iov); return &cond.data(); } diff --git a/DDCond/src/ConditionsAccess.cpp b/DDCond/src/ConditionsAccess.cpp index 2a1d5ac42..aaa1aa1a1 100644 --- a/DDCond/src/ConditionsAccess.cpp +++ b/DDCond/src/ConditionsAccess.cpp @@ -12,9 +12,8 @@ //========================================================================== // Framework include files -#include "DD4hep/Conditions.h" -#include "DDCond/ConditionsInterna.h" #include "DDCond/ConditionsAccess.h" +#include "DDCond/ConditionsManagerObject.h" using namespace std; using namespace DD4hep; diff --git a/DDCond/src/ConditionsDataLoader.cpp b/DDCond/src/ConditionsDataLoader.cpp index e9c9b1562..49bfe6111 100644 --- a/DDCond/src/ConditionsDataLoader.cpp +++ b/DDCond/src/ConditionsDataLoader.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -13,10 +12,10 @@ //========================================================================== // Framework include files +#include "DDCond/ConditionsDataLoader.h" +#include "DDCond/ConditionsManagerObject.h" #include "DD4hep/Handle.inl" #include "DD4hep/Printout.h" -#include "DDCond/ConditionsInterna.h" -#include "DDCond/ConditionsDataLoader.h" using std::string; using namespace DD4hep::Conditions; @@ -25,7 +24,8 @@ DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsDataLoader); /// Default constructor ConditionsDataLoader::ConditionsDataLoader(LCDD& lcdd, ConditionsManager mgr, const string nam) - : NamedObject(nam,"ConditionsDataLoader"), m_lcdd(lcdd), m_mgr(mgr) { + : NamedObject(nam,"ConditionsDataLoader"), m_lcdd(lcdd), m_mgr(mgr) +{ if ( m_mgr.isValid() ) return; except("ConditionsDataLoader","+++ Cannot create loader without a valid conditions manager handle!"); } @@ -40,9 +40,9 @@ void ConditionsDataLoader::addSource(const string& source, const IOV& iov) { } /// Queue update to manager. -Condition ConditionsDataLoader::queueUpdate(Entry* data) { - return m_mgr->__queue_update(data); -} +//Condition ConditionsDataLoader::queueUpdate(Entry* data) { +// return m_mgr->__queue_update(data); +//} /// Push update to manager. void ConditionsDataLoader::pushUpdates() { diff --git a/DDCond/src/ConditionsDependencyHandler.cpp b/DDCond/src/ConditionsDependencyHandler.cpp index 1be9b0b26..1fd64f3e8 100644 --- a/DDCond/src/ConditionsDependencyHandler.cpp +++ b/DDCond/src/ConditionsDependencyHandler.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -13,14 +12,15 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" #include "DDCond/ConditionsDependencyHandler.h" +#include "DDCond/ConditionsManagerObject.h" +#include "DD4hep/Printout.h" using namespace DD4hep; using namespace DD4hep::Conditions; /// Default constructor -ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManager::Object* mgr, +ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManagerObject* mgr, UserPool& pool, const Dependencies& dependencies, void* user_param) @@ -32,6 +32,11 @@ ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManager::Obje ConditionsDependencyHandler::~ConditionsDependencyHandler() { } +/// ConditionResolver implementation: Access to the detector description instance +LCDD& ConditionsDependencyHandler::lcdd() const { + return m_manager->lcdd(); +} + /// ConditionResolver implementation: Interface to access conditions Condition ConditionsDependencyHandler::get(unsigned int key) const { Condition c = m_pool.get(key); diff --git a/DDCond/src/ConditionsLoaderImp.cpp b/DDCond/src/ConditionsLoaderImp.cpp index f0d69afc1..02b7e0a80 100644 --- a/DDCond/src/ConditionsLoaderImp.cpp +++ b/DDCond/src/ConditionsLoaderImp.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -14,8 +13,8 @@ // Framework include files #include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsInterna.h" #include "DDCond/ConditionsLoaderImp.h" +#include "DDCond/ConditionsManagerObject.h" using namespace DD4hep::Conditions; diff --git a/DDCond/src/ConditionsManager.cpp b/DDCond/src/ConditionsManager.cpp index 01e7625b4..5d22477d5 100644 --- a/DDCond/src/ConditionsManager.cpp +++ b/DDCond/src/ConditionsManager.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -14,17 +13,25 @@ // Framework include files #include "DD4hep/LCDD.h" +#include "DD4hep/Errors.h" +#include "DD4hep/Handle.inl" #include "DD4hep/Printout.h" -#include "DDCond/ConditionsInterna.h" +#include "DD4hep/InstanceCount.h" + +#include "DD4hep/ConditionsListener.h" #include "DDCond/ConditionsManager.h" +#include "DDCond/ConditionsManagerObject.h" using namespace std; using namespace DD4hep; using namespace DD4hep::Conditions; +DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsManagerObject); + /// Namespace for the AIDA detector description toolkit namespace DD4hep { + /// Namespace for the geometry part of the AIDA detector description toolkit namespace Conditions { @@ -32,15 +39,114 @@ namespace DD4hep { template <> ConditionsManager ConditionsManager::from<LCDD>(LCDD& host) { Object* obj = host.extension<Object>(); if ( obj ) return ConditionsManager(obj); - except("ConditionsManager","+++ Failed to access manager from LCDD."); + except("ConditionsManager","+++ Failed to access installed manager from LCDD."); return ConditionsManager(); } } } +/// Default constructor +ConditionsManagerObject::ConditionsManagerObject(LCDD& ref_lcdd) + : NamedObject(), m_lcdd(ref_lcdd) +{ + InstanceCount::increment(this); +} + +/// Default destructor +ConditionsManagerObject::~ConditionsManagerObject() { + m_onRegister.clear(); + m_onRemove.clear(); + InstanceCount::decrement(this); +} + +void ConditionsManagerObject::registerCallee(Listeners& listeners, const Listener& callee, bool add) { + if ( add ) { + listeners.insert(callee); + return; + } + Listeners::iterator i=listeners.find(callee); + if ( i != listeners.end() ) listeners.erase(i); +} + +/// (Un)Registration of conditions listeners with callback when a new condition is registered +void ConditionsManagerObject::callOnRegister(const Listener& callee, bool add) { + registerCallee(m_onRegister, callee, add); +} + +/// (Un)Registration of conditions listeners with callback when a condition is de-registered +void ConditionsManagerObject::callOnRemove(const Listener& callee, bool add) { + registerCallee(m_onRemove, callee, add); +} + +/// Call this when a condition is registered to the cache +void ConditionsManagerObject::onRegister(Condition condition) { + for(const auto& listener : m_onRegister ) + listener.first->onRegisterCondition(condition, listener.second); +} + +/// Call this when a condition is deregistered from the cache +void ConditionsManagerObject::onRemove(Condition condition) { + for(const auto& listener : m_onRemove ) + listener.first->onRegisterCondition(condition, listener.second); +} + +/// Access the used/registered IOV types +const vector<const IOVType*> ConditionsManagerObject::iovTypesUsed() const { + vector<const IOVType*> result; + const IOVTypes& types = iovTypes(); + for ( const auto& i : types ) { + if ( int(i.type) != IOVType::UNKNOWN_IOV ) result.push_back(&i); + } + return result; +} + +/// Create IOV from string +void ConditionsManagerObject::fromString(const std::string& data, IOV& iov) { + size_t id1 = data.find(','); + size_t id2 = data.find('#'); + if ( id2 == string::npos ) { + except("ConditionsManager","+++ Unknown IOV string representation: %s",data.c_str()); + } + string iov_name = data.substr(id2+1); + IOV::Key key; + int nents = 0; + if ( id1 != string::npos ) + nents = ::sscanf(data.c_str(),"%ld,%ld#",&key.first,&key.second) == 2 ? 2 : 0; + else { + nents = ::sscanf(data.c_str(),"%ld#",&key.first) == 1 ? 1 : 0; + key.second = key.first; + } + if ( nents == 0 ) { + except("ConditionsManager", + "+++ Failed to read keys from IOV string representation: %s",data.c_str()); + } + + // Check if this IOV type is known + const IOVType* typ = iovType(iov_name); + if ( !typ ) { + // Severe: We have an unknown IOV type. This is not allowed, + // because we do not known hot to handle it..... + except("ConditionsManager","+++ Unknown IOV type requested from data: %s. [%s]", + data.c_str(),Errors::invalidArg().c_str()); + } + iov.type = typ->type; + iov.iovType = typ; + iov.set(key); +} + +/// Register IOV using new string data +ConditionsPool* ConditionsManagerObject::registerIOV(const string& data) { + IOV iov(0); + // Convert string to IOV + fromString(data, iov); + // IOV read and checked. Now register it. + // The validity of iov->iovType is already ensured in 'fromString' + return registerIOV(*iov.iovType, iov.keyData); +} + /// Default constructor ConditionsManager::ConditionsManager(LCDD& lcdd) { - assign(new Object(lcdd), "ConditionsManager",""); + assign(ConditionsManager::from(lcdd).ptr(), "ConditionsManager",""); } ConditionsManager& ConditionsManager::initialize() { @@ -59,13 +165,13 @@ Property& ConditionsManager::operator[](const std::string& property_name) const } /// Access the conditions loader -Handle<ConditionsManager::Loader> ConditionsManager::loader() const { +ConditionsManager::Loader* ConditionsManager::loader() const { return access()->loader(); } /// Register new IOV type if it does not (yet) exist. pair<bool, const IOVType*> -ConditionsManager::registerIOVType(size_t iov_type, const string& iov_name) { +ConditionsManager::registerIOVType(size_t iov_type, const string& iov_name) const { return access()->registerIOVType(iov_type, iov_name); } @@ -75,8 +181,8 @@ const IOVType* ConditionsManager::iovType (const string& iov_name) const { } /// Access conditions multi IOV pool by iov type -ConditionsIOVPool* ConditionsManager::iovPool(const IOVType& iov_type) const { - return access()->m_rawPool[iov_type.type]; +ConditionsIOVPool* ConditionsManager::iovPool(const IOVType& iov_type) const { + return access()->iovPool(iov_type); } /// Access the used/registered IOV types @@ -90,33 +196,48 @@ const vector<const IOVType*> ConditionsManager::iovTypesUsed() const { } /// Register IOV with type and key -ConditionsPool* ConditionsManager::registerIOV(const IOVType& typ, IOV::Key key) { +ConditionsPool* ConditionsManager::registerIOV(const string& iov_rep) const { + IOV iov(0); + Object* o = access(); + o->fromString(iov_rep, iov); + if ( iov.iovType ) + return o->registerIOV(*iov.iovType, iov.key()); + except("ConditionsManager","Invalid IOV type registration requested by IOV:%s",iov_rep.c_str()); + return 0; +} + +/// Register IOV with type and key +ConditionsPool* ConditionsManager::registerIOV(const IOVType& typ, IOV::Key key) const { return access()->registerIOV(typ, key); } /// Create IOV from string -void ConditionsManager::fromString(const string& iov_str, IOV& iov) { +void ConditionsManager::fromString(const string& iov_str, IOV& iov) const { access()->fromString(iov_str, iov); } /// Register new condition with the conditions store. Unlocked version, not multi-threaded -bool ConditionsManager::registerUnlocked(ConditionsPool* pool, Condition cond) { +bool ConditionsManager::registerUnlocked(ConditionsPool* pool, Condition cond) const { return access()->registerUnlocked(pool, cond); } +/// Push all pending updates to the conditions store. +void ConditionsManager::pushUpdates() const { +} + /// Clean conditions, which are above the age limit. -void ConditionsManager::clean(const IOVType* typ, int max_age) { +void ConditionsManager::clean(const IOVType* typ, int max_age) const { access()->clean(typ, max_age); } /// Full cleanup of all managed conditions. -void ConditionsManager::clear() { +void ConditionsManager::clear() const { access()->clear(); } /// Prepare all updates for the given keys to the clients with the defined IOV -long ConditionsManager::prepare(const IOV& required_validity, - const ConditionKeys& keys, +long ConditionsManager::prepare(const IOV& required_validity, + const ConditionKeys& keys, dd4hep_ptr<UserPool>& user_pool) { return access()->prepare(required_validity, keys, user_pool); } @@ -137,9 +258,9 @@ long ConditionsManager::prepare(const IOV& required_validity, dd4hep_ptr<UserPoo } /// Prepare all updates to the clients with the defined IOV -long ConditionsManager::prepare(const IOV& required_validity, +long ConditionsManager::prepare(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies) { + const Dependencies& dependencies, + bool verify_dependencies) { return access()->prepare(required_validity, user_pool, dependencies, verify_dependencies); } diff --git a/DDCond/src/ConditionsOperators.cpp b/DDCond/src/ConditionsOperators.cpp index fb8f4a2d6..66e71c6a1 100644 --- a/DDCond/src/ConditionsOperators.cpp +++ b/DDCond/src/ConditionsOperators.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -15,12 +14,9 @@ // Framework include files #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" -#include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsOperators.h" #include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsInterna.h" #include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsInterna.h" using namespace std; using namespace DD4hep; @@ -44,15 +40,15 @@ size_t Operators::collectAllConditions(ConditionsManager manager, RangeCondition if ( type ) { ConditionsIOVPool* pool = manager.iovPool(*type); if ( pool ) { - const _E& e = pool->elements; - for (_E::const_iterator j=e.begin(); j != e.end(); ++j) { - ConditionsPool* cp = (*j).second; - RangeConditions rc; - cp->select_all(rc); - for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) - conditions.push_back(*ic); - num_conditions += rc.size(); - } + const _E& e = pool->elements; + for (_E::const_iterator j=e.begin(); j != e.end(); ++j) { + ConditionsPool* cp = (*j).second; + RangeConditions rc; + cp->select_all(rc); + for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) + conditions.push_back(*ic); + num_conditions += rc.size(); + } } } } @@ -76,15 +72,15 @@ size_t Operators::collectAllConditions(ConditionsManager manager, std::map<int,C if ( type ) { ConditionsIOVPool* pool = manager.iovPool(*type); if ( pool ) { - const _E& e = pool->elements; - for (_E::const_iterator j=e.begin(); j != e.end(); ++j) { - ConditionsPool* cp = (*j).second; - RangeConditions rc; - cp->select_all(rc); - for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) - conditions.insert(make_pair((*ic)->hash,*ic)); - num_conditions += rc.size(); - } + const _E& e = pool->elements; + for (_E::const_iterator j=e.begin(); j != e.end(); ++j) { + ConditionsPool* cp = (*j).second; + RangeConditions rc; + cp->select_all(rc); + for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) + conditions.insert(make_pair((*ic)->hash,*ic)); + num_conditions += rc.size(); + } } } } diff --git a/DDCond/src/ConditionsPool.cpp b/DDCond/src/ConditionsPool.cpp index 18da50512..c8902a025 100644 --- a/DDCond/src/ConditionsPool.cpp +++ b/DDCond/src/ConditionsPool.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -13,11 +12,12 @@ //========================================================================== // Framework include files +#include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsManagerObject.h" #include "DD4hep/Handle.inl" #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsInterna.h" +#include "DD4hep/objects/ConditionsInterna.h" using std::string; using namespace DD4hep; diff --git a/DDCond/src/ConditionsRepository.cpp b/DDCond/src/ConditionsRepository.cpp index f4b187ac7..a241a95c2 100644 --- a/DDCond/src/ConditionsRepository.cpp +++ b/DDCond/src/ConditionsRepository.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -14,6 +13,7 @@ // Framework include files #include "DDCond/ConditionsRepository.h" +#include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsIOVPool.h" #include "DDCond/ConditionsTags.h" #include "DD4hep/Printout.h" diff --git a/DDCond/src/ConditionsTest.cpp b/DDCond/src/ConditionsTest.cpp index 97b0fed1f..64492a28b 100644 --- a/DDCond/src/ConditionsTest.cpp +++ b/DDCond/src/ConditionsTest.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -16,6 +15,8 @@ #include "DD4hep/DetConditions.h" #include "DD4hep/DetectorTools.h" #include "DDCond/ConditionsTest.h" +#include "DDCond/ConditionsDataLoader.h" +#include "DDCond/ConditionsManager.h" #include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/objects/ConditionsInterna.h" @@ -38,10 +39,8 @@ namespace DD4hep { /// Namespace for test environments in DDCond namespace Test { - template <typename T> void print_bound_condition(Condition /* c */, const char* /* norm */) {} - template<typename T> void __print_bound_val(Condition c, const char* norm) { char text_format[1024]; const T& value = access_val<T>(c); @@ -202,38 +201,10 @@ DetElement Test::TestEnv::daughter(const string& sub_path) const { void Test::TestEnv::add_xml_data_source(const string& file, const string& iov_str) { string source = "xml:"+string(::getenv("DD4hepINSTALL"))+file; IOV iov(0); - this->manager->fromString(iov_str, iov); + this->manager.fromString(iov_str, iov); this->loader->addSource(source, iov); } -void Test::TestEnv::dump_conditions_pools() -{ - typedef RangeConditions _R; - typedef ConditionsIOVPool::Elements _E; - typedef ConditionsManagerObject::TypedConditionPool _P; - int cnt = 0; - const _P& p = manager->conditionsPool(); - for(_P::const_iterator i=p.begin(); i != p.end(); ++i, ++cnt) { - const ConditionsIOVPool* pool = (*i); - if ( pool ) { - const _E& e = pool->elements; - const IOVType* typ = this->manager->iovType(cnt); - printout(INFO,"Example","+++ ConditionsIOVPool for type %s", typ->str().c_str()); - for (_E::const_iterator j=e.begin(); j != e.end(); ++j) { - _R rc; - ConditionsPool* cp = (*j).second; - cp->select_all(rc); - printout(INFO,"Example","+++ Conditions for pool with IOV: %s age:%d", - cp->iov->str().c_str(), cp->age_value); - print_conditions<void>(rc); - } - } - } - printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - printout(INFO,"Example","SUCCESS: +++ Conditions pools successfully dumped"); - printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); -} - /// Dump the conditions of one detectpr element void Test::TestEnv::dump_detector_element(DetElement elt) { diff --git a/DDCond/src/ConditionsTest.h b/DDCond/src/ConditionsTest.h deleted file mode 100644 index 4f48943d5..000000000 --- a/DDCond/src/ConditionsTest.h +++ /dev/null @@ -1,72 +0,0 @@ -// $Id$ -//========================================================================== -// 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 -// -//========================================================================== -#ifndef DDCOND_CONDITIONSTEST_H -#define DDCOND_CONDITIONSTEST_H - -// Framework include files -#include "DD4hep/LCDD.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Conditions.h" -#include "DD4hep/DetFactoryHelper.h" - -#include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsInterna.h" - -/// Namespace for the AIDA detector description toolkit -namespace DD4hep { - - /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Conditions { - - /// Namespace for test environments in DDCond - namespace Test { - - using Geometry::LCDD; - using Geometry::Position; - using Geometry::DetElement; - - struct TestEnv { - LCDD& lcdd; - DetElement detector; - ConditionsManager manager; - Handle<ConditionsDataLoader> loader; - const IOVType* epoch; - const IOVType* run; - - TestEnv(LCDD& _lcdd, const std::string& detector_name); - /// Find daughter element of the detector object - DetElement daughter(const std::string& sub_path) const; - - void add_xml_data_source(const std::string& file); - void dump_conditions_pools(); - static void dump_detector_element(DetElement elt); - static void dump_conditions_tree(DetElement elt); - }; - - template <typename T> void print_condition(Condition condition); - template <typename T> void print_bound_value(Condition condition, const char* norm=0); - template <typename T> void print_conditions(const RangeConditions& rc); - void check_discrete_condition(Condition c, const IOV& iov); - - template<typename T> const T& access_val(Condition c) { - if ( !c->is_bound() ) { - c.bind<T>(); - } - return c.get<T>(); - } - } - } -} -#endif // DDCOND_CONDITIONSTEST_H diff --git a/DDCond/src/ConditionsTextRepository.cpp b/DDCond/src/ConditionsTextRepository.cpp index e9913f7d4..1d2e43277 100644 --- a/DDCond/src/ConditionsTextRepository.cpp +++ b/DDCond/src/ConditionsTextRepository.cpp @@ -1,4 +1,3 @@ -// $Id: ConditionsRepository.cpp 2336 2016-09-07 17:27:40Z markus.frank@cern.ch $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -17,6 +16,7 @@ #include "DDCond/ConditionsIOVPool.h" #include "DDCond/ConditionsTags.h" #include "DD4hep/Printout.h" +#include "DD4hep/objects/ConditionsInterna.h" #include "XML/DocumentHandler.h" #include "XML/XMLTags.h" diff --git a/DDCond/src/ConditionsInterna.cpp b/DDCond/src/Type1/Manager_Type1.cpp similarity index 70% rename from DDCond/src/ConditionsInterna.cpp rename to DDCond/src/Type1/Manager_Type1.cpp index dcd9976cb..99123df3a 100644 --- a/DDCond/src/ConditionsInterna.cpp +++ b/DDCond/src/Type1/Manager_Type1.cpp @@ -22,18 +22,19 @@ #include "DD4hep/InstanceCount.h" #include "DD4hep/PluginCreators.h" #include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/ConditionsListener.h" #include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/objects/ConditionsInterna.h" #include "DD4hep/objects/AlignmentsInterna.h" +#include "DD4hep/DetFactoryHelper.h" #include "DDCond/ConditionsPool.h" #include "DDCond/ConditionsEntry.h" #include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsDataLoader.h" -#include "DDCond/ConditionsInterna.h" -#include "DDCond/ConditionsListener.h" #include "DDCond/ConditionsLoaderImp.h" #include "DDCond/AlignmentsLoaderImp.h" +#include "DDCond/Type1/Manager_Type1.h" using namespace std; using namespace DD4hep; @@ -43,7 +44,12 @@ typedef Alignments::AlignmentsLoader AlignmentsLoader; typedef UpdatePool::UpdateEntries Updates; typedef RangeConditions RC; -DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsManagerObject); +DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsManagerObject_Type1); + +static void* ddcond_create_manager_instance(LCDD& lcdd, int, char**) { + return (ConditionsManagerObject*)new ConditionsManagerObject_Type1(lcdd); +} +DECLARE_LCDD_CONSTRUCTOR(DD4hep_ConditionsManager_Type1,ddcond_create_manager_instance) #define NO_AGE 0 @@ -54,10 +60,10 @@ namespace { int s_debug = INFO; /// Helper: IOV Check function declaration - template <typename T> const IOVType* check_iov_type(const ConditionsManagerObject* o, const IOV* iov); + template <typename T> const IOVType* check_iov_type(const ConditionsManagerObject_Type1* o, const IOV* iov); /// Helper: Specialized IOV check - template <> const IOVType* check_iov_type<void>(const ConditionsManagerObject* o, const IOV* iov) { + template <> const IOVType* check_iov_type<void>(const ConditionsManagerObject_Type1* o, const IOV* iov) { if ( iov ) { const IOVType* typ = iov->iovType ? iov->iovType : o->iovType(iov->type); if ( typ ) { @@ -74,20 +80,20 @@ namespace { } /// Helper: Specialized IOV check for discrete IOV values - template <> const IOVType* check_iov_type<Discrete>(const ConditionsManagerObject* o, const IOV* iov) { + template <> const IOVType* check_iov_type<Discrete>(const ConditionsManagerObject_Type1* o, const IOV* iov) { const IOVType* typ = check_iov_type<void>(o,iov); if ( typ && !iov->has_range() ) return typ; return 0; } /// Helper: Specialized IOV check for range IOV values - template <> const IOVType* check_iov_type<Range>(const ConditionsManagerObject* o, const IOV* iov) { + template <> const IOVType* check_iov_type<Range>(const ConditionsManagerObject_Type1* o, const IOV* iov) { const IOVType* typ = check_iov_type<void>(o,iov); if ( typ && iov->has_range() ) return typ; return 0; } /// Helper: Check conditions result for consistency - template <typename T> void __check_values__(const ConditionsManagerObject* o, Condition::key_type key, const IOV* iov) + template <typename T> void __check_values__(const ConditionsManagerObject_Type1* o, Condition::key_type key, const IOV* iov) { if ( !iov ) { except("ConditionsManager","+++ Invalid IOV to access condition: %08X. [Null-reference]",key); @@ -124,18 +130,16 @@ namespace { } template <typename PMF> - void __callListeners(const ConditionsManagerObject::Listeners& listeners, PMF pmf, Condition& cond) { + void __callListeners(const ConditionsManagerObject_Type1::Listeners& listeners, PMF pmf, Condition& cond) { for(const auto& listener : listeners ) (listener.first->*pmf)(cond, listener.second); } } /// Standard constructor -ConditionsManagerObject::ConditionsManagerObject(LCDD& lcdd_instance) - : NamedObject(), ObjectExtensions(typeid(ConditionsManagerObject)), m_lcdd(lcdd_instance), m_iovTypes(), m_rawPool(), - m_updateLock(), m_poolLock(), m_loader(), - m_updatePool(), - locked(0) +ConditionsManagerObject_Type1::ConditionsManagerObject_Type1(LCDD& lcdd_instance) + : ConditionsManagerObject(lcdd_instance), ObjectExtensions(typeid(ConditionsManagerObject_Type1)), + m_rawPool(), m_updateLock(), m_poolLock(), m_updatePool(), m_locked(0) { InstanceCount::increment(this); declareProperty("MaxIOVTypes", m_maxIOVTypes=32); @@ -148,7 +152,7 @@ ConditionsManagerObject::ConditionsManagerObject(LCDD& lcdd_instance) } /// Default destructor -ConditionsManagerObject::~ConditionsManagerObject() { +ConditionsManagerObject_Type1::~ConditionsManagerObject_Type1() { Geometry::World world(m_lcdd.world()); for_each(m_rawPool.begin(), m_rawPool.end(), DestroyObject<ConditionsIOVPool*>()); if ( world.isValid() ) { @@ -162,7 +166,7 @@ ConditionsManagerObject::~ConditionsManagerObject() { InstanceCount::decrement(this); } -void ConditionsManagerObject::initialize() { +void ConditionsManagerObject_Type1::initialize() { if ( !m_updatePool.get() ) { string typ = "DD4hep_Conditions_"+m_loaderType+"_Loader"; const void* argv_loader[] = {"ConditionsDataLoader", this, 0}; @@ -182,37 +186,8 @@ void ConditionsManagerObject::initialize() { } } -void ConditionsManagerObject::registerCallee(Listeners& listeners, const Listener& callee, bool add) { - if ( add ) { - listeners.insert(callee); - return; - } - Listeners::iterator i=listeners.find(callee); - if ( i != listeners.end() ) listeners.erase(i); -} - -/// (Un)Registration of conditions listeners with callback when a new condition is registered -void ConditionsManagerObject::callOnRegister(const Listener& callee, bool add) { - registerCallee(m_onRegister, callee, add); -} - -/// (Un)Registration of conditions listeners with callback when a condition is de-registered -void ConditionsManagerObject::callOnRemove(const Listener& callee, bool add) { - registerCallee(m_onRemove, callee, add); -} - -/// Call this when a condition is registered to the cache -void ConditionsManagerObject::onRegister(Condition condition) { - __callListeners(m_onRegister, &ConditionsListener::onRegisterCondition, condition); -} - -/// Call this when a condition is deregistered from the cache -void ConditionsManagerObject::onRemove(Condition condition) { - __callListeners(m_onRemove, &ConditionsListener::onRemoveCondition, condition); -} - /// Register new IOV type if it does not (yet) exist. -pair<bool, const IOVType*> ConditionsManagerObject::registerIOVType(size_t iov_type, const string& iov_name) { +pair<bool, const IOVType*> ConditionsManagerObject_Type1::registerIOVType(size_t iov_type, const string& iov_name) { if ( iov_type<m_iovTypes.size() ) { IOVType& t = m_iovTypes[iov_type]; bool eq_type = t.type == iov_type; @@ -235,7 +210,7 @@ pair<bool, const IOVType*> ConditionsManagerObject::registerIOVType(size_t iov_t } /// Access IOV by its type -const IOVType* ConditionsManagerObject::iovType (size_t iov_type) const { +const IOVType* ConditionsManagerObject_Type1::iovType (size_t iov_type) const { if ( iov_type<m_iovTypes.size() ) { const IOVType& t = m_iovTypes[iov_type]; if ( t.type == iov_type ) return &t; @@ -245,59 +220,15 @@ const IOVType* ConditionsManagerObject::iovType (size_t iov_type) const { } /// Access IOV by its name -const IOVType* ConditionsManagerObject::iovType (const string& iov_name) const { +const IOVType* ConditionsManagerObject_Type1::iovType (const string& iov_name) const { for( const auto& i : m_iovTypes ) if ( i.name == iov_name ) return &i; except("ConditionsManager","Request to access an unregistered IOV type: %s.", iov_name.c_str()); return 0; } -/// Create IOV from string -void ConditionsManagerObject::fromString(const std::string& data, IOV& iov) { - size_t id1 = data.find(','); - size_t id2 = data.find('#'); - if ( id2 == string::npos ) { - except("ConditionsManager","+++ Unknown IOV string representation: %s",data.c_str()); - } - string iov_name = data.substr(id2+1); - IOV::Key key; - int nents = 0; - if ( id1 != string::npos ) - nents = ::sscanf(data.c_str(),"%ld,%ld#",&key.first,&key.second) == 2 ? 2 : 0; - else { - nents = ::sscanf(data.c_str(),"%ld#",&key.first) == 1 ? 1 : 0; - key.second = key.first; - } - if ( nents == 0 ) { - except("ConditionsManager", - "+++ Failed to read keys from IOV string representation: %s",data.c_str()); - } - - // Check if this IOV type is known - const IOVType* typ = iovType(iov_name); - if ( !typ ) { - // Severe: We have an unknown IOV type. This is not allowed, - // because we do not known hot to handle it..... - except("ConditionsManager","+++ Unknown IOV type requested from data: %s. [%s]", - data.c_str(),Errors::invalidArg().c_str()); - } - iov.type = typ->type; - iov.iovType = typ; - iov.set(key); -} - -/// Register IOV using new string data -ConditionsPool* ConditionsManagerObject::registerIOV(const string& data) { - IOV iov(0); - // Convert string to IOV - fromString(data, iov); - // IOV read and checked. Now register it. - // The validity of iov->iovType is already ensured in 'fromString' - return registerIOV(*iov.iovType, iov.keyData); -} - /// Register IOV with type and key -ConditionsPool* ConditionsManagerObject::registerIOV(const IOVType& typ, IOV::Key key) { +ConditionsPool* ConditionsManagerObject_Type1::registerIOV(const IOVType& typ, IOV::Key key) { // IOV read and checked. Now register it, but always locked! ConditionsIOVPool* pool = m_rawPool[typ.type]; dd4hep_lock_t lock(m_poolLock); @@ -318,8 +249,13 @@ ConditionsPool* ConditionsManagerObject::registerIOV(const IOVType& typ, IOV::Ke return cond_pool; } +/// Access conditions multi IOV pool by iov type +ConditionsIOVPool* ConditionsManagerObject_Type1::iovPool(const IOVType& iov_type) const { + return m_rawPool[iov_type.type]; +} + /// Register new condition with the conditions store. Unlocked version, not multi-threaded -bool ConditionsManagerObject::registerUnlocked(ConditionsPool* pool, Condition cond) { +bool ConditionsManagerObject_Type1::registerUnlocked(ConditionsPool* pool, Condition cond) { if ( pool && cond.isValid() ) { cond->pool = pool; cond->iov = pool->iov; @@ -338,9 +274,9 @@ bool ConditionsManagerObject::registerUnlocked(ConditionsPool* pool, Condition c /// Set a single conditions value to be managed. /// Requires external lock on update pool! -Condition ConditionsManagerObject::__queue_update(Conditions::Entry* e) { +Condition ConditionsManagerObject_Type1::__queue_update(Conditions::Entry* e) { if ( e ) { - ConditionsPool* p = registerIOV(e->validity); + ConditionsPool* p = this->ConditionsManagerObject::registerIOV(e->validity); Condition condition(e->name,e->type); Condition::Object* c = condition.ptr(); //c->name = e->name; @@ -363,7 +299,7 @@ Condition ConditionsManagerObject::__queue_update(Conditions::Entry* e) { } /// Clean conditions, which are above the age limit. -int ConditionsManagerObject::clean(const IOVType* typ, int max_age) { +int ConditionsManagerObject_Type1::clean(const IOVType* typ, int max_age) { int count = 0; dd4hep_lock_t lock(m_updateLock); ConditionsIOVPool* pool = m_rawPool[typ->type]; @@ -374,7 +310,7 @@ int ConditionsManagerObject::clean(const IOVType* typ, int max_age) { } /// Full cleanup of all managed conditions. -pair<int,int> ConditionsManagerObject::clear() { +pair<int,int> ConditionsManagerObject_Type1::clear() { pair<int,int> count(0,0); for( TypedConditionPool::iterator i=m_rawPool.begin(); i != m_rawPool.end(); ++i) { ConditionsIOVPool* p = *i; @@ -387,7 +323,7 @@ pair<int,int> ConditionsManagerObject::clear() { } /// Push all pending updates to the conditions store -void ConditionsManagerObject::pushUpdates() { +void ConditionsManagerObject_Type1::pushUpdates() { Updates entries; { dd4hep_lock_t lock(m_updateLock); m_updatePool->popEntries(entries); @@ -407,7 +343,7 @@ void ConditionsManagerObject::pushUpdates() { } /// Helper to check iov and user pool and create user pool if not present -void ConditionsManagerObject::__get_checked_pool(const IOV& req_iov, +void ConditionsManagerObject_Type1::__get_checked_pool(const IOV& req_iov, dd4hep_ptr<UserPool>& up) { const IOVType* typ = check_iov_type<Discrete>(this, &req_iov); @@ -426,7 +362,7 @@ void ConditionsManagerObject::__get_checked_pool(const IOV& req_iov, } /// Prepare all updates for the given keys to the clients with the defined IOV -long ConditionsManagerObject::prepare(const IOV& req_iov, +long ConditionsManagerObject_Type1::prepare(const IOV& req_iov, const ConditionKeys& keys, dd4hep_ptr<UserPool>& up) { @@ -440,7 +376,7 @@ long ConditionsManagerObject::prepare(const IOV& req_iov, /// Prepare all updates for the given keys to the clients with the defined IOV -long ConditionsManagerObject::prepare(const IOV& req_iov, +long ConditionsManagerObject_Type1::prepare(const IOV& req_iov, const ConditionKeys& keys, dd4hep_ptr<UserPool>& up, const Dependencies& dependencies, @@ -455,7 +391,7 @@ long ConditionsManagerObject::prepare(const IOV& req_iov, } /// Prepare all updates to the clients with the defined IOV -long ConditionsManagerObject::prepare(const Condition::iov_type& req_iov, dd4hep_ptr<UserPool>& up) { +long ConditionsManagerObject_Type1::prepare(const Condition::iov_type& req_iov, dd4hep_ptr<UserPool>& up) { RC valid, expired; __get_checked_pool(req_iov, up); /// First push any pending updates and register them to pending pools... @@ -465,7 +401,7 @@ long ConditionsManagerObject::prepare(const Condition::iov_type& req_iov, dd4hep } /// Prepare all updates to the clients with the defined IOV -long ConditionsManagerObject::prepare(const Condition::iov_type& req_iov, +long ConditionsManagerObject_Type1::prepare(const Condition::iov_type& req_iov, dd4hep_ptr<UserPool>& up, const Dependencies& dependencies, bool verify_dependencies) @@ -478,37 +414,8 @@ long ConditionsManagerObject::prepare(const Condition::iov_type& req_iov, return num_raw_updates; } -/// Register a new managed condition -void ConditionsManagerObject::registerCondition(Condition c) { - dd4hep_ptr<Condition::Object> cond(c.ptr()); - if ( !cond.get() ) { - except("ConditionsManager","+++ Failed to register invalid handle."); - } - if ( !locked ) { - IOV* iov = const_cast<IOV*>(cond->iov); - // Check arguments. This also checks the existence of the proper pool - __check_values__<Discrete>(this,cond->hash,iov); - ConditionsIOVPool* pool = m_rawPool[iov->type]; - { // We are now modifying the pool: need to lock any access - dd4hep_lock_t lock(m_poolLock); - ConditionsIOVPool::Elements::iterator it = pool->elements.find(iov->keyData); - if ( it != pool->elements.end() ) { - (*it).second->insert(c); - return; - } - const void* argv_pool[] = {this, 0}; - ConditionsPool* cp = createPlugin<ConditionsPool>(m_poolType,m_lcdd,1,argv_pool); - pool->elements.insert(make_pair(iov->keyData,cp)); - cp->insert(c); - onRegister(c); - } - return; - } - except("ConditionsManager","+++ You cannot register new conditions while the conditions manager is locked!"); -} - /// Retrieve a condition set given a Detector Element and the conditions name according to their validity -bool ConditionsManagerObject::select(Condition::key_type key, +bool ConditionsManagerObject_Type1::select(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& conditions) { { @@ -525,7 +432,7 @@ bool ConditionsManagerObject::select(Condition::key_type key, } /// Retrieve a condition set given a Detector Element and the conditions name according to their validity -bool ConditionsManagerObject::select_range(Condition::key_type key, +bool ConditionsManagerObject_Type1::select_range(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& conditions) { @@ -542,29 +449,9 @@ bool ConditionsManagerObject::select_range(Condition::key_type key, return is_range_complete(req_validity,conditions); } -#if 0 -/// Register a new managed condition. -void ConditionsManagerObject::__register_immediate(RangeConditions& rc) { - // We modify the pool. For this we need a lock, - // since this may happen during the event processing in parallel - dd4hep_lock_t locked_action(m_poolLock); - for(RC::iterator i=rc.begin(); i != rc.end(); ++i) { - Condition c = *i; - if ( !c->pool ) { - except("ConditionsManager","+++ __register_immediate: Invalid pool. [Fatal, Internal or Usage Error]"); - } - if ( s_debug > INFO ) { - printout(INFO,"ConditionsManager","+++ __register(1): %s [%s]", - c.name().c_str(), c->iov->str().c_str()); - } - c->pool->insert(c); - } -} -#endif - /// Retrieve a condition given a Detector Element and the conditions name Condition -ConditionsManagerObject::get(Condition::key_type key, const Condition::iov_type& iov) +ConditionsManagerObject_Type1::get(Condition::key_type key, const Condition::iov_type& iov) { RC conditions; __check_values__<Discrete>(this, key, &iov); @@ -599,7 +486,7 @@ ConditionsManagerObject::get(Condition::key_type key, const Condition::iov_type& /// Retrieve a condition given a Detector Element and the conditions name RangeConditions -ConditionsManagerObject::getRange(Condition::key_type key, const Condition::iov_type& iov) +ConditionsManagerObject_Type1::getRange(Condition::key_type key, const Condition::iov_type& iov) { RC conditions; __check_values__<Range>(this, key, &iov); diff --git a/DDCond/src/plugins/ConditionsExample.cpp b/DDCond/src/plugins/ConditionsExample.cpp index 1e88edcb6..dc4206bc1 100644 --- a/DDCond/src/plugins/ConditionsExample.cpp +++ b/DDCond/src/plugins/ConditionsExample.cpp @@ -114,7 +114,7 @@ namespace { env.add_xml_data_source("/examples/Conditions/xml/TPC_run_563543.xml","563543#run"); env.add_xml_data_source("/examples/Conditions/xml/TPC_run_234567.xml","234567#run"); print_tpc_discrete_conditions(env); - env.dump_conditions_pools(); + lcdd.apply("DD4hep_ConditionsDump",0,0); print_tpc_range_conditions(env,234567,563543); // Should fail ! print_tpc_range_conditions(env,123456,563543); // Should fail ! diff --git a/DDCond/src/plugins/ConditionsLinearPool.cpp b/DDCond/src/plugins/ConditionsLinearPool.cpp index e548263d7..1407d0b43 100644 --- a/DDCond/src/plugins/ConditionsLinearPool.cpp +++ b/DDCond/src/plugins/ConditionsLinearPool.cpp @@ -14,7 +14,6 @@ #define DDCOND_CONDITIONSLINEARPOOL_H // Framework include files -#include "DD4hep/objects/ConditionsInterna.h" #include "DDCond/ConditionsPool.h" #include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsSelectors.h" @@ -30,6 +29,11 @@ namespace DD4hep { /// Class implementing the conditions collection for a given IOV type /** + * Please note: + * Users should not directly interact with object instances of this type. + * Data are not thread protected and interaction may cause serious harm. + * Only the ConditionsManager implementation should interact with + * this class or any subclass to ensure data integrity. * * \author M.Frank * \version 1.0 @@ -181,6 +185,7 @@ namespace DD4hep { #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" +using DD4hep::Handle; using namespace DD4hep::Conditions; /// Default constructor diff --git a/DDCond/src/plugins/ConditionsMappedPool.cpp b/DDCond/src/plugins/ConditionsMappedPool.cpp index d0d796bc2..5b66ae171 100644 --- a/DDCond/src/plugins/ConditionsMappedPool.cpp +++ b/DDCond/src/plugins/ConditionsMappedPool.cpp @@ -16,7 +16,6 @@ // Framework include files #include "DD4hep/objects/ConditionsInterna.h" #include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsSelectors.h" // C/C++ include files @@ -31,6 +30,12 @@ namespace DD4hep { /// Class implementing the conditions collection for a given IOV type /** + * + * Please note: + * Users should not directly interact with object instances of this type. + * Data are not thread protected and interaction may cause serious harm. + * Only the ConditionsManager implementation should interact with + * this class or any subclass to ensure data integrity. * * \author M.Frank * \version 1.0 @@ -167,7 +172,6 @@ namespace DD4hep { } /* End namespace DD4hep */ #endif // DDCOND_CONDITIONSMAPPEDPOOL_H -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -186,6 +190,7 @@ namespace DD4hep { #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" +using DD4hep::Handle; using namespace DD4hep::Conditions; /// Default constructor @@ -206,7 +211,7 @@ namespace { typedef Condition::key_type key_type; ConditionsManager _mgr(int argc, char** argv) { if ( argc > 0 ) { - ConditionsManager::Object* m = (ConditionsManager::Object*)argv[0]; + ConditionsManagerObject* m = (ConditionsManagerObject*)argv[0]; return m; } DD4hep::except("ConditionsMappedPool","++ Insufficient arguments: arg[0] = ConditionManager!"); diff --git a/DDCond/src/plugins/ConditionsMultiLoader.cpp b/DDCond/src/plugins/ConditionsMultiLoader.cpp index 9687b5b2e..65738ad12 100644 --- a/DDCond/src/plugins/ConditionsMultiLoader.cpp +++ b/DDCond/src/plugins/ConditionsMultiLoader.cpp @@ -77,14 +77,13 @@ namespace DD4hep { // \version 1.0 // //========================================================================== -// $Id$ // Framework include files //#include "ConditionsMultiLoader.h" #include "DD4hep/Printout.h" #include "DD4hep/Factories.h" #include "DD4hep/PluginCreators.h" -#include "DD4hep/objects/ConditionsInterna.h" +#include "DDCond/ConditionsManager.h" // Forward declartions using std::string; @@ -93,7 +92,7 @@ using namespace DD4hep::Conditions; namespace { void* create_loader(DD4hep::Geometry::LCDD& lcdd, int argc, char** argv) { const char* name = argc>0 ? argv[0] : "MULTILoader"; - ConditionsManagerObject* mgr = (ConditionsManagerObject*)(argc>0 ? argv[1] : 0); + ConditionsManager::Object* mgr = (ConditionsManager::Object*)(argc>0 ? argv[1] : 0); return new ConditionsMultiLoader(lcdd,ConditionsManager(mgr),name); } } @@ -194,7 +193,7 @@ size_t ConditionsMultiLoader::update(const iov_type& req_validity, size_t items = load(cond->hash,req_validity,upda); if ( items < 1 ) { // Error: no such condition - except("ConditionsManager", + except("MultiLoader", "+++ update_expired: Cannot update condition %s [%s] to iov:%s.", cond->name.c_str(), cond->iov->str().c_str(), req_validity.str().c_str()); } diff --git a/DDCond/src/plugins/ConditionsParser.cpp b/DDCond/src/plugins/ConditionsParser.cpp index 25212f766..921a6be8a 100644 --- a/DDCond/src/plugins/ConditionsParser.cpp +++ b/DDCond/src/plugins/ConditionsParser.cpp @@ -22,9 +22,8 @@ #include "DDCond/ConditionsTags.h" #include "DDCond/ConditionsEntry.h" -#include "DDCond/ConditionsDataLoader.h" #include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsInterna.h" +#include "DDCond/ConditionsDataLoader.h" /* * DD4hep namespace declaration diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index c9b39f4bc..91f1318aa 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -19,12 +19,13 @@ #include "DD4hep/PluginCreators.h" #include "DD4hep/DetFactoryHelper.h" #include "DD4hep/ConditionsPrinter.h" +#include "DD4hep/DetectorProcessor.h" +#include "DD4hep/objects/ConditionsInterna.h" #include "DDCond/ConditionsManager.h" +#include "DDCond/ConditionsManagerObject.h" #include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsInterna.h" #include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsInterna.h" #include "DDCond/ConditionsRepository.h" using namespace std; @@ -42,20 +43,51 @@ using Geometry::PlacedVolume; * \date 01/04/2016 */ static int ddcond_install_cond_mgr (LCDD& lcdd, int argc, char** argv) { + Handle<NamedObject>* h = 0; Handle<ConditionsManagerObject> mgr(lcdd.extension<ConditionsManagerObject>(false)); if ( !mgr.isValid() ) { - ConditionsManager mgr_handle(lcdd); - lcdd.addExtension<ConditionsManagerObject>(mgr_handle.ptr()); + bool arg_error = false; + string factory = "DD4hep_ConditionsManager_Type1"; + for(int i=0; i<argc && argv[i]; ++i) { + if ( 0 == ::strncmp("-type",argv[i],4) ) + factory = argv[++i]; + else if ( 0 == ::strncmp("-handle",argv[i],5) ) + h = (Handle<NamedObject>*)argv[++i]; + else + arg_error = true; + } + if ( arg_error ) { + /// Help printout describing the basic command line interface + cout << + "Usage: -plugin <name> -arg [-arg] \n" + " name: factory name DD4hep_ConditionsManagerInstaller \n" + " -type <string> Manager type. \n" + " Default: ConditionsManagerObject_Type1_t \n" + " -handle <pointer> Pointer to Handle<NamedObject> to pass pointer \n" + " to the caller. \n" + "\tArguments given: " << arguments(argc,argv) << endl << flush; + ::exit(EINVAL); + } + ConditionsManagerObject* obj = createPlugin<ConditionsManagerObject>(factory,lcdd); + if ( !obj ) { + except("ConditionsManagerInstaller","Failed to create manager object of type %s", + factory.c_str()); + } + lcdd.addExtension<ConditionsManagerObject>(obj); printout(INFO,"ConditionsManager", - "+++ Successfully installed conditions manager instance to LCDD."); - mgr = mgr_handle; + "+++ Successfully installed conditions manager instance '%s' to LCDD.", + factory.c_str()); + mgr = obj; } - if ( argc == 2 ) { - if ( ::strncmp(argv[0],"-handle",7)==0 ) { - Handle<NamedObject>* h = (Handle<NamedObject>*)argv[1]; - *h = mgr; + else if ( argc > 0 ) { + for(int i=0; i<argc && argv[i]; ++i) { + if ( 0 == ::strncmp("-handle",argv[i],5) ) { + h = (Handle<NamedObject>*)argv[++i]; + break; + } } } + if ( h ) *h = mgr; return 1; } DECLARE_APPLY(DD4hep_ConditionsManagerInstaller,ddcond_install_cond_mgr) @@ -159,7 +191,7 @@ DECLARE_APPLY(DD4hep_ConditionsDump,ddcond_dump_conditions) */ static int ddcond_detelement_dump(LCDD& lcdd, int /* argc */, char** /* argv */) { - struct Actor { + struct Actor : public Geometry::DetectorProcessor { ConditionsManager manager; ConditionsPrinter printer; dd4hep_ptr<UserPool> user_pool; @@ -178,15 +210,14 @@ static int ddcond_detelement_dump(LCDD& lcdd, int /* argc */, char** /* argv */) printer.setPool(user_pool.get()); } /// Default destructor - ~Actor() { + virtual ~Actor() { manager.clean(iov_type, 20); user_pool->clear(); user_pool.release(); } /// Dump method. - long dump(DetElement de,int level) { + virtual int operator()(DetElement de,int level) { const DetElement::Children& children = de.children(); - PlacedVolume place = de.placement(); char sens = place.volume().isSensitive() ? 'S' : ' '; char fmt[128], tmp[32]; @@ -198,12 +229,10 @@ static int ddcond_detelement_dump(LCDD& lcdd, int /* argc */, char** /* argv */) if ( de.hasConditions() ) { printer.processElement(de); } - for (const auto& c : de.children() ) - dump(c.second,level+1); return 1; } }; - return Actor(ConditionsManager::from(lcdd)).dump(lcdd.world(),0); + return Actor(ConditionsManager::from(lcdd)).process(lcdd.world(),0,true); } DECLARE_APPLY(DD4hep_DetElementConditionsDump,ddcond_detelement_dump) @@ -256,14 +285,15 @@ DECLARE_LCDD_CONSTRUCTOR(DD4hep_ConditionsPrepare,ddcond_prepare) */ static int ddcond_detelement_processor(LCDD& lcdd, int argc, char** argv) { - struct Actor { + struct Actor : public Geometry::DetElementProcessor<ConditionsProcessor> { ConditionsManager manager; - ConditionsProcessor* processor; dd4hep_ptr<UserPool> user_pool; const IOVType* iov_type; /// Standard constructor - Actor(ConditionsProcessor* p, ConditionsManager m) : manager(m), processor(p) { + Actor(ConditionsProcessor* p, ConditionsManager m) + : DetElementProcessor<ConditionsProcessor>(p), manager(m) + { iov_type = manager.iovType("run"); IOV iov(iov_type); iov.set(1500); @@ -276,18 +306,16 @@ static int ddcond_detelement_processor(LCDD& lcdd, int argc, char** argv) { } /// Default destructor - ~Actor() { + virtual ~Actor() { manager.clean(iov_type, 20); user_pool->clear(); user_pool.release(); } /// Dump method. - long dump(DetElement de) { + virtual int operator()(DetElement de, int) { if ( de.hasConditions() ) { - processor->processElement(de); + return processor->processElement(de); } - for (const auto& c : de.children() ) - dump(c.second); return 1; } }; @@ -299,7 +327,7 @@ static int ddcond_detelement_processor(LCDD& lcdd, int argc, char** argv) { const void* args[] = { "-processor", "DD4hepConditionsPrinter", 0}; processor = createProcessor<ConditionsProcessor>(lcdd, 2, (char**)args); } - return Actor(processor,ConditionsManager::from(lcdd)).dump(lcdd.world()); + return Actor(processor,ConditionsManager::from(lcdd)).process(lcdd.world(),0,true); } DECLARE_APPLY(DD4hep_DetElementConditionsProcessor,ddcond_detelement_processor) diff --git a/DDCond/src/plugins/ConditionsRepositoryParser.cpp b/DDCond/src/plugins/ConditionsRepositoryParser.cpp index a8c68cc53..9f9f5b466 100644 --- a/DDCond/src/plugins/ConditionsRepositoryParser.cpp +++ b/DDCond/src/plugins/ConditionsRepositoryParser.cpp @@ -26,7 +26,6 @@ #include "DDCond/ConditionsTags.h" #include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsInterna.h" // C/C++ include files #include <stdexcept> @@ -94,9 +93,11 @@ namespace { DetElement detector; ConditionsPool* pool; ConditionsManager manager; + ConversionArg() = delete; + ConversionArg(const ConversionArg&) = delete; ConversionArg(DetElement det, ConditionsManager m) : detector(det), pool(0), manager(m) - { - } + { } + ConversionArg& operator=(const ConversionArg&) = delete; }; /// Local helper class to interprete XML conditions @@ -224,7 +225,7 @@ namespace DD4hep { ConversionArg* arg = _param<ConversionArg>(); CurrentPool pool(arg); printout(s_parseLevel,"XMLConditions","++ Reading IOV file: %s -> %s", val.c_str(), ref.c_str()); - pool.set(arg->manager->registerIOV(val)); + pool.set(arg->manager.registerIOV(val)); XML::DocumentHolder doc(XML::DocumentHandler().load(element, element.attr_value(_U(ref)))); Converter<conditions>(lcdd,param,optional)(doc.root()); } diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp index 9741a17bf..bb1c21fd8 100644 --- a/DDCond/src/plugins/ConditionsUserPool.cpp +++ b/DDCond/src/plugins/ConditionsUserPool.cpp @@ -25,19 +25,27 @@ namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit namespace Conditions { + /// Forward declarations + class ConditionsDataLoader; + /// Class implementing the conditions user pool for a given IOV type /** + * + * Please note: + * Users should not directly interact with object instances of this type. + * Data are not thread protected and interaction may cause serious harm. + * Only the ConditionsManager implementation should interact with + * this class or any subclass to ensure data integrity. * * \author M.Frank * \version 1.0 * \ingroup DD4HEP_CONDITIONS */ template<typename MAPPING> - class ConditionsMappedUserPool : public UserPool - { + class ConditionsMappedUserPool : public UserPool { typedef MAPPING Mapping; - Mapping m_conditions; - + Mapping m_conditions; + ConditionsDataLoader* m_loader; Condition::Object* i_findCondition(key_type key) const; public: @@ -72,12 +80,10 @@ namespace DD4hep { /// Evaluate and register all derived conditions from the dependency list virtual long compute(const Dependencies& dependencies, void* user_param); }; + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DDCOND_CONDITIONSMAPPEDUSERPOOL_H */ - } /* End namespace Conditions */ -} /* End namespace DD4hep */ -#endif // DDCOND_CONDITIONSMAPPEDUSERPOOL_H - -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -96,10 +102,11 @@ namespace DD4hep { #include "DD4hep/Printout.h" #include "DD4hep/Factories.h" #include "DD4hep/InstanceCount.h" -#include "DD4hep/objects/ConditionsInterna.h" -#include "DDCond/ConditionsInterna.h" + #include "DDCond/ConditionsIOVPool.h" #include "DDCond/ConditionsSelectors.h" +#include "DDCond/ConditionsDataLoader.h" +#include "DDCond/ConditionsManagerObject.h" #include "DDCond/ConditionsDependencyHandler.h" using namespace DD4hep::Conditions; @@ -122,6 +129,12 @@ ConditionsMappedUserPool<MAPPING>::ConditionsMappedUserPool(ConditionsManager mg : UserPool(mgr, pool) { InstanceCount::increment(this); + if ( mgr.isValid() ) { + m_loader = mgr->loader(); + if ( m_loader ) return; + except("UserPool","The conditions manager is not properly setup. No conditions loader present."); + } + except("UserPool","FAILED to create user pool. [Invalid conditions manager]"); } /// Default destructor @@ -229,7 +242,7 @@ long ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required) { for_each(valid.begin(),valid.end(),Inserter<MAPPING>(m_conditions)); long num_expired = (long)expired.size(); if ( num_expired > 0 ) { - m_manager->loader()->update(required, expired, pool_iov); + m_loader->update(required, expired, pool_iov); for_each(expired.begin(),expired.end(),Inserter<MAPPING>(m_conditions)); } m_iov = pool_iov; @@ -248,7 +261,7 @@ long ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required, const Condi typename MAPPING::const_iterator i=m_conditions.find(k.hash); if ( i == m_conditions.end() ) { RangeConditions loaded; - m_manager->loader()->load(k.hash, required, loaded); + m_loader->load(k.hash, required, loaded); if ( loaded.empty() ) { DD4hep::except("UserPool","++ Failed to load condition: %s",k.name.c_str()); } @@ -264,8 +277,9 @@ template<typename MAPPING> long ConditionsMappedUserPool<MAPPING>::compute(const Dependencies& deps, void* user_param) { long num_updates = 0; if ( !deps.empty() ) { - ConditionsDependencyHandler handler(m_manager.ptr(), *this, deps, user_param); - ConditionsPool* pool = m_manager->registerIOV(*m_iov.iovType, m_iov.keyData); + ConditionsManagerObject* m = m_manager.access(); + ConditionsDependencyHandler handler(m, *this, deps, user_param); + ConditionsPool* pool = m->registerIOV(*m_iov.iovType, m_iov.keyData); // Loop over the dependencies and check if they have to be upgraded for ( const auto& i : deps ) { typename MAPPING::iterator j = m_conditions.find(i.first); @@ -278,7 +292,7 @@ long ConditionsMappedUserPool<MAPPING>::compute(const Dependencies& deps, void* } const ConditionDependency* d = i.second.get(); Condition::Object* cond = handler(d); - m_manager->registerUnlocked(pool, cond); // Would bulk update be more efficient? + m->registerUnlocked(pool, cond); // Would bulk update be more efficient? ++num_updates; } } @@ -288,7 +302,7 @@ long ConditionsMappedUserPool<MAPPING>::compute(const Dependencies& deps, void* namespace { void* create_user_pool(DD4hep::Geometry::LCDD&, int argc, char** argv) { if ( argc > 1 ) { - ConditionsManager::Object* m = (ConditionsManager::Object*)argv[0]; + ConditionsManagerObject* m = (ConditionsManagerObject*)argv[0]; ConditionsIOVPool* p = (ConditionsIOVPool*)argv[1]; UserPool* pool = new ConditionsMappedUserPool<std::map<Condition::key_type,Condition::Object*> >(m, p); return pool; diff --git a/DDCond/src/plugins/ConditionsXmlLoader.cpp b/DDCond/src/plugins/ConditionsXmlLoader.cpp index ba35d23bc..87ecd64fb 100644 --- a/DDCond/src/plugins/ConditionsXmlLoader.cpp +++ b/DDCond/src/plugins/ConditionsXmlLoader.cpp @@ -69,7 +69,6 @@ namespace DD4hep { #include "XML/XMLElements.h" #include "XML/DocumentHandler.h" -#include "DDCond/ConditionsInterna.h" #include "DDCond/ConditionsEntry.h" // C/C++ include files @@ -114,7 +113,8 @@ size_t ConditionsXmlLoader::load_source(const std::string& nam, if ( result == &m_lcdd ) { // All OK. for (ConditionsStack::iterator c=stack.begin(); c!=stack.end(); ++c) { Entry* e = (*c); - Condition condition = queueUpdate(e); + Condition condition;/// = queueUpdate(e); + except("ConditionsXmlLoader","Fix me: queueUpdate(e) not implemented"); delete e; if ( condition.isValid() ) { if ( key == condition->hash ) { diff --git a/DDCore/include/DD4hep/AlignedVolumePrinter.h b/DDCore/include/DD4hep/AlignedVolumePrinter.h index 77759adbe..70b9706b6 100644 --- a/DDCore/include/DD4hep/AlignedVolumePrinter.h +++ b/DDCore/include/DD4hep/AlignedVolumePrinter.h @@ -46,6 +46,8 @@ namespace DD4hep { public: /// Initializing constructor AlignedVolumePrinter(const std::string& prefix="",int flags=0); + /// Initializing constructor + AlignedVolumePrinter(UserPool* pool, const std::string& prefix="",int flags=0); /// Default destructor virtual ~AlignedVolumePrinter() = default; /// Set name for printouts diff --git a/DDCore/include/DD4hep/AlignmentsPrinter.h b/DDCore/include/DD4hep/AlignmentsPrinter.h index 1c7a6726b..1bba8f208 100644 --- a/DDCore/include/DD4hep/AlignmentsPrinter.h +++ b/DDCore/include/DD4hep/AlignmentsPrinter.h @@ -46,6 +46,8 @@ namespace DD4hep { public: /// Initializing constructor AlignmentsPrinter(const std::string& prefix="",int flags=0); + /// Initializing constructor + AlignmentsPrinter(UserPool* pool, const std::string& prefix="",int flags=0); /// Default destructor virtual ~AlignmentsPrinter() = default; /// Set name for printouts diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h index 97e71a8dc..3a53d62c5 100644 --- a/DDCore/include/DD4hep/Conditions.h +++ b/DDCore/include/DD4hep/Conditions.h @@ -43,7 +43,6 @@ namespace DD4hep { // Forward declarations class ConditionsManagerObject; - class ConditionsManager; class ConditionsLoader; class UserPool; diff --git a/DDCond/include/DDCond/ConditionsListener.h b/DDCore/include/DD4hep/ConditionsListener.h similarity index 99% rename from DDCond/include/DDCond/ConditionsListener.h rename to DDCore/include/DD4hep/ConditionsListener.h index e2fd91a09..e439415a3 100644 --- a/DDCond/include/DDCond/ConditionsListener.h +++ b/DDCore/include/DD4hep/ConditionsListener.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/include/DD4hep/DetectorProcessor.h b/DDCore/include/DD4hep/DetectorProcessor.h new file mode 100644 index 000000000..2fa421a57 --- /dev/null +++ b/DDCore/include/DD4hep/DetectorProcessor.h @@ -0,0 +1,102 @@ +//========================================================================== +// 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 +// +//========================================================================== +#ifndef DD4HEP_DDCORE_DETECTORPROCESSOR_H +#define DD4HEP_DDCORE_DETECTORPROCESSOR_H + +// Framework includes +#include "DD4hep/Detector.h" + +// C/C++ include files +#include <vector> +#include <algorithm> + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the AIDA detector description toolkit supporting XML utilities + namespace Geometry { + + /// Generic Detector processor + /** + * Please note that the principle of locality applies: + * The object is designed for stack allocation and configuration. + * It may NOT be shared across threads! + * + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + * \ingroup DD4HEP_GEOMETRY + */ + class DetectorProcessor { + public: + /// Self type definition + typedef DetectorProcessor self_type; + public: + /// Initializing constructor + DetectorProcessor() = default; + /// Default destructor + virtual ~DetectorProcessor() = default; + /// Callback to output detector information of an single DetElement + virtual int operator()(DetElement de, int level); + /// Callback to output detector information of an entire DetElement + virtual int process(DetElement de, int level, bool recursive); + }; + + /// Detector scanner using a Processor object + /** + * Please see the documentation of the + * DetectorProcessor base class for further information. + * + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + * \ingroup DD4HEP_GEOMETRY + */ + template <typename T> class DetElementProcessor : virtual public DetectorProcessor { + public: + /// Collection container + T* processor; + public: + /// Default constructor + DetElementProcessor() = delete; + /// Default constructor + DetElementProcessor(T* p) : processor(p) {} + /// Default destructor + virtual ~DetElementProcessor() = default; + }; + + /// Generic Condition object collector + /** + * Please see the documentation of the + * DetectorProcessor base class for further information. + * + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + * \ingroup DD4HEP_GEOMETRY + */ + class DetectorCollector : virtual public DetectorProcessor { + public: + /// Collection container + std::vector<std::pair<int,DetElement> > detectors; + public: + /// Default constructor + DetectorCollector() = default; + /// Default destructor + virtual ~DetectorCollector() = default; + /// Callback to output detector information of an entire DetElement + virtual int operator()(DetElement de, int level); + }; + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_DDCORE_DETECTORPROCESSOR_H */ diff --git a/DDCore/include/DD4hep/IOV.h b/DDCore/include/DD4hep/IOV.h index f18c121b0..b3fabbf5a 100644 --- a/DDCore/include/DD4hep/IOV.h +++ b/DDCore/include/DD4hep/IOV.h @@ -20,6 +20,7 @@ /// Namespace for the AIDA detector description toolkit namespace DD4hep { + // Forward declarations class IOVType; class IOV; @@ -74,8 +75,10 @@ namespace DD4hep { /// Initializing constructor explicit IOV(const IOVType* typ); - /// Specialized copy constructor + /// Specialized copy constructor for range IOVs explicit IOV(const IOVType* typ, const Key& key); + /// Specialized copy constructor for discrete IOVs + explicit IOV(const IOVType* typ, Key_first_type iov_value); /// Copy constructor IOV(const IOV& copy) = default; /// Standard Destructor diff --git a/DDCore/include/DD4hep/NamedObject.h b/DDCore/include/DD4hep/NamedObject.h index 790cf2d0c..86d669dbf 100644 --- a/DDCore/include/DD4hep/NamedObject.h +++ b/DDCore/include/DD4hep/NamedObject.h @@ -35,20 +35,21 @@ namespace DD4hep { /// The object type std::string type; - /// Standard constructor - NamedObject(); /// Initializing constructor NamedObject(const char* nam, const char* typ=""); /// Initializing constructor NamedObject(const std::string& nam); /// Initializing constructor NamedObject(const std::string& nam, const std::string& typ); + + /// Standard constructor + NamedObject() = default; /// Copy constructor - NamedObject(const NamedObject& c); + NamedObject(const NamedObject& c) = default; /// Default destructor - virtual ~NamedObject(); + virtual ~NamedObject() = default; /// Assignment operator - NamedObject& operator=(const NamedObject& c); + NamedObject& operator=(const NamedObject& c) = default; /// Access name const char* GetName() const { diff --git a/DDCore/include/DD4hep/objects/ConditionsInterna.h b/DDCore/include/DD4hep/objects/ConditionsInterna.h index 125f90ba8..143ac727d 100644 --- a/DDCore/include/DD4hep/objects/ConditionsInterna.h +++ b/DDCore/include/DD4hep/objects/ConditionsInterna.h @@ -34,6 +34,9 @@ /// Namespace for the AIDA detector description toolkit namespace DD4hep { + // Forward declarations + class IOVType; + /// Namespace for the conditions part of the AIDA detector description toolkit namespace Conditions { @@ -54,6 +57,7 @@ namespace DD4hep { typedef Condition::iov_type iov_type; /// Protected destructor virtual ~ConditionsLoader(); + public: /// Addreference count. Use object virtual void addRef() = 0; diff --git a/DDCore/src/AlignedVolumePrinter.cpp b/DDCore/src/AlignedVolumePrinter.cpp index 8323ef3a4..498b6db78 100644 --- a/DDCore/src/AlignedVolumePrinter.cpp +++ b/DDCore/src/AlignedVolumePrinter.cpp @@ -25,6 +25,12 @@ AlignedVolumePrinter::AlignedVolumePrinter(const string& pref, int flg) { } +/// Initializing constructor +AlignedVolumePrinter::AlignedVolumePrinter(UserPool* p, const std::string& pref,int flg) + : AlignmentsProcessor(p), name("Alignment"), prefix(pref), m_flag(flg) +{ +} + /// Callback to output alignments information int AlignedVolumePrinter::operator()(Alignment a) { printAlignment(name, a); diff --git a/DDCore/src/AlignmentsPrinter.cpp b/DDCore/src/AlignmentsPrinter.cpp index 1ea71fe06..c9183a740 100644 --- a/DDCore/src/AlignmentsPrinter.cpp +++ b/DDCore/src/AlignmentsPrinter.cpp @@ -31,6 +31,12 @@ AlignmentsPrinter::AlignmentsPrinter(const string& pref, int flg) { } +/// Initializing constructor +AlignmentsPrinter::AlignmentsPrinter(UserPool* p, const std::string& pref,int flg) + : AlignmentsProcessor(p), name("Alignment"), prefix(pref), m_flag(flg) +{ +} + /// Callback to output alignments information int AlignmentsPrinter::operator()(Alignment a) { printAlignment(name, a); diff --git a/DDCore/src/ConditionsInterna.cpp b/DDCore/src/ConditionsInterna.cpp index 19d7626f2..0dd09506b 100644 --- a/DDCore/src/ConditionsInterna.cpp +++ b/DDCore/src/ConditionsInterna.cpp @@ -16,6 +16,7 @@ #include "DD4hep/Handle.inl" #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" +#include "DD4hep/ConditionsListener.h" #include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/objects/ConditionsInterna.h" diff --git a/DDCond/src/ConditionsListener.cpp b/DDCore/src/ConditionsListener.cpp similarity index 94% rename from DDCond/src/ConditionsListener.cpp rename to DDCore/src/ConditionsListener.cpp index fe1b92e32..cb1710787 100644 --- a/DDCond/src/ConditionsListener.cpp +++ b/DDCore/src/ConditionsListener.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -13,7 +12,7 @@ //========================================================================== // Framework include files -#include "DDCond/ConditionsListener.h" +#include "DD4hep/ConditionsListener.h" using namespace DD4hep::Conditions; diff --git a/DDCore/src/DetectorProcessor.cpp b/DDCore/src/DetectorProcessor.cpp new file mode 100644 index 000000000..1bacf0de7 --- /dev/null +++ b/DDCore/src/DetectorProcessor.cpp @@ -0,0 +1,51 @@ +//========================================================================== +// 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 +// +//========================================================================== + +// Framework includes +#include "DD4hep/Printout.h" +#include "DD4hep/DetectorProcessor.h" + +using namespace DD4hep; +using namespace DD4hep::Geometry; + +/// Callback to output detector information of an single DetElement +int DetectorProcessor::operator()(DetElement de, int /* level */) { + if ( de.isValid() ) { + return 1; + } + except("Detector","Cannot process an invalid detector element"); + return 0; +} + +/// Callback to output detector information of an entire DetElement +int DetectorProcessor::process(DetElement de, int level, bool recursive) { + if ( de.isValid() ) { + int ret = 1; + (*this)(de, level); + for (const auto& c : de.children() ) + ret += process(c.second,level+1,recursive); + return ret; + } + except("Detector","Cannot process an invalid detector element"); + return 0; +} + +/// Callback to output detector information of an single DetElement +int DetectorCollector::operator()(DetElement de, int level) { + if ( de.isValid() ) { + detectors.push_back(std::make_pair(level,de)); + return 1; + } + except("Detector","Cannot process an invalid detector element"); + return 0; +} diff --git a/DDCore/src/Fields.cpp b/DDCore/src/Fields.cpp index 0b727c73a..37a9d105d 100644 --- a/DDCore/src/Fields.cpp +++ b/DDCore/src/Fields.cpp @@ -27,8 +27,7 @@ DD4HEP_INSTANTIATE_HANDLE(OverlayedFieldObject); namespace { void calculate_combined_field(vector<CartesianField>& v, const double* pos, double* field) { - for (vector<CartesianField>::iterator i = v.begin(); i != v.end(); ++i) - (*i).value(pos, field); + for (const auto& i : v ) i.value(pos, field); } } diff --git a/DDCore/src/IOV.cpp b/DDCore/src/IOV.cpp index fc443662d..43c248445 100644 --- a/DDCore/src/IOV.cpp +++ b/DDCore/src/IOV.cpp @@ -44,6 +44,13 @@ IOV::IOV(const IOVType* t) : iovType(t), keyData(0,0), optData(0) { type = t ? t->type : int(IOVType::UNKNOWN_IOV); } +/// Specialized copy constructor for discrete IOVs +IOV::IOV(const IOVType* t, Key_first_type iov_value) + : iovType(t), keyData(iov_value,iov_value), optData(0) +{ + type = t ? t->type : int(IOVType::UNKNOWN_IOV); +} + /// Copy constructor IOV::IOV(const IOVType* t, const Key& k) : iovType(t), keyData(k), optData(0) diff --git a/DDCore/src/NamedObject.cpp b/DDCore/src/NamedObject.cpp index 51d3e1dd0..3b8566f2d 100644 --- a/DDCore/src/NamedObject.cpp +++ b/DDCore/src/NamedObject.cpp @@ -23,10 +23,6 @@ using namespace DD4hep::Geometry; DD4HEP_INSTANTIATE_HANDLE_NAMED(NamedObject); -/// Standard constructor -NamedObject::NamedObject() { -} - /// Initializing constructor NamedObject::NamedObject(const char* nam, const char* typ) : name(nam ? nam : ""), type(typ ? typ : "") @@ -44,21 +40,3 @@ NamedObject::NamedObject(const std::string& nam, const std::string& typ) : name(nam), type(typ) { } - -/// Copy constructor -NamedObject::NamedObject(const NamedObject& c) : name(c.name), type(c.type) { -} - -/// Default destructor -NamedObject::~NamedObject() { -} - -/// Assignment operator -NamedObject& NamedObject::operator=(const NamedObject& c) { - if ( this != &c ) { - name = c.name; - type = c.type; - } - return *this; -} - diff --git a/DDDB/include/DDDB/DDDBConditionsLoader.h b/DDDB/include/DDDB/DDDBConditionsLoader.h index 90f573c73..6a9bd4ac1 100644 --- a/DDDB/include/DDDB/DDDBConditionsLoader.h +++ b/DDDB/include/DDDB/DDDBConditionsLoader.h @@ -23,7 +23,7 @@ #define DD4HEP_DDDB_DDDBCONDITONSLOADER_H // Framework include files -#include "DDCond/ConditionsListener.h" +#include "DD4hep/ConditionsListener.h" #include "DDCond/ConditionsDataLoader.h" #include "XML/UriReader.h" diff --git a/DDDB/src/DDDBConditionsLoader.cpp b/DDDB/src/DDDBConditionsLoader.cpp index 857b5a9d8..64ec484fe 100644 --- a/DDDB/src/DDDBConditionsLoader.cpp +++ b/DDDB/src/DDDBConditionsLoader.cpp @@ -29,7 +29,7 @@ #include "DD4hep/Operators.h" #include "DD4hep/ConditionsData.h" #include "DD4hep/objects/ConditionsInterna.h" -#include "DDCond/ConditionsInterna.h" +#include "DDCond/ConditionsManagerObject.h" // C/C++ include files #include <set> diff --git a/DDDB/src/DDDBDerivedCondTest.cpp b/DDDB/src/DDDBDerivedCondTest.cpp index 8bfbdc8e5..896397c6c 100644 --- a/DDDB/src/DDDBDerivedCondTest.cpp +++ b/DDDB/src/DDDBDerivedCondTest.cpp @@ -30,7 +30,7 @@ #include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsIOVPool.h" #include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsInterna.h" +#include "DDCond/ConditionsManagerObject.h" #include "DDCond/ConditionsOperators.h" #include "DDDB/DDDBReader.h" diff --git a/examples/AlignDet/CMakeLists.txt b/examples/AlignDet/CMakeLists.txt index 39c1c7f48..46c5fe4d8 100644 --- a/examples/AlignDet/CMakeLists.txt +++ b/examples/AlignDet/CMakeLists.txt @@ -1,4 +1,3 @@ -# $Id: $ #========================================================================== # AIDA Detector description implementation for LCD #-------------------------------------------------------------------------- @@ -16,7 +15,7 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake ) dd4hep_configure_output() dd4hep_package ( AlignDet MAJOR 0 MINOR 0 PATCH 1 USES [ROOT REQUIRED COMPONENTS Geom GenVector MathCore] - [DD4hep REQUIRED COMPONENTS DDCore] + [DD4hep REQUIRED COMPONENTS DDCore DDAlign] OPTIONAL XERCESC INCLUDE_DIRS include ) diff --git a/examples/AlignDet/src/AlignmentExample.cpp b/examples/AlignDet/src/AlignmentExample.cpp new file mode 100644 index 000000000..9f0c34fb8 --- /dev/null +++ b/examples/AlignDet/src/AlignmentExample.cpp @@ -0,0 +1,135 @@ +//========================================================================== +// 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_AlignmentExample \ + -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml \ + -delta file:${DD4hep_DIR}/examples/Conditions/data/repository.xml + +*/ +// Framework include files +#include "DD4hep/LCDD.h" +#include "DD4hep/Printout.h" +#include "DD4hep/Conditions.h" +#include "DD4hep/Alignments.h" +#include "DD4hep/DetectorProcessor.h" +#include "DD4hep/AlignedVolumePrinter.h" +#include "DD4hep/Factories.h" + +#include "DDCond/ConditionsManager.h" +#include "DDAlign/AlignmentsManager.h" +#include "DDAlign/DDAlignUpdateCall.h" +#include "DDAlign/DDAlignForwardCall.h" +#include "DDAlign/AlignmentsRegister.h" +#include "DDAlign/AlignmentsForward.h" + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Alignments; + +namespace { + struct Proc : public Geometry::DetectorProcessor { + DetElement::Processor* proc; + virtual int operator()(DetElement de, int) + { return proc->processElement(de); } + template <typename Q> Proc& scan(Q& p, DetElement start) + { proc = &p; this->process(start, 0, true); return *this; } + }; +} + +/// Plugin function: Alignment program example +/** + * Factory: DD4hep_AlignmentExample + * + * \author M.Frank + * \version 1.0 + * \date 01/04/2016 + */ +static int alignment_example (Geometry::LCDD& lcdd, int argc, char** argv) { + + string input, delta; + 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("-deltas",argv[i],5) ) + delta = argv[++i]; + else + arg_error = true; + } + if ( arg_error || input.empty() || delta.empty() ) { + /// Help printout describing the basic command line interface + cout << + "Usage: -plugin <name> -arg [-arg] \n" + " name: factory name DD4hep_AlignmentExample \n" + " -input <string> Geometry file \n" + " -deltas <string> Alignment deltas (Conditions \n" + "\tArguments given: " << arguments(argc,argv) << endl << flush; + ::exit(EINVAL); + } + + // First we load the geometry + lcdd.fromXML(input); + // Now we instantiate the conditions manager + lcdd.apply("DD4hep_ConditionsManagerInstaller",0,(char**)0); + // Now we instantiate the alignments manager + lcdd.apply("DD4hep_AlignmentsManagerInstaller",0,(char**)0); + + Conditions::ConditionsManager condMgr = Conditions::ConditionsManager::from(lcdd); + AlignmentsManager alignMgr = AlignmentsManager::from(lcdd); + const void* delta_args[] = {delta.c_str(), 0}; // Better zero-terminate + + lcdd.apply("DD4hep_ConditionsXMLRepositoryParser",1,(char**)delta_args); + // Now the deltas are stored in the conditions manager in the proper IOV pools + const IOVType* iov_typ = condMgr.iovType("run"); + if ( 0 == iov_typ ) { + except("ConditionsPrepare","++ Unknown IOV type supplied."); + } + IOV iov(iov_typ,1500); // IOV goes from run 1000 ... 2000 + dd4hep_ptr<Conditions::UserPool> pool; // Working set up conditions for this IOV + + long num_updated = condMgr.prepare(iov, pool); + printout(DEBUG,"Example","Updated %ld conditions of type %s.",num_updated, iov_typ->str().c_str()); + + AlignmentsRegister reg(alignMgr,new DDAlignUpdateCall(),pool.get()); + AlignmentsForward fwd(alignMgr,new DDAlignForwardCall(),pool.get()); + // Let's register the callbacks to compute dependent conditions/alignments + Proc() + .scan(reg,lcdd.world()) + .scan(fwd,lcdd.world()); + + // ++++++++++++++++++++++++ Now the registration is finished. + + // ++++++++++++++++++++++++ The following has to be done for each new IOV.... + + // Need to compute the conditions sources + num_updated = condMgr.prepare(iov, pool); + printout(DEBUG,"Example","Updated %ld conditions of type %s.",num_updated, iov_typ->str().c_str()); + + // Let's compute the tranformation matrices + alignMgr.compute(pool); + + // What else ? let's print the result + AlignedVolumePrinter printer(pool.get(),"ExamplePrint"); + Proc().scan(printer,lcdd.world()); + + // All done. + return 1; +} + +// first argument is the type from the xml file +DECLARE_APPLY(DD4hep_AlignmentExample,alignment_example) diff --git a/examples/DDG4/CMakeLists.txt b/examples/DDG4/CMakeLists.txt index d619ab606..7cb546fd9 100644 --- a/examples/DDG4/CMakeLists.txt +++ b/examples/DDG4/CMakeLists.txt @@ -29,7 +29,7 @@ if (DD4HEP_USE_GEANT4) dd4hep_add_test_reg( test_DDG4_HepMC_reader COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4.sh" EXEC_ARGS python ${DD4hep_DIR}/examples/DDG4/examples/readHEPMC.py - ${CMAKE_INSTALL_PREFIX}/DDG4/data/hepmc_geant4.dat + ${DD4hep_DIR}/examples/DDG4/data/hepmc_geant4.dat REQUIRES DDG4 Geant4 REGEX_PASS "EventReaderHepMC::moveToEvent INFO Current event number: 9") endif() -- GitLab