Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:22

0001 // -*- C++ -*-
0002 //
0003 // Package:    CondTools/RunInfo
0004 // Class:      MagFieldConfigTestESProducer
0005 //
0006 /**\class MagFieldConfigTestESProducer
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Christopher Jones
0015 //         Created:  Wed, 02 Oct 2019 17:34:35 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <unordered_map>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/ModuleFactory.h"
0025 #include "FWCore/Framework/interface/ESProducer.h"
0026 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0028 
0029 #include "CondFormats/MFObjects/interface/MagFieldConfig.h"
0030 #include "CondFormats/DataRecord/interface/MagFieldConfigRcd.h"
0031 
0032 //
0033 // class declaration
0034 //
0035 
0036 class MagFieldConfigTestESProducer : public edm::ESProducer {
0037 public:
0038   MagFieldConfigTestESProducer(const edm::ParameterSet&);
0039 
0040   using ReturnType = std::unique_ptr<MagFieldConfig>;
0041 
0042   ReturnType produce(const MagFieldConfigRcd&);
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046 private:
0047   std::pair<unsigned int, MagFieldConfig> makeMagFieldConfig(edm::ParameterSet const& pset) const;
0048   // ----------member data ---------------------------
0049   std::unordered_map<unsigned int, MagFieldConfig> configs_;
0050 };
0051 
0052 //
0053 // constants, enums and typedefs
0054 //
0055 
0056 //
0057 // static data member definitions
0058 //
0059 
0060 //
0061 // constructors and destructor
0062 //
0063 MagFieldConfigTestESProducer::MagFieldConfigTestESProducer(const edm::ParameterSet& iConfig) {
0064   std::vector<edm::ParameterSet> const& configs = iConfig.getParameter<std::vector<edm::ParameterSet>>("configs");
0065   configs_.reserve(configs.size());
0066   for (auto const& pset : configs) {
0067     configs_.insert(makeMagFieldConfig(pset));
0068   }
0069 
0070   setWhatProduced(this);
0071 }
0072 
0073 //
0074 // member functions
0075 //
0076 
0077 // ------------ method called to produce the data  ------------
0078 MagFieldConfigTestESProducer::ReturnType MagFieldConfigTestESProducer::produce(const MagFieldConfigRcd& iRecord) {
0079   const unsigned int run = iRecord.validityInterval().first().eventID().run();
0080 
0081   auto itFound = configs_.find(run);
0082   if (itFound == configs_.end()) {
0083     return nullptr;
0084   }
0085   return std::make_unique<MagFieldConfig>(itFound->second);
0086 }
0087 
0088 std::pair<unsigned int, MagFieldConfig> MagFieldConfigTestESProducer::makeMagFieldConfig(
0089     edm::ParameterSet const& pset) const {
0090   return std::pair<unsigned int, MagFieldConfig>(pset.getParameter<unsigned int>("run"),
0091                                                  pset.getParameter<edm::ParameterSet>("config"));
0092 }
0093 
0094 void MagFieldConfigTestESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0095   edm::ParameterSetDescription desc;
0096   {
0097     edm::ParameterSetDescription entryDesc;
0098     entryDesc.add<unsigned int>("run");
0099     {
0100       //Do not enforce what the MagFieldConfig wants
0101       edm::ParameterSetDescription magConfig;
0102       magConfig.setAllowAnything();
0103       entryDesc.add<edm::ParameterSetDescription>("config", magConfig);
0104     }
0105 
0106     desc.addVPSet("configs", entryDesc, {});
0107   }
0108   descriptions.addDefault(desc);
0109 }
0110 
0111 //define this as a plug-in
0112 DEFINE_FWK_EVENTSETUP_MODULE(MagFieldConfigTestESProducer);