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 
5 // Message logger.
7 
8 #include <assert.h>
9 
10 namespace DDI {
11 
12 Specific::Specific(const std::vector<std::string>& selections,
13  const DDsvalues_type & specs,
14  bool doRegex)
15  : specifics_(specs),
16  partSelections_(0),
17  valid_(false),
18  doRegex_(doRegex)
19 {
20  std::vector<std::string>::const_iterator it = selections.begin();
21  for(; it != selections.end(); ++it) {
23  }
24 }
25 
26 Specific::Specific(const std::vector<DDPartSelection> & selections,
27  const DDsvalues_type & specs)
28  : specifics_(specs), partSelections_(selections), valid_(false), doRegex_(false)
29 { }
30 
31 void Specific::createPartSelections(const std::string & selString)
32 {
33 
34  std::vector<DDPartSelRegExpLevel> regv;
35  std::vector<DDPartSelection> temp;
36  DDTokenize2(selString,regv);
37 
38  if (!regv.size()) throw DDException("Could not evaluate the selection-std::string ->" + selString + "<-");
39  std::vector<DDPartSelRegExpLevel>::const_iterator it = regv.begin();
40  std::pair<bool,std::string> res;
41  for (; it != regv.end(); ++it) {
42  std::vector<DDLogicalPart> lpv;
43  res = DDIsValid(it->ns_,it->nm_,lpv,doRegex_);
44  if (!res.first) {
45  std::string msg("Could not process q-name of a DDLogicalPart, reason:\n"+res.second);
46  msg+="\nSpecPar selection is:\n" + selString + "\n";
47  //throw DDException("Could not process q-name of a DDLogicalPart, reason:\n"+res.second);
48  edm::LogError("Specific") << msg;
49  break; //EXIT for loop
50  }
51  //edm::LogInfo ("Specific") << "call addSelectionLevel" << std::endl;
52  addSelectionLevel(lpv,it->copyno_,it->selectionType_,temp);
53  }
54  if ( res.first ) { // i.e. it wasn't "thrown" out of the loop
55  std::vector<DDPartSelection>::const_iterator iit = temp.begin();
56  partSelections_.reserve(temp.size() + partSelections_.size());
57  for (; iit != temp.end(); ++iit) {
58  partSelections_.push_back(*iit);
59  //edm::LogInfo ("Specific") << *iit << std::endl;
60  }
61  }
62 }
63 
64 
65 
66 void Specific::addSelectionLevel(std::vector<DDLogicalPart> & lpv, int copyno, ddselection_type st,
67  std::vector<DDPartSelection> & selv)
68 {
69  //static int count =0;
70  //++count;
71  //edm::LogInfo ("Specific") << "count=" << count << " " << flush;
72  if (!selv.size()) { // create one, no entry yet!
73  selv.push_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  //edm::LogInfo ("Specific") << "lpv_sz=" << lpv_sz << std::endl;
80  lpv_sizetype lpv_i = 0;
81  std::vector<DDPartSelection> result;
82  for (; lpv_i < lpv_sz; ++lpv_i) {
83  std::vector<DDPartSelection>::const_iterator ps_it = selv.begin();
84  for (; ps_it != selv.end(); ++ps_it) {
85  result.push_back(*ps_it);
86  }
87  }
88  //edm::LogInfo ("Specific") << "result-size=" << result.size() << std::endl;
89  //ps_sizetype ps_sz = result.size();
90  ps_sizetype ps_i = 0;
91  for(lpv_i=0; lpv_i < lpv_sz; ++lpv_i) {
92  for(ps_i = ps_sz*lpv_i; ps_i < ps_sz*(lpv_i+1); ++ps_i) {
93  result[ps_i].push_back(DDPartSelectionLevel(lpv[lpv_i],copyno,st));
94  }
95  }
96  selv = result;
97 }
98 
99 const std::vector<DDPartSelection> & Specific::selection() const
100 {
101  return partSelections_;
102 }
103 
104 
105 void Specific::stream(std::ostream & os) const
106 {
107  // os << " no output available yet, sorry. ";
108  os << " Size: " << specifics_.size() << std::endl;
109  os << "\tSelections:" << std::endl;
110  partsel_type::const_iterator pit(partSelections_.begin()), pend(partSelections_.end());
111  for (;pit!=pend;++pit) {
112  os << *pit << std::endl;
113  }
114 
115  DDsvalues_type::const_iterator vit(specifics_.begin()), ved(specifics_.end());
116  for (;vit!=ved;++vit) {
117  const DDValue & v = vit->second;
118  os << "\tParameter name= \"" << v.name() << "\" " << std::endl;
119  os << "\t\t Value pairs: " << std::endl;
120  size_t s=v.size();
121  size_t i=0;
122  if ( v.isEvaluated() ) {
123  for (; i<s; ++i) {
124  os << "\t\t\t\"" << v[i].first << "\"" << ", " << v[i].second << std::endl;
125  }
126  } else { // v is not evaluated
127  const std::vector<std::string>& vs = v.strings();
128  for (; i<s; ++i) {
129  os << "\t\t\t\"" << vs[i] << "\"" << ", not evaluated" << std::endl;
130  }
131  }
132  }
133 }
134 
135 void Specific::updateLogicalPart(std::vector<std::pair<DDLogicalPart, std::pair<DDPartSelection*,DDsvalues_type*> > >& result) const
136 {
137  if (partSelections_.size()) {
138  partsel_type::const_iterator it = partSelections_.begin();
139  DDsvalues_type* sv = const_cast<DDsvalues_type*>(&specifics_);
140  for (; it != partSelections_.end(); ++it) {
141  DDLogicalPart logp = it->back().lp_;
142  /*if (!logp.isDefined().second) {
143  throw DDException("Specific::updateLogicalPart(..): LogicalPart not defined, name=" + std::string(logp.ddname()));
144  }*/
145  DDPartSelection * ps = const_cast<DDPartSelection*>(&(*it));
146  assert(ps);
147  assert(sv);
148  std::pair<DDPartSelection*,DDsvalues_type*> pssv(ps,sv);
149  result.push_back(std::make_pair(logp,pssv));
150  }
151  }
152 }
153 
162 std::pair<bool,DDExpandedView> Specific::node() const
163 {
165  DDExpandedView e(c);
166 
167  if (partSelections_.size() != 1) {
168  edm::LogError("Specific") << " >> more or less than one part-selector, currently NOT SUPPORTED! <<" << std::endl;
169  return std::make_pair(false,e);
170  }
171  const DDPartSelection & ps = partSelections_[0];
172 
173  DDPartSelection::const_iterator it = ps.begin();
174  DDPartSelection::const_iterator ed = ps.end();
175  if ( (it != ed) && ( it->selectionType_ != ddanyposp) ) {
176  edm::LogError("Specific") << " >> part-selector must start with //Name[no] ! << " << std::endl;
177  return std::make_pair(false,e);
178  }
179  ++it;
180  for (; it != ps.end(); ++it) {
181  if ( it->selectionType_ != ddchildposp ) {
182  edm::LogError("Specific") << " >> part-selector must be a concatenation of direct children\n"
183  << " including their copy-number only, CURRENT LIMITATION! <<" << std::endl;
184  return std::make_pair(false,e);
185  }
186  }
187 
188  it = ps.begin();
189  bool result = true;
190  for (; it != ed; ++it) {
191  while(result) {
192  if( (it->copyno_ == e.copyno()) && (it->lp_ == e.logicalPart())) {
193  break;
194  }
195  else {
196  result = e.nextSibling();
197  }
198  }
199  if ((ed-it)>1) {
200  result = e.firstChild();
201  }
202  }
203  return std::make_pair(result,e);
204 }
205 
206 
208 {
209 // DDsvalues_type::iterator it = specifics_.begin();
210 // for (; it != specifics_.end(); ++it) {
211 // it->second.clear();
212 // }
213 }
214 
215 }
void addSelectionLevel(std::vector< DDLogicalPart > &lpv, int copyno, ddselection_type st, std::vector< DDPartSelection > &selv)
Definition: Specific.cc:66
const std::vector< DDPartSelection > & selection() const
Definition: Specific.cc:99
int i
Definition: DBlmapReader.cc:9
An exception for DDD errors.
Definition: DDException.h:23
static const uint16_t valid_
Definition: Constants.h:18
type of data representation of DDCompactView
Definition: DDCompactView.h:81
uint16_t size_type
DDsvalues_type specifics_
Definition: Specific.h:54
bool isEvaluated() const
true, if values are numerical evaluated; else false.
Definition: DDValue.cc:207
bool doRegex_
Definition: Specific.h:57
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:12
void createPartSelections(const std::string &selString)
Definition: Specific.cc:31
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:95
std::pair< bool, DDExpandedView > node() const
gives the geometrical history of a fully specified PartSelector
Definition: Specific.cc:162
void updateLogicalPart(std::vector< std::pair< DDLogicalPart, std::pair< DDPartSelection *, DDsvalues_type * > > > &) const
Definition: Specific.cc:135
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:76
partsel_type partSelections_
Definition: Specific.h:55
int copyno() const
Copy number associated with the current node.
bool firstChild()
set the current node to the first child ...
void DDTokenize2(const std::string &selectionString, std::vector< DDPartSelRegExpLevel > &result)
bool nextSibling()
set the current node to the next sibling ...
std::pair< bool, std::string > DDIsValid(const std::string &ns, const std::string &name, std::vector< DDLogicalPart > &result, bool doRegex=true)
unsigned int size() const
the size of the stored value-pairs (std::string,double)
Definition: DDValue.h:83
string s
Definition: asciidump.py:422
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
const std::string & name() const
the name of the DDValue
Definition: DDValue.h:69
Provides an exploded view of the detector (tree-view)
mathSSE::Vec4< T > v
void stream(std::ostream &) const
Definition: Specific.cc:105