1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
// -*- C++ -*-
//
// Package: CondTools/RunInfo
// Class: RunInfoTestESProducer
//
/**\class RunInfoTestESProducer
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author: Christopher Jones
// Created: Wed, 02 Oct 2019 17:34:35 GMT
//
//
// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "CondFormats/RunInfo/interface/RunInfo.h"
#include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
//
// class declaration
//
class RunInfoTestESProducer : public edm::ESProducer {
public:
RunInfoTestESProducer(const edm::ParameterSet&);
using ReturnType = std::unique_ptr<RunInfo>;
ReturnType produce(const RunInfoRcd&);
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
RunInfo makeRunInfo(edm::ParameterSet const& pset) const;
// ----------member data ---------------------------
std::vector<RunInfo> runInfos_;
};
//
// constants, enums and typedefs
//
namespace {
bool ri_less(RunInfo const& iLHS, RunInfo const& iRHS) { return iLHS.m_run < iRHS.m_run; }
} // namespace
//
// static data member definitions
//
//
// constructors and destructor
//
RunInfoTestESProducer::RunInfoTestESProducer(const edm::ParameterSet& iConfig) {
std::vector<edm::ParameterSet> const& runInfos = iConfig.getParameter<std::vector<edm::ParameterSet>>("runInfos");
runInfos_.reserve(runInfos.size());
for (auto const& pset : runInfos) {
runInfos_.emplace_back(makeRunInfo(pset));
}
std::sort(runInfos_.begin(), runInfos_.end(), ri_less);
setWhatProduced(this);
}
//
// member functions
//
// ------------ method called to produce the data ------------
RunInfoTestESProducer::ReturnType RunInfoTestESProducer::produce(const RunInfoRcd& iRecord) {
const int run = iRecord.validityInterval().first().eventID().run();
RunInfo toFind;
toFind.m_run = run;
auto itFound = std::lower_bound(runInfos_.begin(), runInfos_.end(), toFind, ri_less);
if (itFound == runInfos_.end() or itFound->m_run != run) {
return nullptr;
}
return std::make_unique<RunInfo>(*itFound);
}
RunInfo RunInfoTestESProducer::makeRunInfo(edm::ParameterSet const& pset) const {
RunInfo retValue;
retValue.m_run = pset.getParameter<int>("run");
retValue.m_start_time_ll = pset.getParameter<long long>("start_time");
retValue.m_start_time_str = pset.getParameter<std::string>("start_time_str");
retValue.m_stop_time_ll = pset.getParameter<long long>("stop_time");
retValue.m_stop_time_str = pset.getParameter<std::string>("stop_time_str");
retValue.m_fed_in = pset.getParameter<std::vector<int>>("fed_in");
retValue.m_start_current = pset.getParameter<double>("start_current");
retValue.m_stop_current = pset.getParameter<double>("stop_current");
retValue.m_avg_current = pset.getParameter<double>("avg_current");
retValue.m_min_current = pset.getParameter<double>("min_current");
retValue.m_max_current = pset.getParameter<double>("max_current");
retValue.m_run_intervall_micros = pset.getParameter<double>("run_intervall_micros");
auto convert = [](std::vector<double> const& iIn) {
std::vector<float> f;
f.reserve(iIn.size());
std::copy(iIn.begin(), iIn.end(), std::back_inserter(f));
return f;
};
retValue.m_current = convert(pset.getParameter<std::vector<double>>("current"));
retValue.m_times_of_currents = convert(pset.getParameter<std::vector<double>>("times_of_currents"));
return retValue;
}
void RunInfoTestESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription runInfoDesc;
runInfoDesc.add<int>("run");
runInfoDesc.add<long long>("start_time", 0);
runInfoDesc.add<std::string>("start_time_str", "");
runInfoDesc.add<long long>("stop_time", 0);
runInfoDesc.add<std::string>("stop_time_str", "");
runInfoDesc.add<std::vector<int>>("fed_in", {});
runInfoDesc.add<double>("start_current", 0);
runInfoDesc.add<double>("stop_current", 0);
runInfoDesc.add<double>("avg_current", 0);
runInfoDesc.add<double>("min_current", 0);
runInfoDesc.add<double>("max_current", 0);
runInfoDesc.add<double>("run_intervall_micros", 0);
runInfoDesc.add<std::vector<double>>("current", {});
runInfoDesc.add<std::vector<double>>("times_of_currents", {});
edm::ParameterSetDescription desc;
desc.addVPSet("runInfos", runInfoDesc, {});
descriptions.addDefault(desc);
}
//define this as a plug-in
DEFINE_FWK_EVENTSETUP_MODULE(RunInfoTestESProducer);
|