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,
21  const DDsvalues_type & specs,
22  bool doRegex)
23  : specifics_(specs),
24  partSelections_(0),
25  valid_(false),
26  doRegex_(doRegex)
27  {
28  for( const auto& it : selections ) {
30  }
31  }
32 
33  Specific::Specific(const std::vector<DDPartSelection> & selections,
34  const DDsvalues_type & specs)
35  : specifics_(specs), partSelections_(selections), valid_(false), doRegex_(false)
36  { }
37 
39  {
40  std::vector<DDPartSelRegExpLevel> regv;
41  std::vector<DDPartSelection> temp;
42  DDTokenize2(selString,regv);
43 
44  if (regv.empty()) throw cms::Exception("DDException")
45  << "Could not evaluate the selection-std::string ->"
46  << selString << "<-";
47 
48  std::pair<bool,std::string> res;
49  for( const auto& it : regv ) {
50  std::vector<DDLogicalPart> lpv;
51  res = DDIsValid( it.ns_, it.nm_, lpv, doRegex_ );
52  if (!res.first) {
53  std::string msg("Could not process q-name of a DDLogicalPart, reason:\n"+res.second);
54  msg+="\nSpecPar selection is:\n" + selString + "\n";
55  //throw cms::Exception("DDException") << "Could not process q-name of a DDLogicalPart, reason:\n" << res.second;
56  edm::LogError("Specific") << msg;
57  break; //EXIT for loop
58  }
59  addSelectionLevel( lpv, it.copyno_, it.selectionType_, temp );
60  }
61  if ( res.first ) { // i.e. it wasn't "thrown" out of the loop
62  partSelections_.reserve(temp.size() + partSelections_.size());
63  for( const auto& iit : temp ) {
64  partSelections_.emplace_back( iit );
65  }
66  }
67  }
68 
69  void Specific::addSelectionLevel(std::vector<DDLogicalPart> & lpv, int copyno, ddselection_type st,
70  std::vector<DDPartSelection> & selv)
71  {
72  if (selv.empty()) { // create one, no entry yet!
73  selv.emplace_back(DDPartSelection());
74  }
75  typedef std::vector<DDLogicalPart>::size_type lpv_sizetype;
76  typedef std::vector<DDPartSelection>::size_type ps_sizetype;
77  ps_sizetype ps_sz = selv.size();
78  lpv_sizetype lpv_sz = lpv.size();
79  lpv_sizetype lpv_i = 0;
80  std::vector<DDPartSelection> result;
81  for (; lpv_i < lpv_sz; ++lpv_i) {
82  std::vector<DDPartSelection>::const_iterator ps_it = selv.begin();
83  for (; ps_it != selv.end(); ++ps_it) {
84  result.emplace_back(*ps_it);
85  }
86  }
87  ps_sizetype ps_i = 0;
88  for(lpv_i=0; lpv_i < lpv_sz; ++lpv_i) {
89  for(ps_i = ps_sz*lpv_i; ps_i < ps_sz*(lpv_i+1); ++ps_i) {
90  result[ps_i].emplace_back(DDPartSelectionLevel(lpv[lpv_i],copyno,st));
91  }
92  }
93  selv = result;
94  }
95 
96  const std::vector<DDPartSelection> & Specific::selection() const
97  {
98  return partSelections_;
99  }
100 
101  void Specific::stream(std::ostream & os) const
102  {
103  os << " Size: " << specifics_.size() << std::endl;
104  os << "\tSelections:" << std::endl;
105  for( const auto& pit : partSelections_ ) {
106  os << pit << std::endl;
107  }
108  for( const auto& vit : specifics_ ) {
109  const DDValue & v = vit.second;
110  os << "\tParameter name= \"" << v.name() << "\" " << std::endl;
111  os << "\t\t Value pairs: " << std::endl;
112  size_t s=v.size();
113  size_t i=0;
114  if ( v.isEvaluated() ) {
115  for( ; i<s; ++i) {
116  os << "\t\t\t\"" << v[i].first << "\"" << ", " << v[i].second << std::endl;
117  }
118  } else { // v is not evaluated
119  for( const auto& i : v.strings()) {
120  os << "\t\t\t\"" << i << "\"" << ", not evaluated" << std::endl;
121  }
122  }
123  }
124  }
125 
126  void Specific::updateLogicalPart(std::vector<std::pair<DDLogicalPart, std::pair<const DDPartSelection*, const DDsvalues_type*> > >& result) const
127  {
128  if (!partSelections_.empty()) {
129  const DDsvalues_type* sv = (&specifics_);
130  for( const auto& it : partSelections_ ) {
131  DDLogicalPart logp = it.back().lp_;
132  const DDPartSelection * ps = (&it);
133  assert(ps);
134  assert(sv);
135  std::pair<const DDPartSelection*,const DDsvalues_type*> pssv(ps,sv);
136  result.emplace_back(std::make_pair(logp,pssv));
137  }
138  }
139  }
140 
149  std::pair<bool,DDExpandedView> Specific::node() const
150  {
152  DDExpandedView e(c);
153 
154  if (partSelections_.size() != 1) {
155  edm::LogError("Specific") << " >> more or less than one part-selector, currently NOT SUPPORTED! <<" << std::endl;
156  return std::make_pair(false,e);
157  }
158  const DDPartSelection & ps = partSelections_[0];
159 
160  DDPartSelection::const_iterator it = ps.begin();
161  DDPartSelection::const_iterator ed = ps.end();
162  if ( (it != ed) && ( it->selectionType_ != ddanyposp) ) {
163  edm::LogError("Specific") << " >> part-selector must start with //Name[no] ! << " << std::endl;
164  return std::make_pair(false,e);
165  }
166  ++it;
167  for (; it != ps.end(); ++it) {
168  if ( it->selectionType_ != ddchildposp ) {
169  edm::LogError("Specific") << " >> part-selector must be a concatenation of direct children\n"
170  << " including their copy-number only, CURRENT LIMITATION! <<" << std::endl;
171  return std::make_pair(false,e);
172  }
173  }
174 
175  it = ps.begin();
176  bool result = true;
177  for (; it != ed; ++it) {
178  while(result) {
179  if( (it->copyno_ == e.copyno()) && (it->lp_ == e.logicalPart())) {
180  break;
181  }
182  else {
183  result = e.nextSibling();
184  }
185  }
186  if ((ed-it)>1) {
187  result = e.firstChild();
188  }
189  }
190  return std::make_pair(result,e);
191  }
192 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:54
void addSelectionLevel(std::vector< DDLogicalPart > &lpv, int copyno, ddselection_type st, std::vector< DDPartSelection > &selv)
Definition: Specific.cc:69
const std::vector< DDPartSelection > & selection() const
Definition: Specific.cc:96
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:204
DDsvalues_type specifics_
Definition: Specific.h:46
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:38
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:149
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:61
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:126
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
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:68
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:101