CMS 3D CMS Logo

MuonOffsetFromDD.cc
Go to the documentation of this file.
8 #include <iostream>
9 #include <iomanip>
10 #include <sstream>
11 
12 //#define EDM_ML_DEBUG
13 
14 MuonOffsetFromDD::MuonOffsetFromDD(std::vector<std::string> name) : specpars_(name), nset_(name.size()) {
15 #ifdef EDM_ML_DEBUG
16  edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD initialized with " << nset_ << " specpars";
17  std::ostringstream st1;
18  for (const auto& name : specpars_)
19  st1 << " " << name;
20  edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD::SpecPars:" << st1.str();
21 #endif
22 }
23 
25 #ifdef EDM_ML_DEBUG
26  edm::LogVerbatim("MuonGeom") << "Inside MuonOffsetFromDD::build(const DDCompactView*, MuonOffsetMap&)";
27 #endif
28 
29  // Loop over all the sets
30  std::string attribute = "OnlyForMuonNumbering";
32  for (unsigned int k = 0; k < nset_; ++k) {
33  name = "muonstep" + std::to_string(k);
35  DDFilteredView fv(*cpv, filter);
36  bool dodet = fv.firstChild();
38  int offset = getNumber("CopyNoOffset", sv);
39  int tag = getNumber("CopyNoTag", sv);
40  while (dodet) {
41  name = fv.logicalPart().name().name();
42  php.muonMap_[name] = std::make_pair(offset, tag);
43  dodet = fv.next();
44  }
45  }
46  return this->debugParameters(php);
47 }
48 
50  edm::LogVerbatim("MuonGeom") << "Inside MuonOffsetFromDD::build(const cms::DDCompactView*, MuonOffsetMap&)";
51 
52  // Get the offsets and tags first
53  int offsets[nset_], tags[nset_];
54  cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume());
55  for (unsigned int k = 0; k < nset_; ++k) {
56  std::vector<int> off = fv.get<std::vector<int>>(specpars_[k], "CopyNoOffset");
57  offsets[k] = (!off.empty()) ? off[0] : 0;
58  std::vector<int> tag = fv.get<std::vector<int>>(specpars_[k], "CopyNoTag");
59  tags[k] = (!tag.empty()) ? tag[0] : 0;
60  }
61  // Now loop over the detectors
62  std::string attribute = "OnlyForMuonNumbering";
64  for (unsigned int k = 0; k < nset_; ++k) {
65  name = "muonstep" + std::to_string(k);
66  const cms::DDFilter filter(attribute, name);
67  cms::DDFilteredView fv((*cpv), filter);
68  while (fv.firstChild()) {
69  name = static_cast<std::string>(fv.name());
70  php.muonMap_[name] = std::make_pair(offsets[k], tags[k]);
71  }
72  }
73  return this->debugParameters(php);
74 }
75 
77  edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD: Finds " << php.muonMap_.size() << " entries in the map";
78 #ifdef EDM_ML_DEBUG
79  unsigned int k(0);
80  for (auto itr = php.muonMap_.begin(); itr != php.muonMap_.end(); ++itr, ++k) {
81  edm::LogVerbatim("MuonGeom") << "[" << k << "] " << itr->first << ": (" << (itr->second).first << ", "
82  << (itr->second).second << ")";
83  }
84 #endif
85  return true;
86 }
87 
89 #ifdef EDM_ML_DEBUG
90  edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD::getNumbers called for " << str;
91 #endif
92  DDValue value(str);
93  if (DDfetch(&sv, value)) {
94  const std::vector<double>& fvec = value.doubles();
95  int nval = (!fvec.empty()) ? static_cast<int>(fvec[0]) : 0;
96  return nval;
97  } else {
98  return 0;
99  }
100 }
size
Write out results.
Log< level::Info, true > LogVerbatim
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
std::string to_string(const V &value)
Definition: OMSAccess.h:71
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
std::string_view name() const
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
bool next()
set current node to the next node in the filtered tree
const unsigned int nset_
Definition: value.py:1
bool firstChild()
set the current node to the first child
DDsvalues_type mergedSpecifics() const
const N & name() const
Definition: DDBase.h:59
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
T get(const std::string &)
extract attribute value
const std::vector< std::string > specpars_
dd4hep::Volume worldVolume() const
Handle to the world volume containing everything.
Definition: DDDetector.cc:67
bool debugParameters(const MuonOffsetMap &)
int getNumber(const std::string &, const DDsvalues_type &)
bool firstChild()
set the current node to the first child ...
bool build(const DDCompactView *, MuonOffsetMap &)
#define str(s)
MuonOffsetFromDD(std::vector< std::string > names)
std::unordered_map< std::string, std::pair< int, int > > muonMap_
Definition: MuonOffsetMap.h:14