Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:09:54

0001 #include "Geometry/MuonNumbering/interface/MuonOffsetFromDD.h"
0002 #include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h"
0003 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0004 #include "DetectorDescription/Core/interface/DDFilter.h"
0005 #include "DetectorDescription/Core/interface/DDValue.h"
0006 #include "DetectorDescription/Core/interface/DDutils.h"
0007 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0008 #include <iostream>
0009 #include <iomanip>
0010 #include <sstream>
0011 
0012 //#define EDM_ML_DEBUG
0013 
0014 MuonOffsetFromDD::MuonOffsetFromDD(std::vector<std::string> name) : specpars_(name), nset_(name.size()) {
0015 #ifdef EDM_ML_DEBUG
0016   edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD initialized with " << nset_ << " specpars";
0017   std::ostringstream st1;
0018   for (const auto& name : specpars_)
0019     st1 << " " << name;
0020   edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD::SpecPars:" << st1.str();
0021 #endif
0022 }
0023 
0024 bool MuonOffsetFromDD::build(const DDCompactView* cpv, MuonOffsetMap& php) {
0025 #ifdef EDM_ML_DEBUG
0026   edm::LogVerbatim("MuonGeom") << "Inside MuonOffsetFromDD::build(const DDCompactView*, MuonOffsetMap&)";
0027 #endif
0028 
0029   // Loop over all the sets
0030   std::string attribute = "OnlyForMuonNumbering";
0031   std::string name;
0032   for (unsigned int k = 0; k < nset_; ++k) {
0033     name = "muonstep" + std::to_string(k);
0034     DDSpecificsMatchesValueFilter filter{DDValue(attribute, name, 0)};
0035     DDFilteredView fv(*cpv, filter);
0036     bool dodet = fv.firstChild();
0037     DDsvalues_type sv(fv.mergedSpecifics());
0038     int offset = getNumber("CopyNoOffset", sv);
0039     int tag = getNumber("CopyNoTag", sv);
0040     while (dodet) {
0041       name = fv.logicalPart().name().name();
0042       php.muonMap_[name] = std::make_pair(offset, tag);
0043       dodet = fv.next();
0044     }
0045   }
0046   return this->debugParameters(php);
0047 }
0048 
0049 bool MuonOffsetFromDD::build(const cms::DDCompactView* cpv, MuonOffsetMap& php) {
0050   edm::LogVerbatim("MuonGeom") << "Inside MuonOffsetFromDD::build(const cms::DDCompactView*, MuonOffsetMap&)";
0051 
0052   // Get the offsets and tags first
0053   int offsets[nset_], tags[nset_];
0054   cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume());
0055   for (unsigned int k = 0; k < nset_; ++k) {
0056     std::vector<int> off = fv.get<std::vector<int>>(specpars_[k], "CopyNoOffset");
0057     offsets[k] = (!off.empty()) ? off[0] : 0;
0058     std::vector<int> tag = fv.get<std::vector<int>>(specpars_[k], "CopyNoTag");
0059     tags[k] = (!tag.empty()) ? tag[0] : 0;
0060   }
0061   // Now loop over the detectors
0062   std::string attribute = "OnlyForMuonNumbering";
0063   std::string name;
0064   for (unsigned int k = 0; k < nset_; ++k) {
0065     name = "muonstep" + std::to_string(k);
0066     const cms::DDFilter filter(attribute, name);
0067     cms::DDFilteredView fv((*cpv), filter);
0068     while (fv.firstChild()) {
0069       name = static_cast<std::string>(fv.name());
0070       php.muonMap_[name] = std::make_pair(offsets[k], tags[k]);
0071     }
0072   }
0073   return this->debugParameters(php);
0074 }
0075 
0076 bool MuonOffsetFromDD::debugParameters(const MuonOffsetMap& php) {
0077   edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD: Finds " << php.muonMap_.size() << " entries in the map";
0078 #ifdef EDM_ML_DEBUG
0079   unsigned int k(0);
0080   for (auto itr = php.muonMap_.begin(); itr != php.muonMap_.end(); ++itr, ++k) {
0081     edm::LogVerbatim("MuonGeom") << "[" << k << "] " << itr->first << ": (" << (itr->second).first << ", "
0082                                  << (itr->second).second << ")";
0083   }
0084 #endif
0085   return true;
0086 }
0087 
0088 int MuonOffsetFromDD::getNumber(const std::string& str, const DDsvalues_type& sv) {
0089 #ifdef EDM_ML_DEBUG
0090   edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD::getNumbers called for " << str;
0091 #endif
0092   DDValue value(str);
0093   if (DDfetch(&sv, value)) {
0094     const std::vector<double>& fvec = value.doubles();
0095     int nval = (!fvec.empty()) ? static_cast<int>(fvec[0]) : 0;
0096     return nval;
0097   } else {
0098     return 0;
0099   }
0100 }