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 
cond::service::PoolDBOutputService::tag
std::string tag(const std::string &recordName)
Definition: PoolDBOutputService.cc:124
EDAnalyzer.h
PCLMetadataWriter::~PCLMetadataWriter
~PCLMetadataWriter() override=default
Destructor.
PCLMetadataWriter::readFromDB
bool readFromDB
Definition: PCLMetadataWriter.cc:37
PCLMetadataWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PCLMetadataWriter.cc:71
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::JobReport::reportAnalysisFile
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:473
PCLMetadataWriter::PCLMetadataWriter
PCLMetadataWriter(const edm::ParameterSet &)
Constructor.
Definition: PCLMetadataWriter.cc:44
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
DropBoxMetadata.h
MakerMacros.h
PoolDBOutputService.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
cond::service::PoolDBOutputService::session
cond::persistency::Session session() const
Definition: PoolDBOutputService.cc:92
Service.h
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
TrackingMonitor_cfi.metadata
metadata
Definition: TrackingMonitor_cfi.py:71
PCLMetadataWriter::dropBoxToken_
const edm::ESGetToken< DropBoxMetadata, DropBoxMetadataRcd > dropBoxToken_
Definition: PCLMetadataWriter.cc:36
PCLMetadataWriter::recordMap
std::map< std::string, std::map< std::string, std::string > > recordMap
Definition: PCLMetadataWriter.cc:38
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
cond::persistency::Session::connectionString
std::string connectionString()
Definition: Session.cc:216
edm::Service< cond::service::PoolDBOutputService >
DropBoxMetadata
Definition: DropBoxMetadata.h:17
edm::EventSetup
Definition: EventSetup.h:58
AlCaHarvesting_cff.record
record
Definition: AlCaHarvesting_cff.py:42
PCLMetadataWriter::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: PCLMetadataWriter.cc:73
PCLMetadataWriter::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: PCLMetadataWriter.cc:75
edm::ESGetToken< DropBoxMetadata, DropBoxMetadataRcd >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Frameworkfwd.h
EventSetup.h
DropBoxMetadataRcd
Definition: DropBoxMetadataRcd.h:24
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
PCLMetadataWriter
Definition: PCLMetadataWriter.cc:21
JobReport.h
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
event
Definition: event.py:1
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
edm::Transition::EndRun
crabWrapper.key
key
Definition: crabWrapper.py:19
DropBoxMetadataRcd.h