CMS 3D CMS Logo

LogicalPart.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <memory>
3 
8 
9 using DDI::LogicalPart;
10 
11 LogicalPart::LogicalPart(const DDMaterial & m,
12  const DDSolid & s,
14  : material_(m), solid_(s), cat_(c), weight_(0), specifics_(0), hasDDValue_(1,false)
15 { }
16 
17 const DDMaterial & LogicalPart::material() const { return material_; }
18 
19 const DDSolid & LogicalPart::solid() const { return solid_; }
20 
22 
23 void LogicalPart::stream(std::ostream & os)
24 {
25  os << std::endl << " mat=" << material().ddname() << std::endl << " solid=" << solid();
26 }
27 
28 double & LogicalPart::weight() { return weight_; }
29 
30 void LogicalPart::addSpecifics(const std::pair<const DDPartSelection*, const DDsvalues_type*> & s)
31 {
32  if ( ! (s.first && s.second) ) {
33  // FIXME
34  std::cerr << "LogicalPart::addSpecific error pointer 0 "
35  << s.first << "," << s.second << std::endl;
36  return;
37  }
38  specifics_.push_back(s);
39  for( const auto& it : *s.second ) {
40  unsigned int id = it.first;
41  if ( id < hasDDValue_.size() ) {
42  hasDDValue_[id] = true;
43  }
44  else {
45  hasDDValue_.resize(id+1,false);
46  hasDDValue_[id] = true;
47  }
48  }
49 }
50 
51 bool LogicalPart::hasDDValue(const DDValue & v) const
52 {
53  bool result = false;
54  unsigned int id = v.id();
55  if ( id < hasDDValue_.size()) {
56  result = hasDDValue_[id];
57  }
58  return result;
59 }
60 
61 void LogicalPart::removeSpecifics(const std::pair<const DDPartSelection*, const DDsvalues_type*> & s)
62 {
63  std::vector<std::pair<const DDPartSelection*, const DDsvalues_type* > >::iterator it =
64  std::find(specifics_.begin(),specifics_.end(),s);
65  specifics_.erase(it);
66 }
67 
68 std::vector<const DDsvalues_type*> LogicalPart::specifics() const
69 {
70  std::vector<const DDsvalues_type*> result;
71  specificsV(result);
72  return result;
73 
74 }
75 
76 void LogicalPart::specificsV(std::vector<const DDsvalues_type*> & result) const
77 {
78  for( const auto& it : specifics_ ) {
79  const DDPartSelection & ps = *(it.first);
80  if (ps.size()==1 && ps[0].selectionType_==ddanylogp) {
81  result.push_back(it.second);
82  }
83  }
84 }
85 
87  DDsvalues_type merged;
88  mergedSpecificsV(merged);
89  return merged;
90 }
91 
93  merged.clear();
94  std::vector<const DDsvalues_type *> unmerged;
95  specificsV(unmerged);
96  if (unmerged.size()==1) {
97  merged = *(unmerged[0]);
98  }
99  else if (unmerged.size()>1) {
100  for( const auto& it : unmerged ) {
101  merge(merged, *it);
102  }
103  }
104 }
std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > specifics_
Definition: LogicalPart.h:48
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
DDEnums::Category category() const
Definition: LogicalPart.cc:21
void removeSpecifics(const std::pair< const DDPartSelection *, const DDsvalues_type * > &)
Definition: LogicalPart.cc:61
void addSpecifics(const std::pair< const DDPartSelection *, const DDsvalues_type * > &)
Definition: LogicalPart.cc:30
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:48
A DDSolid represents the shape of a part.
Definition: DDSolid.h:37
std::vector< bool > hasDDValue_
Definition: LogicalPart.h:49
const DDMaterial & material() const
Definition: LogicalPart.cc:17
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
void stream(std::ostream &)
Definition: LogicalPart.cc:23
Category
Definition: DDEnums.h:7
std::vector< const DDsvalues_type * > specifics() const
Definition: LogicalPart.cc:68
DDMaterial material_
Definition: LogicalPart.h:41
bool hasDDValue(const DDValue &) const
Definition: LogicalPart.cc:51
DDEnums::Category cat_
Definition: LogicalPart.h:43
void mergedSpecificsV(DDsvalues_type &res) const
Definition: LogicalPart.cc:92
const DDSolid & solid() const
Definition: LogicalPart.cc:19
double & weight()
Definition: LogicalPart.cc:28
DDsvalues_type mergedSpecifics() const
Definition: LogicalPart.cc:86
void specificsV(std::vector< const DDsvalues_type * > &result) const
Definition: LogicalPart.cc:76
const N & ddname() const
Definition: DDBase.h:80
def merge(dictlist, TELL=False)
Definition: MatrixUtil.py:191