#include <RecoLuminosity/LumiProducer/src/DIPLumiProducer.cc>
Public Types | |
typedef boost::shared_ptr < DIPLumiDetail > | ReturnDetailType |
typedef boost::shared_ptr < DIPLumiSummary > | ReturnSummaryType |
Public Member Functions | |
DIPLumiProducer (const edm::ParameterSet &) | |
ReturnDetailType | produceDetail (const DIPLuminosityRcd &) |
ReturnSummaryType | produceSummary (const DIPLuminosityRcd &) |
~DIPLumiProducer () | |
Protected Member Functions | |
virtual void | setIntervalFor (const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) |
Private Member Functions | |
void | filldetailcache (unsigned int runnumber, unsigned int startlsnum) |
void | fillsummarycache (unsigned int runnumber, unsigned int startlsnum) |
unsigned int | maxavailableLSforRun (coral::ISchema &schema, const std::string &tablename, unsigned int runnumber) |
Private Attributes | |
unsigned int | m_cachesize |
std::string | m_connectStr |
std::map< unsigned int, boost::shared_ptr < DIPLumiDetail > > | m_detailcache |
unsigned int | m_detailcachedrun |
boost::shared_ptr< DIPLumiDetail > | m_detailresult |
bool | m_isNullRun |
const edm::IOVSyncValue * | m_pcurrentTime |
std::map< unsigned int, boost::shared_ptr < DIPLumiSummary > > | m_summarycache |
unsigned int | m_summarycachedrun |
boost::shared_ptr< DIPLumiSummary > | m_summaryresult |
HF Luminosity numbers from DIP. Only exist if stable beam. No data available for other beam status
Description: A essource/esproducer for lumi values from DIP via runtime logger DB
Definition at line 22 of file DIPLumiProducer.h.
typedef boost::shared_ptr<DIPLumiDetail> DIPLumiProducer::ReturnDetailType |
Definition at line 27 of file DIPLumiProducer.h.
typedef boost::shared_ptr<DIPLumiSummary> DIPLumiProducer::ReturnSummaryType |
Definition at line 25 of file DIPLumiProducer.h.
DIPLumiProducer::DIPLumiProducer | ( | const edm::ParameterSet & | iConfig | ) |
Definition at line 65 of file DIPLumiProducer.cc.
References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_cachesize, m_connectStr, produceDetail(), produceSummary(), and edm::ESProducer::setWhatProduced().
:m_connectStr(""),m_summarycachedrun(0),m_detailcachedrun(0),m_cachesize(0){ setWhatProduced(this,&DIPLumiProducer::produceSummary); setWhatProduced(this,&DIPLumiProducer::produceDetail); findingRecord<DIPLuminosityRcd>(); m_connectStr=iConfig.getParameter<std::string>("connect"); m_cachesize=iConfig.getUntrackedParameter<unsigned int>("ncacheEntries",3); }
DIPLumiProducer::~DIPLumiProducer | ( | ) |
Definition at line 349 of file DIPLumiProducer.cc.
{}
void DIPLumiProducer::filldetailcache | ( | unsigned int | runnumber, |
unsigned int | startlsnum | ||
) | [private] |
Definition at line 271 of file DIPLumiProducer.cc.
References Exception, edm::Service< T >::isAvailable(), m_cachesize, m_connectStr, m_detailcache, m_detailcachedrun, m_summarycachedrun, maxavailableLSforRun(), cond::runnumber, python::IdGenerator::schema, and python::CommonUtils::session.
Referenced by produceDetail().
{ m_detailcache.clear(); m_detailcachedrun=runnumber; // //queries once per cache refill // //select lumisection,bunch,bunchlumi from cms_runtime_logger.bunch_lumi_sections where lumisection>=:lsmin and lumisection<:lsmax and runnumber=:runnumber ; // edm::Service<lumi::service::DBService> mydbservice; if( !mydbservice.isAvailable() ){ throw cms::Exception("Non existing service lumi::service::DBService"); } coral::ISessionProxy* session=mydbservice->connectReadOnly(m_connectStr); coral::ITypeConverter& tconverter=session->typeConverter(); tconverter.setCppTypeForSqlType(std::string("float"),std::string("FLOAT(63)")); tconverter.setCppTypeForSqlType(std::string("unsigned int"),std::string("NUMBER(10)")); unsigned int lsmin=1; unsigned int lsmax=currentlsnum; try{ session->transaction().start(true); coral::ISchema& schema=session->nominalSchema(); unsigned int maxavailableLS=maxavailableLSforRun(schema,std::string("BUNCH_LUMI_SECTIONS"),m_summarycachedrun); if(maxavailableLS!=0 &&maxavailableLS<currentlsnum ){ lsmax=maxavailableLS; }else if(maxavailableLS==0){ //this run not existing (yet) session->transaction().commit(); mydbservice->disconnect(session); return; } if(m_cachesize!=0){ lsmin=(lsmax-m_cachesize)>0 ? (lsmax-m_cachesize+1) : 1; } coral::AttributeList lumidetailBindVariables; lumidetailBindVariables.extend("lsmin",typeid(unsigned int)); lumidetailBindVariables.extend("lsmax",typeid(unsigned int)); lumidetailBindVariables.extend("runnumber",typeid(unsigned int)); lumidetailBindVariables["runnumber"].data<unsigned int>()=m_detailcachedrun; lumidetailBindVariables["lsmin"].data<unsigned int>()=lsmin; lumidetailBindVariables["lsmax"].data<unsigned int>()=lsmax; std::string conditionStr("RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND LUMISECTION<=:lsmax AND BUNCHLUMI>0 "); coral::AttributeList lumidetailOutput; lumidetailOutput.extend("LUMISECTION",typeid(unsigned int)); lumidetailOutput.extend("BUNCH",typeid(unsigned int)); lumidetailOutput.extend("BUNCHLUMI",typeid(float)); coral::IQuery* lumidetailQuery=schema.newQuery(); lumidetailQuery->addToTableList(std::string("BUNCH_LUMI_SECTIONS")); lumidetailQuery->addToOutputList("LUMISECTION"); lumidetailQuery->addToOutputList("BUNCH"); lumidetailQuery->addToOutputList("BUNCHLUMI"); lumidetailQuery->setCondition(conditionStr,lumidetailBindVariables); lumidetailQuery->defineOutput(lumidetailOutput); coral::ICursor& lumidetailcursor=lumidetailQuery->execute(); while( lumidetailcursor.next() ){ const coral::AttributeList& row=lumidetailcursor.currentRow(); unsigned int lsnum=row["LUMISECTION"].data<unsigned int>(); if(m_detailcache.find(lsnum)==m_detailcache.end()){ m_detailcache.insert(std::make_pair(lsnum,boost::shared_ptr<DIPLumiDetail>(new DIPLumiDetail))); m_detailcache[lsnum]->setOrigin(m_detailcachedrun,lsnum); } if(!row["BUNCH"].isNull()){ unsigned int bxidx=row["BUNCH"].data<unsigned int>(); float bxlumi=0.0; if(!row["BUNCHLUMI"].isNull()){ bxlumi=row["BUNCHLUMI"].data<float>();//Hz/ub } m_detailcache[lsnum]->fillbxdata(bxidx,bxlumi); } } delete lumidetailQuery; session->transaction().commit(); }catch(const coral::Exception& er){ session->transaction().rollback(); mydbservice->disconnect(session); throw cms::Exception("DatabaseError ")<<er.what(); } mydbservice->disconnect(session); }
void DIPLumiProducer::fillsummarycache | ( | unsigned int | runnumber, |
unsigned int | startlsnum | ||
) | [private] |
Definition at line 148 of file DIPLumiProducer.cc.
References Exception, edm::Service< T >::isAvailable(), m_cachesize, m_connectStr, m_summarycache, m_summarycachedrun, maxavailableLSforRun(), cond::runnumber, python::IdGenerator::schema, and python::CommonUtils::session.
Referenced by produceSummary().
{ m_summarycache.clear(); m_summarycachedrun=runnumber; // // queries once per cache refill // // select max(lumi_sections) as maxavailable from cms_runtime_logger.lumi_sections where runnumber=:runnumber; // // if maxavailable<currentls: get lsmax=maxavailable ; else: get lsmax=currentls // lsmin=lsmax-cachesize // select runnumber,lumisection,instlumi,delivlumi,livelumi from cms_runtime_logger.lumi_sections where lumisection>=:lsmin and lumisection<=:lsmax and runnumber=:runnumber; // edm::Service<lumi::service::DBService> mydbservice; if( !mydbservice.isAvailable() ){ throw cms::Exception("Non existing service lumi::service::DBService"); } coral::ISessionProxy* session=mydbservice->connectReadOnly(m_connectStr); coral::ITypeConverter& tconverter=session->typeConverter(); tconverter.setCppTypeForSqlType(std::string("float"),std::string("FLOAT(63)")); tconverter.setCppTypeForSqlType(std::string("unsigned int"),std::string("NUMBER(10)")); tconverter.setCppTypeForSqlType(std::string("unsigned short"),std::string("NUMBER(1)")); unsigned int lsmin=1; unsigned int lsmax=currentlsnum; try{ session->transaction().start(true); coral::ISchema& schema=session->nominalSchema(); unsigned int maxavailableLS=maxavailableLSforRun(schema,std::string("LUMI_SECTIONS"),m_summarycachedrun); if(maxavailableLS!=0 && maxavailableLS<currentlsnum){ lsmax=maxavailableLS; }else if(maxavailableLS==0){ //this run not existing (yet) session->transaction().commit(); mydbservice->disconnect(session); return; } if(m_cachesize!=0){ lsmin=(lsmax-m_cachesize)>0 ? (lsmax-m_cachesize+1) : 1; } //std::cout<<"lsmin "<<lsmin<<" lsmax "<<lsmax<<std::endl; coral::AttributeList lumisummaryBindVariables; lumisummaryBindVariables.extend("lsmin",typeid(unsigned int)); lumisummaryBindVariables.extend("lsmax",typeid(unsigned int)); lumisummaryBindVariables.extend("runnumber",typeid(unsigned int)); lumisummaryBindVariables["runnumber"].data<unsigned int>()=m_summarycachedrun; lumisummaryBindVariables["lsmin"].data<unsigned int>()=lsmin; lumisummaryBindVariables["lsmax"].data<unsigned int>()=lsmax; std::string conditionStr("RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND LUMISECTION<=:lsmax"); coral::AttributeList lumisummaryOutput; lumisummaryOutput.extend("LUMISECTION",typeid(unsigned int)); lumisummaryOutput.extend("INSTLUMI",typeid(float)); lumisummaryOutput.extend("DELIVLUMISECTION",typeid(float)); lumisummaryOutput.extend("LIVELUMISECTION",typeid(float)); lumisummaryOutput.extend("CMS_ACTIVE",typeid(unsigned short)); coral::IQuery* lumisummaryQuery=schema.newQuery(); lumisummaryQuery->addToTableList(std::string("LUMI_SECTIONS")); lumisummaryQuery->addToOutputList("LUMISECTION"); lumisummaryQuery->addToOutputList("INSTLUMI"); lumisummaryQuery->addToOutputList("DELIVLUMISECTION"); lumisummaryQuery->addToOutputList("LIVELUMISECTION"); lumisummaryQuery->addToOutputList("CMS_ACTIVE"); lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables); lumisummaryQuery->defineOutput(lumisummaryOutput); coral::ICursor& lumisummarycursor=lumisummaryQuery->execute(); while( lumisummarycursor.next() ){ const coral::AttributeList& row=lumisummarycursor.currentRow(); unsigned int lsnum=row["LUMISECTION"].data<unsigned int>(); float instlumi=0.0; if(!row["INSTLUMI"].isNull()){ instlumi=row["INSTLUMI"].data<float>();//Hz/ub } float intgdellumi=0.0; if(!row["DELIVLUMISECTION"].isNull()){ intgdellumi=row["DELIVLUMISECTION"].data<float>()*1000.0;//convert to /ub } float intgreclumi=0.0; if(!row["LIVELUMISECTION"].isNull()){ intgreclumi=row["LIVELUMISECTION"].data<float>()*1000.0;//convert to /ub } unsigned short cmsalive=0; if(!row["CMS_ACTIVE"].isNull()){ cmsalive=row["CMS_ACTIVE"].data<unsigned short>(); } boost::shared_ptr<DIPLumiSummary> tmpls(new DIPLumiSummary(instlumi,intgdellumi,intgreclumi,cmsalive)); tmpls->setOrigin(m_summarycachedrun,lsnum); //std::cout<<"filling "<<lsnum<<std::endl; m_summarycache.insert(std::make_pair(lsnum,tmpls)); } delete lumisummaryQuery; session->transaction().commit(); }catch(const coral::Exception& er){ session->transaction().rollback(); mydbservice->disconnect(session); throw cms::Exception("DatabaseError ")<<er.what(); } mydbservice->disconnect(session); }
unsigned int DIPLumiProducer::maxavailableLSforRun | ( | coral::ISchema & | schema, |
const std::string & | tablename, | ||
unsigned int | runnumber | ||
) | [private] |
select max(lumisection) as maxavailable from cms_runtime_logger.lumi_sections where runnumber=:runnumber;
Definition at line 245 of file DIPLumiProducer.cc.
References UserOptions_cff::myQuery, and query::result.
Referenced by filldetailcache(), and fillsummarycache().
{ unsigned int result=0; coral::AttributeList bindVariables; bindVariables.extend("runnumber",typeid(unsigned int)); bindVariables["runnumber"].data<unsigned int>()=runnumber; std::string conditionStr("RUNNUMBER=:runnumber"); coral::AttributeList MyOutput; MyOutput.extend("maxavailablels",typeid(unsigned int)); coral::IQuery* myQuery=schema.newQuery(); myQuery->addToTableList(tablename); myQuery->addToOutputList("max(LUMISECTION)","maxavailablels"); myQuery->setCondition(conditionStr,bindVariables); myQuery->defineOutput(MyOutput); coral::ICursor& mycursor=myQuery->execute(); while( mycursor.next() ){ const coral::AttributeList& row=mycursor.currentRow(); if(!row["maxavailablels"].isNull()){ result=row["maxavailablels"].data<unsigned int>(); } } return result; }
DIPLumiProducer::ReturnDetailType DIPLumiProducer::produceDetail | ( | const DIPLuminosityRcd & | ) |
Definition at line 106 of file DIPLumiProducer.cc.
References edm::IOVSyncValue::eventID(), filldetailcache(), edm::IOVSyncValue::luminosityBlockNumber(), m_detailcache, m_detailcachedrun, m_detailresult, m_pcurrentTime, Association::map, and v.
Referenced by DIPLumiProducer().
{ unsigned int currentrun=m_pcurrentTime->eventID().run(); unsigned int currentls=m_pcurrentTime->luminosityBlockNumber(); if(currentls==0||currentls==4294967295){ return boost::shared_ptr<DIPLumiDetail>(new DIPLumiDetail()); } if(m_detailcachedrun!=currentrun){//i'm in a new run filldetailcache(currentrun,currentls);//starting ls }else{ //i'm in an known run if(m_detailcache.find(currentls)==m_detailcache.end()){//i'm in a unknown ls filldetailcache(currentrun,currentls);//cache all ls>=currentls } } if(m_detailcache.empty()){ return boost::shared_ptr<DIPLumiDetail>(new DIPLumiDetail()); } if(m_detailcache.find(currentls)==m_detailcache.end()){ std::vector<unsigned int> v; for(std::map<unsigned int,boost::shared_ptr<DIPLumiDetail> >::iterator it=m_detailcache.begin();it!=m_detailcache.end();++it){ v.push_back(it->first); } m_detailresult=m_detailcache[v.back()]; }else{ m_detailresult=m_detailcache[currentls]; } if(m_detailresult.get()==0){ return boost::shared_ptr<DIPLumiDetail>(new DIPLumiDetail()); } return m_detailresult; }
DIPLumiProducer::ReturnSummaryType DIPLumiProducer::produceSummary | ( | const DIPLuminosityRcd & | ) |
Definition at line 74 of file DIPLumiProducer.cc.
References edm::IOVSyncValue::eventID(), fillsummarycache(), edm::IOVSyncValue::luminosityBlockNumber(), m_pcurrentTime, m_summarycache, m_summarycachedrun, m_summaryresult, Association::map, and v.
Referenced by DIPLumiProducer().
{ unsigned int currentrun=m_pcurrentTime->eventID().run(); unsigned int currentls=m_pcurrentTime->luminosityBlockNumber(); if(currentls==0||currentls==4294967295){ return boost::shared_ptr<DIPLumiSummary>(new DIPLumiSummary()); } if(m_summarycachedrun!=currentrun){//i'm in a new run fillsummarycache(currentrun,currentls);//starting ls }else{ //i'm in an old run if(m_summarycache.find(currentls)==m_summarycache.end()){//i'm not cached fillsummarycache(currentrun,currentls);// } } if(m_summarycache.empty()){ return boost::shared_ptr<DIPLumiSummary>(new DIPLumiSummary()); } if(m_summarycache.find(currentls)==m_summarycache.end()){ std::vector<unsigned int> v; for(std::map<unsigned int,boost::shared_ptr<DIPLumiSummary> >::iterator it=m_summarycache.begin();it!=m_summarycache.end();++it){ v.push_back(it->first); } m_summaryresult=m_summarycache[v.back()]; }else{ m_summaryresult=m_summarycache[currentls]; } if(m_summaryresult.get()==0){ return boost::shared_ptr<DIPLumiSummary>(new DIPLumiSummary()); } return m_summaryresult; }
void DIPLumiProducer::setIntervalFor | ( | const edm::eventsetup::EventSetupRecordKey & | iKey, |
const edm::IOVSyncValue & | iTime, | ||
edm::ValidityInterval & | oValidity | ||
) | [protected, virtual] |
Implements edm::EventSetupRecordIntervalFinder.
Definition at line 139 of file DIPLumiProducer.cc.
References m_pcurrentTime, edm::ValidityInterval::setFirst(), and edm::ValidityInterval::setLast().
{ m_pcurrentTime=&iTime; oValidity.setFirst(iTime); oValidity.setLast(iTime); }
unsigned int DIPLumiProducer::m_cachesize [private] |
Definition at line 44 of file DIPLumiProducer.h.
Referenced by DIPLumiProducer(), filldetailcache(), and fillsummarycache().
std::string DIPLumiProducer::m_connectStr [private] |
Definition at line 38 of file DIPLumiProducer.h.
Referenced by DIPLumiProducer(), filldetailcache(), and fillsummarycache().
std::map< unsigned int,boost::shared_ptr<DIPLumiDetail> > DIPLumiProducer::m_detailcache [private] |
Definition at line 40 of file DIPLumiProducer.h.
Referenced by filldetailcache(), and produceDetail().
unsigned int DIPLumiProducer::m_detailcachedrun [private] |
Definition at line 43 of file DIPLumiProducer.h.
Referenced by filldetailcache(), and produceDetail().
boost::shared_ptr<DIPLumiDetail> DIPLumiProducer::m_detailresult [private] |
Definition at line 46 of file DIPLumiProducer.h.
Referenced by produceDetail().
bool DIPLumiProducer::m_isNullRun [private] |
Definition at line 41 of file DIPLumiProducer.h.
const edm::IOVSyncValue* DIPLumiProducer::m_pcurrentTime [private] |
Definition at line 47 of file DIPLumiProducer.h.
Referenced by produceDetail(), produceSummary(), and setIntervalFor().
std::map< unsigned int,boost::shared_ptr<DIPLumiSummary> > DIPLumiProducer::m_summarycache [private] |
Definition at line 39 of file DIPLumiProducer.h.
Referenced by fillsummarycache(), and produceSummary().
unsigned int DIPLumiProducer::m_summarycachedrun [private] |
Definition at line 42 of file DIPLumiProducer.h.
Referenced by filldetailcache(), fillsummarycache(), and produceSummary().
boost::shared_ptr<DIPLumiSummary> DIPLumiProducer::m_summaryresult [private] |
Definition at line 45 of file DIPLumiProducer.h.
Referenced by produceSummary().