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