1 #ifndef CondCore_Utilities_PayloadInspector_h 2 #define CondCore_Utilities_PayloadInspector_h 11 #include <boost/python/list.hpp> 12 #include <boost/python/extract.hpp> 13 #include <boost/uuid/uuid.hpp> 14 #include <boost/uuid/uuid_generators.hpp> 15 #include <boost/uuid/uuid_io.hpp> 19 namespace payloadInspector {
32 std::map<std::string,std::string>
m;
41 ss <<
"\""<<entryLabel<<
"\":"<<
value;
47 ss <<
"\""<<entryLabel<<
"\":\""<<value<<
"\"";
54 ss << serializeValue( entryLabel, std::get<0>(
value) );
71 ss <<
"\"version\": \""<<JSON_FORMAT_VERSION<<
"\",";
72 ss <<
"\"annotations\": {";
74 for(
auto a: annotations.
m ){
75 if ( !first ) ss <<
",";
76 ss <<
"\""<<
a.first<<
"\":\"" <<
a.second <<
"\"";
91 for (
auto d :
data ){
92 if( !first ) ss <<
",";
103 std::stringstream ss;
109 for (
auto d :
data ){
110 if( !first ) ss <<
",";
120 std::stringstream ss;
124 ss <<
"\"file\": \""<<imageFileName<<
"\"";
148 bool isSingleIov()
const;
162 virtual std::string processData(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs );
165 void setSingleIov(
bool flag );
169 return m_dbSession.fetchPayload<PayloadType>( payloadHash );
191 template <
typename PayloadType,
typename X,
typename Y>
class Plot2D :
public PlotBase {
201 virtual ~
Plot2D() =
default;
203 return serialize( m_plotAnnotations, m_plotData);
208 return serializeData();
212 return PlotBase::fetchPayload<PayloadType>( payloadHash );
215 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) = 0;
220 template <
typename PayloadType,
typename X,
typename Y,
typename Z>
class Plot3D :
public PlotBase {
231 virtual ~
Plot3D() =
default;
233 return serialize( m_plotAnnotations, m_plotData);
238 return serializeData();
242 return PlotBase::fetchPayload<PayloadType>( payloadHash );
245 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) = 0;
250 template<
typename PayloadType,
typename Y>
class HistoryPlot :
public Plot2D<PayloadType,unsigned long long,Y > {
255 Base(
"History", title,
"iov_since" , yLabel ){
258 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
259 for(
auto iov : iovs ) {
260 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
262 Y value = getFromPayload( *payload );
263 Base::m_plotData.push_back( std::make_tuple(std::get<0>(iov),value));
269 virtual Y getFromPayload( PayloadType&
payload ) = 0;
273 template<
typename PayloadType,
typename Y>
class RunHistoryPlot :
public Plot2D<PayloadType,std::tuple<float,std::string>,Y > {
278 Base(
"RunHistory", title,
"iov_since" , yLabel ){
281 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
283 std::map<cond::Time_t,unsigned int>
runs;
285 for(
auto iov : iovs ) {
286 unsigned int run = std::get<0>(iov) >> 32;
287 auto it = runs.find( run );
288 if( it == runs.end() ) it = runs.insert( std::make_pair( run, 0 ) ).first;
292 unsigned int currentRun = 0;
294 unsigned int lumiSize = 0;
295 unsigned int rind = 0;
298 for(
auto iov : iovs ) {
299 unsigned long long since = std::get<0>(iov);
302 unsigned int run = since >> 32;
303 unsigned int lumi = since & 0xFFFFFFFF;
304 if( run != currentRun ) {
307 auto it = runs.find( run );
308 if( it == runs.end() ) {
312 lumiSize = it->second;
316 ind = rind + (lumiIndex/lumiSize);
317 label = std::to_string(run )+
" : "+std::to_string(lumi );
324 label = boost::posix_time::to_simple_string( t );
326 label = std::to_string(since );
329 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
331 Y value = getFromPayload( *payload );
332 Base::m_plotData.push_back( std::make_tuple(std::make_tuple(ind,label),value));
338 virtual Y getFromPayload( PayloadType&
payload ) = 0;
342 template<
typename PayloadType,
typename Y>
class TimeHistoryPlot :
public Plot2D<PayloadType,std::tuple<unsigned long long,std::string>,Y > {
347 Base(
"TimeHistory", title,
"iov_since" , yLabel ){
350 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
359 runInfo = Base::dbSession().getRunInfo( min, max );
361 for(
auto iov : iovs ) {
363 boost::posix_time::ptime
time;
366 unsigned int nlumi = since & 0xFFFFFFFF;
367 if( Base::tagTimeType()==
cond::lumiid ) since = since >> 32;
368 label = std::to_string(since );
369 auto it = runInfo.
find( since );
370 if ( it == runInfo.
end() ){
378 label += (
" : "+std::to_string(nlumi ) );
382 label = boost::posix_time::to_simple_string( time );
384 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
386 Y value = getFromPayload( *payload );
393 virtual Y getFromPayload( PayloadType&
payload ) = 0;
397 template<
typename PayloadType,
typename X,
typename Y>
class ScatterPlot :
public Plot2D<PayloadType,X,Y > {
402 Base(
"Scatter", title, xLabel , yLabel ){
405 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
406 for(
auto iov : iovs ) {
407 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
409 std::tuple<X,Y>
value = getFromPayload( *payload );
410 Base::m_plotData.push_back( value );
416 virtual std::tuple<X,Y> getFromPayload( PayloadType&
payload ) = 0;
426 Base(
"Histo1D", title, xLabel , yLabel),m_nbins(nbins),m_min(min),m_max(max){
431 Base::m_plotData.clear();
432 float binSize = (m_max-m_min)/m_nbins;
435 Base::m_plotData.resize( m_nbins );
436 for(
size_t i=0;
i<m_nbins;
i++ ){
437 Base::m_plotData[
i] = std::make_tuple( m_min+
i*m_binSize, 0 );
445 if( Base::m_plotData.
size() && (value < m_max) && (value >= m_min) ){
446 size_t ibin = (value-m_min)/m_binSize;
447 std::get<1>(Base::m_plotData[ibin])+=
weight;
453 if(bin>=0 && bin<Base::m_plotData.
size()){
454 std::get<1>(Base::m_plotData[
bin])=
weight;
459 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
460 for(
auto iov : iovs ) {
461 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
463 float value = getFromPayload( *payload );
464 fillWithValue( value );
483 template<
typename PayloadType>
class Histogram2D:
public Plot3D<PayloadType,float,float,float > {
489 Base(
"Histo2D", title, xLabel , yLabel,
"entries" ),m_nxbins( nxbins), m_xmin(xmin),m_xmax(xmax),m_nybins(nybins),m_ymin(ymin),m_ymax(ymax){
495 Base::m_plotData.clear();
496 float xbinSize = (m_xmax-m_xmin)/m_nxbins;
497 float ybinSize = (m_ymax-m_ymin)/m_nybins;
498 if( xbinSize>0 && ybinSize>0){
499 m_xbinSize = xbinSize;
500 m_ybinSize = ybinSize;
501 Base::m_plotData.resize( m_nxbins*m_nybins );
502 for(
size_t i=0;
i<m_nybins;
i++ ){
503 for(
size_t j=0;j<m_nxbins;j++ ){
504 Base::m_plotData[
i*m_nxbins+j] = std::make_tuple( m_xmin+j*m_xbinSize, m_ymin+
i*m_ybinSize, 0 );
513 if( Base::m_plotData.
size() && xvalue < m_xmax && xvalue >= m_xmin && yvalue < m_ymax && yvalue >= m_ymin ){
514 size_t ixbin = (xvalue-m_xmin)/m_xbinSize;
515 size_t iybin = (yvalue-m_ymin)/m_ybinSize;
516 std::get<2>(Base::m_plotData[iybin*m_nxbins+ixbin])+=
weight;
521 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
522 for(
auto iov : iovs ) {
523 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
525 std::tuple<float,float>
value = getFromPayload( *payload );
526 fillWithValue( std::get<0>(value),std::get<1>(value) );
536 return std::make_tuple(x,y);
541 float m_xbinSize = 0;
544 float m_ybinSize = 0;
557 std::string payloadTypeName = cond::demangledName(
typeid(PayloadType) );
559 m_imageFileName = boost::lexical_cast<
std::string>( ( boost::uuids::random_generator())() )+
".png";
563 return serialize( m_plotAnnotations, m_imageFileName);
568 return serializeData();
572 return PlotBase::fetchPayload<PayloadType>( payloadHash );
575 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
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)
T x() const
Cartesian x coordinate.
std::string processData(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
payload
payload postfix for testing
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)
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
cond::TimeType m_tagTimeType
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
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)
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
PlotImage(const std::string &title)