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 ()
 
ModuleDescription const & moduleDescription () const
 
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 ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) 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
 
- 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::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 62 of file ExpressLumiProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 111 of file ExpressLumiProducer.cc.

111  {
112 }

Member Function Documentation

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

Definition at line 134 of file ExpressLumiProducer.cc.

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

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

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

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

Referenced by fillLSCache().

175  {
179  unsigned int result=0;
180  coral::AttributeList bindVariables;
181  bindVariables.extend("runnumber",typeid(unsigned int));
182  bindVariables["runnumber"].data<unsigned int>()=runnumber;
183  std::string conditionStr("RUNNUMBER=:runnumber");
184  coral::AttributeList MyOutput;
185  MyOutput.extend("maxavailablels",typeid(unsigned int));
186  coral::IQuery* myQuery=schema.newQuery();
187  myQuery->addToTableList(tablename);
188  myQuery->addToOutputList("max(LUMISECTION)","maxavailablels");
189  myQuery->setCondition(conditionStr,bindVariables);
190  myQuery->defineOutput(MyOutput);
191  coral::ICursor& mycursor=myQuery->execute();
192  while( mycursor.next() ){
193  const coral::AttributeList& row=mycursor.currentRow();
194  if(!row["maxavailablels"].isNull()){
195  result=row["maxavailablels"].data<unsigned int>();
196  }
197  }
198  return result;
199 }
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 118 of file ExpressLumiProducer.cc.

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

Definition at line 123 of file ExpressLumiProducer.cc.

References edm::LuminosityBlock::put().

Referenced by beginLuminosityBlockProduce().

123  {
124  std::auto_ptr<LumiSummary> pOut1;
125  std::auto_ptr<LumiDetails> pOut2;
126  LumiSummary* pIn1=new LumiSummary;
127  LumiDetails* pIn2=new LumiDetails;
128  pOut1.reset(pIn1);
129  iLBlock.put(pOut1);
130  pOut2.reset(pIn2);
131  iLBlock.put(pOut2);
132 }
void put(std::auto_ptr< PROD > product)
Put a new product.
void ExpressLumiProducer::writeProductsForEntry ( edm::LuminosityBlock iLBlock,
unsigned int  luminum 
)
private

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

358  {
359  //std::cout<<"writing runnumber,luminum "<<runnumber<<" "<<luminum<<std::endl;
360  std::auto_ptr<LumiSummary> pOut1;
361  std::auto_ptr<LumiDetails> pOut2;
362  LumiSummary* pIn1=new LumiSummary;
363  LumiDetails* pIn2=new LumiDetails;
364  if(m_isNullRun){
365  pIn1->setLumiVersion("DIP");
366  pIn2->setLumiVersion("DIP");
367  pOut1.reset(pIn1);
368  iLBlock.put(pOut1);
369  pOut2.reset(pIn2);
370  iLBlock.put(pOut2);
371  return;
372  }
373  PerLSData& lsdata=m_lscache[luminum];
374  pIn1->setLumiVersion("DIP");
375  pIn1->setLumiData(lsdata.lumivalue,0.0,0.0);
376  pIn1->setDeadCount(lsdata.deadcount);
377  pIn1->setBitZeroCount(lsdata.bitzerocount);
378  pIn1->setlsnumber(lsdata.lsnum);
379  pIn1->setOrbitData(lsdata.startorbit,lsdata.numorbit);
380 
381  pIn2->setLumiVersion("DIP");
382  pIn2->fill(LumiDetails::kOCC1,lsdata.bunchlumivalue,lsdata.bunchlumierror,lsdata.bunchlumiquality);
383  pOut1.reset(pIn1);
384  iLBlock.put(pOut1);
385  pOut2.reset(pIn2);
386  iLBlock.put(pOut2);
387 }
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 94 of file ExpressLumiProducer.cc.

Referenced by beginLuminosityBlockProduce(), and fillLSCache().

unsigned int ExpressLumiProducer::m_cachesize
private

Definition at line 96 of file ExpressLumiProducer.cc.

Referenced by fillLSCache().

std::string ExpressLumiProducer::m_connectStr
private

Definition at line 93 of file ExpressLumiProducer.cc.

Referenced by fillLSCache().

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