diff --git a/DDCore/include/DD4hep/Objects.h b/DDCore/include/DD4hep/Objects.h index 6e23aa159e3abd207ff14b05ac35182fbe9d9daf..563b3acaa37ee9f3bd1d8cc8e52f6ffca10ffbdf 100644 --- a/DDCore/include/DD4hep/Objects.h +++ b/DDCore/include/DD4hep/Objects.h @@ -84,6 +84,11 @@ namespace DD4hep { } /// Constructor to be used when creating a new DOM tree Author(LCDD& doc); + /// Assignment operator + Author& operator=(const Author& e) { + m_element = e.m_element; + return *this; + } /// Access the auhor's name std::string authorName() const; /// Set the author's name diff --git a/DDCore/include/DD4hep/VolumeManager.h b/DDCore/include/DD4hep/VolumeManager.h index bddf6ea912064a59edcfe7ca829087e21de9f0fd..f1424b5bedaa7144fa8f8b09b0280be5b402e1dd 100644 --- a/DDCore/include/DD4hep/VolumeManager.h +++ b/DDCore/include/DD4hep/VolumeManager.h @@ -228,6 +228,12 @@ namespace DD4hep { */ VolumeManager(LCDD& lcdd, const std::string& name, DetElement world = DetElement(), Readout ro = Readout(), int flags = NONE); + + /// Assignment operator + VolumeManager& operator=(const VolumeManager& m) { + m_element = m.m_element; + return *this; + } /// Add a new Volume manager section according to a new subdetector VolumeManager addSubdetector(DetElement detector, Readout ro); /// Access the volume manager by cell id diff --git a/DDCore/include/XML/UnicodeValues.h b/DDCore/include/XML/UnicodeValues.h index 9bbdfe465eb17c72171f74411ae07ffe1358681b..62b6e29628132f12ea8950e948233862ffc6adc4 100644 --- a/DDCore/include/XML/UnicodeValues.h +++ b/DDCore/include/XML/UnicodeValues.h @@ -160,6 +160,7 @@ namespace DD4hep { UNICODE (idfield); UNICODE (idspec); UNICODE (idspecref); + UNICODE (include); UNICODE (includes); UNICODE (incoming_r); UNICODE (info); diff --git a/DDCore/src/ExpressionEvaluator.cpp b/DDCore/src/ExpressionEvaluator.cpp index 2d060576fae7165b7da476499d963d0a9b8e785f..92fc67f134055ef53edc67b9789cac5b4387ef3b 100644 --- a/DDCore/src/ExpressionEvaluator.cpp +++ b/DDCore/src/ExpressionEvaluator.cpp @@ -1,33 +1,54 @@ #include "XML/Evaluator.h" -namespace DD4hep { - XmlTools::Evaluator& evaluator() { - static XmlTools::Evaluator e; - return e; +namespace { + void _init(XmlTools::Evaluator& e) { + // Initialize numerical expressions parser with the standard math functions + // and the system of units used by Gaudi (Geant4) + e.setStdMath(); + } + void _cgsUnits(XmlTools::Evaluator& e) { + // =================================================================================== + // CGS units + e.setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0); + } + void _tgeoUnits(XmlTools::Evaluator& e) { + // =================================================================================== + // DDG4 units (TGeo) 1 sec = 10^9 [nsec] + // 1 Coulomb = 1/e As + // Ampere = C/s = 1/e * As / s = 1. / 1.60217733e-19 + // kilogram = joule*s*s/(m*m) 1/e_SI * 1 *1 / 1e2 / 1e2 + e.setSystemOfUnits(1.e+2, 1./1.60217733e-6, 1.0, 1./1.60217733e-19, 1.0, 1.0, 1.0); + } + void _g4Units(XmlTools::Evaluator& e) { + // =================================================================================== + // Geant4 units + // Geant4: kilogram = joule*s*s/(m*m) 1/e_SI * 1e-6 * 1e9 1e9 / 1e3 / 1e3 = 1. / 1.60217733e-25 + e.setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10, 1.0, 1.0, 1.0); } } -namespace { - struct _Init { - _Init() { - // Initialize numerical expressions parser with the standard math functions - // and the system of units used by Gaudi (Geant4) - DD4hep::evaluator().setStdMath(); - // ====================================================================================== - // Geant4 units - // Geant4: kilogram = joule*s*s/(m*m) 1/e_SI * 1e-6 * 1e9 1e9 / 1e3 / 1e3 = 1. / 1.60217733e-25 - //DD4hep::evaluator().setSystemOfUnits(1.e+3, 1. / 1.60217733e-25, 1.e+9, 1. / 1.60217733e-10, 1.0, 1.0, 1.0); - // ====================================================================================== - // CGS units - //DD4hep::evaluator().setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0); - // ====================================================================================== - // DDG4 units (TGeo) 1 sec = 10^9 [nsec] - // 1 Coulomb = 1/e As - // Ampere = C/s = 1/e * As / s = 1. / 1.60217733e-19 - // kilogram = joule*s*s/(m*m) 1/e_SI * 1 *1 / 1e2 / 1e2 - DD4hep::evaluator().setSystemOfUnits(1.e+2, 1./1.60217733e-6, 1.0, 1./1.60217733e-19, 1.0, 1.0, 1.0); +namespace DD4hep { + XmlTools::Evaluator& evaluator() { + static XmlTools::Evaluator* e = 0; + if ( !e ) { + static XmlTools::Evaluator ev; + _init(ev); + _tgeoUnits(ev); + e = &ev; } + return *e; + } - }; - _Init s_init; + /// Access to G4 evaluator. Note: Uses Geant4 units! + XmlTools::Evaluator& g4Evaluator() { + static XmlTools::Evaluator* e = 0; + if ( !e ) { + static XmlTools::Evaluator ev; + _init(ev); + _g4Units(ev); + e = &ev; + } + return *e; + } } + diff --git a/DDCore/src/Objects.cpp b/DDCore/src/Objects.cpp index 3ae550ebb7a01f18ce2ad77b0ef12930452634df..63991804a21f55527e5c1a3ce00bc4957464d2e7 100644 --- a/DDCore/src/Objects.cpp +++ b/DDCore/src/Objects.cpp @@ -404,7 +404,9 @@ const set<Limit>& LimitSet::limits() const { } /// Standard constructor -Region::Object::Object() { +Region::Object::Object() + : magic(magic_word()), threshold(10.0), cut(10.0), store_secondaries(false) +{ InstanceCount::increment(this); } diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index 668db0445a2d2d30fcd707e2aeff94389d64ef02..3468e89654a95222b4158a4d1dd611c1ad10afec 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -277,7 +277,7 @@ VolumeManager::Context::~Context() { /// Default constructor VolumeManager::Object::Object(LCDD& l) - : lcdd(l), top(0), sysID(0), detMask(~0x0ULL), flags(VolumeManager::NONE) { + : lcdd(l), top(0), system(0), sysID(0), detMask(~0x0ULL), flags(VolumeManager::NONE) { } /// Default destructor diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 86b04284a1c154287b310895a8cb9a1890a2a342..59a7d57af51d03ced8acd7b654ad7f6bee7352f5 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -37,6 +37,7 @@ namespace DD4hep { struct GdmlFile; struct Property; struct AlignmentFile; + struct DetElementInclude {}; } template <> void Converter<Constant>::operator()(xml_h e) const; template <> void Converter<Material>::operator()(xml_h e) const; @@ -53,6 +54,7 @@ namespace DD4hep { template <> void Converter<GdmlFile>::operator()(xml_h element) const; template <> void Converter<AlignmentFile>::operator()(xml_h element) const; template <> void Converter<Header>::operator()(xml_h element) const; + template <> void Converter<DetElementInclude>::operator()(xml_h element) const; template <> void Converter<Compact>::operator()(xml_h element) const; } @@ -235,14 +237,14 @@ template <> void Converter<Material>::operator()(xml_h e) const { dens_val *= dens_unit; } #if 0 - cout << "Gev " << XML::_toDouble("GeV") << endl; - cout << "sec " << XML::_toDouble("second") << endl; - cout << "nsec " << XML::_toDouble("nanosecond") << endl; - cout << "kilo " << XML::_toDouble("kilogram") << endl; - cout << "kilo " << XML::_toDouble("joule*s*s/(m*m)") << endl; - cout << "meter " << XML::_toDouble("meter") << endl; - cout << "ampere " << XML::_toDouble("ampere") << endl; - cout << "degree " << XML::_toDouble("degree") << endl; + cout << "Gev " << XML::_toDouble(_Unicode(GeV)) << endl; + cout << "sec " << XML::_toDouble(_Unicode(second)) << endl; + cout << "nsec " << XML::_toDouble(_Unicode(nanosecond)) << endl; + cout << "kilo " << XML::_toDouble(_Unicode(kilogram)) << endl; + cout << "kilo " << XML::_toDouble(_Unicode(joule*s*s/(m*m))) << endl; + cout << "meter " << XML::_toDouble(_Unicode(meter)) << endl; + cout << "ampere " << XML::_toDouble(_Unicode(ampere)) << endl; + cout << "degree " << XML::_toDouble(_Unicode(degree)) << endl; #endif //throw 1; printout(DEBUG, "Compact", "++ Creating material %s", matname); @@ -707,20 +709,42 @@ template <> void Converter<AlignmentFile>::operator()(xml_h element) const { xml_coll_t(alignments, _U(alignment)).for_each(Converter < AlignmentEntry > (this->lcdd)); } +/// Read material entries from a seperate file in one of the include sections of the geometry +template <> void Converter<DetElementInclude>::operator()(xml_h element) const { + xml_h node = XML::DocumentHandler().load(element, element.attr_value(_U(ref))).root(); + string tag = node.tag(); + if ( tag == "lcdd" ) + Converter < Compact > (this->lcdd)(node); + else if ( tag == "define" ) + xml_coll_t(node, _U(constant)).for_each(Converter < Constant > (this->lcdd)); + else if ( tag == "display" ) + xml_coll_t(node,_U(vis)).for_each(Converter < VisAttr > (this->lcdd)); + else if ( tag == "detector" ) + Converter < DetElement > (this->lcdd)(node); + else if ( tag == "detectors" ) + xml_coll_t(node,_U(detector)).for_each(Converter < DetElement > (this->lcdd)); +} + template <> void Converter<Compact>::operator()(xml_h element) const { char text[32]; xml_elt_t compact(element); xml_coll_t(compact, _U(includes)).for_each(_U(gdmlFile), Converter < GdmlFile > (lcdd)); + xml_coll_t(compact, _U(include)).for_each(Converter < DetElementInclude > (this->lcdd)); + if (element.hasChild(_U(info))) (Converter < Header > (lcdd))(xml_h(compact.child(_U(info)))); + + xml_coll_t(compact, _U(define)).for_each(_U(include), Converter < DetElementInclude > (lcdd)); xml_coll_t(compact, _U(define)).for_each(_U(constant), Converter < Constant > (lcdd)); xml_coll_t(compact, _U(materials)).for_each(_U(element), Converter < Atom > (lcdd)); xml_coll_t(compact, _U(materials)).for_each(_U(material), Converter < Material > (lcdd)); xml_coll_t(compact, _U(properties)).for_each(_U(attributes), Converter < Property > (lcdd)); lcdd.init(); xml_coll_t(compact, _U(limits)).for_each(_U(limitset), Converter < LimitSet > (lcdd)); + xml_coll_t(compact, _U(display)).for_each(_U(include), Converter < DetElementInclude > (lcdd)); xml_coll_t(compact, _U(display)).for_each(_U(vis), Converter < VisAttr > (lcdd)); xml_coll_t(compact, _U(readouts)).for_each(_U(readout), Converter < Readout > (lcdd)); + xml_coll_t(compact, _U(detectors)).for_each(_U(include), Converter < DetElementInclude > (lcdd)); xml_coll_t(compact, _U(detectors)).for_each(_U(detector), Converter < DetElement > (lcdd)); xml_coll_t(compact, _U(includes)).for_each(_U(alignment), Converter < AlignmentFile > (lcdd)); xml_coll_t(compact, _U(alignments)).for_each(_U(alignment), Converter < AlignmentEntry > (lcdd)); diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp index 3bfb0351fae1e9a3a5a55e1a590c928e825c3957..141c115af5ea515ddfcb9fdcfc30c7a9e11d7dfc 100644 --- a/DDCore/src/plugins/LCDDConverter.cpp +++ b/DDCore/src/plugins/LCDDConverter.cpp @@ -970,9 +970,12 @@ void LCDDConverter::handleProperties(LCDD::Properties& prp) const { long result = PluginService::Create<long>(tag, &m_lcdd, ptr, &vals); if (0 == result) { PluginDebug dbg; - PluginService::Create<long>(tag, &m_lcdd, ptr, &vals); - throw runtime_error("Failed to locate plugin to interprete files of type" - " \"" + tag + "\" - no factory:" + type + ". " + dbg.missingFactory(tag)); + result = PluginService::Create<long>(tag, &m_lcdd, ptr, &vals); + if (0 == result) { + throw runtime_error("Failed to locate plugin to interprete files of type" + " \"" + tag + "\" - no factory:" + type + ". " + + dbg.missingFactory(tag)); + } } result = *(long*) result; if (result != 1) { diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp index d79a11af9802c0edc364c327cfc24a139ddc408f..ddd084090954d63a907498efd3d47ba516fd01e6 100644 --- a/DDCore/src/plugins/StandardPlugins.cpp +++ b/DDCore/src/plugins/StandardPlugins.cpp @@ -64,8 +64,11 @@ DECLARE_APPLY(DD4hepXMLLoader,load_xml); static long load_volmgr(LCDD& lcdd, int, char**) { try { LCDDImp* imp = dynamic_cast<LCDDImp*>(&lcdd); - imp->m_volManager = VolumeManager(lcdd, "World", imp->world(), Readout(), VolumeManager::TREE); - cout << "++ Volume manager populated and loaded." << endl; + if ( imp ) { + imp->m_volManager = VolumeManager(lcdd, "World", imp->world(), Readout(), VolumeManager::TREE); + cout << "++ Volume manager populated and loaded." << endl; + return 1; + } } catch (const exception& e) { throw runtime_error(string(e.what()) + "\n" @@ -74,6 +77,6 @@ static long load_volmgr(LCDD& lcdd, int, char**) { catch (...) { throw runtime_error("UNKNOWN exception while programming VolumeManager. Are your volIDs correct?"); } - return 1; + return 0; } DECLARE_APPLY(DD4hepVolumeManager,load_volmgr);