From c09d6ee91a14c8f8538ae4fe0d5577fdd9fb383a Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Sat, 10 Oct 2020 21:45:59 +0200 Subject: [PATCH 01/16] replace tbb containers with std ones --- DetectorDescription/DDCMS/interface/DDParsingContext.h | 1 + 1 file changed, 1 insertion(+) diff --git a/DetectorDescription/DDCMS/interface/DDParsingContext.h b/DetectorDescription/DDCMS/interface/DDParsingContext.h index 86a9fff85513d..d885a9efe36cd 100644 --- a/DetectorDescription/DDCMS/interface/DDParsingContext.h +++ b/DetectorDescription/DDCMS/interface/DDParsingContext.h @@ -66,6 +66,7 @@ namespace cms { bool debug_specpars = false; dd4hep::Detector& description; + std::unordered_map assemblies; std::unordered_map rotations; std::unordered_map shapes; From 966e1299f6362d90d53664fd082c81e28c5aadb7 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 13 Oct 2020 16:00:14 +0200 Subject: [PATCH 02/16] final changes to replace tbb with std - requires updated dd4hep --- .../DDCMS/interface/DDFilteredView.h | 4 +- .../DDCMS/plugins/test/DDTestSpecPars.cc | 2 +- .../plugins/test/DDTestSpecParsFilter.cc | 8 +- .../DDCMS/src/DDCompactView.cc | 6 +- .../DDCMS/src/DDFilteredView.cc | 94 ++++++++++++++----- DetectorDescription/DDCMS/test/BuildFile.xml | 8 ++ .../DDCMS/test/Filter.cppunit.cc | 44 +++++++-- 7 files changed, 126 insertions(+), 40 deletions(-) diff --git a/DetectorDescription/DDCMS/interface/DDFilteredView.h b/DetectorDescription/DDCMS/interface/DDFilteredView.h index f1fe2729262f1..38fc916db11be 100644 --- a/DetectorDescription/DDCMS/interface/DDFilteredView.h +++ b/DetectorDescription/DDCMS/interface/DDFilteredView.h @@ -172,7 +172,7 @@ namespace cms { std::string path = this->path(); for (const auto& specPar : refs) { - for (const auto& part : specPar->paths) { + for (const auto& part : specPar.second->paths) { bool flag(true); std::size_t from = 0; for (auto name : dd4hep::dd::split(part, "/")) { @@ -185,7 +185,7 @@ namespace cms { } } if (flag) { - return specPar->value>(key); + return specPar.second->value>(key); } } } diff --git a/DetectorDescription/DDCMS/plugins/test/DDTestSpecPars.cc b/DetectorDescription/DDCMS/plugins/test/DDTestSpecPars.cc index 30610a900f5ef..3ed77010eb060 100644 --- a/DetectorDescription/DDCMS/plugins/test/DDTestSpecPars.cc +++ b/DetectorDescription/DDCMS/plugins/test/DDTestSpecPars.cc @@ -32,7 +32,7 @@ void DDTestSpecPars::analyze(const Event&, const EventSetup& iEventSetup) { LogVerbatim("Geometry").log([®istry](auto& log) { log << "DD SpecPar Registry size: " << registry->specpars.size(); for (const auto& i : registry->specpars) { - log << " " << i.first << " == " << std::string({i.second.name.data(), i.second.name.size()}) << " =>"; + log << " " << i.first << " =>"; log << "\npaths:\n"; for (const auto& k : i.second.paths) log << k << ", "; diff --git a/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc b/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc index 7ca45d554f9e2..1dba92270a7b8 100644 --- a/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc +++ b/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc @@ -52,10 +52,10 @@ void DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup) log << "Filtered DD SpecPar Registry size: " << myReg.size() << "\n"; for (const auto& t : myReg) { log << "\nRegExps { "; - for (const auto& ki : t->paths) + for (const auto& ki : t.second->paths) log << ki << " "; log << "};\n "; - for (const auto& kl : t->spars) { + for (const auto& kl : t.second->spars) { log << kl.first << " = "; for (const auto& kil : kl.second) { log << kil << " "; @@ -66,8 +66,8 @@ void DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup) }); std::cout << "*** Check names in a path after filtering:\n"; for (auto it : myReg) { - if (it->hasPath("//ME11AlumFrame")) { - std::cout << it->name << "\n"; + if (it.second->hasPath("//ME11AlumFrame")) { + std::cout << it.first << "\n"; } } } diff --git a/DetectorDescription/DDCMS/src/DDCompactView.cc b/DetectorDescription/DDCMS/src/DDCompactView.cc index b434b15e912fc..31c99522e8b64 100644 --- a/DetectorDescription/DDCMS/src/DDCompactView.cc +++ b/DetectorDescription/DDCMS/src/DDCompactView.cc @@ -3,7 +3,7 @@ #include #include -#include "tbb/concurrent_vector.h" +#include template <> std::vector cms::DDCompactView::getVector(const std::string& key) const { @@ -42,8 +42,8 @@ std::vector const& cms::DDCompactView::get>(const st } template <> -tbb::concurrent_vector const& cms::DDCompactView::get>( - const std::string& name, const std::string& key) const { +std::vector const& cms::DDCompactView::get>(const std::string& name, + const std::string& key) const { const auto& spec = specpars().specPar(name); if (spec != nullptr) { auto const& nitem = spec->numpars.find(key); diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index c922a9e8c394e..f2be79e5f741d 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -50,11 +50,11 @@ DDFilteredView::DDFilteredView(const DDCompactView& cpv, const cms::DDFilter& fi log << "Filtered by an attribute " << filter.attribute() << "==" << filter.value() << " DD SpecPar Registry size: " << refs_.size() << "\n"; for (const auto& t : refs_) { - log << "\nRegExps { "; - for (const auto& ki : t->paths) + log << "\nSpecPar " << t.first << "\nRegExps { "; + for (const auto& ki : t.second->paths) log << ki << " "; log << "};\n "; - for (const auto& kl : t->spars) { + for (const auto& kl : t.second->spars) { log << kl.first << " = "; for (const auto& kil : kl.second) { log << kil << " "; @@ -164,7 +164,7 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { filters_.shrink_to_fit(); } for (const auto& i : specs) { - for (const auto& j : i->paths) { + for (const auto& j : i.second->paths) { auto const& firstTok = front(j); auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { auto const& k = find_if(begin(f->skeys), end(f->skeys), [&](auto const& p) { return firstTok == p; }); @@ -175,12 +175,20 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { return false; }); if (filter == end(filters_)) { - filters_.emplace_back(unique_ptr( - new Filter{{firstTok}, - {std::regex(std::string("^").append({firstTok.data(), firstTok.size()}).append("$"))}, - nullptr, - nullptr, - i})); + bool isRegex = dd4hep::dd::isRegex(firstTok); + filters_.emplace_back(make_unique()); + filters_.back()->isRegex.emplace_back(isRegex); + filters_.back()->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(firstTok)); + if (isRegex) { + filters_.back()->index.emplace_back(filters_.back()->keys.size()); + filters_.back()->keys.emplace_back(std::regex(begin(firstTok), end(firstTok))); + } else { + filters_.back()->index.emplace_back(filters_.back()->skeys.size()); + } + filters_.back()->skeys.emplace_back(firstTok); + filters_.back()->up = nullptr; + filters_.back()->spec = i.second; + // initialize current filter if it's empty if (currentFilter_ == nullptr) { currentFilter_ = filters_.back().get(); @@ -195,26 +203,63 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { return toks.front() == p; }); if (l == end(currentFilter_->skeys)) { + bool isRegex = dd4hep::dd::isRegex(toks[pos]); + currentFilter_->isRegex.emplace_back(isRegex); + currentFilter_->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + if (isRegex) { + currentFilter_->index.emplace_back(currentFilter_->keys.size()); + currentFilter_->keys.emplace_back(std::regex(std::begin(toks[pos]), std::end(toks[pos]))); + } else { + currentFilter_->index.emplace_back(currentFilter_->skeys.size()); + } currentFilter_->skeys.emplace_back(toks[pos]); - currentFilter_->keys.emplace_back( - std::regex(std::string("^").append({toks[pos].data(), toks[pos].size()}).append("$"))); } } else { - currentFilter_->next.reset( - new Filter{{toks[pos]}, - {std::regex(std::string("^").append({toks[pos].data(), toks[pos].size()}).append("$"))}, - nullptr, - currentFilter_, - i}); + auto filter = std::make_unique(); + bool isRegex = dd4hep::dd::isRegex(toks[pos]); + filter->isRegex.emplace_back(isRegex); + filter->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + if (isRegex) { + filter->index.emplace_back(filters_.back()->keys.size()); + filter->keys.emplace_back(std::regex(toks[pos].begin(), toks[pos].end())); + } else { + filter->index.emplace_back(filters_.back()->skeys.size()); + } + filter->skeys.emplace_back(toks.front()); + filter->next = nullptr; + filter->up = currentFilter_; + filter->spec = i.second; + + currentFilter_->next = std::move(filter); } } } } } +void print(const Filter* filter) { + edm::LogVerbatim("Geometry").log([&](auto& log) { + for (const auto& it : filter->skeys) { + log << it << ", "; + } + }); +} + void DDFilteredView::printFilter() const { for (const auto& f : filters_) { - f->print(); + edm::LogVerbatim("Geometry").log([&](auto& log) { + for (const auto& it : f->skeys) { + log << it << ", "; + } + if (f->next) { + log << "Next:\n"; + print(&*f->next); + } + if (f->up) { + log << "Up:\n"; + print(f->up); + } + }); } } @@ -664,10 +709,11 @@ const DDSpecPar* DDFilteredView::find(const std::string& key) const { filter(specParRefs, key); for (auto const& specPar : specParRefs) { - auto pos = find_if( - begin(specPar->paths), end(specPar->paths), [&](auto const& partSelector) { return matchPath(partSelector); }); - if (pos != end(specPar->paths)) { - return specPar; + auto pos = find_if(begin(specPar.second->paths), end(specPar.second->paths), [&](auto const& partSelector) { + return matchPath(partSelector); + }); + if (pos != end(specPar.second->paths)) { + return specPar.second; } } @@ -677,7 +723,7 @@ const DDSpecPar* DDFilteredView::find(const std::string& key) const { void DDFilteredView::filter(DDSpecParRefs& refs, const std::string& key) const { for (auto const& it : registry_->specpars) { if (it.second.hasValue(key) || (it.second.spars.find(key) != end(it.second.spars))) { - refs.emplace_back(&it.second); + refs.emplace_back(it.first, &it.second); } } } diff --git a/DetectorDescription/DDCMS/test/BuildFile.xml b/DetectorDescription/DDCMS/test/BuildFile.xml index 3a55304f92426..9e6f6b904bd6b 100644 --- a/DetectorDescription/DDCMS/test/BuildFile.xml +++ b/DetectorDescription/DDCMS/test/BuildFile.xml @@ -2,36 +2,43 @@ + + + + + + + @@ -48,6 +55,7 @@ + diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc index 982d30390999d..29eab71e88d68 100644 --- a/DetectorDescription/DDCMS/test/Filter.cppunit.cc +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -51,8 +51,19 @@ void testFilter::setUp() { return false; }); if (filter == end(filters_)) { - filters_.emplace_back(unique_ptr(new Filter{ - {toks.front()}, {std::regex(std::string(toks.front().data(), toks.front().size()))}, nullptr, nullptr})); + bool isRegex = dd4hep::dd::isRegex(toks.front()); + filters_.emplace_back(make_unique()); + filters_.back()->isRegex.emplace_back(isRegex); + filters_.back()->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks.front())); + if (isRegex) { + filters_.back()->index.emplace_back(filters_.back()->keys.size()); + filters_.back()->keys.emplace_back(std::regex(std::begin(toks.front()), std::end(toks.front()))); + } else { + filters_.back()->index.emplace_back(filters_.back()->skeys.size()); + } + filters_.back()->skeys.emplace_back(toks.front()); + filters_.back()->up = nullptr; + filters_.back()->spec = nullptr; currentFilter = filters_.back().get(); } // all next levels @@ -62,12 +73,33 @@ void testFilter::setUp() { auto const& l = find_if( begin(currentFilter->skeys), end(currentFilter->skeys), [&](auto const& p) { return toks[pos] == p; }); if (l == end(currentFilter->skeys)) { + bool isRegex = dd4hep::dd::isRegex(toks.front()); + currentFilter->isRegex.emplace_back(isRegex); + currentFilter->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks.front())); + if (isRegex) { + currentFilter->index.emplace_back(currentFilter->keys.size()); + currentFilter->keys.emplace_back(std::regex(std::begin(toks.front()), std::end(toks.front()))); + } else { + currentFilter->index.emplace_back(currentFilter->skeys.size()); + } currentFilter->skeys.emplace_back(toks.front()); - currentFilter->keys.emplace_back(std::regex(std::string(toks.front().data(), toks.front().size()))); } } else { - currentFilter->next.reset(new Filter{ - {toks[pos]}, {std::regex(std::string({toks[pos].data(), toks[pos].size()}))}, nullptr, currentFilter}); + auto filter = std::make_unique(); + bool isRegex = dd4hep::dd::isRegex(toks[pos]); + filter->isRegex.emplace_back(isRegex); + filter->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + if (isRegex) { + filter->index.emplace_back(filters_.back()->keys.size()); + filter->keys.emplace_back(std::regex(toks[pos].begin(), toks[pos].end())); + } else { + filter->index.emplace_back(filters_.back()->skeys.size()); + } + filter->skeys.emplace_back(toks.front()); + filter->next = nullptr; + filter->up = currentFilter; + + currentFilter->next = std::move(filter); } } } @@ -75,7 +107,7 @@ void testFilter::setUp() { void testFilter::checkFilter() { string_view name = "MB2P.*"sv; - CPPUNIT_ASSERT(std::regex_match(std::string({name.data(), name.size()}), filters_.front()->keys.front()) == 1); + CPPUNIT_ASSERT(std::regex_match(name.begin(), name.end(), filters_.front()->keys.front()) == 1); CPPUNIT_ASSERT(filters_.front()->up == nullptr); CPPUNIT_ASSERT(filters_.front()->next != nullptr); CPPUNIT_ASSERT(filters_.size() == 1); From 66f87c6f2b5c11d06c1bbfe0493eea24dab2c68d Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 13 Oct 2020 17:13:00 +0200 Subject: [PATCH 03/16] update to a new API --- .../MTDCommonData/test/DD4hep_TestMTDIdealGeometry.cc | 8 ++++---- .../test/DD4hep_MTDTopologyAnalyzer.cc | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Geometry/MTDCommonData/test/DD4hep_TestMTDIdealGeometry.cc b/Geometry/MTDCommonData/test/DD4hep_TestMTDIdealGeometry.cc index 8cb2e58e43d96..8fac42a0d9199 100644 --- a/Geometry/MTDCommonData/test/DD4hep_TestMTDIdealGeometry.cc +++ b/Geometry/MTDCommonData/test/DD4hep_TestMTDIdealGeometry.cc @@ -121,11 +121,11 @@ void DD4hep_TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::E edm::LogVerbatim("Geometry").log([&specs](auto& log) { log << "Filtered DD SpecPar Registry size: " << specs.size() << "\n"; for (const auto& t : specs) { - log << "\nRegExps { "; - for (const auto& ki : t->paths) + log << "\nSpecPar " << t.first << ":\nRegExps { "; + for (const auto& ki : t.second->paths) log << ki << " "; log << "};\n "; - for (const auto& kl : t->spars) { + for (const auto& kl : t.second->spars) { log << kl.first << " = "; for (const auto& kil : kl.second) { log << kil << " "; @@ -193,7 +193,7 @@ void DD4hep_TestMTDIdealGeometry::analyze(const edm::Event& iEvent, const edm::E bool isSens = false; for (auto const& t : specs) { - for (auto const& it : t->paths) { + for (auto const& it : t.second->paths) { if (dd4hep::dd::compareEqual(fv.name(), dd4hep::dd::realTopName(it))) { isSens = true; break; diff --git a/Geometry/MTDNumberingBuilder/test/DD4hep_MTDTopologyAnalyzer.cc b/Geometry/MTDNumberingBuilder/test/DD4hep_MTDTopologyAnalyzer.cc index 9514140f1a17d..d16aac25d1390 100644 --- a/Geometry/MTDNumberingBuilder/test/DD4hep_MTDTopologyAnalyzer.cc +++ b/Geometry/MTDNumberingBuilder/test/DD4hep_MTDTopologyAnalyzer.cc @@ -112,10 +112,10 @@ void DD4hep_MTDTopologyAnalyzer::analyze(const edm::Event& iEvent, const edm::Ev log << "Filtered DD SpecPar Registry size: " << specs.size() << "\n"; for (const auto& t : specs) { log << "\nRegExps { "; - for (const auto& ki : t->paths) + for (const auto& ki : t.second->paths) log << ki << " "; log << "};\n "; - for (const auto& kl : t->spars) { + for (const auto& kl : t.second->spars) { log << kl.first << " = "; for (const auto& kil : kl.second) { log << kil << " "; @@ -178,7 +178,7 @@ void DD4hep_MTDTopologyAnalyzer::analyze(const edm::Event& iEvent, const edm::Ev bool isSens = false; for (auto const& t : specs) { - for (auto const& it : t->paths) { + for (auto const& it : t.second->paths) { if (dd4hep::dd::compareEqual(fv.name(), dd4hep::dd::realTopName(it))) { isSens = true; break; From 755406f9c2e91cccd8cacc0cf9202436e116f5fc Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 14 Oct 2020 19:16:57 +0200 Subject: [PATCH 04/16] update to the new dd4hep version --- .../plugins/dd4hep/DDDefinitions2Objects.cc | 302 +++++++++++++++++- .../DDCMS/src/DDFilteredView.cc | 24 +- .../DDCMS/test/Filter.cppunit.cc | 6 +- .../data/dd4hep/cmsExtendedGeometry2021.xml | 2 +- 4 files changed, 309 insertions(+), 25 deletions(-) diff --git a/DetectorDescription/DDCMS/plugins/dd4hep/DDDefinitions2Objects.cc b/DetectorDescription/DDCMS/plugins/dd4hep/DDDefinitions2Objects.cc index 8599cb0f3e6a8..e1a4ad5b43c2c 100644 --- a/DetectorDescription/DDCMS/plugins/dd4hep/DDDefinitions2Objects.cc +++ b/DetectorDescription/DDCMS/plugins/dd4hep/DDDefinitions2Objects.cc @@ -29,6 +29,8 @@ #include #include +#define EDM_ML_DEBUG + using namespace std; using namespace dd4hep; using namespace cms; @@ -415,6 +417,9 @@ void Converter::operator()(xml_h element) const { ns.addConstant(nam, val, typ); res->originalConst[real] = val; } catch (const exception& e) { + +#ifdef EDM_ML_DEBUG + printout(INFO, "DD4CMS", "++ Unresolved constant: %s = %s [%s]. Try to resolve later. [%s]", @@ -422,6 +427,8 @@ void Converter::operator()(xml_h element) const { val.c_str(), typ.c_str(), e.what()); +#endif + } return; } @@ -436,8 +443,14 @@ void Converter::operator()(xml_h element) const { val[idp] = NAMESPACE_SEP; idx = val.find('[', idx); } + +#ifdef EDM_ML_DEBUG + printout( ns.context()->debug_constants ? ALWAYS : DEBUG, "Constant", "Unresolved: %s -> %s", real.c_str(), val.c_str()); + +#endif + res->originalConst[real] = val; res->unresolvedConst[real] = val; } @@ -457,8 +470,13 @@ void Converter::operator()(xml_h element) const { double atomicWeight = xmat.attr(DD_CMU(atomicWeight)) / (dd4hep::g / dd4hep::mole); TGeoElementTable* tab = mgr.GetElementTable(); int nElem = tab->GetNelements(); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS", "+++ Element table size = %d", nElem); +#endif + if (nElem <= 1) { // Restore the element table DD4hep destroyed. tab->TGeoElementTable::~TGeoElementTable(); new (tab) TGeoElementTable(); @@ -466,6 +484,9 @@ void Converter::operator()(xml_h element) const { } TGeoMixture* mix = new TGeoMixture(nam.c_str(), 1, density); TGeoElement* elt = tab->FindElement(xmat.nameStr().c_str()); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS", "+++ Searching for material %-48s elt_ptr = %ld", @@ -482,10 +503,15 @@ void Converter::operator()(xml_h element) const { density, mix->GetDensity()); +#endif + bool newMatDef = false; if (elt) { // A is Mass of a mole in Geant4 units for atoms with atomic shell + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS", " ROOT definition of %-50s Atomic weight %g, Atomic number %u, Number of nucleons %u", @@ -498,6 +524,8 @@ void Converter::operator()(xml_h element) const { "+++ Compared to XML values: Atomic weight %g, Atomic number %u", atomicWeight, atomicNumber); +#endif + static constexpr double const weightTolerance = 1.0e-6; if (atomicNumber != elt->Z() || (std::abs(atomicWeight - elt->A()) > (weightTolerance * (atomicWeight + elt->A())))) @@ -505,17 +533,29 @@ void Converter::operator()(xml_h element) const { } if (!elt || newMatDef) { - if (newMatDef) + if (newMatDef) { + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS Warning", "+++ Converter Different definition of a default element with name:%s [CREATE NEW " "MATERIAL]", matname); - else + +#endif + + } else { + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS Warning", "+++ Converter No default element present with name:%s [CREATE NEW MATERIAL]", matname); + +#endif + } elt = new TGeoElement(xmat.nameStr().c_str(), "CMS element", atomicNumber, atomicWeight); } @@ -547,6 +587,8 @@ void Converter::operator()(xml_h element) const { xml_coll_t composites(xmat, DD_CMU(MaterialFraction)); TGeoMixture* mix = new TGeoMixture(nam.c_str(), composites.size(), density); +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS", "++ Converting material %-48s Density: %8.3f [g/cm3] ROOT: %8.3f [g/cm3]", @@ -554,6 +596,8 @@ void Converter::operator()(xml_h element) const { density, mix->GetDensity()); +#endif + for (composites.reset(); composites; ++composites) { xml_dim_t xfrac(composites); xml_dim_t xfrac_mat(xfrac.child(DD_CMU(rMaterial))); @@ -568,11 +612,16 @@ void Converter::operator()(xml_h element) const { continue; } +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS Warning", "+++ Composite material \"%s\" [nor \"%s\"] not present! [delay resolution]", fracname.c_str(), ns.prepend(fracname).c_str()); + +#endif + ns.context()->unresolvedMaterials[nam].emplace_back( cms::DDParsingContext::CompositeMaterial(ns.prepend(fracname), fraction)); } @@ -602,6 +651,9 @@ void Converter::operator()(xml_h element) const { double thetaZ = xrot.hasAttr(DD_CMU(thetaZ)) ? ns.attr(xrot, DD_CMU(thetaZ)) : 0e0; double phiZ = xrot.hasAttr(DD_CMU(phiZ)) ? ns.attr(xrot, DD_CMU(phiZ)) : 0e0; Rotation3D rot = makeRotation3D(thetaX, phiX, thetaY, phiY, thetaZ, phiZ); + +#ifdef EDM_ML_DEBUG + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+++ Adding rotation: %-32s: (theta/phi)[rad] X: %6.3f %6.3f Y: %6.3f %6.3f Z: %6.3f %6.3f", @@ -612,6 +664,9 @@ void Converter::operator()(xml_h element) const { phiY, thetaZ, phiZ); + +#endif + ns.addRotation(nam, rot); } @@ -628,6 +683,9 @@ void Converter::operator()(xml_h element) const { double phiY = xrot.hasAttr(DD_CMU(phiY)) ? ns.attr(xrot, DD_CMU(phiY)) : 0e0; double thetaZ = xrot.hasAttr(DD_CMU(thetaZ)) ? ns.attr(xrot, DD_CMU(thetaZ)) : 0e0; double phiZ = xrot.hasAttr(DD_CMU(phiZ)) ? ns.attr(xrot, DD_CMU(phiZ)) : 0e0; + +#ifdef EDM_ML_DEBUG + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+++ Adding reflection rotation: %-32s: (theta/phi)[rad] X: %6.3f %6.3f Y: %6.3f %6.3f Z: %6.3f %6.3f", @@ -638,6 +696,9 @@ void Converter::operator()(xml_h element) const { phiY, thetaZ, phiZ); + +#endif + Rotation3D rot = makeRotReflect(thetaX, phiX, thetaY, phiY, thetaZ, phiZ); ns.addRotation(name, rot); } @@ -655,17 +716,26 @@ void Converter::operator()(xml_h element) const { string axis = ns.attr(rotations, DD_CMU(axis)); double angle = ns.attr(rotations, _U(angle)); rot = makeRotation3D(rot, axis, angle); + +#ifdef EDM_ML_DEBUG + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+ Adding rotation to: %-29s: (axis/angle)[rad] Axis: %s Angle: %6.3f", nam.c_str(), axis.c_str(), angle); + +#endif + } double xx, xy, xz; double yx, yy, yz; double zx, zy, zz; rot.GetComponents(xx, xy, xz, yx, yy, yz, zx, zy, zz); + +#ifdef EDM_ML_DEBUG + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+++ Adding rotation sequence: %-23s: %6.3f %6.3f %6.3f, %6.3f %6.3f %6.3f, %6.3f %6.3f %6.3f", @@ -679,6 +749,9 @@ void Converter::operator()(xml_h element) const { zx, zy, zz); + +#endif + ns.addRotation(nam, rot); } @@ -695,12 +768,18 @@ void Converter::operator()(xml_h element) const { double angle = ns.attr(xrot, _U(angle)); Rotation3D rot; rot = makeRotation3D(rot, axis, angle); + +#ifdef EDM_ML_DEBUG + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+++ Adding rotation: %-32s: (axis/angle)[rad] Axis: %s Angle: %6.3f", ns.prepend(nam).c_str(), axis.c_str(), angle); + +#endif + ns.addRotation(nam, rot); } } @@ -715,7 +794,15 @@ void Converter::operator()(xml_h element) const { string volName = e.attr(_U(name)); Solid solid = ns.solid(sol); Material material = ns.material(mat); - Volume volume = ns.addVolume(Volume(volName, solid, material)); + +#ifdef EDM_ML_DEBUG + Volume volume = +#endif + + ns.addVolume(Volume(volName, solid, material)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_volumes ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Volume: %-24s [%s] Shape: %-32s [%s] Material: %-40s [%s]", @@ -726,6 +813,8 @@ void Converter::operator()(xml_h element) const { solid.isValid() ? "VALID" : "INVALID", mat.c_str(), material.isValid() ? "VALID" : "INVALID"); + +#endif } /// Helper converter @@ -772,6 +861,9 @@ void Converter::operator()(xml_h element) const { string childName = ns.attr(e.child(DD_CMU(rChild)), _U(name)); Volume parent = ns.volume(parentName, false); Volume child = ns.volume(childName, false); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Parent: %-24s [%s] Child: %-32s [%s] copy:%d", @@ -782,6 +874,8 @@ void Converter::operator()(xml_h element) const { child.isValid() ? "VALID" : "INVALID", copy); +#endif + if (!parent.isValid() && strchr(parentName.c_str(), NAMESPACE_SEP) == nullptr) parentName = ns.prepend(parentName); parent = ns.volume(parentName); @@ -790,6 +884,8 @@ void Converter::operator()(xml_h element) const { childName = ns.prepend(childName); child = ns.volume(childName, false); +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Parent: %-24s [%s] Child: %-32s [%s] copy:%d", @@ -800,6 +896,8 @@ void Converter::operator()(xml_h element) const { child.isValid() ? "VALID" : "INVALID", copy); +#endif + PlacedVolume pv; if (child.isValid()) { Transform3D transform; @@ -863,12 +961,17 @@ void Converter::operator()(xml_h element) const { xml_dim_t specPar = e.parent(); string specParName = specPar.attr(_U(name)); string path = e.attr(DD_CMU(path)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_specpars ? ALWAYS : DEBUG, "DD4CMS", "+++ PartSelector for %s path: %s", specParName.c_str(), path.c_str()); +#endif + size_t pos = std::string::npos; if ((pos = path.find("//.*:")) != std::string::npos) { path.erase(pos + 2, 3); @@ -892,6 +995,8 @@ void Converter::operator()(xml_h element) const { : (specParSect.hasAttr(_U(eval)) ? specParSect.attr(_U(eval)) : false); string type = eval ? "number" : "string"; +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_specpars ? ALWAYS : DEBUG, "DD4CMS", "+++ Parameter for %s: %s value %s is a %s", @@ -900,6 +1005,8 @@ void Converter::operator()(xml_h element) const { value.c_str(), type.c_str()); +#endif + size_t idx = value.find('['); if (idx == string::npos || type == "string") { registry.specpars[specParName].spars[name].emplace_back(std::move(value)); @@ -929,7 +1036,7 @@ void Converter::operator()(xml_h element) const { v.replace(idx, idq - idx + 1, rep); } } - registry.specpars[specParName].numpars[name].emplace_back(_toDouble(value)); + registry.specpars[specParName].numpars[name].emplace_back(dd4hep::_toDouble(value)); } template @@ -958,6 +1065,8 @@ static void convert_boolean(cms::DDParsingContext* context, xml_h element) { except("DD4CMS", "+++ Failed to create boolean solid %s. Found only %d parts.", nam.c_str(), cnt); } +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ BooleanSolid: %s Left: %-32s Right: %-32s", @@ -965,6 +1074,8 @@ static void convert_boolean(cms::DDParsingContext* context, xml_h element) { ((solids[0].ptr() == nullptr) ? solidName[0].c_str() : solids[0]->GetName()), ((solids[1].ptr() == nullptr) ? solidName[1].c_str() : solids[1]->GetName())); +#endif + if (solids[0].isValid() && solids[1].isValid()) { Transform3D trafo; Converter(context->description, context, &trafo)(element); @@ -1021,14 +1132,23 @@ void Converter::operator()(xml_h element) const { rmax.emplace_back(ns.attr(zplane, DD_CMU(rMax))); z.emplace_back(ns.attr(zplane, _U(z))); } + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Polycone: startPhi=%10.3f [rad] deltaPhi=%10.3f [rad] %4ld z-planes", startPhi, deltaPhi, z.size()); + +#endif + ns.addSolid(nam, Polycone(startPhi, deltaPhi, rmin, rmax, z)); } else { + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Polycone: startPhi=%10.3f [rad] deltaPhi=%10.3f [rad] %4ld z-planes and %4ld radii", @@ -1036,6 +1156,9 @@ void Converter::operator()(xml_h element) const { deltaPhi, z.size(), r.size()); + +#endif + ns.addSolid(nam, Polycone(startPhi, deltaPhi, r, z)); } } @@ -1058,11 +1181,17 @@ void Converter::operator()(xml_h element) const { pt_x.emplace_back(ns.attr(pt, _U(x))); pt_y.emplace_back(ns.attr(pt, _U(y))); } + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ ExtrudedPolygon: %4ld points %4ld zxy sections", pt_x.size(), sec_z.size()); + +#endif + ns.addSolid(nam, ExtrudedPolygon(pt_x, pt_y, sec_z, sec_x, sec_y, sec_scale)); } @@ -1087,6 +1216,9 @@ void Converter::operator()(xml_h element) const { rmax.emplace_back(ns.attr(zplane, DD_CMU(rMax))); z.emplace_back(ns.attr(zplane, _U(z))); } + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Polyhedra:startPhi=%8.3f [rad] deltaPhi=%8.3f [rad] %4d sides %4ld z-planes", @@ -1094,6 +1226,9 @@ void Converter::operator()(xml_h element) const { deltaPhi, numSide, z.size()); + +#endif + ns.addSolid(nam, Polyhedra(numSide, startPhi, deltaPhi, z, rmin, rmax)); } @@ -1109,6 +1244,9 @@ void Converter::operator()(xml_h element) const { double deltaPhi = ns.attr(e, DD_CMU(deltaPhi)); double startTheta = ns.attr(e, DD_CMU(startTheta)); double deltaTheta = ns.attr(e, DD_CMU(deltaTheta)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Sphere: r_inner=%8.3f [cm] r_outer=%8.3f [cm]" @@ -1119,6 +1257,9 @@ void Converter::operator()(xml_h element) const { deltaPhi, startTheta, deltaTheta); + +#endif + ns.addSolid(nam, Sphere(rinner, router, startTheta, deltaTheta, startPhi, deltaPhi)); } @@ -1133,6 +1274,9 @@ void Converter::operator()(xml_h element) const { double router = ns.attr(e, DD_CMU(outerRadius)); double startPhi = ns.attr(e, DD_CMU(startPhi)); double deltaPhi = ns.attr(e, DD_CMU(deltaPhi)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Torus: r=%10.3f [cm] r_inner=%10.3f [cm] r_outer=%10.3f [cm]" @@ -1142,6 +1286,9 @@ void Converter::operator()(xml_h element) const { router, startPhi, deltaPhi); + +#endif + ns.addSolid(nam, Torus(r, rinner, router, startPhi, deltaPhi)); } @@ -1158,6 +1305,9 @@ void Converter::operator()(xml_h element) const { double dz = ns.attr(e, _U(dz)); double r = ns.attr(e, _U(radius)); bool atMinusZ = ns.attr(e, DD_CMU(atMinusZ)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Pseudotrap: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2=%.3f dy2=%.3f radius:%.3f atMinusZ:%s", @@ -1168,6 +1318,9 @@ void Converter::operator()(xml_h element) const { dy2, r, yes_no(atMinusZ)); + +#endif + ns.addSolid(nam, PseudoTrap(dx1, dx2, dy1, dy2, dz, r, atMinusZ)); } @@ -1189,6 +1342,8 @@ void Converter::operator()(xml_h element) const { double phi = ns.attr(e, _U(phi), 0.0); double theta = ns.attr(e, _U(theta), 0.0); +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Trapezoid: dz=%10.3f [cm] alp1:%.3f bl1=%.3f tl1=%.3f alp2=%.3f bl2=%.3f tl2=%.3f h2=%.3f phi=%.3f " @@ -1204,6 +1359,9 @@ void Converter::operator()(xml_h element) const { h2, phi, theta); + +#endif + ns.addSolid(nam, Trap(dz, theta, phi, h1, bl1, tl1, alp1, h2, bl2, tl2, alp2)); } @@ -1219,6 +1377,9 @@ void Converter::operator()(xml_h element) const { double dy2 = ns.attr(e, DD_CMU(dy2), dy1); double dz = ns.attr(e, DD_CMU(dz)); if (dy1 == dy2) { + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Trd1: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2:%.3f dy2:%.3f", @@ -1227,8 +1388,14 @@ void Converter::operator()(xml_h element) const { dy1, dx2, dy2); + +#endif + ns.addSolid(nam, Trd1(dx1, dx2, dy1, dz)); } else { + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Trd1(which is actually Trd2): dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2:%.3f dy2:%.3f", @@ -1237,6 +1404,9 @@ void Converter::operator()(xml_h element) const { dy1, dx2, dy2); + +#endif + ns.addSolid(nam, Trd2(dx1, dx2, dy1, dy2, dz)); } } @@ -1252,6 +1422,9 @@ void Converter::operator()(xml_h element) const { double dx2 = ns.attr(e, DD_CMU(dx2), 0.0); double dy2 = ns.attr(e, DD_CMU(dy2), dy1); double dz = ns.attr(e, DD_CMU(dz)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Trd1: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2:%.3f dy2:%.3f", @@ -1260,6 +1433,9 @@ void Converter::operator()(xml_h element) const { dy1, dx2, dy2); + +#endif + ns.addSolid(nam, Trd2(dx1, dx2, dy1, dy2, dz)); } @@ -1274,6 +1450,9 @@ void Converter::operator()(xml_h element) const { double rmax = ns.attr(e, DD_CMU(rMax)); double startPhi = ns.attr(e, DD_CMU(startPhi), 0.0); double deltaPhi = ns.attr(e, DD_CMU(deltaPhi), 2 * M_PI); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Tubs: dz=%8.3f [cm] rmin=%8.3f [cm] rmax=%8.3f [cm]" @@ -1283,6 +1462,9 @@ void Converter::operator()(xml_h element) const { rmax, startPhi, deltaPhi); + +#endif + ns.addSolid(nam, Tube(rmin, rmax, dz, startPhi, startPhi + deltaPhi)); } @@ -1303,6 +1485,9 @@ void Converter::operator()(xml_h element) const { double tx = ns.attr(e, DD_CMU(tx)); double ty = ns.attr(e, DD_CMU(ty)); double tz = ns.attr(e, DD_CMU(tz)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ CutTube: dz=%8.3f [cm] rmin=%8.3f [cm] rmax=%8.3f [cm]" @@ -1312,6 +1497,9 @@ void Converter::operator()(xml_h element) const { rmax, startPhi, deltaPhi); + +#endif + ns.addSolid(nam, CutTube(rmin, rmax, dz, startPhi, startPhi + deltaPhi, lx, ly, lz, tx, ty, tz)); } @@ -1329,6 +1517,9 @@ void Converter::operator()(xml_h element) const { double cutAtStart = ns.attr(e, DD_CMU(cutAtStart)); double cutAtDelta = ns.attr(e, DD_CMU(cutAtDelta)); bool cutInside = ns.attr(e, DD_CMU(cutInside)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ TruncTube:zHalf=%8.3f [cm] rmin=%8.3f [cm] rmax=%8.3f [cm]" @@ -1341,6 +1532,9 @@ void Converter::operator()(xml_h element) const { cutAtStart, cutAtDelta, yes_no(cutInside)); + + #endif + ns.addSolid(nam, TruncatedTube(zhalf, rmin, rmax, startPhi, deltaPhi, cutAtStart, cutAtDelta, cutInside)); } @@ -1353,12 +1547,18 @@ void Converter::operator()(xml_h element) const { double dx = ns.attr(e, DD_CMU(xSemiAxis)); double dy = ns.attr(e, DD_CMU(ySemiAxis)); double dz = ns.attr(e, DD_CMU(zHeight)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ EllipticalTube xSemiAxis=%8.3f [cm] ySemiAxis=%8.3f [cm] zHeight=%8.3f [cm]", dx, dy, dz); + +#endif + ns.addSolid(nam, EllipticalTube(dx, dy, dz)); } @@ -1376,6 +1576,9 @@ void Converter::operator()(xml_h element) const { double startPhi = ns.attr(e, DD_CMU(startPhi)); double deltaPhi = ns.attr(e, DD_CMU(deltaPhi)); double phi2 = startPhi + deltaPhi; + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Cone: dz=%8.3f [cm]" @@ -1389,6 +1592,9 @@ void Converter::operator()(xml_h element) const { rmax2, startPhi, deltaPhi); + +#endif + ns.addSolid(nam, ConeSegment(dz, rmin1, rmax1, rmin2, rmax2, startPhi, phi2)); } @@ -1398,10 +1604,16 @@ void Converter::operator()(xml_h element) const { cms::DDNamespace ns(_param()); xml_dim_t e(element); string nam = e.nameStr(); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Shapeless: THIS ONE CAN ONLY BE USED AT THE VOLUME LEVEL -> Assembly%s", nam.c_str()); + +#endif + ns.addSolid(nam, Box(1, 1, 1)); } @@ -1414,12 +1626,18 @@ void Converter::operator()(xml_h element) const { double dx = ns.attr(e, DD_CMU(dx)); double dy = ns.attr(e, DD_CMU(dy)); double dz = ns.attr(e, DD_CMU(dz)); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Box: dx=%10.3f [cm] dy=%10.3f [cm] dz=%10.3f [cm]", dx, dy, dz); + +#endif + ns.addSolid(nam, Box(dx, dy, dz)); } @@ -1430,10 +1648,16 @@ void Converter::operator()(xml_h element) const { edm::FileInPath fp(fname); xml::Document doc; doc = xml::DocumentHandler().load(fp.fullPath()); + +#ifdef EDM_ML_DEBUG + printout(_param()->debug_includes ? ALWAYS : DEBUG, "DD4CMS", "+++ Processing the CMS detector description %s", fname.c_str()); + +#endif + _option()->includes.emplace_back(doc); } @@ -1442,10 +1666,14 @@ template <> void Converter::operator()(xml_h element) const { string fname = xml::DocumentHandler::system_path(element); xml::DocumentHolder(xml_elt_t(element).document()).assign(nullptr); + +#ifdef EDM_ML_DEBUG + printout(_param()->debug_includes ? ALWAYS : DEBUG, "DD4CMS", "+++ Finished processing %s", fname.c_str()); +#endif } /// DD4hep specific Converter for tags: process only the constants @@ -1491,6 +1719,8 @@ void Converter::operator()(xml_h element) const { double width = e.hasAttr(DD_CMU(width)) ? ns.attr(e, DD_CMU(width)) : 0e0; int nReplicas = e.hasAttr(DD_CMU(nReplicas)) ? ns.attr(e, DD_CMU(nReplicas)) : 0; +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ Start executing Division of %s along %s (%d) with offset %6.3f and %6.3f to produce %s....", @@ -1501,6 +1731,8 @@ void Converter::operator()(xml_h element) const { width, childName.c_str()); +#endif + Volume parent = ns.volume(parentName); const TGeoShape* shape = parent.solid(); @@ -1510,6 +1742,9 @@ void Converter::operator()(xml_h element) const { double widthInDeg = convertRadToDeg(width); double startInDeg = convertRadToDeg(offset); int numCopies = (int)((sh->GetPhi2() - sh->GetPhi1()) / widthInDeg); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ ...divide %s along %s (%d) with offset %6.3f deg and %6.3f deg to produce %d copies", @@ -1519,10 +1754,15 @@ void Converter::operator()(xml_h element) const { startInDeg, widthInDeg, numCopies); + +#endif + Volume child = parent.divide(childName, static_cast(axesmap.at(axis)), numCopies, startInDeg, widthInDeg); ns.context()->volumes[childName] = child; +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Parent: %-24s [%s] Child: %-32s [%s] is multivolume [%s]", @@ -1532,9 +1772,13 @@ void Converter::operator()(xml_h element) const { child.name(), child.isValid() ? "VALID" : "INVALID", child->IsVolumeMulti() ? "YES" : "NO"); - +#endif + } else if (cl == TGeoTrd1::Class()) { double dy = static_cast(shape)->GetDy(); + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ ...divide %s along %s (%d) with offset %6.3f cm and %6.3f cm to produce %d copies in %6.3f", @@ -1545,10 +1789,15 @@ void Converter::operator()(xml_h element) const { width, nReplicas, dy); + +#endif + Volume child = parent.divide(childName, static_cast(axesmap.at(axis)), nReplicas, -dy + offset + width, width); ns.context()->volumes[childName] = child; +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Parent: %-24s [%s] Child: %-32s [%s] is multivolume [%s]", @@ -1558,6 +1807,9 @@ void Converter::operator()(xml_h element) const { child.name(), child.isValid() ? "VALID" : "INVALID", child->IsVolumeMulti() ? "YES" : "NO"); + +#endif + } else { printout(ERROR, "DD4CMS", "++ FAILED Division of a %s is not implemented yet!", parent.solid().type()); } @@ -1574,16 +1826,26 @@ void Converter::operator()(xml_h element) const { while ((idx = type.find(NAMESPACE_SEP)) != string::npos) type[idx] = '_'; +#ifdef EDM_ML_DEBUG + printout( ns.context()->debug_algorithms ? ALWAYS : DEBUG, "DD4CMS", "+++ Start executing algorithm %s....", type.c_str()); +#endif + long ret = PluginService::Create(type, &description, ns.context(), &element); if (ret == s_executed) { + +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_algorithms ? ALWAYS : DEBUG, - "DD4CMS", + + "DD4CMS", "+++ Executed algorithm: %08lX = %s", ret, name.c_str()); + +#endif return; } printout(ERROR, "DD4CMS", "++ FAILED NOT ADDING SUBDETECTOR %08lX = %s", ret, name.c_str()); @@ -1647,6 +1909,8 @@ void Converter::operator()(xml_h element) const { string val = e.text(); val.erase(remove_if(val.begin(), val.end(), [](unsigned char x) { return isspace(x); }), val.end()); +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_constants ? ALWAYS : DEBUG, "DD4CMS", "+++ Vector<%s>: %s[%s]: %s", @@ -1654,12 +1918,18 @@ void Converter::operator()(xml_h element) const { name.c_str(), nEntries.c_str(), val.c_str()); + +#endif + try { std::vector results = splitNumeric(val); registry->insert( {name, results}); //tbb::concurrent_vector>(results.begin(), results.end())}); } catch (const exception& e) { + +#ifdef EDM_ML_DEBUG + printout(INFO, "DD4CMS", "++ Unresolved Vector<%s>: %s[%s]: %s. Try to resolve later. [%s]", @@ -1669,6 +1939,8 @@ void Converter::operator()(xml_h element) const { val.c_str(), e.what()); +#endif + std::vector results = splitString(val); context->unresolvedVectors.insert({name, results}); } @@ -1706,12 +1978,15 @@ void Converter::operator()(xml_h /* element */) const { cms::DDNamespace ns(context); int count = 0; +#ifdef EDM_ML_DEBUG + printout(context->debug_constants ? ALWAYS : DEBUG, "DD4CMS", "+++ RESOLVING %ld unknown constants..... (out of %ld)", res->unresolvedConst.size(), res->originalConst.size()); - +#endif + while (!res->unresolvedConst.empty()) { for (auto& i : res->unresolvedConst) { const string& n = i.first; @@ -1734,12 +2009,18 @@ void Converter::operator()(xml_h /* element */) const { while ((idx = v.find("+-")) != string::npos) v.replace(idx, 2, "-"); } - printout(context->debug_constants ? ALWAYS : DEBUG, + +#ifdef EDM_ML_DEBUG + + printout(context->debug_constants ? ALWAYS : DEBUG, "DD4CMS", "+++ [%06ld] ---------- %-40s = %s", res->unresolvedConst.size() - 1, n.c_str(), res->originalConst[n].c_str()); + +#endif + ns.addConstantNS(n, v, "number"); res->unresolvedConst.erase(n); break; @@ -1760,10 +2041,15 @@ void Converter::operator()(xml_h /* element */) const { template <> void Converter::operator()(xml_h element) const { string fname = xml::DocumentHandler::system_path(element); + +#ifdef EDM_ML_DEBUG + printout(_param()->debug_includes ? ALWAYS : DEBUG, "DD4CMS", "+++ Processing data from: %s", fname.c_str()); + +#endif } /// Converter for tags diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index f2be79e5f741d..747d7ff827614 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -50,7 +50,7 @@ DDFilteredView::DDFilteredView(const DDCompactView& cpv, const cms::DDFilter& fi log << "Filtered by an attribute " << filter.attribute() << "==" << filter.value() << " DD SpecPar Registry size: " << refs_.size() << "\n"; for (const auto& t : refs_) { - log << "\nSpecPar " << t.first << "\nRegExps { "; + log << "\nSpecPar " << std::string(t.first.data(), t.first.size()) << "\nRegExps { "; for (const auto& ki : t.second->paths) log << ki << " "; log << "};\n "; @@ -178,7 +178,7 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { bool isRegex = dd4hep::dd::isRegex(firstTok); filters_.emplace_back(make_unique()); filters_.back()->isRegex.emplace_back(isRegex); - filters_.back()->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(firstTok)); + filters_.back()->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(firstTok)); if (isRegex) { filters_.back()->index.emplace_back(filters_.back()->keys.size()); filters_.back()->keys.emplace_back(std::regex(begin(firstTok), end(firstTok))); @@ -205,7 +205,7 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { if (l == end(currentFilter_->skeys)) { bool isRegex = dd4hep::dd::isRegex(toks[pos]); currentFilter_->isRegex.emplace_back(isRegex); - currentFilter_->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + currentFilter_->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); if (isRegex) { currentFilter_->index.emplace_back(currentFilter_->keys.size()); currentFilter_->keys.emplace_back(std::regex(std::begin(toks[pos]), std::end(toks[pos]))); @@ -218,7 +218,7 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { auto filter = std::make_unique(); bool isRegex = dd4hep::dd::isRegex(toks[pos]); filter->isRegex.emplace_back(isRegex); - filter->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + filter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); if (isRegex) { filter->index.emplace_back(filters_.back()->keys.size()); filter->keys.emplace_back(std::regex(toks[pos].begin(), toks[pos].end())); @@ -413,7 +413,7 @@ bool DDFilteredView::firstSibling() { else return false; do { - if (accepted(currentFilter_->keys, noNamespace(node->GetVolume()->GetName()))) { + if (dd4hep::dd::accepted(currentFilter_, noNamespace(node->GetVolume()->GetName()))) { node_ = node; return true; } @@ -435,7 +435,7 @@ bool DDFilteredView::nextSibling() { it_.back().SetType(1); Node* node = node_; do { - if (accepted(currentFilter_->keys, noNamespace(node->GetVolume()->GetName()))) { + if (dd4hep::dd::accepted(currentFilter_, noNamespace(node->GetVolume()->GetName()))) { node_ = node; return true; } @@ -453,7 +453,7 @@ bool DDFilteredView::sibling() { it_.back().SetType(1); Node* node = nullptr; while ((node = it_.back().Next())) { - if (accepted(currentFilter_->keys, node->GetVolume()->GetName())) { + if (dd4hep::dd::accepted(currentFilter_, node->GetVolume()->GetName())) { node_ = node; return true; } @@ -469,7 +469,7 @@ bool DDFilteredView::checkChild() { it_.back().SetType(1); Node* node = nullptr; while ((node = it_.back().Next())) { - if (accepted(currentFilter_->keys, node->GetVolume()->GetName())) { + if (dd4hep::dd::accepted(currentFilter_, node->GetVolume()->GetName())) { return true; } } @@ -523,14 +523,12 @@ void DDFilteredView::up() { } bool DDFilteredView::accept(std::string_view name) { - bool result = false; for (const auto& it : filters_) { currentFilter_ = it.get(); - result = accepted(currentFilter_->keys, name); - if (result) - return result; + if (dd4hep::dd::accepted(currentFilter_, name)) + return true; } - return result; + return false; } const std::vector DDFilteredView::parameters() const { diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc index 29eab71e88d68..46d88476d8814 100644 --- a/DetectorDescription/DDCMS/test/Filter.cppunit.cc +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -54,7 +54,7 @@ void testFilter::setUp() { bool isRegex = dd4hep::dd::isRegex(toks.front()); filters_.emplace_back(make_unique()); filters_.back()->isRegex.emplace_back(isRegex); - filters_.back()->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks.front())); + filters_.back()->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks.front())); if (isRegex) { filters_.back()->index.emplace_back(filters_.back()->keys.size()); filters_.back()->keys.emplace_back(std::regex(std::begin(toks.front()), std::end(toks.front()))); @@ -75,7 +75,7 @@ void testFilter::setUp() { if (l == end(currentFilter->skeys)) { bool isRegex = dd4hep::dd::isRegex(toks.front()); currentFilter->isRegex.emplace_back(isRegex); - currentFilter->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks.front())); + currentFilter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks.front())); if (isRegex) { currentFilter->index.emplace_back(currentFilter->keys.size()); currentFilter->keys.emplace_back(std::regex(std::begin(toks.front()), std::end(toks.front()))); @@ -88,7 +88,7 @@ void testFilter::setUp() { auto filter = std::make_unique(); bool isRegex = dd4hep::dd::isRegex(toks[pos]); filter->isRegex.emplace_back(isRegex); - filter->hasNamaspace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + filter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); if (isRegex) { filter->index.emplace_back(filters_.back()->keys.size()); filter->keys.emplace_back(std::regex(toks[pos].begin(), toks[pos].end())); diff --git a/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml b/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml index 521f45c29cc66..ade5ecbed2f23 100644 --- a/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml +++ b/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml @@ -1,7 +1,7 @@ - + From 129015272d61cdc509f8447204a847ef6c9e6e54 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Thu, 15 Oct 2020 19:43:38 +0200 Subject: [PATCH 05/16] use regex comparison if selection is a regex --- SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc b/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc index 41a8aff41385a..7bce4be3f7c2f 100644 --- a/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc +++ b/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc @@ -40,9 +40,10 @@ G4VPhysicalVolume *DDG4Builder::BuildGeometry(SensitiveDetectorCatalog &catalog) dd4hep::SpecParRefs specs; specPars.filter(specs, "SensitiveDetector"); for (auto const &it : map_) { + bool isRegex = dd4hep::dd::isRegex(it.first.name()); for (auto const &fit : specs) { for (auto const &pit : fit->paths) { - if (dd4hep::dd::compareEqual(dd4hep::dd::noNamespace(it.first.name()), dd4hep::dd::realTopName(pit))) { + if (dd4hep::dd::compareEqualName(dd4hep::dd::noNamespace(it.first.name()), dd4hep::dd::realTopName(pit))) { dd4hepVec.emplace_back(&*it.second, &*fit); } } From d4a5a55fc01ba6d32b44c22e979f0f3d9ff2d975 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Thu, 15 Oct 2020 19:49:04 +0200 Subject: [PATCH 06/16] remove unused variable --- SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc b/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc index 7bce4be3f7c2f..30b55e8dd0c38 100644 --- a/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc +++ b/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc @@ -40,7 +40,6 @@ G4VPhysicalVolume *DDG4Builder::BuildGeometry(SensitiveDetectorCatalog &catalog) dd4hep::SpecParRefs specs; specPars.filter(specs, "SensitiveDetector"); for (auto const &it : map_) { - bool isRegex = dd4hep::dd::isRegex(it.first.name()); for (auto const &fit : specs) { for (auto const &pit : fit->paths) { if (dd4hep::dd::compareEqualName(dd4hep::dd::noNamespace(it.first.name()), dd4hep::dd::realTopName(pit))) { From 6d1e1d07144568dfa375bf650901ce36fd4134f1 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Thu, 15 Oct 2020 20:18:51 +0200 Subject: [PATCH 07/16] update to new vesrion of dd4hep --- SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc | 4 ++-- SimG4Core/Geometry/src/DDG4ProductionCuts.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc b/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc index 30b55e8dd0c38..7bbb8bea2d645 100644 --- a/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc +++ b/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc @@ -41,9 +41,9 @@ G4VPhysicalVolume *DDG4Builder::BuildGeometry(SensitiveDetectorCatalog &catalog) specPars.filter(specs, "SensitiveDetector"); for (auto const &it : map_) { for (auto const &fit : specs) { - for (auto const &pit : fit->paths) { + for (auto const &pit : fit.second->paths) { if (dd4hep::dd::compareEqualName(dd4hep::dd::noNamespace(it.first.name()), dd4hep::dd::realTopName(pit))) { - dd4hepVec.emplace_back(&*it.second, &*fit); + dd4hepVec.emplace_back(&*it.second, &*fit.second); } } } diff --git a/SimG4Core/Geometry/src/DDG4ProductionCuts.cc b/SimG4Core/Geometry/src/DDG4ProductionCuts.cc index a50c3530b541a..23f66e0c14f67 100644 --- a/SimG4Core/Geometry/src/DDG4ProductionCuts.cc +++ b/SimG4Core/Geometry/src/DDG4ProductionCuts.cc @@ -113,9 +113,9 @@ void DDG4ProductionCuts::dd4hepInitialize() { for (auto const& it : *dd4hepMap_) { for (auto const& fit : specs) { - for (auto const& pit : fit->paths) { + for (auto const& pit : fit.second->paths) { if (dd4hep::dd::compareEqual(dd4hep::dd::noNamespace(it.first.name()), dd4hep::dd::realTopName(pit))) { - dd4hepVec_.emplace_back(std::make_pair(&*it.second, &*fit)); + dd4hepVec_.emplace_back(std::make_pair(&*it.second, &*fit.second)); } } } From 02c84a8a12d46ccaca176a1091b763eaef5c1bf7 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Thu, 15 Oct 2020 21:04:18 +0200 Subject: [PATCH 08/16] reverse comparison --- SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc b/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc index 7bbb8bea2d645..0ffb65513965f 100644 --- a/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc +++ b/SimG4Core/Geometry/src/DD4hep_DDG4Builder.cc @@ -42,7 +42,7 @@ G4VPhysicalVolume *DDG4Builder::BuildGeometry(SensitiveDetectorCatalog &catalog) for (auto const &it : map_) { for (auto const &fit : specs) { for (auto const &pit : fit.second->paths) { - if (dd4hep::dd::compareEqualName(dd4hep::dd::noNamespace(it.first.name()), dd4hep::dd::realTopName(pit))) { + if (dd4hep::dd::compareEqualName(dd4hep::dd::realTopName(pit), dd4hep::dd::noNamespace(it.first.name()))) { dd4hepVec.emplace_back(&*it.second, &*fit.second); } } From 724d9417cb7dde18a36524a4d6b95eab4b745c7b Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Sat, 10 Oct 2020 21:45:59 +0200 Subject: [PATCH 09/16] replace tbb containers with std ones --- DetectorDescription/DDCMS/interface/DDParsingContext.h | 2 +- DetectorDescription/DDCMS/src/DDNamespace.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DetectorDescription/DDCMS/interface/DDParsingContext.h b/DetectorDescription/DDCMS/interface/DDParsingContext.h index d885a9efe36cd..77cfab1c01749 100644 --- a/DetectorDescription/DDCMS/interface/DDParsingContext.h +++ b/DetectorDescription/DDCMS/interface/DDParsingContext.h @@ -12,7 +12,7 @@ namespace cms { class DDParsingContext { public: - DDParsingContext(dd4hep::Detector& det) : description(det) { + DDParsingContext(dd4hep::Detector* det) : description(det) { assemblies.reserve(100); rotations.reserve(3000); shapes.reserve(4000); diff --git a/DetectorDescription/DDCMS/src/DDNamespace.cc b/DetectorDescription/DDCMS/src/DDNamespace.cc index 4e5b453e7adfb..3c2ccf0736375 100644 --- a/DetectorDescription/DDCMS/src/DDNamespace.cc +++ b/DetectorDescription/DDCMS/src/DDNamespace.cc @@ -109,6 +109,7 @@ void DDNamespace::addConstantNS(const string& name, const string& val, const str type.c_str()); dd4hep::_toDictionary(n, v, type); dd4hep::Constant c(n, v, type); + m_context->description.addConstant(c); } From fe0ac3fbf4989c4cf3926eaf8ea1bee8e283cb10 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Mon, 12 Oct 2020 10:51:44 +0200 Subject: [PATCH 10/16] no need for atomic --- DetectorDescription/DDCMS/interface/DDParsingContext.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DetectorDescription/DDCMS/interface/DDParsingContext.h b/DetectorDescription/DDCMS/interface/DDParsingContext.h index 77cfab1c01749..d885a9efe36cd 100644 --- a/DetectorDescription/DDCMS/interface/DDParsingContext.h +++ b/DetectorDescription/DDCMS/interface/DDParsingContext.h @@ -12,7 +12,7 @@ namespace cms { class DDParsingContext { public: - DDParsingContext(dd4hep::Detector* det) : description(det) { + DDParsingContext(dd4hep::Detector& det) : description(det) { assemblies.reserve(100); rotations.reserve(3000); shapes.reserve(4000); From 6cd3fe5abaae5ab9d0676c843be34b8da50382dc Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Fri, 16 Oct 2020 10:42:22 +0200 Subject: [PATCH 11/16] final changes and cleanup --- .../interface/CocoaAnalyzer.h | 43 ---- .../CocoaApplication/src/CocoaAnalyzer.cc | 146 ++++++------ Alignment/CocoaApplication/src/SealModule.cc | 4 - .../DDCMS/interface/DDCompactView.h | 39 ++++ .../DDCMS/interface/DDSpecParRegistry.h | 1 + .../plugins/dd4hep/DDDefinitions2Objects.cc | 214 +++++++++--------- .../plugins/dd4hep/DD4hep_ListGroups.cc | 4 +- .../plugins/dd4hep/DD4hep_ListIds.cc | 2 +- .../dd4hep/DD4hep_MaterialAccountingGroup.cc | 2 +- 9 files changed, 216 insertions(+), 239 deletions(-) delete mode 100644 Alignment/CocoaApplication/interface/CocoaAnalyzer.h delete mode 100644 Alignment/CocoaApplication/src/SealModule.cc diff --git a/Alignment/CocoaApplication/interface/CocoaAnalyzer.h b/Alignment/CocoaApplication/interface/CocoaAnalyzer.h deleted file mode 100644 index 3438b652fa2cc..0000000000000 --- a/Alignment/CocoaApplication/interface/CocoaAnalyzer.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef ALIGNMENT_COCOA_APPLICATION_COCOA_ANALYZER_H -#define ALIGNMENT_COCOA_APPLICATION_COCOA_ANALYZER_H - -#include "FWCore/Framework/interface/one/EDAnalyzer.h" -#include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h" -#include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h" -#include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h" - -class CocoaAnalyzer : public edm::one::EDAnalyzer { -public: - explicit CocoaAnalyzer(edm::ParameterSet const& p); - explicit CocoaAnalyzer(int i) {} - ~CocoaAnalyzer() override {} - - void beginJob() override; - void analyze(const edm::Event& e, const edm::EventSetup& c) override; - -private: - void readXMLFile(const edm::EventSetup& evts); - - std::vector readCalibrationDB(const edm::EventSetup& evts); - void correctAllOpticalAlignments(std::vector& allDBOpticalAlignments); - void correctOpticalAlignmentParameter(OpticalAlignParam& myXMLParam, const OpticalAlignParam& myDBParam); - - void runCocoa(); - - template - std::vector getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, - const std::string& nodePath, - const std::string& parameterName); - template - T getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, - const std::string& nodePath, - const std::string& parameterName, - const unsigned int parameterValueIndex); - -private: - OpticalAlignments oaList_; - OpticalAlignMeasurements measList_; - std::string theCocoaDaqRootFileName_; -}; - -#endif diff --git a/Alignment/CocoaApplication/src/CocoaAnalyzer.cc b/Alignment/CocoaApplication/src/CocoaAnalyzer.cc index f9aab2322b4ce..466aefcfc9d9e 100644 --- a/Alignment/CocoaApplication/src/CocoaAnalyzer.cc +++ b/Alignment/CocoaApplication/src/CocoaAnalyzer.cc @@ -10,9 +10,9 @@ #include "FWCore/Framework/interface/ESTransientHandle.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" #include "Geometry/Records/interface/IdealGeometryRecord.h" -#include "Alignment/CocoaApplication/interface/CocoaAnalyzer.h" #include "Alignment/CocoaUtilities/interface/ALIUtils.h" #include "Alignment/CocoaModel/interface/Model.h" #include "Alignment/CocoaFit/interface/Fit.h" @@ -22,6 +22,34 @@ #include "Alignment/CocoaModel/interface/OpticalObject.h" #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h" #include "Alignment/CocoaFit/interface/CocoaDBMgr.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h" +#include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h" +#include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h" + +class CocoaAnalyzer : public edm::one::EDAnalyzer { +public: + explicit CocoaAnalyzer(edm::ParameterSet const& p); + explicit CocoaAnalyzer(int i) {} + ~CocoaAnalyzer() override {} + + void beginJob() override; + void analyze(const edm::Event& e, const edm::EventSetup& c) override; + +private: + void readXMLFile(const edm::EventSetup& evts); + + std::vector readCalibrationDB(const edm::EventSetup& evts); + void correctAllOpticalAlignments(std::vector& allDBOpticalAlignments); + void correctOpticalAlignmentParameter(OpticalAlignParam& myXMLParam, const OpticalAlignParam& myDBParam); + + void runCocoa(); + +private: + OpticalAlignments oaList_; + OpticalAlignMeasurements measList_; + std::string theCocoaDaqRootFileName_; +}; using namespace cms_units::operators; @@ -160,35 +188,35 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) { oaInfo.x_.name_ = "X"; oaInfo.x_.dim_type_ = "centre"; oaInfo.x_.value_ = transl.x() / (1._m); // COCOA units are m - oaInfo.x_.error_ = getParameterValueFromSpecParSections(allSpecParSections, - nodePath, - "centre_X_sigma", - 0) / + oaInfo.x_.error_ = cms::getParameterValueFromSpecParSections(allSpecParSections, + nodePath, + "centre_X_sigma", + 0) / (1._m); // COCOA units are m oaInfo.x_.quality_ = static_cast( - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "centre_X_quality", 0)); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "centre_X_quality", 0)); // Y oaInfo.y_.name_ = "Y"; oaInfo.y_.dim_type_ = "centre"; oaInfo.y_.value_ = transl.y() / (1._m); // COCOA units are m - oaInfo.y_.error_ = getParameterValueFromSpecParSections(allSpecParSections, - nodePath, - "centre_Y_sigma", - 0) / + oaInfo.y_.error_ = cms::getParameterValueFromSpecParSections(allSpecParSections, + nodePath, + "centre_Y_sigma", + 0) / (1._m); // COCOA units are m oaInfo.y_.quality_ = static_cast( - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "centre_Y_quality", 0)); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "centre_Y_quality", 0)); // Z oaInfo.z_.name_ = "Z"; oaInfo.z_.dim_type_ = "centre"; oaInfo.z_.value_ = transl.z() / (1._m); // COCOA units are m - oaInfo.z_.error_ = getParameterValueFromSpecParSections(allSpecParSections, - nodePath, - "centre_Z_sigma", - 0) / + oaInfo.z_.error_ = cms::getParameterValueFromSpecParSections(allSpecParSections, + nodePath, + "centre_Z_sigma", + 0) / (1._m); // COCOA units are m oaInfo.z_.quality_ = static_cast( - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "centre_Z_quality", 0)); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "centre_Z_quality", 0)); // ROTATIONS @@ -234,34 +262,35 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) { oaInfo.angx_.name_ = "X"; oaInfo.angx_.dim_type_ = "angles"; oaInfo.angx_.value_ = - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_value", 0); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_value", 0); oaInfo.angx_.error_ = - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_sigma", 0); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_sigma", 0); oaInfo.angx_.quality_ = static_cast( - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_quality", 0)); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_quality", 0)); // Y oaInfo.angy_.name_ = "Y"; oaInfo.angy_.dim_type_ = "angles"; oaInfo.angy_.value_ = - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_value", 0); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_value", 0); oaInfo.angy_.error_ = - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_sigma", 0); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_sigma", 0); oaInfo.angy_.quality_ = static_cast( - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_quality", 0)); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_quality", 0)); // Z oaInfo.angz_.name_ = "Z"; oaInfo.angz_.dim_type_ = "angles"; oaInfo.angz_.value_ = - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_value", 0); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_value", 0); oaInfo.angz_.error_ = - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_sigma", 0); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_sigma", 0); oaInfo.angz_.quality_ = static_cast( - getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_quality", 0)); + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_quality", 0)); - oaInfo.type_ = getParameterValueFromSpecParSections(allSpecParSections, nodePath, "cocoa_type", 0); + oaInfo.type_ = + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "cocoa_type", 0); - oaInfo.ID_ = - static_cast(getParameterValueFromSpecParSections(allSpecParSections, nodePath, "cmssw_ID", 0)); + oaInfo.ID_ = static_cast( + cms::getParameterValueFromSpecParSections(allSpecParSections, nodePath, "cmssw_ID", 0)); if (ALIUtils::debug >= 4) { edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML OBJECT " << oaInfo.name_ << " pos/angles read "; @@ -279,15 +308,15 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) { // EXTRA PARAM ENTRIES (FROM XMLS) // Here initial code to define the containers was fully removed, this is much more compact. const std::vector& names = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "extra_entry"); + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "extra_entry"); const std::vector& dims = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "dimType"); + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "dimType"); const std::vector& values = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "value"); + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "value"); const std::vector& errors = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "sigma"); + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "sigma"); const std::vector& quality = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "quality"); + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "quality"); if (ALIUtils::debug >= 4) { edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters "; @@ -320,9 +349,9 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) { // MEASUREMENTS (FROM XMLS) const std::vector& measNames = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_name"); + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_name"); const std::vector& measTypes = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_type"); + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_type"); std::map> measObjectNames; std::map> measParamNames; @@ -330,15 +359,15 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) { std::map> measParamSigmas; std::map> measIsSimulatedValue; for (const auto& name : measNames) { - measObjectNames[name] = getAllParameterValuesFromSpecParSections( + measObjectNames[name] = cms::getAllParameterValuesFromSpecParSections( allSpecParSections, nodePath, "meas_object_name_" + name); - measParamNames[name] = getAllParameterValuesFromSpecParSections( + measParamNames[name] = cms::getAllParameterValuesFromSpecParSections( allSpecParSections, nodePath, "meas_value_name_" + name); measParamValues[name] = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_value_" + name); + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_value_" + name); measParamSigmas[name] = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_sigma_" + name); - measIsSimulatedValue[name] = getAllParameterValuesFromSpecParSections( + cms::getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_sigma_" + name); + measIsSimulatedValue[name] = cms::getAllParameterValuesFromSpecParSections( allSpecParSections, nodePath, "meas_is_simulated_value_" + name); } @@ -568,39 +597,4 @@ void CocoaAnalyzer::runCocoa() { } } -/* Helper: For a given node, get the values associated to a given parameter, from the XMLs SpecPar sections. - * NB: The same parameter can appear several times WITHIN the same SpecPar section (hence, we have a std::vector). - * WARNING: This stops at the first relevant SpecPar section encountered. - * Hence, if A GIVEN NODE HAS SEVERAL SPECPAR XML SECTIONS RE-DEFINING THE SAME PARAMETER, - * only the first XML SpecPar block will be considered. - */ -template -std::vector CocoaAnalyzer::getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, - const std::string& nodePath, - const std::string& parameterName) { - cms::DDSpecParRefs filteredSpecParSections; - allSpecParSections.filter(filteredSpecParSections, parameterName); - for (const auto& mySpecParSection : filteredSpecParSections) { - if (mySpecParSection->hasPath(nodePath)) { - return mySpecParSection->value>(parameterName); - } - } - - return std::vector(); -} - -/* Helper: For a given node, get the value associated to a given parameter, from the XMLs SpecPar sections. - * This is the parameterValueIndex-th value (within a XML SpecPar block.) of the desired parameter. - */ -template -T CocoaAnalyzer::getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, - const std::string& nodePath, - const std::string& parameterName, - const unsigned int parameterValueIndex) { - const std::vector& allParameterValues = - getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, parameterName); - if (parameterValueIndex < allParameterValues.size()) { - return allParameterValues.at(parameterValueIndex); - } - return T(); -} +DEFINE_FWK_MODULE(CocoaAnalyzer); diff --git a/Alignment/CocoaApplication/src/SealModule.cc b/Alignment/CocoaApplication/src/SealModule.cc deleted file mode 100644 index 6fabe6d7c6341..0000000000000 --- a/Alignment/CocoaApplication/src/SealModule.cc +++ /dev/null @@ -1,4 +0,0 @@ -#include "FWCore/Framework/interface/MakerMacros.h" -#include "Alignment/CocoaApplication/interface/CocoaAnalyzer.h" - -DEFINE_FWK_MODULE(CocoaAnalyzer); diff --git a/DetectorDescription/DDCMS/interface/DDCompactView.h b/DetectorDescription/DDCMS/interface/DDCompactView.h index 1c19a9a0f58b4..652ed53385025 100644 --- a/DetectorDescription/DDCMS/interface/DDCompactView.h +++ b/DetectorDescription/DDCMS/interface/DDCompactView.h @@ -26,6 +26,7 @@ namespace cms { using DDSpecParRegistry = dd4hep::SpecParRegistry; + using DDSpecParRefs = dd4hep::SpecParRefs; class DDCompactView { public: @@ -43,6 +44,44 @@ namespace cms { private: const cms::DDDetector& m_det; }; + + /* Helper: For a given node, get the values associated to a given parameter, from the XMLs SpecPar sections. + * NB: The same parameter can appear several times WITHIN the same SpecPar section (hence, we have a std::vector). + * WARNING: This stops at the first relevant SpecPar section encountered. + * Hence, if A GIVEN NODE HAS SEVERAL SPECPAR XML SECTIONS RE-DEFINING THE SAME PARAMETER, + * only the first XML SpecPar block will be considered. + */ + template + std::vector getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, + const std::string& nodePath, + const std::string& parameterName) { + cms::DDSpecParRefs filteredSpecParSections; + allSpecParSections.filter(filteredSpecParSections, parameterName); + for (const auto& mySpecParSection : filteredSpecParSections) { + if (mySpecParSection.second->hasPath(nodePath)) { + return mySpecParSection.second->value>(parameterName); + } + } + + return std::vector(); + } + + /* Helper: For a given node, get the value associated to a given parameter, from the XMLs SpecPar sections. + * This is the parameterValueIndex-th value (within a XML SpecPar block.) of the desired parameter. + */ + template + T getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, + const std::string& nodePath, + const std::string& parameterName, + const unsigned int parameterValueIndex) { + const std::vector& allParameterValues = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, parameterName); + if (parameterValueIndex < allParameterValues.size()) { + return allParameterValues.at(parameterValueIndex); + } + return T(); + } + } // namespace cms #endif diff --git a/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h b/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h index 8c03a5fd3a5f6..297e00a29d89f 100644 --- a/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h +++ b/DetectorDescription/DDCMS/interface/DDSpecParRegistry.h @@ -7,6 +7,7 @@ namespace cms { using DDSpecParRegistry = dd4hep::SpecParRegistry; using DDSpecPar = dd4hep::SpecPar; + using DDSpecParRefs = dd4hep::SpecParRefs; } // namespace cms diff --git a/DetectorDescription/DDCMS/plugins/dd4hep/DDDefinitions2Objects.cc b/DetectorDescription/DDCMS/plugins/dd4hep/DDDefinitions2Objects.cc index e1a4ad5b43c2c..576b4e8353f23 100644 --- a/DetectorDescription/DDCMS/plugins/dd4hep/DDDefinitions2Objects.cc +++ b/DetectorDescription/DDCMS/plugins/dd4hep/DDDefinitions2Objects.cc @@ -417,7 +417,6 @@ void Converter::operator()(xml_h element) const { ns.addConstant(nam, val, typ); res->originalConst[real] = val; } catch (const exception& e) { - #ifdef EDM_ML_DEBUG printout(INFO, @@ -428,7 +427,6 @@ void Converter::operator()(xml_h element) const { typ.c_str(), e.what()); #endif - } return; } @@ -504,7 +502,7 @@ void Converter::operator()(xml_h element) const { mix->GetDensity()); #endif - + bool newMatDef = false; if (elt) { @@ -525,7 +523,7 @@ void Converter::operator()(xml_h element) const { atomicWeight, atomicNumber); #endif - + static constexpr double const weightTolerance = 1.0e-6; if (atomicNumber != elt->Z() || (std::abs(atomicWeight - elt->A()) > (weightTolerance * (atomicWeight + elt->A())))) @@ -534,9 +532,8 @@ void Converter::operator()(xml_h element) const { if (!elt || newMatDef) { if (newMatDef) { +#ifdef EDM_ML_DEBUG -#ifdef EDM_ML_DEBUG - printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS Warning", "+++ Converter Different definition of a default element with name:%s [CREATE NEW " @@ -544,11 +541,10 @@ void Converter::operator()(xml_h element) const { matname); #endif - + } else { - #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS Warning", "+++ Converter No default element present with name:%s [CREATE NEW MATERIAL]", @@ -587,8 +583,8 @@ void Converter::operator()(xml_h element) const { xml_coll_t composites(xmat, DD_CMU(MaterialFraction)); TGeoMixture* mix = new TGeoMixture(nam.c_str(), composites.size(), density); -#ifdef EDM_ML_DEBUG - +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS", "++ Converting material %-48s Density: %8.3f [g/cm3] ROOT: %8.3f [g/cm3]", @@ -597,7 +593,7 @@ void Converter::operator()(xml_h element) const { mix->GetDensity()); #endif - + for (composites.reset(); composites; ++composites) { xml_dim_t xfrac(composites); xml_dim_t xfrac_mat(xfrac.child(DD_CMU(rMaterial))); @@ -612,8 +608,8 @@ void Converter::operator()(xml_h element) const { continue; } -#ifdef EDM_ML_DEBUG - +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_materials ? ALWAYS : DEBUG, "DD4CMS Warning", "+++ Composite material \"%s\" [nor \"%s\"] not present! [delay resolution]", @@ -621,7 +617,7 @@ void Converter::operator()(xml_h element) const { ns.prepend(fracname).c_str()); #endif - + ns.context()->unresolvedMaterials[nam].emplace_back( cms::DDParsingContext::CompositeMaterial(ns.prepend(fracname), fraction)); } @@ -653,7 +649,7 @@ void Converter::operator()(xml_h element) const { Rotation3D rot = makeRotation3D(thetaX, phiX, thetaY, phiY, thetaZ, phiZ); #ifdef EDM_ML_DEBUG - + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+++ Adding rotation: %-32s: (theta/phi)[rad] X: %6.3f %6.3f Y: %6.3f %6.3f Z: %6.3f %6.3f", @@ -666,7 +662,7 @@ void Converter::operator()(xml_h element) const { phiZ); #endif - + ns.addRotation(nam, rot); } @@ -685,7 +681,7 @@ void Converter::operator()(xml_h element) const { double phiZ = xrot.hasAttr(DD_CMU(phiZ)) ? ns.attr(xrot, DD_CMU(phiZ)) : 0e0; #ifdef EDM_ML_DEBUG - + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+++ Adding reflection rotation: %-32s: (theta/phi)[rad] X: %6.3f %6.3f Y: %6.3f %6.3f Z: %6.3f %6.3f", @@ -697,8 +693,8 @@ void Converter::operator()(xml_h element) const { thetaZ, phiZ); -#endif - +#endif + Rotation3D rot = makeRotReflect(thetaX, phiX, thetaY, phiY, thetaZ, phiZ); ns.addRotation(name, rot); } @@ -718,7 +714,7 @@ void Converter::operator()(xml_h element) const { rot = makeRotation3D(rot, axis, angle); #ifdef EDM_ML_DEBUG - + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+ Adding rotation to: %-29s: (axis/angle)[rad] Axis: %s Angle: %6.3f", @@ -727,7 +723,6 @@ void Converter::operator()(xml_h element) const { angle); #endif - } double xx, xy, xz; double yx, yy, yz; @@ -735,7 +730,7 @@ void Converter::operator()(xml_h element) const { rot.GetComponents(xx, xy, xz, yx, yy, yz, zx, zy, zz); #ifdef EDM_ML_DEBUG - + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+++ Adding rotation sequence: %-23s: %6.3f %6.3f %6.3f, %6.3f %6.3f %6.3f, %6.3f %6.3f %6.3f", @@ -750,8 +745,8 @@ void Converter::operator()(xml_h element) const { zy, zz); -#endif - +#endif + ns.addRotation(nam, rot); } @@ -770,7 +765,7 @@ void Converter::operator()(xml_h element) const { rot = makeRotation3D(rot, axis, angle); #ifdef EDM_ML_DEBUG - + printout(context->debug_rotations ? ALWAYS : DEBUG, "DD4CMS", "+++ Adding rotation: %-32s: (axis/angle)[rad] Axis: %s Angle: %6.3f", @@ -779,7 +774,7 @@ void Converter::operator()(xml_h element) const { angle); #endif - + ns.addRotation(nam, rot); } } @@ -798,11 +793,11 @@ void Converter::operator()(xml_h element) const { #ifdef EDM_ML_DEBUG Volume volume = #endif - - ns.addVolume(Volume(volName, solid, material)); + + ns.addVolume(Volume(volName, solid, material)); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_volumes ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Volume: %-24s [%s] Shape: %-32s [%s] Material: %-40s [%s]", @@ -814,7 +809,7 @@ void Converter::operator()(xml_h element) const { mat.c_str(), material.isValid() ? "VALID" : "INVALID"); -#endif +#endif } /// Helper converter @@ -863,7 +858,7 @@ void Converter::operator()(xml_h element) const { Volume child = ns.volume(childName, false); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Parent: %-24s [%s] Child: %-32s [%s] copy:%d", @@ -875,7 +870,7 @@ void Converter::operator()(xml_h element) const { copy); #endif - + if (!parent.isValid() && strchr(parentName.c_str(), NAMESPACE_SEP) == nullptr) parentName = ns.prepend(parentName); parent = ns.volume(parentName); @@ -885,7 +880,7 @@ void Converter::operator()(xml_h element) const { child = ns.volume(childName, false); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Parent: %-24s [%s] Child: %-32s [%s] copy:%d", @@ -896,8 +891,8 @@ void Converter::operator()(xml_h element) const { child.isValid() ? "VALID" : "INVALID", copy); -#endif - +#endif + PlacedVolume pv; if (child.isValid()) { Transform3D transform; @@ -962,16 +957,16 @@ void Converter::operator()(xml_h element) const { string specParName = specPar.attr(_U(name)); string path = e.attr(DD_CMU(path)); -#ifdef EDM_ML_DEBUG - +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_specpars ? ALWAYS : DEBUG, "DD4CMS", "+++ PartSelector for %s path: %s", specParName.c_str(), path.c_str()); -#endif - +#endif + size_t pos = std::string::npos; if ((pos = path.find("//.*:")) != std::string::npos) { path.erase(pos + 2, 3); @@ -996,7 +991,7 @@ void Converter::operator()(xml_h element) const { string type = eval ? "number" : "string"; #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_specpars ? ALWAYS : DEBUG, "DD4CMS", "+++ Parameter for %s: %s value %s is a %s", @@ -1005,7 +1000,7 @@ void Converter::operator()(xml_h element) const { value.c_str(), type.c_str()); -#endif +#endif size_t idx = value.find('['); if (idx == string::npos || type == "string") { @@ -1065,8 +1060,8 @@ static void convert_boolean(cms::DDParsingContext* context, xml_h element) { except("DD4CMS", "+++ Failed to create boolean solid %s. Found only %d parts.", nam.c_str(), cnt); } -#ifdef EDM_ML_DEBUG - +#ifdef EDM_ML_DEBUG + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ BooleanSolid: %s Left: %-32s Right: %-32s", @@ -1075,7 +1070,7 @@ static void convert_boolean(cms::DDParsingContext* context, xml_h element) { ((solids[1].ptr() == nullptr) ? solidName[1].c_str() : solids[1]->GetName())); #endif - + if (solids[0].isValid() && solids[1].isValid()) { Transform3D trafo; Converter(context->description, context, &trafo)(element); @@ -1134,7 +1129,7 @@ void Converter::operator()(xml_h element) const { } #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Polycone: startPhi=%10.3f [rad] deltaPhi=%10.3f [rad] %4ld z-planes", @@ -1142,13 +1137,12 @@ void Converter::operator()(xml_h element) const { deltaPhi, z.size()); -#endif - +#endif + ns.addSolid(nam, Polycone(startPhi, deltaPhi, rmin, rmax, z)); } else { - #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Polycone: startPhi=%10.3f [rad] deltaPhi=%10.3f [rad] %4ld z-planes and %4ld radii", @@ -1158,7 +1152,7 @@ void Converter::operator()(xml_h element) const { r.size()); #endif - + ns.addSolid(nam, Polycone(startPhi, deltaPhi, r, z)); } } @@ -1183,15 +1177,15 @@ void Converter::operator()(xml_h element) const { } #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ ExtrudedPolygon: %4ld points %4ld zxy sections", pt_x.size(), sec_z.size()); -#endif - +#endif + ns.addSolid(nam, ExtrudedPolygon(pt_x, pt_y, sec_z, sec_x, sec_y, sec_scale)); } @@ -1218,7 +1212,7 @@ void Converter::operator()(xml_h element) const { } #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Polyhedra:startPhi=%8.3f [rad] deltaPhi=%8.3f [rad] %4d sides %4ld z-planes", @@ -1228,7 +1222,7 @@ void Converter::operator()(xml_h element) const { z.size()); #endif - + ns.addSolid(nam, Polyhedra(numSide, startPhi, deltaPhi, z, rmin, rmax)); } @@ -1246,7 +1240,7 @@ void Converter::operator()(xml_h element) const { double deltaTheta = ns.attr(e, DD_CMU(deltaTheta)); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Sphere: r_inner=%8.3f [cm] r_outer=%8.3f [cm]" @@ -1259,7 +1253,7 @@ void Converter::operator()(xml_h element) const { deltaTheta); #endif - + ns.addSolid(nam, Sphere(rinner, router, startTheta, deltaTheta, startPhi, deltaPhi)); } @@ -1276,7 +1270,7 @@ void Converter::operator()(xml_h element) const { double deltaPhi = ns.attr(e, DD_CMU(deltaPhi)); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Torus: r=%10.3f [cm] r_inner=%10.3f [cm] r_outer=%10.3f [cm]" @@ -1288,7 +1282,7 @@ void Converter::operator()(xml_h element) const { deltaPhi); #endif - + ns.addSolid(nam, Torus(r, rinner, router, startPhi, deltaPhi)); } @@ -1307,7 +1301,7 @@ void Converter::operator()(xml_h element) const { bool atMinusZ = ns.attr(e, DD_CMU(atMinusZ)); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Pseudotrap: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2=%.3f dy2=%.3f radius:%.3f atMinusZ:%s", @@ -1320,7 +1314,7 @@ void Converter::operator()(xml_h element) const { yes_no(atMinusZ)); #endif - + ns.addSolid(nam, PseudoTrap(dx1, dx2, dy1, dy2, dz, r, atMinusZ)); } @@ -1343,7 +1337,7 @@ void Converter::operator()(xml_h element) const { double theta = ns.attr(e, _U(theta), 0.0); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Trapezoid: dz=%10.3f [cm] alp1:%.3f bl1=%.3f tl1=%.3f alp2=%.3f bl2=%.3f tl2=%.3f h2=%.3f phi=%.3f " @@ -1361,7 +1355,7 @@ void Converter::operator()(xml_h element) const { theta); #endif - + ns.addSolid(nam, Trap(dz, theta, phi, h1, bl1, tl1, alp1, h2, bl2, tl2, alp2)); } @@ -1377,9 +1371,8 @@ void Converter::operator()(xml_h element) const { double dy2 = ns.attr(e, DD_CMU(dy2), dy1); double dz = ns.attr(e, DD_CMU(dz)); if (dy1 == dy2) { - #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Trd1: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2:%.3f dy2:%.3f", @@ -1390,12 +1383,11 @@ void Converter::operator()(xml_h element) const { dy2); #endif - + ns.addSolid(nam, Trd1(dx1, dx2, dy1, dz)); } else { - #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Trd1(which is actually Trd2): dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2:%.3f dy2:%.3f", @@ -1406,7 +1398,7 @@ void Converter::operator()(xml_h element) const { dy2); #endif - + ns.addSolid(nam, Trd2(dx1, dx2, dy1, dy2, dz)); } } @@ -1424,7 +1416,7 @@ void Converter::operator()(xml_h element) const { double dz = ns.attr(e, DD_CMU(dz)); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Trd1: dz=%8.3f [cm] dx1:%.3f dy1:%.3f dx2:%.3f dy2:%.3f", @@ -1435,7 +1427,7 @@ void Converter::operator()(xml_h element) const { dy2); #endif - + ns.addSolid(nam, Trd2(dx1, dx2, dy1, dy2, dz)); } @@ -1452,7 +1444,7 @@ void Converter::operator()(xml_h element) const { double deltaPhi = ns.attr(e, DD_CMU(deltaPhi), 2 * M_PI); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Tubs: dz=%8.3f [cm] rmin=%8.3f [cm] rmax=%8.3f [cm]" @@ -1464,7 +1456,7 @@ void Converter::operator()(xml_h element) const { deltaPhi); #endif - + ns.addSolid(nam, Tube(rmin, rmax, dz, startPhi, startPhi + deltaPhi)); } @@ -1499,7 +1491,7 @@ void Converter::operator()(xml_h element) const { deltaPhi); #endif - + ns.addSolid(nam, CutTube(rmin, rmax, dz, startPhi, startPhi + deltaPhi, lx, ly, lz, tx, ty, tz)); } @@ -1533,8 +1525,8 @@ void Converter::operator()(xml_h element) const { cutAtDelta, yes_no(cutInside)); - #endif - +#endif + ns.addSolid(nam, TruncatedTube(zhalf, rmin, rmax, startPhi, deltaPhi, cutAtStart, cutAtDelta, cutInside)); } @@ -1558,7 +1550,7 @@ void Converter::operator()(xml_h element) const { dz); #endif - + ns.addSolid(nam, EllipticalTube(dx, dy, dz)); } @@ -1594,7 +1586,7 @@ void Converter::operator()(xml_h element) const { deltaPhi); #endif - + ns.addSolid(nam, ConeSegment(dz, rmin1, rmax1, rmin2, rmax2, startPhi, phi2)); } @@ -1613,7 +1605,7 @@ void Converter::operator()(xml_h element) const { nam.c_str()); #endif - + ns.addSolid(nam, Box(1, 1, 1)); } @@ -1628,7 +1620,7 @@ void Converter::operator()(xml_h element) const { double dz = ns.attr(e, DD_CMU(dz)); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_shapes ? ALWAYS : DEBUG, "DD4CMS", "+ Box: dx=%10.3f [cm] dy=%10.3f [cm] dz=%10.3f [cm]", @@ -1637,7 +1629,7 @@ void Converter::operator()(xml_h element) const { dz); #endif - + ns.addSolid(nam, Box(dx, dy, dz)); } @@ -1656,8 +1648,8 @@ void Converter::operator()(xml_h element) const { "+++ Processing the CMS detector description %s", fname.c_str()); -#endif - +#endif + _option()->includes.emplace_back(doc); } @@ -1668,12 +1660,12 @@ void Converter::operator()(xml_h element) const { xml::DocumentHolder(xml_elt_t(element).document()).assign(nullptr); #ifdef EDM_ML_DEBUG - + printout(_param()->debug_includes ? ALWAYS : DEBUG, "DD4CMS", "+++ Finished processing %s", fname.c_str()); -#endif +#endif } /// DD4hep specific Converter for tags: process only the constants @@ -1720,7 +1712,7 @@ void Converter::operator()(xml_h element) const { int nReplicas = e.hasAttr(DD_CMU(nReplicas)) ? ns.attr(e, DD_CMU(nReplicas)) : 0; #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ Start executing Division of %s along %s (%d) with offset %6.3f and %6.3f to produce %s....", @@ -1732,7 +1724,7 @@ void Converter::operator()(xml_h element) const { childName.c_str()); #endif - + Volume parent = ns.volume(parentName); const TGeoShape* shape = parent.solid(); @@ -1744,7 +1736,7 @@ void Converter::operator()(xml_h element) const { int numCopies = (int)((sh->GetPhi2() - sh->GetPhi1()) / widthInDeg); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ ...divide %s along %s (%d) with offset %6.3f deg and %6.3f deg to produce %d copies", @@ -1756,13 +1748,13 @@ void Converter::operator()(xml_h element) const { numCopies); #endif - + Volume child = parent.divide(childName, static_cast(axesmap.at(axis)), numCopies, startInDeg, widthInDeg); ns.context()->volumes[childName] = child; #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Parent: %-24s [%s] Child: %-32s [%s] is multivolume [%s]", @@ -1773,7 +1765,7 @@ void Converter::operator()(xml_h element) const { child.isValid() ? "VALID" : "INVALID", child->IsVolumeMulti() ? "YES" : "NO"); #endif - + } else if (cl == TGeoTrd1::Class()) { double dy = static_cast(shape)->GetDy(); @@ -1791,13 +1783,13 @@ void Converter::operator()(xml_h element) const { dy); #endif - + Volume child = parent.divide(childName, static_cast(axesmap.at(axis)), nReplicas, -dy + offset + width, width); ns.context()->volumes[childName] = child; #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_placements ? ALWAYS : DEBUG, "DD4CMS", "+++ %s Parent: %-24s [%s] Child: %-32s [%s] is multivolume [%s]", @@ -1809,7 +1801,7 @@ void Converter::operator()(xml_h element) const { child->IsVolumeMulti() ? "YES" : "NO"); #endif - + } else { printout(ERROR, "DD4CMS", "++ FAILED Division of a %s is not implemented yet!", parent.solid().type()); } @@ -1827,25 +1819,24 @@ void Converter::operator()(xml_h element) const { type[idx] = '_'; #ifdef EDM_ML_DEBUG - + printout( ns.context()->debug_algorithms ? ALWAYS : DEBUG, "DD4CMS", "+++ Start executing algorithm %s....", type.c_str()); -#endif +#endif long ret = PluginService::Create(type, &description, ns.context(), &element); if (ret == s_executed) { - #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_algorithms ? ALWAYS : DEBUG, - "DD4CMS", + "DD4CMS", "+++ Executed algorithm: %08lX = %s", ret, name.c_str()); -#endif +#endif return; } printout(ERROR, "DD4CMS", "++ FAILED NOT ADDING SUBDETECTOR %08lX = %s", ret, name.c_str()); @@ -1910,7 +1901,7 @@ void Converter::operator()(xml_h element) const { val.erase(remove_if(val.begin(), val.end(), [](unsigned char x) { return isspace(x); }), val.end()); #ifdef EDM_ML_DEBUG - + printout(ns.context()->debug_constants ? ALWAYS : DEBUG, "DD4CMS", "+++ Vector<%s>: %s[%s]: %s", @@ -1920,16 +1911,15 @@ void Converter::operator()(xml_h element) const { val.c_str()); #endif - + try { std::vector results = splitNumeric(val); registry->insert( {name, results}); //tbb::concurrent_vector>(results.begin(), results.end())}); } catch (const exception& e) { - #ifdef EDM_ML_DEBUG - + printout(INFO, "DD4CMS", "++ Unresolved Vector<%s>: %s[%s]: %s. Try to resolve later. [%s]", @@ -1940,7 +1930,7 @@ void Converter::operator()(xml_h element) const { e.what()); #endif - + std::vector results = splitString(val); context->unresolvedVectors.insert({name, results}); } @@ -1979,14 +1969,14 @@ void Converter::operator()(xml_h /* element */) const { int count = 0; #ifdef EDM_ML_DEBUG - + printout(context->debug_constants ? ALWAYS : DEBUG, "DD4CMS", "+++ RESOLVING %ld unknown constants..... (out of %ld)", res->unresolvedConst.size(), res->originalConst.size()); #endif - + while (!res->unresolvedConst.empty()) { for (auto& i : res->unresolvedConst) { const string& n = i.first; @@ -2009,10 +1999,10 @@ void Converter::operator()(xml_h /* element */) const { while ((idx = v.find("+-")) != string::npos) v.replace(idx, 2, "-"); } - + #ifdef EDM_ML_DEBUG - printout(context->debug_constants ? ALWAYS : DEBUG, + printout(context->debug_constants ? ALWAYS : DEBUG, "DD4CMS", "+++ [%06ld] ---------- %-40s = %s", res->unresolvedConst.size() - 1, @@ -2020,7 +2010,7 @@ void Converter::operator()(xml_h /* element */) const { res->originalConst[n].c_str()); #endif - + ns.addConstantNS(n, v, "number"); res->unresolvedConst.erase(n); break; @@ -2043,7 +2033,7 @@ void Converter::operator()(xml_h element) const { string fname = xml::DocumentHandler::system_path(element); #ifdef EDM_ML_DEBUG - + printout(_param()->debug_includes ? ALWAYS : DEBUG, "DD4CMS", "+++ Processing data from: %s", diff --git a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc index 306e61d48c51b..c6fe2206a9f38 100644 --- a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc +++ b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc @@ -367,7 +367,7 @@ void DD4hep_ListGroups::analyze(const edm::Event &evt, const edm::EventSetup &se cms::DDFilteredView fv(*cpv, filter); for (const auto &t : fv.specpars()) { - m_group_names.insert(t->strValue("TrackingMaterialGroup")); + m_group_names.insert(t.second->strValue("TrackingMaterialGroup")); } for (const auto &i : m_group_names) { @@ -376,7 +376,7 @@ void DD4hep_ListGroups::analyze(const edm::Event &evt, const edm::EventSetup &se bool firstChild = fv1.firstChild(); for (const auto j : fv1.specpars()) { - for (const auto &k : j->paths) { + for (const auto &k : j.second->paths) { if (firstChild) { std::vector> children = fv1.children(k); for (auto const &path : children) { diff --git a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListIds.cc b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListIds.cc index b5a29926e1086..d829b23665cc3 100644 --- a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListIds.cc +++ b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListIds.cc @@ -51,7 +51,7 @@ void DD4hep_ListIds::analyze(const edm::Event &evt, const edm::EventSetup &setup std::set tkdss; for (const auto &t : fv.specpars()) { - tkdss.insert(t->strValue(attribute)); + tkdss.insert(t.second->strValue(attribute)); } for (const auto &i : tkdss) { diff --git a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc index 8dc741b90338b..a2230fbe84b23 100644 --- a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc +++ b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc @@ -35,7 +35,7 @@ DD4hep_MaterialAccountingGroup::DD4hep_MaterialAccountingGroup(const std::string edm::LogVerbatim("TrackingMaterialAnalysis") << "Elements within: " << name; for (const auto j : fv.specpars()) { - for (const auto& k : j->paths) { + for (const auto& k : j.second->paths) { if (firstChild) { std::vector> children = fv.children(k); for (auto const& path : children) { From 58a5d0df77d81091639c7dceb83125abbd18856a Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Fri, 16 Oct 2020 11:20:52 +0200 Subject: [PATCH 12/16] clang tidy --- .../TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc | 2 +- .../plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc index c6fe2206a9f38..d8335b2fb5f2a 100644 --- a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc +++ b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc @@ -375,7 +375,7 @@ void DD4hep_ListGroups::analyze(const edm::Event &evt, const edm::EventSetup &se cms::DDFilteredView fv1(*cpv, filter1); bool firstChild = fv1.firstChild(); - for (const auto j : fv1.specpars()) { + for (const auto& j : fv1.specpars()) { for (const auto &k : j.second->paths) { if (firstChild) { std::vector> children = fv1.children(k); diff --git a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc index a2230fbe84b23..896eac59774e5 100644 --- a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc +++ b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_MaterialAccountingGroup.cc @@ -34,7 +34,7 @@ DD4hep_MaterialAccountingGroup::DD4hep_MaterialAccountingGroup(const std::string edm::LogVerbatim("TrackingMaterialAnalysis") << "Elements within: " << name; - for (const auto j : fv.specpars()) { + for (const auto& j : fv.specpars()) { for (const auto& k : j.second->paths) { if (firstChild) { std::vector> children = fv.children(k); From 784badbcfcea1c84bb9264860400737a2c066ac9 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Mon, 19 Oct 2020 15:57:52 +0200 Subject: [PATCH 13/16] one more fix and code format --- SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc | 6 +++--- .../plugins/dd4hep/DD4hep_ListGroups.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc b/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc index 4a8faa9e74551..3ab1eeaf56d4a 100644 --- a/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc +++ b/SimG4Core/DD4hepGeometry/test/plugins/DD4hepTestDDDWorld.cc @@ -106,14 +106,14 @@ void DD4hepTestDDDWorld::initialize(const dd4hep::sim::Geant4GeometryMaps::Volum LogVerbatim("Geometry").log([&](auto& log) { for (auto const& it : vmap) { for (auto const& fit : specs_) { - for (auto const& sit : fit->spars) { + for (auto const& sit : fit.second->spars) { log << sit.first << " = " << sit.second[0] << "\n"; } - for (auto const& pit : fit->paths) { + for (auto const& pit : fit.second->paths) { log << dd4hep::dd::realTopName(pit) << "\n"; log << " compare equal to " << dd4hep::dd::noNamespace(it.first.name()) << " ... "; if (dd4hep::dd::compareEqual(dd4hep::dd::noNamespace(it.first.name()), dd4hep::dd::realTopName(pit))) { - vec_.emplace_back(std::make_pair(&*it.second, &*fit)); + vec_.emplace_back(std::make_pair(&*it.second, &*fit.second)); log << " are equal!\n"; } else log << " nope.\n"; diff --git a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc index d8335b2fb5f2a..35335a64c2b7b 100644 --- a/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc +++ b/SimTracker/TrackerMaterialAnalysis/plugins/dd4hep/DD4hep_ListGroups.cc @@ -375,7 +375,7 @@ void DD4hep_ListGroups::analyze(const edm::Event &evt, const edm::EventSetup &se cms::DDFilteredView fv1(*cpv, filter1); bool firstChild = fv1.firstChild(); - for (const auto& j : fv1.specpars()) { + for (const auto &j : fv1.specpars()) { for (const auto &k : j.second->paths) { if (firstChild) { std::vector> children = fv1.children(k); From 057332518b60cd2dbb2c93a41277b242dddf1a95 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Tue, 20 Oct 2020 22:49:54 +0200 Subject: [PATCH 14/16] clean up filter test and merge specifics --- .../DDCMS/src/DDFilteredView.cc | 103 +++++++++--------- .../DDCMS/test/Filter.cppunit.cc | 15 ++- 2 files changed, 61 insertions(+), 57 deletions(-) diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index 747d7ff827614..32d632dbd57e8 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -156,81 +156,79 @@ void DDFilteredView::rot(dd4hep::Rotation3D& matrixOut) const { rotation[8]); } -void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specs) { +void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specPars) { currentSpecPar_ = nullptr; - if (!filters_.empty()) { filters_.clear(); filters_.shrink_to_fit(); } - for (const auto& i : specs) { - for (const auto& j : i.second->paths) { - auto const& firstTok = front(j); - auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { - auto const& k = find_if(begin(f->skeys), end(f->skeys), [&](auto const& p) { return firstTok == p; }); - if (k != end(f->skeys)) { - currentFilter_ = f.get(); + + Filter* currentFilter = nullptr; + for (const auto& section : specPars) { + for (const auto& partSelector : section.second->paths) { + auto const& firstPartName = front(partSelector); + auto const& filterMatch = find_if(begin(filters_), end(filters_), [&](auto const& it) { + auto const& key = + find_if(begin(it->skeys), end(it->skeys), [&](auto const& partName) { return firstPartName == partName; }); + if (key != end(it->skeys)) { + currentFilter = it.get(); return true; } return false; }); - if (filter == end(filters_)) { - bool isRegex = dd4hep::dd::isRegex(firstTok); + if (filterMatch == end(filters_)) { filters_.emplace_back(make_unique()); - filters_.back()->isRegex.emplace_back(isRegex); - filters_.back()->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(firstTok)); - if (isRegex) { + filters_.back()->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(firstPartName)); + if (dd4hep::dd::isRegex(firstPartName)) { + filters_.back()->isRegex.emplace_back(true); filters_.back()->index.emplace_back(filters_.back()->keys.size()); - filters_.back()->keys.emplace_back(std::regex(begin(firstTok), end(firstTok))); + filters_.back()->keys.emplace_back(std::regex(std::begin(firstPartName), std::end(firstPartName))); } else { + filters_.back()->isRegex.emplace_back(false); filters_.back()->index.emplace_back(filters_.back()->skeys.size()); } - filters_.back()->skeys.emplace_back(firstTok); + filters_.back()->skeys.emplace_back(firstPartName); filters_.back()->up = nullptr; - filters_.back()->spec = i.second; - - // initialize current filter if it's empty - if (currentFilter_ == nullptr) { - currentFilter_ = filters_.back().get(); - } + filters_.back()->next = nullptr; + filters_.back()->spec = section.second; + currentFilter = filters_.back().get(); } // all next levels - vector toks = split(j, "/"); + vector toks = split(partSelector, "/"); for (size_t pos = 1; pos < toks.size(); ++pos) { - if (currentFilter_->next != nullptr) { - currentFilter_ = currentFilter_->next.get(); - auto const& l = find_if(begin(currentFilter_->skeys), end(currentFilter_->skeys), [&](auto const& p) { - return toks.front() == p; - }); - if (l == end(currentFilter_->skeys)) { - bool isRegex = dd4hep::dd::isRegex(toks[pos]); - currentFilter_->isRegex.emplace_back(isRegex); - currentFilter_->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); - if (isRegex) { - currentFilter_->index.emplace_back(currentFilter_->keys.size()); - currentFilter_->keys.emplace_back(std::regex(std::begin(toks[pos]), std::end(toks[pos]))); + if (currentFilter->next != nullptr) { + currentFilter = currentFilter->next.get(); + auto const& key = find_if( + begin(currentFilter->skeys), end(currentFilter->skeys), [&](auto const& p) { return toks[pos] == p; }); + if (key == end(currentFilter->skeys)) { + currentFilter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + if (dd4hep::dd::isRegex(toks[pos])) { + currentFilter->isRegex.emplace_back(true); + currentFilter->index.emplace_back(currentFilter->keys.size()); + currentFilter->keys.emplace_back(std::regex(std::begin(toks[pos]), std::end(toks[pos]))); } else { - currentFilter_->index.emplace_back(currentFilter_->skeys.size()); + currentFilter->isRegex.emplace_back(false); + currentFilter->index.emplace_back(currentFilter->skeys.size()); } - currentFilter_->skeys.emplace_back(toks[pos]); + currentFilter->skeys.emplace_back(toks[pos]); } } else { - auto filter = std::make_unique(); + auto nextLevelFilter = std::make_unique(); bool isRegex = dd4hep::dd::isRegex(toks[pos]); - filter->isRegex.emplace_back(isRegex); - filter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + nextLevelFilter->isRegex.emplace_back(isRegex); + nextLevelFilter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); if (isRegex) { - filter->index.emplace_back(filters_.back()->keys.size()); - filter->keys.emplace_back(std::regex(toks[pos].begin(), toks[pos].end())); + nextLevelFilter->index.emplace_back(filters_.back()->keys.size()); + nextLevelFilter->keys.emplace_back(std::regex(toks[pos].begin(), toks[pos].end())); } else { - filter->index.emplace_back(filters_.back()->skeys.size()); + nextLevelFilter->index.emplace_back(filters_.back()->skeys.size()); } - filter->skeys.emplace_back(toks.front()); - filter->next = nullptr; - filter->up = currentFilter_; - filter->spec = i.second; + nextLevelFilter->skeys.emplace_back(toks[pos]); + nextLevelFilter->next = nullptr; + nextLevelFilter->up = currentFilter; + nextLevelFilter->spec = section.second; - currentFilter_->next = std::move(filter); + currentFilter->next = std::move(nextLevelFilter); } } } @@ -248,15 +246,16 @@ void print(const Filter* filter) { void DDFilteredView::printFilter() const { for (const auto& f : filters_) { edm::LogVerbatim("Geometry").log([&](auto& log) { + log << "\nFilter: "; for (const auto& it : f->skeys) { log << it << ", "; } if (f->next) { - log << "Next:\n"; + log << "\nNext: "; print(&*f->next); } if (f->up) { - log << "Up:\n"; + log << "Up: "; print(f->up); } }); @@ -853,7 +852,9 @@ double DDFilteredView::getNextValue(const std::string& key) const { return result; } -std::string_view DDFilteredView::name() const { return (volume().volume().name()); } +std::string_view DDFilteredView::name() const { + return (node_ == nullptr ? std::string_view() : (volume().volume().name())); +} dd4hep::Solid DDFilteredView::solid() const { return (volume().volume().solid()); } diff --git a/DetectorDescription/DDCMS/test/Filter.cppunit.cc b/DetectorDescription/DDCMS/test/Filter.cppunit.cc index 46d88476d8814..c82f6f698220f 100644 --- a/DetectorDescription/DDCMS/test/Filter.cppunit.cc +++ b/DetectorDescription/DDCMS/test/Filter.cppunit.cc @@ -41,7 +41,6 @@ void testFilter::setUp() { for (const auto& i : selections) { vector toks = split(i, "/"); - unique_ptr f = nullptr; auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) { auto const& k = find_if(begin(f->skeys), end(f->skeys), [&](auto const& p) { return toks.front() == p; }); if (k != end(f->skeys)) { @@ -73,16 +72,16 @@ void testFilter::setUp() { auto const& l = find_if( begin(currentFilter->skeys), end(currentFilter->skeys), [&](auto const& p) { return toks[pos] == p; }); if (l == end(currentFilter->skeys)) { - bool isRegex = dd4hep::dd::isRegex(toks.front()); + bool isRegex = dd4hep::dd::isRegex(toks[pos]); currentFilter->isRegex.emplace_back(isRegex); - currentFilter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks.front())); + currentFilter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); if (isRegex) { currentFilter->index.emplace_back(currentFilter->keys.size()); - currentFilter->keys.emplace_back(std::regex(std::begin(toks.front()), std::end(toks.front()))); + currentFilter->keys.emplace_back(std::regex(std::begin(toks[pos]), std::end(toks[pos]))); } else { currentFilter->index.emplace_back(currentFilter->skeys.size()); } - currentFilter->skeys.emplace_back(toks.front()); + currentFilter->skeys.emplace_back(toks[pos]); } } else { auto filter = std::make_unique(); @@ -95,7 +94,7 @@ void testFilter::setUp() { } else { filter->index.emplace_back(filters_.back()->skeys.size()); } - filter->skeys.emplace_back(toks.front()); + filter->skeys.emplace_back(toks[pos]); filter->next = nullptr; filter->up = currentFilter; @@ -116,6 +115,10 @@ void testFilter::checkFilter() { for (auto const& i : filters_) { current = i.get(); do { + for (auto const& i : current->skeys) { + std::cout << i << ", "; + } + std::cout << "\n"; current = current->next.get(); } while (current != nullptr); } From d20498f04bfc708f827f339165f1bfe872517eeb Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 21 Oct 2020 23:54:43 +0200 Subject: [PATCH 15/16] restore merge filters --- .../DDCMS/src/DDFilteredView.cc | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/DetectorDescription/DDCMS/src/DDFilteredView.cc b/DetectorDescription/DDCMS/src/DDFilteredView.cc index 32d632dbd57e8..04febf2136a10 100644 --- a/DetectorDescription/DDCMS/src/DDFilteredView.cc +++ b/DetectorDescription/DDCMS/src/DDFilteredView.cc @@ -163,7 +163,6 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specPars) { filters_.shrink_to_fit(); } - Filter* currentFilter = nullptr; for (const auto& section : specPars) { for (const auto& partSelector : section.second->paths) { auto const& firstPartName = front(partSelector); @@ -171,7 +170,7 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specPars) { auto const& key = find_if(begin(it->skeys), end(it->skeys), [&](auto const& partName) { return firstPartName == partName; }); if (key != end(it->skeys)) { - currentFilter = it.get(); + currentFilter_ = it.get(); return true; } return false; @@ -191,26 +190,30 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specPars) { filters_.back()->up = nullptr; filters_.back()->next = nullptr; filters_.back()->spec = section.second; - currentFilter = filters_.back().get(); + // initialize current filter if it's empty + if (currentFilter_ == nullptr) { + currentFilter_ = filters_.back().get(); + } } // all next levels vector toks = split(partSelector, "/"); for (size_t pos = 1; pos < toks.size(); ++pos) { - if (currentFilter->next != nullptr) { - currentFilter = currentFilter->next.get(); - auto const& key = find_if( - begin(currentFilter->skeys), end(currentFilter->skeys), [&](auto const& p) { return toks[pos] == p; }); - if (key == end(currentFilter->skeys)) { - currentFilter->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); + if (currentFilter_->next != nullptr) { + currentFilter_ = currentFilter_->next.get(); + auto const& key = find_if(begin(currentFilter_->skeys), end(currentFilter_->skeys), [&](auto const& p) { + return toks.front() == p; + }); + if (key == end(currentFilter_->skeys)) { + currentFilter_->hasNamespace.emplace_back(dd4hep::dd::hasNamespace(toks[pos])); if (dd4hep::dd::isRegex(toks[pos])) { - currentFilter->isRegex.emplace_back(true); - currentFilter->index.emplace_back(currentFilter->keys.size()); - currentFilter->keys.emplace_back(std::regex(std::begin(toks[pos]), std::end(toks[pos]))); + currentFilter_->isRegex.emplace_back(true); + currentFilter_->index.emplace_back(currentFilter_->keys.size()); + currentFilter_->keys.emplace_back(std::regex(std::begin(toks[pos]), std::end(toks[pos]))); } else { - currentFilter->isRegex.emplace_back(false); - currentFilter->index.emplace_back(currentFilter->skeys.size()); + currentFilter_->isRegex.emplace_back(false); + currentFilter_->index.emplace_back(currentFilter_->skeys.size()); } - currentFilter->skeys.emplace_back(toks[pos]); + currentFilter_->skeys.emplace_back(toks[pos]); } } else { auto nextLevelFilter = std::make_unique(); @@ -225,10 +228,10 @@ void DDFilteredView::mergedSpecifics(DDSpecParRefs const& specPars) { } nextLevelFilter->skeys.emplace_back(toks[pos]); nextLevelFilter->next = nullptr; - nextLevelFilter->up = currentFilter; + nextLevelFilter->up = currentFilter_; nextLevelFilter->spec = section.second; - currentFilter->next = std::move(nextLevelFilter); + currentFilter_->next = std::move(nextLevelFilter); } } } From 6841d20ddf6fa55017b7232fb956dafef4e5779a Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Thu, 22 Oct 2020 10:28:04 +0200 Subject: [PATCH 16/16] apply code check patch --- DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc b/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc index 1dba92270a7b8..3f96052842367 100644 --- a/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc +++ b/DetectorDescription/DDCMS/plugins/test/DDTestSpecParsFilter.cc @@ -65,7 +65,7 @@ void DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup) } }); std::cout << "*** Check names in a path after filtering:\n"; - for (auto it : myReg) { + for (const auto& it : myReg) { if (it.second->hasPath("//ME11AlumFrame")) { std::cout << it.first << "\n"; }