CMS 3D CMS Logo

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 () override
 
- Public Member Functions inherited from edm::one::EDProducer< edm::BeginLuminosityBlockProducer >
 EDProducer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDProducerBase () override
 
- 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 ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
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, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 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 & itemsToGetFrom (BranchType iType) 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
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void beginLuminosityBlockProduce (edm::LuminosityBlock &iLBlock, edm::EventSetup const &iSetup) 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)
 
void produce (edm::Event &, const edm::EventSetup &) 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, PerLSDatam_lscache
 

Additional Inherited Members

- Public Types inherited from edm::one::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
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 ( )
override

Definition at line 111 of file ExpressLumiProducer.cc.

111  {
112 }

Member Function Documentation

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

Definition at line 128 of file ExpressLumiProducer.cc.

References edm::LuminosityBlockBase::luminosityBlock(), edm::LuminosityBlockBase::run(), and findQualityFiles::v.

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, Exception, edm::Service< T >::isAvailable(), checklumidiff::l, ExpressLumiProducer::PerLSData::lsnum, ExpressLumiProducer::PerLSData::lumivalue, gen::n, ExpressLumiProducer::PerLSData::numorbit, cond::runnumber, dataDML::schema, dataDML::session, ExpressLumiProducer::PerLSData::startorbit, and AlCaHLTBitMon_QueryRunRegistry::string.

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  auto 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  return;
224  }
225  if(m_cachesize!=0){
226  lsmin=(lsmax-m_cachesize)>0 ? (lsmax-m_cachesize+1) : 1;
227  }
228  for(unsigned int n=lsmin;n<=lsmax;++n){
229  PerLSData l;
230  std::vector<float> mytmp(3564,0.0);
231  l.bunchlumivalue.swap(mytmp);
232  std::vector<float> myerrtmp(3564,0.0);
233  l.bunchlumierror.swap(myerrtmp);
234  std::vector<short> myqtmp(3564,0);
235  l.bunchlumiquality.swap(myqtmp);
236  m_lscache.insert(std::make_pair(n,l));
237  }
238 
239  coral::AttributeList lumisummaryBindVariables;
240  lumisummaryBindVariables.extend("lsmin",typeid(unsigned int));
241  lumisummaryBindVariables.extend("runnumber",typeid(unsigned int));
242  lumisummaryBindVariables["runnumber"].data<unsigned int>()=m_cachedrun;
243  lumisummaryBindVariables["lsmin"].data<unsigned int>()=lsmin;
244  std::string conditionStr(" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin ");
245  coral::AttributeList lumisummaryOutput;
246  lumisummaryOutput.extend("LUMISECTION",typeid(unsigned int));
247  lumisummaryOutput.extend("INSTLUMI",typeid(float));
248  lumisummaryOutput.extend("DELIVLUMISECTION",typeid(float));
249  lumisummaryOutput.extend("LIVELUMISECTION",typeid(float));
250  lumisummaryOutput.extend("STARTORBIT",typeid(unsigned long long));
251  if(m_cachesize!=0){
252  lumisummaryBindVariables.extend("lsmax",typeid(unsigned int));
253  conditionStr=conditionStr+"AND LUMISECTION<=:lsmax";
254  lumisummaryBindVariables["lsmax"].data<unsigned int>()=lsmax;
255  }
256  coral::IQuery* lumisummaryQuery=schema.newQuery();
257  lumisummaryQuery->addToTableList(std::string("LUMI_SECTIONS"));
258  lumisummaryQuery->addToOutputList("LUMISECTION");
259  lumisummaryQuery->addToOutputList("INSTLUMI");
260  lumisummaryQuery->addToOutputList("DELIVLUMISECTION");
261  lumisummaryQuery->addToOutputList("LIVELUMISECTION");
262  lumisummaryQuery->addToOutputList("STARTORBIT");
263  lumisummaryQuery->setCondition(conditionStr,lumisummaryBindVariables);
264  lumisummaryQuery->defineOutput(lumisummaryOutput);
265  coral::ICursor& lumisummarycursor=lumisummaryQuery->execute();
266  unsigned int rowcounter=0;
267  while( lumisummarycursor.next() ){
268  const coral::AttributeList& row=lumisummarycursor.currentRow();
269  unsigned int lsnum=row["LUMISECTION"].data<unsigned int>();
270  float instlumi=0.0;
271  if(!row["INSTLUMI"].isNull()){
272  instlumi=row["INSTLUMI"].data<float>();//Hz/ub
273  }
274  float deadfrac=1.0;
275  float intgdellumi=0.0;
276  float intgreclumi=0.0;
277  unsigned long long startorbit=0;
278  if(!row["DELIVLUMISECTION"].isNull()){
279  intgdellumi=row["DELIVLUMISECTION"].data<float>()*1000.0;//convert to /ub
280  }
281  if(!row["LIVELUMISECTION"].isNull()){
282  intgreclumi=row["LIVELUMISECTION"].data<float>()*1000.0;//convert to /ub
283  }
284  if(intgdellumi>0){
285  deadfrac=1.0-intgreclumi/intgdellumi;
286  }
287  if(!row["STARTORBIT"].isNull()){
288  startorbit=row["STARTORBIT"].data<unsigned long long>();//convert to /ub
289  }
290  unsigned long long deadcount=deadfrac*10000.0;
291  unsigned long long bitzerocount=10000.0;
292  PerLSData& lsdata=m_lscache[lsnum];
293  lsdata.lsnum=lsnum;
294  lsdata.lumivalue=instlumi;
295  lsdata.deadcount=deadcount;
296  lsdata.bitzerocount=bitzerocount;
297  lsdata.startorbit=startorbit;
298  lsdata.numorbit=262144;
299  ++rowcounter;
300  }
301  if (rowcounter==0){
302  m_isNullRun=true;
303  }
304  delete lumisummaryQuery;
305  if(m_isNullRun) return;
306  //
307  //queries once per cache refill
308  //
309  //select lumisection,bunch,bunchlumi from cms_runtime_logger.bunch_lumi_sections where lumisection>=:lsmin and lumisection<:lsmax and runnumber=:runnumber;
310  //
311  coral::AttributeList lumidetailBindVariables;
312  lumidetailBindVariables.extend("lsmin",typeid(unsigned int));
313  lumidetailBindVariables.extend("runnumber",typeid(unsigned int));
314  lumidetailBindVariables["runnumber"].data<unsigned int>()=m_cachedrun;
315  lumidetailBindVariables["lsmin"].data<unsigned int>()=lsmin;
316  std::string detailconditionStr(" RUNNUMBER=:runnumber AND LUMISECTION>=:lsmin AND BUNCHLUMI>0 ");
317  coral::AttributeList lumidetailOutput;
318  lumidetailOutput.extend("LUMISECTION",typeid(unsigned int));
319  lumidetailOutput.extend("BUNCH",typeid(unsigned int));
320  lumidetailOutput.extend("BUNCHLUMI",typeid(float));
321  if(m_cachesize!=0){
322  lumidetailBindVariables.extend("lsmax",typeid(unsigned int));
323  detailconditionStr=detailconditionStr+"AND LUMISECTION<=:lsmax";
324  lumidetailBindVariables["lsmax"].data<unsigned int>()=lsmax;
325  }
326  coral::IQuery* lumidetailQuery=schema.newQuery();
327  lumidetailQuery->addToTableList(std::string("BUNCH_LUMI_SECTIONS"));
328  lumidetailQuery->addToOutputList("LUMISECTION");
329  lumidetailQuery->addToOutputList("BUNCH");
330  lumidetailQuery->addToOutputList("BUNCHLUMI");
331  lumidetailQuery->setCondition(detailconditionStr,lumidetailBindVariables);
332  lumidetailQuery->defineOutput(lumidetailOutput);
333  coral::ICursor& lumidetailcursor=lumidetailQuery->execute();
334  while( lumidetailcursor.next() ){
335  const coral::AttributeList& row=lumidetailcursor.currentRow();
336  unsigned int lsnum=row["LUMISECTION"].data<unsigned int>();
337  unsigned int bxidx=row["BUNCH"].data<unsigned int>();
338  float bxlumi=row["BUNCHLUMI"].data<float>();//Hz/ub
339  m_lscache[lsnum].bunchlumivalue[bxidx]=bxlumi;
340  }
341  delete lumidetailQuery;
342  session->transaction().commit();
343  }catch(const coral::Exception& er){
344  session->transaction().rollback();
345  throw cms::Exception("DatabaseError ")<<er.what();
346  }
347 }
ISessionProxyPtr connectReadOnly(const std::string &connectstring)
Definition: DBService.cc:22
std::map< unsigned int, PerLSData > m_lscache
bool isAvailable() const
Definition: Service.h:46
unsigned int maxavailableLSforRun(coral::ISchema &schema, const std::string &tablename, unsigned int runnumber)
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 mps_fire::result, and AlCaHLTBitMon_QueryRunRegistry::string.

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 }
void ExpressLumiProducer::produce ( edm::Event e,
const edm::EventSetup iSetup 
)
finalprivate

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

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

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

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

Member Data Documentation

unsigned int ExpressLumiProducer::m_cachedrun
private

Definition at line 94 of file ExpressLumiProducer.cc.

unsigned int ExpressLumiProducer::m_cachesize
private

Definition at line 96 of file ExpressLumiProducer.cc.

std::string ExpressLumiProducer::m_connectStr
private

Definition at line 93 of file ExpressLumiProducer.cc.

bool ExpressLumiProducer::m_isNullRun
private

Definition at line 95 of file ExpressLumiProducer.cc.

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

Definition at line 97 of file ExpressLumiProducer.cc.