Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature for the Payload Inspector: support for two tags/ single IOV plot generation #26294

Merged
merged 3 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CondCore/CondDB/interface/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ namespace cond {

//
bool existsIov( const std::string& tag );


//
bool getTagInfo( const std::string& tag, cond::Tag_t& info );

// retrieves an IOV range. Peforms a query at every call.
bool getIovRange( const std::string& tag,
cond::Time_t begin, cond::Time_t end,
Expand Down
1 change: 1 addition & 0 deletions CondCore/CondDB/interface/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace cond {
std::string tag;
std::string payloadType;
TimeType timeType;
SynchronizationType synchronizationType;
Time_t endOfValidity;
Time_t lastValidatedTime;
};
Expand Down
8 changes: 8 additions & 0 deletions CondCore/CondDB/src/Session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ namespace cond {
m_session->openIovDb();
return m_session->iovSchema().tagTable().select( tag );
}

bool Session::getTagInfo( const std::string& tag,
cond::Tag_t& info ){
m_session->openIovDb();
std::string description;
return m_session->iovSchema().tagTable().select( tag, info.timeType, info.payloadType, info.synchronizationType,
info.endOfValidity, description, info.lastValidatedTime );
}

IOVProxy Session::iovProxy(){
m_session->openIovDb();
Expand Down
38 changes: 27 additions & 11 deletions CondCore/Utilities/interface/PayloadInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace cond {
std::string get( const std::string& key ) const;
std::map<std::string,std::string> m;
bool singleIov = false;
bool twoTags = false;
};

static const char* const JSON_FORMAT_VERSION = "1.0";
Expand Down Expand Up @@ -147,12 +148,18 @@ namespace cond {
// required in the browser
bool isSingleIov() const;

// required in the browser
bool isTwoTags() const;

// returns the json file with the plot data
std::string data() const;

// triggers the processing producing the plot
bool process( const std::string& connectionString, const std::string& tag, const std::string& timeType, cond::Time_t begin, cond::Time_t end );
//bool process( const std::string& connectionString, const std::string& tag, cond::Time_t begin, cond::Time_t end );

bool processTwoTags( const std::string& connectionString, const std::string& tag0, const std::string& tag1, cond::Time_t time0, cond::Time_t time1 );

// not exposed in python:
// called internally in process()
virtual void init();
Expand All @@ -164,25 +171,31 @@ namespace cond {
// to be set in order to limit the iov selection ( and processing ) to 1 iov
void setSingleIov( bool flag );

void setTwoTags( bool flag );

// access to the fetch function of the configured reader, to be used in the processData implementations
template <typename PayloadType> std::shared_ptr<PayloadType> fetchPayload( const cond::Hash& payloadHash ){
return m_dbSession.fetchPayload<PayloadType>( payloadHash );
}

cond::Tag_t getTagInfo( const std::string& tag );

// access to the timeType of the tag in process
cond::TimeType tagTimeType() const;
//cond::TimeType tagTimeType() const;

// access to the underlying db session
cond::persistency::Session dbSession();

protected:

PlotAnnotations m_plotAnnotations;
std::string m_tag0 = "";
std::string m_tag1 = "";

private:

cond::persistency::Session m_dbSession;
cond::TimeType m_tagTimeType;
//cond::TimeType m_tagTimeType;

std::string m_data = "";
};
Expand Down Expand Up @@ -279,9 +292,11 @@ namespace cond {
}
~RunHistoryPlot() override = default;
bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override {

// for the lumi iovs we need to count the number of lumisections in every runs
std::map<cond::Time_t,unsigned int> runs;
if( Base::tagTimeType()==cond::lumiid ){
cond::Tag_t tagInfo = Base::getTagInfo( Base::m_tag0 );
if( tagInfo.timeType==cond::lumiid ){
for( auto iov : iovs ) {
unsigned int run = std::get<0>(iov) >> 32;
auto it = runs.find( run );
Expand All @@ -298,7 +313,7 @@ namespace cond {
for( auto iov : iovs ) {
unsigned long long since = std::get<0>(iov);
// for the lumi iovs we squeeze the lumi section available in the constant run 'slot' of witdth=1
if( Base::tagTimeType()==cond::lumiid ){
if( tagInfo.timeType==cond::lumiid ){
unsigned int run = since >> 32;
unsigned int lumi = since & 0xFFFFFFFF;
if( run != currentRun ) {
Expand All @@ -319,7 +334,7 @@ namespace cond {
} else {
ind++;
// for the timestamp based iovs, it does not really make much sense to use this plot...
if( Base::tagTimeType()==cond::timestamp ){
if( tagInfo.timeType==cond::timestamp ){
boost::posix_time::ptime t = cond::time::to_boost( since );
label = boost::posix_time::to_simple_string( t );
} else {
Expand Down Expand Up @@ -349,10 +364,11 @@ namespace cond {
~TimeHistoryPlot() override = default;
bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override {
cond::persistency::RunInfoProxy runInfo;
if( Base::tagTimeType()==cond::lumiid || Base::tagTimeType()==cond::runnumber){
cond::Tag_t tagInfo = Base::getTagInfo( Base::m_tag0 );
if( tagInfo.timeType==cond::lumiid || tagInfo.timeType==cond::runnumber){
cond::Time_t min = std::get<0>(iovs.front());
cond::Time_t max = std::get<0>( iovs.back() );
if( Base::tagTimeType()==cond::lumiid ){
if( tagInfo.timeType==cond::lumiid ){
min = min >> 32;
max = max >> 32;
}
Expand All @@ -362,9 +378,9 @@ namespace cond {
cond::Time_t since = std::get<0>(iov);
boost::posix_time::ptime time;
std::string label("");
if( Base::tagTimeType()==cond::lumiid || Base::tagTimeType()==cond::runnumber){
if( tagInfo.timeType==cond::lumiid || tagInfo.timeType==cond::runnumber){
unsigned int nlumi = since & 0xFFFFFFFF;
if( Base::tagTimeType()==cond::lumiid ) since = since >> 32;
if( tagInfo.timeType==cond::lumiid ) since = since >> 32;
label = std::to_string(since );
auto it = runInfo.find( since );
if ( it == runInfo.end() ){
Expand All @@ -373,11 +389,11 @@ namespace cond {
}
time = (*it).start;
// add the lumi sections...
if( Base::tagTimeType()==cond::lumiid ){
if( tagInfo.timeType==cond::lumiid ){
time += boost::posix_time::seconds( cond::time::SECONDS_PER_LUMI*nlumi );
label += (" : "+std::to_string(nlumi ) );
}
} else if ( Base::tagTimeType()==cond::timestamp ){
} else if ( tagInfo.timeType==cond::timestamp ){
time = cond::time::to_boost( since );
label = boost::posix_time::to_simple_string( time );
}
Expand Down
2 changes: 2 additions & 0 deletions CondCore/Utilities/interface/PayloadInspectorModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#define PAYLOAD_INSPECTOR_CLASS( CLASS_NAME ) \
boost::python::class_< CLASS_NAME, boost::python::bases<cond::payloadInspector::PlotBase> >( STRINGIZE(PPCAT(plot_,CLASS_NAME)), boost::python::init<>()) \
.def("process",&cond::payloadInspector::PlotBase::process ) \
.def("processTwoTags",&cond::payloadInspector::PlotBase::processTwoTags ) \
.def("payloadType",&cond::payloadInspector::PlotBase::payloadType ) \
.def("title",&cond::payloadInspector::PlotBase::title ) \
.def("isSingleIov",&cond::payloadInspector::PlotBase::isSingleIov ) \
.def("isTwoTags",&cond::payloadInspector::PlotBase::isTwoTags ) \
.def("data",&cond::payloadInspector::PlotBase::data ) \
;
85 changes: 85 additions & 0 deletions CondCore/Utilities/plugins/BasicP_PayloadInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,90 @@ namespace {
}
};

class BasicPayload_data7 : public cond::payloadInspector::PlotImage<cond::BasicPayload> {
public:
BasicPayload_data7() : cond::payloadInspector::PlotImage<cond::BasicPayload>( "Example delivery picture" ){
setTwoTags( true );
}

bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
auto iov0 = iovs.front();
auto iov1 = iovs.back();
std::shared_ptr<cond::BasicPayload> payload0 = fetchPayload( std::get<1>(iov0) );
std::shared_ptr<cond::BasicPayload> payload1 = fetchPayload( std::get<1>(iov1) );

double xmax(100.),ymax(100.);

TH2D h2D("h2D","Example",100,0.,xmax,100,0.,ymax);

if( payload0.get() && payload1.get() ){
if(payload0->m_vec.size()==10000 && payload1->m_vec.size()==10000 ){
for( size_t i=0;i<100;i++ )
for( size_t j=0;j<100;j++ ) {
auto diff = abs(payload0->m_vec[i*100+j] - payload1->m_vec[i*100+j]);
h2D.Fill(i,j,diff);
}
h2D.SetStats(false);
}
}

TCanvas c("c","",20,20,900,500);
c.cd();
c.SetLogz();
h2D.SetNdivisions(18, "X");
h2D.GetXaxis()->SetTickLength(0.00);
h2D.GetYaxis()->SetTickLength(0.00);
h2D.GetXaxis()->SetTitle("iphi");
h2D.GetYaxis()->SetTitle("ieta");
h2D.Draw("col");

//======= drawing lines ========
///// this is quite specific to the line style they need

TLine l;
l.SetLineStyle(2);
l.DrawLine(0., ymax/2., xmax, ymax/2.);
for(int m = 0; m < int(xmax); m+=10) {
l.DrawLine(m, 0., m, 100.);
}

c.RedrawAxis();

//========== writing text in the canvas==============
//// This is again quite specific part. I just tried to emulate what is there in DQM for EB.

TLatex Tl;
TLatex Tll;
Tl.SetTextAlign(23);
Tl.SetTextSize(0.04);

Tll.SetTextAlign(23);
Tll.SetTextSize(0.04);

int j = 0;
for(int i = 1; i <=10; i++){
std::string s = "+" + std::to_string(i);
char const *pchar = s.c_str();
j+=10;
Tl.DrawLatex(j-5,int(ymax)/1.33,pchar);
}

int z = 0;
for(int g = -10; g <0; g++){
std::string ss = std::to_string(g);
char const *pchar1 = ss.c_str();
z+= 10;
Tll.DrawLatex(z-5,int(ymax)/4,pchar1);
}
//=========================

std::string fileName(m_imageFileName);
c.SaveAs(fileName.c_str());

return true;
}
};

}

PAYLOAD_INSPECTOR_MODULE( BasicPayload ){
Expand All @@ -187,4 +271,5 @@ PAYLOAD_INSPECTOR_MODULE( BasicPayload ){
PAYLOAD_INSPECTOR_CLASS( BasicPayload_data4 );
PAYLOAD_INSPECTOR_CLASS( BasicPayload_data5 );
PAYLOAD_INSPECTOR_CLASS( BasicPayload_data6 );
PAYLOAD_INSPECTOR_CLASS( BasicPayload_data7 );
}
2 changes: 2 additions & 0 deletions CondCore/Utilities/plugins/Module_PayloadInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ BOOST_PYTHON_MODULE( pluginModule_PayloadInspector ) {
.def_readonly("label", &cond::payloadInspector::ModuleVersion::label );
boost::python::class_< cond::payloadInspector::PlotBase > ( "PlotBase" )
.def("process",&cond::payloadInspector::PlotBase::process )
.def("processTwoTags",&cond::payloadInspector::PlotBase::processTwoTags )
.def("payloadType",&cond::payloadInspector::PlotBase::payloadType )
.def("type",&cond::payloadInspector::PlotBase::type )
.def("title",&cond::payloadInspector::PlotBase::title )
.def("isSingleIov",&cond::payloadInspector::PlotBase::isSingleIov )
.def("isTwoTags",&cond::payloadInspector::PlotBase::isTwoTags )
.def("data",&cond::payloadInspector::PlotBase::data );
}
Loading