CMS 3D CMS Logo

DDFilteredView.cc
Go to the documentation of this file.
3 #include "DD4hep/Detector.h"
4 #include <TGeoBBox.h>
5 #include <TGeoBoolNode.h>
6 #include <vector>
7 
8 using namespace cms;
9 using namespace std;
10 using namespace cms::dd;
11 
13  : registry_(&det->specpars()) {
14  it_.emplace_back(Iterator(volume));
15 }
16 
17 const PlacedVolume
19  return PlacedVolume(node_);
20 }
21 
22 const Double_t*
24  return it_.back().GetCurrentMatrix()->GetTranslation();
25 }
26 
27 const Double_t*
29  return it_.back().GetCurrentMatrix()->GetRotationMatrix();
30 }
31 
32 void
34  for(const auto& i : specs) {
35  for(const auto& j : i->paths) {
36  vector<string_view> toks = split(j, "/");
37  auto const& filter = find_if(begin(filters_), end(filters_), [&](auto const& f) {
38  auto const& k = find(begin(f->keys), end(f->keys), toks.front());
39  if(k != end(f->keys)) {
40  currentFilter_ = f.get();
41  return true;
42  }
43  return false;
44  });
45  if(filter == end(filters_)) {
46  filters_.emplace_back(unique_ptr<Filter>(new Filter{{toks.front()}, nullptr, nullptr}));
47  currentFilter_ = filters_.back().get();
48  }
49  // all next levels
50  for(size_t pos = 1; pos < toks.size(); ++pos) {
51  if(currentFilter_->next != nullptr) {
53  auto const& l = find(begin(currentFilter_->keys), end(currentFilter_->keys), toks[pos]);
54  if(l == end(currentFilter_->keys)) {
55  currentFilter_->keys.emplace_back(toks[pos]);
56  }
57  } else {
58  currentFilter_->next.reset(new Filter{{toks[pos]}, nullptr, currentFilter_});
59  }
60  }
61  }
62  }
63 }
64 
65 bool
67  it_.back().SetType(0);
68  Node *node = nullptr;
69  while((node = it_.back().Next())) {
70  if(accept(node->GetVolume()->GetName())) {
71  addPath(node);
72  return true;
73  }
74  }
75  return false;
76 }
77 
78 bool
80  next(0);
81  it_.emplace_back(Iterator(it_.back()));
82  it_.back().SetType(1);
83  if(currentFilter_->next)
85  else
86  return false;
87  do {
88  if(accepted(currentFilter_->keys, node_->GetVolume()->GetName())) {
89  addNode(node_);
90  return true;
91  }
92  } while((node_ = it_.back().Next()));
93 
94  return false;
95 }
96 
97 bool
99  it_.back().SetType(1);
100  unCheckNode();
101  do {
102  if(accepted(currentFilter_->keys, node_->GetVolume()->GetName())) {
103  addNode(node_);
104  return true;
105  }
106  } while((node_ = it_.back().Next()));
107 
108  return false;
109 }
110 
111 bool
113  it_.back().SetType(1);
114  Node *node = nullptr;
115  while((node = it_.back().Next())) {
116  if(accepted(currentFilter_->keys, node->GetVolume()->GetName())) {
117  addNode(node);
118  return true;
119  }
120  }
121  return false;
122 }
123 
124 bool
126  it_.back().SetType(1);
127  Node *node = nullptr;
128  while((node = it_.back().Next())) {
129  if(accepted(currentFilter_->keys, node->GetVolume()->GetName())) {
130  node_ = node;
131  return true;
132  }
133  }
134  return false;
135 }
136 
137 bool
139  it_.back().SetType(1);
140  Node *node = nullptr;
141  while((node = it_.back().Next())) {
142  if(accepted(currentFilter_->keys, node->GetVolume()->GetName())) {
143  return true;
144  }
145  }
146  return false;
147 }
148 
149 bool
151  up();
152  it_.back().SetType(0);
153  it_.back().Skip();
154 
155  return true;
156 }
157 
158 bool
160  it_.back().SetType(type);
161  Node *node = nullptr;
162  if((node = it_.back().Next())) {
163  node_ = node;
164  return true;
165  }
166  else
167  return false;
168 }
169 
170 void
172  it_.emplace_back(Iterator(it_.back()));
173  next(0);
174  if(currentFilter_->next)
176 }
177 
178 void
180  it_.pop_back();
181  if(currentFilter_->up)
183 }
184 
185 bool
186 DDFilteredView::accept(std::string_view name) {
187  bool result = false;
188  for(const auto& it : filters_) {
189  currentFilter_ = it.get();
190  result = accepted(currentFilter_->keys, name);
191  if(result)
192  return result;
193  }
194  return result;
195 }
196 
197 vector<double>
199  Volume volume = node_->GetVolume();
200  if(volume->GetShape()->IsA() == TGeoBBox::Class()) {
201  const TGeoBBox* box = static_cast<const TGeoBBox*>(volume->GetShape());
202  return {box->GetDX(), box->GetDY(), box->GetDZ()};
203  }
204  else if(volume->GetShape()->IsA() == TGeoCompositeShape::Class()) {
205  const TGeoCompositeShape* shape = static_cast<const TGeoCompositeShape*>(volume->GetShape());
206  const TGeoBoolNode* boolean = shape->GetBoolNode();
207  while(boolean->GetLeftShape()->IsA() != TGeoBBox::Class()) {
208  boolean = static_cast<const TGeoCompositeShape*>(boolean->GetLeftShape())->GetBoolNode();
209  }
210  const TGeoBBox* box = static_cast<const TGeoBBox*>(boolean->GetLeftShape());
211  return {box->GetDX(), box->GetDY(), box->GetDZ()};
212  } else
213  return {1, 1, 1};
214 }
215 
216 bool
218  assert(registry_);
219  node_ = node;
220  nodes_.tags.clear();
221  nodes_.offsets.clear();
222  nodes_.copyNos.clear();
223  bool result(false);
224 
225  int level = it_.back().GetLevel();
226  for(int nit = level; nit > 0; --nit) {
227  for_each(begin(registry_->specpars), end(registry_->specpars), [&](auto const& i) {
228  auto k = find_if(begin(i.second.paths), end(i.second.paths),[&](auto const& j) {
229  return (compareEqual(it_.back().GetNode(nit)->GetVolume()->GetName(), *begin(split(realTopName(j), "/"))) &&
230  (i.second.hasValue("CopyNoTag") ||
231  i.second.hasValue("CopyNoOffset")));
232  });
233  if(k != end(i.second.paths)) {
234  nodes_.tags.emplace_back(i.second.dblValue("CopyNoTag"));
235  nodes_.offsets.emplace_back(i.second.dblValue("CopyNoOffset"));
236  nodes_.copyNos.emplace_back(it_.back().GetNode(nit)->GetNumber());
237  result = true;
238  }
239  });
240  }
241  return result;
242 }
243 
244 bool
246  assert(registry_);
247  node_ = node;
248  bool result(false);
249  for_each(begin(registry_->specpars), end(registry_->specpars), [&](auto const& i) {
250  auto k = find_if(begin(i.second.paths), end(i.second.paths),[&](auto const& j) {
251  return (compareEqual(node_->GetVolume()->GetName(), *begin(split(realTopName(j), "/"))) &&
252  (i.second.hasValue("CopyNoTag") ||
253  i.second.hasValue("CopyNoOffset")));
254  });
255  if(k != end(i.second.paths)) {
256  nodes_.tags.emplace_back(i.second.dblValue("CopyNoTag"));
257  nodes_.offsets.emplace_back(i.second.dblValue("CopyNoOffset"));
258  nodes_.copyNos.emplace_back(node_->GetNumber());
259  result = true;
260  }
261  });
262  return result;
263 }
264 
265 void
267  nodes_.tags.pop_back();
268  nodes_.offsets.pop_back();
269  nodes_.copyNos.pop_back();
270 }
type
Definition: HCALResponse.h:21
void up()
set current node to the parent node in the filtered tree
std::vector< std::unique_ptr< Filter > > filters_
bool firstSibling()
set the current node to the first sibling
TGeoNode Node
void mergedSpecifics(DDSpecParRefs const &)
User specific data.
ExpandedNodes nodes_
std::vector< std::string_view > keys
Definition: Filter.h:27
struct Filter * up
Definition: Filter.h:29
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const PlacedVolume volume() const
The physical volume of the current node.
bool sibling()
set the current node to the next sub sibling
std::unique_ptr< Filter > next
Definition: Filter.h:28
void down()
set current node to the child node in the filtered tree
TGeoIterator Iterator
Definition: Filter.h:32
std::vector< int > copyNos
Definition: ExpandedNodes.h:29
std::vector< double > offsets
Definition: ExpandedNodes.h:28
bool nextSibling()
set the current node to the next sibling
bool addPath(Node *const)
dd4hep::PlacedVolume PlacedVolume
bool accept(std::string_view)
const Double_t * rot() const
The absolute rotation of the current node.
double f[11][100]
#define end
Definition: vmac.h:39
bool parent()
set the current node to the parent node ...
bool firstChild()
set the current node to the first child
bool next(int)
set current node to the next node in the filtered tree
dd4hep::Volume Volume
int k[5][pyjets_maxn]
Namespace of DDCMS conversion namespace.
std::vector< double > extractParameters() const
extract shape parameters
const Double_t * trans() const
The absolute translation of the current node.
bool accepted(std::vector< std::string_view > const &, std::string_view)
std::vector< const DDSpecPar * > DDSpecParRefs
Definition: Filter.py:1
#define begin
Definition: vmac.h:32
std::vector< double > tags
Definition: ExpandedNodes.h:27
const DDSpecParRegistry * registry_
bool checkChild()
count the number of children matching selection
void unCheckNode()
pop current node
double split
Definition: MVATrainer.cc:139
std::vector< Iterator > it_
bool addNode(Node *const)