CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
LHCInfoPerFillPopConSourceHandler Class Reference
Inheritance diagram for LHCInfoPerFillPopConSourceHandler:
popcon::PopConSourceHandler< LHCInfoPerFill >

Public Member Functions

void getNewObjects () override
 
std::string id () const override
 
 LHCInfoPerFillPopConSourceHandler (edm::ParameterSet const &pset)
 
 ~LHCInfoPerFillPopConSourceHandler () override=default
 
- Public Member Functions inherited from popcon::PopConSourceHandler< LHCInfoPerFill >
void initialize (const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry)
 
Ref lastPayload () const
 
cond::LogDBEntry_t const & logDBEntry () const
 
std::pair< Container const *, std::string const > operator() (const cond::persistency::Session &session, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry) const
 
 PopConSourceHandler ()
 
Container const & returnData ()
 
cond::TagInfo_t const & tagInfo () const
 
std::string const & userTextLog () const
 
virtual ~PopConSourceHandler ()
 

Static Public Attributes

static constexpr unsigned int kLumisectionsQueryLimit = 4000
 

Private Member Functions

void addEmptyPayload (cond::Time_t iov)
 
void addPayloadToBuffer (cond::OMSServiceResultRef &row)
 
void convertBufferedIovsToLumiid (std::map< cond::Time_t, cond::Time_t > timestampToLumiid)
 
bool getCTPPSData (cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 
void getDipData (const cond::OMSService &oms, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 
bool getEcalData (cond::persistency::Session &session, const boost::posix_time::ptime &lowerTime, const boost::posix_time::ptime &upperTime)
 
size_t getLumiData (const cond::OMSService &oms, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
 

Private Attributes

std::string m_authpath
 
std::string m_connectionString
 
bool m_debug
 
std::string m_ecalConnectionString
 
bool m_endFillMode = true
 
boost::posix_time::ptime m_endTime
 
std::unique_ptr< LHCInfoPerFillm_fillPayload
 
bool m_lastPayloadEmpty = false
 
std::string m_name
 
std::string m_omsBaseUrl
 
std::shared_ptr< LHCInfoPerFillm_prevPayload
 
boost::posix_time::ptime m_startTime
 
std::map< cond::Time_t, cond::Time_tm_timestampToLumiid
 
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer
 

Additional Inherited Members

- Public Types inherited from popcon::PopConSourceHandler< LHCInfoPerFill >
typedef std::map< Time_t, std::shared_ptr< LHCInfoPerFill > > Container
 
typedef std::unique_ptr< LHCInfoPerFillRef
 
typedef PopConSourceHandler< LHCInfoPerFillself
 
typedef cond::Time_t Time_t
 
typedef LHCInfoPerFill value_type
 
- Protected Member Functions inherited from popcon::PopConSourceHandler< LHCInfoPerFill >
cond::persistency::SessiondbSession () const
 
- Protected Attributes inherited from popcon::PopConSourceHandler< LHCInfoPerFill >
Container m_iovs
 
std::vector< std::pair< LHCInfoPerFill *, Time_t > > m_to_transfer
 
std::string m_userTextLog
 

Detailed Description

Definition at line 202 of file LHCInfoPerFillPopConAnalyzer.cc.

Constructor & Destructor Documentation

◆ LHCInfoPerFillPopConSourceHandler()

LHCInfoPerFillPopConSourceHandler::LHCInfoPerFillPopConSourceHandler ( edm::ParameterSet const &  pset)
inline

Definition at line 204 of file LHCInfoPerFillPopConAnalyzer.cc.

References m_endTime, m_startTime, submitPVValidationJobs::now, muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

205  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
206  m_startTime(),
207  m_endTime(),
208  m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
209  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerFillPopConSourceHandler")),
210  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
211  m_ecalConnectionString(pset.getUntrackedParameter<std::string>("ecalConnectionString", "")),
212  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
213  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
214  m_fillPayload(),
215  m_prevPayload(),
216  m_tmpBuffer() {
217  if (!pset.getUntrackedParameter<std::string>("startTime").empty()) {
218  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
219  }
220  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
221  m_endTime = now;
222  if (!pset.getUntrackedParameter<std::string>("endTime").empty()) {
223  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
224  if (m_endTime > now)
225  m_endTime = now;
226  }
227  }
std::shared_ptr< LHCInfoPerFill > m_prevPayload
std::unique_ptr< LHCInfoPerFill > m_fillPayload
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ ~LHCInfoPerFillPopConSourceHandler()

LHCInfoPerFillPopConSourceHandler::~LHCInfoPerFillPopConSourceHandler ( )
overridedefault

Member Function Documentation

◆ addEmptyPayload()

void LHCInfoPerFillPopConSourceHandler::addEmptyPayload ( cond::Time_t  iov)
inlineprivate

Definition at line 380 of file LHCInfoPerFillPopConAnalyzer.cc.

References PVValHelper::add(), popcon::PopConSourceHandler< LHCInfoPerFill >::m_iovs, m_lastPayloadEmpty, m_name, m_prevPayload, and cond::time::to_boost().

Referenced by getNewObjects().

380  {
381  bool add = false;
382  if (m_iovs.empty()) {
383  if (!m_lastPayloadEmpty)
384  add = true;
385  } else {
386  auto lastAdded = m_iovs.rbegin()->second;
387  if (lastAdded->fillNumber() != 0) {
388  add = true;
389  }
390  }
391  if (add) {
392  auto newPayload = std::make_shared<LHCInfoPerFill>();
393  m_iovs.insert(std::make_pair(iov, newPayload));
394  m_prevPayload = newPayload;
395  edm::LogInfo(m_name) << "Added empty payload with IOV " << iov << " ( "
396  << boost::posix_time::to_iso_extended_string(cond::time::to_boost(iov)) << " )";
397  }
398  }
std::shared_ptr< LHCInfoPerFill > m_prevPayload
Log< level::Info, false > LogInfo
void add(std::map< std::string, TH1 *> &h, TH1 *hist)
boost::posix_time::ptime to_boost(Time_t iValue)

◆ addPayloadToBuffer()

void LHCInfoPerFillPopConSourceHandler::addPayloadToBuffer ( cond::OMSServiceResultRef row)
inlineprivate

Definition at line 401 of file LHCInfoPerFillPopConAnalyzer.cc.

References EcalPhiSymFlatTableProducers_cfi::delivLumi, cond::time::from_boost(), cond::OMSServiceResultRef::get(), cond::lumiid, cond::time::lumiTime(), m_endFillMode, m_fillPayload, m_timestampToLumiid, m_tmpBuffer, jetsAK4_Puppi_cff::payload, EcalPhiSymFlatTableProducers_cfi::recLumi, convertSQLiteXML::runNumber, dcs_print_summary_cfg::startTime, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getLumiData().

401  {
402  auto startTime = row.get<boost::posix_time::ptime>("start_time");
403  auto delivLumi = row.get<float>("delivered_lumi");
404  auto recLumi = row.get<float>("recorded_lumi");
405  auto runNumber = std::stoul(row.get<std::string>("run_number"));
406  auto lsNumber = std::stoul(row.get<std::string>("lumisection_number"));
407  auto lumiid = cond::time::lumiTime(runNumber, lsNumber);
408 
409  LHCInfoPerFill* thisLumiSectionInfo = m_fillPayload->cloneFill();
410  m_tmpBuffer.emplace_back(std::make_pair(cond::time::from_boost(startTime), thisLumiSectionInfo));
411  if (!m_endFillMode) {
413  }
414  LHCInfoPerFill& payload = *thisLumiSectionInfo;
415  payload.setDelivLumi(delivLumi);
416  payload.setRecLumi(recLumi);
417  }
T get(const std::string &attributeName)
Definition: OMSAccess.h:114
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
std::unique_ptr< LHCInfoPerFill > m_fillPayload
Time_t from_boost(boost::posix_time::ptime bt)
std::map< cond::Time_t, cond::Time_t > m_timestampToLumiid
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ convertBufferedIovsToLumiid()

void LHCInfoPerFillPopConSourceHandler::convertBufferedIovsToLumiid ( std::map< cond::Time_t, cond::Time_t timestampToLumiid)
inlineprivate

Definition at line 419 of file LHCInfoPerFillPopConAnalyzer.cc.

References Exception, B2GTnPMonitor_cfi::item, and m_tmpBuffer.

Referenced by getNewObjects().

419  {
420  for (auto& item : m_tmpBuffer) {
421  // Check if the lumiid IOV corresponding to the timestamp is present in the map
422  if (timestampToLumiid.find(item.first) == timestampToLumiid.end()) {
423  throw cms::Exception("LHCInfoPerFillPopConSourceHandler")
424  << "Can't find corresponding lumiid IOV for timestamp " << item.first << "\n";
425  }
426  // Update the buffer with the lumiid-type IOV
427  item.first = timestampToLumiid.at(item.first);
428  }
429  }
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ getCTPPSData()

bool LHCInfoPerFillPopConSourceHandler::getCTPPSData ( cond::persistency::Session session,
const boost::posix_time::ptime &  beginFillTime,
const boost::posix_time::ptime &  endFillTime 
)
inlineprivate

Definition at line 522 of file LHCInfoPerFillPopConAnalyzer.cc.

References ALCARECOTkAlBeamHalo_cff::filter, cond::time::from_boost(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, m_debug, m_name, m_tmpBuffer, jetsAK4_Puppi_cff::payload, runTheMatrix::ret, convertSQLiteXML::runNumber, run_AlCaRecoTriggerBitsUpdateWorkflow::session, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getNewObjects().

524  {
525  //run the fifth query against the CTPPS schema
526  //Initializing the CMS_CTP_CTPPS_COND schema.
527  coral::ISchema& CTPPS = session.coralSession().schema("CMS_PPS_SPECT_COND");
528  //execute query for CTPPS Data
529  std::unique_ptr<coral::IQuery> CTPPSDataQuery(CTPPS.newQuery());
530  //FROM clause
531  CTPPSDataQuery->addToTableList(std::string("PPS_LHC_MACHINE_PARAMS"));
532  //SELECT clause
533  CTPPSDataQuery->addToOutputList(std::string("DIP_UPDATE_TIME"));
534  CTPPSDataQuery->addToOutputList(std::string("LHC_STATE"));
535  CTPPSDataQuery->addToOutputList(std::string("LHC_COMMENT"));
536  if (m_debug) {
537  CTPPSDataQuery->addToOutputList(std::string("RUN_NUMBER"));
538  CTPPSDataQuery->addToOutputList(std::string("LUMI_SECTION"));
539  }
540  //WHERE CLAUSE
541  coral::AttributeList CTPPSDataBindVariables;
542  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
543  CTPPSDataBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
544  CTPPSDataBindVariables[std::string("beginFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
545  CTPPSDataBindVariables[std::string("endFillTime")].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
546  std::string conditionStr = std::string("DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime");
547  CTPPSDataQuery->setCondition(conditionStr, CTPPSDataBindVariables);
548  //ORDER BY clause
549  CTPPSDataQuery->addToOrderList(std::string("DIP_UPDATE_TIME"));
550  //define query output
551  coral::AttributeList CTPPSDataOutput;
552  CTPPSDataOutput.extend<coral::TimeStamp>(std::string("DIP_UPDATE_TIME"));
553  CTPPSDataOutput.extend<std::string>(std::string("LHC_STATE"));
554  CTPPSDataOutput.extend<std::string>(std::string("LHC_COMMENT"));
555  if (m_debug) {
556  CTPPSDataOutput.extend<int>(std::string("RUN_NUMBER"));
557  CTPPSDataOutput.extend<int>(std::string("LUMI_SECTION"));
558  }
559  CTPPSDataQuery->defineOutput(CTPPSDataOutput);
560  //execute the query
561  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
562  cond::Time_t dipTime = 0;
563  std::string lhcState = "", lhcComment = "", ctppsStatus = "";
564 
565  //debug informations
566  unsigned int lumiSection = 0;
568  cond::Time_t savedDipTime = 0;
569  unsigned int savedLumiSection = 0;
570  cond::Time_t savedRunNumber = 0;
571 
572  bool ret = false;
574  while (CTPPSDataCursor.next()) {
575  if (m_debug) {
576  std::ostringstream CTPPS;
577  CTPPSDataCursor.currentRow().toOutputStream(CTPPS);
578  }
579  coral::Attribute const& dipTimeAttribute = CTPPSDataCursor.currentRow()[std::string("DIP_UPDATE_TIME")];
580  if (!dipTimeAttribute.isNull()) {
581  dipTime = cond::time::from_boost(dipTimeAttribute.data<coral::TimeStamp>().time());
582  if (filter.process(dipTime)) {
583  ret = true;
584  coral::Attribute const& lhcStateAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_STATE")];
585  if (!lhcStateAttribute.isNull()) {
586  lhcState = lhcStateAttribute.data<std::string>();
587  }
588  coral::Attribute const& lhcCommentAttribute = CTPPSDataCursor.currentRow()[std::string("LHC_COMMENT")];
589  if (!lhcCommentAttribute.isNull()) {
590  lhcComment = lhcCommentAttribute.data<std::string>();
591  }
592 
593  if (m_debug) {
594  coral::Attribute const& runNumberAttribute = CTPPSDataCursor.currentRow()[std::string("RUN_NUMBER")];
595  if (!runNumberAttribute.isNull()) {
596  runNumber = runNumberAttribute.data<int>();
597  }
598  coral::Attribute const& lumiSectionAttribute = CTPPSDataCursor.currentRow()[std::string("LUMI_SECTION")];
599  if (!lumiSectionAttribute.isNull()) {
600  lumiSection = lumiSectionAttribute.data<int>();
601  }
602  }
603 
604  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
605  // set the current values to all of the payloads of the lumi section samples after the current since
606  LHCInfoPerFill& payload = *(it->second);
607  payload.setLhcState(lhcState);
608  payload.setLhcComment(lhcComment);
609  payload.setCtppsStatus(ctppsStatus);
610 
611  if (m_debug) {
612  savedDipTime = dipTime;
613  savedLumiSection = lumiSection;
614  savedRunNumber = runNumber;
615  }
616  }
617  }
618  }
619  }
620  if (m_debug) {
621  edm::LogInfo(m_name) << "Last assigned: "
622  << "DipTime: " << savedDipTime << " "
623  << "LumiSection: " << savedLumiSection << " "
624  << "RunNumber: " << savedRunNumber;
625  }
626  return ret;
627  }
ret
prodAgent to be discontinued
unsigned long long Time_t
Definition: Time.h:14
Time_t from_boost(boost::posix_time::ptime bt)
Log< level::Info, false > LogInfo
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ getDipData()

void LHCInfoPerFillPopConSourceHandler::getDipData ( const cond::OMSService oms,
const boost::posix_time::ptime &  beginFillTime,
const boost::posix_time::ptime &  endFillTime 
)
inlineprivate

Definition at line 460 of file LHCInfoPerFillPopConAnalyzer.cc.

References m_fillPayload, cond::OMSService::query(), and FCDTask_cfi::slot.

Referenced by getNewObjects().

462  {
463  // unsure how to handle this.
464  // the old implementation is not helping: apparently it is checking only the bunchconfiguration for the first diptime set of values...
465  auto query1 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam1");
466  query1->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
467  //This query is limited to 100 rows, but currently only one is used
468  //If all this data is needed and saved properly the limit has to be set: query1->limit(...)
469  if (query1->execute()) {
470  auto res = query1->result();
471  if (!res.empty()) {
472  std::bitset<LHCInfoPerFill::bunchSlots + 1> bunchConfiguration1(0ULL);
473  auto row = *res.begin();
474  auto vbunchConf1 = row.getArray<unsigned short>("value");
475  for (auto vb : vbunchConf1) {
476  if (vb != 0) {
477  unsigned short slot = (vb - 1) / 10 + 1;
478  bunchConfiguration1[slot] = true;
479  }
480  }
481  m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1);
482  }
483  }
484  auto query2 = oms.query("diplogger/dip/acc/LHC/RunControl/CirculatingBunchConfig/Beam2");
485  query2->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
486  //This query is limited to 100 rows, but currently only one is used
487  if (query2->execute()) {
488  auto res = query2->result();
489  if (!res.empty()) {
490  std::bitset<LHCInfoPerFill::bunchSlots + 1> bunchConfiguration2(0ULL);
491  auto row = *res.begin();
492  auto vbunchConf2 = row.getArray<unsigned short>("value");
493  for (auto vb : vbunchConf2) {
494  if (vb != 0) {
495  unsigned short slot = (vb - 1) / 10 + 1;
496  bunchConfiguration2[slot] = true;
497  }
498  }
499  m_fillPayload->setBunchBitsetForBeam2(bunchConfiguration2);
500  }
501  }
502 
503  auto query3 = oms.query("diplogger/dip/CMS/LHC/LumiPerBunch");
504  query3->filterGT("dip_time", beginFillTime).filterLT("dip_time", endFillTime);
505  //This query is limited to 100 rows, but currently only one is used
506  if (query3->execute()) {
507  auto res = query3->result();
508  if (!res.empty()) {
509  std::vector<float> lumiPerBX;
510  auto row = *res.begin();
511  auto lumiBunchInst = row.getArray<float>("lumi_bunch_inst");
512  for (auto lb : lumiBunchInst) {
513  if (lb != 0.) {
514  lumiPerBX.push_back(lb);
515  }
516  }
517  m_fillPayload->setLumiPerBX(lumiPerBX);
518  }
519  }
520  }
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
Definition: Electron.h:6
std::unique_ptr< LHCInfoPerFill > m_fillPayload

◆ getEcalData()

bool LHCInfoPerFillPopConSourceHandler::getEcalData ( cond::persistency::Session session,
const boost::posix_time::ptime &  lowerTime,
const boost::posix_time::ptime &  upperTime 
)
inlineprivate

Definition at line 629 of file LHCInfoPerFillPopConAnalyzer.cc.

References ECAL, ALCARECOTkAlBeamHalo_cff::filter, cond::time::from_boost(), CommonMethods::isnan(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, m_debug, m_name, m_prevPayload, m_tmpBuffer, jetsAK4_Puppi_cff::payload, runTheMatrix::ret, run_AlCaRecoTriggerBitsUpdateWorkflow::session, theLHCInfoPerFillImpl::setElementData(), AlCaHLTBitMon_QueryRunRegistry::string, hcalRecHitTable_cff::time, and cond::time::to_boost().

Referenced by getNewObjects().

631  {
632  //run the sixth query against the CMS_DCS_ENV_PVSS_COND schema
633  //Initializing the CMS_DCS_ENV_PVSS_COND schema.
634  coral::ISchema& ECAL = session.nominalSchema();
635  //start the transaction against the fill logging schema
636  //execute query for ECAL Data
637  std::unique_ptr<coral::IQuery> ECALDataQuery(ECAL.newQuery());
638  //FROM clause
639  ECALDataQuery->addToTableList(std::string("BEAM_PHASE"));
640  //SELECT clause
641  ECALDataQuery->addToOutputList(std::string("CHANGE_DATE"));
642  ECALDataQuery->addToOutputList(std::string("DIP_value"));
643  ECALDataQuery->addToOutputList(std::string("element_nr"));
644  ECALDataQuery->addToOutputList(std::string("VALUE_NUMBER"));
645  //WHERE CLAUSE
646  coral::AttributeList ECALDataBindVariables;
647  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("lowerTime"));
648  ECALDataBindVariables.extend<coral::TimeStamp>(std::string("upperTime"));
649  ECALDataBindVariables[std::string("lowerTime")].data<coral::TimeStamp>() = coral::TimeStamp(lowerTime);
650  ECALDataBindVariables[std::string("upperTime")].data<coral::TimeStamp>() = coral::TimeStamp(upperTime);
651  std::string conditionStr = std::string(
652  "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND "
653  "CHANGE_DATE < :upperTime");
654 
655  ECALDataQuery->setCondition(conditionStr, ECALDataBindVariables);
656  //ORDER BY clause
657  ECALDataQuery->addToOrderList(std::string("CHANGE_DATE"));
658  ECALDataQuery->addToOrderList(std::string("DIP_value"));
659  ECALDataQuery->addToOrderList(std::string("element_nr"));
660  //define query output
661  coral::AttributeList ECALDataOutput;
662  ECALDataOutput.extend<coral::TimeStamp>(std::string("CHANGE_DATE"));
663  ECALDataOutput.extend<std::string>(std::string("DIP_value"));
664  ECALDataOutput.extend<unsigned int>(std::string("element_nr"));
665  ECALDataOutput.extend<float>(std::string("VALUE_NUMBER"));
666  //ECALDataQuery->limitReturnedRows( 14256 ); //3564 entries per vector.
667  ECALDataQuery->defineOutput(ECALDataOutput);
668  //execute the query
669  coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
670  cond::Time_t changeTime = 0;
671  cond::Time_t firstTime = 0;
672  std::string dipVal = "";
673  unsigned int elementNr = 0;
674  float value = 0.;
675  std::set<cond::Time_t> initializedVectors;
677  bool ret = false;
678  if (m_prevPayload.get()) {
679  for (auto& lumiSlot : m_tmpBuffer) {
680  lumiSlot.second->setBeam1VC(m_prevPayload->beam1VC());
681  lumiSlot.second->setBeam2VC(m_prevPayload->beam2VC());
682  lumiSlot.second->setBeam1RF(m_prevPayload->beam1RF());
683  lumiSlot.second->setBeam2RF(m_prevPayload->beam2RF());
684  }
685  }
686  std::map<cond::Time_t, cond::Time_t> iovMap;
687  if (m_tmpBuffer.empty()) {
688  return ret;
689  }
690  cond::Time_t lowerLumi = m_tmpBuffer.front().first;
691  while (ECALDataCursor.next()) {
692  if (m_debug) {
693  std::ostringstream ECAL;
694  ECALDataCursor.currentRow().toOutputStream(ECAL);
695  }
696  coral::Attribute const& changeDateAttribute = ECALDataCursor.currentRow()[std::string("CHANGE_DATE")];
697  if (!changeDateAttribute.isNull()) {
698  ret = true;
699  boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().time();
700  // move the first IOV found to the start of the fill interval selected
701  if (changeTime == 0) {
702  firstTime = cond::time::from_boost(chTime);
703  }
704  changeTime = cond::time::from_boost(chTime);
705  cond::Time_t iovTime = changeTime;
706  if (changeTime == firstTime)
707  iovTime = lowerLumi;
708  coral::Attribute const& dipValAttribute = ECALDataCursor.currentRow()[std::string("DIP_value")];
709  coral::Attribute const& valueNumberAttribute = ECALDataCursor.currentRow()[std::string("VALUE_NUMBER")];
710  coral::Attribute const& elementNrAttribute = ECALDataCursor.currentRow()[std::string("element_nr")];
711  if (!dipValAttribute.isNull() and !valueNumberAttribute.isNull()) {
712  dipVal = dipValAttribute.data<std::string>();
713  elementNr = elementNrAttribute.data<unsigned int>();
714  value = valueNumberAttribute.data<float>();
715  if (std::isnan(value))
716  value = 0.;
717  if (filter.process(iovTime)) {
718  iovMap.insert(std::make_pair(changeTime, filter.current()->first));
719  for (auto it = filter.current(); it != m_tmpBuffer.end(); it++) {
720  LHCInfoPerFill& payload = *(it->second);
721  theLHCInfoPerFillImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors);
722  }
723  }
724  }
725  }
726  }
727  if (m_debug) {
728  for (auto& im : iovMap) {
729  edm::LogInfo(m_name) << "Found iov=" << im.first << " (" << cond::time::to_boost(im.first) << " ) moved to "
730  << im.second << " ( " << cond::time::to_boost(im.second) << " )";
731  }
732  }
733  return ret;
734  }
def isnan(num)
ret
prodAgent to be discontinued
std::shared_ptr< LHCInfoPerFill > m_prevPayload
void setElementData(cond::Time_t since, const std::string &dipVal, unsigned int elementNr, float value, LHCInfoPerFill &payload, std::set< cond::Time_t > &initList)
unsigned long long Time_t
Definition: Time.h:14
Definition: value.py:1
Time_t from_boost(boost::posix_time::ptime bt)
Log< level::Info, false > LogInfo
boost::posix_time::ptime to_boost(Time_t iValue)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ getLumiData()

size_t LHCInfoPerFillPopConSourceHandler::getLumiData ( const cond::OMSService oms,
unsigned short  fillId,
const boost::posix_time::ptime &  beginFillTime,
const boost::posix_time::ptime &  endFillTime 
)
inlineprivate

Definition at line 431 of file LHCInfoPerFillPopConAnalyzer.cc.

References addPayloadToBuffer(), kLumisectionsQueryLimit, m_endFillMode, m_name, and cond::OMSService::query().

Referenced by getNewObjects().

434  {
435  auto query = oms.query("lumisections");
436  query->addOutputVars(
437  {"start_time", "delivered_lumi", "recorded_lumi", "beams_stable", "run_number", "lumisection_number"});
438  query->filterEQ("fill_number", fillId);
439  query->filterGT("start_time", beginFillTime).filterLT("start_time", endFillTime);
440  query->filterEQ("beams_stable", "true");
442  if (query->execute()) {
443  auto queryResult = query->result();
444  edm::LogInfo(m_name) << "Found " << queryResult.size() << " lumisections with STABLE BEAM during the fill "
445  << fillId;
446 
447  if (!queryResult.empty()) {
448  if (m_endFillMode) {
449  auto firstRow = queryResult.front();
450  addPayloadToBuffer(firstRow);
451  }
452 
453  auto lastRow = queryResult.back();
454  addPayloadToBuffer(lastRow);
455  }
456  }
457  return 0;
458  }
static constexpr unsigned int kLumisectionsQueryLimit
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
Definition: query.py:1
void addPayloadToBuffer(cond::OMSServiceResultRef &row)
Log< level::Info, false > LogInfo

◆ getNewObjects()

void LHCInfoPerFillPopConSourceHandler::getNewObjects ( )
inlineoverridevirtual

Implements popcon::PopConSourceHandler< LHCInfoPerFill >.

Definition at line 231 of file LHCInfoPerFillPopConAnalyzer.cc.

References addEmptyPayload(), cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::configure(), cond::OMSService::connect(), convertBufferedIovsToLumiid(), cond::persistency::ConnectionPool::createSession(), popcon::PopConSourceHandler< LHCInfoPerFill >::dbSession(), Debug, cond::persistency::Session::fetchPayload(), cond::time::from_boost(), getCTPPSData(), getDipData(), getEcalData(), cond::lhcInfoHelper::getFillLastLumiIOV(), getLumiData(), cond::TagInfo_t::lastInterval, cond::time::lumiTime(), m_authpath, m_connectionString, m_debug, m_ecalConnectionString, m_endFillMode, m_endTime, m_fillPayload, popcon::PopConSourceHandler< LHCInfoPerFill >::m_iovs, m_name, m_omsBaseUrl, m_prevPayload, m_startTime, m_timestampToLumiid, m_tmpBuffer, theLHCInfoPerFillImpl::makeFillPayload(), WZElectronSkims53X_cff::max, cond::TagInfo_t::name, cond::Iov_t::payloadId, cond::OMSService::query(), run_AlCaRecoTriggerBitsUpdateWorkflow::session, cond::persistency::ConnectionPool::setAuthenticationPath(), cond::persistency::ConnectionPool::setMessageVerbosity(), cond::Iov_t::since, cond::TagInfo_t::size, findQualityFiles::size, cond::persistency::Transaction::start(), popcon::PopConSourceHandler< LHCInfoPerFill >::tagInfo(), cond::time::to_boost(), cond::persistency::Session::transaction(), and theLHCInfoPerFillImpl::transferPayloads().

231  {
232  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
233  if (tagInfo().size == 0) {
234  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
235  } else {
236  //check what is already inside the database
237  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
238  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
239  << boost::posix_time::to_iso_extended_string(
240  cond::time::to_boost(tagInfo().lastInterval.since))
241  << " ); from " << m_name << "::getNewObjects";
242  }
243 
244  cond::Time_t lastSince = tagInfo().lastInterval.since;
245  if (tagInfo().isEmpty()) {
246  // for a new or empty tag, an empty payload should be added on top with since=1
247  if (m_endFillMode) {
248  addEmptyPayload(1);
249  lastSince = 1;
250  } else {
252  lastSince = cond::time::lumiTime(1, 1);
253  }
254  } else {
255  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
256  << m_name << "::getNewObjects";
257  }
258 
259  //retrieve the data from the relational database source
261  //configure the connection
262  if (m_debug) {
263  connection.setMessageVerbosity(coral::Debug);
264  } else {
265  connection.setMessageVerbosity(coral::Error);
266  }
267  connection.setAuthenticationPath(m_authpath);
268  connection.configure();
269  //create the sessions
272  // fetch last payload when available
273  if (!tagInfo().lastInterval.payloadId.empty()) {
275  session3.transaction().start(true);
277  session3.transaction().commit();
278  }
279 
280  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
281  cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
282 
283  cond::Time_t startTimestamp = m_startTime.is_not_a_date_time() ? 0 : cond::time::from_boost(m_startTime);
284  cond::Time_t nextFillSearchTimestamp =
285  std::max(startTimestamp, m_endFillMode ? lastSince : m_prevPayload->createTime());
286 
287  edm::LogInfo(m_name) << "Starting sampling at "
288  << boost::posix_time::to_simple_string(cond::time::to_boost(nextFillSearchTimestamp));
289 
290  while (true) {
291  if (nextFillSearchTimestamp >= executionTimeIov) {
292  edm::LogInfo(m_name) << "Sampling ended at the time "
293  << boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
294  break;
295  }
296  boost::posix_time::ptime nextFillSearchTime = cond::time::to_boost(nextFillSearchTimestamp);
297  boost::posix_time::ptime startSampleTime;
298  boost::posix_time::ptime endSampleTime;
299 
300  cond::OMSService oms;
301  oms.connect(m_omsBaseUrl);
302  auto query = oms.query("fills");
303 
304  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(nextFillSearchTime);
305  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
306  if (nextFillSearchTime > cond::time::to_boost(m_prevPayload->createTime())) {
307  query->filterGE("start_time", nextFillSearchTime);
308  } else {
309  query->filterGT("start_time", nextFillSearchTime);
310  }
311 
312  query->filterLT("start_time", m_endTime);
313  if (m_endFillMode)
314  query->filterNotNull("end_time");
315  bool foundFill = query->execute();
316  if (foundFill)
318  if (!foundFill) {
319  edm::LogInfo(m_name) << "No fill found - END of job.";
320  break;
321  }
322 
323  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
324  cond::Time_t startFillTime = m_fillPayload->createTime();
325  cond::Time_t endFillTime = m_fillPayload->endTime();
326  unsigned short lhcFill = m_fillPayload->fillNumber();
327  bool ongoingFill = endFillTime == 0ULL;
328  if (ongoingFill) {
329  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at "
330  << cond::time::to_boost(startFillTime);
331  endSampleTime = executionTime;
332  nextFillSearchTimestamp = executionTimeIov;
333  } else {
334  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
335  << " ending at " << cond::time::to_boost(endFillTime);
336  endSampleTime = cond::time::to_boost(endFillTime);
337  nextFillSearchTimestamp = endFillTime;
338  }
339  if (m_endFillMode || ongoingFill) {
340  getDipData(oms, startSampleTime, endSampleTime);
341  getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
342  if (!m_tmpBuffer.empty()) {
343  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
344  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
345  edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
346  session.transaction().start(true);
347  getCTPPSData(session, startSampleTime, endSampleTime);
348  session.transaction().commit();
349  session2.transaction().start(true);
350  getEcalData(session2, startSampleTime, endSampleTime);
351  session2.transaction().commit();
352  }
353  }
354 
355  // In duringFill mode, convert the timestamp-type IOVs to lumiid-type IOVs
356  // before transferring the payloads from the buffer to the final collection
357  if (!m_endFillMode) {
359  }
360 
362  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
363  m_tmpBuffer.clear();
364  m_timestampToLumiid.clear();
365  if (m_prevPayload->fillNumber() and !ongoingFill) {
366  if (m_endFillMode) {
367  addEmptyPayload(endFillTime);
368  } else {
370  }
371  }
372  }
373  }
size
Write out results.
edm::ErrorSummaryEntry Error
Iov_t lastInterval
Definition: Types.h:73
std::unique_ptr< OMSServiceQuery > query(const std::string &function) const
Definition: OMSAccess.cc:129
void start(bool readOnly=true)
Definition: Session.cc:18
std::shared_ptr< LHCInfoPerFill > m_prevPayload
Time_t since
Definition: Types.h:53
size_t size
Definition: Types.h:74
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
Transaction & transaction()
Definition: Session.cc:52
void getDipData(const cond::OMSService &oms, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
std::string name
Definition: Types.h:72
Definition: query.py:1
unsigned long long Time_t
Definition: Time.h:14
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
bool getCTPPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
bool makeFillPayload(std::unique_ptr< LHCInfoPerFill > &targetPayload, const cond::OMSServiceResult &queryResult)
std::unique_ptr< LHCInfoPerFill > m_fillPayload
Hash payloadId
Definition: Types.h:55
Session createSession(const std::string &connectionString, bool writeCapable=false)
bool getEcalData(cond::persistency::Session &session, const boost::posix_time::ptime &lowerTime, const boost::posix_time::ptime &upperTime)
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
Log< level::Info, false > LogInfo
void convertBufferedIovsToLumiid(std::map< cond::Time_t, cond::Time_t > timestampToLumiid)
cond::persistency::Session & dbSession() const
std::map< cond::Time_t, cond::Time_t > m_timestampToLumiid
void connect(const std::string &baseUrl)
Definition: OMSAccess.cc:128
size_t getLumiData(const cond::OMSService &oms, unsigned short fillId, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
void setAuthenticationPath(const std::string &p)
const bool Debug
cond::Time_t getFillLastLumiIOV(const cond::OMSService &oms, unsigned short fillId)
Definition: LHCInfoHelper.cc:8
boost::posix_time::ptime to_boost(Time_t iValue)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer
size_t transferPayloads(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill >>> &buffer, std::map< cond::Time_t, std::shared_ptr< LHCInfoPerFill >> &iovsToTransfer, std::shared_ptr< LHCInfoPerFill > &prevPayload)

◆ id()

std::string LHCInfoPerFillPopConSourceHandler::id ( ) const
inlineoverridevirtual

Member Data Documentation

◆ kLumisectionsQueryLimit

constexpr unsigned int LHCInfoPerFillPopConSourceHandler::kLumisectionsQueryLimit = 4000
static

Definition at line 377 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getLumiData().

◆ m_authpath

std::string LHCInfoPerFillPopConSourceHandler::m_authpath
private

Definition at line 745 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPerFillPopConSourceHandler::m_connectionString
private

Definition at line 744 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPerFillPopConSourceHandler::m_debug
private

Definition at line 737 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getCTPPSData(), getEcalData(), and getNewObjects().

◆ m_ecalConnectionString

std::string LHCInfoPerFillPopConSourceHandler::m_ecalConnectionString
private

Definition at line 744 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_endFillMode

bool LHCInfoPerFillPopConSourceHandler::m_endFillMode = true
private

Definition at line 741 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by addPayloadToBuffer(), getLumiData(), and getNewObjects().

◆ m_endTime

boost::posix_time::ptime LHCInfoPerFillPopConSourceHandler::m_endTime
private

◆ m_fillPayload

std::unique_ptr<LHCInfoPerFill> LHCInfoPerFillPopConSourceHandler::m_fillPayload
private

Definition at line 747 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by addPayloadToBuffer(), getDipData(), and getNewObjects().

◆ m_lastPayloadEmpty

bool LHCInfoPerFillPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 750 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by addEmptyPayload().

◆ m_name

std::string LHCInfoPerFillPopConSourceHandler::m_name
private

◆ m_omsBaseUrl

std::string LHCInfoPerFillPopConSourceHandler::m_omsBaseUrl
private

Definition at line 746 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by getNewObjects().

◆ m_prevPayload

std::shared_ptr<LHCInfoPerFill> LHCInfoPerFillPopConSourceHandler::m_prevPayload
private

Definition at line 748 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by addEmptyPayload(), getEcalData(), and getNewObjects().

◆ m_startTime

boost::posix_time::ptime LHCInfoPerFillPopConSourceHandler::m_startTime
private

◆ m_timestampToLumiid

std::map<cond::Time_t, cond::Time_t> LHCInfoPerFillPopConSourceHandler::m_timestampToLumiid
private

Definition at line 752 of file LHCInfoPerFillPopConAnalyzer.cc.

Referenced by addPayloadToBuffer(), and getNewObjects().

◆ m_tmpBuffer

std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerFill> > > LHCInfoPerFillPopConSourceHandler::m_tmpBuffer
private