CMS 3D CMS Logo

Specific.cc
Go to the documentation of this file.
2 
3 #include <cassert>
4 #include <ext/alloc_traits.h>
5 #include <cstddef>
6 #include <memory>
7 
17 
18 namespace DDI {
19 
20  Specific::Specific(const std::vector<std::string>& selections, const DDsvalues_type& specs, bool doRegex)
21  : specifics_(specs), partSelections_(0), valid_(false), doRegex_(doRegex) {
22  for (const auto& it : selections) {
24  }
25  }
26 
27  Specific::Specific(const std::vector<DDPartSelection>& selections, const DDsvalues_type& specs)
28  : specifics_(specs), partSelections_(selections), valid_(false), doRegex_(false) {}
29 
31  std::vector<DDPartSelRegExpLevel> regv;
32  std::vector<DDPartSelection> temp;
33  DDTokenize2(selString, regv);
34 
35  if (regv.empty())
36  throw cms::Exception("DDException") << "Could not evaluate the selection-std::string ->" << selString << "<-";
37 
38  std::pair<bool, std::string> res;
39  for (const auto& it : regv) {
40  std::vector<DDLogicalPart> lpv;
41  res = DDIsValid(it.ns_, it.nm_, lpv, doRegex_);
42  if (!res.first) {
43  std::string msg("Could not process q-name of a DDLogicalPart, reason:\n" + res.second);
44  msg += "\nSpecPar selection is:\n" + selString + "\n";
45  //throw cms::Exception("DDException") << "Could not process q-name of a DDLogicalPart, reason:\n" << res.second;
46  edm::LogError("Specific") << msg;
47  break; //EXIT for loop
48  }
49  addSelectionLevel(lpv, it.copyno_, it.selectionType_, temp);
50  }
51  if (res.first) { // i.e. it wasn't "thrown" out of the loop
52  partSelections_.reserve(temp.size() + partSelections_.size());
53  for (const auto& iit : temp) {
54  partSelections_.emplace_back(iit);
55  }
56  }
57  }
58 
59  void Specific::addSelectionLevel(std::vector<DDLogicalPart>& lpv,
60  int copyno,
62  std::vector<DDPartSelection>& selv) {
63  if (selv.empty()) { // create one, no entry yet!
64  selv.emplace_back(DDPartSelection());
65  }
66  typedef std::vector<DDLogicalPart>::size_type lpv_sizetype;
67  typedef std::vector<DDPartSelection>::size_type ps_sizetype;
68  ps_sizetype ps_sz = selv.size();
69  lpv_sizetype lpv_sz = lpv.size();
70  lpv_sizetype lpv_i = 0;
71  std::vector<DDPartSelection> result;
72  for (; lpv_i < lpv_sz; ++lpv_i) {
73  std::vector<DDPartSelection>::const_iterator ps_it = selv.begin();
74  for (; ps_it != selv.end(); ++ps_it) {
75  result.emplace_back(*ps_it);
76  }
77  }
78  ps_sizetype ps_i = 0;
79  for (lpv_i = 0; lpv_i < lpv_sz; ++lpv_i) {
80  for (ps_i = ps_sz * lpv_i; ps_i < ps_sz * (lpv_i + 1); ++ps_i) {
81  result[ps_i].emplace_back(DDPartSelectionLevel(lpv[lpv_i], copyno, st));
82  }
83  }
84  selv = result;
85  }
86 
87  const std::vector<DDPartSelection>& Specific::selection() const { return partSelections_; }
88 
89  void Specific::stream(std::ostream& os) const {
90  os << " Size: " << specifics_.size() << std::endl;
91  os << "\tSelections:" << std::endl;
92  for (const auto& pit : partSelections_) {
93  os << pit << std::endl;
94  }
95  for (const auto& vit : specifics_) {
96  const DDValue& v = vit.second;
97  os << "\tParameter name= \"" << v.name() << "\" " << std::endl;
98  os << "\t\t Value pairs: " << std::endl;
99  size_t s = v.size();
100  size_t i = 0;
101  if (v.isEvaluated()) {
102  for (; i < s; ++i) {
103  os << "\t\t\t\"" << v[i].first << "\""
104  << ", " << v[i].second << std::endl;
105  }
106  } else { // v is not evaluated
107  for (const auto& i : v.strings()) {
108  os << "\t\t\t\"" << i << "\""
109  << ", not evaluated" << std::endl;
110  }
111  }
112  }
113  }
114 
116  std::vector<std::pair<DDLogicalPart, std::pair<const DDPartSelection*, const DDsvalues_type*> > >& result) const {
117  if (!partSelections_.empty()) {
118  const DDsvalues_type* sv = (&specifics_);
119  for (const auto& it : partSelections_) {
120  DDLogicalPart logp = it.back().lp_;
121  const DDPartSelection* ps = (&it);
122  assert(ps);
123  assert(sv);
124  std::pair<const DDPartSelection*, const DDsvalues_type*> pssv(ps, sv);
125  result.emplace_back(std::make_pair(logp, pssv));
126  }
127  }
128  }
129 
138  std::pair<bool, DDExpandedView> Specific::node() const {
140  DDExpandedView e(c);
141 
142  if (partSelections_.size() != 1) {
143  edm::LogError("Specific") << " >> more or less than one part-selector, currently NOT SUPPORTED! <<" << std::endl;
144  return std::make_pair(false, e);
145  }
146  const DDPartSelection& ps = partSelections_[0];
147 
148  DDPartSelection::const_iterator it = ps.begin();
149  DDPartSelection::const_iterator ed = ps.end();
150  if ((it != ed) && (it->selectionType_ != ddanyposp)) {
151  edm::LogError("Specific") << " >> part-selector must start with //Name[no] ! << " << std::endl;
152  return std::make_pair(false, e);
153  }
154  ++it;
155  for (; it != ps.end(); ++it) {
156  if (it->selectionType_ != ddchildposp) {
157  edm::LogError("Specific") << " >> part-selector must be a concatenation of direct children\n"
158  << " including their copy-number only, CURRENT LIMITATION! <<" << std::endl;
159  return std::make_pair(false, e);
160  }
161  }
162 
163  it = ps.begin();
164  bool result = true;
165  for (; it != ed; ++it) {
166  while (result) {
167  if ((it->copyno_ == e.copyno()) && (it->lp_ == e.logicalPart())) {
168  break;
169  } else {
170  result = e.nextSibling();
171  }
172  }
173  if ((ed - it) > 1) {
174  result = e.firstChild();
175  }
176  }
177  return std::make_pair(result, e);
178  }
179 } // namespace DDI
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:53
void addSelectionLevel(std::vector< DDLogicalPart > &lpv, int copyno, ddselection_type st, std::vector< DDPartSelection > &selv)
Definition: Specific.cc:59
const std::vector< DDPartSelection > & selection() const
Definition: Specific.cc:87
std::vector< DDPartSelection > partSelections_
Definition: Specific.h:47
static const uint16_t valid_
Definition: Constants.h:17
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
uint16_t size_type
Definition: Electron.h:6
bool valid_
Definition: Specific.h:48
bool isEvaluated(void) const
true, if values are numerical evaluated; else false.
Definition: DDValue.cc:152
DDsvalues_type specifics_
Definition: Specific.h:46
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
bool doRegex_
Definition: Specific.h:49
ddselection_type
Specific(const std::vector< std::string > &selections, const DDsvalues_type &specs, bool doRegex=true)
Definition: Specific.cc:20
void createPartSelections(const std::string &selString)
Definition: Specific.cc:30
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::pair< bool, DDExpandedView > node() const
gives the geometrical history of a fully specified PartSelector
Definition: Specific.cc:138
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:60
std::pair< bool, std::string > DDIsValid(const std::string &ns, const std::string &name, std::vector< DDLogicalPart > &result, bool doRegex=true)
int copyno() const
Copy number associated with the current node.
bool firstChild()
set the current node to the first child ...
void updateLogicalPart(std::vector< std::pair< DDLogicalPart, std::pair< const DDPartSelection *, const DDsvalues_type * > > > &) const
Definition: Specific.cc:115
void DDTokenize2(const std::string &selectionString, std::vector< DDPartSelRegExpLevel > &result)
bool nextSibling()
set the current node to the next sibling ...
tuple msg
Definition: mps_check.py:285
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:67
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
Provides an exploded view of the detector (tree-view)
void stream(std::ostream &) const
Definition: Specific.cc:89