CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DetectorDescription/Core/src/LogicalPart.cc

Go to the documentation of this file.
00001 
00002 #include <algorithm>
00003 #include "DetectorDescription/Core/src/LogicalPart.h"
00004 #include "DetectorDescription/Core/interface/DDPartSelection.h"
00005 #include "DetectorDescription/Base/interface/DDdebug.h"
00006 //#include "DetectorDescription/Core/interface/DDSpecifics.h"
00007 
00008 
00009 using DDI::LogicalPart;
00010 
00011 LogicalPart::LogicalPart(const DDMaterial & m,
00012                          const DDSolid & s,
00013                          DDEnums::Category c)
00014  : material_(m), solid_(s), cat_(c), weight_(0), specifics_(0), hasDDValue_(1,false)
00015 { }
00016 
00017 
00018 
00019 
00020 const DDMaterial & LogicalPart::material() const { return material_; }
00021 const DDSolid & LogicalPart::solid() const { return solid_; }
00022 DDEnums::Category LogicalPart::category() const { return cat_; }
00023 void LogicalPart::stream(std::ostream & os) 
00024 {
00025   os << std::endl << " mat=" << material().ddname() << std::endl << " solid=" << solid();
00026 }
00027 
00028 double & LogicalPart::weight()  { return weight_; }
00029 
00030 void LogicalPart::addSpecifics(const std::pair<DDPartSelection*,DDsvalues_type*> & s)
00031 {
00032   if ( ! (s.first && s.second) ) {
00033     // FIXME
00034     std::cerr << "LogicalPart::addSpecific error pointer 0 " 
00035               << s.first << "," << s.second << std::endl;
00036     return;
00037   }
00038   specifics_.push_back(s);
00039   DDsvalues_type::const_iterator it = s.second->begin();
00040   DDsvalues_type::const_iterator ed = s.second->end();
00041   for (; it != ed; ++it) {
00042     unsigned int id = it->first;
00043     if ( id < hasDDValue_.size() ) {
00044       hasDDValue_[id] = true;
00045     }
00046     else {
00047       hasDDValue_.resize(id+1,false);
00048       hasDDValue_[id] = true;
00049     }
00050     
00051     DCOUT('S', "hasValue_.size()=" << hasDDValue_.size() << " DDValue_id=" << id << std::flush
00052           << " DDValue_name=" << DDValue(id).name() << std::flush 
00053            << " DDValue_string=" << DDValue(id).strings().size() );
00054   }
00055 }
00056 
00057 bool LogicalPart::hasDDValue(const DDValue & v) const
00058 {
00059    bool result = false;
00060    unsigned int id = v.id();
00061    if ( id < hasDDValue_.size()) {
00062      result = hasDDValue_[id];
00063    }
00064    return result; 
00065 }
00066 
00067 void LogicalPart::removeSpecifics(const std::pair<DDPartSelection*,DDsvalues_type*> & s)
00068 {
00069    std::vector<std::pair<DDPartSelection*,DDsvalues_type* > >::iterator it = 
00070      std::find(specifics_.begin(),specifics_.end(),s);
00071    specifics_.erase(it);
00072 }
00073 
00074 
00075 std::vector<const DDsvalues_type*> LogicalPart::specifics() const
00076 {
00077    std::vector<const DDsvalues_type*> result;
00078    specificsV(result);
00079    return result;
00080 
00081 }
00082 
00083 void LogicalPart::specificsV(std::vector<const DDsvalues_type*> & result) const
00084 {
00085   typedef std::vector<std::pair<DDPartSelection*,DDsvalues_type* > > sp_type;
00086   sp_type::const_iterator it = specifics_.begin();
00087   sp_type::const_iterator ed = specifics_.end();
00088   for (; it != ed; ++it) {
00089     DDPartSelection & ps = *(it->first);
00090     if (ps.size()==1 && ps[0].selectionType_==ddanylogp) {
00091       result.push_back(it->second);
00092     }
00093   }
00094 }
00095 
00096 DDsvalues_type LogicalPart::mergedSpecifics() const {
00097   DDsvalues_type merged;
00098   mergedSpecificsV(merged);  
00099   return merged;
00100 }
00101 
00102 
00103 void LogicalPart::mergedSpecificsV(DDsvalues_type & merged) const {
00104   merged.clear();
00105   std::vector<const DDsvalues_type *> unmerged; specificsV(unmerged);
00106   if (unmerged.size()==1) {
00107     merged = *(unmerged[0]);
00108   }
00109   else if (unmerged.size()>1) {
00110     std::vector<const DDsvalues_type *>::const_iterator it = unmerged.begin();
00111     std::vector<const DDsvalues_type *>::const_iterator ed = unmerged.end();
00112     for (; it != ed; ++it) {
00113       merge(merged, **it);
00114     } 
00115   }
00116 }  
00117 
00118 
00119 /*
00120 const std::vector<DDPartSelection*> & LogicalPart::partSelections(const DDValue &) const{
00121   static std::vector<DDPartSelection*> empty_;
00122   std::vector<DDPartSelection*> * result_ = &empty;
00123   std::map<DDValue, std::vector<DDPartSelection*> >::const_iterator it = valToPartsel_.find(v);
00124   if (it != valToPartsel_.end()) {
00125      result = &(it->second);
00126   }
00127   return *result;
00128 }
00129 */