File indexing completed on 2024-09-07 04:35:19
0001
0002
0003
0004
0005
0006
0007
0008 #include <string>
0009 #include <vector>
0010 #include <iostream>
0011
0012
0013 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0014 #include "CondFormats/Common/interface/DropBoxMetadata.h"
0015 #include "CondFormats/DataRecord/interface/DropBoxMetadataRcd.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0019 #include "FWCore/MessageLogger/interface/JobReport.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/ServiceRegistry/interface/Service.h"
0022
0023 class PCLMetadataWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0024 public:
0025
0026 PCLMetadataWriter(const edm::ParameterSet &);
0027
0028
0029 ~PCLMetadataWriter() override = default;
0030
0031
0032 void analyze(const edm::Event &, const edm::EventSetup &) override {}
0033 void beginRun(const edm::Run &, const edm::EventSetup &) override {}
0034 void endRun(const edm::Run &, const edm::EventSetup &) override;
0035
0036 protected:
0037 private:
0038 const edm::ESGetToken<DropBoxMetadata, DropBoxMetadataRcd> dropBoxToken_;
0039 bool readFromDB;
0040 std::map<std::string, std::map<std::string, std::string>> recordMap;
0041 };
0042
0043 using namespace std;
0044 using namespace edm;
0045
0046 PCLMetadataWriter::PCLMetadataWriter(const edm::ParameterSet &pSet)
0047 : dropBoxToken_(esConsumes<DropBoxMetadata, DropBoxMetadataRcd, edm::Transition::EndRun>()) {
0048 readFromDB = pSet.getParameter<bool>("readFromDB");
0049
0050 vector<ParameterSet> recordsToMap = pSet.getParameter<vector<ParameterSet>>("recordsToMap");
0051 for (const auto &recordPset : recordsToMap) {
0052
0053
0054
0055 string record = recordPset.getUntrackedParameter<string>("record");
0056
0057 map<string, string> jrInfo;
0058 if (!readFromDB) {
0059 vector<string> paramKeys = recordPset.getParameterNames();
0060 for (const auto &key : paramKeys) {
0061 jrInfo["Source"] = "AlcaHarvesting";
0062 jrInfo["FileClass"] = "ALCA";
0063 if (key != "record") {
0064 jrInfo[key] = recordPset.getUntrackedParameter<string>(key);
0065 }
0066 }
0067 }
0068 recordMap[record] = jrInfo;
0069 }
0070 }
0071
0072 void PCLMetadataWriter::endRun(const edm::Run &run, const edm::EventSetup &eSetup) {
0073 const DropBoxMetadata *metadata = nullptr;
0074
0075 if (readFromDB) {
0076
0077 metadata = &eSetup.getData(dropBoxToken_);
0078 }
0079
0080
0081 Service<cond::service::PoolDBOutputService> poolDbService;
0082 if (poolDbService.isAvailable()) {
0083 edm::Service<edm::JobReport> jr;
0084 if (jr.isAvailable()) {
0085
0086 string filename = poolDbService->session().connectionString();
0087
0088
0089 for (const auto &recordAndMap : recordMap) {
0090 string record = recordAndMap.first;
0091
0092
0093 map<string, string> jrInfo = recordAndMap.second;
0094 if (readFromDB) {
0095 if (metadata->knowsRecord(record)) {
0096 jrInfo = metadata->getRecordParameters(record).getParameterMap();
0097 }
0098 }
0099
0100
0101
0102
0103 jrInfo["inputtag"] = poolDbService->tag(record);
0104
0105
0106 jr->reportAnalysisFile(filename, jrInfo);
0107 }
0108 }
0109 }
0110 }
0111
0112 #include "FWCore/Framework/interface/MakerMacros.h"
0113 DEFINE_FWK_MODULE(PCLMetadataWriter);