CMS 3D CMS Logo

PCLMetadataWriter.cc
Go to the documentation of this file.
1 
7 // system includes
8 #include <string>
9 #include <vector>
10 #include <iostream>
11 
12 // cmssw includes
22 
23 class PCLMetadataWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
24 public:
27 
29  ~PCLMetadataWriter() override = default;
30 
31  // Operations
32  void analyze(const edm::Event &, const edm::EventSetup &) override{};
33  void beginRun(const edm::Run &, const edm::EventSetup &) override{};
34  void endRun(const edm::Run &, const edm::EventSetup &) override;
35 
36 protected:
37 private:
39  bool readFromDB;
40  std::map<std::string, std::map<std::string, std::string>> recordMap;
41 };
42 
43 using namespace std;
44 using namespace edm;
45 
48  readFromDB = pSet.getParameter<bool>("readFromDB");
49 
50  vector<ParameterSet> recordsToMap = pSet.getParameter<vector<ParameterSet>>("recordsToMap");
51  for (const auto &recordPset : recordsToMap) {
52  // record is the key which identifies one set of metadata in
53  // DropBoxMetadataRcd (not necessarily a record in the strict framework
54  // sense)
55  string record = recordPset.getUntrackedParameter<string>("record");
56 
57  map<string, string> jrInfo;
58  if (!readFromDB) {
59  vector<string> paramKeys = recordPset.getParameterNames();
60  for (const auto &key : paramKeys) {
61  jrInfo["Source"] = "AlcaHarvesting";
62  jrInfo["FileClass"] = "ALCA";
63  if (key != "record") {
64  jrInfo[key] = recordPset.getUntrackedParameter<string>(key);
65  }
66  }
67  }
68  recordMap[record] = jrInfo;
69  }
70 }
71 
73  const DropBoxMetadata *metadata = nullptr;
74 
75  if (readFromDB) {
76  // Read the objects
77  metadata = &eSetup.getData(dropBoxToken_);
78  }
79 
80  // get the PoolDBOutputService
82  if (poolDbService.isAvailable()) {
84  if (jr.isAvailable()) {
85  // the filename is unique for all records
86  string filename = poolDbService->session().connectionString();
87 
88  // loop over all records
89  for (const auto &recordAndMap : recordMap) {
90  string record = recordAndMap.first;
91 
92  // this is the map of metadata that we write in the JR
93  map<string, string> jrInfo = recordAndMap.second;
94  if (readFromDB) {
95  if (metadata->knowsRecord(record)) {
96  jrInfo = metadata->getRecordParameters(record).getParameterMap();
97  }
98  }
99 
100  // name of the the input tag in the metadata for the condUploader
101  // metadata needs to be the same as the tag written out by the
102  // harvesting step
103  jrInfo["inputtag"] = poolDbService->tag(record);
104 
105  // actually write in the job report
106  jr->reportAnalysisFile(filename, jrInfo);
107  }
108  }
109  }
110 }
111 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
~PCLMetadataWriter() override=default
Destructor.
PCLMetadataWriter(const edm::ParameterSet &)
Constructor.
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::ESGetToken< DropBoxMetadata, DropBoxMetadataRcd > dropBoxToken_
std::string tag(const std::string &recordName)
std::map< std::string, std::map< std::string, std::string > > recordMap
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string connectionString()
Definition: Session.cc:216
void endRun(const edm::Run &, const edm::EventSetup &) override
HLT enums.
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:509
void beginRun(const edm::Run &, const edm::EventSetup &) override
bool isAvailable() const
Definition: Service.h:40
Definition: Run.h:45
cond::persistency::Session session() const