File indexing completed on 2023-03-17 10:51:40
0001 #include <algorithm>
0002 #include <memory>
0003
0004 #include "DetectorDescription/Core/interface/DDName.h"
0005 #include "DetectorDescription/Core/interface/DDPartSelection.h"
0006 #include "DetectorDescription/Core/interface/LogicalPart.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008
0009 using DDI::LogicalPart;
0010
0011 LogicalPart::LogicalPart(const DDMaterial& m, const DDSolid& s, DDEnums::Category c)
0012 : material_(m), solid_(s), cat_(c), specifics_(0), hasDDValue_(1, false) {}
0013
0014 const DDMaterial& LogicalPart::material() const { return material_; }
0015
0016 const DDSolid& LogicalPart::solid() const { return solid_; }
0017
0018 DDEnums::Category LogicalPart::category() const { return cat_; }
0019
0020 void LogicalPart::stream(std::ostream& os) {
0021 os << std::endl << " mat=" << material().ddname() << std::endl << " solid=" << solid();
0022 }
0023
0024 void LogicalPart::addSpecifics(const std::pair<const DDPartSelection*, const DDsvalues_type*>& s) {
0025 if (!(s.first && s.second)) {
0026
0027 std::cerr << "LogicalPart::addSpecific error pointer 0 " << s.first << "," << s.second << std::endl;
0028 return;
0029 }
0030 specifics_.emplace_back(s);
0031 for (const auto& it : *s.second) {
0032 unsigned int id = it.first;
0033 if (id < hasDDValue_.size()) {
0034 hasDDValue_[id] = true;
0035 } else {
0036 hasDDValue_.resize(id + 1, false);
0037 hasDDValue_[id] = true;
0038 }
0039 }
0040 }
0041
0042 bool LogicalPart::hasDDValue(const DDValue& v) const {
0043 bool result = false;
0044 unsigned int id = v.id();
0045 if (id < hasDDValue_.size()) {
0046 result = hasDDValue_[id];
0047 }
0048 return result;
0049 }
0050
0051 void LogicalPart::removeSpecifics(const std::pair<const DDPartSelection*, const DDsvalues_type*>& s) {
0052 std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >::iterator it =
0053 std::find(specifics_.begin(), specifics_.end(), s);
0054 specifics_.erase(it);
0055 }
0056
0057 std::vector<const DDsvalues_type*> LogicalPart::specifics() const {
0058 std::vector<const DDsvalues_type*> result;
0059 specificsV(result);
0060 return result;
0061 }
0062
0063 void LogicalPart::specificsV(std::vector<const DDsvalues_type*>& result) const {
0064 for (const auto& it : specifics_) {
0065 const DDPartSelection& ps = *(it.first);
0066 if (ps.size() == 1 && ps[0].selectionType_ == ddanylogp) {
0067 result.emplace_back(it.second);
0068 }
0069 }
0070 }
0071
0072 DDsvalues_type LogicalPart::mergedSpecifics() const {
0073 DDsvalues_type merged;
0074 mergedSpecificsV(merged);
0075 return merged;
0076 }
0077
0078 void LogicalPart::mergedSpecificsV(DDsvalues_type& merged) const {
0079 merged.clear();
0080 std::vector<const DDsvalues_type*> unmerged;
0081 specificsV(unmerged);
0082 if (unmerged.size() == 1) {
0083 merged = *(unmerged[0]);
0084 } else if (unmerged.size() > 1) {
0085 for (const auto& it : unmerged) {
0086 merge(merged, *it);
0087 }
0088 }
0089 }