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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 61 of file ExpressLumiProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 110 of file ExpressLumiProducer.cc.

110  {
111 }

Member Function Documentation

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

Definition at line 127 of file ExpressLumiProducer.cc.

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

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

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

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

168  {
172  unsigned int result=0;
173  coral::AttributeList bindVariables;
174  bindVariables.extend("runnumber",typeid(unsigned int));
175  bindVariables["runnumber"].data<unsigned int>()=runnumber;
176  std::string conditionStr("RUNNUMBER=:runnumber");
177  coral::AttributeList MyOutput;
178  MyOutput.extend("maxavailablels",typeid(unsigned int));
179  coral::IQuery* myQuery=schema.newQuery();
180  myQuery->addToTableList(tablename);
181  myQuery->addToOutputList("max(LUMISECTION)","maxavailablels");
182  myQuery->setCondition(conditionStr,bindVariables);
183  myQuery->defineOutput(MyOutput);
184  coral::ICursor& mycursor=myQuery->execute();
185  while( mycursor.next() ){
186  const coral::AttributeList& row=mycursor.currentRow();
187  if(!row["maxavailablels"].isNull()){
188  result=row["maxavailablels"].data<unsigned int>();
189  }
190  }
191  return result;
192 }
void ExpressLumiProducer::produce ( edm::Event e,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 117 of file ExpressLumiProducer.cc.

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

Definition at line 122 of file ExpressLumiProducer.cc.

References edm::LuminosityBlock::put().

122  {
123  iLBlock.put(std::make_unique<LumiSummary>());
124  iLBlock.put(std::make_unique<LumiDetails>());
125 }
void put(std::unique_ptr< PROD > product)
Put a new product.
void ExpressLumiProducer::writeProductsForEntry ( edm::LuminosityBlock iLBlock,
unsigned int  luminum 
)
private

Definition at line 348 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.

348  {
349  //std::cout<<"writing runnumber,luminum "<<runnumber<<" "<<luminum<<std::endl;
350  auto pIn1 = std::make_unique<LumiSummary>();
351  auto pIn2 = std::make_unique<LumiDetails>();
352  if(m_isNullRun){
353  pIn1->setLumiVersion("DIP");
354  pIn2->setLumiVersion("DIP");
355  iLBlock.put(std::move(pIn1));
356  iLBlock.put(std::move(pIn2));
357  return;
358  }
359  PerLSData& lsdata=m_lscache[luminum];
360  pIn1->setLumiVersion("DIP");
361  pIn1->setLumiData(lsdata.lumivalue,0.0,0.0);
362  pIn1->setDeadCount(lsdata.deadcount);
363  pIn1->setBitZeroCount(lsdata.bitzerocount);
364  pIn1->setlsnumber(lsdata.lsnum);
365  pIn1->setOrbitData(lsdata.startorbit,lsdata.numorbit);
366 
367  pIn2->setLumiVersion("DIP");
368  pIn2->fill(LumiDetails::kOCC1,lsdata.bunchlumivalue,lsdata.bunchlumierror,lsdata.bunchlumiquality);
369  iLBlock.put(std::move(pIn1));
370  iLBlock.put(std::move(pIn2));
371 }
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:511

Member Data Documentation

unsigned int ExpressLumiProducer::m_cachedrun
private

Definition at line 93 of file ExpressLumiProducer.cc.

unsigned int ExpressLumiProducer::m_cachesize
private

Definition at line 95 of file ExpressLumiProducer.cc.

std::string ExpressLumiProducer::m_connectStr
private

Definition at line 92 of file ExpressLumiProducer.cc.

bool ExpressLumiProducer::m_isNullRun
private

Definition at line 94 of file ExpressLumiProducer.cc.

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

Definition at line 96 of file ExpressLumiProducer.cc.