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::one::EDProducer< edm::BeginLuminosityBlockProducer > edm::one::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Classes

struct  PerLSData
 

Public Member Functions

 ExpressLumiProducer (const edm::ParameterSet &)
 
 ~ExpressLumiProducer ()
 
- Public Member Functions inherited from edm::one::EDProducer< edm::BeginLuminosityBlockProducer >
 EDProducer ()=default
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void beginLuminosityBlockProduce (edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup) overridefinal
 
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 &) overridefinal
 
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::one::EDProducerBase
typedef EDProducerBase ModuleType
 
typedef WorkerT< EDProducerBaseWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::one::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::one::EDProducerBase
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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 112 of file ExpressLumiProducer.cc.

112  {
113 }

Member Function Documentation

void ExpressLumiProducer::beginLuminosityBlockProduce ( edm::LuminosityBlock iLBlock,
edm::EventSetup const &  iSetup 
)
finaloverrideprivatevirtual

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().

136 {
137  unsigned int currentrun=iLBlock.run();
138  unsigned int currentls=iLBlock.luminosityBlock();
139  //if is null run, fill empty values and return
140  if(m_isNullRun){
141  writeEmptyProductForEntry(iLBlock);
142  return;
143  }
144  if(m_cachedrun!=currentrun){
145  fillLSCache(currentrun,currentls);
146  }else{
147  if(m_lscache.find(currentls)==m_lscache.end()){
148  //if runnumber is cached but LS is not, this is the first LS, fill LS cache to full capacity
149  fillLSCache(currentrun,currentls);
150  }
151  }
152  if( m_lscache.empty() ){
153  writeEmptyProductForEntry(iLBlock);
154  return;
155  }
156  unsigned int lstowriteout=0;
157  if(m_lscache.find(currentls)==m_lscache.end()){//if the currentls is not in the cache
158  std::vector<unsigned int> v;
159  for(std::map<unsigned int,ExpressLumiProducer::PerLSData >::iterator it=m_lscache.begin();it!=m_lscache.end();++it){
160  v.push_back(it->first);
161  }
162  lstowriteout=v.back();//last available
163  }else{//if the current ls is cached
164  lstowriteout=currentls;
165  }
166  //here the presence of ls is guaranteed
167  //std::cout<<"writing "<<runnumber<<" "<<luminum<<std::endl;
168  if(lstowriteout==0){
169  writeEmptyProductForEntry(iLBlock);
170  }else{
171  writeProductsForEntry(iLBlock,lstowriteout);
172  }
173 }
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)
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, 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, ExpressLumiProducer::PerLSData::startorbit, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by beginLuminosityBlockProduce().

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

References inputsource_file_cfi::myQuery, query::result, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by fillLSCache().

176  {
180  unsigned int result=0;
181  coral::AttributeList bindVariables;
182  bindVariables.extend("runnumber",typeid(unsigned int));
183  bindVariables["runnumber"].data<unsigned int>()=runnumber;
184  std::string conditionStr("RUNNUMBER=:runnumber");
185  coral::AttributeList MyOutput;
186  MyOutput.extend("maxavailablels",typeid(unsigned int));
187  coral::IQuery* myQuery=schema.newQuery();
188  myQuery->addToTableList(tablename);
189  myQuery->addToOutputList("max(LUMISECTION)","maxavailablels");
190  myQuery->setCondition(conditionStr,bindVariables);
191  myQuery->defineOutput(MyOutput);
192  coral::ICursor& mycursor=myQuery->execute();
193  while( mycursor.next() ){
194  const coral::AttributeList& row=mycursor.currentRow();
195  if(!row["maxavailablels"].isNull()){
196  result=row["maxavailablels"].data<unsigned int>();
197  }
198  }
199  return result;
200 }
list tablename
Definition: asciidump.py:411
tuple result
Definition: query.py:137
void ExpressLumiProducer::produce ( edm::Event e,
const edm::EventSetup iSetup 
)
finaloverrideprivatevirtual

Implements edm::one::EDProducerBase.

Definition at line 119 of file ExpressLumiProducer.cc.

120 {
121 }
void ExpressLumiProducer::writeEmptyProductForEntry ( edm::LuminosityBlock iLBlock)
private

Definition at line 124 of file ExpressLumiProducer.cc.

References edm::LuminosityBlock::put().

Referenced by beginLuminosityBlockProduce().

124  {
125  std::auto_ptr<LumiSummary> pOut1;
126  std::auto_ptr<LumiDetails> pOut2;
127  LumiSummary* pIn1=new LumiSummary;
128  LumiDetails* pIn2=new LumiDetails;
129  pOut1.reset(pIn1);
130  iLBlock.put(pOut1);
131  pOut2.reset(pIn2);
132  iLBlock.put(pOut2);
133 }
void put(std::auto_ptr< PROD > product)
Put a new product.
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().

359  {
360  //std::cout<<"writing runnumber,luminum "<<runnumber<<" "<<luminum<<std::endl;
361  std::auto_ptr<LumiSummary> pOut1;
362  std::auto_ptr<LumiDetails> pOut2;
363  LumiSummary* pIn1=new LumiSummary;
364  LumiDetails* pIn2=new LumiDetails;
365  if(m_isNullRun){
366  pIn1->setLumiVersion("DIP");
367  pIn2->setLumiVersion("DIP");
368  pOut1.reset(pIn1);
369  iLBlock.put(pOut1);
370  pOut2.reset(pIn2);
371  iLBlock.put(pOut2);
372  return;
373  }
374  PerLSData& lsdata=m_lscache[luminum];
375  pIn1->setLumiVersion("DIP");
376  pIn1->setLumiData(lsdata.lumivalue,0.0,0.0);
377  pIn1->setDeadCount(lsdata.deadcount);
378  pIn1->setBitZeroCount(lsdata.bitzerocount);
379  pIn1->setlsnumber(lsdata.lsnum);
380  pIn1->setOrbitData(lsdata.startorbit,lsdata.numorbit);
381 
382  pIn2->setLumiVersion("DIP");
383  pIn2->fill(LumiDetails::kOCC1,lsdata.bunchlumivalue,lsdata.bunchlumierror,lsdata.bunchlumiquality);
384  pOut1.reset(pIn1);
385  iLBlock.put(pOut1);
386  pOut2.reset(pIn2);
387  iLBlock.put(pOut2);
388 }
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:142
void setOrbitData(unsigned int startorbit, unsigned int numorbit)
Definition: LumiSummary.cc:146
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:124
void setLumiData(float instlumi, float instlumierr, short lumiquality)
Definition: LumiSummary.cc:128
void setBitZeroCount(unsigned long long bitzerocount)
Definition: LumiSummary.cc:138
void setDeadCount(unsigned long long deadcount)
Definition: LumiSummary.cc:134
void put(std::auto_ptr< PROD > product)
Put a new product.

Member Data Documentation

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
std::map< unsigned int,PerLSData > ExpressLumiProducer::m_lscache
private