Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-09 23:31:46

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/IdealGeometryRecord.h"
0007 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0008 #include "DD4hep/Detector.h"
0009 #include "DD4hep/DD4hepRootPersistency.h"
0010 
0011 #include "TGeoManager.h"
0012 #include "TFile.h"
0013 #include "TSystem.h"
0014 
0015 #include <iostream>
0016 #include <string>
0017 
0018 using namespace std;
0019 using namespace cms;
0020 using namespace edm;
0021 using namespace dd4hep;
0022 
0023 class DDTestDumpFile : public one::EDAnalyzer<> {
0024 public:
0025   explicit DDTestDumpFile(const ParameterSet&);
0026 
0027   void beginJob() override {}
0028   void analyze(Event const& iEvent, EventSetup const&) override;
0029   void endJob() override {}
0030 
0031 private:
0032   const string m_tag;
0033   const string m_outputFileName;
0034   const ESInputTag m_label;
0035   const ESGetToken<DDDetector, IdealGeometryRecord> m_token;
0036 };
0037 
0038 DDTestDumpFile::DDTestDumpFile(const ParameterSet& iConfig)
0039     : m_tag(iConfig.getUntrackedParameter<string>("tag", "unknown")),
0040       m_outputFileName(iConfig.getUntrackedParameter<string>("outputFileName", "cmsDD4hepGeom.root")),
0041       m_label(iConfig.getParameter<ESInputTag>("DDDetector")),
0042       m_token(esConsumes(m_label)) {}
0043 
0044 void DDTestDumpFile::analyze(const Event&, const EventSetup& iEventSetup) {
0045   LogVerbatim("Geometry") << "DDTestDumpFile::analyze: " << m_label;
0046   ESTransientHandle<DDDetector> det = iEventSetup.getTransientHandle(m_token);
0047 
0048   TGeoManager& geom = det->manager();
0049 
0050   int level = 1 + geom.GetTopVolume()->CountNodes(100, 3);
0051 
0052   LogVerbatim("Geometry") << "In the DDTestDumpFile::analyze method...obtained main geometry, level=" << level;
0053 
0054   TFile file(m_outputFileName.c_str(), "RECREATE");
0055   file.WriteTObject(&geom);
0056   file.WriteTObject(new TNamed("CMSSW_VERSION", gSystem->Getenv("CMSSW_VERSION")));
0057   file.WriteTObject(new TNamed("tag", m_tag.c_str()));
0058   file.Close();
0059 }
0060 
0061 DEFINE_FWK_MODULE(DDTestDumpFile);