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;
40 ss <<
"\""<<entryLabel<<
"\":"<<
value;
46 ss <<
"\""<<entryLabel<<
"\":\""<<value<<
"\"";
53 ss << serializeValue( entryLabel, std::get<0>(
value) );
70 ss <<
"\"version\": \""<<JSON_FORMAT_VERSION<<
"\",";
71 ss <<
"\"annotations\": {";
73 for(
auto a: annotations.
m ){
74 if ( !first ) ss <<
",";
75 ss <<
"\""<<
a.first<<
"\":\"" <<
a.second <<
"\"";
90 for (
auto d :
data ){
91 if( !first ) ss <<
",";
102 std::stringstream ss;
108 for (
auto d :
data ){
109 if( !first ) ss <<
",";
119 std::stringstream ss;
123 ss <<
"\"file\": \""<<imageFileName<<
"\"";
147 bool isSingleIov()
const;
150 bool isTwoTags()
const;
167 virtual std::string processData(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs );
170 void setSingleIov(
bool flag );
172 void setTwoTags(
bool flag );
176 return m_dbSession.fetchPayload<PayloadType>( payloadHash );
202 template <
typename PayloadType,
typename X,
typename Y>
class Plot2D :
public PlotBase {
212 ~
Plot2D()
override =
default;
214 return serialize( m_plotAnnotations, m_plotData);
219 return serializeData();
223 return PlotBase::fetchPayload<PayloadType>( payloadHash );
226 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) = 0;
231 template <
typename PayloadType,
typename X,
typename Y,
typename Z>
class Plot3D :
public PlotBase {
242 ~
Plot3D()
override =
default;
244 return serialize( m_plotAnnotations, m_plotData);
249 return serializeData();
253 return PlotBase::fetchPayload<PayloadType>( payloadHash );
256 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) = 0;
261 template<
typename PayloadType,
typename Y>
class HistoryPlot :
public Plot2D<PayloadType,unsigned long long,Y > {
266 Base(
"History", title,
"iov_since" , yLabel ){
269 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
270 for(
auto iov : iovs ) {
271 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
273 Y value = getFromPayload( *payload );
274 Base::m_plotData.push_back( std::make_tuple(std::get<0>(iov),value));
280 virtual Y getFromPayload( PayloadType&
payload ) = 0;
284 template<
typename PayloadType,
typename Y>
class RunHistoryPlot :
public Plot2D<PayloadType,std::tuple<float,std::string>,Y > {
289 Base(
"RunHistory", title,
"iov_since" , yLabel ){
292 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
295 std::map<cond::Time_t,unsigned int>
runs;
296 cond::Tag_t tagInfo = Base::getTagInfo( Base::m_tag0 );
298 for(
auto iov : iovs ) {
299 unsigned int run = std::get<0>(iov) >> 32;
300 auto it = runs.find( run );
301 if( it == runs.end() ) it = runs.insert( std::make_pair( run, 0 ) ).first;
305 unsigned int currentRun = 0;
307 unsigned int lumiSize = 0;
308 unsigned int rind = 0;
311 for(
auto iov : iovs ) {
312 unsigned long long since = std::get<0>(iov);
315 unsigned int run = since >> 32;
316 unsigned int lumi = since & 0xFFFFFFFF;
317 if( run != currentRun ) {
320 auto it = runs.find( run );
321 if( it == runs.end() ) {
325 lumiSize = it->second;
329 ind = rind + (lumiIndex/lumiSize);
330 label = std::to_string(run )+
" : "+std::to_string(lumi );
337 label = boost::posix_time::to_simple_string( t );
339 label = std::to_string(since );
342 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
344 Y value = getFromPayload( *payload );
345 Base::m_plotData.push_back( std::make_tuple(std::make_tuple(ind,label),value));
351 virtual Y getFromPayload( PayloadType&
payload ) = 0;
355 template<
typename PayloadType,
typename Y>
class TimeHistoryPlot :
public Plot2D<PayloadType,std::tuple<unsigned long long,std::string>,Y > {
360 Base(
"TimeHistory", title,
"iov_since" , yLabel ){
363 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
365 cond::Tag_t tagInfo = Base::getTagInfo( Base::m_tag0 );
373 runInfo = Base::dbSession().getRunInfo( min, max );
375 for(
auto iov : iovs ) {
377 boost::posix_time::ptime
time;
380 unsigned int nlumi = since & 0xFFFFFFFF;
382 label = std::to_string(since );
383 auto it = runInfo.
find( since );
384 if ( it == runInfo.
end() ){
392 label += (
" : "+std::to_string(nlumi ) );
396 label = boost::posix_time::to_simple_string( time );
398 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
400 Y value = getFromPayload( *payload );
407 virtual Y getFromPayload( PayloadType&
payload ) = 0;
411 template<
typename PayloadType,
typename X,
typename Y>
class ScatterPlot :
public Plot2D<PayloadType,X,Y > {
416 Base(
"Scatter", title, xLabel , yLabel ){
419 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
420 for(
auto iov : iovs ) {
421 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
423 std::tuple<X,Y>
value = getFromPayload( *payload );
424 Base::m_plotData.push_back( value );
430 virtual std::tuple<X,Y> getFromPayload( PayloadType&
payload ) = 0;
440 Base(
"Histo1D", title, xLabel , yLabel),m_nbins(nbins),m_min(min),m_max(max){
445 Base::m_plotData.clear();
446 float binSize = (m_max-m_min)/m_nbins;
449 Base::m_plotData.resize( m_nbins );
450 for(
size_t i=0;
i<m_nbins;
i++ ){
451 Base::m_plotData[
i] = std::make_tuple( m_min+
i*m_binSize, 0 );
459 if( !Base::m_plotData.
empty() && (value < m_max) && (value >= m_min) ){
460 size_t ibin = (value-m_min)/m_binSize;
461 std::get<1>(Base::m_plotData[ibin])+=
weight;
467 if(bin>=0 && bin<Base::m_plotData.
size()){
468 std::get<1>(Base::m_plotData[
bin])=
weight;
473 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
474 for(
auto iov : iovs ) {
475 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
477 float value = getFromPayload( *payload );
478 fillWithValue( value );
497 template<
typename PayloadType>
class Histogram2D:
public Plot3D<PayloadType,float,float,float > {
503 Base(
"Histo2D", title, xLabel , yLabel,
"entries" ),m_nxbins( nxbins), m_xmin(xmin),m_xmax(xmax),m_nybins(nybins),m_ymin(ymin),m_ymax(ymax){
509 Base::m_plotData.clear();
510 float xbinSize = (m_xmax-m_xmin)/m_nxbins;
511 float ybinSize = (m_ymax-m_ymin)/m_nybins;
512 if( xbinSize>0 && ybinSize>0){
513 m_xbinSize = xbinSize;
514 m_ybinSize = ybinSize;
515 Base::m_plotData.resize( m_nxbins*m_nybins );
516 for(
size_t i=0;
i<m_nybins;
i++ ){
517 for(
size_t j=0;j<m_nxbins;j++ ){
518 Base::m_plotData[
i*m_nxbins+j] = std::make_tuple( m_xmin+j*m_xbinSize, m_ymin+
i*m_ybinSize, 0 );
527 if( !Base::m_plotData.
empty() && xvalue < m_xmax && xvalue >= m_xmin && yvalue < m_ymax && yvalue >= m_ymin ){
528 size_t ixbin = (xvalue-m_xmin)/m_xbinSize;
529 size_t iybin = (yvalue-m_ymin)/m_ybinSize;
530 std::get<2>(Base::m_plotData[iybin*m_nxbins+ixbin])+=
weight;
535 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
536 for(
auto iov : iovs ) {
537 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
539 std::tuple<float,float>
value = getFromPayload( *payload );
540 fillWithValue( std::get<0>(value),std::get<1>(value) );
550 return std::make_tuple(x,y);
555 float m_xbinSize = 0;
558 float m_ybinSize = 0;
571 std::string payloadTypeName = cond::demangledName(
typeid(PayloadType) );
573 m_imageFileName = boost::lexical_cast<
std::string>( ( boost::uuids::random_generator())() )+
".png";
577 return serialize( m_plotAnnotations, m_imageFileName);
582 return serializeData();
586 return PlotBase::fetchPayload<PayloadType>( payloadHash );
589 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) = 0;
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
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
Plot3D< PayloadType, float, float, float > Base
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
std::vector< std::tuple< X, Y, Z > > m_plotData
Plot2D< PayloadType, unsigned long long, Y > Base
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)
std::map< std::string, std::string > m
static const char *const ZAXIS_K
std::vector< std::tuple< X, Y > > m_plotData
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
std::string serializeValue(const std::string &entryLabel, const V &value)
PlotAnnotations m_plotAnnotations
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)
Plot2D< PayloadType, float, float > Base
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)
Time_t from_boost(boost::posix_time::ptime bt)
static const char *const PAYLOAD_TYPE_K
const unsigned int SECONDS_PER_LUMI(23)
bin
set the eta bin as selection string.
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()
Plot2D< PayloadType, std::tuple< float, std::string >, Y > Base
TimeHistoryPlot(const std::string &title, const std::string &yLabel)
Iterator find(Time_t target) const
virtual std::tuple< float, float > getFromPayload(PayloadType &payload)
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
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, std::tuple< unsigned long long, std::string >, Y > Base
Plot2D(const std::string &type, const std::string &title, const std::string xLabel, const std::string &yLabel)
static const char *const XAXIS_K
boost::posix_time::ptime to_boost(Time_t iValue)
PlotImage(const std::string &title)