1 #ifndef CondCore_Utilities_PayloadInspector_h 2 #define CondCore_Utilities_PayloadInspector_h 11 #include <boost/uuid/uuid.hpp> 12 #include <boost/uuid/uuid_generators.hpp> 13 #include <boost/uuid/uuid_io.hpp> 17 namespace payloadInspector {
30 std::map<std::string, std::string>
m;
41 ss <<
"\"" << entryLabel <<
"\":" <<
value;
48 ss <<
"\"" << entryLabel <<
"\":\"" << value <<
"\"";
56 ss << serializeValue(entryLabel, std::get<0>(
value));
74 ss <<
"\"version\": \"" << JSON_FORMAT_VERSION <<
"\",";
75 ss <<
"\"annotations\": {";
77 for (
auto a : annotations.
m) {
80 ss <<
"\"" <<
a.first <<
"\":\"" <<
a.second <<
"\"";
87 template <
typename X,
typename Y>
107 template <
typename X,
typename Y,
typename Z>
110 std::stringstream
ss;
116 for (
auto d :
data) {
129 std::stringstream
ss;
133 ss <<
"\"file\": \"" << imageFileName <<
"\"";
157 bool isSingleIov()
const;
160 bool isTwoTags()
const;
173 bool processTwoTags(
const std::string& connectionString,
185 virtual std::string processData(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs);
188 void setSingleIov(
bool flag);
190 void setTwoTags(
bool flag);
193 template <
typename PayloadType>
195 return m_dbSession.fetchPayload<PayloadType>(payloadHash);
219 template <
typename PayloadType,
typename X,
typename Y>
230 ~
Plot2D()
override =
default;
235 return serializeData();
239 return PlotBase::fetchPayload<PayloadType>(payloadHash);
242 virtual bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) = 0;
248 template <
typename PayloadType,
typename X,
typename Y,
typename Z>
264 ~
Plot3D()
override =
default;
269 return serializeData();
273 return PlotBase::fetchPayload<PayloadType>(payloadHash);
276 virtual bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) = 0;
282 template <
typename PayloadType,
typename Y>
289 bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)
override {
290 for (
auto iov : iovs) {
291 std::shared_ptr<PayloadType>
payload = Base::fetchPayload(std::get<1>(iov));
293 Y value = getFromPayload(*payload);
294 Base::m_plotData.push_back(std::make_tuple(std::get<0>(iov), value));
300 virtual Y getFromPayload(PayloadType&
payload) = 0;
303 template <
typename PayloadType,
typename Y>
309 : Base(
"RunHistory", title,
"iov_since", yLabel) {}
311 bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)
override {
313 std::map<cond::Time_t, unsigned int>
runs;
316 for (
auto iov : iovs) {
317 unsigned int run = std::get<0>(iov) >> 32;
318 auto it = runs.find(run);
319 if (it == runs.end())
320 it = runs.insert(std::make_pair(run, 0)).first;
324 unsigned int currentRun = 0;
326 unsigned int lumiSize = 0;
327 unsigned int rind = 0;
330 for (
auto iov : iovs) {
331 unsigned long long since = std::get<0>(iov);
334 unsigned int run = since >> 32;
335 unsigned int lumi = since & 0xFFFFFFFF;
336 if (run != currentRun) {
339 auto it = runs.find(run);
340 if (it == runs.end()) {
344 lumiSize = it->second;
348 ind = rind + (lumiIndex / lumiSize);
349 label = std::to_string(run) +
" : " + std::to_string(lumi);
356 label = boost::posix_time::to_simple_string(t);
358 label = std::to_string(since);
361 std::shared_ptr<PayloadType>
payload = Base::fetchPayload(std::get<1>(iov));
363 Y value = getFromPayload(*payload);
364 Base::m_plotData.push_back(std::make_tuple(std::make_tuple(ind, label), value));
370 virtual Y getFromPayload(PayloadType&
payload) = 0;
373 template <
typename PayloadType,
typename Y>
379 : Base(
"TimeHistory", title,
"iov_since", yLabel) {}
381 bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)
override {
391 runInfo = Base::dbSession().getRunInfo(min, max);
393 for (
auto iov : iovs) {
395 boost::posix_time::ptime
time;
398 unsigned int nlumi = since & 0xFFFFFFFF;
401 label = std::to_string(since);
402 auto it = runInfo.
find(since);
403 if (it == runInfo.
end()) {
411 label += (
" : " + std::to_string(nlumi));
415 label = boost::posix_time::to_simple_string(time);
417 std::shared_ptr<PayloadType>
payload = Base::fetchPayload(std::get<1>(iov));
419 Y value = getFromPayload(*payload);
426 virtual Y getFromPayload(PayloadType&
payload) = 0;
429 template <
typename PayloadType,
typename X,
typename Y>
435 : Base(
"Scatter", title, xLabel, yLabel) {}
437 bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)
override {
438 for (
auto iov : iovs) {
439 std::shared_ptr<PayloadType>
payload = Base::fetchPayload(std::get<1>(iov));
441 std::tuple<X, Y>
value = getFromPayload(*payload);
442 Base::m_plotData.push_back(value);
448 virtual std::tuple<X, Y> getFromPayload(PayloadType&
payload) = 0;
452 template <
typename PayloadType>
463 : Base(
"Histo1D", title, xLabel, yLabel), m_nbins(nbins), m_min(min), m_max(max) {}
467 Base::m_plotData.clear();
468 float binSize = (m_max - m_min) / m_nbins;
471 Base::m_plotData.resize(m_nbins);
472 for (
size_t i = 0;
i < m_nbins;
i++) {
473 Base::m_plotData[
i] = std::make_tuple(m_min +
i * m_binSize, 0);
481 if (!Base::m_plotData.
empty() && (value < m_max) && (value >= m_min)) {
482 size_t ibin = (value - m_min) / m_binSize;
483 std::get<1>(Base::m_plotData[ibin]) +=
weight;
489 if (bin >= 0 && bin < Base::m_plotData.
size()) {
490 std::get<1>(Base::m_plotData[
bin]) =
weight;
495 bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)
override {
496 for (
auto iov : iovs) {
497 std::shared_ptr<PayloadType>
payload = Base::fetchPayload(std::get<1>(iov));
499 float value = getFromPayload(*payload);
500 fillWithValue(value);
517 template <
typename PayloadType>
531 : Base(
"Histo2D", title, xLabel, yLabel,
"entries"),
542 Base::m_plotData.clear();
543 float xbinSize = (m_xmax - m_xmin) / m_nxbins;
544 float ybinSize = (m_ymax - m_ymin) / m_nybins;
545 if (xbinSize > 0 && ybinSize > 0) {
546 m_xbinSize = xbinSize;
547 m_ybinSize = ybinSize;
548 Base::m_plotData.resize(m_nxbins * m_nybins);
549 for (
size_t i = 0;
i < m_nybins;
i++) {
550 for (
size_t j = 0;
j < m_nxbins;
j++) {
551 Base::m_plotData[
i * m_nxbins +
j] = std::make_tuple(m_xmin +
j * m_xbinSize, m_ymin +
i * m_ybinSize, 0);
560 if (!Base::m_plotData.
empty() && xvalue < m_xmax && xvalue >= m_xmin && yvalue < m_ymax && yvalue >= m_ymin) {
561 size_t ixbin = (xvalue - m_xmin) / m_xbinSize;
562 size_t iybin = (yvalue - m_ymin) / m_ybinSize;
563 std::get<2>(Base::m_plotData[iybin * m_nxbins + ixbin]) +=
weight;
568 bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)
override {
569 for (
auto iov : iovs) {
570 std::shared_ptr<PayloadType>
payload = Base::fetchPayload(std::get<1>(iov));
572 std::tuple<float, float>
value = getFromPayload(*payload);
573 fillWithValue(std::get<0>(value), std::get<1>(value));
583 return std::make_tuple(x, y);
588 float m_xbinSize = 0;
591 float m_ybinSize = 0;
598 template <
typename PayloadType>
604 std::string payloadTypeName = cond::demangledName(
typeid(PayloadType));
606 m_imageFileName = boost::lexical_cast<
std::string>((boost::uuids::random_generator())()) +
".png";
613 return serializeData();
617 return PlotBase::fetchPayload<PayloadType>(payloadHash);
620 virtual bool fill(
const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) = 0;
std::vector< std::tuple< X, Y > > m_plotData
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
Plot2D< PayloadType, std::tuple< float, std::string >, Y > Base
const boost::posix_time::ptime time0
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
std::string serializeData()
static const char *const JSON_FORMAT_VERSION
std::string m_imageFileName
std::string serializeData()
void fillWithValue(float xvalue, float yvalue, float weight=1)
static const char *const ZAXIS_K
ScatterPlot(const std::string &title, const std::string &xLabel, const std::string &yLabel)
virtual float getFromPayload(PayloadType &payload)
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
std::string processData(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
unsigned long long Time_t
static const char *const PLOT_TYPE_K
static const char *const INFO_K
virtual std::tuple< float, float > getFromPayload(PayloadType &payload)
std::string serializeValue(const std::string &entryLabel, const V &value)
PlotAnnotations m_plotAnnotations
std::vector< std::tuple< X, Y, Z > > m_plotData
Plot2D< PayloadType, X, Y > Base
std::string processData(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
RunHistoryPlot(const std::string &title, const std::string &yLabel)
static const char *const YAXIS_K
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
std::string serialize(const PlotAnnotations &annotations, const std::vector< std::tuple< X, Y > > &data)
void fillWithValue(float value, float weight=1)
Plot2D< PayloadType, std::tuple< unsigned long long, std::string >, Y > Base
Time_t from_boost(boost::posix_time::ptime bt)
static const char *const PAYLOAD_TYPE_K
const unsigned int SECONDS_PER_LUMI(23)
Plot3D(const std::string &type, const std::string &title, const std::string xLabel, const std::string &yLabel, const std::string &zLabel)
Histogram1D(const std::string &title, const std::string &xLabel, size_t nbins, float min, float max, const std::string &yLabel="entries")
void fillWithBinAndValue(size_t bin, float weight=1)
std::string processData(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
static const char *const TITLE_K
std::string serializeData()
TimeHistoryPlot(const std::string &title, const std::string &yLabel)
Iterator find(Time_t target) const
HistoryPlot(const std::string &title, const std::string &yLabel)
std::string serializeAnnotations(const PlotAnnotations &annotations)
Histogram2D(const std::string &title, const std::string &xLabel, size_t nxbins, float xmin, float xmax, const std::string &yLabel, size_t nybins, float ymin, float ymax)
char data[epos_bytes_allocation]
cond::persistency::Session m_dbSession
std::map< std::string, std::string > m
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Plot2D< PayloadType, float, float > Base
Plot3D< PayloadType, float, float, float > Base
Plot2D(const std::string &type, const std::string &title, const std::string xLabel, const std::string &yLabel)
static const char *const XAXIS_K
Plot2D< PayloadType, unsigned long long, Y > Base
boost::posix_time::ptime to_boost(Time_t iValue)
PlotImage(const std::string &title)