CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
LHCInfoPerFillPopConSourceHandler Class Reference

#include <LHCInfoPerFillPopConSourceHandler.h>

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

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 6 of file LHCInfoPerFillPopConSourceHandler.h.

Constructor & Destructor Documentation

◆ LHCInfoPerFillPopConSourceHandler()

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

Definition at line 197 of file LHCInfoPerFillPopConSourceHandler.cc.

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

198  : m_debug(pset.getUntrackedParameter<bool>("debug", false)),
199  m_startTime(),
200  m_endTime(),
201  m_endFillMode(pset.getUntrackedParameter<bool>("endFill", true)),
202  m_name(pset.getUntrackedParameter<std::string>("name", "LHCInfoPerFillPopConSourceHandler")),
203  m_connectionString(pset.getUntrackedParameter<std::string>("connectionString", "")),
204  m_ecalConnectionString(pset.getUntrackedParameter<std::string>("ecalConnectionString", "")),
205  m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
206  m_omsBaseUrl(pset.getUntrackedParameter<std::string>("omsBaseUrl", "")),
207  m_fillPayload(),
208  m_prevPayload(),
209  m_tmpBuffer() {
210  if (!pset.getUntrackedParameter<std::string>("startTime").empty()) {
211  m_startTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("startTime"));
212  }
213  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
214  m_endTime = now;
215  if (!pset.getUntrackedParameter<std::string>("endTime").empty()) {
216  m_endTime = boost::posix_time::time_from_string(pset.getUntrackedParameter<std::string>("endTime"));
217  if (m_endTime > now)
218  m_endTime = now;
219  }
220 }
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)
private

Definition at line 389 of file LHCInfoPerFillPopConSourceHandler.cc.

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

Referenced by getNewObjects().

389  {
390  bool add = false;
391  if (m_iovs.empty()) {
392  if (!m_lastPayloadEmpty)
393  add = true;
394  } else {
395  auto lastAdded = m_iovs.rbegin()->second;
396  if (lastAdded->fillNumber() != 0) {
397  add = true;
398  }
399  }
400  if (add) {
401  auto newPayload = std::make_shared<LHCInfoPerFill>();
402  m_iovs.insert(make_pair(iov, newPayload));
403  m_prevPayload = newPayload;
404  edm::LogInfo(m_name) << "Added empty payload with IOV " << iov << " ( "
405  << boost::posix_time::to_iso_extended_string(cond::time::to_boost(iov)) << " )";
406  }
407 }
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)
private

Definition at line 410 of file LHCInfoPerFillPopConSourceHandler.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().

410  {
411  auto startTime = row.get<boost::posix_time::ptime>("start_time");
412  auto delivLumi = row.get<float>("delivered_lumi");
413  auto recLumi = row.get<float>("recorded_lumi");
414  auto runNumber = std::stoul(row.get<std::string>("run_number"));
415  auto lsNumber = std::stoul(row.get<std::string>("lumisection_number"));
416  auto lumiid = cond::time::lumiTime(runNumber, lsNumber);
417 
418  LHCInfoPerFill* thisLumiSectionInfo = m_fillPayload->cloneFill();
419  m_tmpBuffer.emplace_back(make_pair(cond::time::from_boost(startTime), thisLumiSectionInfo));
420  if (!m_endFillMode) {
422  }
423  LHCInfoPerFill& payload = *thisLumiSectionInfo;
424  payload.setDelivLumi(delivLumi);
425  payload.setRecLumi(recLumi);
426 }
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)
private

Definition at line 428 of file LHCInfoPerFillPopConSourceHandler.cc.

References Exception, B2GTnPMonitor_cfi::item, and m_tmpBuffer.

Referenced by getNewObjects().

429  {
430  for (auto& item : m_tmpBuffer) {
431  // Check if the lumiid IOV corresponding to the timestamp is present in the map
432  if (timestampToLumiid.find(item.first) == timestampToLumiid.end()) {
433  throw cms::Exception("LHCInfoPerFillPopConSourceHandler")
434  << "Can't find corresponding lumiid IOV for timestamp " << item.first << "\n";
435  }
436  // Update the buffer with the lumiid-type IOV
437  item.first = timestampToLumiid.at(item.first);
438  }
439 }
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 
)
private

Definition at line 532 of file LHCInfoPerFillPopConSourceHandler.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().

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

Definition at line 470 of file LHCInfoPerFillPopConSourceHandler.cc.

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

Referenced by getNewObjects().

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

Definition at line 639 of file LHCInfoPerFillPopConSourceHandler.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().

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

Definition at line 441 of file LHCInfoPerFillPopConSourceHandler.cc.

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

Referenced by getNewObjects().

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

◆ getNewObjects()

void LHCInfoPerFillPopConSourceHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< LHCInfoPerFill >.

Definition at line 222 of file LHCInfoPerFillPopConSourceHandler.cc.

References addEmptyPayload(), cond::persistency::Transaction::commit(), theLHCInfoPerFillImpl::comparePayloads(), cond::persistency::ConnectionPool::configure(), cond::OMSService::connect(), convertBufferedIovsToLumiid(), cond::persistency::ConnectionPool::createSession(), popcon::PopConSourceHandler< LHCInfoPerFill >::dbSession(), Debug, Exception, cond::persistency::Session::fetchPayload(), cond::time::from_boost(), getCTPPSData(), getDipData(), getEcalData(), cond::lhcInfoHelper::getFillLastLumiIOV(), getLumiData(), cond::TagInfo_t::lastInterval, 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::OMSServiceQuery::SNULL, cond::persistency::Transaction::start(), popcon::PopConSourceHandler< LHCInfoPerFill >::tagInfo(), cond::time::to_boost(), cond::persistency::Session::transaction(), and theLHCInfoPerFillImpl::transferPayloads().

222  {
223  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
224  if (tagInfo().size == 0) {
225  edm::LogInfo(m_name) << "New tag " << tagInfo().name << "; from " << m_name << "::getNewObjects";
226  } else {
227  //check what is already inside the database
228  edm::LogInfo(m_name) << "got info for tag " << tagInfo().name << ": size " << tagInfo().size
229  << ", last object valid since " << tagInfo().lastInterval.since << " ( "
230  << boost::posix_time::to_iso_extended_string(
231  cond::time::to_boost(tagInfo().lastInterval.since))
232  << " ); from " << m_name << "::getNewObjects";
233  }
234 
235  cond::Time_t lastSince = tagInfo().lastInterval.since;
236  if (tagInfo().isEmpty()) {
237  // for a new or empty tag in endFill mode, an empty payload should be added on top with since=1
238  addEmptyPayload(1);
239  lastSince = 1;
240  if (!m_endFillMode) {
241  edm::LogInfo(m_name) << "Empty or new tag: uploading a default payload and ending the job";
242  return;
243  }
244  } else {
245  edm::LogInfo(m_name) << "The last Iov in tag " << tagInfo().name << " valid since " << lastSince << "from "
246  << m_name << "::getNewObjects";
247  }
248 
249  //retrieve the data from the relational database source
251  //configure the connection
252  if (m_debug) {
253  connection.setMessageVerbosity(coral::Debug);
254  } else {
255  connection.setMessageVerbosity(coral::Error);
256  }
257  connection.setAuthenticationPath(m_authpath);
258  connection.configure();
259  //create the sessions
262  // fetch last payload when available
263  if (!tagInfo().lastInterval.payloadId.empty()) {
265  session3.transaction().start(true);
267  session3.transaction().commit();
268  }
269 
270  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
271  cond::Time_t executionTimeIov = cond::time::from_boost(executionTime);
272 
273  cond::Time_t startTimestamp = m_startTime.is_not_a_date_time() ? 0 : cond::time::from_boost(m_startTime);
274  cond::Time_t nextFillSearchTimestamp =
275  std::max(startTimestamp, m_endFillMode ? lastSince : m_prevPayload->createTime());
276 
277  edm::LogInfo(m_name) << "Starting sampling at "
278  << boost::posix_time::to_simple_string(cond::time::to_boost(nextFillSearchTimestamp));
279 
280  while (true) {
281  if (nextFillSearchTimestamp >= executionTimeIov) {
282  edm::LogInfo(m_name) << "Sampling ended at the time "
283  << boost::posix_time::to_simple_string(cond::time::to_boost(executionTimeIov));
284  break;
285  }
286  boost::posix_time::ptime nextFillSearchTime = cond::time::to_boost(nextFillSearchTimestamp);
287  boost::posix_time::ptime startSampleTime;
288  boost::posix_time::ptime endSampleTime;
289 
290  cond::OMSService oms;
291  oms.connect(m_omsBaseUrl);
292  auto query = oms.query("fills");
293 
294  edm::LogInfo(m_name) << "Searching new fill after " << boost::posix_time::to_simple_string(nextFillSearchTime);
295  query->filterNotNull("start_stable_beam").filterNotNull("fill_number");
296  if (nextFillSearchTime > cond::time::to_boost(m_prevPayload->createTime())) {
297  query->filterGE("start_time", nextFillSearchTime);
298  } else {
299  query->filterGT("start_time", nextFillSearchTime);
300  }
301 
302  query->filterLT("start_time", m_endTime);
303  if (m_endFillMode)
304  query->filterNotNull("end_time");
305  else
306  query->filterEQ("end_time", cond::OMSServiceQuery::SNULL);
307 
308  bool foundFill = query->execute();
309  if (foundFill)
311  if (!foundFill) {
312  edm::LogInfo(m_name) << "No fill found - END of job.";
313  break;
314  }
315 
316  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
317  cond::Time_t startFillTime = m_fillPayload->createTime();
318  cond::Time_t endFillTime = m_fillPayload->endTime();
319  unsigned short lhcFill = m_fillPayload->fillNumber();
320  bool ongoingFill = endFillTime == 0ULL;
321  if (ongoingFill) {
322  edm::LogInfo(m_name) << "Found ongoing fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime);
323  endSampleTime = executionTime;
324  nextFillSearchTimestamp = executionTimeIov;
325  } else {
326  edm::LogInfo(m_name) << "Found fill " << lhcFill << " created at " << cond::time::to_boost(startFillTime)
327  << " ending at " << cond::time::to_boost(endFillTime);
328  endSampleTime = cond::time::to_boost(endFillTime);
329  nextFillSearchTimestamp = endFillTime;
330  }
331  if (m_endFillMode || ongoingFill) {
332  getDipData(oms, startSampleTime, endSampleTime);
333  getLumiData(oms, lhcFill, startSampleTime, endSampleTime);
334  if (!m_tmpBuffer.empty()) {
335  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
336  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
337  edm::LogInfo(m_name) << "First lumi starts at " << flumiStart << " last lumi starts at " << flumiStop;
338  session.transaction().start(true);
339  getCTPPSData(session, startSampleTime, endSampleTime);
340  session.transaction().commit();
341  session2.transaction().start(true);
342  getEcalData(session2, startSampleTime, endSampleTime);
343  session2.transaction().commit();
344  }
345  }
346 
347  if (!m_endFillMode) {
348  if (m_tmpBuffer.size() > 1) {
349  throw cms::Exception("LHCInfoPerFillPopConSourceHandler")
350  << "More than 1 payload buffered for writing in duringFill mode.\
351  In this mode only up to 1 payload can be written";
352  } else if (m_tmpBuffer.size() == 1) {
354  m_tmpBuffer.clear();
356  << "The buffered payload has the same data as the previous payload in the tag. It will not be written.";
357  }
358  } else if (m_tmpBuffer.empty()) {
360  cond::lhcInfoHelper::getFillLastLumiIOV(oms, lhcFill)); //the IOV doesn't matter when using OnlinePopCon
361  }
362  // In duringFill mode, convert the timestamp-type IOVs to lumiid-type IOVs
363  // before transferring the payloads from the buffer to the final collection
365  }
366 
368  edm::LogInfo(m_name) << "Added " << niovs << " iovs within the Fill time";
369  m_tmpBuffer.clear();
370  m_timestampToLumiid.clear();
371 
372  if (!m_endFillMode) {
373  return;
374  }
375 
376  // endFill mode only:
377  if (m_prevPayload->fillNumber() and !ongoingFill) {
378  if (m_endFillMode) {
379  addEmptyPayload(endFillTime);
380  } else {
382  }
383  }
384  }
385 }
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
bool comparePayloads(const LHCInfoPerFill &rhs, const LHCInfoPerFill &lhs)
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)
size_t transferPayloads(const std::vector< pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill >>> &buffer, std::map< cond::Time_t, std::shared_ptr< LHCInfoPerFill >> &iovsToTransfer, std::shared_ptr< LHCInfoPerFill > &prevPayload)
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)
static constexpr const char *const SNULL
Definition: OMSAccess.h:183
void setAuthenticationPath(const std::string &p)
const bool Debug
cond::Time_t getFillLastLumiIOV(const cond::OMSService &oms, unsigned short fillId)
boost::posix_time::ptime to_boost(Time_t iValue)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfoPerFill > > > m_tmpBuffer

◆ id()

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

Member Data Documentation

◆ m_authpath

std::string LHCInfoPerFillPopConSourceHandler::m_authpath
private

Definition at line 47 of file LHCInfoPerFillPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_connectionString

std::string LHCInfoPerFillPopConSourceHandler::m_connectionString
private

Definition at line 46 of file LHCInfoPerFillPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_debug

bool LHCInfoPerFillPopConSourceHandler::m_debug
private

Definition at line 39 of file LHCInfoPerFillPopConSourceHandler.h.

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

◆ m_ecalConnectionString

std::string LHCInfoPerFillPopConSourceHandler::m_ecalConnectionString
private

Definition at line 46 of file LHCInfoPerFillPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_endFillMode

bool LHCInfoPerFillPopConSourceHandler::m_endFillMode = true
private

◆ m_endTime

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

◆ m_fillPayload

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

◆ m_lastPayloadEmpty

bool LHCInfoPerFillPopConSourceHandler::m_lastPayloadEmpty = false
private

Definition at line 52 of file LHCInfoPerFillPopConSourceHandler.h.

Referenced by addEmptyPayload().

◆ m_name

std::string LHCInfoPerFillPopConSourceHandler::m_name
private

◆ m_omsBaseUrl

std::string LHCInfoPerFillPopConSourceHandler::m_omsBaseUrl
private

Definition at line 48 of file LHCInfoPerFillPopConSourceHandler.h.

Referenced by getNewObjects().

◆ m_prevPayload

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

Definition at line 50 of file LHCInfoPerFillPopConSourceHandler.h.

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 54 of file LHCInfoPerFillPopConSourceHandler.h.

Referenced by addPayloadToBuffer(), and getNewObjects().

◆ m_tmpBuffer

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