From 7eea9578173451e5081f5d5246ff4bce030269ca Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Thu, 10 Nov 2016 20:47:54 +0100 Subject: [PATCH] Simplify opaque data mappings for conditions --- DDCond/include/DDCond/ConditionsManager.h | 1 - DDCond/include/DDCond/ConditionsTags.h | 9 + DDCond/src/ConditionsIOVPool.cpp | 1 - DDCond/src/ConditionsInterna.cpp | 1 - DDCond/src/ConditionsPool.cpp | 2 +- DDCond/src/plugins/ConditionsExample.cpp | 1 - DDCond/src/plugins/ConditionsLinearPool.cpp | 1 - DDCond/src/plugins/ConditionsMappedPool.cpp | 1 - DDCond/src/plugins/ConditionsMultiLoader.cpp | 2 +- DDCond/src/plugins/ConditionsParser.cpp | 97 ++-- DDCond/src/plugins/ConditionsPlugins.cpp | 45 +- .../plugins/ConditionsRepositoryParser.cpp | 481 ++++++++++++++++++ DDCond/src/plugins/ConditionsUserPool.cpp | 1 - DDCond/src/plugins/ConditionsXmlLoader.cpp | 1 - DDCore/include/DD4hep/AlignmentsKeyAssign.h | 50 ++ DDCore/include/DD4hep/Conditions.h | 6 + DDCore/include/DD4hep/ConditionsKeyAssign.h | 50 ++ .../include/DD4hep/{ROOTUI.h => DD4hepUI.h} | 6 +- DDCore/include/DD4hep/Dictionary.h | 4 +- DDCore/include/DD4hep/OpaqueData.h | 2 + DDCore/include/DD4hep/OpaqueDataBinder.h | 127 +++++ .../DD4hep/objects/ConditionsInterna.h | 61 ++- .../include/DD4hep/objects/OpaqueData_inl.h | 10 + DDCore/include/XML/XMLElements.h | 4 + DDCore/src/AlignmentsKeyAssign.cpp | 38 ++ DDCore/src/Conditions.cpp | 1 - DDCore/src/ConditionsInterna.cpp | 1 - DDCore/src/ConditionsKeyAssign.cpp | 40 ++ DDCore/src/ConditonsTypes.cpp | 1 - DDCore/src/{ROOTUI.cpp => DD4hepUI.cpp} | 28 +- DDCore/src/OpaqueDataBinder.cpp | 277 ++++++++++ DDCore/src/plugins/StandardPlugins.cpp | 36 +- DDDB/src/CondDB2DDDB.cpp | 222 +------- examples/AlignDet/compact/Telescope.xml | 4 +- examples/AlignDet/src/Telescope_geo.cpp | 15 +- .../ClientTests/src/FCC_HcalBarrel_geo.cpp | 64 +-- .../data/Module1_run-1000...2000.xml | 31 +- examples/Conditions/data/default_module.xml | 16 + examples/Conditions/data/repository.xml | 19 +- 39 files changed, 1378 insertions(+), 379 deletions(-) create mode 100644 DDCond/src/plugins/ConditionsRepositoryParser.cpp create mode 100644 DDCore/include/DD4hep/AlignmentsKeyAssign.h create mode 100644 DDCore/include/DD4hep/ConditionsKeyAssign.h rename DDCore/include/DD4hep/{ROOTUI.h => DD4hepUI.h} (95%) create mode 100644 DDCore/include/DD4hep/OpaqueDataBinder.h create mode 100644 DDCore/src/AlignmentsKeyAssign.cpp create mode 100644 DDCore/src/ConditionsKeyAssign.cpp rename DDCore/src/{ROOTUI.cpp => DD4hepUI.cpp} (69%) create mode 100644 DDCore/src/OpaqueDataBinder.cpp create mode 100644 examples/Conditions/data/default_module.xml diff --git a/DDCond/include/DDCond/ConditionsManager.h b/DDCond/include/DDCond/ConditionsManager.h index fae71cddb..87c613fa2 100644 --- a/DDCond/include/DDCond/ConditionsManager.h +++ b/DDCond/include/DDCond/ConditionsManager.h @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCond/include/DDCond/ConditionsTags.h b/DDCond/include/DDCond/ConditionsTags.h index 678d76af6..af15563c6 100644 --- a/DDCond/include/DDCond/ConditionsTags.h +++ b/DDCond/include/DDCond/ConditionsTags.h @@ -37,6 +37,15 @@ namespace DD4hep { UNICODE(validity); UNICODE(open_transaction); UNICODE(close_transaction); + + UNICODE(value); + UNICODE(mapping); + UNICODE(sequence); + UNICODE(alignment); + + UNICODE(iov); + UNICODE(iov_type); + UNICODE(manager); } // User must ensure there are no clashes. If yes, then the clashing entry is unnecessary. using namespace ::DD4hep::XML::Conditions; diff --git a/DDCond/src/ConditionsIOVPool.cpp b/DDCond/src/ConditionsIOVPool.cpp index 8e0cc9e70..99a996dc0 100644 --- a/DDCond/src/ConditionsIOVPool.cpp +++ b/DDCond/src/ConditionsIOVPool.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCond/src/ConditionsInterna.cpp b/DDCond/src/ConditionsInterna.cpp index 192eeff89..8e71dc4bb 100644 --- a/DDCond/src/ConditionsInterna.cpp +++ b/DDCond/src/ConditionsInterna.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCond/src/ConditionsPool.cpp b/DDCond/src/ConditionsPool.cpp index 3a651dc31..18da50512 100644 --- a/DDCond/src/ConditionsPool.cpp +++ b/DDCond/src/ConditionsPool.cpp @@ -40,7 +40,7 @@ ConditionsPool::~ConditionsPool() { /// Print pool basics void ConditionsPool::print(const string& opt) const { - printout(INFO,"Example","+++ %s Conditions for pool with IOV: %-32s age:%3d [%4d entries]", + printout(INFO,"ConditionsPool","+++ %s Conditions for pool with IOV: %-32s age:%3d [%4d entries]", opt.c_str(), iov->str().c_str(), age_value, count()); } diff --git a/DDCond/src/plugins/ConditionsExample.cpp b/DDCond/src/plugins/ConditionsExample.cpp index d429da8c9..1e88edcb6 100644 --- a/DDCond/src/plugins/ConditionsExample.cpp +++ b/DDCond/src/plugins/ConditionsExample.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCond/src/plugins/ConditionsLinearPool.cpp b/DDCond/src/plugins/ConditionsLinearPool.cpp index c32de44ae..e548263d7 100644 --- a/DDCond/src/plugins/ConditionsLinearPool.cpp +++ b/DDCond/src/plugins/ConditionsLinearPool.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCond/src/plugins/ConditionsMappedPool.cpp b/DDCond/src/plugins/ConditionsMappedPool.cpp index 0b9a2ae93..d0d796bc2 100644 --- a/DDCond/src/plugins/ConditionsMappedPool.cpp +++ b/DDCond/src/plugins/ConditionsMappedPool.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCond/src/plugins/ConditionsMultiLoader.cpp b/DDCond/src/plugins/ConditionsMultiLoader.cpp index 303920ecf..9687b5b2e 100644 --- a/DDCond/src/plugins/ConditionsMultiLoader.cpp +++ b/DDCond/src/plugins/ConditionsMultiLoader.cpp @@ -1,3 +1,4 @@ +//========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) @@ -11,7 +12,6 @@ // \version 1.0 // //========================================================================== -// $Id$ #ifndef DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H #define DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H diff --git a/DDCond/src/plugins/ConditionsParser.cpp b/DDCond/src/plugins/ConditionsParser.cpp index 5ac2129b7..25212f766 100644 --- a/DDCond/src/plugins/ConditionsParser.cpp +++ b/DDCond/src/plugins/ConditionsParser.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -24,9 +23,8 @@ #include "DDCond/ConditionsTags.h" #include "DDCond/ConditionsEntry.h" #include "DDCond/ConditionsDataLoader.h" - -// C/C++ include files -#include <stdexcept> +#include "DDCond/ConditionsManager.h" +#include "DDCond/ConditionsInterna.h" /* * DD4hep namespace declaration @@ -35,28 +33,45 @@ namespace DD4hep { namespace { /// Some utility class to specialize the converters: - class iov; class include; class arbitrary; class conditions; + + class iov; + class iov_type; + class manager; + class repository; + class detelement; + class align_conditions; + class align_arbitrary; + /// Conditions types + class value; + class mapping; + class sequence; + class alignment; + class position; + class rotation; + class pivot; } - /// Forward declarations for all specialized converters - template <> void Converter<iov>::operator()(xml_h seq) const; template <> void Converter<include>::operator()(xml_h seq) const; template <> void Converter<arbitrary>::operator()(xml_h seq) const; template <> void Converter<conditions>::operator()(xml_h seq) const; } - + +using std::string; using namespace DD4hep; using namespace DD4hep::Conditions; using Geometry::DetElement; -using std::string; + namespace DD4hep { struct ConversionArg { - DetElement detector; - ConditionsStack* stack; - ConversionArg(DetElement det, ConditionsStack* s) : detector(det), stack(s) {} + DetElement detector; + ConditionsStack* stack; + ConversionArg(DetElement det, ConditionsStack* s) + : detector(det), stack(s) + { + } }; /// Helper: Extract the validity from the xml element @@ -68,13 +83,9 @@ namespace DD4hep { return elt.attr<string>(_U(validity)); } - ConversionArg* _getArgs(void* param) { - ConversionArg* arg = static_cast<ConversionArg*>(param); - return arg; - } /// Helper: Extract the required detector element from the parsing information DetElement _getDetector(void* param, xml_h e) { - ConversionArg* arg = _getArgs(param); + ConversionArg* arg = static_cast<ConversionArg*>(param); DetElement detector = arg ? arg->detector : DetElement(); string subpath = e.hasAttr(_U(path)) ? e.attr<string>(_U(path)) : string(); return subpath.empty() ? detector : Geometry::DetectorTools::findDaughterElement(detector,subpath); @@ -88,17 +99,6 @@ namespace DD4hep { return new Entry(elt,name,e.tag(),_getValidity(element),hash32(name)); } - /** Convert iov repository objects - * - * @author M.Frank - * @version 1.0 - * @date 01/04/2014 - */ - template <> void Converter<iov>::operator()(xml_h element) const { - xml_dim_t e = element; - - } - /** Convert arbitrary conditon objects containing standard tags * @@ -134,31 +134,30 @@ namespace DD4hep { template <> void Converter<arbitrary>::operator()(xml_h e) const { xml_comp_t elt(e); string tag = elt.tag(); - if ( tag == "open_transaction" ) + ConversionArg* arg = _param<ConversionArg>(); + if ( tag == "conditions" ) + Converter<conditions>(lcdd,param,optional)(e); + else if ( arg->stack && tag == "detelement" ) + Converter<conditions>(lcdd,param,optional)(e); + else if ( tag == "open_transaction" ) return; else if ( tag == "close_transaction" ) return; else if ( tag == "include" ) - Converter<include>(lcdd,param)(e); - else if ( tag == "conditions" ) - Converter<conditions>(lcdd,param)(e); - else if ( tag == "detelement" ) - Converter<conditions>(lcdd,param)(e); - else if ( tag == "iov" ) // Processing repository file - xml_coll_t(e,_U(star)).for_each(Converter<iov>(lcdd,param)); - else if ( tag == "subdetectors" ) - xml_coll_t(e,_U(star)).for_each(Converter<conditions>(lcdd,param)); + Converter<include>(lcdd,param,optional)(e); else if ( tag == "detelements" ) - xml_coll_t(e,_U(star)).for_each(Converter<conditions>(lcdd,param)); + xml_coll_t(e,_U(star)).for_each(Converter<conditions>(lcdd,param,optional)); + else if ( tag == "subdetectors" ) + xml_coll_t(e,_U(star)).for_each(Converter<conditions>(lcdd,param,optional)); else if ( tag == "alignment" ) { dd4hep_ptr<Entry> val(_createStackEntry(param,e)); val->value = elt.attr<string>(_U(ref)); - _getArgs(param)->stack->push_back(val.release()); + arg->stack->push_back(val.release()); } else { dd4hep_ptr<Entry> val(_createStackEntry(param,e)); val->value = elt.hasAttr(_U(value)) ? elt.valueStr() : e.text(); - _getArgs(param)->stack->push_back(val.release()); + arg->stack->push_back(val.release()); } } @@ -170,7 +169,7 @@ namespace DD4hep { */ template <> void Converter<include>::operator()(xml_h element) const { XML::DocumentHolder doc(XML::DocumentHandler().load(element, element.attr_value(_U(ref)))); - xml_coll_t(doc.root(),_U(star)).for_each(Converter<arbitrary>(lcdd,param)); + xml_coll_t(doc.root(),_U(star)).for_each(Converter<arbitrary>(lcdd,param,optional)); } /** Convert objects containing standard conditions tags @@ -189,29 +188,29 @@ namespace DD4hep { * @date 01/04/2014 */ template <> void Converter<conditions>::operator()(xml_h e) const { - ConversionArg* arg = _getArgs(param); + ConversionArg* arg = _param<ConversionArg>(); DetElement elt = arg->detector; arg->detector = _getDetector(param,e); - xml_coll_t(e,_U(star)).for_each(Converter<arbitrary>(lcdd,param)); + xml_coll_t(e,_U(star)).for_each(Converter<arbitrary>(lcdd,param,optional)); arg->detector = elt; } } -/** Basic entry point to read conditions files +/** Basic entry point to read global conditions files * * @author M.Frank * @version 1.0 * @date 01/04/2014 */ -static void* setup_Conditions(lcdd_t& lcdd, int argc, char** argv) { +static void* setup_global_Conditions(lcdd_t& lcdd, int argc, char** argv) { if ( argc == 2 ) { xml_h e = xml_h::Elt_t(argv[0]); ConditionsStack* stack = (ConditionsStack*)argv[1]; ConversionArg args(lcdd.world(), stack); - (DD4hep::Converter<DD4hep::conditions>(lcdd,&args))(e); + (DD4hep::Converter<conditions>(lcdd,&args))(e); return &lcdd; } - except("XML_DOC_READER","Invalid number of arguments to interprete conditions."); + except("XML_DOC_READER","Invalid number of arguments to interprete conditions: %d != %d.",argc,2); return 0; } -DECLARE_LCDD_CONSTRUCTOR(XMLConditionsParser,setup_Conditions) +DECLARE_LCDD_CONSTRUCTOR(XMLConditionsParser,setup_global_Conditions) diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index 07d690877..25a7128e9 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -72,8 +72,8 @@ namespace { ConditionsIOVPool* pool = manager.iovPool(*type); if ( pool ) { const _E& e = pool->elements; - printout(INFO,"CondPoolDump","+++ ConditionsIOVPool for type %s [%d IOV elements]", - type->str().c_str(), int(e.size())); + printout(INFO,"CondPoolDump","+++ ConditionsIOVPool for type %s [%d IOV element%s]", + type->str().c_str(), int(e.size()),e.size()==1 ? "" : "s"); for (_E::const_iterator j=e.begin(); j != e.end(); ++j) { ConditionsPool* cp = (*j).second; cp->print(""); @@ -89,9 +89,9 @@ namespace { } } } - printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - printout(INFO,"Example","SUCCESS: +++ Conditions pools successfully dumped"); - printout(INFO,"Example","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + printout(INFO,"CondPoolDump","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + printout(INFO,"CondPoolDump","SUCCESS: +++ Conditions pools successfully dumped"); + printout(INFO,"CondPoolDump","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); return 1; } @@ -106,6 +106,41 @@ namespace { DECLARE_APPLY(DD4hep_ConditionsPoolDump,ddcond_dump_pools) DECLARE_APPLY(DD4hep_ConditionsDump,ddcond_dump_conditions) // ====================================================================================== +#if 0 +namespace { + + int ddcond_assign_keys(LCDD& lcdd, int /* argc */, char** /* argv */) { + typedef std::vector<const IOVType*> _T; + typedef ConditionsIOVPool::Elements _E; + typedef RangeConditions _R; + ConditionsManager manager = ConditionsManager::from(lcdd); + + const _T types = manager.iovTypesUsed(); + for( _T::const_iterator i = types.begin(); i != types.end(); ++i ) { + const IOVType* type = *i; + 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) { + _R rc; + ConditionsPool* cp = (*j).second; + cp->select_all(rc); + for(_R::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) { + Condition cond(*ic); + + } + } + } + } + } + return 1; + } +} + +DECLARE_APPLY(DD4hep_AssignConditionsKeys,ddcond_assign_keys) +#endif +// ====================================================================================== namespace { /// Plugin entry point. diff --git a/DDCond/src/plugins/ConditionsRepositoryParser.cpp b/DDCond/src/plugins/ConditionsRepositoryParser.cpp new file mode 100644 index 000000000..ab2fa8b32 --- /dev/null +++ b/DDCond/src/plugins/ConditionsRepositoryParser.cpp @@ -0,0 +1,481 @@ +//========================================================================== +// 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 include files +#include "DD4hep/LCDD.h" +#include "XML/Conversions.h" +#include "XML/XMLElements.h" +#include "XML/DocumentHandler.h" +#include "DD4hep/Path.h" +#include "DD4hep/Printout.h" +#include "DD4hep/DetectorTools.h" +#include "DD4hep/AlignmentData.h" +#include "DD4hep/OpaqueDataBinder.h" +#include "DD4hep/ConditionsKeyAssign.h" +#include "DD4hep/AlignmentsKeyAssign.h" +#include "DD4hep/DetFactoryHelper.h" + +#include "DDCond/ConditionsTags.h" +#include "DDCond/ConditionsManager.h" +#include "DDCond/ConditionsInterna.h" + +// C/C++ include files +#include <stdexcept> + +/* + * DD4hep namespace declaration + */ +namespace DD4hep { + + namespace { + /// List of XML tags used by this parser + class iov; + class iov_type; + class manager; + class repository; + class detelement; + class align_conditions; + class align_arbitrary; + /// Conditions types + class value; + class mapping; + class sequence; + class alignment; + class position; + class rotation; + class pivot; + } + /// Forward declarations for all specialized converters + template <> void Converter<iov>::operator()(xml_h seq) const; + template <> void Converter<iov_type>::operator()(xml_h seq) const; + template <> void Converter<repository>::operator()(xml_h seq) const; + template <> void Converter<manager>::operator()(xml_h seq) const; + template <> void Converter<rotation>::operator()(xml_h e) const; + template <> void Converter<position>::operator()(xml_h e) const; + template <> void Converter<pivot>::operator()(xml_h e) const; + template <> void Converter<value>::operator()(xml_h e) const; + template <> void Converter<sequence>::operator()(xml_h e) const; + template <> void Converter<mapping>::operator()(xml_h e) const; + template <> void Converter<alignment>::operator()(xml_h e) const; + template <> void Converter<align_conditions>::operator()(xml_h seq) const; + template <> void Converter<align_arbitrary>::operator()(xml_h seq) const; +} + +using std::string; +using namespace DD4hep; +using namespace DD4hep::Conditions; +using Geometry::RotationZYX; +using Geometry::Transform3D; +using Geometry::Translation3D; +using Geometry::Position; +using Geometry::DetElement; + + +namespace { + struct ConversionArg { + DetElement detector; + ConditionsPool* pool; + ConditionsManager manager; + ConversionArg(DetElement det, ConditionsManager m) : detector(det), pool(0), manager(m) + { + } + }; + struct CurrentDetector { + DetElement detector; + ConversionArg* arg; + CurrentDetector(ConversionArg* a) : arg(a) { + detector = arg->detector; + } + ~CurrentDetector() { + arg->detector = detector; + } + void set(const string& path) { + if ( !path.empty() ) { + arg->detector = Geometry::DetectorTools::findDaughterElement(detector,path); + } + } + }; + struct CurrentPool { + ConditionsPool* pool; + ConversionArg* arg; + CurrentPool(ConversionArg* a) : arg(a) { + pool = arg->pool; + } + ~CurrentPool() { + arg->pool = pool; + } + void set(ConditionsPool* p) { + arg->pool = p; + } + }; + + Condition create_condition(DetElement det, xml_h e) { + xml_dim_t elt(e); + string tag = elt.tag(); + string typ = elt.hasAttr(_U(type)) ? elt.typeStr() : tag; + string nam = elt.hasAttr(_U(name)) ? elt.nameStr() : tag; + string add = XML::DocumentHandler::system_path(e); + Condition cond(det.path()+"/"+nam, typ); + + printout(INFO,"XMLConditions","++ Processing condition tag:%s name:%s type:%s [%s]", + tag.c_str(), nam.c_str(), typ.c_str(), + Path(add).filename().c_str()); + cond->address = add; + cond->value = ""; + cond->validity = ""; + cond->hash = Conditions::ConditionKey::hashCode(cond->name); + cond->setFlag(Condition::ACTIVE); + if ( elt.hasAttr(_U(comment)) ) { + cond->comment = elt.attr<string>(_U(comment)); + } + ConditionsKeyAssign(det) + .addKey(cond.name()) + .addKey(nam,cond.name()); + return cond; + } + template <typename BINDER> Condition bind_condition(const BINDER& bnd, + DetElement det, + xml_h e, + const std::string& type="") + { + xml_dim_t elt(e); + string typ = type.empty() ? elt.typeStr() : type; + string val = elt.hasAttr(_U(value)) ? elt.valueStr() : elt.text(); + Condition con = create_condition(det, e); + OpaqueDataBinder::bind(bnd, con, typ, val); + return con; + } +} + +namespace DD4hep { + /** Convert iov_type repository objects + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<iov_type>::operator()(xml_h element) const { + xml_dim_t e = element; + size_t id = e.id(); + string nam = e.nameStr(); + ConversionArg* arg = _param<ConversionArg>(); + printout(INFO,"XMLConditions","++ Registering IOV type: [%d]: %s",id,nam.c_str()); + const IOVType* iov_type = arg->manager.registerIOVType(id,nam).second; + if ( !iov_type ) { + except("XMLConditions","Failed to register iov type: [%d]: %s",id,nam.c_str()); + } + } + + /// Convert iov repository objects + /** + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<iov>::operator()(xml_h element) const { + xml_dim_t e = element; + string ref = e.attr<string>(_U(ref)); + string val = e.attr<string>(_U(validity)); + ConversionArg* arg = _param<ConversionArg>(); + CurrentPool pool(arg); + printout(INFO,"XMLConditions","++ Reading IOV file: %s -> %s", val.c_str(), ref.c_str()); + pool.set(arg->manager->registerIOV(val)); + XML::DocumentHolder doc(XML::DocumentHandler().load(element, element.attr_value(_U(ref)))); + Converter<align_conditions>(lcdd,param,optional)(doc.root()); + } + + /// Convert manager repository objects + /** + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<manager>::operator()(xml_h element) const { + ConversionArg* arg = _param<ConversionArg>(); + for( xml_coll_t c(element,_Unicode(property)); c; ++c) { + xml_dim_t d = c; + string nam = d.nameStr(); + string val = d.valueStr(); + try { + printout(INFO,"XMLConditions","++ Setup conditions Manager[%s] = %s",nam.c_str(),val.c_str()); + arg->manager[nam] = val; + } + catch(const std::exception& e) { + printout(ERROR,"XMLConditions","++ FAILED: conditions Manager[%s] = %s [%s]",nam.c_str(),val.c_str(),e.what()); + } + } + arg->manager.initialize(); + printout(INFO,"XMLConditions","++ Conditions Manager successfully initialized."); + } + + /// Convert rotation objects + /** + * + * <rotation x="0.5" y="0" z="0"/> + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<rotation>::operator()(xml_h e) const { + xml_comp_t r(e); + RotationZYX* v = (RotationZYX*)param; + v->SetComponents(r.z(), r.y(), r.x()); + printout(INFO,"XMLConditions", + "++ Rotation: x=%9.3f y=%9.3f z=%9.3f phi=%7.4f psi=%7.4f theta=%7.4f", + r.x(), r.y(), r.z(), v->Phi(), v->Psi(), v->Theta()); + } + + /// Convert position objects + /** + * + * <position x="0.5" y="0" z="0"/> + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<position>::operator()(xml_h e) const { + xml_comp_t p(e); + Position* v = (Position*)param; + v->SetXYZ(p.x(), p.y(), p.z()); + printout(INFO,"XMLConditions","++ Position: x=%9.3f y=%9.3f z=%9.3f", + v->X(), v->Y(), v->Z()); + } + + /// Convert pivot objects + /** + * + * <pivot x="0.5" y="0" z="0"/> + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<pivot>::operator()(xml_h e) const { + xml_comp_t p(e); + double x,y,z; + Translation3D* v = (Translation3D*)param; + v->SetXYZ(x=p.x(), y=p.y(), z=p.z()); + printout(INFO,"XMLConditions","++ Pivot: x=%9.3f y=%9.3f z=%9.3f",x,y,z); + } + + /// Convert conditions value objects (scalars) + /** + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<value>::operator()(xml_h e) const { + ConversionArg* arg = _param<ConversionArg>(); + Condition con = bind_condition(ValueBinder(), arg->detector, e); + arg->manager.registerUnlocked(arg->pool, con); + } + + /// Convert conditions sequence objects (unmapped containers) + /** + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<sequence>::operator()(xml_h e) const { + xml_dim_t elt(e); + Condition con(0); + string typ = elt.typeStr(); + ConversionArg* arg = _param<ConversionArg>(); + size_t idx = typ.find('['); + size_t idq = typ.find(']'); + string value_type = typ.substr(idx+1,idq-idx-1); + if ( typ.substr(0,6) == "vector" ) + con = bind_condition(VectorBinder(), arg->detector, e, value_type); + else if ( typ.substr(0,4) == "list" ) + con = bind_condition(ListBinder(), arg->detector, e, value_type); + else if ( typ.substr(0,3) == "set" ) + con = bind_condition(SetBinder(), arg->detector, e, value_type); + else + except("XMLConditions", + "++ Failed to convert unknown sequence conditions type: %s",typ.c_str()); + arg->manager.registerUnlocked(arg->pool, con); + } + + /// Convert conditions STL maps + /** + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<mapping>::operator()(xml_h e) const { + xml_comp_t elt(e); + ConversionArg* arg = _param<ConversionArg>(); + string typ = elt.typeStr(); + Condition con = create_condition(arg->detector, e); + string val = elt.hasAttr(_U(value)) ? elt.valueStr() : elt.text(); + OpaqueDataBinder::bind(VectorBinder(), con, typ, val); + arg->manager.registerUnlocked(arg->pool, con); + } + + /** Convert alignment delta objects + * + * A generic alignment transformation is defined by + * - a translation in 3D space identified in XML as a + * <position/> element + * - a rotation in 3D space around a pivot point specified in XML by + * 2 elements: the <rotation/> and the <pivot/> element. + * The specification of any of the elements is optional: + * - The absence of a translation implies the origine (0,0,0) + * - The absence of a pivot point implies the origine (0,0,0) + * - The absence of a rotation implies the identity rotation. + * Any supplied pivot point in this case is ignored. + * + * <xx> + * <position x="0" y="0" z="0.0001*mm"/> + * <rotation x="0" y="0" z="0"/> + * <pivot x="0" y="0" z="100"/> + * </xx> + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<alignment>::operator()(xml_h e) const { + using Alignments::Delta; + Position pos; + RotationZYX rot; + Translation3D piv; + xml_h child_rot, child_pos, child_piv; + ConversionArg* arg = _param<ConversionArg>(); + Condition con = create_condition(arg->detector, e); + Delta& del = con.bind<Delta>(); + + if ( (child_pos=e.child(_U(position),false)) ) + Converter<position>(lcdd,&del.translation)(child_pos); + if ( (child_rot=e.child(_U(rotation),false)) ) { + Converter<rotation>(lcdd,&del.rotation)(child_rot); + if ( (child_piv=e.child(_U(pivot),false)) ) + Converter<pivot>(lcdd,&del.pivot)(child_piv); + } + if ( child_rot && child_pos && child_piv ) + del.flags |= Delta::HAVE_ROTATION|Delta::HAVE_PIVOT|Delta::HAVE_TRANSLATION; + else if ( child_rot && child_pos ) + del.flags |= Delta::HAVE_ROTATION|Delta::HAVE_TRANSLATION; + else if ( child_rot && child_piv ) + del.flags |= Delta::HAVE_ROTATION|Delta::HAVE_PIVOT; + else if ( child_rot ) + del.flags |= Delta::HAVE_ROTATION; + else if ( child_pos ) + del.flags |= Delta::HAVE_TRANSLATION; + + Alignments::AlignmentsKeyAssign(arg->detector) + .addKey(con.name()+"/Transformation") + .addKey(con.type(),con.name()+"/Transformation"); + + arg->manager.registerUnlocked(arg->pool, con); + } + + /** Convert detelement objects + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<detelement>::operator()(xml_h e) const { + xml_comp_t elt(e); + ConversionArg* arg = _param<ConversionArg>(); + CurrentDetector detector(arg); + if ( elt.hasAttr(_U(path)) ) { + detector.set(e.attr<string>(_U(path))); + printout(INFO,"XMLConditions","++ Processing condition for:%s", + arg->detector.path().c_str()); + } + if ( elt.hasAttr(_U(ref)) ) { + XML::DocumentHolder doc(XML::DocumentHandler().load(e, e.attr_value(_U(ref)))); + (*this)(doc.root()); + } + xml_coll_t(e,_UC(value)).for_each(Converter<value>(lcdd,param,optional)); + xml_coll_t(e,_UC(mapping)).for_each(Converter<mapping>(lcdd,param,optional)); + xml_coll_t(e,_UC(sequence)).for_each(Converter<sequence>(lcdd,param,optional)); + xml_coll_t(e,_UC(alignment)).for_each(Converter<alignment>(lcdd,param,optional)); + } + + /** Convert repository objects + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<repository>::operator()(xml_h element) const { + xml_coll_t(element,_UC(manager)).for_each(Converter<manager>(lcdd,param,optional)); + xml_coll_t(element,_UC(iov_type)).for_each(Converter<iov_type>(lcdd,param,optional)); + xml_coll_t(element,_UC(iov)).for_each(Converter<iov>(lcdd,param,optional)); + } + + /** Convert any top level tag in the XML file + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ + template <> void Converter<align_arbitrary>::operator()(xml_h e) const { + xml_comp_t elt(e); + string tag = elt.tag(); + if ( tag == "repository" ) + Converter<repository>(lcdd,param,optional)(e); + else if ( tag == "manager" ) + Converter<manager>(lcdd,param,optional)(e); + else if ( tag == "detelement" ) + Converter<detelement>(lcdd,param,optional)(e); + else if ( tag == "iov" ) // Processing repository file + Converter<iov>(lcdd,param,optional)(e); + else + except("XMLConditions", + "++ Failed to handle unknown tag: %s",tag.c_str()); + } + + /// Convert alignment conditions entries + template <> void Converter<align_conditions>::operator()(xml_h e) const { + xml_coll_t(e,_U(star)).for_each(Converter<align_arbitrary>(lcdd,param,optional)); + } +} +#include "DD4hep/DD4hepUI.h" + +/** Basic entry point to read alignment conditions files + * + +geoPluginRun -compact file:checkout/examples/AlignDet/compact/Telescope.xml -volmgr -destroy \ + -plugin DD4hepDetectorDump \ + -plugin DD4hepVolumeDump volids \ + -plugin DD4hepVolumeMgrTest all \ + -plugin DD4hep_XMLAlignmentConditionsParser file:checkout/examples/Conditions/data/repository.xml \ + -plugin DD4hep_ConditionsPoolDump + + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ +static long setup_alignment_Conditions(lcdd_t& lcdd, int argc, char** argv) { + if ( argc == 1 ) { + //xml_h e = xml_h::Elt_t(argv[0]); + DD4hepUI ui(lcdd); + string fname = argv[0]; + ConditionsManager mgr = ui.conditionsMgr(); + ConversionArg args(lcdd.world(), mgr); + XML::DocumentHolder doc(XML::DocumentHandler().load(fname)); + (DD4hep::Converter<align_conditions>(lcdd,&args))(doc.root()); + return 1; + } + except("XML_DOC_READER","Invalid number of arguments to interprete conditions: %d != %d.",argc,1); + return 0; +} +DECLARE_APPLY(DD4hep_XMLAlignmentConditionsParser,setup_alignment_Conditions) diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp index 98a565279..9f6c5c7db 100644 --- a/DDCond/src/plugins/ConditionsUserPool.cpp +++ b/DDCond/src/plugins/ConditionsUserPool.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCond/src/plugins/ConditionsXmlLoader.cpp b/DDCond/src/plugins/ConditionsXmlLoader.cpp index e56a33147..ba35d23bc 100644 --- a/DDCond/src/plugins/ConditionsXmlLoader.cpp +++ b/DDCond/src/plugins/ConditionsXmlLoader.cpp @@ -11,7 +11,6 @@ // \version 1.0 // //========================================================================== -// $Id$ #ifndef DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H #define DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H diff --git a/DDCore/include/DD4hep/AlignmentsKeyAssign.h b/DDCore/include/DD4hep/AlignmentsKeyAssign.h new file mode 100644 index 000000000..1a8b3465d --- /dev/null +++ b/DDCore/include/DD4hep/AlignmentsKeyAssign.h @@ -0,0 +1,50 @@ +//========================================================================== +// 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_ALIGNMENTS_ALIGNMENTSKEYASSIGN_H +#define DD4HEP_ALIGNMENTS_ALIGNMENTSKEYASSIGN_H + +// Framework include files +#include "DD4hep/Detector.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the alignments part of the AIDA detector description toolkit + namespace Alignments { + + /// Helper class to assign alignments keys based on patterms + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_ALIGNMENTS + */ + class AlignmentsKeyAssign { + public: + Geometry::DetElement detector; + + /// Default constructor + AlignmentsKeyAssign(Geometry::DetElement det) : detector(det) {} + /// Copy constructor + AlignmentsKeyAssign(const AlignmentsKeyAssign& c) = default; + /// Assignment operator + AlignmentsKeyAssign& operator=(const AlignmentsKeyAssign& c) = default; + + /// Add a new key to the alignments access map + const AlignmentsKeyAssign& addKey(const std::string& key_value) const; + /// Add a new key to the alignments access map: Allow for alias if key_val != data_val + const AlignmentsKeyAssign& addKey(const std::string& key_value, const std::string& data_value) const; + }; + } /* End namespace Alignments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_ALIGNMENTS_ALIGNMENTSKEYASSIGN_H */ diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h index 8b40f75bd..97c1d385f 100644 --- a/DDCore/include/DD4hep/Conditions.h +++ b/DDCore/include/DD4hep/Conditions.h @@ -170,6 +170,12 @@ namespace DD4hep { * Any further rebindings MUST match the identical type. */ template <typename T> T& bind(); + /** Set and bind the data of the conditions object to a given format. + * + * Note: The type definition is possible exactly once. + * Any further rebindings MUST match the identical type. + */ + template <typename T> T& bind(const std::string& val); /// Generic getter. Specify the exact type, not a polymorph type template <typename T> T& get(); /// Generic getter (const version). Specify the exact type, not a polymorph type diff --git a/DDCore/include/DD4hep/ConditionsKeyAssign.h b/DDCore/include/DD4hep/ConditionsKeyAssign.h new file mode 100644 index 000000000..d82893d26 --- /dev/null +++ b/DDCore/include/DD4hep/ConditionsKeyAssign.h @@ -0,0 +1,50 @@ +//========================================================================== +// 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_CONDITIONS_CONDITIONSKEYASSIGN_H +#define DD4HEP_CONDITIONS_CONDITIONSKEYASSIGN_H + +// Framework include files +#include "DD4hep/Detector.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the conditions part of the AIDA detector description toolkit + namespace Conditions { + + /// Helper class to assign conditions keys based on patterms + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionsKeyAssign { + public: + Geometry::DetElement detector; + + /// Default constructor + ConditionsKeyAssign(Geometry::DetElement det) : detector(det) {} + /// Copy constructor + ConditionsKeyAssign(const ConditionsKeyAssign& c) = default; + /// Assignment operator + ConditionsKeyAssign& operator=(const ConditionsKeyAssign& c) = default; + + /// Add a new key to the conditions access map + const ConditionsKeyAssign& addKey(const std::string& key_value) const; + /// Add a new key to the conditions access map: Allow for alias if key_val != data_val + const ConditionsKeyAssign& addKey(const std::string& key_value, const std::string& data_value) const; + }; + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_CONDITIONS_CONDITIONSKEYASSIGN_H */ diff --git a/DDCore/include/DD4hep/ROOTUI.h b/DDCore/include/DD4hep/DD4hepUI.h similarity index 95% rename from DDCore/include/DD4hep/ROOTUI.h rename to DDCore/include/DD4hep/DD4hepUI.h index d91282a8a..d4f3850f3 100644 --- a/DDCore/include/DD4hep/ROOTUI.h +++ b/DDCore/include/DD4hep/DD4hepUI.h @@ -26,7 +26,7 @@ namespace DD4hep { * \version 1.0 * \ingroup DD4HEP */ - class ROOTUI { + class DD4hepUI { protected: /// Reference to the LCDD instance object Geometry::LCDD& m_lcdd; @@ -35,9 +35,9 @@ namespace DD4hep { public: /// Default constructor - ROOTUI(Geometry::LCDD& instance); + DD4hepUI(Geometry::LCDD& instance); /// Default destructor - virtual ~ROOTUI(); + virtual ~DD4hepUI(); /// Access to the LCDD instance Geometry::LCDD* instance() const; diff --git a/DDCore/include/DD4hep/Dictionary.h b/DDCore/include/DD4hep/Dictionary.h index c64c8b91c..82258f7f4 100644 --- a/DDCore/include/DD4hep/Dictionary.h +++ b/DDCore/include/DD4hep/Dictionary.h @@ -35,7 +35,7 @@ #include "DD4hep/objects/VolumeManagerInterna.h" #include "DD4hep/World.h" -#include "DD4hep/ROOTUI.h" +#include "DD4hep/DD4hepUI.h" #include "DD4hep/Callback.h" #include "DD4hep/LCDDData.h" #include "DD4hep/Conditions.h" @@ -97,7 +97,7 @@ template class pair<DD4hep::Callback,unsigned long>; #pragma link C++ class map<string, DD4hep::Handle<DD4hep::NamedObject> >+; #pragma link C++ class map<string, DD4hep::Handle<DD4hep::NamedObject> >::iterator; #pragma link C++ class map<string, DD4hep::Handle<DD4hep::NamedObject> >::const_iterator; -#pragma link C++ class DD4hep::ROOTUI; +#pragma link C++ class DD4hep::DD4hepUI; #ifdef R__MACOSX // We only need these declarations for the clang compiler diff --git a/DDCore/include/DD4hep/OpaqueData.h b/DDCore/include/DD4hep/OpaqueData.h index 3c8ca5798..741f8c318 100644 --- a/DDCore/include/DD4hep/OpaqueData.h +++ b/DDCore/include/DD4hep/OpaqueData.h @@ -112,6 +112,8 @@ namespace DD4hep { void (*dtor)(void*)); /// Bind data value template <typename T> T& bind(); + /// Bind data value [Equivalent to set(value)] + template <typename T> T& bind(const std::string& value); /// Set data value void assign(const void* ptr,const std::type_info& typ); /// Bind grammar and assign value diff --git a/DDCore/include/DD4hep/OpaqueDataBinder.h b/DDCore/include/DD4hep/OpaqueDataBinder.h new file mode 100644 index 000000000..dc5b02b77 --- /dev/null +++ b/DDCore/include/DD4hep/OpaqueDataBinder.h @@ -0,0 +1,127 @@ +//========================================================================== +// 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_OPAQUEDATABINDER_H +#define DD4HEP_OPAQUEDATABINDER_H + +// Framework include files +#include "DD4hep/Printout.h" + +// C/C++ include files +#include <string> + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Helper class to bind string values to C++ data objects (primitive or complex) + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + */ + struct ValueBinder { + template <typename T, typename Q> bool bind(T& object, const std::string& val, const Q*) const; + }; + + /// Helper class to bind string values to a STL vector of data objects (primitive or complex) + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + */ + struct VectorBinder { + template <typename T, typename Q> bool bind(T& object, const std::string& val, const Q*) const; + }; + + /// Helper class to bind string values to a STL list of data objects (primitive or complex) + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + */ + struct ListBinder { + template <typename T, typename Q> bool bind(T& object, const std::string& val, const Q*) const; + }; + + /// Helper class to bind string values to a STL set of data objects (primitive or complex) + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + */ + struct SetBinder { + template <typename T, typename Q> bool bind(T& object, const std::string& val, const Q*) const; + }; + + /// Helper class to bind STL map objects + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + */ + struct MapBinder { + template <typename T, typename Q> bool bind(T& object, const Q*) const; + }; + + /// Helper class to bind string values to C++ data items + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + */ + class OpaqueDataBinder { + protected: + static const char* _char() { return 0; } + static const unsigned char* _uchar() { return 0; } + static const short* _short() { return 0; } + static const unsigned short* _ushort() { return 0; } + static const int* _int() { return 0; } + static const unsigned int* _uint() { return 0; } + static const long* _long() { return 0; } + static const unsigned long* _ulong() { return 0; } + static const float* _float() { return 0; } + static const double* _double() { return 0; } + static const std::string* _string() { return 0; } + + public: + /// Default constructor + OpaqueDataBinder() = default; + /// Default destructor + ~OpaqueDataBinder() = default; + + /// Binding function for scalar items. See the implementation function for the concrete instantiations + template <typename BINDER, typename T> static + bool bind(const BINDER& b, T& object, const std::string& typ, const std::string& val); + + /// Binding function for sequences (unmapped STL containers) + template <typename T> static + bool bind_sequence(T& object, const std::string& typ, const std::string& val); + + /// Binding function for STL maps. Does not fill data! + template <typename T> static + bool bind_map(T& object, const std::string& key_type, const std::string& val_type); + + /// Filling function for STL maps. + template <typename T> static + bool insert_map(T& object, + const std::string& key_type, const std::string& key, + const std::string& val_type, const std::string& val); + + }; +} /* End namespace DD4hep */ +#endif /* DD4HEP_OPAQUEDATABINDER_H */ diff --git a/DDCore/include/DD4hep/objects/ConditionsInterna.h b/DDCore/include/DD4hep/objects/ConditionsInterna.h index 628d37b40..c164ff326 100644 --- a/DDCore/include/DD4hep/objects/ConditionsInterna.h +++ b/DDCore/include/DD4hep/objects/ConditionsInterna.h @@ -195,6 +195,11 @@ namespace DD4hep { Object* o = access(); return o->data.set<T>(o->value); } + /// Bind the data of the conditions object to a given format. + template <typename T> T& Condition::bind(const std::string& val) { + Object* o = access(); + return o->data.set<T>(o->value=val); + } /// Generic getter. Specify the exact type, not a polymorph type template <typename T> T& Condition::get() { return access()->data.get<T>(); @@ -207,47 +212,49 @@ namespace DD4hep { } /* End namespace Conditions */ } /* End namespace DD4hep */ -#define DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - namespace DD4hep { namespace Conditions { \ - template x& Condition::bind<x>(); \ - template x& Condition::get<x>(); \ - template const x& Condition::get<x>() const; \ +#define DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ + namespace DD4hep { namespace Conditions { \ + template x& Condition::bind<x>(const std::string& val); \ + template x& Condition::bind<x>(); \ + template x& Condition::get<x>(); \ + template const x& Condition::get<x>() const; \ }} -#define DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(x) \ +#define DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(x) \ namespace DD4hep{namespace Parsers{int parse(x&, const std::string&){return 1;}}} \ DD4HEP_DEFINE_CONDITIONS_TYPE(x) -#define DD4HEP_DEFINE_EXTERNAL_CONDITIONS_TYPE(x) \ - namespace DD4hep { namespace Conditions { \ - template <> x& Condition::bind<x>(); \ - template <> x& Condition::get<x>(); \ - template <> const x& Condition::get<x>() const; \ +#define DD4HEP_DEFINE_EXTERNAL_CONDITIONS_TYPE(x) \ + namespace DD4hep { namespace Conditions { \ + template <> x& Condition::bind<x>(const std::string& val); \ + template <> x& Condition::bind<x>(); \ + template <> x& Condition::get<x>(); \ + template <> const x& Condition::get<x>() const; \ }} #if defined(DD4HEP_HAVE_ALL_PARSERS) -#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::deque<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::int_map_t) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::ulong_map_t) \ +#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::deque<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::int_map_t) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::ulong_map_t) \ DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::string_map_t) -#define DD4HEP_DEFINE_CONDITIONS_U_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_CONT(x) \ +#define DD4HEP_DEFINE_CONDITIONS_U_CONT(x) \ + DD4HEP_DEFINE_CONDITIONS_CONT(x) \ DD4HEP_DEFINE_CONDITIONS_CONT(unsigned x) #else -#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::int_map_t) \ +#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::int_map_t) \ DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::string_map_t) #define DD4HEP_DEFINE_CONDITIONS_U_CONT(x) DD4HEP_DEFINE_CONDITIONS_CONT(x) diff --git a/DDCore/include/DD4hep/objects/OpaqueData_inl.h b/DDCore/include/DD4hep/objects/OpaqueData_inl.h index 2c76a4aec..376d37cb0 100644 --- a/DDCore/include/DD4hep/objects/OpaqueData_inl.h +++ b/DDCore/include/DD4hep/objects/OpaqueData_inl.h @@ -22,6 +22,7 @@ #define DD4HEP_OPAQUEDATA_INL_H // Framework include files +#include "DD4hep/Primitives.h" #include "DD4hep/OpaqueData.h" #include "DD4hep/BasicGrammar.h" @@ -53,6 +54,15 @@ namespace DD4hep { return *(new(this->pointer) T()); } /// Bind grammar and assign value + template <typename T> T& OpaqueDataBlock::bind(const std::string& value) { + T& ret = this->bind<T>(); + if ( !value.empty() && !this->fromString(value) ) { + throw std::runtime_error("OpaqueDataBlock::set> Failed to bind type "+ + typeName(typeid(T))+" to condition data block."); + } + return ret; + } + /// Bind grammar and assign value template <typename T> T& OpaqueDataBlock::set(const std::string& value) { T& ret = this->bind<T>(); if ( !value.empty() && !this->fromString(value) ) { diff --git a/DDCore/include/XML/XMLElements.h b/DDCore/include/XML/XMLElements.h index 7f0c546e0..7c8c967c3 100644 --- a/DDCore/include/XML/XMLElements.h +++ b/DDCore/include/XML/XMLElements.h @@ -744,6 +744,10 @@ namespace DD4hep { const XmlChar* tagName() const { return m_element.rawTag(); } + /// Access the tag name of this DOM element + std::string text() const { + return m_element.text(); + } /// Append a new element to the existing tree void append(Handle_t handle) const { m_element.append(handle); diff --git a/DDCore/src/AlignmentsKeyAssign.cpp b/DDCore/src/AlignmentsKeyAssign.cpp new file mode 100644 index 000000000..08bd059f5 --- /dev/null +++ b/DDCore/src/AlignmentsKeyAssign.cpp @@ -0,0 +1,38 @@ +//========================================================================== +// 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/AlignmentsKeyAssign.h" +#include "DD4hep/objects/AlignmentsInterna.h" +#include "DD4hep/DetAlign.h" + +using std::string; +using namespace DD4hep::Alignments; + +/// Add a new key to the conditions access map +const AlignmentsKeyAssign& +AlignmentsKeyAssign::addKey(const string& key_value) const { + DetAlign conds(detector); + conds.alignments()->addKey(key_value); + return *this; +} + +/// Add a new key to the conditions access map: Allow for alias if key_val != data_val +const AlignmentsKeyAssign& +AlignmentsKeyAssign::addKey(const string& key_value, const string& data_value) const { + DetAlign conds(detector); + conds.alignments()->addKey(key_value, data_value); + return *this; +} + + diff --git a/DDCore/src/Conditions.cpp b/DDCore/src/Conditions.cpp index 4916db716..e16486183 100644 --- a/DDCore/src/Conditions.cpp +++ b/DDCore/src/Conditions.cpp @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/ConditionsInterna.cpp b/DDCore/src/ConditionsInterna.cpp index 3e551ba69..19d7626f2 100644 --- a/DDCore/src/ConditionsInterna.cpp +++ b/DDCore/src/ConditionsInterna.cpp @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/ConditionsKeyAssign.cpp b/DDCore/src/ConditionsKeyAssign.cpp new file mode 100644 index 000000000..799c8add5 --- /dev/null +++ b/DDCore/src/ConditionsKeyAssign.cpp @@ -0,0 +1,40 @@ +//========================================================================== +// 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/ConditionsKeyAssign.h" +#include "DD4hep/objects/ConditionsInterna.h" +#include "DD4hep/DetConditions.h" + +using std::string; +using namespace DD4hep::Conditions; + +/// Add a new key to the conditions access map +const ConditionsKeyAssign& +ConditionsKeyAssign::addKey(const string& key_value) const +{ + DetConditions conds(detector); + conds.conditions()->addKey(key_value); + return *this; +} + +/// Add a new key to the conditions access map: Allow for alias if key_val != data_val +const ConditionsKeyAssign& +ConditionsKeyAssign::addKey(const string& key_value, const string& data_value) const +{ + DetConditions conds(detector); + conds.conditions()->addKey(key_value, data_value); + return *this; +} + + diff --git a/DDCore/src/ConditonsTypes.cpp b/DDCore/src/ConditonsTypes.cpp index 1c15bff1c..49cd23a63 100644 --- a/DDCore/src/ConditonsTypes.cpp +++ b/DDCore/src/ConditonsTypes.cpp @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDCore/src/ROOTUI.cpp b/DDCore/src/DD4hepUI.cpp similarity index 69% rename from DDCore/src/ROOTUI.cpp rename to DDCore/src/DD4hepUI.cpp index f6dde3269..5f7a2972a 100644 --- a/DDCore/src/ROOTUI.cpp +++ b/DDCore/src/DD4hepUI.cpp @@ -12,7 +12,7 @@ //========================================================================== // Framework includes -#include "DD4hep/ROOTUI.h" +#include "DD4hep/DD4hepUI.h" #include "DD4hep/Printout.h" using namespace std; @@ -20,34 +20,34 @@ using namespace DD4hep; using namespace DD4hep::Geometry; /// Default constructor -ROOTUI::ROOTUI(LCDD& instance) : m_lcdd(instance) { +DD4hepUI::DD4hepUI(LCDD& instance) : m_lcdd(instance) { } /// Default destructor -ROOTUI::~ROOTUI() { +DD4hepUI::~DD4hepUI() { } /// Access to the LCDD instance -LCDD* ROOTUI::instance() const { +LCDD* DD4hepUI::instance() const { return &m_lcdd; } /// Install the DD4hep conditions manager object -Handle<NamedObject> ROOTUI::conditionsMgr() const { +Handle<NamedObject> DD4hepUI::conditionsMgr() const { if ( !m_condMgr.isValid() ) { const void* argv[] = {"-handle",&m_condMgr,0}; if ( 1 != apply("DD4hep_ConditionsManagerInstaller",2,(char**)argv) ) { - except("ROOTUI","Failed to install the conditions manager object."); + except("DD4hepUI","Failed to install the conditions manager object."); } if ( !m_condMgr.isValid() ) { - except("ROOTUI","Failed to access the conditions manager object."); + except("DD4hepUI","Failed to access the conditions manager object."); } } return m_condMgr; } /// Load conditions from file -long ROOTUI::loadConditions(const std::string& fname) const { +long DD4hepUI::loadConditions(const std::string& fname) const { Handle<NamedObject> h = conditionsMgr(); if ( h.isValid() ) { m_lcdd.fromXML(fname, BUILD_DEFAULT); @@ -57,30 +57,30 @@ long ROOTUI::loadConditions(const std::string& fname) const { } /// Install the DD4hep alignment manager object -Handle<NamedObject> ROOTUI::alignmentMgr() const { +Handle<NamedObject> DD4hepUI::alignmentMgr() const { if ( !m_alignMgr.isValid() ) { const void* argv[] = {"-handle",&m_alignMgr,0}; if ( 1 != apply("DD4hep_AlignmentsManagerInstaller",2,(char**)argv) ) { - except("ROOTUI","Failed to install the alignment manager object."); + except("DD4hepUI","Failed to install the alignment manager object."); } if ( !m_alignMgr.isValid() ) { - except("ROOTUI","Failed to access the alignment manager object."); + except("DD4hepUI","Failed to access the alignment manager object."); } } return m_alignMgr; } /// LCDD interface: Manipulate geometry using facroy converter -long ROOTUI::apply(const char* factory, int argc, char** argv) const { +long DD4hepUI::apply(const char* factory, int argc, char** argv) const { return m_lcdd.apply(factory,argc,argv); } /// LCDD interface: Read any geometry description or alignment file -void ROOTUI::fromXML(const std::string& fname, LCDDBuildType type) const { +void DD4hepUI::fromXML(const std::string& fname, LCDDBuildType type) const { return m_lcdd.fromXML(fname, type); } /// LCDD interface: Re-draw the entire scene -void ROOTUI::redraw() const { +void DD4hepUI::redraw() const { m_lcdd.worldVolume()->Draw("oglsame"); } diff --git a/DDCore/src/OpaqueDataBinder.cpp b/DDCore/src/OpaqueDataBinder.cpp new file mode 100644 index 000000000..4371bb4d3 --- /dev/null +++ b/DDCore/src/OpaqueDataBinder.cpp @@ -0,0 +1,277 @@ +//========================================================================== +// 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 include files +#include "DD4hep/OpaqueDataBinder.h" +#include "DD4hep/objects/OpaqueData_inl.h" +#include "DD4hep/objects/ConditionsInterna.h" +#include "DD4hep/Conditions.h" + +// C/C++ include files +#include <set> +#include <map> +#include <list> +#include <vector> + +using namespace std; + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Helper class to bind string values to C++ data objects (primitive or complex) + template <typename T, typename Q> bool ValueBinder::bind(T& object, const string& val, const Q*) const + { object.bind<Q>(val); return true; } + + /// Helper class to bind string values to a STL vector of data objects (primitive or complex) + template <typename T, typename Q> bool VectorBinder::bind(T& object, const string& val, const Q*) const + { object.bind<vector<Q> >(val); return true; } + + /// Helper class to bind string values to a STL list of data objects (primitive or complex) + template <typename T, typename Q> bool ListBinder::bind(T& object, const string& val, const Q*) const + { object.bind<list<Q> >(val); return true; } + + /// Helper class to bind string values to a STL set of data objects (primitive or complex) + template <typename T, typename Q> bool SetBinder::bind(T& object, const string& val, const Q*) const + { object.bind<set<Q> >(val); return true; } + + /// Helper class to bind STL map objects + template <typename T, typename Q> bool MapBinder::bind(T& object, const Q*) const + { object.bind<set<Q> >(); return true; } + + /// Binding function for scalar items. See the implementation function for the concrete instantiations + template <typename BINDER, typename T> + bool OpaqueDataBinder::bind(const BINDER& b, T& object, const string& typ, const string& val) { +#if defined(DD4HEP_HAVE_ALL_PARSERS) + if ( typ.substr(0,4) == "char" ) + return b.bind(object,val,_char()); + else if ( typ.substr(0,13) == "unsigned char" ) + return b.bind(object,val,_uchar()); + else if ( typ.substr(0,5) == "short" ) + return b.bind(object,val,_short()); + else if ( typ.substr(0,14) == "unsigned short" ) + return b.bind(object,val,_ushort()); + else if ( typ.substr(0,12) == "unsigned int" ) + return b.bind(object,val,_uint()); + else if ( typ.substr(0,13) == "unsigned long" ) + return b.bind(object,val,_ulong()); +#else + // Short and char is not part of the standard dictionaries. Fall back to 'int'. + if ( typ.substr(0,4) == "char" ) + return b.bind(object,val,_int()); + else if ( typ.substr(0,5) == "short" ) + return b.bind(object,val,_int()); +#endif + else if ( typ.substr(0,3) == "int" ) + return b.bind(object,val,_int()); + else if ( typ.substr(0,4) == "long" ) + return b.bind(object,val,_long()); + else if ( typ.substr(0,5) == "float" ) + return b.bind(object,val,_float()); + else if ( typ.substr(0,6) == "double" ) + return b.bind(object,val,_double()); + else if ( typ.substr(0,6) == "string" ) + return b.bind(object,val,_string()); + else if ( typ == "std::string" ) + return b.bind(object,val,_string()); + else if ( typ == "Histo1D" ) + return b.bind(object,val,_string()); + else if ( typ == "Histo2D" ) + return b.bind(object,val,_string()); + else + printout(INFO,"Param","++ Unknown conditions parameter type:%s val:%s",typ.c_str(),val.c_str()); + return b.bind(object,val,_string()); + } + + /// Binding function for sequences (unmapped STL containers) + template <typename T> + bool OpaqueDataBinder::bind_sequence(T& object, const string& typ, const string& val) + { + size_t idx = typ.find('['); + size_t idq = typ.find(']'); + string value_type = typ.substr(idx+1,idq-idx-1); + if ( typ.substr(0,6) == "vector" ) + return bind(VectorBinder(), object, value_type, val); + else if ( typ.substr(0,6) == "list" ) + return bind(ListBinder(), object, value_type, val); + //else if ( typ.substr(0,6) == "set" ) + // return bind(SetBinder(), object, value_type, val); + else if ( idx == string::npos && idq == string::npos ) + return bind(ValueBinder(), object, value_type, val); + return false; + } + + + template<typename KEY, typename VAL, typename OBJECT> + static void insert_map_item(const KEY& k, const string& val, OBJECT& block) { + typedef map<KEY,VAL> map_t; + map_t& m = block.get<map_t>(); + VAL v; + if ( !BasicGrammar::instance<VAL>().fromString(&v, val) ) { + except("Condition::map","++ Failed to convert conditions map entry."); + } + m.insert(make_pair(k,v)); + } + + template<typename KEY, typename OBJECT> + static void insert_map_key(const string& key_val, + const string& val_type, + const string& val, + OBJECT& block) + { + KEY key; + BasicGrammar::instance<KEY>().fromString(&key, key_val); + // Short and char is not part of the standard dictionaries. Fall back to 'int'. + if ( val_type.substr(0,4) == "char" ) + insert_map_item<KEY,int>(key,val,block); + else if ( val_type.substr(0,5) == "short" ) + insert_map_item<KEY,int>(key,val,block); + else if ( val_type.substr(0,3) == "int" ) + insert_map_item<KEY,int>(key,val,block); + else if ( val_type.substr(0,4) == "long" ) + insert_map_item<KEY,long>(key,val,block); + else if ( val_type.substr(0,5) == "float" ) + insert_map_item<KEY,float>(key,val,block); + else if ( val_type.substr(0,6) == "double" ) + insert_map_item<KEY,double>(key,val,block); + else if ( val_type.substr(0,6) == "string" ) + insert_map_item<KEY,string>(key,val,block); + else if ( val_type == "std::string" ) + insert_map_item<KEY,string>(key,val,block); + else { + printout(INFO,"Param","++ Unknown conditions parameter type:%s data:%s", + val_type.c_str(),val.c_str()); + insert_map_item<KEY,string>(key,val,block); + } + } + + template<typename BINDER, typename OBJECT, typename KEY> + static void bind_mapping(const BINDER& b, const string& val_type, OBJECT& object, const KEY*) { + if ( val_type.substr(0,3) == "int" ) + b.bind(object, (map<KEY,int>*)0); +#if defined(DD4HEP_HAVE_ALL_PARSERS) + else if ( val_type.substr(0,12) == "unsigned int" ) + b.bind(object, (map<KEY,unsigned int>*)0); + else if ( val_type.substr(0,4) == "char" ) + b.bind(object, (map<KEY,char>*)0); + else if ( val_type.substr(0,13) == "unsigned char" ) + b.bind(object, (map<KEY,unsigned char>*)0); + else if ( val_type.substr(0,5) == "short" ) + b.bind(object, (map<KEY,short>*)0); + else if ( val_type.substr(0,14) == "unsigned short" ) + b.bind(object, (map<KEY,unsigned short>*)0); + else if ( val_type.substr(0,13) == "unsigned long" ) + b.bind(object, (map<KEY,unsigned long>*)0); +#else + // Short and char is not part of the standard dictionaries. Fall back to 'int'. + else if ( val_type.substr(0,4) == "char" ) + b.bind(object, (map<KEY,int>*)0); + else if ( val_type.substr(0,5) == "short" ) + b.bind(object, (map<KEY,int>*)0); +#endif + else if ( val_type.substr(0,4) == "long" ) + b.bind(object, (map<KEY,long>*)0); + else if ( val_type.substr(0,5) == "float" ) + b.bind(object, (map<KEY,float>*)0); + else if ( val_type.substr(0,6) == "double" ) + b.bind(object, (map<KEY,double>*)0); + else if ( val_type.substr(0,6) == "string" ) + b.bind(object, (map<KEY,string>*)0); + else if ( val_type == "std::string" ) + b.bind(object, (map<KEY,string>*)0); + else { + b.bind(object, (map<KEY,string>*)0); + } + } + + /// Binding function for STL maps + template <typename T> + bool OpaqueDataBinder::bind_map(T& object, const string& key_type, const string& val_type) { + // Short and char is not part of the standard dictionaries. Fall back to 'int'. + if ( key_type.substr(0,3) == "int" ) + bind_mapping(MapBinder(),val_type,object,_int()); +#if defined(DD4HEP_HAVE_ALL_PARSERS) + else if ( key_type.substr(0,4) == "char" ) + bind_mapping(MapBinder(),val_type,object,_int()); + else if ( key_type.substr(0,5) == "short" ) + bind_mapping(MapBinder(),val_type,object,_int()); + else if ( key_type.substr(0,4) == "long" ) + bind_mapping(MapBinder(),val_type,object,_long()); + else if ( key_type.substr(0,5) == "float" ) + bind_mapping(MapBinder(),val_type,object,_float()); + else if ( key_type.substr(0,6) == "double" ) + bind_mapping(MapBinder(),val_type,object,_double()); +#endif + else if ( key_type.substr(0,6) == "string" ) + bind_mapping(MapBinder(),val_type,object,_string()); + else if ( key_type == "std::string" ) + bind_mapping(MapBinder(),val_type,object,_string()); + else { + printout(INFO,"Param","++ Unknown MAP-conditions key-type:%s",key_type.c_str()); + bind_mapping(MapBinder(),val_type,object,_string()); + } + return true; + } + + /// Filling function for STL maps. + template <typename T> + bool OpaqueDataBinder::insert_map(T& object, const string& key_type, const string& key, const string& val_type, const string& val) { + if ( key_type.substr(0,3) == "int" ) + insert_map_key<int>(key,val_type,val,object); +#if defined(DD4HEP_HAVE_ALL_PARSERS) + // Short and char is not part of the standard dictionaries. Fall back to 'int'. + else if ( key_type.substr(0,4) == "char" ) + insert_map_key<int>(key,val_type,val,object); + else if ( key_type.substr(0,5) == "short" ) + insert_map_key<int>(key,val_type,val,object); + else if ( key_type.substr(0,4) == "long" ) + insert_map_key<long>(key,val_type,val,object); + else if ( key_type.substr(0,5) == "float" ) + insert_map_key<float>(key,val_type,val,object); + else if ( key_type.substr(0,6) == "double" ) + insert_map_key<double>(key,val_type,val,object); +#endif + else if ( key_type.substr(0,6) == "string" ) + insert_map_key<string>(key,val_type,val,object); + else if ( key_type == "std::string" ) + insert_map_key<string>(key,val_type,val,object); + else { + printout(INFO,"Param","++ Unknown MAP-conditions key-type:%s",key_type.c_str()); + insert_map_key<string>(key,val_type,val,object); + } + return true; + } + + /// Binding function for STL maps + template <> + bool OpaqueDataBinder::bind_map(Conditions::Condition& object, const string& key_type, const string& val_type) { + return bind_map(object->data, key_type, val_type); + } + /// Filling function for STL maps. + template <> + bool OpaqueDataBinder::insert_map(Conditions::Condition& object, + const string& key_type, const string& key, + const string& val_type, const string& val) { + return insert_map(object->data, key_type, key, val_type, val); + } + + /// Instantiate the data binder for OpaqueData + template bool + OpaqueDataBinder::bind_sequence<OpaqueDataBlock>(OpaqueDataBlock& object,const string& typ,const string& val); + template bool + OpaqueDataBinder::bind_map<OpaqueDataBlock>(OpaqueDataBlock& object,const string& typ,const string& val); + template bool + OpaqueDataBinder::insert_map<OpaqueDataBlock>(OpaqueDataBlock& object, + const string& key_type, const string& key, + const string& val_type, const string& val); + +} diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp index d58f0a646..ca4543622 100644 --- a/DDCore/src/plugins/StandardPlugins.cpp +++ b/DDCore/src/plugins/StandardPlugins.cpp @@ -13,7 +13,7 @@ // Framework include files #include "DD4hep/LCDD.h" -#include "DD4hep/ROOTUI.h" +#include "DD4hep/DD4hepUI.h" #include "DD4hep/Factories.h" #include "DD4hep/Printout.h" #include "DD4hep/DetectorTools.h" @@ -83,15 +83,15 @@ DECLARE_APPLY(DD4hepGeometryDisplay,display) static long root_ui(LCDD& lcdd, int /* argc */, char** /* argv */) { char cmd[256]; - ROOTUI* ui = new ROOTUI(lcdd); - ::snprintf(cmd,sizeof(cmd),"DD4hep::ROOTUI* gDD4hepUI = (DD4hep::ROOTUI*)%p;",(void*)ui); + DD4hepUI* ui = new DD4hepUI(lcdd); + ::snprintf(cmd,sizeof(cmd),"DD4hep::DD4hepUI* gDD4hepUI = (DD4hep::DD4hepUI*)%p;",(void*)ui); gInterpreter->ProcessLine(cmd); - printout(ALWAYS,"ROOTUI", + printout(ALWAYS,"DD4hepUI", "Use the ROOT interpreter variable gDD4hepUI " "to interact with the detector description."); return 1; } -DECLARE_APPLY(DD4hepROOTUI,root_ui) +DECLARE_APPLY(DD4hepInteractiveUI,root_ui) static long load_compact(LCDD& lcdd, int argc, char** argv) { if ( argc > 0 ) { @@ -244,11 +244,6 @@ static long dump_volume_tree(LCDD& lcdd, int argc, char** argv) { bool sensitive = false; if ( m_printPositions || m_printVolIDs ) { stringstream log; - if ( m_printPositions ) { - const double* trans = ideal->GetMatrix()->GetTranslation(); - ::snprintf(fmt, sizeof(fmt), "Pos: (%f,%f,%f) ",trans[0],trans[1],trans[2]); - log << fmt; - } // Top level volume! have no volume ids if ( m_printVolIDs && ideal && ideal->GetMotherVolume() ) { VIDs vid = pv.volIDs(); @@ -260,24 +255,39 @@ static long dump_volume_tree(LCDD& lcdd, int argc, char** argv) { ::snprintf(fmt, sizeof(fmt), "%s:%2d ",(*i).first.c_str(), (*i).second); log << fmt; } + if ( !vid.empty() || pv.volume().isSensitive() ) { + SensitiveDetector sd = pv.volume().sensitiveDetector(); + if ( sd.isValid() ) { + IDDescriptor dsc = sd.readout().idSpec(); + if ( dsc.isValid() ) { + log << hex << " (0x" << setfill('0') << setw(8) + << dsc.encode(volids) + << setfill(' ') << dec << ") "; + } + } + } } } + if ( m_printPositions ) { + const double* trans = ideal->GetMatrix()->GetTranslation(); + ::snprintf(fmt, sizeof(fmt), "Pos: (%f,%f,%f) ",trans[0],trans[1],trans[2]); + log << fmt; + } opt_info = log.str(); } TGeoVolume* volume = ideal->GetVolume(); if ( !m_printSensitivesOnly || (m_printSensitivesOnly && sensitive) ) { char sens = pv.volume().isSensitive() ? 'S' : ' '; if ( ideal == aligned ) { - ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%s (%%s: %%s) \t[%p] %c %%s", + ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%-16s (%%s) \t[%p] %c %%s", level+1,2*level+1,(void*)ideal, sens); } else { - ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%s (%%s: %%s) Ideal:%p Aligned:%p %c %%s", + ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%-16s (%%s) Ideal:%p Aligned:%p %c %%s", level+1,2*level+1,(void*)ideal,(void*)aligned, sens); } printout(INFO,"VolumeDump",fmt,"", aligned->GetName(), - volume->GetTitle(), volume->GetShape()->IsA()->GetName(), opt_info.c_str()); } diff --git a/DDDB/src/CondDB2DDDB.cpp b/DDDB/src/CondDB2DDDB.cpp index 8c5cf60e3..8d0f2e6a6 100644 --- a/DDDB/src/CondDB2DDDB.cpp +++ b/DDDB/src/CondDB2DDDB.cpp @@ -21,6 +21,7 @@ // Framework includes #include "DD4hep/Path.h" #include "DD4hep/Alignments.h" +#include "DD4hep/OpaqueDataBinder.h" #include "DDDB/DDDBTags.h" #include "DDDB/DDDBDimension.h" #include "DDDB/DDDBHelper.h" @@ -458,145 +459,6 @@ namespace DD4hep { } } - template<typename KEY, typename VAL> - static void insert_map_item(const KEY& k, const string& val, OpaqueDataBlock& block) { - typedef std::map<KEY,VAL> map_t; - map_t& m = block.get<map_t>(); - VAL v; - if ( !BasicGrammar::instance<VAL>().fromString(&v, val) ) { - except("Condition::map","++ Failed to convert conditions map entry."); - } - m.insert(make_pair(k,v)); - } - - template<typename KEY> - static void insert_map_key(const string& key_val, const string& val_type, - const string& val, OpaqueDataBlock& block) - { - KEY key; - BasicGrammar::instance<KEY>().fromString(&key, key_val); - // Short and char is not part of the standard dictionaries. Fall back to 'int'. - if ( val_type.substr(0,4) == "char" ) - insert_map_item<KEY,int>(key,val,block); - else if ( val_type.substr(0,5) == "short" ) - insert_map_item<KEY,int>(key,val,block); - else if ( val_type.substr(0,3) == "int" ) - insert_map_item<KEY,int>(key,val,block); - else if ( val_type.substr(0,4) == "long" ) - insert_map_item<KEY,long>(key,val,block); - else if ( val_type.substr(0,5) == "float" ) - insert_map_item<KEY,float>(key,val,block); - else if ( val_type.substr(0,6) == "double" ) - insert_map_item<KEY,double>(key,val,block); - else if ( val_type.substr(0,6) == "string" ) - insert_map_item<KEY,string>(key,val,block); - else if ( val_type == "std::string" ) - insert_map_item<KEY,string>(key,val,block); - else { - printout(INFO,"Param","++ Unknown conditions parameter type:%s data:%s", - val_type.c_str(),val.c_str()); - insert_map_item<KEY,string>(key,val,block); - } - } - - template<typename KEY> - static void bind_map(const string& val_type, OpaqueDataBlock& block) { - if ( val_type.substr(0,3) == "int" ) - block.bind< map<KEY,int> >(); -#if defined(DD4HEP_HAVE_ALL_PARSERS) - else if ( val_type.substr(0,12) == "unsigned int" ) - block.bind< map<KEY,unsigned int> >(); - else if ( val_type.substr(0,4) == "char" ) - block.bind< map<KEY,char> >(); - else if ( val_type.substr(0,13) == "unsigned char" ) - block.bind< map<KEY,unsigned char> >(); - else if ( val_type.substr(0,5) == "short" ) - block.bind< map<KEY,short> >(); - else if ( val_type.substr(0,14) == "unsigned short" ) - block.bind< map<KEY,unsigned short> >(); - else if ( val_type.substr(0,13) == "unsigned long" ) - block.bind< map<KEY,unsigned long> >(); -#else - // Short and char is not part of the standard dictionaries. Fall back to 'int'. - else if ( val_type.substr(0,4) == "char" ) - block.bind< map<KEY,int> >(); - else if ( val_type.substr(0,5) == "short" ) - block.bind< map<KEY,int> >(); -#endif - else if ( val_type.substr(0,4) == "long" ) - block.bind< map<KEY,long> >(); - else if ( val_type.substr(0,5) == "float" ) - block.bind< map<KEY,float> >(); - else if ( val_type.substr(0,6) == "double" ) - block.bind< map<KEY,double> >(); - else if ( val_type.substr(0,6) == "string" ) - block.bind< map<KEY,string> >(); - else if ( val_type == "std::string" ) - block.bind< map<KEY,string> >(); - else { - block.bind< map<KEY,string> >(); - } - } - - static void extractMap(xml_h element, OpaqueDataBlock& block) { - dddb_dim_t e = element; - string n = e.nameStr(); - string key_type = e.attr<string>(_LBU(keytype)); - string val_type = e.attr<string>(_LBU(valuetype)); - - // Short and char is not part of the standard dictionaries. Fall back to 'int'. - if ( key_type.substr(0,3) == "int" ) - bind_map<int>(val_type,block); -#if defined(DD4HEP_HAVE_ALL_PARSERS) - else if ( key_type.substr(0,4) == "char" ) - bind_map<int>(val_type,block); - else if ( key_type.substr(0,5) == "short" ) - bind_map<int>(val_type,block); - else if ( key_type.substr(0,4) == "long" ) - bind_map<long>(val_type,block); - else if ( key_type.substr(0,5) == "float" ) - bind_map<float>(val_type,block); - else if ( key_type.substr(0,6) == "double" ) - bind_map<double>(val_type,block); -#endif - else if ( key_type.substr(0,6) == "string" ) - bind_map<string>(val_type,block); - else if ( key_type == "std::string" ) - bind_map<string>(val_type,block); - else { - printout(INFO,"Param","++ Unknown MAP-conditions key-type:%s",key_type.c_str()); - bind_map<string>(val_type,block); - } - - for(xml_coll_t i(e,_LBU(item)); i; ++i) { - string key = i.attr<string>(_LBU(key)); - string val = i.attr<string>(_LBU(value)); - if ( key_type.substr(0,3) == "int" ) - insert_map_key<int>(key,val_type,val,block); -#if defined(DD4HEP_HAVE_ALL_PARSERS) - // Short and char is not part of the standard dictionaries. Fall back to 'int'. - else if ( key_type.substr(0,4) == "char" ) - insert_map_key<int>(key,val_type,val,block); - else if ( key_type.substr(0,5) == "short" ) - insert_map_key<int>(key,val_type,val,block); - else if ( key_type.substr(0,4) == "long" ) - insert_map_key<long>(key,val_type,val,block); - else if ( key_type.substr(0,5) == "float" ) - insert_map_key<float>(key,val_type,val,block); - else if ( key_type.substr(0,6) == "double" ) - insert_map_key<double>(key,val_type,val,block); -#endif - else if ( key_type.substr(0,6) == "string" ) - insert_map_key<string>(key,val_type,val,block); - else if ( key_type == "std::string" ) - insert_map_key<string>(key,val_type,val,block); - else { - printout(INFO,"Param","++ Unknown MAP-conditions key-type:%s",key_type.c_str()); - insert_map_key<string>(key,val_type,val,block); - } - } - } - /// Specialized conversion of <param/> and <paramVector> entities template <> void Conv<ConditionParam>::convert(xml_h element) const { string nam = element.attr<string>(_U(name)); @@ -605,46 +467,7 @@ namespace DD4hep { pair<string,OpaqueDataBlock> block; block.first = nam; -#if defined(DD4HEP_HAVE_ALL_PARSERS) - if ( typ.substr(0,4) == "char" ) - block.second.set<char>(data); - else if ( typ.substr(0,13) == "unsigned char" ) - block.second.set<unsigned char>(data); - else if ( typ.substr(0,5) == "short" ) - block.second.set<short>(data); - else if ( typ.substr(0,14) == "unsigned short" ) - block.second.set<unsigned short>(data); - else if ( typ.substr(0,12) == "unsigned int" ) - block.second.set<unsigned int>(data); - else if ( typ.substr(0,13) == "unsigned long" ) - block.second.set<unsigned long>(data); -#else - // Short and char is not part of the standard dictionaries. Fall back to 'int'. - if ( typ.substr(0,4) == "char" ) - block.second.set<int>(data); - else if ( typ.substr(0,5) == "short" ) - block.second.set<int>(data); -#endif - else if ( typ.substr(0,3) == "int" ) - block.second.set<int>(data); - else if ( typ.substr(0,4) == "long" ) - block.second.set<long>(data); - else if ( typ.substr(0,5) == "float" ) - block.second.set<float>(data); - else if ( typ.substr(0,6) == "double" ) - block.second.set<double>(data); - else if ( typ.substr(0,6) == "string" ) - block.second.set<string>(data); - else if ( typ == "std::string" ) - block.second.set<string>(data); - else if ( typ == "Histo1D" ) - block.second.set<string>(data); - else if ( typ == "Histo2D" ) - block.second.set<string>(data); - else { - printout(INFO,"Param","++ Unknown conditions parameter type:%s data:%s",typ.c_str(),data.c_str()); - block.second.set<string>(data); - } + OpaqueDataBinder::bind(VectorBinder(), block.second, typ, data); ConditionParams* par = _option<ConditionParams>(); pair<ConditionParams::iterator,bool> res = par->insert(block); if ( !res.second ) { @@ -679,34 +502,7 @@ namespace DD4hep { break; } d[d.length()-1] = ']'; - if ( typ.substr(0,3) == "int" ) - block.second.set<vector<int> >(d); -#if defined(DD4HEP_HAVE_ALL_PARSERS) - else if ( typ.substr(0,4) == "char" ) - block.second.set<vector<char> >(d); - else if ( typ.substr(0,5) == "short" ) - block.second.set<vector<short> >(d); -#else - // Short and char is not part of the standard dictionaries. Fall back to 'int'. - else if ( typ.substr(0,4) == "char" ) - block.second.set<vector<int> >(d); - else if ( typ.substr(0,5) == "short" ) - block.second.set<vector<int> >(d); -#endif - else if ( typ.substr(0,4) == "long" ) - block.second.set<vector<long> >(d); - else if ( typ.substr(0,5) == "float" ) - block.second.set<vector<float> >(d); - else if ( typ.substr(0,6) == "double" ) - block.second.set<vector<double> >(d); - else if ( typ.substr(0,6) == "string" ) - block.second.set<vector<string> >(d); - else if ( typ == "std::string" ) - block.second.set<vector<string> >(d); - else { - printout(INFO,"ParamVector","++ Unknown conditions parameter type:%s",typ.c_str()); - block.second.set<vector<string> >(d); - } + OpaqueDataBinder::bind(VectorBinder(), block.second, typ, d); ConditionParams* par = _option<ConditionParams>(); pair<ConditionParams::iterator,bool> res = par->insert(block); if ( !res.second ) { @@ -716,11 +512,19 @@ namespace DD4hep { /// Specialized conversion of <map/> conditions entities template <> void Conv<ConditionParamMap>::convert(xml_h element) const { + dddb_dim_t e = element; string nam = element.attr<string>(_U(name)); + string key_type = e.attr<string>(_LBU(keytype)); + string val_type = e.attr<string>(_LBU(valuetype)); pair<string,OpaqueDataBlock> block; - block.first = nam; - extractMap(element,block.second); + block.first = nam; + OpaqueDataBinder::bind_map(block.second, key_type, val_type); + for(xml_coll_t i(e,_LBU(item)); i; ++i) { + string key = i.attr<string>(_LBU(key)); + string val = i.attr<string>(_LBU(value)); + OpaqueDataBinder::insert_map(block.second, key_type, key, val_type, val); + } ConditionParams* par = _option<ConditionParams>(); pair<ConditionParams::iterator,bool> res = par->insert(block); if ( !res.second ) diff --git a/examples/AlignDet/compact/Telescope.xml b/examples/AlignDet/compact/Telescope.xml index be92ad0ed..f9940f03a 100644 --- a/examples/AlignDet/compact/Telescope.xml +++ b/examples/AlignDet/compact/Telescope.xml @@ -42,7 +42,7 @@ <detectors> <comment>No comment so far</comment> - <detector name="Telescope" type="DD4hep_Example_Telescope" vis="DetVis" id ="1" readout="TelescopeHits"> + <detector name="Telescope" type="DD4hep_Example_Telescope" vis="DetVis" id ="3" readout="TelescopeHits"> <!-- Front arm --> <module z="0.0*cm" id="1" vis="ModVis"> <sensor thickness="3*mm" pitch="55*micron" NoOfPixY="256" NoOfPixX="256" vis="SensorVis"/> @@ -105,7 +105,7 @@ <readouts> <readout name="TelescopeHits"> <segmentation type="CartesianGridXY" grid_size_x="55*micron" grid_size_y="55*micron" /> - <id>system:6,sensor:10,x:16,y:16</id> + <id>system:8,module:10,sensor:10,x:16,y:16</id> </readout> </readouts> diff --git a/examples/AlignDet/src/Telescope_geo.cpp b/examples/AlignDet/src/Telescope_geo.cpp index 514674ba2..e9094a09a 100644 --- a/examples/AlignDet/src/Telescope_geo.cpp +++ b/examples/AlignDet/src/Telescope_geo.cpp @@ -39,7 +39,8 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sd) { int noPixY = sens.attr<int>(_Unicode(NoOfPixY)); double pitch = sens.attr<double>(_Unicode(pitch)); double mod_thick = sens.thickness()+chip.thickness()+pcb.thickness(); - + DetElement mod_det(det,_toString(mod.id(),"module_%d"),x_det.id()); + // Make envelope box for each module a bit bigger to ensure all children are within bounds... box = Box(pitch*noPixX/2e0+small, pitch*noPixY/2e0+small, mod_thick/2e0+small); Volume modvol(_toString(mod.id(),"module_%d"), box, air); @@ -50,19 +51,23 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sd) { vol.setSensitiveDetector(sd); vol.setVisAttributes(lcdd.visAttributes(sens.visStr())); phv = modvol.placeVolume(vol, Position(0, 0, -mod_thick/2e0+sens.thickness()/2e0)); - phv.addPhysVolID("sensor",mod.id()); + phv.addPhysVolID("sensor",1); box = Box(pitch*noPixX/2e0, pitch*noPixY/2e0, chip.thickness()/2e0); vol = Volume(_toString(mod.id(),"chip_%d"), box, air); vol.setVisAttributes(lcdd.visAttributes(chip.visStr())); - modvol.placeVolume(vol, Position(0, 0, -mod_thick/2e0+sens.thickness()+chip.thickness()/2e0)); + phv = modvol.placeVolume(vol, Position(0, 0, -mod_thick/2e0+sens.thickness()+chip.thickness()/2e0)); + phv.addPhysVolID("sensor",2); box = Box(pitch*noPixX/2e0, pitch*noPixY/2e0, pcb.thickness()/2e0); vol = Volume(_toString(mod.id(),"PCB_%d"), box, air); vol.setVisAttributes(lcdd.visAttributes(pcb.visStr())); - modvol.placeVolume(vol, Position(0, 0, -mod_thick/2e0+sens.thickness()+chip.thickness()+pcb.thickness()/2e0)); + phv = modvol.placeVolume(vol, Position(0, 0, -mod_thick/2e0+sens.thickness()+chip.thickness()+pcb.thickness()/2e0)); + phv.addPhysVolID("sensor",3); - envVol.placeVolume(modvol,Position(0e0, 0e0, mod.z())); + phv = envVol.placeVolume(modvol,Position(0e0, 0e0, mod.z())); + phv.addPhysVolID("module",mod.id()); + mod_det.setPlacement(phv); } envVol.setVisAttributes(lcdd.visAttributes(x_det.visStr())); phv = lcdd.pickMotherVolume(det).placeVolume(envVol,Position(0,0,0)); diff --git a/examples/ClientTests/src/FCC_HcalBarrel_geo.cpp b/examples/ClientTests/src/FCC_HcalBarrel_geo.cpp index 571d2cc97..a3f44add1 100644 --- a/examples/ClientTests/src/FCC_HcalBarrel_geo.cpp +++ b/examples/ClientTests/src/FCC_HcalBarrel_geo.cpp @@ -74,14 +74,14 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { float z = x_det_layer.dr(); if(debug){ - cout << " r:" << r - << " dr:" << dr - << " x1:" << x1 - << " x2:" << x2 - << " y1:" << y1 - << " y2:" << y2 - << " z:" << z - << endl; + cout << " r:" << r + << " dr:" << dr + << " x1:" << x1 + << " x2:" << x2 + << " y1:" << y1 + << " y2:" << y2 + << " z:" << z + << endl; } //Shape a Trapezoid (tile): DDCore/DD4hep/Shapes.h @@ -105,38 +105,38 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { tile_seq.setVisAttributes(lcdd.visAttributes("VisibleGreen")); for(xml_coll_t k(x_det_layer,_U(slice)); k; ++k, ++slice_num) { - xml_comp_t tile_xml = k; - string tile_name = layer_name + _toString(tile_number,"_slice%d"); - Material tile_material = lcdd.material(tile_xml.materialStr()); - float tile_thickness = tile_xml.dz(); - float tile_y1 = tile_thickness; - float tile_y2 = tile_thickness; - float tile_z = x_det_layer.dr(); + xml_comp_t tile_xml = k; + string tile_name = layer_name + _toString(tile_number,"_slice%d"); + Material tile_material = lcdd.material(tile_xml.materialStr()); + float tile_thickness = tile_xml.dz(); + float tile_y1 = tile_thickness; + float tile_y2 = tile_thickness; + float tile_z = x_det_layer.dr(); - Trapezoid tile_shape(x1,x2,tile_y1,tile_y2,tile_z); - Volume tile_vol(tile_name,tile_shape,tile_material); - pv = tile_seq.placeVolume(tile_vol,Position(0,total_thickness,0)); - pv.addPhysVolID("slice",slice_num); - total_thickness += tile_thickness; - if ( tile_xml.isSensitive() ) { - cout << "Set volume " << tile_name << " sensitive...." << endl; - tile_vol.setSensitiveDetector(sens); - } + Trapezoid tile_shape(x1,x2,tile_y1,tile_y2,tile_z); + Volume tile_vol(tile_name,tile_shape,tile_material); + pv = tile_seq.placeVolume(tile_vol,Position(0,total_thickness,0)); + pv.addPhysVolID("slice",slice_num); + total_thickness += tile_thickness; + if ( tile_xml.isSensitive() ) { + cout << "Set volume " << tile_name << " sensitive...." << endl; + tile_vol.setSensitiveDetector(sens); + } - // Set region, limitset, and visibility settings - tile_vol.setAttributes(lcdd,tile_xml.regionStr(),tile_xml.limitsStr(),tile_xml.visStr()); - tiles.push_back(tile_vol); - tile_number++; + // Set region, limitset, and visibility settings + tile_vol.setAttributes(lcdd,tile_xml.regionStr(),tile_xml.limitsStr(),tile_xml.visStr()); + tiles.push_back(tile_vol); + tile_number++; } // Place the same volumes inside the envelope float tile_pos_z = -x_det_dim.z()/2.; int tile_num = 0; while(tile_pos_z<x_det_dim.z()/2.){ - pv = layer_vol.placeVolume(tile_seq,Position(0,tile_pos_z,0)); - pv.addPhysVolID("tile",tile_num); - tile_pos_z += total_thickness; - tile_num++; + pv = layer_vol.placeVolume(tile_seq,Position(0,tile_pos_z,0)); + pv.addPhysVolID("tile",tile_num); + tile_pos_z += total_thickness; + tile_num++; } // Place the same layer around the beam axis phiBins times diff --git a/examples/Conditions/data/Module1_run-1000...2000.xml b/examples/Conditions/data/Module1_run-1000...2000.xml index 84c7786fb..e6628b25d 100644 --- a/examples/Conditions/data/Module1_run-1000...2000.xml +++ b/examples/Conditions/data/Module1_run-1000...2000.xml @@ -1,8 +1,33 @@ <?xml version="1.0" encoding="ISO-8859-1"?> -<!--- $Id: --> <!--- Author : Markus Frank --> -<!--- Created : 2016-11-07 --> - +<!--- Created : 2016-11-07 --> <conditions> + <detelement path="/world/Telescope/module_1" ref="default_module.xml"> + <alignment> + <position x="0" y="0" z="290.0*mm"/> + <rotation x="0" y="pi/2" z="0"/> + </alignment> + </detelement> + + <detelement path="/world/Telescope/module_2" ref="default_module.xml"> + <alignment> + <position x="0" y="0" z="290.0*mm"/> + <rotation x="0" y="pi/2" z="0"/> + </alignment> + </detelement> + + <detelement path="/world/Telescope/module_3" ref="default_module.xml"> + <alignment> + <position x="0" y="0" z="290.0*mm"/> + <rotation x="0" y="pi/2" z="0"/> + </alignment> + </detelement> + + <detelement path="/world/Telescope/module_4" ref="default_module.xml"> + </detelement> + + <detelement path="/world/Telescope/module_5" ref="default_module.xml"> + </detelement> + </conditions> diff --git a/examples/Conditions/data/default_module.xml b/examples/Conditions/data/default_module.xml new file mode 100644 index 000000000..986f94e60 --- /dev/null +++ b/examples/Conditions/data/default_module.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!--- Author : Markus Frank --> +<!--- Created : 2016-11-07 --> +<conditions> + + <value name="external_pressure" type="float" value="980*hPa"/> + <value name="other_pressure" type="double">980*hPa</value> + + <sequence name="Seq1" type="vector[int]" value="[0,1,2,3,4,5]"/> + <sequence name="Seq2" type="list[int]">[0,1,2,3,4,5]</sequence> +<!-- + <mapping> name="Map1" key_type="string" mapped_type="int"> + ("a": 1, "b": 2 ) + </mapping> +--> +</conditions> diff --git a/examples/Conditions/data/repository.xml b/examples/Conditions/data/repository.xml index de1a4cfbd..f914194b2 100644 --- a/examples/Conditions/data/repository.xml +++ b/examples/Conditions/data/repository.xml @@ -3,8 +3,23 @@ <!--- Created : 2016-11-07 --> <conditions> - <iov type="run" start="1000" end="2000" ref="module1_run-1000...2000.xml"/> + + <repository> + <manager> + <property name="PoolType" value="DD4hep_ConditionsLinearPool"/> + <property name="LoaderType" value="xml"/> + <property name="UserPoolType" value="DD4hep_ConditionsMapUserPool"/> + <property name="UpdatePoolType" value="DD4hep_ConditionsLinearUpdatePool"/> + </manager> + <iov_type name="epoch" id="0"/> + <iov_type name="run" id="1"/> + <iov_type name="fill" id="2"/> + </repository> + + <repository> + <iov validity="1000,2000#run" ref="Module1_run-1000...2000.xml"/> <!-- - <iov type="run" start="1000" end="2000" ref="module2_run-1000...2000.xml"/> + <iov type="run" start="1000" end="2000" ref="module2_run-1000...2000.xml"/> --> + </repository> </conditions> -- GitLab