CMS 3D CMS Logo

RunInfoTestESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondTools/RunInfo
4 // Class: RunInfoTestESProducer
5 //
13 //
14 // Original Author: Christopher Jones
15 // Created: Wed, 02 Oct 2019 17:34:35 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
27 
30 
31 //
32 // class declaration
33 //
34 
36 public:
38 
39  using ReturnType = std::unique_ptr<RunInfo>;
40 
42 
43  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
44 
45 private:
47  // ----------member data ---------------------------
48  std::vector<RunInfo> runInfos_;
49 };
50 
51 //
52 // constants, enums and typedefs
53 //
54 namespace {
55  bool ri_less(RunInfo const& iLHS, RunInfo const& iRHS) { return iLHS.m_run < iRHS.m_run; }
56 } // namespace
57 
58 //
59 // static data member definitions
60 //
61 
62 //
63 // constructors and destructor
64 //
66  std::vector<edm::ParameterSet> const& runInfos = iConfig.getParameter<std::vector<edm::ParameterSet>>("runInfos");
67  runInfos_.reserve(runInfos.size());
68  for (auto const& pset : runInfos) {
69  runInfos_.emplace_back(makeRunInfo(pset));
70  }
71  std::sort(runInfos_.begin(), runInfos_.end(), ri_less);
72 
73  setWhatProduced(this);
74 }
75 
76 //
77 // member functions
78 //
79 
80 // ------------ method called to produce the data ------------
82  const int run = iRecord.validityInterval().first().eventID().run();
83  RunInfo toFind;
84  toFind.m_run = run;
85  auto itFound = std::lower_bound(runInfos_.begin(), runInfos_.end(), toFind, ri_less);
86  if (itFound == runInfos_.end() or itFound->m_run != run) {
87  return nullptr;
88  }
89  return std::make_unique<RunInfo>(*itFound);
90 }
91 
93  RunInfo retValue;
94  retValue.m_run = pset.getParameter<int>("run");
95  retValue.m_start_time_ll = pset.getParameter<long long>("start_time");
96  retValue.m_start_time_str = pset.getParameter<std::string>("start_time_str");
97  retValue.m_stop_time_ll = pset.getParameter<long long>("stop_time");
98  retValue.m_stop_time_str = pset.getParameter<std::string>("stop_time_str");
99  retValue.m_fed_in = pset.getParameter<std::vector<int>>("fed_in");
100  retValue.m_start_current = pset.getParameter<double>("start_current");
101  retValue.m_stop_current = pset.getParameter<double>("stop_current");
102  retValue.m_avg_current = pset.getParameter<double>("avg_current");
103  retValue.m_min_current = pset.getParameter<double>("min_current");
104  retValue.m_max_current = pset.getParameter<double>("max_current");
105  retValue.m_run_intervall_micros = pset.getParameter<double>("run_intervall_micros");
106 
107  auto convert = [](std::vector<double> const& iIn) {
108  std::vector<float> f;
109  f.reserve(iIn.size());
110  std::copy(iIn.begin(), iIn.end(), std::back_inserter(f));
111  return f;
112  };
113 
114  retValue.m_current = convert(pset.getParameter<std::vector<double>>("current"));
115  retValue.m_times_of_currents = convert(pset.getParameter<std::vector<double>>("times_of_currents"));
116 
117  return retValue;
118 }
119 
121  edm::ParameterSetDescription runInfoDesc;
122  runInfoDesc.add<int>("run");
123  runInfoDesc.add<long long>("start_time", 0);
124  runInfoDesc.add<std::string>("start_time_str", "");
125  runInfoDesc.add<long long>("stop_time", 0);
126  runInfoDesc.add<std::string>("stop_time_str", "");
127  runInfoDesc.add<std::vector<int>>("fed_in", {});
128  runInfoDesc.add<double>("start_current", 0);
129  runInfoDesc.add<double>("stop_current", 0);
130  runInfoDesc.add<double>("avg_current", 0);
131  runInfoDesc.add<double>("min_current", 0);
132  runInfoDesc.add<double>("max_current", 0);
133  runInfoDesc.add<double>("run_intervall_micros", 0);
134  runInfoDesc.add<std::vector<double>>("current", {});
135  runInfoDesc.add<std::vector<double>>("times_of_currents", {});
136 
138  desc.addVPSet("runInfos", runInfoDesc, {});
139 
140  descriptions.addDefault(desc);
141 }
142 
143 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
const EventID & eventID() const
Definition: IOVSyncValue.h:40
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void addDefault(ParameterSetDescription const &psetDescription)
ReturnType produce(const RunInfoRcd &)
std::vector< int > m_fed_in
Definition: RunInfo.h:25
std::string m_start_time_str
Definition: RunInfo.h:22
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::unique_ptr< RunInfo > ReturnType
std::vector< RunInfo > runInfos_
double f[11][100]
RunInfo makeRunInfo(edm::ParameterSet const &pset) const
std::vector< float > m_current
Definition: RunInfo.h:32
ParameterDescriptionBase * add(U const &iLabel, T const &value)
def convert(infile, ofile)
float m_stop_current
Definition: RunInfo.h:27
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
long long m_stop_time_ll
Definition: RunInfo.h:23
ValidityInterval validityInterval() const
float m_min_current
Definition: RunInfo.h:30
float m_avg_current
Definition: RunInfo.h:28
float m_run_intervall_micros
Definition: RunInfo.h:31
float m_max_current
Definition: RunInfo.h:29
float m_start_current
Definition: RunInfo.h:26
std::string m_stop_time_str
Definition: RunInfo.h:24
const IOVSyncValue & first() const
int m_run
Definition: RunInfo.h:20
std::vector< float > m_times_of_currents
Definition: RunInfo.h:33
long long m_start_time_ll
Definition: RunInfo.h:21
RunInfoTestESProducer(const edm::ParameterSet &)