Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:23

0001 // -*- C++ -*-
0002 //
0003 // Package:    CondTools/RunInfo
0004 // Class:      RunInfoTestESProducer
0005 //
0006 /**\class RunInfoTestESProducer
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 
0022 // user include files
0023 #include "FWCore/Framework/interface/ModuleFactory.h"
0024 #include "FWCore/Framework/interface/ESProducer.h"
0025 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 
0028 #include "CondFormats/RunInfo/interface/RunInfo.h"
0029 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
0030 
0031 //
0032 // class declaration
0033 //
0034 
0035 class RunInfoTestESProducer : public edm::ESProducer {
0036 public:
0037   RunInfoTestESProducer(const edm::ParameterSet&);
0038 
0039   using ReturnType = std::unique_ptr<RunInfo>;
0040 
0041   ReturnType produce(const RunInfoRcd&);
0042 
0043   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0044 
0045 private:
0046   RunInfo makeRunInfo(edm::ParameterSet const& pset) const;
0047   // ----------member data ---------------------------
0048   std::vector<RunInfo> runInfos_;
0049 };
0050 
0051 //
0052 // constants, enums and typedefs
0053 //
0054 namespace {
0055   bool ri_less(RunInfo const& iLHS, RunInfo const& iRHS) { return iLHS.m_run < iRHS.m_run; }
0056 }  // namespace
0057 
0058 //
0059 // static data member definitions
0060 //
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 RunInfoTestESProducer::RunInfoTestESProducer(const edm::ParameterSet& iConfig) {
0066   std::vector<edm::ParameterSet> const& runInfos = iConfig.getParameter<std::vector<edm::ParameterSet>>("runInfos");
0067   runInfos_.reserve(runInfos.size());
0068   for (auto const& pset : runInfos) {
0069     runInfos_.emplace_back(makeRunInfo(pset));
0070   }
0071   std::sort(runInfos_.begin(), runInfos_.end(), ri_less);
0072 
0073   setWhatProduced(this);
0074 }
0075 
0076 //
0077 // member functions
0078 //
0079 
0080 // ------------ method called to produce the data  ------------
0081 RunInfoTestESProducer::ReturnType RunInfoTestESProducer::produce(const RunInfoRcd& iRecord) {
0082   const int run = iRecord.validityInterval().first().eventID().run();
0083   RunInfo toFind;
0084   toFind.m_run = run;
0085   auto itFound = std::lower_bound(runInfos_.begin(), runInfos_.end(), toFind, ri_less);
0086   if (itFound == runInfos_.end() or itFound->m_run != run) {
0087     return nullptr;
0088   }
0089   return std::make_unique<RunInfo>(*itFound);
0090 }
0091 
0092 RunInfo RunInfoTestESProducer::makeRunInfo(edm::ParameterSet const& pset) const {
0093   RunInfo retValue;
0094   retValue.m_run = pset.getParameter<int>("run");
0095   retValue.m_start_time_ll = pset.getParameter<long long>("start_time");
0096   retValue.m_start_time_str = pset.getParameter<std::string>("start_time_str");
0097   retValue.m_stop_time_ll = pset.getParameter<long long>("stop_time");
0098   retValue.m_stop_time_str = pset.getParameter<std::string>("stop_time_str");
0099   retValue.m_fed_in = pset.getParameter<std::vector<int>>("fed_in");
0100   retValue.m_start_current = pset.getParameter<double>("start_current");
0101   retValue.m_stop_current = pset.getParameter<double>("stop_current");
0102   retValue.m_avg_current = pset.getParameter<double>("avg_current");
0103   retValue.m_min_current = pset.getParameter<double>("min_current");
0104   retValue.m_max_current = pset.getParameter<double>("max_current");
0105   retValue.m_run_intervall_micros = pset.getParameter<double>("run_intervall_micros");
0106 
0107   auto convert = [](std::vector<double> const& iIn) {
0108     std::vector<float> f;
0109     f.reserve(iIn.size());
0110     std::copy(iIn.begin(), iIn.end(), std::back_inserter(f));
0111     return f;
0112   };
0113 
0114   retValue.m_current = convert(pset.getParameter<std::vector<double>>("current"));
0115   retValue.m_times_of_currents = convert(pset.getParameter<std::vector<double>>("times_of_currents"));
0116 
0117   return retValue;
0118 }
0119 
0120 void RunInfoTestESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0121   edm::ParameterSetDescription runInfoDesc;
0122   runInfoDesc.add<int>("run");
0123   runInfoDesc.add<long long>("start_time", 0);
0124   runInfoDesc.add<std::string>("start_time_str", "");
0125   runInfoDesc.add<long long>("stop_time", 0);
0126   runInfoDesc.add<std::string>("stop_time_str", "");
0127   runInfoDesc.add<std::vector<int>>("fed_in", {});
0128   runInfoDesc.add<double>("start_current", 0);
0129   runInfoDesc.add<double>("stop_current", 0);
0130   runInfoDesc.add<double>("avg_current", 0);
0131   runInfoDesc.add<double>("min_current", 0);
0132   runInfoDesc.add<double>("max_current", 0);
0133   runInfoDesc.add<double>("run_intervall_micros", 0);
0134   runInfoDesc.add<std::vector<double>>("current", {});
0135   runInfoDesc.add<std::vector<double>>("times_of_currents", {});
0136 
0137   edm::ParameterSetDescription desc;
0138   desc.addVPSet("runInfos", runInfoDesc, {});
0139 
0140   descriptions.addDefault(desc);
0141 }
0142 
0143 //define this as a plug-in
0144 DEFINE_FWK_EVENTSETUP_MODULE(RunInfoTestESProducer);