CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
ExpressLumiProducer Class Reference

#include <RecoLuminosity/LumiProducer/src/ExpressLumiProducer.cc>

Inheritance diagram for ExpressLumiProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Classes

struct  PerLSData
 

Public Member Functions

 ExpressLumiProducer (const edm::ParameterSet &)
 
 ~ExpressLumiProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Member Functions

virtual void beginLuminosityBlock (edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup)
 
virtual void beginRun (edm::Run &, edm::EventSetup const &)
 
virtual void endLuminosityBlock (edm::LuminosityBlock &lumiBlock, edm::EventSetup const &c)
 
virtual void endRun (edm::Run &, edm::EventSetup const &)
 
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 &)
 
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, PerLSDatam_lscache
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

Description: A essource/esproducer for lumi values from DIP via runtime logger DB

Definition at line 63 of file ExpressLumiProducer.cc.

Constructor & Destructor Documentation

ExpressLumiProducer::ExpressLumiProducer ( const edm::ParameterSet )
explicit
ExpressLumiProducer::~ExpressLumiProducer ( )

Definition at line 118 of file ExpressLumiProducer.cc.

118  {
119 }

Member Function Documentation

void ExpressLumiProducer::beginLuminosityBlock ( edm::LuminosityBlock iLBlock,
edm::EventSetup const &  iSetup 
)
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 145 of file ExpressLumiProducer.cc.

References fillLSCache(), edm::LuminosityBlockBase::luminosityBlock(), m_cachedrun, m_isNullRun, m_lscache, edm::LuminosityBlockBase::run(), v, writeEmptyProductForEntry(), and writeProductsForEntry().

146 {
147  unsigned int currentrun=iLBlock.run();
148  unsigned int currentls=iLBlock.luminosityBlock();
149  //if is null run, fill empty values and return
150  if(m_isNullRun){
151  writeEmptyProductForEntry(iLBlock);
152  return;
153  }
154  if(m_cachedrun!=currentrun){
155  fillLSCache(currentrun,currentls);
156  }else{
157  if(m_lscache.find(currentls)==m_lscache.end()){
158  //if runnumber is cached but LS is not, this is the first LS, fill LS cache to full capacity
159  fillLSCache(currentrun,currentls);
160  }
161  }
162  if( m_lscache.empty() ){
163  writeEmptyProductForEntry(iLBlock);
164  return;
165  }
166  unsigned int lstowriteout=0;
167  if(m_lscache.find(currentls)==m_lscache.end()){//if the currentls is not in the cache
168  std::vector<unsigned int> v;
169  for(std::map<unsigned int,ExpressLumiProducer::PerLSData >::iterator it=m_lscache.begin();it!=m_lscache.end();++it){
170  v.push_back(it->first);
171  }
172  lstowriteout=v.back();//last available
173  }else{//if the current ls is cached
174  lstowriteout=currentls;
175  }
176  //here the presence of ls is guaranteed
177  //std::cout<<"writing "<<runnumber<<" "<<luminum<<std::endl;
178  if(lstowriteout==0){
179  writeEmptyProductForEntry(iLBlock);
180  }else{
181  writeProductsForEntry(iLBlock,lstowriteout);
182  }
183 }
LuminosityBlockNumber_t luminosityBlock() const
std::map< unsigned int, PerLSData > m_lscache
void fillLSCache(unsigned int runnum, unsigned int luminum)
RunNumber_t run() const
void writeProductsForEntry(edm::LuminosityBlock &iLBlock, unsigned int luminum)
void writeEmptyProductForEntry(edm::LuminosityBlock &iLBlock)
mathSSE::Vec4< T > v
void ExpressLumiProducer::beginRun ( edm::Run run,
edm::EventSetup const &  iSetup 
)
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 129 of file ExpressLumiProducer.cc.

130 {
131 }
void ExpressLumiProducer::endLuminosityBlock ( edm::LuminosityBlock lumiBlock,
edm::EventSetup const &  c 
)
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 185 of file ExpressLumiProducer.cc.

186 {
187 }
void ExpressLumiProducer::endRun ( edm::Run run,
edm::EventSetup const &  iSetup 
)
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 189 of file ExpressLumiProducer.cc.

190 {
191 }
void ExpressLumiProducer::fillLSCache ( unsigned int  runnum,
unsigned int  luminum 
)
private

Definition at line 220 of file ExpressLumiProducer.cc.

References ExpressLumiProducer::PerLSData::bitzerocount, ExpressLumiProducer::PerLSData::bunchlumierror, ExpressLumiProducer::PerLSData::bunchlumiquality, ExpressLumiProducer::PerLSData::bunchlumivalue, lumi::service::DBService::connectReadOnly(), ExpressLumiProducer::PerLSData::deadcount, lumi::service::DBService::disconnect(), edm::hlt::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, and ExpressLumiProducer::PerLSData::startorbit.

Referenced by beginLuminosityBlock().

220  {
221  m_lscache.clear();
223  //
224  //queries once per cache refill
225  //
226  //select lumisection,instlumi,delivlumi,livelumi from cms_runtime_logger.lumi_sections where lumisection>=:lsmin and lumisection<:lsmax and runnumber=:runnumber;
227  //
229  if( !mydbservice.isAvailable() ){
230  throw cms::Exception("Non existing service lumi::service::DBService");
231  }
232  coral::ISessionProxy* session=mydbservice->connectReadOnly(m_connectStr);
233  coral::ITypeConverter& tconverter=session->typeConverter();
234  tconverter.setCppTypeForSqlType(std::string("float"),std::string("FLOAT(63)"));
235  tconverter.setCppTypeForSqlType(std::string("unsigned int"),std::string("NUMBER(10)"));
236  tconverter.setCppTypeForSqlType(std::string("unsigned short"),std::string("NUMBER(1)"));
237  unsigned int lsmin=1;
238  unsigned int lsmax=currentlsnum;
239  try{
240  session->transaction().start(true);
241  coral::ISchema& schema=session->nominalSchema();
242  unsigned int maxavailableLS=maxavailableLSforRun(schema,std::string("LUMI_SECTIONS"),m_cachedrun);
243  if(maxavailableLS!=0 && maxavailableLS<currentlsnum){
244  lsmax=maxavailableLS;
245  }else if(maxavailableLS==0){
246  //this run not existing (yet)
247  session->transaction().commit();
248  mydbservice->disconnect(session);
249  return;
250  }
251  if(m_cachesize!=0){
252  lsmin=(lsmax-m_cachesize)>0 ? (lsmax-m_cachesize+1) : 1;
253  }
254  for(unsigned int n=lsmin;n<=lsmax;++n){
255  PerLSData l;
256  std::vector<float> mytmp(3564,0.0);
257  l.bunchlumivalue.swap(mytmp);
258  std::vector<float> myerrtmp(3564,0.0);
259  l.bunchlumierror.swap(myerrtmp);
260  std::vector<short> myqtmp(3564,0);
261  l.bunchlumiquality.swap(myqtmp);
262  m_lscache.insert(std::make_pair(n,l));
263  }
264 
265  coral::AttributeList lumisummaryBindVariables;
266  lumisummaryBindVariables.extend("lsmin",typeid(unsigned int));
267  lumisummaryBindVariables.extend("runnumber",typeid(unsigned int));
268  lumisummaryBindVariables["runnumber"].data<unsigned int>()=m_cachedrun;
269  lumisummaryBindVariables["lsmin"].data<unsigned int>()=lsmin;
270  std::string conditionStr(" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
271  coral::AttributeList lumisummaryOutput;
272  lumisummaryOutput.extend("LUMISECTION",typeid(unsigned int));
273  lumisummaryOutput.extend("INSTLUMI",typeid(float));
274  lumisummaryOutput.extend("DELIVLUMISECTION",typeid(float));
275  lumisummaryOutput.extend("LIVELUMISECTION",typeid(float));
276  lumisummaryOutput.extend("STARTORBIT",typeid(unsigned long long));
277  if(m_cachesize!=0){
278  lumisummaryBindVariables.extend("lsmax",typeid(unsigned int));
279  conditionStr=conditionStr+"AND LUMISECTION<=:lsmax";
280  lumisummaryBindVariables["lsmax"].data<unsigned int>()=lsmax;
281  }
282  coral::IQuery* lumisummaryQuery=schema.newQuery();
283  lumisummaryQuery->addToTableList(std::string("LUMI_SECTIONS"));
284  lumisummaryQuery->addToOutputList("LUMISECTION");
285  lumisummaryQuery->addToOutputList("INSTLUMI");
286  lumisummaryQuery->addToOutputList("DELIVLUMISECTION");
287  lumisummaryQuery->addToOutputList("LIVELUMISECTION");
288  lumisummaryQuery->addToOutputList("STARTORBIT");
289  lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables);
290  lumisummaryQuery->defineOutput(lumisummaryOutput);
291  coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
292  unsigned int rowcounter=0;
293  while( lumisummarycursor.next() ){
294  const coral::AttributeList& row=lumisummarycursor.currentRow();
295  unsigned int lsnum=row["LUMISECTION"].data<unsigned int>();
296  float instlumi=0.0;
297  if(!row["INSTLUMI"].isNull()){
298  instlumi=row["INSTLUMI"].data<float>();//Hz/ub
299  }
300  float deadfrac=1.0;
301  float intgdellumi=0.0;
302  float intgreclumi=0.0;
303  unsigned long long startorbit=0;
304  if(!row["DELIVLUMISECTION"].isNull()){
305  intgdellumi=row["DELIVLUMISECTION"].data<float>()*1000.0;//convert to /ub
306  }
307  if(!row["LIVELUMISECTION"].isNull()){
308  intgreclumi=row["LIVELUMISECTION"].data<float>()*1000.0;//convert to /ub
309  }
310  if(intgdellumi>0){
311  deadfrac=1.0-intgreclumi/intgdellumi;
312  }
313  if(!row["STARTORBIT"].isNull()){
314  startorbit=row["STARTORBIT"].data<unsigned long long>();//convert to /ub
315  }
316  unsigned long long deadcount=deadfrac*10000.0;
317  unsigned long long bitzerocount=10000.0;
318  PerLSData& lsdata=m_lscache[lsnum];
319  lsdata.lsnum=lsnum;
320  lsdata.lumivalue=instlumi;
321  lsdata.deadcount=deadcount;
322  lsdata.bitzerocount=bitzerocount;
323  lsdata.startorbit=startorbit;
324  lsdata.numorbit=262144;
325  ++rowcounter;
326  }
327  if (rowcounter==0){
328  m_isNullRun=true;
329  }
330  delete lumisummaryQuery;
331  if(m_isNullRun) return;
332  //
333  //queries once per cache refill
334  //
335  //select lumisection,bunch,bunchlumi from cms_runtime_logger.bunch_lumi_sections where lumisection>=:lsmin and lumisection<:lsmax and runnumber=:runnumber;
336  //
337  coral::AttributeList lumidetailBindVariables;
338  lumidetailBindVariables.extend("lsmin",typeid(unsigned int));
339  lumidetailBindVariables.extend("runnumber",typeid(unsigned int));
340  lumidetailBindVariables["runnumber"].data<unsigned int>()=m_cachedrun;
341  lumidetailBindVariables["lsmin"].data<unsigned int>()=lsmin;
342  std::string detailconditionStr(" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
343  coral::AttributeList lumidetailOutput;
344  lumidetailOutput.extend("LUMISECTION",typeid(unsigned int));
345  lumidetailOutput.extend("BUNCH",typeid(unsigned int));
346  lumidetailOutput.extend("BUNCHLUMI",typeid(float));
347  if(m_cachesize!=0){
348  lumidetailBindVariables.extend("lsmax",typeid(unsigned int));
349  detailconditionStr=detailconditionStr+"AND LUMISECTION<=:lsmax";
350  lumidetailBindVariables["lsmax"].data<unsigned int>()=lsmax;
351  }
352  coral::IQuery* lumidetailQuery=schema.newQuery();
353  lumidetailQuery->addToTableList(std::string("BUNCH_LUMI_SECTIONS"));
354  lumidetailQuery->addToOutputList("LUMISECTION");
355  lumidetailQuery->addToOutputList("BUNCH");
356  lumidetailQuery->addToOutputList("BUNCHLUMI");
357  lumidetailQuery->setCondition(detailconditionStr,lumidetailBindVariables);
358  lumidetailQuery->defineOutput(lumidetailOutput);
359  coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
360  while( lumidetailcursor.next() ){
361  const coral::AttributeList& row=lumidetailcursor.currentRow();
362  unsigned int lsnum=row["LUMISECTION"].data<unsigned int>();
363  unsigned int bxidx=row["BUNCH"].data<unsigned int>();
364  float bxlumi=row["BUNCHLUMI"].data<float>();//Hz/ub
365  m_lscache[lsnum].bunchlumivalue[bxidx]=bxlumi;
366  }
367  delete lumidetailQuery;
368  session->transaction().commit();
369  }catch(const coral::Exception& er){
370  session->transaction().rollback();
371  mydbservice->disconnect(session);
372  throw cms::Exception("DatabaseError ")<<er.what();
373  }
374  mydbservice->disconnect(session);
375 }
std::map< unsigned int, PerLSData > m_lscache
bool isAvailable() const
Definition: Service.h:47
void disconnect(coral::ISessionProxy *session)
Definition: DBService.cc:46
unsigned int maxavailableLSforRun(coral::ISchema &schema, const std::string &tablename, unsigned int runnumber)
coral::ISessionProxy * connectReadOnly(const std::string &connectstring)
Definition: DBService.cc:42
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 194 of file ExpressLumiProducer.cc.

References UserOptions_cff::myQuery, and query::result.

Referenced by fillLSCache().

194  {
198  unsigned int result=0;
199  coral::AttributeList bindVariables;
200  bindVariables.extend("runnumber",typeid(unsigned int));
201  bindVariables["runnumber"].data<unsigned int>()=runnumber;
202  std::string conditionStr("RUNNUMBER=:runnumber");
203  coral::AttributeList MyOutput;
204  MyOutput.extend("maxavailablels",typeid(unsigned int));
205  coral::IQuery* myQuery=schema.newQuery();
206  myQuery->addToTableList(tablename);
207  myQuery->addToOutputList("max(LUMISECTION)","maxavailablels");
208  myQuery->setCondition(conditionStr,bindVariables);
209  myQuery->defineOutput(MyOutput);
210  coral::ICursor& mycursor=myQuery->execute();
211  while( mycursor.next() ){
212  const coral::AttributeList& row=mycursor.currentRow();
213  if(!row["maxavailablels"].isNull()){
214  result=row["maxavailablels"].data<unsigned int>();
215  }
216  }
217  return result;
218 }
list tablename
Definition: asciidump.py:411
tuple result
Definition: query.py:137
void ExpressLumiProducer::produce ( edm::Event e,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 125 of file ExpressLumiProducer.cc.

126 {
127 }
void ExpressLumiProducer::writeEmptyProductForEntry ( edm::LuminosityBlock iLBlock)
private

Definition at line 134 of file ExpressLumiProducer.cc.

References edm::LuminosityBlock::put().

Referenced by beginLuminosityBlock().

134  {
135  std::auto_ptr<LumiSummary> pOut1;
136  std::auto_ptr<LumiDetails> pOut2;
137  LumiSummary* pIn1=new LumiSummary;
138  LumiDetails* pIn2=new LumiDetails;
139  pOut1.reset(pIn1);
140  iLBlock.put(pOut1);
141  pOut2.reset(pIn2);
142  iLBlock.put(pOut2);
143 }
void put(std::auto_ptr< PROD > product)
Put a new product.
void ExpressLumiProducer::writeProductsForEntry ( edm::LuminosityBlock iLBlock,
unsigned int  luminum 
)
private

Definition at line 377 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 beginLuminosityBlock().

377  {
378  //std::cout<<"writing runnumber,luminum "<<runnumber<<" "<<luminum<<std::endl;
379  std::auto_ptr<LumiSummary> pOut1;
380  std::auto_ptr<LumiDetails> pOut2;
381  LumiSummary* pIn1=new LumiSummary;
382  LumiDetails* pIn2=new LumiDetails;
383  if(m_isNullRun){
384  pIn1->setLumiVersion("DIP");
385  pIn2->setLumiVersion("DIP");
386  pOut1.reset(pIn1);
387  iLBlock.put(pOut1);
388  pOut2.reset(pIn2);
389  iLBlock.put(pOut2);
390  return;
391  }
392  PerLSData& lsdata=m_lscache[luminum];
393  pIn1->setLumiVersion("DIP");
394  pIn1->setLumiData(lsdata.lumivalue,0.0,0.0);
395  pIn1->setDeadCount(lsdata.deadcount);
396  pIn1->setBitZeroCount(lsdata.bitzerocount);
397  pIn1->setlsnumber(lsdata.lsnum);
398  pIn1->setOrbitData(lsdata.startorbit,lsdata.numorbit);
399 
400  pIn2->setLumiVersion("DIP");
401  pIn2->fill(LumiDetails::kOCC1,lsdata.bunchlumivalue,lsdata.bunchlumierror,lsdata.bunchlumiquality);
402  pOut1.reset(pIn1);
403  iLBlock.put(pOut1);
404  pOut2.reset(pIn2);
405  iLBlock.put(pOut2);
406 }
void setLumiVersion(std::string const &lumiVersion)
Definition: LumiDetails.cc:36
std::map< unsigned int, PerLSData > m_lscache
void setlsnumber(unsigned int lsnumber)
Definition: LumiSummary.cc:141
void setOrbitData(unsigned int startorbit, unsigned int numorbit)
Definition: LumiSummary.cc:145
void fill(AlgoType algo, std::vector< float > const &values, std::vector< float > const &errors, std::vector< short > const &qualities)
Definition: LumiDetails.cc:51
void setLumiVersion(const std::string &lumiversion)
Definition: LumiSummary.cc:123
void setLumiData(float instlumi, float instlumierr, short lumiquality)
Definition: LumiSummary.cc:127
void setBitZeroCount(unsigned long long bitzerocount)
Definition: LumiSummary.cc:137
void setDeadCount(unsigned long long deadcount)
Definition: LumiSummary.cc:133
void put(std::auto_ptr< PROD > product)
Put a new product.

Member Data Documentation

unsigned int ExpressLumiProducer::m_cachedrun
private

Definition at line 101 of file ExpressLumiProducer.cc.

Referenced by beginLuminosityBlock(), and fillLSCache().

unsigned int ExpressLumiProducer::m_cachesize
private

Definition at line 103 of file ExpressLumiProducer.cc.

Referenced by fillLSCache().

std::string ExpressLumiProducer::m_connectStr
private

Definition at line 100 of file ExpressLumiProducer.cc.

Referenced by fillLSCache().

bool ExpressLumiProducer::m_isNullRun
private
std::map< unsigned int,PerLSData > ExpressLumiProducer::m_lscache
private