CMS 3D CMS Logo

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