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