CMS 3D CMS Logo

PCLMetadataWriter.cc
Go to the documentation of this file.
1 
16 
17 #include <string>
18 #include <vector>
19 #include <iostream>
20 
21 class PCLMetadataWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
22 public:
25 
27  ~PCLMetadataWriter() override = default;
28 
29  // Operations
30  void analyze(const edm::Event &, const edm::EventSetup &) override;
31  void beginRun(const edm::Run &, const edm::EventSetup &) override;
32  void endRun(const edm::Run &, const edm::EventSetup &) override;
33 
34 protected:
35 private:
37  bool readFromDB;
38  std::map<std::string, std::map<std::string, std::string>> recordMap;
39 };
40 
41 using namespace std;
42 using namespace edm;
43 
46  readFromDB = pSet.getParameter<bool>("readFromDB");
47 
48  vector<ParameterSet> recordsToMap = pSet.getParameter<vector<ParameterSet>>("recordsToMap");
49  for (vector<ParameterSet>::const_iterator recordPset = recordsToMap.begin(); recordPset != recordsToMap.end();
50  ++recordPset) {
51  // record is the key which identifies one set of metadata in
52  // DropBoxMetadataRcd (not necessarily a record in the strict framework
53  // sense)
54  string record = (*recordPset).getUntrackedParameter<string>("record");
55 
56  map<string, string> jrInfo;
57  if (!readFromDB) {
58  vector<string> paramKeys = (*recordPset).getParameterNames();
59  for (vector<string>::const_iterator key = paramKeys.begin(); key != paramKeys.end(); ++key) {
60  jrInfo["Source"] = "AlcaHarvesting";
61  jrInfo["FileClass"] = "ALCA";
62  if (*key != "record") {
63  jrInfo[*key] = (*recordPset).getUntrackedParameter<string>(*key);
64  }
65  }
66  }
67  recordMap[record] = jrInfo;
68  }
69 }
70 
72 
74 
76  const DropBoxMetadata *metadata = nullptr;
77 
78  if (readFromDB) {
79  // Read the objects
80  metadata = &eSetup.getData(dropBoxToken_);
81  }
82 
83  // get the PoolDBOutputService
85  if (poolDbService.isAvailable()) {
87  if (jr.isAvailable()) {
88  // the filename is unique for all records
89  string filename = poolDbService->session().connectionString();
90 
91  // loop over all records
92  for (map<string, map<string, string>>::const_iterator recordAndMap = recordMap.begin();
93  recordAndMap != recordMap.end();
94  ++recordAndMap) {
95  string record = (*recordAndMap).first;
96 
97  // this is the map of metadata that we write in the JR
98  map<string, string> jrInfo = (*recordAndMap).second;
99  if (readFromDB) {
100  if (metadata->knowsRecord(record)) {
101  jrInfo = metadata->getRecordParameters(record).getParameterMap();
102  }
103  }
104 
105  // name of the the input tag in the metadata for the condUploader
106  // metadata needs to be the same as the tag written out by the
107  // harvesting step
108  jrInfo["inputtag"] = poolDbService->tag(record);
109 
110  // actually write in the job report
111  jr->reportAnalysisFile(filename, jrInfo);
112  }
113  }
114  }
115 }
116 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
~PCLMetadataWriter() override=default
Destructor.
PCLMetadataWriter(const edm::ParameterSet &)
Constructor.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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:473
void beginRun(const edm::Run &, const edm::EventSetup &) override
bool isAvailable() const
Definition: Service.h:40
Definition: event.py:1
Definition: Run.h:45
cond::persistency::Session session() const