Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:49:07

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/Framework/interface/ESTransientHandle.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0008 #include "DetectorDescription/Core/interface/DDCompactView.h"
0009 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0010 
0011 class DDFilteredViewAnalyzer : public edm::one::EDAnalyzer<> {
0012 public:
0013   explicit DDFilteredViewAnalyzer(const edm::ParameterSet&);
0014   ~DDFilteredViewAnalyzer(void) override {}
0015 
0016   void beginJob() override {}
0017   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0018   void endJob() override {}
0019 
0020 private:
0021   std::string m_attribute;
0022   std::string m_value;
0023   bool m_shouldPrint;
0024   DDCompOp m_comp;
0025   edm::ESGetToken<DDCompactView, IdealGeometryRecord> ddToken_;
0026 };
0027 
0028 DDFilteredViewAnalyzer::DDFilteredViewAnalyzer(const edm::ParameterSet& pset) {
0029   m_attribute = pset.getParameter<std::string>("attribute");
0030   m_value = pset.getParameter<std::string>("value");
0031 
0032   m_shouldPrint = pset.getUntrackedParameter<bool>("shouldPrint", true);
0033   if (pset.getUntrackedParameter<bool>("compareNotEquals", true)) {
0034     m_comp = DDCompOp::not_equals;
0035   } else {
0036     m_comp = DDCompOp::equals;
0037   }
0038   ddToken_ = esConsumes<DDCompactView, IdealGeometryRecord>();
0039 }
0040 
0041 void DDFilteredViewAnalyzer::analyze(const edm::Event&, const edm::EventSetup& iSetup) {
0042   edm::ESTransientHandle<DDCompactView> cpv = iSetup.getTransientHandle(ddToken_);
0043 
0044   DDValue val(m_attribute, m_value, 0.0);
0045   DDSpecificsFilter filter;
0046   filter.setCriteria(val,  // name & value of a variable
0047                      m_comp);
0048   DDFilteredView fv(*cpv, filter);
0049   if (fv.firstChild()) {
0050     edm::LogVerbatim("CMSGeom") << "Found attribute " << m_attribute.c_str() << " with value " << m_value.c_str();
0051     bool dodet = true;
0052     int i = 0;
0053     while (dodet) {
0054       dodet = fv.next();
0055       if (m_shouldPrint) {
0056         edm::LogVerbatim("CMSGeom") << i++ << ": " << fv.logicalPart().name();
0057       }
0058     }
0059   } else
0060     edm::LogVerbatim("CMSGeom") << "No luck...";
0061 }
0062 
0063 DEFINE_FWK_MODULE(DDFilteredViewAnalyzer);