1 #ifndef CondCore_Utilities_PayloadInspector_h 2 #define CondCore_Utilities_PayloadInspector_h 11 #include <boost/python/list.hpp> 12 #include <boost/python/extract.hpp> 16 namespace payloadInspector {
29 std::map<std::string,std::string>
m;
38 ss <<
"\""<<entryLabel<<
"\":"<<
value;
44 ss <<
"\""<<entryLabel<<
"\":\""<<value<<
"\"";
51 ss << serializeValue( entryLabel, std::get<0>(
value) );
68 ss <<
"\"version\": \""<<JSON_FORMAT_VERSION<<
"\",";
69 ss <<
"\"annotations\": {";
71 for(
auto a: annotations.
m ){
72 if ( !first ) ss <<
",";
73 ss <<
"\""<<
a.first<<
"\":\"" <<
a.second <<
"\"";
88 for (
auto d :
data ){
89 if( !first ) ss <<
",";
100 std::stringstream ss;
106 for (
auto d :
data ){
107 if( !first ) ss <<
",";
135 bool isSingleIov()
const;
149 virtual std::string processData(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs );
152 void setSingleIov(
bool flag );
156 return m_dbSession.fetchPayload<PayloadType>( payloadHash );
178 template <
typename PayloadType,
typename X,
typename Y>
class Plot2D :
public PlotBase {
190 return serialize( m_plotAnnotations, m_plotData);
195 return serializeData();
199 return PlotBase::fetchPayload<PayloadType>( payloadHash );
202 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) = 0;
207 template <
typename PayloadType,
typename X,
typename Y,
typename Z>
class Plot3D :
public PlotBase {
220 return serialize( m_plotAnnotations, m_plotData);
225 return serializeData();
229 return PlotBase::fetchPayload<PayloadType>( payloadHash );
232 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) = 0;
237 template<
typename PayloadType,
typename Y>
class HistoryPlot :
public Plot2D<PayloadType,unsigned long long,Y > {
242 Base(
"History", title,
"iov_since" , yLabel ){
245 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
246 for(
auto iov : iovs ) {
247 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
249 Y value = getFromPayload( *payload );
250 Base::m_plotData.push_back( std::make_tuple(std::get<0>(iov),value));
256 virtual Y getFromPayload( PayloadType&
payload ) = 0;
260 template<
typename PayloadType,
typename Y>
class RunHistoryPlot :
public Plot2D<PayloadType,std::tuple<float,std::string>,Y > {
265 Base(
"RunHistory", title,
"iov_since" , yLabel ){
268 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
270 std::map<cond::Time_t,unsigned int>
runs;
272 for(
auto iov : iovs ) {
273 unsigned int run = std::get<0>(iov) >> 32;
274 auto it = runs.find( run );
275 if( it == runs.end() ) it = runs.insert( std::make_pair( run, 0 ) ).first;
279 unsigned int currentRun = 0;
281 unsigned int lumiSize = 0;
282 unsigned int rind = 0;
285 for(
auto iov : iovs ) {
286 unsigned long long since = std::get<0>(iov);
289 unsigned int run = since >> 32;
290 unsigned int lumi = since & 0xFFFFFFFF;
291 if( run != currentRun ) {
294 auto it = runs.find( run );
295 if( it == runs.end() ) {
299 lumiSize = it->second;
303 ind = rind + (lumiIndex/lumiSize);
304 label = boost::lexical_cast<
std::string>(
run )+
" : "+boost::lexical_cast<std::string>( lumi );
311 label = boost::posix_time::to_simple_string( t );
316 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
318 Y value = getFromPayload( *payload );
319 Base::m_plotData.push_back( std::make_tuple(std::make_tuple(ind,label),value));
325 virtual Y getFromPayload( PayloadType&
payload ) = 0;
329 template<
typename PayloadType,
typename Y>
class TimeHistoryPlot :
public Plot2D<PayloadType,std::tuple<unsigned long long,std::string>,Y > {
334 Base(
"TimeHistory", title,
"iov_since" , yLabel ){
337 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
346 runInfo = Base::dbSession().getRunInfo( min, max );
348 for(
auto iov : iovs ) {
350 boost::posix_time::ptime
time;
353 unsigned int nlumi = since & 0xFFFFFFFF;
354 if( Base::tagTimeType()==
cond::lumiid ) since = since >> 32;
356 auto it = runInfo.
find( since );
357 if ( it == runInfo.
end() ){
365 label += (
" : "+boost::lexical_cast<
std::string>( nlumi ) );
369 label = boost::posix_time::to_simple_string( time );
371 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
373 Y value = getFromPayload( *payload );
380 virtual Y getFromPayload( PayloadType&
payload ) = 0;
384 template<
typename PayloadType,
typename X,
typename Y>
class ScatterPlot :
public Plot2D<PayloadType,X,Y > {
389 Base(
"Scatter", title, xLabel , yLabel ){
392 bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
393 for(
auto iov : iovs ) {
394 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
396 std::tuple<X,Y>
value = getFromPayload( *payload );
397 Base::m_plotData.push_back( value );
403 virtual std::tuple<X,Y> getFromPayload( PayloadType&
payload ) = 0;
413 Base(
"Histo1D", title, xLabel ,
"entries" ),m_nbins(nbins),m_min(min),m_max(max){
418 Base::m_plotData.clear();
419 float binSize = (m_max-m_min)/m_nbins;
422 Base::m_plotData.resize( m_nbins );
423 for(
size_t i=0;
i<m_nbins;
i++ ){
424 Base::m_plotData[
i] = std::make_tuple( m_min+
i*m_binSize, 0 );
432 if( Base::m_plotData.
size() && (value < m_max) && (value >= m_min) ){
433 size_t ibin = (value-m_min)/m_binSize;
434 std::get<1>(Base::m_plotData[ibin])+=
weight;
439 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
440 for(
auto iov : iovs ) {
441 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
443 float value = getFromPayload( *payload );
444 fillWithValue( value );
463 template<
typename PayloadType>
class Histogram2D:
public Plot3D<PayloadType,float,float,float > {
469 Base(
"Histo2D", title, xLabel , yLabel,
"entries" ),m_nxbins( nxbins), m_xmin(xmin),m_xmax(xmax),m_nybins(nybins),m_ymin(ymin),m_ymax(ymax){
474 Base::m_plotData.clear();
475 float xbinSize = (m_xmax-m_xmin)/m_nxbins;
476 float ybinSize = (m_ymax-m_ymin)/m_nybins;
477 if( xbinSize>0 && ybinSize>0){
478 m_xbinSize = xbinSize;
479 m_ybinSize = ybinSize;
480 Base::m_plotData.resize( m_nxbins*m_nybins );
481 for(
size_t i=0;
i<m_nybins;
i++ ){
482 for(
size_t j=0;j<m_nxbins;j++ ){
483 Base::m_plotData[
i*m_nxbins+j] = std::make_tuple( m_xmin+j*m_xbinSize, m_ymin+
i*m_ybinSize, 0 );
492 if( Base::m_plotData.
size() && xvalue < m_xmax && xvalue >= m_xmin && yvalue < m_ymax && yvalue >= m_ymin ){
493 size_t ixbin = (xvalue-m_xmin)/m_xbinSize;
494 size_t iybin = (yvalue-m_ymin)/m_ybinSize;
495 std::get<2>(Base::m_plotData[iybin*m_nxbins+ixbin])+=
weight;
500 virtual bool fill(
const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs )
override {
501 for(
auto iov : iovs ) {
502 std::shared_ptr<PayloadType>
payload = Base::fetchPayload( std::get<1>(iov) );
504 std::tuple<float,float>
value = getFromPayload( *payload );
505 fillWithValue( std::get<0>(value),std::get<1>(value) );
515 return std::make_tuple(x,y);
520 float m_xbinSize = 0;
523 float m_ybinSize = 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::vector< std::tuple< X, Y, Z > > m_plotData
Plot2D< PayloadType, unsigned long long, Y > Base
static const char *const JSON_FORMAT_VERSION
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
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
Histogram1D(const std::string &title, const std::string &xLabel, size_t nbins, float min, float max)
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)
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