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