Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-30 10:17:34

0001 // system include files
0002 #include <map>
0003 #include <string>
0004 
0005 // user include files
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 #include "FWCore/PluginManager/interface/ModuleDef.h"
0015 #include "DetectorDescription/Core/interface/DDCompactView.h"
0016 #include "DetectorDescription/Core/interface/DDSolid.h"
0017 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
0018 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0019 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0020 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0021 #include "DD4hep/Detector.h"
0022 #include "DD4hep/DD4hepRootPersistency.h"
0023 
0024 #include "TGeoManager.h"
0025 #include "TFile.h"
0026 #include "TSystem.h"
0027 
0028 class PrintGeomSolids : public edm::one::EDAnalyzer<> {
0029 public:
0030   explicit PrintGeomSolids(const edm::ParameterSet&);
0031   ~PrintGeomSolids() override {}
0032   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0033 
0034   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0035 
0036 private:
0037   edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvTokenDDD_;
0038   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> cpvTokenDD4hep_;
0039   bool fromDD4hep_;
0040 };
0041 
0042 PrintGeomSolids::PrintGeomSolids(const edm::ParameterSet& ps) {
0043   fromDD4hep_ = ps.getParameter<bool>("fromDD4hep");
0044   if (fromDD4hep_)
0045     cpvTokenDD4hep_ = esConsumes<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0046   else
0047     cpvTokenDDD_ = esConsumes<DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0048 
0049   edm::LogVerbatim("PrintGeom") << "PrintGeomSolids created with dd4hep: " << fromDD4hep_;
0050 }
0051 
0052 void PrintGeomSolids::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0053   edm::ParameterSetDescription desc;
0054   desc.add<bool>("fromDD4hep", false);
0055   descriptions.add("printGeomSolids", desc);
0056 }
0057 
0058 void PrintGeomSolids::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0059   int solids(0);
0060   if (fromDD4hep_) {
0061     const cms::DDCompactView* cpv = &iSetup.getData(cpvTokenDD4hep_);
0062     const cms::DDDetector* det = cpv->detector();
0063     TGeoManager const& geom = det->description()->manager();
0064     TGeoIterator next(geom.GetTopVolume());
0065     TGeoNode* node;
0066     TString path;
0067     std::vector<std::string> names;
0068     while ((node = next())) {
0069       next.GetPath(path);
0070       std::string name = static_cast<std::string>(node->GetVolume()->GetName());
0071       if (std::find(names.begin(), names.end(), name) == names.end()) {
0072         edm::LogVerbatim("PrintGeom") << name << "   "
0073                                       << static_cast<std::string>(node->GetVolume()->GetShape()->GetTitle());
0074         names.emplace_back(name);
0075         ++solids;
0076       }
0077     }
0078 
0079   } else {
0080     const DDCompactView* cpv = &iSetup.getData(cpvTokenDDD_);
0081     const auto& gra = cpv->graph();
0082     for (DDCompactView::Graph::const_adj_iterator git = gra.begin(); git != gra.end(); ++git) {
0083       const DDLogicalPart& ddLP = gra.nodeData(git);
0084       const DDSolid& solid = ddLP.solid();
0085       edm::LogVerbatim("PrintGeom") << solid.name() << "   " << DDSolidShapesName::name(solid.shape());
0086       ++solids;
0087     }
0088   }
0089   edm::LogVerbatim("PrintGeom") << "\n\nPrintGeomSolids finds " << solids << " solids";
0090 }
0091 
0092 //define this as a plug-in
0093 DEFINE_FWK_MODULE(PrintGeomSolids);