#include <RecoLuminosity/LumiProducer/src/ExpressLumiProducer.cc>
Classes | |
struct | PerLSData |
Public Member Functions | |
ExpressLumiProducer (const edm::ParameterSet &) | |
~ExpressLumiProducer () | |
Private Member Functions | |
virtual void | beginLuminosityBlockProduce (edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup) override final |
void | fillLSCache (unsigned int runnum, unsigned int luminum) |
bool | fillLumi (edm::LuminosityBlock &iLBlock) |
unsigned int | maxavailableLSforRun (coral::ISchema &schema, const std::string &tablename, unsigned int runnumber) |
virtual void | produce (edm::Event &, const edm::EventSetup &) override final |
void | writeEmptyProductForEntry (edm::LuminosityBlock &iLBlock) |
void | writeProductsForEntry (edm::LuminosityBlock &iLBlock, unsigned int luminum) |
Private Attributes | |
unsigned int | m_cachedrun |
unsigned int | m_cachesize |
std::string | m_connectStr |
bool | m_isNullRun |
std::map< unsigned int, PerLSData > | m_lscache |
Description: A essource/esproducer for lumi values from DIP via runtime logger DB
Definition at line 63 of file ExpressLumiProducer.cc.
ExpressLumiProducer::ExpressLumiProducer | ( | const edm::ParameterSet & | ) | [explicit] |
ExpressLumiProducer::~ExpressLumiProducer | ( | ) |
Definition at line 112 of file ExpressLumiProducer.cc.
{ }
void ExpressLumiProducer::beginLuminosityBlockProduce | ( | edm::LuminosityBlock & | iLBlock, |
edm::EventSetup const & | iSetup | ||
) | [override, private, virtual] |
Definition at line 135 of file ExpressLumiProducer.cc.
References fillLSCache(), edm::LuminosityBlockBase::luminosityBlock(), m_cachedrun, m_isNullRun, m_lscache, edm::LuminosityBlockBase::run(), findQualityFiles::v, writeEmptyProductForEntry(), and writeProductsForEntry().
{ unsigned int currentrun=iLBlock.run(); unsigned int currentls=iLBlock.luminosityBlock(); //if is null run, fill empty values and return if(m_isNullRun){ writeEmptyProductForEntry(iLBlock); return; } if(m_cachedrun!=currentrun){ fillLSCache(currentrun,currentls); }else{ if(m_lscache.find(currentls)==m_lscache.end()){ //if runnumber is cached but LS is not, this is the first LS, fill LS cache to full capacity fillLSCache(currentrun,currentls); } } if( m_lscache.empty() ){ writeEmptyProductForEntry(iLBlock); return; } unsigned int lstowriteout=0; if(m_lscache.find(currentls)==m_lscache.end()){//if the currentls is not in the cache std::vector<unsigned int> v; for(std::map<unsigned int,ExpressLumiProducer::PerLSData >::iterator it=m_lscache.begin();it!=m_lscache.end();++it){ v.push_back(it->first); } lstowriteout=v.back();//last available }else{//if the current ls is cached lstowriteout=currentls; } //here the presence of ls is guaranteed //std::cout<<"writing "<<runnumber<<" "<<luminum<<std::endl; if(lstowriteout==0){ writeEmptyProductForEntry(iLBlock); }else{ writeProductsForEntry(iLBlock,lstowriteout); } }
void ExpressLumiProducer::fillLSCache | ( | unsigned int | runnum, |
unsigned int | luminum | ||
) | [private] |
Definition at line 202 of file ExpressLumiProducer.cc.
References ExpressLumiProducer::PerLSData::bitzerocount, ExpressLumiProducer::PerLSData::bunchlumierror, ExpressLumiProducer::PerLSData::bunchlumiquality, ExpressLumiProducer::PerLSData::bunchlumivalue, ExpressLumiProducer::PerLSData::deadcount, Exception, edm::Service< T >::isAvailable(), prof2calltree::l, ExpressLumiProducer::PerLSData::lsnum, ExpressLumiProducer::PerLSData::lumivalue, m_cachedrun, m_cachesize, m_connectStr, m_isNullRun, m_lscache, maxavailableLSforRun(), n, ExpressLumiProducer::PerLSData::numorbit, cond::runnumber, python::IdGenerator::schema, python::CommonUtils::session, ExpressLumiProducer::PerLSData::startorbit, and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by beginLuminosityBlockProduce().
{ m_lscache.clear(); m_cachedrun=runnumber; // //queries once per cache refill // //select 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_cachedrun); 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; } for(unsigned int n=lsmin;n<=lsmax;++n){ PerLSData l; std::vector<float> mytmp(3564,0.0); l.bunchlumivalue.swap(mytmp); std::vector<float> myerrtmp(3564,0.0); l.bunchlumierror.swap(myerrtmp); std::vector<short> myqtmp(3564,0); l.bunchlumiquality.swap(myqtmp); m_lscache.insert(std::make_pair(n,l)); } coral::AttributeList lumisummaryBindVariables; lumisummaryBindVariables.extend("lsmin",typeid(unsigned int)); lumisummaryBindVariables.extend("runnumber",typeid(unsigned int)); lumisummaryBindVariables["runnumber"].data<unsigned int>()=m_cachedrun; lumisummaryBindVariables["lsmin"].data<unsigned int>()=lsmin; std::string conditionStr(" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin "); 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("STARTORBIT",typeid(unsigned long long)); if(m_cachesize!=0){ lumisummaryBindVariables.extend("lsmax",typeid(unsigned int)); conditionStr=conditionStr+"AND LUMISECTION<=:lsmax"; lumisummaryBindVariables["lsmax"].data<unsigned int>()=lsmax; } 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("STARTORBIT"); lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables); lumisummaryQuery->defineOutput(lumisummaryOutput); coral::ICursor& lumisummarycursor=lumisummaryQuery->execute(); unsigned int rowcounter=0; 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 deadfrac=1.0; float intgdellumi=0.0; float intgreclumi=0.0; unsigned long long startorbit=0; if(!row["DELIVLUMISECTION"].isNull()){ intgdellumi=row["DELIVLUMISECTION"].data<float>()*1000.0;//convert to /ub } if(!row["LIVELUMISECTION"].isNull()){ intgreclumi=row["LIVELUMISECTION"].data<float>()*1000.0;//convert to /ub } if(intgdellumi>0){ deadfrac=1.0-intgreclumi/intgdellumi; } if(!row["STARTORBIT"].isNull()){ startorbit=row["STARTORBIT"].data<unsigned long long>();//convert to /ub } unsigned long long deadcount=deadfrac*10000.0; unsigned long long bitzerocount=10000.0; PerLSData& lsdata=m_lscache[lsnum]; lsdata.lsnum=lsnum; lsdata.lumivalue=instlumi; lsdata.deadcount=deadcount; lsdata.bitzerocount=bitzerocount; lsdata.startorbit=startorbit; lsdata.numorbit=262144; ++rowcounter; } if (rowcounter==0){ m_isNullRun=true; } delete lumisummaryQuery; if(m_isNullRun) return; // //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; // coral::AttributeList lumidetailBindVariables; lumidetailBindVariables.extend("lsmin",typeid(unsigned int)); lumidetailBindVariables.extend("runnumber",typeid(unsigned int)); lumidetailBindVariables["runnumber"].data<unsigned int>()=m_cachedrun; lumidetailBindVariables["lsmin"].data<unsigned int>()=lsmin; std::string detailconditionStr(" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 "); coral::AttributeList lumidetailOutput; lumidetailOutput.extend("LUMISECTION",typeid(unsigned int)); lumidetailOutput.extend("BUNCH",typeid(unsigned int)); lumidetailOutput.extend("BUNCHLUMI",typeid(float)); if(m_cachesize!=0){ lumidetailBindVariables.extend("lsmax",typeid(unsigned int)); detailconditionStr=detailconditionStr+"AND LUMISECTION<=:lsmax"; lumidetailBindVariables["lsmax"].data<unsigned int>()=lsmax; } coral::IQuery* lumidetailQuery=schema.newQuery(); lumidetailQuery->addToTableList(std::string("BUNCH_LUMI_SECTIONS")); lumidetailQuery->addToOutputList("LUMISECTION"); lumidetailQuery->addToOutputList("BUNCH"); lumidetailQuery->addToOutputList("BUNCHLUMI"); lumidetailQuery->setCondition(detailconditionStr,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>(); unsigned int bxidx=row["BUNCH"].data<unsigned int>(); float bxlumi=row["BUNCHLUMI"].data<float>();//Hz/ub m_lscache[lsnum].bunchlumivalue[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); }
bool ExpressLumiProducer::fillLumi | ( | edm::LuminosityBlock & | iLBlock | ) | [private] |
unsigned int ExpressLumiProducer::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 176 of file ExpressLumiProducer.cc.
References inputsource_file_cfi::myQuery, query::result, and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by fillLSCache().
{ 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; }
void ExpressLumiProducer::produce | ( | edm::Event & | e, |
const edm::EventSetup & | iSetup | ||
) | [override, private, virtual] |
void ExpressLumiProducer::writeEmptyProductForEntry | ( | edm::LuminosityBlock & | iLBlock | ) | [private] |
Definition at line 124 of file ExpressLumiProducer.cc.
References edm::LuminosityBlock::put().
Referenced by beginLuminosityBlockProduce().
{ std::auto_ptr<LumiSummary> pOut1; std::auto_ptr<LumiDetails> pOut2; LumiSummary* pIn1=new LumiSummary; LumiDetails* pIn2=new LumiDetails; pOut1.reset(pIn1); iLBlock.put(pOut1); pOut2.reset(pIn2); iLBlock.put(pOut2); }
void ExpressLumiProducer::writeProductsForEntry | ( | edm::LuminosityBlock & | iLBlock, |
unsigned int | luminum | ||
) | [private] |
Definition at line 359 of file ExpressLumiProducer.cc.
References ExpressLumiProducer::PerLSData::bitzerocount, ExpressLumiProducer::PerLSData::bunchlumierror, ExpressLumiProducer::PerLSData::bunchlumiquality, ExpressLumiProducer::PerLSData::bunchlumivalue, ExpressLumiProducer::PerLSData::deadcount, LumiDetails::fill(), LumiDetails::kOCC1, ExpressLumiProducer::PerLSData::lsnum, ExpressLumiProducer::PerLSData::lumivalue, m_isNullRun, m_lscache, ExpressLumiProducer::PerLSData::numorbit, edm::LuminosityBlock::put(), LumiSummary::setBitZeroCount(), LumiSummary::setDeadCount(), LumiSummary::setlsnumber(), LumiSummary::setLumiData(), LumiDetails::setLumiVersion(), LumiSummary::setLumiVersion(), LumiSummary::setOrbitData(), and ExpressLumiProducer::PerLSData::startorbit.
Referenced by beginLuminosityBlockProduce().
{ //std::cout<<"writing runnumber,luminum "<<runnumber<<" "<<luminum<<std::endl; std::auto_ptr<LumiSummary> pOut1; std::auto_ptr<LumiDetails> pOut2; LumiSummary* pIn1=new LumiSummary; LumiDetails* pIn2=new LumiDetails; if(m_isNullRun){ pIn1->setLumiVersion("DIP"); pIn2->setLumiVersion("DIP"); pOut1.reset(pIn1); iLBlock.put(pOut1); pOut2.reset(pIn2); iLBlock.put(pOut2); return; } PerLSData& lsdata=m_lscache[luminum]; pIn1->setLumiVersion("DIP"); pIn1->setLumiData(lsdata.lumivalue,0.0,0.0); pIn1->setDeadCount(lsdata.deadcount); pIn1->setBitZeroCount(lsdata.bitzerocount); pIn1->setlsnumber(lsdata.lsnum); pIn1->setOrbitData(lsdata.startorbit,lsdata.numorbit); pIn2->setLumiVersion("DIP"); pIn2->fill(LumiDetails::kOCC1,lsdata.bunchlumivalue,lsdata.bunchlumierror,lsdata.bunchlumiquality); pOut1.reset(pIn1); iLBlock.put(pOut1); pOut2.reset(pIn2); iLBlock.put(pOut2); }
unsigned int ExpressLumiProducer::m_cachedrun [private] |
Definition at line 95 of file ExpressLumiProducer.cc.
Referenced by beginLuminosityBlockProduce(), and fillLSCache().
unsigned int ExpressLumiProducer::m_cachesize [private] |
Definition at line 97 of file ExpressLumiProducer.cc.
Referenced by fillLSCache().
std::string ExpressLumiProducer::m_connectStr [private] |
Definition at line 94 of file ExpressLumiProducer.cc.
Referenced by fillLSCache().
bool ExpressLumiProducer::m_isNullRun [private] |
Definition at line 96 of file ExpressLumiProducer.cc.
Referenced by beginLuminosityBlockProduce(), fillLSCache(), and writeProductsForEntry().
std::map< unsigned int,PerLSData > ExpressLumiProducer::m_lscache [private] |
Definition at line 98 of file ExpressLumiProducer.cc.
Referenced by beginLuminosityBlockProduce(), fillLSCache(), and writeProductsForEntry().