File indexing completed on 2024-04-06 12:19:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <iostream>
0020 #include <sstream>
0021 #include <fstream>
0022
0023 #include "Alignment/Geners/interface/StringArchive.hh"
0024 #include "Alignment/Geners/interface/CompressedIO.hh"
0025
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/stream/EDAnalyzer.h"
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/EventSetup.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 #include "FWCore/Framework/interface/ESHandle.h"
0032
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034
0035 #include "CondFormats/JetMETObjects/interface/FFTJetCorrectorParameters.h"
0036 #include "CondFormats/DataRecord/interface/FFTJetCorrectorParametersRcdTypes.h"
0037
0038 #include "JetMETCorrections/FFTJetObjects/interface/FFTJetCorrectorParametersLoader.h"
0039
0040 #define init_param(type, varname) varname(ps.getParameter<type>(#varname))
0041
0042
0043
0044
0045 class FFTJetCorrectorDBReader : public edm::stream::EDAnalyzer<> {
0046 public:
0047 explicit FFTJetCorrectorDBReader(const edm::ParameterSet&);
0048 FFTJetCorrectorDBReader() = delete;
0049 FFTJetCorrectorDBReader(const FFTJetCorrectorDBReader&) = delete;
0050 FFTJetCorrectorDBReader& operator=(const FFTJetCorrectorDBReader&) = delete;
0051 ~FFTJetCorrectorDBReader() override {}
0052
0053 private:
0054 void analyze(const edm::Event&, const edm::EventSetup&) override;
0055
0056 std::string record;
0057 std::string outputFile;
0058 bool printAsString;
0059 bool readArchive;
0060 bool isArchiveCompressed;
0061
0062 FFTJetCorrectorParametersLoader esLoader;
0063 };
0064
0065 FFTJetCorrectorDBReader::FFTJetCorrectorDBReader(const edm::ParameterSet& ps)
0066 : init_param(std::string, record),
0067 init_param(std::string, outputFile),
0068 init_param(bool, printAsString),
0069 init_param(bool, readArchive),
0070 init_param(bool, isArchiveCompressed) {
0071 esLoader.acquireToken(record, consumesCollector());
0072 }
0073
0074 void FFTJetCorrectorDBReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0075 edm::ESHandle<FFTJetCorrectorParameters> JetCorParams = esLoader.load(record, iSetup);
0076
0077 if (printAsString || readArchive)
0078 std::cout << "++++ FFTJetCorrectorDBReader: info for record \"" << record << '"' << std::endl;
0079
0080 if (printAsString)
0081 std::cout << "++++ String rep: \"" << JetCorParams->str() << '"' << std::endl;
0082 else if (readArchive) {
0083 std::unique_ptr<gs::StringArchive> par;
0084
0085 {
0086 std::istringstream is(JetCorParams->str());
0087 if (isArchiveCompressed)
0088 par = gs::read_compressed_item<gs::StringArchive>(is);
0089 else
0090 par = gs::read_item<gs::StringArchive>(is);
0091 }
0092
0093 const unsigned long long idSmall = par->smallestId();
0094 if (!idSmall)
0095 std::cout << "++++ No valid records in the archive" << std::endl;
0096 else {
0097 std::cout << "++++ Archive metadata begins" << std::endl;
0098 const unsigned long long idLarge = par->largestId();
0099 unsigned long long count = 0;
0100 for (unsigned long long id = idSmall; id <= idLarge; ++id)
0101 if (par->itemExists(id)) {
0102 std::shared_ptr<const gs::CatalogEntry> e = par->catalogEntry(id);
0103 std::cout << '\n';
0104 e->humanReadable(std::cout);
0105 ++count;
0106 }
0107 std::cout << "\n++++ Archive metadata ends, " << count << " items total" << std::endl;
0108 }
0109 }
0110
0111 if (!outputFile.empty()) {
0112 std::ofstream of(outputFile.c_str(), std::ios_base::binary);
0113 if (!of.is_open())
0114 throw cms::Exception("InvalidArgument") << "Failed to open file \"" << outputFile << '"' << std::endl;
0115 if (!JetCorParams->empty()) {
0116 of.write(JetCorParams->getBuffer(), JetCorParams->length());
0117 if (of.fail())
0118 throw cms::Exception("SystemError")
0119 << "Output stream failure while writing file \"" << outputFile << '"' << std::endl;
0120 }
0121 }
0122 }
0123
0124 DEFINE_FWK_MODULE(FFTJetCorrectorDBReader);