Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-09 22:35:05

0001 /** \class PCLMetadataWriter
0002  *  No description available.
0003  *
0004  *  \author G. Cerminara - CERN
0005  */
0006 
0007 // system includes
0008 #include <string>
0009 #include <vector>
0010 #include <iostream>
0011 
0012 // cmssw includes
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   /// Constructor
0026   PCLMetadataWriter(const edm::ParameterSet &);
0027 
0028   /// Destructor
0029   ~PCLMetadataWriter() override = default;
0030 
0031   // Operations
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     // record is the key which identifies one set of metadata in
0053     // DropBoxMetadataRcd (not necessarily a record in the strict framework
0054     // sense)
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     // Read the objects
0077     metadata = &eSetup.getData(dropBoxToken_);
0078   }
0079 
0080   // get the PoolDBOutputService
0081   Service<cond::service::PoolDBOutputService> poolDbService;
0082   if (poolDbService.isAvailable()) {
0083     edm::Service<edm::JobReport> jr;
0084     if (jr.isAvailable()) {
0085       // the filename is unique for all records
0086       string filename = poolDbService->session().connectionString();
0087 
0088       // loop over all records
0089       for (const auto &recordAndMap : recordMap) {
0090         string record = recordAndMap.first;
0091 
0092         // this is the map of metadata that we write in the JR
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         // name of the the input tag in the metadata for the condUploader
0101         // metadata needs to be the same as the tag written out by the
0102         // harvesting step
0103         jrInfo["inputtag"] = poolDbService->tag(record);
0104 
0105         // actually write in the job report
0106         jr->reportAnalysisFile(filename, jrInfo);
0107       }
0108     }
0109   }
0110 }
0111 
0112 #include "FWCore/Framework/interface/MakerMacros.h"
0113 DEFINE_FWK_MODULE(PCLMetadataWriter);