File indexing completed on 2024-04-06 12:03:04
0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "FWCore/ServiceRegistry/interface/Service.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "CondFormats/Common/interface/FileBlob.h"
0010 #include "Geometry/Records/interface/GeometryFileRcd.h"
0011
0012 #include <string>
0013 #include <vector>
0014 #include <fstream>
0015
0016 class XMLGeometryReader : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0017 public:
0018 XMLGeometryReader(const edm::ParameterSet&);
0019
0020 void beginJob() override {}
0021 void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
0022 void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0023 void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
0024
0025 private:
0026 std::string m_fname;
0027 std::string m_label;
0028 edm::ESGetToken<FileBlob, GeometryFileRcd> fileBlobToken_;
0029 };
0030
0031 XMLGeometryReader::XMLGeometryReader(const edm::ParameterSet& iConfig) {
0032 m_fname = iConfig.getUntrackedParameter<std::string>("XMLFileName", "test.xml");
0033 m_label = iConfig.getUntrackedParameter<std::string>("geomLabel", "Extended");
0034 fileBlobToken_ = esConsumes<edm::Transition::BeginRun>();
0035 }
0036
0037 void XMLGeometryReader::beginRun(edm::Run const& run, edm::EventSetup const& iSetup) {
0038 edm::LogInfo("XMLGeometryReader") << "XMLGeometryReader::beginRun";
0039
0040 auto geometry = iSetup.getHandle(fileBlobToken_);
0041 std::unique_ptr<std::vector<unsigned char> > blob((*geometry).getUncompressedBlob());
0042
0043 std::string outfile1(m_fname);
0044 std::ofstream output1(outfile1.c_str());
0045 output1.write((const char*)&(*blob)[0], blob->size());
0046 output1.close();
0047 }
0048
0049 DEFINE_FWK_MODULE(XMLGeometryReader);