Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:58

0001 
0002 /** \class ProduceDropBoxMetadata
0003  *  Create an sqlite file containing the 
0004  *  DropBoxMetadata needed for the PCL uploads
0005  *
0006  *  $Date: 2011/02/22 11:05:16 $
0007  *  $Revision: 1.4 $
0008  *  \author G. Cerminara - CERN
0009  *  Modifications T. Vami - JHU
0010  */
0011 
0012 #include <iostream>
0013 #include <vector>
0014 #include <string>
0015 
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/ServiceRegistry/interface/Service.h"
0018 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0019 
0020 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0021 #include "FWCore/Framework/interface/ESHandle.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 
0024 #include "CondFormats/DataRecord/interface/DropBoxMetadataRcd.h"
0025 #include "CondFormats/Common/interface/DropBoxMetadata.h"
0026 #include "CondFormats/Common/src/headers.h"
0027 
0028 #include "FWCore/PluginManager/interface/ModuleDef.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 class ProduceDropBoxMetadata : public edm::one::EDAnalyzer<> {
0032 public:
0033   /// Constructor
0034   explicit ProduceDropBoxMetadata(const edm::ParameterSet&);
0035 
0036   /// Destructor
0037   ~ProduceDropBoxMetadata() override;
0038 
0039 private:
0040   // Operations
0041   void analyze(const edm::Event&, const edm::EventSetup&) override;
0042 
0043   bool read;
0044   bool write;
0045 
0046   std::vector<edm::ParameterSet> fToWrite;
0047   std::vector<std::string> fToRead;
0048 
0049   const edm::ESGetToken<DropBoxMetadata, DropBoxMetadataRcd> dropBoxMetadataToken_;
0050 };
0051 
0052 using namespace std;
0053 using namespace edm;
0054 
0055 ProduceDropBoxMetadata::ProduceDropBoxMetadata(const edm::ParameterSet& pSet) : dropBoxMetadataToken_(esConsumes()) {
0056   read = pSet.getUntrackedParameter<bool>("read");
0057   write = pSet.getUntrackedParameter<bool>("write");
0058 
0059   fToWrite = pSet.getParameter<vector<ParameterSet> >("toWrite");
0060   fToRead = pSet.getUntrackedParameter<vector<string> >("toRead");
0061 }
0062 
0063 ProduceDropBoxMetadata::~ProduceDropBoxMetadata() = default;
0064 
0065 void ProduceDropBoxMetadata::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0066   // ---------------------------------------------------------------------------------
0067   // Write the payload
0068   if (write) {
0069     DropBoxMetadata metadata;
0070 
0071     edm::LogPrint("ProduceDropBoxMetadata") << "Entering write, to loop over toWrite";
0072     // loop over all the pSets for the TF1 that we want to write to DB
0073     for (vector<ParameterSet>::const_iterator fSetup = fToWrite.begin(); fSetup != fToWrite.end(); ++fSetup) {
0074       string record = (*fSetup).getUntrackedParameter<string>("record");
0075       edm::LogPrint("ProduceDropBoxMetadata") << "\n--- record: " << record;
0076       DropBoxMetadata::Parameters params;
0077       vector<string> paramKeys = (*fSetup).getParameterNames();
0078       for (vector<string>::const_iterator key = paramKeys.begin(); key != paramKeys.end(); ++key) {
0079         if (*key != "record") {
0080           string value = (*fSetup).getUntrackedParameter<string>(*key);
0081           params.addParameter(*key, value);
0082           edm::LogPrint("ProduceDropBoxMetadata") << "           key: " << *key << " value: " << value;
0083         }
0084       }
0085       metadata.addRecordParameters(record, params);
0086     }
0087 
0088     // actually write to DB
0089     edm::Service<cond::service::PoolDBOutputService> dbOut;
0090     if (dbOut.isAvailable()) {
0091       dbOut->writeOneIOV<DropBoxMetadata>(metadata, 1, "DropBoxMetadataRcd");
0092     }
0093   }
0094 
0095   if (read) {
0096     // Read the objects
0097     edm::LogPrint("ProduceDropBoxMetadata") << "Entering read, to loop over toRead";
0098     const auto& mdPayload = iSetup.getData(dropBoxMetadataToken_);
0099 
0100     // loop
0101     for (vector<string>::const_iterator name = fToRead.begin(); name != fToRead.end(); ++name) {
0102       edm::LogPrint("ProduceDropBoxMetadata") << "\n--- record: " << *name;
0103       if (mdPayload.knowsRecord(*name)) {
0104         const map<string, string>& params = mdPayload.getRecordParameters(*name).getParameterMap();
0105         for (map<string, string>::const_iterator par = params.begin(); par != params.end(); ++par) {
0106           edm::LogPrint("ProduceDropBoxMetadata") << "           key: " << par->first << " value: " << par->second;
0107         }
0108       } else {
0109         edm::LogPrint("ProduceDropBoxMetadata") << "     not in the payload!";
0110       }
0111     }
0112   }
0113 }
0114 
0115 DEFINE_FWK_MODULE(ProduceDropBoxMetadata);