Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-15 01:25:11

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/ESTransientHandle.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "Geometry/Records/interface/DDSpecParRegistryRcd.h"
0007 
0008 #include <DD4hep/SpecParRegistry.h>
0009 
0010 #include <iostream>
0011 
0012 using namespace std;
0013 using namespace cms;
0014 using namespace edm;
0015 
0016 class DDTestSpecParsFilter : public one::EDAnalyzer<> {
0017 public:
0018   explicit DDTestSpecParsFilter(const ParameterSet& iConfig)
0019       : m_tag(iConfig.getParameter<ESInputTag>("DDDetector")),
0020         m_token(esConsumes(m_tag)),
0021         m_attribute(iConfig.getUntrackedParameter<string>("attribute", "")),
0022         m_value(iConfig.getUntrackedParameter<string>("value", "")) {}
0023 
0024   void beginJob() override {}
0025   void analyze(Event const& iEvent, EventSetup const&) override;
0026   void endJob() override {}
0027 
0028 private:
0029   const ESInputTag m_tag;
0030   const ESGetToken<dd4hep::SpecParRegistry, DDSpecParRegistryRcd> m_token;
0031   const string m_attribute;
0032   const string m_value;
0033 };
0034 
0035 void DDTestSpecParsFilter::analyze(const Event&, const EventSetup& iEventSetup) {
0036   LogVerbatim("Geometry") << "DDTestSpecParsFilter::analyze: " << m_tag;
0037   ESTransientHandle<dd4hep::SpecParRegistry> registry = iEventSetup.getTransientHandle(m_token);
0038 
0039   LogVerbatim("Geometry") << "DDTestSpecParsFilter::analyze: " << m_tag << " for attribute " << m_attribute
0040                           << " and value " << m_value;
0041   LogVerbatim("Geometry") << "DD SpecPar Registry size: " << registry->specpars.size();
0042   std::cout << "*** Check names in a path:\n";
0043   std::vector<std::string_view> namesInPath = registry->names("//ME11AlumFrame");
0044   for (auto i : namesInPath) {
0045     std::cout << i << "\n";
0046   }
0047   dd4hep::SpecParRefs myReg;
0048   if (m_value.empty())
0049     registry->filter(myReg, m_attribute);
0050   else
0051     registry->filter(myReg, m_attribute, m_value);
0052 
0053   LogVerbatim("Geometry").log([&myReg](auto& log) {
0054     log << "Filtered DD SpecPar Registry size: " << myReg.size() << "\n";
0055     for (const auto& t : myReg) {
0056       log << "\nRegExps { ";
0057       for (const auto& ki : t.second->paths)
0058         log << ki << " ";
0059       log << "};\n ";
0060       for (const auto& kl : t.second->spars) {
0061         log << kl.first << " = ";
0062         for (const auto& kil : kl.second) {
0063           log << kil << " ";
0064         }
0065         log << "\n ";
0066       }
0067       for (const auto& kl : t.second->numpars) {
0068         log << kl.first << " = ";
0069         for (const auto& kil : kl.second) {
0070           log << kil << " ";
0071         }
0072         log << "\n ";
0073       }
0074     }
0075   });
0076   std::cout << "*** Check names in a path after filtering:\n";
0077   for (const auto& it : myReg) {
0078     if (it.second->hasPath("//ME11AlumFrame")) {
0079       std::cout << it.first << "\n";
0080     }
0081   }
0082 }
0083 
0084 DEFINE_FWK_MODULE(DDTestSpecParsFilter);