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
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector
< edm::ProductResolverIndex >
const & 
indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector
< ProductResolverIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

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
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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::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 128 of file ExpressLumiProducer.cc.

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

129 {
130  unsigned int currentrun=iLBlock.run();
131  unsigned int currentls=iLBlock.luminosityBlock();
132  //if is null run, fill empty values and return
133  if(m_isNullRun){
134  writeEmptyProductForEntry(iLBlock);
135  return;
136  }
137  if(m_cachedrun!=currentrun){
138  fillLSCache(currentrun,currentls);
139  }else{
140  if(m_lscache.find(currentls)==m_lscache.end()){
141  //if runnumber is cached but LS is not, this is the first LS, fill LS cache to full capacity
142  fillLSCache(currentrun,currentls);
143  }
144  }
145  if( m_lscache.empty() ){
146  writeEmptyProductForEntry(iLBlock);
147  return;
148  }
149  unsigned int lstowriteout=0;
150  if(m_lscache.find(currentls)==m_lscache.end()){//if the currentls is not in the cache
151  std::vector<unsigned int> v;
152  for(std::map<unsigned int,ExpressLumiProducer::PerLSData >::iterator it=m_lscache.begin();it!=m_lscache.end();++it){
153  v.push_back(it->first);
154  }
155  lstowriteout=v.back();//last available
156  }else{//if the current ls is cached
157  lstowriteout=currentls;
158  }
159  //here the presence of ls is guaranteed
160  //std::cout<<"writing "<<runnumber<<" "<<luminum<<std::endl;
161  if(lstowriteout==0){
162  writeEmptyProductForEntry(iLBlock);
163  }else{
164  writeProductsForEntry(iLBlock,lstowriteout);
165  }
166 }
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 195 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(), Exception, edm::Service< T >::isAvailable(), cmsLHEtoEOSManager::l, ExpressLumiProducer::PerLSData::lsnum, ExpressLumiProducer::PerLSData::lumivalue, m_cachedrun, m_cachesize, m_connectStr, m_isNullRun, m_lscache, maxavailableLSforRun(), gen::n, ExpressLumiProducer::PerLSData::numorbit, cond::runnumber, dataDML::schema, dataDML::session, ExpressLumiProducer::PerLSData::startorbit, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by beginLuminosityBlockProduce().

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

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

Referenced by fillLSCache().

169  {
173  unsigned int result=0;
174  coral::AttributeList bindVariables;
175  bindVariables.extend("runnumber",typeid(unsigned int));
176  bindVariables["runnumber"].data<unsigned int>()=runnumber;
177  std::string conditionStr("RUNNUMBER=:runnumber");
178  coral::AttributeList MyOutput;
179  MyOutput.extend("maxavailablels",typeid(unsigned int));
180  coral::IQuery* myQuery=schema.newQuery();
181  myQuery->addToTableList(tablename);
182  myQuery->addToOutputList("max(LUMISECTION)","maxavailablels");
183  myQuery->setCondition(conditionStr,bindVariables);
184  myQuery->defineOutput(MyOutput);
185  coral::ICursor& mycursor=myQuery->execute();
186  while( mycursor.next() ){
187  const coral::AttributeList& row=mycursor.currentRow();
188  if(!row["maxavailablels"].isNull()){
189  result=row["maxavailablels"].data<unsigned int>();
190  }
191  }
192  return result;
193 }
tuple schema
Definition: dataDML.py:2334
tuple result
Definition: mps_fire.py:84
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  iLBlock.put(std::make_unique<LumiSummary>());
125  iLBlock.put(std::make_unique<LumiDetails>());
126 }
void put(std::unique_ptr< PROD > product)
Put a new product.
void ExpressLumiProducer::writeProductsForEntry ( edm::LuminosityBlock iLBlock,
unsigned int  luminum 
)
private

Definition at line 352 of file ExpressLumiProducer.cc.

References ExpressLumiProducer::PerLSData::bitzerocount, ExpressLumiProducer::PerLSData::bunchlumierror, ExpressLumiProducer::PerLSData::bunchlumiquality, ExpressLumiProducer::PerLSData::bunchlumivalue, ExpressLumiProducer::PerLSData::deadcount, LumiDetails::kOCC1, ExpressLumiProducer::PerLSData::lsnum, ExpressLumiProducer::PerLSData::lumivalue, m_isNullRun, m_lscache, eostools::move(), ExpressLumiProducer::PerLSData::numorbit, edm::LuminosityBlock::put(), and ExpressLumiProducer::PerLSData::startorbit.

Referenced by beginLuminosityBlockProduce().

352  {
353  //std::cout<<"writing runnumber,luminum "<<runnumber<<" "<<luminum<<std::endl;
354  auto pIn1 = std::make_unique<LumiSummary>();
355  auto pIn2 = std::make_unique<LumiDetails>();
356  if(m_isNullRun){
357  pIn1->setLumiVersion("DIP");
358  pIn2->setLumiVersion("DIP");
359  iLBlock.put(std::move(pIn1));
360  iLBlock.put(std::move(pIn2));
361  return;
362  }
363  PerLSData& lsdata=m_lscache[luminum];
364  pIn1->setLumiVersion("DIP");
365  pIn1->setLumiData(lsdata.lumivalue,0.0,0.0);
366  pIn1->setDeadCount(lsdata.deadcount);
367  pIn1->setBitZeroCount(lsdata.bitzerocount);
368  pIn1->setlsnumber(lsdata.lsnum);
369  pIn1->setOrbitData(lsdata.startorbit,lsdata.numorbit);
370 
371  pIn2->setLumiVersion("DIP");
372  pIn2->fill(LumiDetails::kOCC1,lsdata.bunchlumivalue,lsdata.bunchlumierror,lsdata.bunchlumiquality);
373  iLBlock.put(std::move(pIn1));
374  iLBlock.put(std::move(pIn2));
375 }
std::map< unsigned int, PerLSData > m_lscache
void put(std::unique_ptr< PROD > product)
Put a new product.
def move
Definition: eostools.py:510

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