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