1 #ifndef CondCore_Utilities_PayloadInspector_h
2 #define CondCore_Utilities_PayloadInspector_h
13 #include <type_traits>
18 #include <pybind11/pybind11.h>
19 #include <pybind11/stl.h>
20 namespace py = pybind11;
27 ret.append(py::make_tuple(tagName, std::to_string(start), std::to_string(end)));
30 __attribute__((visibility(
"default"))) inline py::list mk_input(
const std::
string& tagName0,
33 const std::
string& tagName1,
37 ret.append(py::make_tuple(tagName0, std::to_string(start0), std::to_string(end0)));
38 ret.append(py::make_tuple(tagName1, std::to_string(start1), std::to_string(end1)));
45 namespace payloadInspector {
50 static constexpr
const char*
const TITLE_K =
"title";
52 static constexpr
const char*
const INFO_K =
"info";
53 static constexpr
const char*
const XAXIS_K =
"x_label";
54 static constexpr
const char*
const YAXIS_K =
"y_label";
55 static constexpr
const char*
const ZAXIS_K =
"z_label";
58 std::map<std::string, std::string>
m;
77 if constexpr (std::is_same_v<
V, std::pair<bool, float>>) {
79 ss <<
"\"" << entryLabel <<
"\":" << value.second;
81 }
else if constexpr (std::is_same_v<V, double>) {
82 if ((value -
int(value)) == 0) {
85 ss <<
"\"" << entryLabel <<
"\":" << std::fixed <<
value;
87 ss <<
"\"" << entryLabel <<
"\":" <<
value;
95 ss <<
"\"" << entryLabel <<
"\":\"" << value <<
"\"";
100 template <
typename V>
102 std::stringstream
ss;
103 ss << serializeValue(entryLabel, std::get<0>(
value));
110 template <
typename V>
112 std::stringstream
ss;
120 std::stringstream
ss;
122 ss <<
"\"annotations\": {";
124 for (
const auto&
a : annotations.
m) {
127 ss <<
"\"" <<
a.first <<
"\":\"" <<
a.second <<
"\"";
134 template <
typename X,
typename Y>
137 std::stringstream
ss;
143 for (
auto d :
data) {
151 if (!serializedY.empty()) {
155 ss <<
" { " << serializedX <<
", " << serializedY <<
" }";
164 template <
typename X,
typename Y,
typename Z>
167 std::stringstream
ss;
173 for (
auto d :
data) {
186 std::stringstream
ss;
190 ss <<
"\"file\": \"" << imageFileName <<
"\"";
196 static constexpr
const char*
const label =
"2.0";
201 const std::pair<cond::Time_t, cond::Time_t>&
b,
202 const std::vector<std::tuple<cond::Time_t, cond::Hash>>&
i)
206 const std::pair<cond::Time_t, cond::Time_t>&
boundary;
207 const std::vector<std::tuple<cond::Time_t, cond::Hash>>&
iovs;
225 unsigned int ntags()
const;
234 __attribute__((visibility(
"default"))) py::list inputParams()
const;
244 const py::list& tagsWithTimeBoundaries);
247 bool exec_process(
const std::string& connectionString,
248 const std::vector<std::tuple<std::string, cond::Time_t, cond::Time_t>>& tagsWithTimeBoundaries);
263 template <
typename PayloadType>
273 if (sz == 0 ||
index >= sz) {
290 std::vector<std::vector<std::tuple<cond::Time_t, cond::Hash>>>
m_tagIovs;
305 target.
ntags = NTAGS;
309 template <IOVMultiplicity IOV_M,
int NTAGS>
324 virtual bool fill() = 0;
343 virtual bool fill() = 0;
363 virtual bool fill() = 0;
388 virtual bool fill() = 0;
414 std::vector<std::tuple<cond::Time_t, cond::Hash>> theIovs = PlotBase::getTag<0>().
iovs;
416 auto tag2iovs = PlotBase::getTag<1>().
iovs;
417 size_t oldSize = theIovs.size();
418 size_t newSize = oldSize + tag2iovs.size();
419 theIovs.resize(newSize);
420 for (
size_t i = 0;
i < tag2iovs.size();
i++) {
421 theIovs[
i + oldSize] = tag2iovs[
i];
424 return fill(theIovs);
431 m_singleIovSet =
true;
443 bool m_singleIovSet =
false;
462 std::vector<std::tuple<cond::Time_t, cond::Hash>> theIovs = PlotBase::getTag<0>().
iovs;
464 auto tag2iovs = PlotBase::getTag<1>().
iovs;
465 size_t oldSize = theIovs.size();
466 size_t newSize = oldSize + tag2iovs.size();
467 theIovs.resize(newSize);
468 for (
size_t i = 0;
i < tag2iovs.size();
i++) {
469 theIovs[
i + oldSize] = tag2iovs[
i];
472 return fill(theIovs);
481 template <
typename PayloadType,
typename X,
typename Y, IOVMultiplicity IOV_M = UNSPECIFIED_IOV,
int NTAGS = 0>
495 return PlotBase::fetchPayload<PayloadType>(payloadHash);
502 template <
typename PayloadType,
526 return PlotBase::fetchPayload<PayloadType>(payloadHash);
533 template <
typename PayloadType,
typename Y>
543 auto tag = PlotBase::getTag<0>();
544 for (
auto iov :
tag.iovs) {
556 template <
typename PayloadType,
typename Y>
562 :
Base(
"RunHistory", title,
"iov_since", yLabel) {}
567 auto tag = PlotBase::getTag<0>();
569 std::map<cond::Time_t, unsigned int>
runs;
573 for (
auto iov :
tag.iovs) {
574 unsigned int run = std::get<0>(iov) >> 32;
575 auto it = runs.find(run);
576 if (it == runs.end())
577 it = runs.insert(std::make_pair(run, 0)).first;
581 unsigned int currentRun = 0;
583 unsigned int lumiSize = 0;
584 unsigned int rind = 0;
587 for (
auto iov :
tag.iovs) {
588 unsigned long long since = std::get<0>(iov);
591 unsigned int run = since >> 32;
592 unsigned int lumi = since & 0xFFFFFFFF;
593 if (run != currentRun) {
596 auto it = runs.find(run);
597 if (it == runs.end()) {
601 lumiSize = it->second;
605 ind = rind + (lumiIndex / lumiSize);
606 label = std::to_string(run) +
" : " + std::to_string(lumi);
613 label = boost::posix_time::to_simple_string(t);
615 label = std::to_string(since);
621 Base::m_plotData.push_back(std::make_tuple(std::make_tuple(ind, label), value));
630 template <
typename PayloadType,
typename Y>
636 :
Base(
"TimeHistory", title,
"iov_since", yLabel) {}
640 auto tag = PlotBase::getTag<0>();
653 for (
auto iov :
tag.iovs) {
655 boost::posix_time::ptime time;
658 unsigned int nlumi = since & 0xFFFFFFFF;
661 label = std::to_string(since);
662 auto it = runInfo.find(since);
663 if (it == runInfo.end()) {
671 label += (
" : " + std::to_string(nlumi));
675 label = boost::posix_time::to_simple_string(time);
689 template <
typename PayloadType,
typename X,
typename Y>
695 :
Base(
"Scatter", title, xLabel, yLabel) {}
699 auto tag = PlotBase::getTag<0>();
700 for (
auto iov :
tag.iovs) {
714 template <
typename AxisType,
typename PayloadType, IOVMultiplicity IOV_M = UNSPECIFIED_IOV>
731 <<
" trying to book an histogram with less then 1 bin!" << std::endl;
736 <<
" trying to book an histogram with minimum " <<
m_min <<
"> maximum" <<
m_max <<
" !" << std::endl;
768 auto tag = PlotBase::getTag<0>();
769 for (
auto iov :
tag.iovs) {
793 template <
typename PayloadType, IOVMultiplicity IOV_M = UNSPECIFIED_IOV>
796 template <
typename PayloadType, IOVMultiplicity IOV_M = UNSPECIFIED_IOV>
800 template <
typename PayloadType, IOVMultiplicity IOV_M = UNSPECIFIED_IOV>
814 :
Base(
"Histo2D", title, xLabel, yLabel,
"entries"),
827 <<
" trying to book an histogram with less then 1 bin!" << std::endl;
831 edm::LogError(
"payloadInspector::Histogram2D()") <<
" trying to book an histogram with x-minimum " <<
m_xmin
832 <<
"> x-maximum" <<
m_xmax <<
" !" << std::endl;
836 edm::LogError(
"payloadInspector::Histogram2D()") <<
" trying to book an histogram with y-minimum " <<
m_ymin
837 <<
"> y-maximum" <<
m_ymax <<
" !" << std::endl;
843 if (xbinSize > 0 && ybinSize > 0) {
867 auto tag = PlotBase::getTag<0>();
868 for (
auto iov :
tag.iovs) {
882 return std::make_tuple(x, y);
897 template <
typename PayloadType, IOVMultiplicity IOV_M = UNSPECIFIED_IOV,
int NTAGS = 0>
902 std::string payloadTypeName = cond::demangledName(
typeid(PayloadType));
910 return PlotBase::fetchPayload<PayloadType>(payloadHash);
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash >> &iovs)
std::string m_imageFileName
virtual AxisType getFromPayload(PayloadType &payload)
std::map< std::string, std::string > m_inputParamValues
PlotImage(const std::string &title)
tuple ret
prodAgent to be discontinued
cond::Tag_t getTagInfo(const std::string &tag)
std::string serializeData() override
void fillWithValue(float xvalue, float yvalue, float weight=1)
std::set< std::string > m_inputParams
unsigned int ntags() const
std::string processData() override
Plot2D(const std::string &type, const std::string &title, const std::string xLabel, const std::string &yLabel)
std::vector< std::string > m_tagNames
std::string serializeData() override
void setAnnotations(const std::string &type, const std::string &title, IOVMultiplicity IOV_M, int NTAGS, PlotAnnotations &target)
PlotImpl(const std::string &type, const std::string &title)
static constexpr const char *const PAYLOAD_TYPE_K
Plot2D< PayloadType, X, Y, MULTI_IOV, 1 > Base
void setSingleIov(bool flag)
static constexpr const char *const ZAXIS_K
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
static const char *const JSON_FORMAT_VERSION
PlotImpl(const std::string &type, const std::string &title)
Log< level::Error, false > LogError
Plot3D(const std::string &type, const std::string &title, const std::string xLabel, const std::string &yLabel, const std::string &zLabel)
cond::persistency::Session dbSession()
void throwException(const std::string &message, const std::string &methodName)
static constexpr const char *const PLOT_TYPE_K
Plot2D< PayloadType, unsigned long long, Y, MULTI_IOV, 1 > Base
Plot2D< PayloadType, std::tuple< float, std::string >, Y, MULTI_IOV, 1 > Base
std::string processData() override
ScatterPlot(const std::string &title, const std::string &xLabel, const std::string &yLabel)
std::string serialize(const PlotAnnotations &annotations, const std::vector< std::tuple< X, Y >> &data)
std::vector< std::tuple< X, Y > > m_plotData
std::string processData() override
virtual std::tuple< float, float > getFromPayload(PayloadType &payload)
void setSingleIov(bool flag)
std::string processData() override
unsigned long long Time_t
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
PlotImpl(const std::string &type, const std::string &title)
TagReference(const TagReference &rhs)
~HistoryPlot() override=default
std::string payloadType() const
static constexpr const char *const YAXIS_K
float __attribute__((vector_size(8))) cms_float32x2_t
Histogram1(const std::string &title, const std::string &xLabel, size_t nbins, float min, float max, const std::string &yLabel="entries")
virtual Y getFromPayload(PayloadType &payload)=0
std::string serializeValue(const std::string &entryLabel, const V &value)
PlotAnnotations m_plotAnnotations
~RunHistoryPlot() override=default
void fillWithValue(AxisType value, AxisType weight=1)
tuple key
prepare the HTCondor submission files and eventually submit them
PlotImpl(const std::string &type, const std::string &title)
TagReference(const std::string &n, const std::pair< cond::Time_t, cond::Time_t > &b, const std::vector< std::tuple< cond::Time_t, cond::Hash >> &i)
RunHistoryPlot(const std::string &title, const std::string &yLabel)
static constexpr const char *const XAXIS_K
~PlotImpl() override=default
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Plot2D< PayloadType, std::tuple< unsigned long long, std::string >, Y, MULTI_IOV, 1 > Base
Plot3D< PayloadType, float, float, float, IOV_M, 1 > Base
PlotImpl< IOV_M, NTAGS > Base
const std::vector< std::tuple< cond::Time_t, cond::Hash > > & iovs
Time_t from_boost(boost::posix_time::ptime bt)
std::vector< std::tuple< X, Y, Z > > m_plotData
virtual std::tuple< X, Y > getFromPayload(PayloadType &payload)=0
const std::pair< cond::Time_t, cond::Time_t > & boundary
PlotImpl< IOV_M, NTAGS > Base
const unsigned int SECONDS_PER_LUMI(23)
virtual Y getFromPayload(PayloadType &payload)=0
std::string createGlobalIdentifier(bool binary=false)
void addInputParam(const std::string ¶mName)
__attribute__((visibility("default"))) inline py
static constexpr const char *const label
~ScatterPlot() override=default
std::string processData() override
PlotImpl< IOV_M, NTAGS > Base
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)
TimeHistoryPlot(const std::string &title, const std::string &yLabel)
virtual std::string serializeData()=0
HistoryPlot(const std::string &title, const std::string &yLabel)
void setTwoTags(bool flag)
std::string serializeAnnotations(const PlotAnnotations &annotations)
std::string serializeData() override
~Plot3D() override=default
char data[epos_bytes_allocation]
cond::persistency::Session m_dbSession
std::map< std::string, std::string > m
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash >> &iovs)
std::string title() const
static constexpr const char *const TITLE_K
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
virtual Y getFromPayload(PayloadType &payload)=0
void setTwoTags(bool flag)
virtual ~PlotBase()=default
std::vector< std::pair< cond::Time_t, cond::Time_t > > m_tagBoundaries
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
~Plot2D() override=default
void setTwoTags(bool flag)
void fillWithBinAndValue(size_t bin, AxisType weight=1)
PlotImpl(const std::string &type, const std::string &title)
Plot2D< PayloadType, AxisType, AxisType, IOV_M, 1 > Base
const std::map< std::string, std::string > & inputParamValues() const
static constexpr const char *const INFO_K
tuple size
Write out results.
boost::posix_time::ptime to_boost(Time_t iValue)
std::vector< std::vector< std::tuple< cond::Time_t, cond::Hash > > > m_tagIovs
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
RunInfoProxy getRunInfo(cond::Time_t start, cond::Time_t end)
virtual std::string processData()
~TimeHistoryPlot() override=default