Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DD4Hep: DT Geometry Builder with Correct Numbering #25897

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions DetectorDescription/DDCMS/interface/BenchmarkGrd.h
@@ -0,0 +1,34 @@
#ifndef DETECTOR_DESCRIPTION_BENCHMARK_GRD_H
#define DETECTOR_DESCRIPTION_BENCHMARK_GRD_H

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <string>
#include <chrono>

class BenchmarkGrd {
public:
BenchmarkGrd( const std::string &name )
: m_start( std::chrono::high_resolution_clock::now()),
m_name( name )
{}

~BenchmarkGrd() {
std::chrono::duration< double, std::milli > diff = std::chrono::high_resolution_clock::now() - m_start;
edm::LogVerbatim("Geometry") << "Benchmark '" << m_name << "' took " << diff.count() << " millis\n";
}

private:
std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
std::string m_name;
};

#ifdef BENCHMARK_ON
# define BENCHMARK_START(X) {BenchmarkGrd(#X)
# define BENCHMARK_END }
#else
# define BENCHMARK_START(X)
# define BENCHMARK_END
#endif

#endif
43 changes: 37 additions & 6 deletions DetectorDescription/DDCMS/interface/DDFilteredView.h
Expand Up @@ -24,13 +24,21 @@

namespace cms {

class DDDetector;

//! Geometrical 'path' of the current node up to the root-node
using DDGeoHistory = std::vector<DDExpandedNode>;
using Volume = dd4hep::Volume;

struct DDFilteredView {

DDFilteredView(DDVolume const&, DDTranslation const&, DDRotationMatrix const&);

struct ExpandedNodes {
std::vector<double> tags;
std::vector<double> offsets;
std::vector<int> copyNos;
} nodes;

DDFilteredView(const DDDetector*);

//! The logical-part of the current node in the filtered-view
const DDVolume & volume() const;
Expand All @@ -42,7 +50,7 @@ namespace cms {
const DDRotationMatrix & rotation() const;

//! User specific data
void mergedSpecifics(DDSpecParRefMap const&);
void mergedSpecifics(DDSpecParRefs const&);

//! set the current node to the first child
bool firstChild();
Expand All @@ -57,18 +65,41 @@ namespace cms {
const DDGeoHistory & geoHistory() const;

bool accepted(std::string_view, std::string_view) const;
bool accepted(std::vector<std::string_view>, std::string_view) const;
bool accepted(std::vector<std::string_view> const&, std::string_view) const;
bool acceptedM(std::vector<std::string_view>&, std::string_view) const;
std::vector<std::string_view> const& topNodes() const { return topNodes_; }
std::vector<std::string_view> const& nextNodes() const { return nextNodes_; }
std::vector<std::string_view> const& afterNextNodes() const { return afterNextNodes_; }

std::vector<double> extractParameters(Volume) const;
std::vector<double> extractParameters() const;
std::vector<std::string_view> paths(const char*) const;
bool checkPath(std::string_view, TGeoNode *);
bool checkNode(TGeoNode *);
void unCheckNode();
void filter(DDSpecParRefs&, std::string_view, std::string_view) const;
std::vector<std::string_view> vPathsTo(const DDSpecPar&, unsigned int) const;
std::vector<std::string_view> tails(const std::vector<std::string_view>& fullPath) const;

DDGeoHistory parents_;

private:
const DDSpecParRegistry* registry_;

bool isRegex(std::string_view) const;
int contains(std::string_view, std::string_view) const;
std::string_view realTopName(std::string_view input) const;
int copyNo(std::string_view input) const;
std::string_view noCopyNo(std::string_view input) const;
std::string_view noNamespace(std::string_view input) const;
std::vector<std::string_view> split(std::string_view, const char*) const;
bool acceptRegex(std::string_view, std::string_view) const;

DDGeoHistory parents_;
std::vector<std::string_view> topNodes_;
std::vector<std::string_view> nextNodes_;
std::vector<std::string_view> afterNextNodes_;

TGeoVolume *topVolume_ = nullptr;
TGeoNode *node_ = nullptr;
};
}

Expand Down
11 changes: 4 additions & 7 deletions DetectorDescription/DDCMS/interface/DDSpecParRegistry.h
Expand Up @@ -12,11 +12,8 @@ namespace cms {
using DDVectorsMap = tbb::concurrent_unordered_map< std::string, tbb::concurrent_vector<double>>;

struct DDSpecPar {
std::vector<std::string_view> tails(const std::vector<std::string_view>&) const;
std::vector<std::string_view> split(std::string_view, const char*) const;
std::vector<std::string_view> vPathsTo(unsigned int) const;
std::string_view realTopName(std::string_view input) const;
std::string_view strValue(const char*) const;
bool hasValue(const char* key) const;
double dblValue(const char*) const;

DDPaths paths;
Expand All @@ -25,11 +22,11 @@ namespace cms {
};

using DDSpecParMap = tbb::concurrent_unordered_map<std::string, DDSpecPar>;
using DDSpecParRefMap = tbb::concurrent_unordered_map<const std::string*, const DDSpecPar*>;
using DDSpecParRefs = std::vector<const DDSpecPar*>;

struct DDSpecParRegistry {
void filter(DDSpecParRefMap&, std::string_view, std::string_view) const;
void filter(DDSpecParRefs&, std::string_view, std::string_view) const;

DDSpecParMap specpars;
};
}
Expand Down
10 changes: 5 additions & 5 deletions DetectorDescription/DDCMS/interface/MuonNumbering.h
@@ -1,7 +1,7 @@
#ifndef DETECTOR_DESCRIPTION_MUON_NUMBERING_H
#define DETECTOR_DESCRIPTION_MUON_NUMBERING_H

#include "DetectorDescription/DDCMS/interface/DDExpandedNode.h"
#include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
#include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
#include <string>
#include <unordered_map>
Expand All @@ -10,12 +10,12 @@ class MuonBaseNumber;

namespace cms {

using DDGeoHistory = std::vector<DDExpandedNode>;
using MuonConstants = std::unordered_map<std::string, int>;
using MuonConstants = std::unordered_map<std::string_view, int>;

struct MuonNumbering {
const MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &, MuonConstants&) const;

const MuonBaseNumber geoHistoryToBaseNumber(const DDFilteredView::ExpandedNodes&) const;
const int get(const char*) const;

MuonConstants values;
};
}
Expand Down
11 changes: 6 additions & 5 deletions DetectorDescription/DDCMS/plugins/DDTestSpecParsFilter.cc
Expand Up @@ -37,20 +37,21 @@ DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup)
ESTransientHandle<DDSpecParRegistry> registry;
iEventSetup.get<DDSpecParRegistryRcd>().get(m_tag.module(), registry);

LogVerbatim("Geometry") << "DDTestSpecParsFilter::analyze: " << m_tag.module() << " for attribute " << m_attribute << " and value " << m_value;
LogVerbatim("Geometry") << "DDTestSpecParsFilter::analyze: " << m_tag.module()
<< " for attribute " << m_attribute << " and value " << m_value;
LogVerbatim("Geometry") << "DD SpecPar Registry size: " << registry->specpars.size();

DDSpecParRefMap myReg;
DDSpecParRefs myReg;
registry->filter(myReg, m_attribute, m_value);

LogVerbatim("Geometry").log([&myReg](auto& log) {
log << "Filtered DD SpecPar Registry size: " << myReg.size();
for(const auto& t: myReg) {
log << "\n " << *t.first << " = { ";
for(const auto& ki : t.second->paths)
log << " = { ";
for(const auto& ki : t->paths)
log << ki << ", ";
log << " };\n ";
for(const auto& kl : t.second->spars) {
for(const auto& kl : t->spars) {
log << kl.first << " = { ";
for(const auto& kil : kl.second) {
log << kil << ", ";
Expand Down